-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathBiquad.h
63 lines (55 loc) · 1.46 KB
/
Biquad.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// Biquad.h
//
// Created by Nigel Redmon on 11/24/12
// EarLevel Engineering: earlevel.com
// Copyright 2012 Nigel Redmon
//
// For a complete explanation of the Biquad code:
// http://www.earlevel.com/main/2012/11/25/biquad-c-source-code/
//
// License:
//
// This source code is provided as is, without warranty.
// You may copy and distribute verbatim copies of this document.
// You may modify and use this source code to create binary code
// for your own purposes, free or commercial.
//
// s60sc 2021 converted from double to float to use ESP32 FPU
#ifndef Biquad_h
#define Biquad_h
#include "appGlobals.h"
enum {
bq_type_lowpass = 0,
bq_type_highpass,
bq_type_bandpass,
bq_type_notch,
bq_type_peak,
bq_type_lowshelf,
bq_type_highshelf
};
class Biquad {
public:
Biquad();
Biquad(int type, float Fc, float Q, float peakGainDB);
~Biquad();
void setType(int type);
void setQ(float Q);
void setFc(float Fc);
void setPeakGain(float peakGainDB);
void setBiquad(int type, float Fc, float Q, float peakGainDB);
float process(float in);
protected:
void calcBiquad(void);
int type;
float a0, a1, a2, b1, b2;
float Fc, Q, peakGain;
float z1, z2;
};
inline float Biquad::process(float in) {
float out = in * a0 + z1;
z1 = in * a1 + z2 - b1 * out;
z2 = in * a2 - b2 * out;
return out;
}
#endif // Biquad_h