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(
'#if ARDUINO >= 100'+
'\n')
16 fout.write(
'#include "Arduino.h"'+
'\n')
17 fout.write(
'#else'+
'\n')
18 fout.write(
'#include "WProgram.h"'+
'\n')
19 fout.write(
'#endif'+
'\n')
20 fout.write(
'#include "mozzi_pgmspace.h"'+
'\n \n')
21 fout.write(
'#define ' + tablename +
'_NUM_CELLS '+ str(tablelength) +
'\n')
22 fout.write(
'CONSTTABLE_STORAGE(int8_t) ' + tablename +
'_DATA [] = { \n')
25 for tablenum
in range(numtables):
28 for num
in range(tablelength):
30 x = float(num)/tablelength
32 t_x = math.sin(2*math.pi*x)*(float(tablenum+1)/numtables)
34 scaled = int16_t(math.floor(t_x*127.999))
36 outstring += str(scaled) +
', ' 38 outstring = textwrap.fill(outstring, 80)
43 fout.write(
'}; \n \n #endif /* ' + tablename +
'_H_ */\n')
45 print "wrote " + outfile
48 generate(
"~/Desktop/sin_64level_int8.h",
"SIN_64LEVEL", 256, 64)