Allolib  1.0
C++ Components For Interactive Multimedia
al_Biquad.hpp
1 // Created by Ryan McGee on 5/8/15.
2 //
3 //
4 
5 #ifndef __AL_BIQUAD__
6 #define __AL_BIQUAD__
7 
8 namespace al {
9 
10 /* this holds the data required to update samples thru a filter */
11 typedef struct {
12  double a0, a1, a2, a3, a4;
13  double x1, x2, y1, y2;
14 } BiquadData;
15 
16 /* filter types */
17 enum BIQUADTYPE {
18  BIQUAD_LPF, /* low pass filter */
19  BIQUAD_HPF, /* High pass filter */
20  BIQUAD_BPF, /* band pass filter */
21  BIQUAD_NOTCH, /* Notch Filter */
22  BIQUAD_PEQ, /* Peaking band EQ filter */
23  BIQUAD_LSH, /* Low shelf filter */
24  BIQUAD_HSH /* High shelf filter */
25 };
26 
31 class BiQuad {
32  public:
33  BiQuad(BIQUADTYPE _type = BIQUAD_LPF, double _sampleRate = 44100);
34  ~BiQuad();
35 
36  void set(double freq, double bandwidth = 1.9, double dbGain = 0);
37  void setSampleRate(double _rate) { mSampleRate = _rate; }
38  void processBuffer(float *buffer, int count);
39  double operator()(double sample);
40 
41  void enable(bool on) { enabled = on; }
42 
43  private:
44  BIQUADTYPE mType;
45  BiquadData mBD;
46  double mSampleRate;
47  bool enabled;
48 };
49 
55 class BiQuadNX {
56  public:
57  BiQuadNX(int _numFilters = 8, BIQUADTYPE _type = BIQUAD_LPF,
58  double _sampleRate = 44100);
59  ~BiQuadNX();
60 
61  void set(double freq, double bandwidth = 0.26, double dbGain = 0);
62  void setSampleRate(double _rate);
63  void processBuffer(float *buffer, int count);
64  double operator()(double sample);
65  void enable(bool on);
66 
67  private:
68  int numFilters;
69  BiQuad *mFilters;
70 };
71 
72 } // namespace al
73 
74 #endif /* defined(__AL_BIQUAD__) */
The BiQuad class.
Definition: al_Biquad.hpp:31
Definition: al_App.hpp:23