-
Notifications
You must be signed in to change notification settings - Fork 1
/
Filter.h
54 lines (46 loc) · 1.14 KB
/
Filter.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
#pragma once
#include <cmath>
class Filter
{
public:
enum FilterMode {
FILTER_MODE_LOWPASS = 0,
FILER_MODE_HIGHPASS,
FILTER_MODE_BANDPASS,
knumFilterModes
};
Filter() :
cutoff(0.99),
resonance(0.01),
cutoffMod(0.0),
mode(FILTER_MODE_LOWPASS),
buf0(0.0),
buf1(0.0),
buf2(0.0),
buf3(0.0){}
double process(double inputValue);
inline void setCutoff(double newCutoff) { cutoff = newCutoff; calculateFeedbackAmount(); }
inline void setResonance(double newResonance) { resonance = newResonance; calculateFeedbackAmount(); }
inline void setFilterMode(FilterMode newMode) { mode = newMode; }
inline void setCutoffMod(double newCutoffMod) {
cutoffMod = newCutoffMod;
calculateFeedbackAmount();
}
void reset() {
buf0 = buf1 = buf2 = buf3 = 0.0;
}
private:
double cutoff;
double resonance;
FilterMode mode;
double feedbackAmount;
inline void calculateFeedbackAmount() { feedbackAmount = resonance + resonance / (1.0 - getCalculatedCutoff()); }
double buf0;
double buf1;
double buf2;
double buf3;
double cutoffMod;
inline double getCalculatedCutoff() const {
return fmax(fmin(cutoff + cutoffMod, 0.99), .01);
};
};