I´ve the same problem, but without using "static" variables.
I wanted to program a simple EQ to improve my C++, DSP and WDL skills. I build a class and a new file for a parametric EQ.
I think the class is the problem, but I´ve no clue how to fix it. Everything works very good as long as I don´t open a second instance.
I change the parameters of the EQ-object in the "void project::OnParamChange(int paramIdx)" function and it works very good.
Has someone a solution for my problem?
clEQ.h
Code:
class clParametric
{
private:
int n;
double pi;
double A;
double x[3];
double y[3];
double w0;
double alpha;
double b0;
double b1;
double b2;
double a0;
double a1;
double a2;
public:
double dBGain; // Cut or Boost in dB
double Fs; // SampleRate
double Q; // Q
double f0; // Frequency
void Initialize();
double Process(double SampleIn);
};
clEQ.cpp
Code:
// Calculate the EQ parameter
void clParametric::Initialize()
{
pi = (2*acos(0.0));
n = 2; // xxx weis nicht ob das geil ist
A = pow (10., dBGain/40.);
w0 = 2.*pi*f0/Fs;
alpha = sin(w0)/(2*Q);
b0 = 1 + alpha * A;
b1 = -2 * cos(w0);
b2 = 1 - alpha * A;
a0 = 1 + alpha / A;
a1 = -2 * cos(w0);
a2 = 1 - alpha /A;
}
double clParametric::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];
}
project.cpp
Code:
// Build a new object
clParametric EQ_parametric;
// processing
for (int s=0; s<nFrames; s++)
{
out1[s] = EQ_parametric.Process(in1[s]);
}