-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLowPass.h
65 lines (56 loc) · 1.07 KB
/
LowPass.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
64
65
#ifndef LowPass_h
#define LowPass_h
#include <Arduino.h>
/*
simple resonant filter posted to musicdsp.org by Paul Kellett http://www.musicdsp.org/archive.php?classid=3#259
// set feedback amount given f and q between 0 and 1
fb = q + q/(1.0 - f);
// for each sample...
buf0 = buf0 + f * (in - buf0 + fb * (buf0 - buf1));
buf1 = buf1 + f * (buf0 - buf1);
out = buf1;
Taken from mozzi
*/
class LowPass {
public:
LowPass() {
}
~LowPass(void) {
}
void SetParameters(float f, float q)
{
if(1.0-f<0.001)
{
f = 0.999;
}
this->f = f;
this->q = q;
fb = q + q/(1.0 - f);
}
float Process(float in)
{
buf0 = buf0 + f * (in - buf0 + fb * (buf0 - buf1));
buf1 = buf1 + f * (buf0 - buf1);
return buf1;
}
float GetFreq()
{
return f;
}
float GetRes()
{
return q;
}
void reset()
{
buf0 = 0;
buf1 = 0;
}
protected:
float q;
float f;
float fb;
float buf0;
float buf1;
};
#endif