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
    00072   StkFloat addTo( unsigned long tapDelay, StkFloat value );
    00073
    00075   StkFloat lastOut( void ) const { return lastFrame_[0]; };
    00076
    00078
    00081   StkFloat nextOut( void ) { return inputs_[outPoint_]; };
    00082
    00084   StkFloat energy( void ) const;
    00085
    00087   StkFloat tick( StkFloat input );
    00088
    00090
    00098   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00099
    00101
    00109   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00110
    00111 protected:
    00112
    00113   unsigned long inPoint_;
    00114   unsigned long outPoint_;
    00115   unsigned long delay_;
    00116 };
    00117
    00118 inline StkFloat Delay :: tick( StkFloat input )
    00119 {
    00120   inputs_[inPoint_++] = input * gain_;
    00121
    00122   // Check for end condition
    00123   if ( inPoint_ == inputs_.size() )
    00124     inPoint_ = 0;
    00125
    00126   // Read out next value
    00127   lastFrame_[0] = inputs_[outPoint_++];
    00128
    00129   if ( outPoint_ == inputs_.size() )
    00130     outPoint_ = 0;
    00131
    00132   return lastFrame_[0];
    00133 }
    00134
    00135 inline StkFrames& Delay :: tick( StkFrames& frames, unsigned int channel )
    00136 {
    00137 #if defined(_STK_DEBUG_)
    00138   if ( channel >= frames.channels() ) {
    00139     errorString_ << "Delay::tick(): channel and StkFrames arguments are incompatible!";
    00140     handleError( StkError::FUNCTION_ARGUMENT );
    00141   }
    00142 #endif
    00143
    00144   StkFloat *samples = &frames[channel];
    00145   unsigned int hop = frames.channels();
    00146   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00147     inputs_[inPoint_++] = *samples * gain_;
    00148     if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
    00149     *samples = inputs_[outPoint_++];
    00150     if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
    00151   }
    00152
    00153   lastFrame_[0] = *(samples-hop);
    00154   return frames;
    00155 }
    00156
    00157 inline StkFrames& Delay :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
    00158 {
    00159 #if defined(_STK_DEBUG_)
    00160   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
    00161     errorString_ << "Delay::tick(): channel and StkFrames arguments are incompatible!";
    00162     handleError( StkError::FUNCTION_ARGUMENT );
    00163   }
    00164 #endif
    00165
    00166   StkFloat *iSamples = &iFrames[iChannel];
    00167   StkFloat *oSamples = &oFrames[oChannel];
    00168   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
    00169   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
    00170     inputs_[inPoint_++] = *iSamples * gain_;
    00171     if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
    00172     *oSamples = inputs_[outPoint_++];
    00173     if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
    00174   }
    00175
    00176   lastFrame_[0] = *(oSamples-oHop);
    00177   return iFrames;
    00178 }
    00179
    00180 } // stk namespace
    00181
    00182 #endif

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