Mozzi  version v2.0
sound synthesis library for Arduino
table_generator_template.py
1 import array
2 import os
3 import textwrap
4 import random
5 
6 def generate(outfile, tablename, tablelength, samplerate):
7  fout = open(os.path.expanduser(outfile), "w")
8  fout.write('#ifndef ' + tablename + '_H_' + '\n')
9  fout.write('#define ' + tablename + '_H_' + '\n \n')
10  fout.write('#include <Arduino.h>'+'\n')
11  fout.write('#include "mozzi_pgmspace.h"'+'\n \n')
12  fout.write('#define ' + tablename + '_NUM_CELLS '+ str(tablelength)+'\n')
13  fout.write('#define ' + tablename + '_SAMPLERATE '+ str(samplerate)+'\n \n')
14  outstring = 'CONSTTABLE_STORAGE(int8_t) ' + tablename + '_DATA [] = {'
15  try:
16  for num in range(tablelength):
17  outstring += str(random.randint(-128, 127)) + ", "
18  finally:
19  outstring += "};"
20  outstring = textwrap.fill(outstring, 80)
21  fout.write(outstring)
22  fout.write('\n \n #endif /* ' + tablename + '_H_ */\n')
23  fout.close()
24  print("wrote " + outfile)
25 
26 generate("~/Desktop/whitenoise_4096_3_int8.h", "WHITENOISE_4096_3", 4096, 16384) # adjust to suit