18 #define _USE_MATH_DEFINES 33 m_filterLP(m_lpa, m_lpb),
34 m_filterHP(m_hpa, m_hpb),
44 double fcNormHigh = fcHigh / srHigh;
45 double fcNormLow = fcLow / srLow;
58 cheby(highPass, fc, 0.5, 2, a, b, fgain);
61 for (
int i=0;
i<3;
i++) {
68 qDebug() <<
"AudioFilter::calculate2:" 69 <<
" highPass: " << highPass
83 void AudioFilter::cheby(
bool highPass,
double fc,
float pr,
int np,
double *a,
double *b,
float fgain)
85 double a0, a1, a2,
b1,
b2;
86 double ta[22], tb[22];
88 std::fill(a, a+22, 0.0);
89 std::fill(b, b+22, 0.0);
93 for (
int p = 1; p <= np/2; p++)
95 cheby_sub(highPass, fc, pr, np, p, a0, a1, a2, b1, b2);
98 for (
int i=0;
i<22;
i++)
104 for (
int i=2;
i<22;
i++)
106 a[
i] = a0*ta[
i] + a1*ta[
i-1] + a2*ta[
i-2];
107 b[
i] = tb[
i] - b1*tb[
i-1] - b2*tb[
i-2];
114 for (
int i=0;
i<20;
i++)
124 for (
int i=0;
i<20;
i++)
128 sa +=
i%2 == 0 ? a[
i] : -a[
i];
129 sb +=
i%2 == 0 ? b[
i] : -b[
i];
138 double gain = sa/(1.0 -sb);
141 for (
int i=0;
i<20;
i++) {
150 void AudioFilter::cheby_sub(
bool highPass,
double fc,
float pr,
int np,
int stage,
double& a0,
double& a1,
double& a2,
double&
b1,
double&
b2)
152 double rp = -
cos((
M_PI/(np*2)) + (stage-1)*(
M_PI/np));
153 double ip =
sin((
M_PI/(np*2)) + (stage-1)*(
M_PI/np));
156 double esx = 100.0 / (100.0 - pr);
157 double es =
sqrt(esx*esx -1.0);
158 double vx = (1.0/np) *
log((1.0/es) +
sqrt((1.0/(es*es)) + 1.0));
159 double kx = (1.0/np) *
log((1.0/es) +
sqrt((1.0/(es*es)) - 1.0));
160 kx = (
exp(kx) +
exp(-kx))/2.0;
161 rp = rp * ((
exp(vx) -
exp(-vx))/2.0) / kx;
162 ip = ip * ((
exp(vx) +
exp(-vx))/2.0) / kx;
164 double t = 2.0 *
tan(0.5);
165 double w = 2.0 *
M_PI * fc;
166 double m = rp*rp + ip*ip;
167 double d = 4.0 - 4.0*rp*t + m*t*t;
169 double x1 = (2.0*t*t)/d;
171 double y1 = (8.0 - 2.0*m*t*t)/d;
172 double y2 = (-4.0 - 4.0*rp*t - m*t*t)/d;
176 k = -
cos(w/2.0 + 0.5) /
cos(w/2.0 - 0.5);
178 k =
sin(0.5 - w/2.0) /
sin(0.5 + w/2.0);
181 d = 1.0 + y1*k - y2*k*k;
183 a0 = (x0 - x1*k + x2*k*k)/d;
184 a1 = (-2.0*x0*k + x1 + x1*k*k - 2.0*x2*k)/d;
185 a2 = (x0*k*k - x1*k + x2)/d;
186 b1 = (2.0*k + y1 + y1*k*k - 2.0*y2*k)/d;
187 b2 = (-(k*k) - y1*k + y2)/d;
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
Fixed< IntType, IntBits > tan(Fixed< IntType, IntBits > const &x)
Type run(const Type &sample)
static const float m_hpb[3]
void setCoeffs(const Type *a, const Type *b)
Fixed< IntType, IntBits > exp(Fixed< IntType, IntBits > const &x)
IIRFilter< float, 2 > m_filterLP
Fixed< IntType, IntBits > log(Fixed< IntType, IntBits > const &x)
Fixed< IntType, IntBits > sin(Fixed< IntType, IntBits > const &x)
IIRFilter< float, 2 > m_filterHP
Fixed< IntType, IntBits > sqrt(Fixed< IntType, IntBits > const &x)
void cheby_sub(bool highPass, double fc, float pr, int np, int stage, double &a0, double &a1, double &a2, double &b1, double &b2)
void cheby(bool highPass, double fc, float pr, int np, double *a, double *b, float fgain)
static const float m_hpa[3]
float run(const float &sample)
void calculate2(bool highPass, double fc, float *a, float *b, float fgain)
float runLP(const float &sample)
static const float m_lpb[3]
void setDecimFilters(int srHigh, int srLow, float fcHigh, float fcLow, float gain=1.0f)
static const float m_lpa[3]
float runHP(const float &sample)