4 import array,os,textwrap,math
8 def generate(outfile, tablename, tablelength, numtables):
9 fout = open(os.path.expanduser(outfile),
"w")
13 fout.write(
'#ifndef ' + tablename +
'_H_' +
'\n')
14 fout.write(
'#define ' + tablename +
'_H_' +
'\n \n')
15 fout.write(
'#include <Arduino.h>'+
'\n')
16 fout.write(
'#include "mozzi_pgmspace.h"'+
'\n \n')
17 fout.write(
'#define ' + tablename +
'_NUM_CELLS '+ str(tablelength) +
'\n')
18 fout.write(
'CONSTTABLE_STORAGE(int8_t) ' + tablename +
'_DATA [] = { \n')
21 for tablenum
in range(numtables):
24 for num
in range(tablelength):
26 x = float(num)/tablelength
28 t_x = math.sin(2*math.pi*x)*(float(tablenum+1)/numtables)
30 scaled = int16_t(math.floor(t_x*127.999))
32 outstring += str(scaled) +
', '
34 outstring = textwrap.fill(outstring, 80)
39 fout.write(
'}; \n \n #endif /* ' + tablename +
'_H_ */\n')
41 print "wrote " + outfile
44 generate(
"~/Desktop/sin_64level_int8.h",
"SIN_64LEVEL", 256, 64)