-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLowPass.h
53 lines (45 loc) · 990 Bytes
/
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
#ifndef LowPass_h
#define LowPass_h
#include <Arduino.h>
#include "Num.h"
using namespace Fixie;
/*
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
*/
IRAM_ATTR class LowPass {
public:
LowPass() {
}
~LowPass(void) {
}
void SetParameters(Num f, Num q)
{
if(f==Num(1))
{
f = Num(0.999);
}
this->f = f;
this->q = q;
fb = q + q/(Num(1) - f);
}
Num Process(Num in)
{
buf0 = buf0 + f * (in - buf0 + fb * (buf0 - buf1));
buf1 = buf1 + f * (buf0 - buf1);
return buf1;
}
protected:
Num q;
Num f;
Num fb;
Num buf0;
Num buf1;
};
#endif