Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# TwoZero.h

    00001 #ifndef STK_TWOZERO_H
    00002 #define STK_TWOZERO_H
    00003
    00004 #include "Filter.h"
    00005
    00006 namespace stk {
    00007
    00008 /***************************************************/
    00018 /***************************************************/
    00019
    00020 class TwoZero : public Filter
    00021 {
    00022  public:
    00024   TwoZero();
    00025
    00027   ~TwoZero();
    00028
    00030   void ignoreSampleRateChange( bool ignore = true ) { ignoreSampleRateChange_ = ignore; };
    00031
    00033   void setB0( StkFloat b0 ) { b_[0] = b0; };
    00034
    00036   void setB1( StkFloat b1 ) { b_[1] = b1; };
    00037
    00039   void setB2( StkFloat b2 ) { b_[2] = b2; };
    00040
    00042   void setCoefficients( StkFloat b0, StkFloat b1, StkFloat b2, bool clearState = false );
    00043
    00045
    00055   void setNotch( StkFloat frequency, StkFloat radius );
    00056
    00058   StkFloat lastOut( void ) const { return lastFrame_[0]; };
    00059
    00061   StkFloat tick( StkFloat input );
    00062
    00064
    00072   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00073
    00075
    00083   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00084
    00085  protected:
    00086
    00087   void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
    00088 };
    00089
    00090 inline StkFloat TwoZero :: tick( StkFloat input )
    00091 {
    00092   inputs_[0] = gain_ * input;
    00093   lastFrame_[0] = b_[2] * inputs_[2] + b_[1] * inputs_[1] + b_[0] * inputs_[0];
    00094   inputs_[2] = inputs_[1];
    00095   inputs_[1] = inputs_[0];
    00096
    00097   return lastFrame_[0];
    00098 }
    00099
    00100 inline StkFrames& TwoZero :: tick( StkFrames& frames, unsigned int channel )
    00101 {
    00102 #if defined(_STK_DEBUG_)
    00103   if ( channel >= frames.channels() ) {
    00104     errorString_ << "TwoZero::tick(): channel and StkFrames arguments are incompatible!";
    00105     handleError( StkError::FUNCTION_ARGUMENT );
    00106   }
    00107 #endif
    00108
    00109   StkFloat *samples = &frames[channel];
    00110   unsigned int hop = frames.channels();
    00111   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00112     inputs_[0] = gain_ * *samples;
    00113     *samples = b_[2] * inputs_[2] + b_[1] * inputs_[1] + b_[0] * inputs_[0];
    00114     inputs_[2] = inputs_[1];
    00115     inputs_[1] = inputs_[0];
    00116   }
    00117
    00118   lastFrame_[0] = *(samples-hop);
    00119   return frames;
    00120 }
    00121
    00122 inline StkFrames& TwoZero :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
    00123 {
    00124 #if defined(_STK_DEBUG_)
    00125   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
    00126     errorString_ << "TwoZero::tick(): channel and StkFrames arguments are incompatible!";
    00127     handleError( StkError::FUNCTION_ARGUMENT );
    00128   }
    00129 #endif
    00130
    00131   StkFloat *iSamples = &iFrames[iChannel];
    00132   StkFloat *oSamples = &oFrames[oChannel];
    00133   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
    00134   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
    00135     inputs_[0] = gain_ * *iSamples;
    00136     *oSamples = b_[2] * inputs_[2] + b_[1] * inputs_[1] + b_[0] * inputs_[0];
    00137     inputs_[2] = inputs_[1];
    00138     inputs_[1] = inputs_[0];
    00139   }
    00140
    00141   lastFrame_[0] = *(oSamples-oHop);
    00142   return iFrames;
    00143 }
    00144
    00145 } // stk namespace
    00146
    00147 #endif

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