summaryrefslogtreecommitdiff
path: root/sw/Core/Src/tables.py
blob: 4b018d9f53a199d01afb089062727131fb93b2e4 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import math,random,struct,sys
sys.stdout = open("tables.h", "w")

s16 = lambda x: x if (x<32768) else x-65536
print("// generated by tables.py")
print("const static float lpf_ks[1025]={ ")
for i in range(1025):  
  x=i/1024
  if (x==0): x=1./65536.
  x=x*x;
  print("%.8ff" % (1.-math.pow(2,-0.00125/x)), end=',') # constants nearer 0 mean longer max decay
  if (i%16==15): print(" ")
print("};\n")

print("const static float pitches[1025]={ // 10 octaves, 8th of a semitone steps")
for i in range(1025):
  x=(i-512)/(12*8)
  print("%.8ff" % math.pow(2,x),end=',')
  if (i%16==15): print(" ")
print("};\n")


#maxf=10000
#imul=(maxf/32000)*math.pi /1024
#print("const static float svfg[1025]={ // used for SVF g term")
#for i in range(1025):
#  g=math.tan(i*imul)
#  print("%.8ff" % g,end=',')
#  if (i%16==15): print(" ")
#print("};\n")
#
#print("const static float svfa1[1025]={ // used for SVF a1 term")
#for i in range(1025):
#  g=math.tan(i*imul)
#  a1=1/(1+g*g)
#  print("%.8ff" % a1,end=',')
#  if (i%16==15): print(" ")
#print("};\n")
#
#print("const static float svfa2[1025]={ // used for SVF a2 term")
#for i in range(1025):
#  g=math.tan(i*imul)
#  a1=1/(1+g*g)
#  a2=g*a1
#  print("%.8ff" % a2,end=',')
#  if (i%16==15): print(" ")
#print("};\n")

print("const static short sigmoid[65536]={")
for j in range(1024):  
 for i in range(64):
  x=s16(i+j*64)
  fx=x/32768.0*4.0
  hy=math.tanh(fx)+math.tanh(fx*fx*0.0005); # bit of even distortion too
  y=0.5*32500.*hy
  print(int(y), end=',')
 print(" ")
print("};\n")

print("const static u8 rndtab[65536]={")
for j in range(1024):
 for i in range(64): print(random.randint(0,255), end=",")
 print(" ")
print("};\n")