0

I am now trying to implement the 2nd order Butterworth LPF in VST3.

I have tried the following methods.

  1. calculated the coefficients ( such as b0, b1, a1) on my own and implemented it the normal way.
  2. designed the same filter in faust and then implemented it natively.

Both methods meet the implementation requirements, and I can see that the specified band is cut off, but It get some noise, like record dust noise. This noise is more pronounced the lower the band to be cut off, and is barely noticeable in the higher bands above about 18 kHz.

Here is main procssing code:

int32 sampleFrames = data.numSamples;
if (sampleFrames > 0)
{
    float* input_L = data.inputs[0].channelBuffers32[0];
    float* input_R = data.inputs[0].channelBuffers32[1];
    float* output_L = data.outputs[0].channelBuffers32[0];
    float* output_R = data.outputs[0].channelBuffers32[1];

    float in_L = 0, in_R = 0;

    float y0_L = 0.f, y1_L = 0.f, y2_L = 0.f;
    float y0_R = 0.f, y1_R = 0.f, y2_R = 0.f;

    float sr = this->processSetup.sampleRate;
    float freq = fFreq1; //cut-off frequency paramater
    float pi = 3.1415926535f;

    float fSlow0 = tan(pi * freq / sr);
    float fSlow1 = 1 / fSlow0;
    float fSlow2 = 1.0f / (((fSlow1 + 1.41421354f) / fSlow0) + 1.0f);
    float fSlow3 = ((fSlow1 - 1.41421354f) / fSlow0) + 1.0f;
    float fSlow4 = 2.0f * (1.0f - (1.0f / (fSlow0 * fSlow0)));

    for (int32 sample = 0; sample < sampleFrames; sample++)
    {
        in_L = input_L[sample];
        in_R = input_R[sample];

        y0_L = (in_L)-(fSlow2 * ((fSlow3 * y2_L) + (fSlow4 * y1_L)));
        output_L[sample] = fSlow2 * (y2_L + (y0_L + (2.0f * y1_L)));
        y0_R = ((in_R)-(fSlow2 * ((fSlow3 * y2_R) + (fSlow4 * y1_R))));
        output_R[sample] = fSlow2 * (y2_R + (y0_R + (2.0f * y1_R)));
        y2_L = y1_L;
        y1_L = y0_L;
        y2_R = y1_R;
        y1_R = y0_R;
    }
}

This code is an implementation of what I designed in faust (my implementation method 2). faust can export the effects we designed directly as a vst plugin, but that plugin didn't cause any noise. The design in faust is: https://faustservicecloud.grame.fr/99BF5F7076036D0441A67B4B9F54418143C3AB18/diagram/process.svg (the link may be broken soon.)

Also, the above code is implemented as a for statement; I've also tried implementing it as a while statement like mda-examples. However, the result is the same.

Even if we don't know the specific solution, what is the main cause of this kind of noise?

  • Looks like feedback is reset every new buffer, which will introduce noise – fdcpp Nov 05 '20 at 07:32
  • @fdcpp Thank you for the advice. So, I have to initialize the feedback (such as y0_L, y1_R) with the initialize function or with setupProcessing function instead of initializing it here? – Takacie Nov 05 '20 at 07:43
  • That's right, but remember that `y0_L, y0_R, y1_L, y1_R` should have scope across both functions. Either they have global scope or are members in the same class. – fdcpp Nov 05 '20 at 08:18
  • @fdcpp The noise is no longer occurring. Thank you so much! – Takacie Nov 05 '20 at 11:10
  • I haven't contributed enough to collect this as an answer. Best practice would be to post a minimum working example of your new code. Try and write an answer that you would have like to have found when first posting this question – fdcpp Nov 05 '20 at 12:19

0 Answers0