mirror of
https://github.com/thestk/stk
synced 2026-01-16 06:21:51 +00:00
Version 4.4.0
This commit is contained in:
committed by
Stephen Sinclair
parent
d199342e86
commit
eccd8c9981
@@ -2,64 +2,36 @@
|
||||
/*! \class OnePole
|
||||
\brief STK one-pole filter class.
|
||||
|
||||
This protected Filter subclass implements
|
||||
a one-pole digital filter. A method is
|
||||
provided for setting the pole position along
|
||||
the real axis of the z-plane while maintaining
|
||||
a constant peak filter gain.
|
||||
This class implements a one-pole digital filter. A method is
|
||||
provided for setting the pole position along the real axis of the
|
||||
z-plane while maintaining a constant peak filter gain.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
#include "OnePole.h"
|
||||
|
||||
OnePole :: OnePole() : Filter()
|
||||
namespace stk {
|
||||
|
||||
OnePole :: OnePole( StkFloat thePole )
|
||||
{
|
||||
std::vector<StkFloat> b(1, 0.1);
|
||||
std::vector<StkFloat> a(2, 1.0);
|
||||
a[1] = -0.9;
|
||||
Filter::setCoefficients( b, a );
|
||||
}
|
||||
b_.resize( 1 );
|
||||
a_.resize( 2 );
|
||||
inputs_.resize( 1, 1, 0.0 );
|
||||
outputs_.resize( 2, 1, 0.0 );
|
||||
|
||||
OnePole :: OnePole(StkFloat thePole) : Filter()
|
||||
{
|
||||
std::vector<StkFloat> b(1);
|
||||
std::vector<StkFloat> a(2, 1.0);
|
||||
a[1] = -thePole;
|
||||
|
||||
// Normalize coefficients for peak unity gain.
|
||||
if (thePole > 0.0)
|
||||
b[0] = (StkFloat) (1.0 - thePole);
|
||||
else
|
||||
b[0] = (StkFloat) (1.0 + thePole);
|
||||
|
||||
Filter::setCoefficients( b, a );
|
||||
this->setPole( thePole );
|
||||
}
|
||||
|
||||
OnePole :: ~OnePole()
|
||||
{
|
||||
}
|
||||
|
||||
void OnePole :: clear(void)
|
||||
{
|
||||
Filter::clear();
|
||||
}
|
||||
|
||||
void OnePole :: setB0(StkFloat b0)
|
||||
{
|
||||
b_[0] = b0;
|
||||
}
|
||||
|
||||
void OnePole :: setA1(StkFloat a1)
|
||||
{
|
||||
a_[1] = a1;
|
||||
}
|
||||
|
||||
void OnePole :: setPole(StkFloat thePole)
|
||||
void OnePole :: setPole( StkFloat thePole )
|
||||
{
|
||||
// Normalize coefficients for peak unity gain.
|
||||
if (thePole > 0.0)
|
||||
if ( thePole > 0.0 )
|
||||
b_[0] = (StkFloat) (1.0 - thePole);
|
||||
else
|
||||
b_[0] = (StkFloat) (1.0 + thePole);
|
||||
@@ -67,31 +39,12 @@ void OnePole :: setPole(StkFloat thePole)
|
||||
a_[1] = -thePole;
|
||||
}
|
||||
|
||||
void OnePole :: setGain(StkFloat gain)
|
||||
void OnePole :: setCoefficients( StkFloat b0, StkFloat a1, bool clearState )
|
||||
{
|
||||
Filter::setGain(gain);
|
||||
b_[0] = b0;
|
||||
a_[1] = a1;
|
||||
|
||||
if ( clearState ) this->clear();
|
||||
}
|
||||
|
||||
StkFloat OnePole :: getGain(void) const
|
||||
{
|
||||
return Filter::getGain();
|
||||
}
|
||||
|
||||
StkFloat OnePole :: lastOut(void) const
|
||||
{
|
||||
return Filter::lastOut();
|
||||
}
|
||||
|
||||
StkFloat OnePole :: tick( StkFloat input )
|
||||
{
|
||||
inputs_[0] = gain_ * input;
|
||||
outputs_[0] = b_[0] * inputs_[0] - a_[1] * outputs_[1];
|
||||
outputs_[1] = outputs_[0];
|
||||
|
||||
return outputs_[0];
|
||||
}
|
||||
|
||||
StkFrames& OnePole :: tick( StkFrames& frames, unsigned int channel )
|
||||
{
|
||||
return Filter::tick( frames, channel );
|
||||
}
|
||||
} // stk namespace
|
||||
|
||||
Reference in New Issue
Block a user