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
    00047   void setMaximumDelay( unsigned long delay );
    00048
    00050
    00053   void setDelay( unsigned long delay );
    00054
    00056   unsigned long getDelay( void ) const { return delay_; };
    00057
    00059
    00064   StkFloat contentsAt( unsigned long tapDelay );
    00065
    00067   StkFloat lastOut( void ) const { return lastFrame_[0]; };
    00068
    00070
    00073   StkFloat nextOut( void ) { return inputs_[outPoint_]; };
    00074
    00076   StkFloat energy( void ) const;
    00077
    00079   StkFloat tick( StkFloat input );
    00080
    00082
    00090   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00091
    00093
    00101   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00102
    00103 protected:
    00104
    00105   unsigned long inPoint_;
    00106   unsigned long outPoint_;
    00107   unsigned long delay_;
    00108 };
    00109
    00110 inline StkFloat Delay :: tick( StkFloat input )
    00111 {
    00112   inputs_[inPoint_++] = input * gain_;
    00113
    00114   // Check for end condition
    00115   if ( inPoint_ == inputs_.size() )
    00116     inPoint_ = 0;
    00117
    00118   // Read out next value
    00119   lastFrame_[0] = inputs_[outPoint_++];
    00120
    00121   if ( outPoint_ == inputs_.size() )
    00122     outPoint_ = 0;
    00123
    00124   return lastFrame_[0];
    00125 }
    00126
    00127 inline StkFrames& Delay :: tick( StkFrames& frames, unsigned int channel )
    00128 {
    00129 #if defined(_STK_DEBUG_)
    00130   if ( channel >= frames.channels() ) {
    00131     errorString_ << "Delay::tick(): channel and StkFrames arguments are incompatible!";
    00132     handleError( StkError::FUNCTION_ARGUMENT );
    00133   }
    00134 #endif
    00135
    00136   StkFloat *samples = &frames[channel];
    00137   unsigned int hop = frames.channels();
    00138   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00139     inputs_[inPoint_++] = *samples * gain_;
    00140     if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
    00141     *samples = inputs_[outPoint_++];
    00142     if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
    00143   }
    00144
    00145   lastFrame_[0] = *(samples-hop);
    00146   return frames;
    00147 }
    00148
    00149 inline StkFrames& Delay :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
    00150 {
    00151 #if defined(_STK_DEBUG_)
    00152   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
    00153     errorString_ << "Delay::tick(): channel and StkFrames arguments are incompatible!";
    00154     handleError( StkError::FUNCTION_ARGUMENT );
    00155   }
    00156 #endif
    00157
    00158   StkFloat *iSamples = &iFrames[iChannel];
    00159   StkFloat *oSamples = &oFrames[oChannel];
    00160   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
    00161   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
    00162     inputs_[inPoint_++] = *iSamples * gain_;
    00163     if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
    00164     *oSamples = inputs_[outPoint_++];
    00165     if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
    00166   }
    00167
    00168   lastFrame_[0] = *(oSamples-oHop);
    00169   return iFrames;
    00170 }
    00171
    00172 } // stk namespace
    00173
    00174 #endif

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