3 import sys, array, os, textwrap, math
6 fin = open(os.path.expanduser(infile),
"rb")
7 print "opened " + infile
8 valuesetad = os.path.getsize(os.path.expanduser(infile))/4
11 valuesfromfile = array.array(
'f')
13 valuesfromfile.fromfile(fin,valuesetad)
17 values=valuesfromfile.tolist()
21 fout = open(os.path.expanduser(outfile),
"w")
22 fout.write(
'#ifndef ' + tablename +
'_H_' +
'\n')
23 fout.write(
'#define ' + tablename +
'_H_' +
'\n \n')
24 fout.write(
'#if ARDUINO >= 100'+
'\n')
25 fout.write(
'#include "Arduino.h"'+
'\n')
26 fout.write(
'#else'+
'\n')
27 fout.write(
'#include "WProgram.h"'+
'\n')
28 fout.write(
'#endif'+
'\n')
29 fout.write(
'#include "mozzi_pgmspace.h"'+
'\n \n')
30 fout.write(
'#define ' + tablename +
'_NUM_CELLS '+ str(len(values))+
'\n')
31 fout.write(
'#define ' + tablename +
'_SAMPLERATE '+ str(samplerate)+
'\n \n')
32 outstring =
'CONSTTABLE_STORAGE(int8_t) ' + tablename +
'_DATA [] = {' 35 outstring += str(math.trunc((num*256)+0.5)) +
", " 40 outstring = textwrap.fill(outstring, 80)
42 fout.write(
'\n \n #endif /* ' + tablename +
'_H_ */\n')
44 print "wrote " + outfile