Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Iir.h

    00001 #ifndef STK_IIR_H
    00002 #define STK_IIR_H
    00003
    00004 #include "Filter.h"
    00005
    00006 namespace stk {
    00007
    00008 /***************************************************/
    00032 /***************************************************/
    00033
    00034 class Iir : public Filter
    00035 {
    00036 public:
    00038   Iir( void );
    00039
    00041
    00045   Iir( std::vector<StkFloat> &bCoefficients, std::vector<StkFloat> &aCoefficients );
    00046
    00048   ~Iir( void );
    00049
    00051
    00058   void setCoefficients( std::vector<StkFloat> &bCoefficients, std::vector<StkFloat> &aCoefficients, bool clearState = false );
    00059
    00061
    00068   void setNumerator( std::vector<StkFloat> &bCoefficients, bool clearState = false );
    00069
    00071
    00080   void setDenominator( std::vector<StkFloat> &aCoefficients, bool clearState = false );
    00081
    00083   StkFloat lastOut( void ) const { return lastFrame_[0]; };
    00084
    00086   StkFloat tick( StkFloat input );
    00087
    00089
    00097   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00098
    00100
    00108   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00109
    00110 protected:
    00111
    00112 };
    00113
    00114 inline StkFloat Iir :: tick( StkFloat input )
    00115 {
    00116   unsigned int i;
    00117
    00118   outputs_[0] = 0.0;
    00119   inputs_[0] = gain_ * input;
    00120   for ( i=b_.size()-1; i>0; i-- ) {
    00121     outputs_[0] += b_[i] * inputs_[i];
    00122     inputs_[i] = inputs_[i-1];
    00123   }
    00124   outputs_[0] += b_[0] * inputs_[0];
    00125
    00126   for ( i=a_.size()-1; i>0; i-- ) {
    00127     outputs_[0] += -a_[i] * outputs_[i];
    00128     outputs_[i] = outputs_[i-1];
    00129   }
    00130
    00131   lastFrame_[0] = outputs_[0];
    00132   return lastFrame_[0];
    00133 }
    00134
    00135 inline StkFrames& Iir :: tick( StkFrames& frames, unsigned int channel )
    00136 {
    00137 #if defined(_STK_DEBUG_)
    00138   if ( channel >= frames.channels() ) {
    00139     errorString_ << "Iir::tick(): channel and StkFrames arguments are incompatible!";
    00140     handleError( StkError::FUNCTION_ARGUMENT );
    00141   }
    00142 #endif
    00143
    00144   StkFloat *samples = &frames[channel];
    00145   unsigned int i, hop = frames.channels();
    00146   for ( unsigned int j=0; j<frames.frames(); j++, samples += hop ) {
    00147     outputs_[0] = 0.0;
    00148     inputs_[0] = gain_ * *samples;
    00149     for ( i=b_.size()-1; i>0; i-- ) {
    00150       outputs_[0] += b_[i] * inputs_[i];
    00151       inputs_[i] = inputs_[i-1];
    00152     }
    00153     outputs_[0] += b_[0] * inputs_[0];
    00154
    00155     for ( i=a_.size()-1; i>0; i-- ) {
    00156       outputs_[0] += -a_[i] * outputs_[i];
    00157       outputs_[i] = outputs_[i-1];
    00158     }
    00159
    00160     *samples = outputs_[0];
    00161   }
    00162
    00163   lastFrame_[0] = *(samples-hop);
    00164   return frames;
    00165 }
    00166
    00167 inline StkFrames& Iir :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
    00168 {
    00169 #if defined(_STK_DEBUG_)
    00170   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
    00171     errorString_ << "Iir::tick(): channel and StkFrames arguments are incompatible!";
    00172     handleError( StkError::FUNCTION_ARGUMENT );
    00173   }
    00174 #endif
    00175
    00176   StkFloat *iSamples = &iFrames[iChannel];
    00177   StkFloat *oSamples = &oFrames[oChannel];
    00178   unsigned int i, iHop = iFrames.channels(), oHop = oFrames.channels();
    00179   for ( unsigned int j=0; j<iFrames.frames(); j++, iSamples += iHop, oSamples += oHop ) {
    00180     outputs_[0] = 0.0;
    00181     inputs_[0] = gain_ * *iSamples;
    00182     for ( i=b_.size()-1; i>0; i-- ) {
    00183       outputs_[0] += b_[i] * inputs_[i];
    00184       inputs_[i] = inputs_[i-1];
    00185     }
    00186     outputs_[0] += b_[0] * inputs_[0];
    00187
    00188     for ( i=a_.size()-1; i>0; i-- ) {
    00189       outputs_[0] += -a_[i] * outputs_[i];
    00190       outputs_[i] = outputs_[i-1];
    00191     }
    00192
    00193     *oSamples = outputs_[0];
    00194   }
    00195
    00196   lastFrame_[0] = *(oSamples-oHop);
    00197   return iFrames;
    00198 }
    00199
    00200 } // stk namespace
    00201
    00202 #endif

The Synthesis ToolKit in C++ (STK)
©1995-2010 Perry R. Cook and Gary P. Scavone. All Rights Reserved.