Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# DelayL.h

    00001 #ifndef STK_DELAYL_H
    00002 #define STK_DELAYL_H
    00003
    00004 #include "Filter.h"
    00005
    00006 namespace stk {
    00007
    00008 /***************************************************/
    00025 /***************************************************/
    00026
    00027 class DelayL : public Filter
    00028 {
    00029 public:
    00030
    00032
    00037   DelayL( StkFloat delay = 0.0, unsigned long maxDelay = 4095 );
    00038
    00040   ~DelayL();
    00041
    00043   unsigned long getMaximumDelay( void ) { return inputs_.size() - 1; };
    00044
    00046
    00053   void setMaximumDelay( unsigned long delay );
    00054
    00056
    00059   void setDelay( StkFloat delay );
    00060
    00062   StkFloat getDelay( void ) const { return delay_; };
    00063
    00065
    00070   StkFloat tapOut( unsigned long tapDelay );
    00071
    00073   void tapIn( StkFloat value, unsigned long tapDelay );
    00074
    00076   StkFloat lastOut( void ) const { return lastFrame_[0]; };
    00077
    00079
    00082   StkFloat nextOut( void );
    00083
    00085   StkFloat tick( StkFloat input );
    00086
    00088
    00096   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00097
    00099
    00107   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00108
    00109  protected:
    00110
    00111   unsigned long inPoint_;
    00112   unsigned long outPoint_;
    00113   StkFloat delay_;
    00114   StkFloat alpha_;
    00115   StkFloat omAlpha_;
    00116   StkFloat nextOutput_;
    00117   bool doNextOut_;
    00118 };
    00119
    00120 inline StkFloat DelayL :: nextOut( void )
    00121 {
    00122   if ( doNextOut_ ) {
    00123     // First 1/2 of interpolation
    00124     nextOutput_ = inputs_[outPoint_] * omAlpha_;
    00125     // Second 1/2 of interpolation
    00126     if (outPoint_+1 < inputs_.size())
    00127       nextOutput_ += inputs_[outPoint_+1] * alpha_;
    00128     else
    00129       nextOutput_ += inputs_[0] * alpha_;
    00130     doNextOut_ = false;
    00131   }
    00132
    00133   return nextOutput_;
    00134 }
    00135
    00136 inline StkFloat DelayL :: tick( StkFloat input )
    00137 {
    00138   inputs_[inPoint_++] = input * gain_;
    00139
    00140   // Increment input pointer modulo length.
    00141   if ( inPoint_ == inputs_.size() )
    00142     inPoint_ = 0;
    00143
    00144   lastFrame_[0] = nextOut();
    00145   doNextOut_ = true;
    00146
    00147   // Increment output pointer modulo length.
    00148   if ( ++outPoint_ == inputs_.size() )
    00149     outPoint_ = 0;
    00150
    00151   return lastFrame_[0];
    00152 }
    00153
    00154 inline StkFrames& DelayL :: tick( StkFrames& frames, unsigned int channel )
    00155 {
    00156 #if defined(_STK_DEBUG_)
    00157   if ( channel >= frames.channels() ) {
    00158     oStream_ << "DelayL::tick(): channel and StkFrames arguments are incompatible!";
    00159     handleError( StkError::FUNCTION_ARGUMENT );
    00160   }
    00161 #endif
    00162
    00163   StkFloat *samples = &frames[channel];
    00164   unsigned int hop = frames.channels();
    00165   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00166     inputs_[inPoint_++] = *samples * gain_;
    00167     if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
    00168     *samples = nextOut();
    00169     doNextOut_ = true;
    00170     if ( ++outPoint_ == inputs_.size() ) outPoint_ = 0;
    00171   }
    00172
    00173   lastFrame_[0] = *(samples-hop);
    00174   return frames;
    00175 }
    00176
    00177 inline StkFrames& DelayL :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
    00178 {
    00179 #if defined(_STK_DEBUG_)
    00180   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
    00181     oStream_ << "DelayL::tick(): channel and StkFrames arguments are incompatible!";
    00182     handleError( StkError::FUNCTION_ARGUMENT );
    00183   }
    00184 #endif
    00185
    00186   StkFloat *iSamples = &iFrames[iChannel];
    00187   StkFloat *oSamples = &oFrames[oChannel];
    00188   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
    00189   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
    00190     inputs_[inPoint_++] = *iSamples * gain_;
    00191     if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
    00192     *oSamples = nextOut();
    00193     doNextOut_ = true;
    00194     if ( ++outPoint_ == inputs_.size() ) outPoint_ = 0;
    00195   }
    00196
    00197   lastFrame_[0] = *(oSamples-oHop);
    00198   return iFrames;
    00199 }
    00200
    00201 } // stk namespace
    00202
    00203 #endif

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