/
SinglePole.sc
63 lines (48 loc) · 1.25 KB
/
SinglePole.sc
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
// one pole filter class for the client side
// useful to smooth out values
SinglePole {
var <>cutoff, <>sr, <output, <a0, <b1;
*new {|cutoff = 100, sr = 1024|
^super.newCopyArgs(cutoff, sr).init;
}
init {
output = 0; // initialize x
this.setWithCutoffFreq(cutoff);
}
compute {|input|
output = (input*a0) + (output*b1);
^output; // return the output
}
}
SinglePoleLP : SinglePole {
*new {|cutoff = 100, sr = 1024|
^super.newCopyArgs(cutoff, sr).init;
}
setWithCutoffFreq {|freq = 10|
// be mindful of the samplerate (sr)
freq = freq/sr;
b1 = exp(-2*pi*freq); // set it with frequency
a0 = 1 - b1.abs;
}
setWithTimeConstant {|time = 0.1|
// be mindful of the samplerate (sr)
b1 = exp(-1/(sr*time)); // set it with time
a0 = 1 - b1.abs;
}
}
SinglePoleHP : SinglePole {
*new {|cutoff = 100, sr = 1024|
^super.newCopyArgs(cutoff, sr).init;
}
setWithCutoffFreq {|freq = 10|
// be mindful of the samplerate (sr)
freq = freq/sr;
b1 = -1 * exp(-2*pi*(0.5-freq)); // set it with frequency
a0 = 1 + b1.abs;
}
setWithTimeConstant {|time = 0.1|
// be mindful of the samplerate (sr)
b1 = -1 * exp(-1/(sr*time)); // set it with time
a0 = 1 + b1.abs;
}
}