Version 4.4.0

This commit is contained in:
Gary Scavone
2013-09-29 23:11:39 +02:00
committed by Stephen Sinclair
parent d199342e86
commit eccd8c9981
287 changed files with 11712 additions and 7676 deletions

View File

@@ -2,25 +2,25 @@
/*! \class TwoZero
\brief STK two-zero filter class.
This protected Filter subclass implements
a two-zero digital filter. A method is
provided for creating a "notch" in the
frequency response while maintaining a
constant filter gain.
This class implements a two-zero digital filter. A method is
provided for creating a "notch" in the frequency response while
maintaining a constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#include "TwoZero.h"
#include <math.h>
#include <cmath>
TwoZero :: TwoZero() : Filter()
namespace stk {
TwoZero :: TwoZero( void )
{
std::vector<StkFloat> b(3, 0.0);
b[0] = 1.0;
std::vector<StkFloat> a(1, 1.0);
Filter::setCoefficients( b, a );
b_.resize( 3, 0.0 );
inputs_.resize( 3, 1, 0.0 );
b_[0] = 1.0;
Stk::addSampleRateAlert( this );
}
@@ -37,66 +37,27 @@ void TwoZero :: sampleRateChanged( StkFloat newRate, StkFloat oldRate )
}
}
void TwoZero :: clear(void)
{
Filter::clear();
}
void TwoZero :: setB0(StkFloat b0)
void TwoZero :: setCoefficients( StkFloat b0, StkFloat b1, StkFloat b2, bool clearState )
{
b_[0] = b0;
}
void TwoZero :: setB1(StkFloat b1)
{
b_[1] = b1;
}
void TwoZero :: setB2(StkFloat b2)
{
b_[2] = b2;
if ( clearState ) this->clear();
}
void TwoZero :: setNotch(StkFloat frequency, StkFloat radius)
void TwoZero :: setNotch( StkFloat frequency, StkFloat radius )
{
b_[2] = radius * radius;
b_[1] = (StkFloat) -2.0 * radius * cos(TWO_PI * (double) frequency / Stk::sampleRate());
// Normalize the filter gain.
if (b_[1] > 0.0) // Maximum at z = 0.
b_[0] = 1.0 / (1.0+b_[1]+b_[2]);
if ( b_[1] > 0.0 ) // Maximum at z = 0.
b_[0] = 1.0 / ( 1.0 + b_[1] + b_[2] );
else // Maximum at z = -1.
b_[0] = 1.0 / (1.0-b_[1]+b_[2]);
b_[0] = 1.0 / ( 1.0 - b_[1] + b_[2] );
b_[1] *= b_[0];
b_[2] *= b_[0];
}
void TwoZero :: setGain(StkFloat gain)
{
Filter::setGain(gain);
}
StkFloat TwoZero :: getGain(void) const
{
return Filter::getGain();
}
StkFloat TwoZero :: lastOut(void) const
{
return Filter::lastOut();
}
StkFloat TwoZero :: tick( StkFloat input )
{
inputs_[0] = gain_ * input;
outputs_[0] = b_[2] * inputs_[2] + b_[1] * inputs_[1] + b_[0] * inputs_[0];
inputs_[2] = inputs_[1];
inputs_[1] = inputs_[0];
return outputs_[0];
}
StkFrames& TwoZero :: tick( StkFrames& frames, unsigned int channel )
{
return Filter::tick( frames, channel );
}
} // stk namespace