1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-24 08:10:05 +02:00

More Biquad refactoring.

This commit is contained in:
Max Maisel 2018-08-06 17:04:26 +02:00
parent 064ddb5a54
commit 86ae0460c9
3 changed files with 27 additions and 34 deletions

View File

@ -18,8 +18,6 @@ Max Maisel
Biquad::Biquad() Biquad::Biquad()
{ {
pfIn = 0;
pfOut = 0;
fNumerCoeffs[B0] = 1; fNumerCoeffs[B0] = 1;
fNumerCoeffs[B1] = 0; fNumerCoeffs[B1] = 0;
fNumerCoeffs[B2] = 0; fNumerCoeffs[B2] = 0;
@ -36,7 +34,7 @@ void Biquad::Reset()
fPrevPrevOut = 0; fPrevPrevOut = 0;
} }
void Biquad::Process(int iNumSamples) void Biquad::Process(float* pfIn, float* pfOut, int iNumSamples)
{ {
for (int i = 0; i < iNumSamples; i++) for (int i = 0; i < iNumSamples; i++)
*pfOut++ = ProcessOne(*pfIn++); *pfOut++ = ProcessOne(*pfIn++);
@ -306,6 +304,26 @@ ArrayOf<Biquad> Biquad::CalcChebyshevType2Filter(int order, double fn, double fc
return std::move(pBiquad); return std::move(pBiquad);
} }
void Biquad::ComplexDiv (float fNumerR, float fNumerI, float fDenomR, float fDenomI, float* pfQuotientR, float* pfQuotientI)
{
float fDenom = square(fDenomR) + square(fDenomI);
*pfQuotientR = (fNumerR * fDenomR + fNumerI * fDenomI) / fDenom;
*pfQuotientI = (fNumerI * fDenomR - fNumerR * fDenomI) / fDenom;
}
bool Biquad::BilinTransform (float fSX, float fSY, float* pfZX, float* pfZY)
{
float fDenom = square (1 - fSX) + square (fSY);
*pfZX = (1 - square (fSX) - square (fSY)) / fDenom;
*pfZY = 2 * fSY / fDenom;
return true;
}
float Biquad::Calc2D_DistSqr (float fX1, float fY1, float fX2, float fY2)
{
return square (fX1 - fX2) + square (fY1 - fY2);
}
double Biquad::ChebyPoly(int Order, double NormFreq) // NormFreq = 1 at the f0 point (where response is R dB down) double Biquad::ChebyPoly(int Order, double NormFreq) // NormFreq = 1 at the f0 point (where response is R dB down)
{ {
// Calc cosh (Order * acosh (NormFreq)); // Calc cosh (Order * acosh (NormFreq));
@ -319,24 +337,3 @@ double Biquad::ChebyPoly(int Order, double NormFreq) // NormFreq = 1 at the f0
} }
return fSum; return fSum;
} }
void ComplexDiv (float fNumerR, float fNumerI, float fDenomR, float fDenomI, float* pfQuotientR, float* pfQuotientI)
{
float fDenom = square(fDenomR) + square(fDenomI);
*pfQuotientR = (fNumerR * fDenomR + fNumerI * fDenomI) / fDenom;
*pfQuotientI = (fNumerI * fDenomR - fNumerR * fDenomI) / fDenom;
}
bool BilinTransform (float fSX, float fSY, float* pfZX, float* pfZY)
{
float fDenom = square (1 - fSX) + square (fSY);
*pfZX = (1 - square (fSX) - square (fSY)) / fDenom;
*pfZY = 2 * fSY / fDenom;
return true;
}
float Calc2D_DistSqr (float fX1, float fY1, float fX2, float fY2)
{
return square (fX1 - fX2) + square (fY1 - fY2);
}

View File

@ -19,7 +19,7 @@ struct Biquad
{ {
Biquad(); Biquad();
void Reset(); void Reset();
void Process(int iNumSamples); void Process(float* pfIn, float* pfOut, int iNumSamples);
enum enum
{ {
@ -47,8 +47,6 @@ struct Biquad
return fOut; return fOut;
} }
float* pfIn;
float* pfOut;
float fNumerCoeffs[3]; // B0 B1 B2 float fNumerCoeffs[3]; // B0 B1 B2
float fDenomCoeffs[2]; // A1 A2, A0 == 1.0 float fDenomCoeffs[2]; // A1 A2, A0 == 1.0
float fPrevIn; float fPrevIn;
@ -67,12 +65,12 @@ struct Biquad
static ArrayOf<Biquad> CalcChebyshevType1Filter(int order, double fn, double fc, double ripple, int type); static ArrayOf<Biquad> CalcChebyshevType1Filter(int order, double fn, double fc, double ripple, int type);
static ArrayOf<Biquad> CalcChebyshevType2Filter(int order, double fn, double fc, double ripple, int type); static ArrayOf<Biquad> CalcChebyshevType2Filter(int order, double fn, double fc, double ripple, int type);
static void ComplexDiv (float fNumerR, float fNumerI, float fDenomR, float fDenomI, float* pfQuotientR, float* pfQuotientI);
static bool BilinTransform (float fSX, float fSY, float* pfZX, float* pfZY);
static float Calc2D_DistSqr (float fX1, float fY1, float fX2, float fY2);
static const double s_fChebyCoeffs[MAX_Order][MAX_Order + 1]; static const double s_fChebyCoeffs[MAX_Order][MAX_Order + 1];
static double ChebyPoly(int Order, double NormFreq); static double ChebyPoly(int Order, double NormFreq);
}; };
void ComplexDiv (float fNumerR, float fNumerI, float fDenomR, float fDenomI, float* pfQuotientR, float* pfQuotientI);
bool BilinTransform (float fSX, float fSY, float* pfZX, float* pfZY);
float Calc2D_DistSqr (float fX1, float fY1, float fX2, float fY2);
#endif #endif

View File

@ -218,9 +218,7 @@ size_t EffectScienFilter::ProcessBlock(float **inBlock, float **outBlock, size_t
float *ibuf = inBlock[0]; float *ibuf = inBlock[0];
for (int iPair = 0; iPair < (mOrder + 1) / 2; iPair++) for (int iPair = 0; iPair < (mOrder + 1) / 2; iPair++)
{ {
mpBiquad[iPair].pfIn = ibuf; mpBiquad[iPair].Process(ibuf, outBlock[0], blockLen);
mpBiquad[iPair].pfOut = outBlock[0];
mpBiquad[iPair].Process(blockLen);
ibuf = outBlock[0]; ibuf = outBlock[0];
} }