Audacity 3.2.0
Biquad.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5Biquad.h
6
7Norm C
8Max Maisel
9
10***********************************************************************/
11
12#ifndef __BIQUAD_H__
13#define __BIQUAD_H__
14
15#include "MemoryX.h"
16
18struct MATH_API Biquad
19{
20 Biquad();
21 void Reset();
22 void Process(const float* pfIn, float* pfOut, int iNumSamples);
23
24 enum
25 {
27 B0=0, B1, B2,
29 A1=0, A2,
30
32 MIN_Order = 1,
33 MAX_Order = 10
34 };
35
36 inline float ProcessOne(float fIn)
37 {
38 // Biquad must use double for all calculations. Otherwise some
39 // filters may have catastrophic rounding errors!
40 double fOut = double(fIn) * fNumerCoeffs[B0] +
41 fPrevIn * fNumerCoeffs[B1] +
42 fPrevPrevIn * fNumerCoeffs[B2] -
43 fPrevOut * fDenomCoeffs[A1] -
44 fPrevPrevOut * fDenomCoeffs[A2];
45 fPrevPrevIn = fPrevIn;
46 fPrevIn = fIn;
47 fPrevPrevOut = fPrevOut;
48 fPrevOut = fOut;
49 return fOut;
50 }
51
52 double fNumerCoeffs[3]; // B0 B1 B2
53 double fDenomCoeffs[2]; // A1 A2, A0 == 1.0
54 double fPrevIn;
56 double fPrevOut;
58
60 {
63 nSubTypes
64 };
65
66 static ArrayOf<Biquad> CalcButterworthFilter(int order, double fn, double fc, int type);
67 static ArrayOf<Biquad> CalcChebyshevType1Filter(int order, double fn, double fc, double ripple, int type);
68 static ArrayOf<Biquad> CalcChebyshevType2Filter(int order, double fn, double fc, double ripple, int type);
69
70 static void ComplexDiv (double fNumerR, double fNumerI, double fDenomR, double fDenomI,
71 double* pfQuotientR, double* pfQuotientI);
72 static bool BilinTransform (double fSX, double fSY, double* pfZX, double* pfZY);
73 static float Calc2D_DistSqr (double fX1, double fY1, double fX2, double fY2);
74
75 static const double s_fChebyCoeffs[MAX_Order][MAX_Order + 1];
76 static double ChebyPoly(int Order, double NormFreq);
77};
78
79#endif
static const auto fn
Represents a biquad digital filter.
Definition: Biquad.h:19
float ProcessOne(float fIn)
Definition: Biquad.h:36
double fPrevOut
Definition: Biquad.h:56
double fPrevIn
Definition: Biquad.h:54
double fPrevPrevIn
Definition: Biquad.h:55
kSubTypes
Definition: Biquad.h:60
@ kLowPass
Definition: Biquad.h:61
@ kHighPass
Definition: Biquad.h:62
double fPrevPrevOut
Definition: Biquad.h:57