rendered paste body#include <math.h>
#include "Biquad.h"
#define M_PI 3.1415926535897932384626433832795f
//----------------------------------------------------------
Biquad::Biquad(long mode, float freq, float q, float fs)
{
// Allocate sample buffers
x1 = 0.f;
x2 = 0.f;
y1 = 0.f;
y2 = 0.f;
// Initial filter attributes
this->mode = mode;
this->freq = freq;
this->q = q;
this->fs = fs;
coefs();
}
//----------------------------------------------------------
void Biquad::setFreq(float freq)
{
this->freq = freq;
coefs();
}
//----------------------------------------------------------
void Biquad::setQ(float q)
{
this->q = q;
coefs();
}
//----------------------------------------------------------
void Biquad::setMode(long mode)
{
this->mode = mode;
coefs();
}
//----------------------------------------------------------
void Biquad::setFs(float fs)
{
this->fs = fs;
coefs();
}
//----------------------------------------------------------
void Biquad::process(float* input, float* output)
{
// Calculate filtered value
output = b0 * input + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
// Shift sample history
x2 = x1;
x1 = input;
y2 = y1;
y1 = output;
}
//----------------------------------------------------------
void Biquad::coefs()
{
// Precalculate some stuff
float w0 = freq / fs * 2.f * M_PI;
float sin_w0 = sin(w0);
float cos_w0 = cos(w0);
float alpha = 0;
if (mode == fmodeHP || mode == fmodeLP)
{
alpha = sin_w0 / (2.f * q);
}
else if (mode == fmodeBP || mode == fmodeBS)
{
alpha = sin_w0 * sinh(log(2.f) / 2.f * q * w0 / sin_w0);
}
// Highpass
if (mode == fmodeHP)
{
b0 = (1.f + cos_w0) / 2.f;
b1 = -(1.f + cos_w0);
b2 = (1.f + cos_w0) / 2.f;
a0 = 1.f + alpha;
a1 = -2.f * cos_w0;
a2 = 1.f - alpha;
}
// Lowpass
else if (mode == fmodeLP)
{
b0 = (1.f - cos_w0) / 2.f;
b1 = 1.f - cos_w0;
b2 = (1.f - cos_w0) / 2.f;
a0 = 1.f + alpha;
a1 = -2.f * cos_w0;
a2 = 1.f - alpha;
}
// Bandpass
else if (mode == fmodeBP)
{
b0 = alpha;
b1 = 0.f;
b2 = -alpha;
a0 = 1 + alpha;
a1 = -2.f * cos_w0;
a2 = 1.f - alpha;
}
// Bandstop
else if (mode == fmodeBS)
{
b0 = 1.f;
b1 = -2.f * cos_w0;
b2 = 1.f;
a0 = 1.f + alpha;
a1 = -2.f * cos_w0;
a2 = 1.f - alpha;
}
// Flat
else if (mode == fmodeFlat)
{
b0 = 1;
b1 = 0;
b2 = 0;
a0 = 1;
a1 = 0;
a2 = 0;
}
}
********************* the error ***********************
I:\Program Files\Microsoft Visual Studio 8\VC\include\biquad.cpp(54) : error C2297: '*' : illegal, right operand has type 'float *'
I:\Program Files\Microsoft Visual Studio 8\VC\include\biquad.cpp(58) : error C2440: '=' : cannot convert from 'float *' to 'float'
There is no context in which this conversion is possible
I:\Program Files\Microsoft Visual Studio 8\VC\include\biquad.cpp(60) : error C2440: '=' : cannot convert from 'float *' to 'float'
There is no context in which this conversion is possible