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

table_generator_template.py
1 import array
2 import os
3 import textwrap
4
5 def generate(outfile, tablename, tablelength, samplerate):
6 fout = open(os.path.expanduser(outfile), "w")
7 fout.write('#ifndef ' + tablename + '_H_' + '\n')
8 fout.write('#define ' + tablename + '_H_' + '\n \n')
9 fout.write('#if ARDUINO >= 100'+'\n')
10 fout.write('#include "Arduino.h"'+'\n')
11 fout.write('#else'+'\n')
12 fout.write('#include "WProgram.h"'+'\n')
13 fout.write('#endif'+'\n')
14 fout.write('#include "mozzi_pgmspace.h"'+'\n \n')
15 fout.write('#define ' + tablename + '_NUM_CELLS '+ str(len(values))+'\n')
16 fout.write('#define ' + tablename + '_SAMPLERATE '+ str(samplerate)+'\n \n')
17 outstring = 'CONSTTABLE_STORAGE(int8_t) ' + tablename + '_DATA [] = {'
18 try:
19 for num in range(tablelength):
20 outstring += str(num/32) + ", "
21 finally:
22 outstring += "};"
23 outstring = textwrap.fill(outstring, 80)
24 fout.write(outstring)
25 fout.write('\n \n #endif /* ' + tablename + '_H_ */\n')
26 fout.close()
27 print "wrote " + outfile
28
29 generate("~/Desktop/phasor8192_uint8.h", "phasor8192", 8192, "8192")