Hi,
I’m very new to DSP programming in c++ and so I thought it would be a good idea, to implement a very simple P-T1 (first order low-pass).
The formula I’ve used is the following:
y[n] = y[n-1] + ( k * x[n-1] - y[n-1] ) * dt / T
with
x: input
y: output
k: gain factor
dt: 1/SampleRate
T: 1/(2pif)
I’ve implemented this filter in the processBlock of my audio plugin (I get the frequency from a slider with values between 0 and 1000. k is between 0 and 1):
// This is the place where you'd normally do the guts of your plugin's
// audio processing...
for (int channel = 0; channel < getNumInputChannels(); ++channel)
{
float* channelData = buffer.getSampleData (channel);
float out = 0;
// ..do something to the data...
for (int i = 0; i < buffer.getNumSamples(); ++i)
{
// P_T1 lowpass:
channelData[i] = out + (k * channelData[i] - out) * 2.0 * 3.14 * (double) frequency / (double) SampleRate;
out = channelData[i];
}
}
The filter works, but there’s a very ugly crackling on the sound. The crackling is getting worse, the lower the frequency is.
Is this maybe the wrongest possible way to implement dsp stuff, or did I miss anything else?
Would be great if someone could help me.
Best,
Philipp.