Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/audaspace/FX/AUD_LowpassFactory.cpp')
-rw-r--r--intern/audaspace/FX/AUD_LowpassFactory.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/intern/audaspace/FX/AUD_LowpassFactory.cpp b/intern/audaspace/FX/AUD_LowpassFactory.cpp
index dfef0f6f7c3..9244e07631b 100644
--- a/intern/audaspace/FX/AUD_LowpassFactory.cpp
+++ b/intern/audaspace/FX/AUD_LowpassFactory.cpp
@@ -24,7 +24,13 @@
*/
#include "AUD_LowpassFactory.h"
-#include "AUD_LowpassReader.h"
+#include "AUD_IIRFilterReader.h"
+
+#include <cmath>
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
AUD_LowpassFactory::AUD_LowpassFactory(AUD_IFactory* factory, float frequency,
float Q) :
@@ -36,5 +42,20 @@ AUD_LowpassFactory::AUD_LowpassFactory(AUD_IFactory* factory, float frequency,
AUD_IReader* AUD_LowpassFactory::createReader() const
{
- return new AUD_LowpassReader(getReader(), m_frequency, m_Q);
+ AUD_IReader* reader = getReader();
+
+ // calculate coefficients
+ float w0 = 2 * M_PI * m_frequency / reader->getSpecs().rate;
+ float alpha = sin(w0) / (2 * m_Q);
+ float norm = 1 + alpha;
+ float c = cos(w0);
+ std::vector<float> a, b;
+ a.push_back(1);
+ a.push_back(-2 * c / norm);
+ a.push_back((1 - alpha) / norm);
+ b.push_back((1 - c) / (2 * norm));
+ b.push_back((1 - c) / norm);
+ b.push_back(b[0]);
+
+ return new AUD_IIRFilterReader(reader, b, a);
}