Class: InevitableCacophony::MidiGenerator::FrequencyTable
- Inherits:
-
Object
- Object
- InevitableCacophony::MidiGenerator::FrequencyTable
- Defined in:
- lib/inevitable_cacophony/midi_generator/frequency_table.rb
Defined Under Namespace
Classes: OutOfRange
Constant Summary collapse
- MIDI_RANGE =
Range of allowed MIDI 1 indices.
0..127
- MIDI_TONIC =
Middle A in MIDI
69
- MIDI_OCTAVE_NOTES =
Standard western notes per octave assumed by MIDI
12
- STANDARD_MIDI_FREQUENCIES =
12TET values of those notes.
MIDI_OCTAVE_NOTES.times.map do |index| OctaveStructure::OCTAVE_RATIO ** (index / MIDI_OCTAVE_NOTES.to_f) end
- FREQUENCY_FUDGE_FACTOR =
Maximum increase/decrease between two frequencies we still treat as “equal”. Approximately 1/30th of human Just Noticeable Difference for pitch.
(1.0/10_000)
Instance Attribute Summary collapse
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #index_for_ratio(ratio) ⇒ Object
-
#initialize(octave_structure, tonic) ⇒ FrequencyTable
constructor
Create a frequency table with a given structure and tonic.
Constructor Details
#initialize(octave_structure, tonic) ⇒ FrequencyTable
Create a frequency table with a given structure and tonic.
49 50 51 52 |
# File 'lib/inevitable_cacophony/midi_generator/frequency_table.rb', line 49 def initialize(octave_structure, tonic) @tonic = tonic @table = build_table(octave_structure, tonic) end |
Instance Attribute Details
#table ⇒ Object (readonly)
Returns the value of attribute table.
54 55 56 |
# File 'lib/inevitable_cacophony/midi_generator/frequency_table.rb', line 54 def table @table end |
Instance Method Details
#index_for_ratio(ratio) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/inevitable_cacophony/midi_generator/frequency_table.rb', line 58 def index_for_ratio(ratio) # TODO: not reliable for approximate matching frequency = @tonic * ratio if (match = table.index(frequency)) match else raise OutOfRange.new(frequency, table) end end |