Plotting RBJ Audio-EQ-Cookbook HPF/LPF
RBJ Audio-EQ-Cookbook
plotting in Excel worksheet version
type | |
|
Fs | 44100 Hz | |
f0 | 1000 Hz | |
Q | 5 | |
Sample Source Code
UI Callback
ftype = LPF;
f0 = 1000;
Q = 5;
filterL.setParameter(ftype, f0, Q);
filterR.setParameter(ftype, f0, Q);
Filter Parameter Setup Function
void CFilter::setParameter(int ftype, float f0, float Q)
{
float omega, sn, cs, alpha;
float a0, a1, a2, b0, b1, b2;
omega = 2.f * PI * f0 / 44100.f;
sn = sin(omega);
cs = cos(omega);
alpha = sn / (2.f * Q);
if (ftype == LPF) {
// LPF
b0 = (1.f - cs) / 2.f;
b1 = 1.f - cs;
b2 = (1.f - cs) / 2.f;
a0 = 1.f + alpha;
a1 = -2.f * cs;
a2 = 1.f - alpha;
} else {
// HPF
b0 = (1.f + cs) / 2.f;
b1 = -(1.f + cs);
b2 = (1.f + cs) / 2.f;
a0 = 1.f + alpha;
a1 = -2.f * cs;
a2 = 1.f - alpha;
}
b0a0 = b0 /a0;
b1a0 = b1 /a0;
b2a0 = b2 /a0;
a1a0 = a1 /a0;
a2a0 = a2 /a0;
x1 = x2 = 0;
y1 = y2 = 0;
}
Filtering Function
float CFilter::filter(float sample)
{
float result = b0a0 * sample + b1a0 * x1 + b2a0 * x2 - a1a0 * y1 - a2a0 * y2;
x2 = x1;
x1 = sample;
y2 = y1;
y1 = result;
return result;
}
Signal Processing
void MyApp::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames)
{
float* inL = inputs[0];
float* inR = inputs[1];
float* outL = outputs[0];
float* outR = outputs[1];
for (VstInt32 i = 0; i < sampleFrames; i++) {
*outL++ = filterL.filter(*inL++);
*outR++ = filterR.filter(*inR++);
}
}