Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# DelayA.h

    00001 #ifndef STK_DELAYA_H
    00002 #define STK_DELAYA_H
    00003
    00004 #include "Filter.h"
    00005
    00006 namespace stk {
    00007
    00008 /***************************************************/
    00026 /***************************************************/
    00027
    00028 class DelayA : public Filter
    00029 {
    00030 public:
    00031
    00033
    00038   DelayA( StkFloat delay = 0.5, unsigned long maxDelay = 4095 );
    00039
    00041   ~DelayA();
    00042
    00044   void clear( void );
    00045
    00047
    00054   void setMaximumDelay( unsigned long delay );
    00055
    00057
    00060   void setDelay( StkFloat delay );
    00061
    00063   StkFloat getDelay( void ) const { return delay_; };
    00064
    00066
    00071   StkFloat contentsAt( unsigned long tapDelay );
    00072
    00074   StkFloat lastOut( void ) const { return lastFrame_[0]; };
    00075
    00077
    00080   StkFloat nextOut( void );
    00081
    00083   StkFloat tick( StkFloat input );
    00084
    00086
    00094   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00095
    00097
    00105   StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
    00106
    00107 protected:
    00108
    00109   unsigned long inPoint_;
    00110   unsigned long outPoint_;
    00111   StkFloat delay_;
    00112   StkFloat alpha_;
    00113   StkFloat coeff_;
    00114   StkFloat apInput_;
    00115   StkFloat nextOutput_;
    00116   bool doNextOut_;
    00117 };
    00118
    00119 inline StkFloat DelayA :: nextOut( void )
    00120 {
    00121   if ( doNextOut_ ) {
    00122     // Do allpass interpolation delay.
    00123     nextOutput_ = -coeff_ * lastFrame_[0];
    00124     nextOutput_ += apInput_ + ( coeff_ * inputs_[outPoint_] );
    00125     doNextOut_ = false;
    00126   }
    00127
    00128   return nextOutput_;
    00129 }
    00130
    00131 inline StkFloat DelayA :: tick( StkFloat input )
    00132 {
    00133   inputs_[inPoint_++] = input * gain_;
    00134
    00135   // Increment input pointer modulo length.
    00136   if ( inPoint_ == inputs_.size() )
    00137     inPoint_ = 0;
    00138
    00139   lastFrame_[0] = nextOut();
    00140   doNextOut_ = true;
    00141
    00142   // Save the allpass input and increment modulo length.
    00143   apInput_ = inputs_[outPoint_++];
    00144   if ( outPoint_ == inputs_.size() )
    00145     outPoint_ = 0;
    00146
    00147   return lastFrame_[0];
    00148 }
    00149
    00150 inline StkFrames& DelayA :: tick( StkFrames& frames, unsigned int channel )
    00151 {
    00152 #if defined(_STK_DEBUG_)
    00153   if ( channel >= frames.channels() ) {
    00154     errorString_ << "DelayA::tick(): channel and StkFrames arguments are incompatible!";
    00155     handleError( StkError::FUNCTION_ARGUMENT );
    00156   }
    00157 #endif
    00158
    00159   StkFloat *samples = &frames[channel];
    00160   unsigned int hop = frames.channels();
    00161   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00162     inputs_[inPoint_++] = *samples * gain_;
    00163     if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
    00164     *samples = nextOut();
    00165     lastFrame_[0] = *samples;
    00166     doNextOut_ = true;
    00167     apInput_ = inputs_[outPoint_++];
    00168     if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
    00169   }
    00170
    00171   return frames;
    00172 }
    00173
    00174 inline StkFrames& DelayA :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
    00175 {
    00176 #if defined(_STK_DEBUG_)
    00177   if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
    00178     errorString_ << "DelayA::tick(): channel and StkFrames arguments are incompatible!";
    00179     handleError( StkError::FUNCTION_ARGUMENT );
    00180   }
    00181 #endif
    00182
    00183   StkFloat *iSamples = &iFrames[iChannel];
    00184   StkFloat *oSamples = &oFrames[oChannel];
    00185   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
    00186   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
    00187     inputs_[inPoint_++] = *iSamples * gain_;
    00188     if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
    00189     *oSamples = nextOut();
    00190     lastFrame_[0] = *oSamples;
    00191     doNextOut_ = true;
    00192     apInput_ = inputs_[outPoint_++];
    00193     if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
    00194   }
    00195
    00196   return iFrames;
    00197 }
    00198
    00199 } // stk namespace
    00200
    00201 #endif

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