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
    00047   void setPole( StkFloat thePole );
    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 OnePole :: tick( StkFloat input )
    00080 {
    00081   inputs_[0] = gain_ * input;
    00082   lastFrame_[0] = b_[0] * inputs_[0] - a_[1] * outputs_[1];
    00083   outputs_[1] = lastFrame_[0];
    00084
    00085   return lastFrame_[0];
    00086 }
    00087
    00088 inline StkFrames& OnePole :: tick( StkFrames& frames, unsigned int channel )
    00089 {
    00090 #if defined(_STK_DEBUG_)
    00091   if ( channel >= frames.channels() ) {
    00092     errorString_ << "OnePole::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] - a_[1] * outputs_[1];
    00102     outputs_[1] = *samples;
    00103   }
    00104
    00105   lastFrame_[0] = outputs_[1];
    00106   return frames;
    00107 }
    00108
    00109 inline StkFrames& OnePole :: 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_ << "OnePole::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_[0] * inputs_[0] - a_[1] * outputs_[1];
    00124     outputs_[1] = *oSamples;
    00125   }
    00126
    00127   lastFrame_[0] = outputs_[1];
    00128   return iFrames;
    00129 }
    00130
    00131 } // stk namespace
    00132
    00133 #endif

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