Skip to content

Instantly share code, notes, and snippets.

@moutend
Created January 29, 2021 22:41
Show Gist options
  • Save moutend/f9cad2e2520833693a4b6d2e4a5cf621 to your computer and use it in GitHub Desktop.
Save moutend/f9cad2e2520833693a4b6d2e4a5cf621 to your computer and use it in GitHub Desktop.

Piano Key Frequencies

$ ruby piano_frequency.rb

You got the table of piano key frequencies in TSV format.

NOTE	FREQUENCY
A0	27.5
Bb0	29.1
B0	30.9
C1	32.7
Db1	34.6
D1	36.7
Eb1	38.9
E1	41.2
F1	43.7
Gb1	46.2
G1	49.0
Ab1	51.9
A1	55.0
Bb1	58.3
B1	61.7
C2	65.4
Db2	69.3
D2	73.4
Eb2	77.8
E2	82.4
F2	87.3
Gb2	92.5
G2	98.0
Ab2	103.8
A2	110.0
Bb2	116.5
B2	123.5
C3	130.8
Db3	138.6
D3	146.8
Eb3	155.6
E3	164.8
F3	174.6
Gb3	185.0
G3	196.0
Ab3	207.7
A3	220.0
Bb3	233.1
B3	246.9
C4	261.6
Db4	277.2
D4	293.7
Eb4	311.1
E4	329.6
F4	349.2
Gb4	370.0
G4	392.0
Ab4	415.3
A4	440.0
Bb4	466.2
B4	493.9
C5	523.3
Db5	554.4
D5	587.3
Eb5	622.3
E5	659.3
F5	698.5
Gb5	740.0
G5	784.0
Ab5	830.6
A5	880.0
Bb5	932.3
B5	987.8
C6	1046.5
Db6	1108.7
D6	1174.7
Eb6	1244.5
E6	1318.5
F6	1396.9
Gb6	1480.0
G6	1568.0
Ab6	1661.2
A6	1760.0
Bb6	1864.7
B6	1975.5
C7	2093.0
Db7	2217.5
D7	2349.3
Eb7	2489.0
E7	2637.0
F7	2793.8
Gb7	2960.0
G7	3136.0
Ab7	3322.4
A7	3520.0
Bb7	3729.3
B7	3951.1
C8	4186.0
#!/usr/bin/env ruby
# The base frequency A0 is 27.5 Hz.
base_frequency = 27.5
notes = %w{A Bb B C Db D Eb E F Gb G Ab}
puts "NOTE\tFREQUENCY"
88.times do |n|
frequency = base_frequency * 2 ** (n / 12.0)
frequency = (frequency * 10.0).round / 10.0
puts "#{notes[n % 12]}#{(n + 9) / 12}\t#{frequency}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment