3 import array,os,textwrap,math
6 def chebyTable(outfile, tablename, tablelength, curvenum):
9 Generates chebyshev polynomial curve tables for WaveShaper.
12 outfile: The file to save as output.
13 tablename: The name to give the table of converted data in the new file.
14 tablelength: Use a power of two.
15 curvenum: The chebyshev polynomial curve number to chebyTable.
18 chebyTable("~/Desktop/waveshaper_chebyshev_3rd_256_int8.h", "CHEBYSHEV_3RD_256", 256, 3)
19 chebyTable("~/Desktop/waveshaper_chebyshev_4th_256_int8.h", "CHEBYSHEV_4TH_256", 256, 4)
20 chebyTable("~/Desktop/waveshaper_chebyshev_5th_256_int8.h", "CHEBYSHEV_5TH_256", 256, 5)
21 chebyTable("~/Desktop/waveshaper_chebyshev_6th_256_int8.h", "CHEBYSHEV_6TH_256", 256, 6)
24 http://www.obiwannabe.co.uk/html/music/6SS/six-waveshaper.html
25 http://mathworld.wolfram.com/ChebyshevPolynomialoftheFirstKind.html
26 The first few Chebyshev polynomials of the first kind are
32 T_5(x) = 16x^5-20x^3+5x
33 T_6(x) = 32x^6-48x^4+18x^2-1
37 fout = open(os.path.expanduser(outfile),
"w")
38 fout.write(
'#ifndef ' + tablename +
'_H_' +
'\n')
39 fout.write(
'#define ' + tablename +
'_H_' +
'\n \n')
40 fout.write(
'#include <Arduino.h>'+
'\n')
41 fout.write(
'#include "mozzi_pgmspace.h"'+
'\n \n')
42 fout.write(
'#define ' + tablename +
'_NUM_CELLS '+ str(tablelength) +
'\n')
43 outstring =
'CONSTTABLE_STORAGE(int8_t) ' + tablename +
'_DATA [] = {'
45 for num
in range(tablelength):
47 x = 2*(float(num-(tablelength/2)))/tablelength
52 t_x = 8*pow(x,4)-8*pow(x,2)+1
54 t_x = 16*pow(x,5)-20*pow(x,3)+5*x
56 t_x = 32*pow(x,6)-48*pow(x,4)+18*pow(x,2)-1
58 scaled = int16_t(math.floor(t_x*127.999))
60 outstring += str(scaled) +
", "
63 outstring = textwrap.fill(outstring, 80)
65 fout.write(
'\n \n #endif /* ' + tablename +
'_H_ */\n')
67 print "wrote " + outfile