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 
00057   void setNotch( StkFloat frequency, StkFloat radius );
00058 
00060   StkFloat lastOut( void ) const { return lastFrame_[0]; };
00061 
00063   StkFloat tick( StkFloat input );
00064 
00066 
00074   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00075 
00077 
00085   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
00086 
00087  protected:
00088 
00089   void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
00090 };
00091 
00092 inline StkFloat TwoZero :: tick( StkFloat input )
00093 {
00094   inputs_[0] = gain_ * input;
00095   lastFrame_[0] = b_[2] * inputs_[2] + b_[1] * inputs_[1] + b_[0] * inputs_[0];
00096   inputs_[2] = inputs_[1];
00097   inputs_[1] = inputs_[0];
00098 
00099   return lastFrame_[0];
00100 }
00101 
00102 inline StkFrames& TwoZero :: tick( StkFrames& frames, unsigned int channel )
00103 {
00104 #if defined(_STK_DEBUG_)
00105   if ( channel >= frames.channels() ) {
00106     oStream_ << "TwoZero::tick(): channel and StkFrames arguments are incompatible!";
00107     handleError( StkError::FUNCTION_ARGUMENT );
00108   }
00109 #endif
00110 
00111   StkFloat *samples = &frames[channel];
00112   unsigned int hop = frames.channels();
00113   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
00114     inputs_[0] = gain_ * *samples;
00115     *samples = b_[2] * inputs_[2] + b_[1] * inputs_[1] + b_[0] * inputs_[0];
00116     inputs_[2] = inputs_[1];
00117     inputs_[1] = inputs_[0];
00118   }
00119 
00120   lastFrame_[0] = *(samples-hop);
00121   return frames;
00122 }
00123 
00124 inline StkFrames& TwoZero :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
00125 {
00126 #if defined(_STK_DEBUG_)
00127   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
00128     oStream_ << "TwoZero::tick(): channel and StkFrames arguments are incompatible!";
00129     handleError( StkError::FUNCTION_ARGUMENT );
00130   }
00131 #endif
00132 
00133   StkFloat *iSamples = &iFrames[iChannel];
00134   StkFloat *oSamples = &oFrames[oChannel];
00135   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
00136   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
00137     inputs_[0] = gain_ * *iSamples;
00138     *oSamples = b_[2] * inputs_[2] + b_[1] * inputs_[1] + b_[0] * inputs_[0];
00139     inputs_[2] = inputs_[1];
00140     inputs_[1] = inputs_[0];
00141   }
00142 
00143   lastFrame_[0] = *(oSamples-oHop);
00144   return iFrames;
00145 }
00146 
00147 } // stk namespace
00148 
00149 #endif

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