-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is to separate concerns: converting the positioned note to a frequency, which could be done in different ways, e.g. equal tempered, pythagorean (these methods belong to PositionedNote), versus properties or functionality related to the frequency itself, such as isHumanAudible or a hypothetical .play() method. Closes #107
- Loading branch information
Showing
5 changed files
with
75 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
part of '../../music_notes.dart'; | ||
|
||
/// Represents an absolute pitch, a physical frequency. | ||
class Frequency { | ||
Frequency(this.hertz); | ||
|
||
final double hertz; | ||
|
||
/// Whether this [Frequency] is inside the human hearing range. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// Note.a.inOctave(4).isHumanAudibleAt() == true | ||
/// Note.d.inOctave(0).isHumanAudibleAt() == false | ||
/// Note.g.inOctave(12).isHumanAudibleAt(442) == false | ||
/// ``` | ||
bool get isHumanAudible { | ||
const minFrequency = 20; | ||
const maxFrequency = 20000; | ||
|
||
return hertz >= minFrequency && hertz <= maxFrequency; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:music_notes/music_notes.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('.isHumanAudible', () { | ||
test('should return whether the frequency is audible by humans', () { | ||
expect(Frequency(0).isHumanAudible, isFalse); | ||
expect(Frequency(100).isHumanAudible, isTrue); | ||
expect(Frequency(400).isHumanAudible, isTrue); | ||
expect(Frequency(15000).isHumanAudible, isTrue); | ||
expect(Frequency(100000).isHumanAudible, isFalse); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters