X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=filter.cpp;fp=filter.cpp;h=d8f97010f2670dd2f4566fa5153f01223640672f;hb=cec99d15ad920457eea61bc442b5ba610c13430e;hp=0000000000000000000000000000000000000000;hpb=1d431da4497326b4496cdc6596c52736d98699e7;p=c64tapwav diff --git a/filter.cpp b/filter.cpp new file mode 100644 index 0000000..d8f9701 --- /dev/null +++ b/filter.cpp @@ -0,0 +1,25 @@ +#include + +#include "filter.h" + +void Filter::reset() +{ + d0 = d1 = 0.0f; +} + +Filter Filter::lpf(float cutoff_radians) +{ + float resonance = 1.0f / sqrt(2.0f); + float sn = sin(cutoff_radians), cs = cos(cutoff_radians); + float alpha = float(sn / (2 * resonance)); + + // coefficients for lowpass filter + float a0 = 1 + alpha; + float b0 = (1 - cs) * 0.5f; + float b1 = 1 - cs; + float b2 = b0; + float a1 = -2 * cs; + float a2 = 1 - alpha; + + return Filter(a0, a1, a2, b0, b1, b2); +}