Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial
00001 #ifndef STK_DELAYL_H 00002 #define STK_DELAYL_H 00003 00004 #include "Delay.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 00050 void setMaximumDelay( unsigned long delay ); 00051 00053 00056 void setDelay( StkFloat delay ); 00057 00059 StkFloat getDelay( void ) const { return delay_; }; 00060 00062 00067 StkFloat contentsAt( unsigned long tapDelay ); 00068 00070 StkFloat lastOut( void ) const { return lastFrame_[0]; }; 00071 00073 00076 StkFloat nextOut( void ); 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 StkFloat delay_; 00108 StkFloat alpha_; 00109 StkFloat omAlpha_; 00110 StkFloat nextOutput_; 00111 bool doNextOut_; 00112 }; 00113 00114 inline StkFloat DelayL :: nextOut( void ) 00115 { 00116 if ( doNextOut_ ) { 00117 // First 1/2 of interpolation 00118 nextOutput_ = inputs_[outPoint_] * omAlpha_; 00119 // Second 1/2 of interpolation 00120 if (outPoint_+1 < inputs_.size()) 00121 nextOutput_ += inputs_[outPoint_+1] * alpha_; 00122 else 00123 nextOutput_ += inputs_[0] * alpha_; 00124 doNextOut_ = false; 00125 } 00126 00127 return nextOutput_; 00128 } 00129 00130 inline StkFloat DelayL :: tick( StkFloat input ) 00131 { 00132 inputs_[inPoint_++] = input * gain_; 00133 00134 // Increment input pointer modulo length. 00135 if ( inPoint_ == inputs_.size() ) 00136 inPoint_ = 0; 00137 00138 lastFrame_[0] = nextOut(); 00139 doNextOut_ = true; 00140 00141 // Increment output pointer modulo length. 00142 if ( ++outPoint_ == inputs_.size() ) 00143 outPoint_ = 0; 00144 00145 return lastFrame_[0]; 00146 } 00147 00148 inline StkFrames& DelayL :: tick( StkFrames& frames, unsigned int channel ) 00149 { 00150 #if defined(_STK_DEBUG_) 00151 if ( channel >= frames.channels() ) { 00152 errorString_ << "DelayL::tick(): channel and StkFrames arguments are incompatible!"; 00153 handleError( StkError::FUNCTION_ARGUMENT ); 00154 } 00155 #endif 00156 00157 StkFloat *samples = &frames[channel]; 00158 unsigned int hop = frames.channels(); 00159 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) { 00160 inputs_[inPoint_++] = *samples * gain_; 00161 if ( inPoint_ == inputs_.size() ) inPoint_ = 0; 00162 *samples = nextOut(); 00163 doNextOut_ = true; 00164 if ( ++outPoint_ == inputs_.size() ) outPoint_ = 0; 00165 } 00166 00167 lastFrame_[0] = *(samples-hop); 00168 return frames; 00169 } 00170 00171 inline StkFrames& DelayL :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel ) 00172 { 00173 #if defined(_STK_DEBUG_) 00174 if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) { 00175 errorString_ << "DelayL::tick(): channel and StkFrames arguments are incompatible!"; 00176 handleError( StkError::FUNCTION_ARGUMENT ); 00177 } 00178 #endif 00179 00180 StkFloat *iSamples = &iFrames[iChannel]; 00181 StkFloat *oSamples = &oFrames[oChannel]; 00182 unsigned int iHop = iFrames.channels(), oHop = oFrames.channels(); 00183 for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) { 00184 inputs_[inPoint_++] = *iSamples * gain_; 00185 if ( inPoint_ == inputs_.size() ) inPoint_ = 0; 00186 *oSamples = nextOut(); 00187 doNextOut_ = true; 00188 if ( ++outPoint_ == inputs_.size() ) outPoint_ = 0; 00189 } 00190 00191 lastFrame_[0] = *(oSamples-oHop); 00192 return iFrames; 00193 } 00194 00195 } // stk namespace 00196 00197 #endif
The Synthesis ToolKit in C++ (STK) |
©1995-2010 Perry R. Cook and Gary P. Scavone. All Rights Reserved. |