1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

IIR filter optimisation.

This commit is contained in:
jules 2013-01-17 16:03:26 +00:00
parent dbd83d85f7
commit ec2ec517f3
2 changed files with 10 additions and 28 deletions

View file

@ -31,17 +31,15 @@
//==============================================================================
IIRFilter::IIRFilter()
: active (false)
: active (false), v1 (0), v2 (0)
{
reset();
}
IIRFilter::IIRFilter (const IIRFilter& other)
: active (other.active)
: active (other.active), v1 (0), v2 (0)
{
const ScopedLock sl (other.processLock);
memcpy (coefficients, other.coefficients, sizeof (coefficients));
reset();
}
IIRFilter::~IIRFilter()
@ -52,27 +50,17 @@ IIRFilter::~IIRFilter()
void IIRFilter::reset() noexcept
{
const ScopedLock sl (processLock);
x1 = 0;
x2 = 0;
y1 = 0;
y2 = 0;
v1 = v2 = 0;
}
float IIRFilter::processSingleSampleRaw (const float in) noexcept
{
float out = coefficients[0] * in
+ coefficients[1] * x1
+ coefficients[2] * x2
- coefficients[4] * y1
- coefficients[5] * y2;
float out = coefficients[0] * in + v1;
JUCE_SNAP_TO_ZERO (out);
x2 = x1;
x1 = in;
y2 = y1;
y1 = out;
v1 = coefficients[1] * in - coefficients[4] * out + v2;
v2 = coefficients[2] * in - coefficients[5] * out;
return out;
}
@ -88,18 +76,12 @@ void IIRFilter::processSamples (float* const samples,
{
const float in = samples[i];
float out = coefficients[0] * in
+ coefficients[1] * x1
+ coefficients[2] * x2
- coefficients[4] * y1
- coefficients[5] * y2;
float out = coefficients[0] * in + v1;
JUCE_SNAP_TO_ZERO (out);
x2 = x1;
x1 = in;
y2 = y1;
y1 = out;
v1 = coefficients[1] * in - coefficients[4] * out + v2;
v2 = coefficients[2] * in - coefficients[5] * out;
samples[i] = out;
}

View file

@ -138,7 +138,7 @@ protected:
bool active;
float coefficients[6];
float x1, x2, y1, y2;
float v1, v2;
// (use the copyCoefficientsFrom() method instead of this operator)
IIRFilter& operator= (const IIRFilter&);