From the original SynthMaker forum (2004–2014), with its members’ names and dates.
tobiah · 8 Oct 2007
Hello everyone!
I want to make a VST with a lattice filter I have found from the tms5220 chip but I cant get it right.
My thoughts are that I might have to work in a lower bitrate but is that possible in SM?
What am I doing wrong?
Thank you in advance!
The source is here, search for lattice_filter:
http://mamedev.org/source/src/emu/sound/tms5220.c.html
the code i have written in a code component is:
------------------------------------------------------------
streamin in;
streamout out;
streamin res1;
streamin res2;
streamin res3;
streamin res4;
streamin res5;
streamin res6;
streamin res7;
streamin res8;
streamin res9;
streamin res10;
float u[10];
float x[9];
u[10] = in;
u[9] = u[10] - (res10 * x[9]);
u[8] = u[9] - (res9 * x[8]);
u[7] = u[8] - (res8 * x[7]);
u[6] = u[7] - (res7 * x[6]);
u[5] = u[6] - (res6 * x[5]);
u[4] = u[5] - (res5 * x[4]);
u[3] = u[4] - (res4 * x[3]);
u[2] = u[3] - (res3 * x[2]);
u[1] = u[2] - (res2 * x[1]);
u[0] = u[1] - (res1 * x[0]);
x[9] = x[8] + (res9 * u[8]);
x[8] = x[7] + (res8 * u[7]);
x[7] = x[6] + (res7 * u[6]);
x[6] = x[5] + (res6 * u[5]);
x[5] = x[4] + (res5 * u[4]);
x[4] = x[3] + (res4 * u[3]);
x[3] = x[2] + (res3 * u[2]);
x[2] = x[1] + (res2 * u[1]);
x[1] = x[0] + (res1 * u[0]);
x[0] = u[0];
out = u[0];
rl · 8 Oct 2007
Welcome tobiah!
hmm... your code looks quite reasonable. For performance reasons I'd avoid arrays as much as possible. For indexing a float->int conversion is needed, which takes a fair amount of clock cycles. The following code is about 10 times faster ( and the frequency response looks quite lattice-ish):
streamin in;
streamout out;
streamin res1;
streamin res2;
streamin res3;
streamin res4;
streamin res5;
streamin res6;
streamin res7;
streamin res8;
streamin res9;
streamin res10;
float u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10;
float x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x9;
u10 = in;
u9 = u10 - (res10 * x9);
u8 = u9 - (res9 * x8);
u7 = u8 - (res8 * x7);
u6 = u7 - (res7 * x6);
u5 = u6 - (res6 * x5);
u4 = u5 - (res5 * x4);
u3 = u4 - (res4 * x3);
u2 = u3 - (res3 * x2);
u1 = u2 - (res2 * x1);
u0 = u1 - (res1 * x0);
x9 = x8 + (res9 * u8);
x8 = x7 + (res8 * u7);
x7 = x6 + (res7 * u6);
x6 = x5 + (res6 * u5);
x5 = x4 + (res5 * u4);
x4 = x3 + (res4 * u3);
x3 = x2 + (res3 * u2);
x2 = x1 + (res2 * u1);
x1 = x0 + (res1 * u0);
x0 = u0;
out = u0;
BTW: there are differences to the C-code (scaling down / 32768), but I guess this is by intention.
tobiah · 8 Oct 2007
Thank you rl.
Now it works as it should. And if it is as you say ten times faster, my CPU will love you.