gen~ & history
Hi there,
a friend researcher at acoustic lab in Marseille & I are porting a matlab code (physical modeling) and we need some previous sample values. History is the key but we have some problem of documentation's lack for codebox version.
How can we grab n-3, n-2 & n-1 sample values using codebox only ?
Thanks for your lights :)
Hi Julian, you'll want to cascade history operators (which only use a single sample delay), or you could use Data/Delay objects if helpful. Here's the genexpr generated by the gen~.biquad.maxpat example which shows z-2 by cascading x1 to x2 (via a temporary variable x2_next_8 which you wouldn't need in your hand coded genexpr).
Let us know if you have further questions.
Param b1(0.2);
Param b2(0.2);
Param a0(0.9);
Param a1(0.1);
Param a2(0.1);
History y2(0);
History x2(0);
History x1(0);
History y1(0);
mul_1 = in1 * a0;
mul_2 = x1 * a1;
mul_3 = x2 * a2;
mul_4 = y2 * b2;
mul_5 = y1 * b1;
sub_6 = ((mul_3 + mul_2) + mul_1) - (mul_5 + mul_4);
out1 = sub_6;
y2_next_7 = y1;
x2_next_8 = x1;
x1_next_9 = in1;
y1_next_10 = sub_6;
y2 = y2_next_7;
y1 = y1_next_10;
x1 = x1_next_9;
x2 = x2_next_8;
Joshua, one more question, if you don't mind.
History keeps the value for the next turn. ok.
Using the object (delay @feedback 1 @interp none), I can have the latest 512 previous values if I use the 512 as first argument. right ?
So in that case, if I want to keep z-1, -2 ,-3, I need to keep these 3 temporary variables, right?
Is that logic, logic ..?
Something else, we tried to start to write things by using (delay) object in gen~, and then, it generated me all rows I needed:
Delay delay_1(10);
tap_2 = delay_1.read(10, interp="none");
delay_1.write(expr_5);
(I removed the other rows not because this is secret but to make things clearer)
Is there a place where I can find documentation for writing this without using first graphical objects then the generated code ?
thank you very much!