Skip to content

Commit

Permalink
refactor(frequency): ♻️ extract reference as 440 Hz
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Mar 27, 2024
1 parent 34eda40 commit 40b347d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/src/note/closest_pitch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ClosestPitch {
/// (Note.a.inOctave(4) + const Cent(12)).frequency() == const Frequency(443)
/// ```
Frequency frequency({
Frequency referenceFrequency = const Frequency(440),
Frequency referenceFrequency = Frequency.reference,
TuningSystem tuningSystem = const EqualTemperament.edo12(),
}) =>
Frequency(
Expand Down
5 changes: 4 additions & 1 deletion lib/src/note/frequency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ extension type const Frequency._(num hertz) implements num {
/// The symbol for the Hertz unit.
static const hertzUnitSymbol = 'Hz';

/// The standard reference [Frequency].
static const reference = Frequency(440);

/// Whether this [Frequency] is inside the [HearingRange.human].
///
/// Example:
Expand Down Expand Up @@ -52,7 +55,7 @@ extension type const Frequency._(num hertz) implements num {
/// frequency.closestPitch().frequency() == frequency;
/// ```
ClosestPitch closestPitch({
Frequency referenceFrequency = const Frequency(440),
Frequency referenceFrequency = Frequency.reference,
TuningSystem tuningSystem = const EqualTemperament.edo12(),
}) {
final cents = Ratio(hertz / referenceFrequency).cents;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/note/pitch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ final class Pitch extends Scalable<Pitch> implements Comparable<Pitch> {
/// pitch.frequency().closestPitch().pitch == pitch;
/// ```
Frequency frequency({
Frequency referenceFrequency = const Frequency(440),
Frequency referenceFrequency = Frequency.reference,
TuningSystem tuningSystem = const EqualTemperament.edo12(),
}) =>
Frequency(referenceFrequency * tuningSystem.ratio(this));
Expand All @@ -419,7 +419,7 @@ final class Pitch extends Scalable<Pitch> implements Comparable<Pitch> {
/// ```
Set<ClosestPitch> harmonics({
required int upToIndex,
Frequency referenceFrequency = const Frequency(440),
Frequency referenceFrequency = Frequency.reference,
TuningSystem tuningSystem = const EqualTemperament.edo12(),
}) =>
frequency(
Expand Down

0 comments on commit 40b347d

Please sign in to comment.