3 import sys, array, os, textwrap, math
6 print 'Usage: float2mozzi.py <infile outfile tablename samplerate>'
9 [infile, outfile, tablename, samplerate] = sys.argv[1:]
11 def float2mozzi(infile, outfile, tablename,samplerate):
12 fin = open(os.path.expanduser(infile),
"rb")
13 print "opened " + infile
14 valuesetad = os.path.getsize(os.path.expanduser(infile))/4
17 valuesfromfile = array.array(
'f')
19 valuesfromfile.fromfile(fin,valuesetad)
23 values=valuesfromfile.tolist()
27 fout = open(os.path.expanduser(outfile),
"w")
28 fout.write(
'#ifndef ' + tablename +
'_H_' +
'\n')
29 fout.write(
'#define ' + tablename +
'_H_' +
'\n \n')
30 fout.write(
'#include <Arduino.h>'+
'\n')
31 fout.write(
'#include "mozzi_pgmspace.h"'+
'\n \n')
32 fout.write(
'#define ' + tablename +
'_NUM_CELLS '+ str(len(values))+
'\n')
33 fout.write(
'#define ' + tablename +
'_SAMPLERATE '+ str(samplerate)+
'\n \n')
34 outstring =
'CONSTTABLE_STORAGE(int8_t) ' + tablename +
'_DATA [] = {'
37 outstring += str(math.trunc((num*256)+0.5)) +
", "
42 outstring = textwrap.fill(outstring, 80)
44 fout.write(
'\n \n #endif /* ' + tablename +
'_H_ */\n')
46 print "wrote " + outfile