Hi,
Just learning JUCE and I want to implement a simple LPF filter as a test.
The approach is ‘sample by sample’, though I’m sure built in classes for full buffer already exists.
In Max/MSP or the like I could code the filter in a simple iterative way, as so:
//coefficient
a = 0.986; //A good coefficient value for LPF
//Function
y = (1 - a) * x + a * yn;
yn = y;
x is the ‘monofied’ input and y is the expected output.
I’ve tried this in JUCE and it failed:
float** channelDatas = buffer.getArrayOfWritePointers();
for (int i = 0; i<buffer.getNumSamples(); ++i)
{
//Define x as the current sample value
float x = 0.5f * (channelDatas[0][i] + channelDatas[1][i]);
//a is the single coefficient
float a = 0.986995;
//Function
float y = (1 - a) * x + a * yn;
//output
channelDatas[0][i] = y;
channelDatas[1][i] = y;
//iterate
float yn = y;
}
I think I’m not initializing y and yn correctly. Any comments please ?