The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Delay.h

    00001 #ifndef STK_DELAY_H
    00002 #define STK_DELAY_H
    00003
    00004 #include "Filter.h"
    00005
    00006 namespace stk {
    00007
    00008 /***************************************************/
    00022 /***************************************************/
    00023
    00024 class Delay : public Filter
    00025 {
    00026 public:
    00027
    00029
    00034   Delay( unsigned long delay = 0, unsigned long maxDelay = 4095 );
    00035
    00037   ~Delay();
    00038
    00040   unsigned long getMaximumDelay( void ) { return inputs_.size() - 1; };
    00041
    00043
    00050   void setMaximumDelay( unsigned long delay );
    00051
    00053
    00056   void setDelay( unsigned long delay );
    00057
    00059   unsigned long getDelay( void ) const { return delay_; };
    00060
    00062
    00067   StkFloat tapOut( unsigned long tapDelay );
    00068
    00070   void tapIn( StkFloat value, unsigned long tapDelay );
    00071
    00073
    00078   StkFloat addTo( StkFloat value, unsigned long tapDelay );
    00079
    00081   StkFloat lastOut( void ) const { return lastFrame_[0]; };
    00082
    00084
    00087   StkFloat nextOut( void ) { return inputs_[outPoint_]; };
    00088
    00090   StkFloat energy( void ) const;
    00091
    00093   StkFloat tick( StkFloat input );
    00094
    00096
    00104   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00105
    00107
    00115   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00116
    00117 protected:
    00118
    00119   unsigned long inPoint_;
    00120   unsigned long outPoint_;
    00121   unsigned long delay_;
    00122 };
    00123
    00124 inline StkFloat Delay :: tick( StkFloat input )
    00125 {
    00126   inputs_[inPoint_++] = input * gain_;
    00127
    00128   // Check for end condition
    00129   if ( inPoint_ == inputs_.size() )
    00130     inPoint_ = 0;
    00131
    00132   // Read out next value
    00133   lastFrame_[0] = inputs_[outPoint_++];
    00134
    00135   if ( outPoint_ == inputs_.size() )
    00136     outPoint_ = 0;
    00137
    00138   return lastFrame_[0];
    00139 }
    00140
    00141 inline StkFrames& Delay :: tick( StkFrames& frames, unsigned int channel )
    00142 {
    00143 #if defined(_STK_DEBUG_)
    00144   if ( channel >= frames.channels() ) {
    00145     oStream_ << "Delay::tick(): channel and StkFrames arguments are incompatible!";
    00146     handleError( StkError::FUNCTION_ARGUMENT );
    00147   }
    00148 #endif
    00149
    00150   StkFloat *samples = &frames[channel];
    00151   unsigned int hop = frames.channels();
    00152   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00153     inputs_[inPoint_++] = *samples * gain_;
    00154     if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
    00155     *samples = inputs_[outPoint_++];
    00156     if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
    00157   }
    00158
    00159   lastFrame_[0] = *(samples-hop);
    00160   return frames;
    00161 }
    00162
    00163 inline StkFrames& Delay :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
    00164 {
    00165 #if defined(_STK_DEBUG_)
    00166   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
    00167     oStream_ << "Delay::tick(): channel and StkFrames arguments are incompatible!";
    00168     handleError( StkError::FUNCTION_ARGUMENT );
    00169   }
    00170 #endif
    00171
    00172   StkFloat *iSamples = &iFrames[iChannel];
    00173   StkFloat *oSamples = &oFrames[oChannel];
    00174   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
    00175   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
    00176     inputs_[inPoint_++] = *iSamples * gain_;
    00177     if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
    00178     *oSamples = inputs_[outPoint_++];
    00179     if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
    00180   }
    00181
    00182   lastFrame_[0] = *(oSamples-oHop);
    00183   return iFrames;
    00184 }
    00185
    00186 } // stk namespace
    00187
    00188 #endif

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