Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


PoleZero.h

00001 #ifndef STK_POLEZERO_H
00002 #define STK_POLEZERO_H
00003 
00004 #include "Filter.h"
00005 
00006 namespace stk {
00007 
00008 /***************************************************/
00019 /***************************************************/
00020 
00021 class PoleZero : public Filter
00022 {
00023  public:
00024 
00026   PoleZero();
00027 
00029   ~PoleZero();
00030 
00032   void setB0( StkFloat b0 ) { b_[0] = b0; };
00033 
00035   void setB1( StkFloat b1 ) { b_[1] = b1; };
00036 
00038   void setA1( StkFloat a1 ) { a_[1] = a1; };
00039 
00041   void setCoefficients( StkFloat b0, StkFloat b1, StkFloat a1, bool clearState = false );
00042 
00044 
00049   void setAllpass( StkFloat coefficient );
00050 
00052 
00058   void setBlockZero( StkFloat thePole = 0.99 );
00059 
00061   StkFloat lastOut( void ) const { return lastFrame_[0]; };
00062 
00064   StkFloat tick( StkFloat input );
00065 
00067 
00074   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00075 
00076 };
00077 
00078 inline StkFloat PoleZero :: tick( StkFloat input )
00079 {
00080   inputs_[0] = gain_ * input;
00081   lastFrame_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] - a_[1] * outputs_[1];
00082   inputs_[1] = inputs_[0];
00083   outputs_[1] = lastFrame_[0];
00084 
00085   return lastFrame_[0];
00086 }
00087 
00088 inline StkFrames& PoleZero :: tick( StkFrames& frames, unsigned int channel )
00089 {
00090 #if defined(_STK_DEBUG_)
00091   if ( channel >= frames.channels() ) {
00092     errorString_ << "PoleZero::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_[0] * inputs_[0] + b_[1] * inputs_[1] - a_[1] * outputs_[1];
00102     inputs_[1] = inputs_[0];
00103     outputs_[1] = *samples;
00104   }
00105 
00106   lastFrame_[0] = outputs_[1];
00107   return frames;
00108 }
00109 
00110 } // stk namespace
00111 
00112 #endif

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