Logo Search packages:      
Sourcecode: csound version File versions  Download package

OnePole.cpp

/***************************************************/
/*! \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.

    by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
*/
/***************************************************/

#include "OnePole.h"

00017 OnePole :: OnePole() : Filter()
{
  std::vector<StkFloat> b(1, 0.1);
  std::vector<StkFloat> a(2, 1.0);
  a[1] = -0.9;
  Filter::setCoefficients( b, a );
}

00025 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 );
}

00040 OnePole :: ~OnePole()    
{
}

00044 void OnePole :: clear(void)
{
  Filter::clear();
}

00049 void OnePole :: setB0(StkFloat b0)
{
  b_[0] = b0;
}

00054 void OnePole :: setA1(StkFloat a1)
{
  a_[1] = a1;
}

00059 void OnePole :: setPole(StkFloat thePole)
{
  // Normalize coefficients for peak unity gain.
  if (thePole > 0.0)
    b_[0] = (StkFloat) (1.0 - thePole);
  else
    b_[0] = (StkFloat) (1.0 + thePole);

  a_[1] = -thePole;
}

00070 void OnePole :: setGain(StkFloat gain)
{
  Filter::setGain(gain);
}

00075 StkFloat OnePole :: getGain(void) const
{
  return Filter::getGain();
}

00080 StkFloat OnePole :: lastOut(void) const
{
  return Filter::lastOut();
}

00085 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];
}

00094 StkFrames& OnePole :: tick( StkFrames& frames, unsigned int channel )
{
  return Filter::tick( frames, channel );
}

Generated by  Doxygen 1.6.0   Back to index