Skip to content

Instantly share code, notes, and snippets.

@Bodacious
Last active January 2, 2016 14:59
Show Gist options
  • Select an option

  • Save Bodacious/8320144 to your computer and use it in GitHub Desktop.

Select an option

Save Bodacious/8320144 to your computer and use it in GitHub Desktop.
List of musical notes and their frequencies calculated in Ruby
# The freqencies of A are easiest as most are integers
# Remember - each octave means double frequency
A_FREQS = %w[ 27.5 55 110 220 440 880 1760 3520 7040 14080 ].map(&:to_f)
# The names of the 12 semitones
NOTES = %W[ A\s A# B\s C\s C# D\s D# E\s F\s F# G\s G# ]
A_FREQS.each_with_index do |freq, octave|
NOTES.each_with_index do |note, i|
octave += 1 if note == "C\s"
note_freq = freq * (2 ** (i/12.to_f))
puts "#{note}#{octave} : #{note_freq}Hz"
end
end
@Bodacious
Copy link
Author

Note - the interval from one semitone (n1) to the next (n2) is n2 = n1 * 2 ** (1/12.to_f) It goes up in intervals of 2 to the 12th power

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment