aboutsummaryrefslogtreecommitdiff
path: root/dfx-library/IIRfilter.cpp
diff options
context:
space:
mode:
authorN.N. <martin_pi@users.sourceforge.net>2003-02-17 14:12:16 +0000
committerN.N. <martin_pi@users.sourceforge.net>2003-02-17 14:12:16 +0000
commite7b24dd7da9de84e218f7d7be623f0cf8b9d1b9c (patch)
treed6f37e159464589e9c5c3dea8b38e4d03631794c /dfx-library/IIRfilter.cpp
This commit was generated by cvs2svn to compensate for changes in r415,svn2git-root
which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/dfx/; revision=416
Diffstat (limited to 'dfx-library/IIRfilter.cpp')
-rwxr-xr-xdfx-library/IIRfilter.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/dfx-library/IIRfilter.cpp b/dfx-library/IIRfilter.cpp
new file mode 100755
index 0000000..d78bf2f
--- /dev/null
+++ b/dfx-library/IIRfilter.cpp
@@ -0,0 +1,61 @@
+#ifndef __IIRfilter
+#include "IIRfilter.h"
+#endif
+
+#include <math.h>
+
+
+//------------------------------------------------------------------------
+IIRfilter::IIRfilter()
+{
+ reset();
+}
+
+//------------------------------------------------------------------------
+IIRfilter::~IIRfilter() { }
+
+//------------------------------------------------------------------------
+void IIRfilter::calculateLowpassCoefficients(float cutoff, float samplerate)
+{
+ float twoPiFreqDivSR, cosTwoPiFreqDivSR, Q, slopeFactor, coeffScalar;
+
+ Q = 0.5f;
+ twoPiFreqDivSR = 2.0f * PI * cutoff / samplerate; // ¹ ... 0
+ cosTwoPiFreqDivSR = cosf(twoPiFreqDivSR); // 1 ... -1
+ slopeFactor = sinf(twoPiFreqDivSR) / (Q * 2.0f); // 0 ... 1 ... 0
+ coeffScalar = 1.0f / (1.0f + slopeFactor); // 1 ... 0.5 ... 1
+
+ // calculate filter coefficients
+ pInCoeff = (1.0f - cosTwoPiFreqDivSR) * coeffScalar; // 0 ... 2
+ inCoeff = ppInCoeff = pInCoeff * 0.5f; // 0 ... 1
+ pOutCoeff = (-2.0f * cosTwoPiFreqDivSR) * coeffScalar; // -2 ... 2
+ ppOutCoeff = (1.0f - slopeFactor) * coeffScalar; // 1 ... 0 ... 1
+}
+
+//------------------------------------------------------------------------
+void IIRfilter::calculateHighpassCoefficients(float cutoff, float samplerate)
+{
+ float twoPiFreqDivSR, cosTwoPiFreqDivSR, Q, slopeFactor, coeffScalar;
+
+ Q = 0.5f;
+ twoPiFreqDivSR = 2.0f * PI * cutoff / samplerate; // ¹ ... 0
+ cosTwoPiFreqDivSR = cosf(twoPiFreqDivSR); // 1 ... -1
+ slopeFactor = sinf(twoPiFreqDivSR) / (Q * 2.0f); // 0 ... 1 ... 0
+ coeffScalar = 1.0f / (1.0f + slopeFactor); // 1 ... 0.5 ... 1
+
+ // calculate filter coefficients
+ pInCoeff = (-1.0f - cosTwoPiFreqDivSR) * coeffScalar; // 2 ... 0
+ inCoeff = ppInCoeff = pInCoeff * (-0.5f); // -1 ... 0
+ pOutCoeff = (-2.0f * cosTwoPiFreqDivSR) * coeffScalar; // -2 ... 2
+ ppOutCoeff = (1.0f - slopeFactor) * coeffScalar; // 1 ... 0 ... 1
+}
+
+//------------------------------------------------------------------------
+void IIRfilter::copyCoefficients(IIRfilter *source)
+{
+ pOutCoeff = source->pOutCoeff;
+ ppOutCoeff = source->ppOutCoeff;
+ pInCoeff = source->pInCoeff;
+ ppInCoeff = source->ppInCoeff;
+ inCoeff = source->inCoeff;
+}