| Mozzi version v1.1.0 sound synthesis library for Arduino |

float2mozzi_uint8.py
1
2
3 import sys, array, os, textwrap, math
4
5 def float2mozzi_uint8(infile, outfile, tablename,samplerate):
6 fin = open(os.path.expanduser(infile), "rb")
7 print "opened " + infile
8 valuesetad = os.path.getsize(os.path.expanduser(infile))/4
9
10
11 valuesfromfile = array.array('f')
12 try:
13 valuesfromfile.fromfile(fin,valuesetad)
14 finally:
15 fin.close()
16
17 values=valuesfromfile.tolist()
18
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 [] = {'
33 try:
34 for num in values:
35 outstring += str(math.trunc((num*256)+0.5)) + ", "
36
38 finally:
39 outstring += "};"
40 outstring = textwrap.fill(outstring, 80)
41 fout.write(outstring)
42 fout.write('\n \n #endif /* ' + tablename + '_H_ */\n')
43 fout.close()
44 print "wrote " + outfile
45
46 float2mozzi_uint8(infile, outfile, tablename, samplerate)
float2mozzi_uint8
Definition: float2mozzi_uint8.py:1