comparison projects/d-box/Biquad.h @ 0:8a575ba3ab52

Initial commit.
author andrewm
date Fri, 31 Oct 2014 19:10:17 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8a575ba3ab52
1 //
2 // Biquad.h
3 //
4 // Created by Nigel Redmon on 11/24/12
5 // EarLevel Engineering: earlevel.com
6 // Copyright 2012 Nigel Redmon
7 //
8 // For a complete explanation of the Biquad code:
9 // http://www.earlevel.com/main/2012/11/25/biquad-c-source-code/
10 //
11 // License:
12 //
13 // This source code is provided as is, without warranty.
14 // You may copy and distribute verbatim copies of this document.
15 // You may modify and use this source code to create binary code
16 // for your own purposes, free or commercial.
17 //
18
19 #ifndef Biquad_h
20 #define Biquad_h
21
22 enum {
23 bq_type_lowpass = 0,
24 bq_type_highpass,
25 bq_type_bandpass,
26 bq_type_notch,
27 bq_type_peak,
28 bq_type_lowshelf,
29 bq_type_highshelf
30 };
31
32 class Biquad {
33 public:
34 Biquad();
35 Biquad(int type, double Fc, double Q, double peakGainDB);
36 ~Biquad();
37 void setType(int type);
38 void setQ(double Q);
39 void setFc(double Fc);
40 void setPeakGain(double peakGainDB);
41 void setBiquad(int type, double Fc, double Q, double peakGain);
42 float process(float in);
43
44 double getQ();
45 double getFc();
46 double getPeakGain();
47
48 double getStartingQ();
49 double getStartingFc();
50 double getStartingPeakGain();
51
52 protected:
53 void calcBiquad(void);
54
55 int type;
56 double a0, a1, a2, b1, b2;
57 double Fc, Q, peakGain;
58 double startFc, startQ, startPeakGain;
59 double z1, z2;
60 };
61
62 inline double Biquad::getQ()
63 {
64 return Q;
65 }
66
67 inline double Biquad::getFc()
68 {
69 return Fc;
70 }
71
72 inline double Biquad::getPeakGain()
73 {
74 return peakGain;
75 }
76
77 inline double Biquad::getStartingQ()
78 {
79 return startQ;
80 }
81
82 inline double Biquad::getStartingFc()
83 {
84 return startFc;
85 }
86
87 inline double Biquad::getStartingPeakGain()
88 {
89 return startPeakGain;
90 }
91
92 inline float Biquad::process(float in) {
93 double out = in * a0 + z1;
94 z1 = in * a1 + z2 - b1 * out;
95 z2 = in * a2 - b2 * out;
96 return out;
97 }
98
99 #endif // Biquad_h