-
Notifications
You must be signed in to change notification settings - Fork 0
/
Filter.ixx
60 lines (46 loc) · 1.11 KB
/
Filter.ixx
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
module;
#include <algorithm>
export module megasynth.filter;
export class Filter {
public:
enum Mode {
LOW_PASS = 0,
HIGH_PASS,
BAND_PASS,
kNumModes
};
double process(double inputValue);
inline void setCutoff(double cutoff) {
this->cutoff = cutoff;
calculateFeedbackAmount();
}
inline void setResonance(double resonance)
{
this->resonance = resonance;
calculateFeedbackAmount();
}
inline void setCutoffMod(double cutoffMod) {
this->cutoffMod = cutoffMod;
calculateFeedbackAmount();
}
inline void setFilterMode(Mode mode) { this->mode = mode; }
void reset() {
buf1 = buf2 = buf3 = buf0 = 0.0;
}
private:
double cutoff = 0.99;
double resonance = 0.0;
double cutoffMod = 0.0;
Mode mode = Mode::LOW_PASS;
double feedbackAmount = 0.0;
double buf0 = 0.0;
double buf1 = 0.0;
double buf2 = 0.0;
double buf3 = 0.0;
inline void calculateFeedbackAmount() {
feedbackAmount = resonance + resonance / (1.0 - getCalculatedCutoff());
}
inline double getCalculatedCutoff() const {
return std::clamp(cutoff + cutoffMod, 0.01, 0.99);
}
};