1 #if !defined(__PeakEq_h)
22 float a
, w0
, q
, s
, alpha
;
23 float cosValue
, sqrtValue
;
24 float vsa
; // Very small amount (Denormal Fix)
29 PeakEq(float sampleRate
, int filterDecibel
)
31 this->sampleRate
= sampleRate
;
32 this->filterDecibel
= filterDecibel
;
40 q
= dBgain
= freq
= 0.0f
;
43 vsa
= (1.0f
/4294967295.0f
); // Very small amount (Denormal Fix)
46 // gain [0..1], q[0..1], freq[0..44100]
47 inline void tick(float *inSample
, float freq
, float q
, float gain
)
49 gain
= filterDecibel
- (1.0f
- gain
) * filterDecibel
* 2.0f
;
50 calcCoefficients(freq
, q
, gain
);
52 outSample
= b0
*x0
+ b1
*x1
+ b2
*x2
- a1
*y1
- a2
*y2
;
53 outSample
= b0
*x0
+ b1
*x1
+ b2
*x2
- a1
*y1
- a2
*y2
;
54 updateHistory(*inSample
, outSample
);
55 *inSample
= outSample
;
58 inline void calcCoefficients(float freq
, float q
, float dBgain
)
60 if (this->q
!= q
|| this->dBgain
!= dBgain
|| this->freq
!= freq
)
62 this->dBgain
= dBgain
;
65 w0
= 2.0f
* 3.141592653589793f
* freq
/ sampleRate
;
66 a
= sqrtf(pow(10, dBgain
/20.0f
));
67 alpha
= sinf(w0
)*sinhf( logf(2.0f
)/2.0f
* q
* w0
/sinf(w0
));
68 // q = 1.0f / sqrt((a + 1.0f/a)*(1.0f/s - 1.0f) + 2.0f);
74 b0
= 1.0f
+ alpha
* a
;
75 b1
= -2.0f
* cosValue
;
76 b2
= 1.0f
- alpha
* a
;
77 a0
= 1.0f
+ alpha
/ a
;
78 a1
= -2.0f
* cosValue
;
79 a2
= 1.0f
- alpha
/ a
;
90 inline void updateHistory(float inSample
, float outSample
)
92 x0
= saturate(x1
, -0.05f
);
93 x1
= saturate(x2
, 0.04f
);
100 inline float saturate(float x
, float variation
)
102 return x
- 0.002f
* (x
+ variation
) * x
* x
;