Sorry, you are right. Code might be the thing to solve the problem.
First my EQ Class. I know that this is not the best way of writing classes, but I am still learning C++ ... Itīs not trivial for a sound engineer.
clEQ.h
Code:
class HiShelvClass
{
private:
int n;
double pi;
double A;
double x[3];
double y[3];
double w0;
double alpha;
double a0;
double a1;
double a2;
double b0;
double b1;
double b2;
public:
double dBGain; // Cut or Boost in dB
double Fs; // Samplefrequency
double f0; // Frequency
double S; // Slope
void Calc(); // Calculation
double Process(double SamplesIn);
};
clEQ.cpp
Code:
#include "clEQ.h"
#include <math.h>
using namespace std;
void HiShelvClass::Calc() // Calculation for the Process function
{
pi = (2*acos(0.0));
n = 2;
A = pow (10., dBGain/40.);
w0 = 2.*pi*f0/Fs;
alpha = sin(w0)/2 *sqrt( (A + 1/A)*(1/S - 1) + 2 );
b0 = A*( (A+1) + (A-1)*cos(w0) + 2*sqrt(A)*alpha );
b1 = -2*A*( (A-1) + (A+1)*cos(w0) );
b2 = A*( (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha );
a0 = (A+1) - (A-1)*cos(w0) + 2*sqrt(A)*alpha;
a1 = 2*( (A-1) - (A+1)*cos(w0) );
a2 = (A+1) - (A-1)*cos(w0) - 2*sqrt(A)*alpha;
}
double HiShelvClass::Process(double SamplesIn)
{
n= 2;
x[n-2] = x[n-1]; x[n-1] = x[n];
x[n]= SamplesIn;
y[n-2] = y[n-1]; y[n-1] = y[n];
y[n] = (b0/a0)*x[n] + (b1/a0)*x[n-1] + (b2/a0)*x[n-2]- (a1/a0)*y[n-1] - (a2/a0)*y[n-2];
return y[n];
}
I create a HiShelvClass object in in my plugin header file:
Code:
….
private:
double mEQGain;
double mEQFrequency;
double mEQOffset;
double mEQSlope;
HiShelvClass Hi_Shelv_EQ; // Creating the EQ object
};
Then I update all the EQ parameters in switch (paramIdx)
Code:
switch (paramIdx)
{
case kEQGain:
mEQGain = GetParam(kEQGain)->Value();;
Hi_Shelv_EQ.dBGain = mEQGain;
Hi_Shelv_EQ.Calc();
break;
mEQFrequency = GetParam(mEQFrequency)->Value();;
Hi_Shelv_EQ.f0 = mEQFrequency;
Hi_Shelv_EQ.Calc();
break;
etc.
ProcessDoubleReplacing
Code:
for (int s = 0; s < nFrames; s++)
{
out1[s] = Hi_Shelv_EQ.Process(in1[s]);
}
Sometimes everything works as expected and sometimes I can hear no signal. Sometimes it happens when I reopen the project and sometimes when I use the first instance of the plugin. Multiple instances are not the problem I think.
I donīt know if the eq process function is the right one. I am not shure where I found these code. Because I was not able to translate everything from EQCookBook into proper c++ code.
Code:
double HiShelvClass::Process(double SamplesIn)
{
n= 2;
x[n-2] = x[n-1]; x[n-1] = x[n];
x[n]= SamplesIn;
y[n-2] = y[n-1]; y[n-1] = y[n];
y[n] = (b0/a0)*x[n] + (b1/a0)*x[n-1] + (b2/a0)*x[n-2]- (a1/a0)*y[n-1] - (a2/a0)*y[n-2];
return y[n];
}