-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmkfreq.py
51 lines (39 loc) · 1.33 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
##########################################################################
# Compute and print piano key frequency table
##########################################################################
from __future__ import division
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
# construct filenames for Salamander piano samples
sampfn = {}
facs = 1, 2**(1/12), 2**(2/12)
nam = "A", "C", "D#", "F#"
def getfn(layer):
for k in range(88):
oct = (k + 9) // 12
sampfn[k] = "%s%uv%u.wav" % (nam[(k // 3) % 4], oct, layer), facs[k % 3]
return sampfn
#x = getfn()
#for a in x:
# print(a, x[a])