Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


OneZero.h

00001 #ifndef STK_ONEZERO_H
00002 #define STK_ONEZERO_H
00003 
00004 #include "Filter.h"
00005 
00006 namespace stk {
00007 
00008 /***************************************************/
00018 /***************************************************/
00019 
00020 class OneZero : public Filter
00021 {
00022  public:
00023 
00025   OneZero( StkFloat theZero = -1.0 );
00026 
00028   ~OneZero();
00029 
00031   void setB0( StkFloat b0 ) { b_[0] = b0; };
00032 
00034   void setB1( StkFloat b1 ) { b_[1] = b1; };
00035 
00037   void setCoefficients( StkFloat b0, StkFloat b1, bool clearState = false );
00038 
00040 
00047   void setZero( StkFloat theZero );
00048 
00050   StkFloat lastOut( void ) const { return lastFrame_[0]; };
00051 
00053   StkFloat tick( StkFloat input );
00054 
00056 
00064   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00065 
00067 
00075   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
00076 
00077 };
00078 
00079 inline StkFloat OneZero :: tick( StkFloat input )
00080 {
00081   inputs_[0] = gain_ * input;
00082   lastFrame_[0] = b_[1] * inputs_[1] + b_[0] * inputs_[0];
00083   inputs_[1] = inputs_[0];
00084 
00085   return lastFrame_[0];
00086 }
00087 
00088 inline StkFrames& OneZero :: tick( StkFrames& frames, unsigned int channel )
00089 {
00090 #if defined(_STK_DEBUG_)
00091   if ( channel >= frames.channels() ) {
00092     errorString_ << "OneZero::tick(): channel and StkFrames arguments are incompatible!";
00093     handleError( StkError::FUNCTION_ARGUMENT );
00094   }
00095 #endif
00096 
00097   StkFloat *samples = &frames[channel];
00098   unsigned int hop = frames.channels();
00099   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
00100     inputs_[0] = gain_ * *samples;
00101     *samples = b_[1] * inputs_[1] + b_[0] * inputs_[0];
00102     inputs_[1] = inputs_[0];
00103   }
00104 
00105   lastFrame_[0] = *(samples-hop);
00106   return frames;
00107 }
00108 
00109 inline StkFrames& OneZero :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
00110 {
00111 #if defined(_STK_DEBUG_)
00112   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
00113     errorString_ << "OneZero::tick(): channel and StkFrames arguments are incompatible!";
00114     handleError( StkError::FUNCTION_ARGUMENT );
00115   }
00116 #endif
00117 
00118   StkFloat *iSamples = &iFrames[iChannel];
00119   StkFloat *oSamples = &oFrames[oChannel];
00120   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
00121   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
00122     inputs_[0] = gain_ * *iSamples;
00123     *oSamples = b_[1] * inputs_[1] + b_[0] * inputs_[0];
00124     inputs_[1] = inputs_[0];
00125   }
00126 
00127   lastFrame_[0] = *(oSamples-oHop);
00128   return iFrames;
00129 }
00130 
00131 } // stk namespace
00132 
00133 #endif
00134 

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