| Mozzi version v1.1.0 sound synthesis library for Arduino |

sin8192_uint8.py
1
2
3
4 import array
5 import os
6 import textwrap
7 import math
8
9 def generate(outfile, tablename, tablelength, samplerate):
10 fout = open(os.path.expanduser(outfile), "w")
11 fout.write('#ifndef ' + tablename + '_H_' + '\n')
12 fout.write('#define ' + tablename + '_H_' + '\n \n')
13 fout.write('#if ARDUINO >= 100'+'\n')
14 fout.write('#include "Arduino.h"'+'\n')
15 fout.write('#else'+'\n')
16 fout.write('#include "WProgram.h"'+'\n')
17 fout.write('#endif'+'\n')
18 fout.write('#include "mozzi_pgmspace.h"'+'\n \n')
19 fout.write('#define ' + tablename + '_NUM_CELLS '+ str(tablelength)+'\n')
20 fout.write('#define ' + tablename + '_SAMPLERATE '+ str(samplerate)+'\n \n')
21 outstring = 'CONSTTABLE_STORAGE(int8_t) ' + tablename + '_DATA [] = {'
22 halftable = tablelength/2
23 try:
24 for num in range(tablelength):
25
27 x = float(num)/tablelength
28
29 t_x = (math.cos(2*math.pi*x-math.pi)+1)/2
30
31 scaled = int(math.floor(t_x*255.999))
32
33 outstring += str(scaled) + ', '
34
36 finally:
37 outstring = textwrap.fill(outstring, 80)
38 outstring += '\n }; \n \n #endif /* ' + tablename + '_H_ */\n'
39 fout.write(outstring)
40 fout.close()
41 print "wrote " + outfile
42
43
44 generate("~/Desktop/sin8192_uint8.h", "sin8192_uint", 8192, "8192")