forked from psemiletov/eko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfx-filter.h
50 lines (37 loc) · 964 Bytes
/
fx-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
#ifndef FXFILTER_H
#define FXFILTER_H
/*
this code based on Martin Finke's filter tutorial,
where the filter itself based on the resonant filter
by Paul Kellett http://www.musicdsp.org/showone.php?id=29
*/
#include <cstring>
#include <cmath>
enum filter_mode {
FILTER_MODE_LOWPASS = 0,
FILTER_MODE_HIGHPASS,
FILTER_MODE_BANDPASS
};
class CFilter
{
public:
float resonance;
int mode;
float feedback_amount;
float cutoff;
float bufl0;
float bufl1;
float bufl2;
float bufl3;
float bufr0;
float bufr1;
float bufr2;
float bufr3;
CFilter();
void reset();
float process (float sample, size_t channel);
inline void set_cutoff (float v) {cutoff = v; calc_feedback_amount();};
inline void set_resonance (float v) {resonance = v; calc_feedback_amount();};
inline void calc_feedback_amount() {feedback_amount = resonance + resonance / (1.0 - cutoff);};
};
#endif // FXFILTER_H