mirror of
https://github.com/thestk/stk
synced 2026-01-14 13:31:53 +00:00
Version 4.4.0
This commit is contained in:
committed by
Stephen Sinclair
parent
d199342e86
commit
eccd8c9981
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user