The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Fir.h

    00001 #ifndef STK_FIR_H
    00002 #define STK_FIR_H
    00003
    00004 #include "Filter.h"
    00005
    00006 namespace stk {
    00007
    00008 /***************************************************/
    00028 /***************************************************/
    00029
    00030 class Fir : public Filter
    00031 {
    00032 public:
    00034   Fir( void );
    00035
    00037
    00041   Fir( std::vector<StkFloat> &coefficients );
    00042
    00044   ~Fir( void );
    00045
    00047
    00052   void setCoefficients( std::vector<StkFloat> &coefficients, bool clearState = false );
    00053
    00055   StkFloat lastOut( void ) const { return lastFrame_[0]; };
    00056
    00058   StkFloat tick( StkFloat input );
    00059
    00061
    00069   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00070
    00072
    00080   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00081
    00082 protected:
    00083
    00084 };
    00085
    00086 inline StkFloat Fir :: tick( StkFloat input )
    00087 {
    00088   lastFrame_[0] = 0.0;
    00089   inputs_[0] = gain_ * input;
    00090
    00091   for ( unsigned int i=b_.size()-1; i>0; i-- ) {
    00092     lastFrame_[0] += b_[i] * inputs_[i];
    00093     inputs_[i] = inputs_[i-1];
    00094   }
    00095   lastFrame_[0] += b_[0] * inputs_[0];
    00096
    00097   return lastFrame_[0];
    00098 }
    00099
    00100 inline StkFrames& Fir :: tick( StkFrames& frames, unsigned int channel )
    00101 {
    00102 #if defined(_STK_DEBUG_)
    00103   if ( channel >= frames.channels() ) {
    00104     oStream_ << "Fir::tick(): channel and StkFrames arguments are incompatible!";
    00105     handleError( StkError::FUNCTION_ARGUMENT );
    00106   }
    00107 #endif
    00108
    00109   StkFloat *samples = &frames[channel];
    00110   unsigned int i, hop = frames.channels();
    00111   for ( unsigned int j=0; j<frames.frames(); j++, samples += hop ) {
    00112     inputs_[0] = gain_ * *samples;
    00113     *samples = 0.0;
    00114
    00115     for ( i=b_.size()-1; i>0; i-- ) {
    00116       *samples += b_[i] * inputs_[i];
    00117       inputs_[i] = inputs_[i-1];
    00118     }
    00119     *samples += b_[0] * inputs_[0];
    00120   }
    00121
    00122   lastFrame_[0] = *(samples-hop);
    00123   return frames;
    00124 }
    00125
    00126 inline StkFrames& Fir :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
    00127 {
    00128 #if defined(_STK_DEBUG_)
    00129   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
    00130     oStream_ << "Fir::tick(): channel and StkFrames arguments are incompatible!";
    00131     handleError( StkError::FUNCTION_ARGUMENT );
    00132   }
    00133 #endif
    00134
    00135   StkFloat *iSamples = &iFrames[iChannel];
    00136   StkFloat *oSamples = &oFrames[oChannel];
    00137   unsigned int i, iHop = iFrames.channels(), oHop = oFrames.channels();
    00138   for ( unsigned int j=0; j<iFrames.frames(); j++, iSamples += iHop, oSamples += oHop ) {
    00139     inputs_[0] = gain_ * *iSamples;
    00140     *oSamples = 0.0;
    00141
    00142     for ( i=b_.size()-1; i>0; i-- ) {
    00143       *oSamples += b_[i] * inputs_[i];
    00144       inputs_[i] = inputs_[i-1];
    00145     }
    00146     *oSamples += b_[0] * inputs_[0];
    00147   }
    00148
    00149   lastFrame_[0] = *(oSamples-oHop);
    00150   return iFrames;
    00151 }
    00152
    00153 } // stk namespace
    00154
    00155 #endif

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