Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial
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 unsigned long getMaximumDelay( void ) { return inputs_.size() - 1; }; 00048 00050 00057 void setMaximumDelay( unsigned long delay ); 00058 00060 00063 void setDelay( StkFloat delay ); 00064 00066 StkFloat getDelay( void ) const { return delay_; }; 00067 00069 00074 StkFloat tapOut( unsigned long tapDelay ); 00075 00077 void tapIn( StkFloat value, unsigned long tapDelay ); 00078 00080 StkFloat lastOut( void ) const { return lastFrame_[0]; }; 00081 00083 00086 StkFloat nextOut( void ); 00087 00089 StkFloat tick( StkFloat input ); 00090 00092 00100 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); 00101 00103 00111 StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 ); 00112 00113 protected: 00114 00115 unsigned long inPoint_; 00116 unsigned long outPoint_; 00117 StkFloat delay_; 00118 StkFloat alpha_; 00119 StkFloat coeff_; 00120 StkFloat apInput_; 00121 StkFloat nextOutput_; 00122 bool doNextOut_; 00123 }; 00124 00125 inline StkFloat DelayA :: nextOut( void ) 00126 { 00127 if ( doNextOut_ ) { 00128 // Do allpass interpolation delay. 00129 nextOutput_ = -coeff_ * lastFrame_[0]; 00130 nextOutput_ += apInput_ + ( coeff_ * inputs_[outPoint_] ); 00131 doNextOut_ = false; 00132 } 00133 00134 return nextOutput_; 00135 } 00136 00137 inline StkFloat DelayA :: tick( StkFloat input ) 00138 { 00139 inputs_[inPoint_++] = input * gain_; 00140 00141 // Increment input pointer modulo length. 00142 if ( inPoint_ == inputs_.size() ) 00143 inPoint_ = 0; 00144 00145 lastFrame_[0] = nextOut(); 00146 doNextOut_ = true; 00147 00148 // Save the allpass input and increment modulo length. 00149 apInput_ = inputs_[outPoint_++]; 00150 if ( outPoint_ == inputs_.size() ) 00151 outPoint_ = 0; 00152 00153 return lastFrame_[0]; 00154 } 00155 00156 inline StkFrames& DelayA :: tick( StkFrames& frames, unsigned int channel ) 00157 { 00158 #if defined(_STK_DEBUG_) 00159 if ( channel >= frames.channels() ) { 00160 oStream_ << "DelayA::tick(): channel and StkFrames arguments are incompatible!"; 00161 handleError( StkError::FUNCTION_ARGUMENT ); 00162 } 00163 #endif 00164 00165 StkFloat *samples = &frames[channel]; 00166 unsigned int hop = frames.channels(); 00167 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) { 00168 inputs_[inPoint_++] = *samples * gain_; 00169 if ( inPoint_ == inputs_.size() ) inPoint_ = 0; 00170 *samples = nextOut(); 00171 lastFrame_[0] = *samples; 00172 doNextOut_ = true; 00173 apInput_ = inputs_[outPoint_++]; 00174 if ( outPoint_ == inputs_.size() ) outPoint_ = 0; 00175 } 00176 00177 return frames; 00178 } 00179 00180 inline StkFrames& DelayA :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel ) 00181 { 00182 #if defined(_STK_DEBUG_) 00183 if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) { 00184 oStream_ << "DelayA::tick(): channel and StkFrames arguments are incompatible!"; 00185 handleError( StkError::FUNCTION_ARGUMENT ); 00186 } 00187 #endif 00188 00189 StkFloat *iSamples = &iFrames[iChannel]; 00190 StkFloat *oSamples = &oFrames[oChannel]; 00191 unsigned int iHop = iFrames.channels(), oHop = oFrames.channels(); 00192 for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) { 00193 inputs_[inPoint_++] = *iSamples * gain_; 00194 if ( inPoint_ == inputs_.size() ) inPoint_ = 0; 00195 *oSamples = nextOut(); 00196 lastFrame_[0] = *oSamples; 00197 doNextOut_ = true; 00198 apInput_ = inputs_[outPoint_++]; 00199 if ( outPoint_ == inputs_.size() ) outPoint_ = 0; 00200 } 00201 00202 return iFrames; 00203 } 00204 00205 } // stk namespace 00206 00207 #endif
The Synthesis ToolKit in C++ (STK) |
©1995-2012 Perry R. Cook and Gary P. Scavone. All Rights Reserved. |