]> git.sesse.net Git - c64tapwav/blob - filter.cpp
Split the filter code into a class.
[c64tapwav] / filter.cpp
1 #include <math.h>
2
3 #include "filter.h"
4
5 void Filter::reset()
6 {
7         d0 = d1 = 0.0f;
8 }
9
10 Filter Filter::lpf(float cutoff_radians)
11 {
12         float resonance = 1.0f / sqrt(2.0f);
13         float sn = sin(cutoff_radians), cs = cos(cutoff_radians);
14         float alpha = float(sn / (2 * resonance));
15
16         // coefficients for lowpass filter
17         float a0 = 1 + alpha;
18         float b0 = (1 - cs) * 0.5f;
19         float b1 = 1 - cs;
20         float b2 = b0;
21         float a1 = -2 * cs;
22         float a2 = 1 - alpha;
23
24         return Filter(a0, a1, a2, b0, b1, b2);
25 }