-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkfreq.py
executable file
·30 lines (26 loc) · 1009 Bytes
/
mkfreq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
##########################################################################
# Compute and print piano key frequency table
##########################################################################
pitchhz, keynum = {}, {}
keys_s = ('a', 'a#', 'b', 'c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#')
keys_f = ('a', 'bb', 'b', 'c', 'db', 'd', 'eb', 'e', 'f', 'gb', 'g', 'ab')
keys_e = ('a', 'bb', 'cb', 'b#', 'db', 'd', 'eb', 'fb', 'e#', 'gb', 'g', 'ab')
def getfreq(pr = False):
if pr:
print("Piano key frequencies (for equal temperament):")
print("Key number\tScientific name\tFrequency (Hz)")
for k in range(88):
freq = 27.5 * 2.**(k/12.)
oct = (k+9) // 12
note = '%s%u' % (keys_s[k%12], oct)
if pr:
print("%10u\t%15s\t%14.2f" % (k+1, note.upper(), freq))
pitchhz[note] = freq
keynum[note] = k
note = '%s%u' % (keys_f[k%12], oct)
pitchhz[note] = freq
keynum[note] = k
note = '%s%u' % (keys_e[k%12], oct)
pitchhz[note] = freq
keynum[note] = k
return pitchhz, keynum