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(
'#include <Arduino.h>'+
'\n')
14 fout.write(
'#include "mozzi_pgmspace.h"'+
'\n \n')
15 fout.write(
'#define ' + tablename +
'_NUM_CELLS '+ str(tablelength)+
'\n')
16 fout.write(
'#define ' + tablename +
'_SAMPLERATE '+ str(samplerate)+
'\n \n')
17 outstring =
'CONSTTABLE_STORAGE(int8_t) ' + tablename +
'_DATA [] = {'
18 halftable = tablelength/2
20 for num
in range(tablelength):
23 x = float(num)/tablelength
25 t_x = (math.cos(2*math.pi*x-math.pi)+1)/2
27 scaled = int(math.floor(t_x*255.999))
29 outstring += str(scaled) +
', '
33 outstring = textwrap.fill(outstring, 80)
34 outstring +=
'\n }; \n \n #endif /* ' + tablename +
'_H_ */\n'
37 print "wrote " + outfile
40 generate(
"~/Desktop/sin8192_uint8.h",
"sin8192_uint", 8192,
"8192")