The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# OnePole.h

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

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