Variable with memory longer then one sample inside Gen Codebox
Hi everybody,
I'm a real beginner with MAX/MSP. Currently I use it as a prototyping playground to get a bit more used with digital audio Processing.
Right now, I'd like to generate a sort of clipping, that holds on outputting the clipped value for some more samples, after the input Signal already got back under the threshold value. This "hold"-time should be half of the time the input signal was over the threshold. To do that, I thought of something like that:
threshold = 0.6; //fixed value
samples_over=0; //initial value
if (in1>threshold){
out1=threshold;
samples_over=samples_over+1;
}
else {
if (samples_over>0){
samples_over=samples_over-2;
out1=threshold;
else {
samples_over=0;
out1=in1;
}
}
But if I noticed everything right, the code in the codebox is looped on a sample basis, so assigning 0 to "samples_over" as an initial value just resets its value with every new sample. How do I create a variable with a memory that lasts longer then one loop cycle and just gets one initial value once the signal processing got started? I'm sure this is a basic and simple task - most probably I just don't know the right keyword to google for ;)
Thank you in advance
Janos
Great, this was exactly what I was looking for! Works exactly like I expected.
I even came across the "History" object while searching for a solution to my problem but I didn't get the Idea of using it this way...