1 /***************************************************/
2 /*! \class DelayL
3 \brief STK linear interpolating delay line class.
4
5 This class implements a fractional-length digital delay-line using
6 first-order linear interpolation. If the delay and maximum length
7 are not specified during instantiation, a fixed maximum length of
8 4095 and a delay of zero is set.
9
10 Linear interpolation is an efficient technique for achieving
11 fractional delay lengths, though it does introduce high-frequency
12 signal attenuation to varying degrees depending on the fractional
13 delay setting. The use of higher order Lagrange interpolators can
14 typically improve (minimize) this attenuation characteristic.
15
16 by Perry R. Cook and Gary P. Scavone, 1995--2021.
17 */
18 /***************************************************/
19
20 #include "DelayL.h"
21
22 namespace stk {
23
DelayL(StkFloat delay,unsigned long maxDelay)24 DelayL :: DelayL( StkFloat delay, unsigned long maxDelay )
25 {
26 if ( delay < 0.0 ) {
27 oStream_ << "DelayL::DelayL: delay must be >= 0.0!";
28 handleError( StkError::FUNCTION_ARGUMENT );
29 }
30
31 if ( delay > (StkFloat) maxDelay ) {
32 oStream_ << "DelayL::DelayL: maxDelay must be > than delay argument!";
33 handleError( StkError::FUNCTION_ARGUMENT );
34 }
35
36 // Writing before reading allows delays from 0 to length-1.
37 if ( maxDelay + 1 > inputs_.size() )
38 inputs_.resize( maxDelay + 1, 1, 0.0 );
39
40 inPoint_ = 0;
41 this->setDelay( delay );
42 doNextOut_ = true;
43 }
44
~DelayL()45 DelayL :: ~DelayL()
46 {
47 }
48
setMaximumDelay(unsigned long delay)49 void DelayL :: setMaximumDelay( unsigned long delay )
50 {
51 if ( delay < inputs_.size() ) return;
52 inputs_.resize(delay + 1, 1, 0.0);
53 }
54
tapOut(unsigned long tapDelay)55 StkFloat DelayL :: tapOut( unsigned long tapDelay )
56 {
57 long tap = inPoint_ - tapDelay - 1;
58 while ( tap < 0 ) // Check for wraparound.
59 tap += inputs_.size();
60
61 return inputs_[tap];
62 }
63
tapIn(StkFloat value,unsigned long tapDelay)64 void DelayL :: tapIn( StkFloat value, unsigned long tapDelay )
65 {
66 long tap = inPoint_ - tapDelay - 1;
67 while ( tap < 0 ) // Check for wraparound.
68 tap += inputs_.size();
69
70 inputs_[tap] = value;
71 }
72
73 } // stk namespace
74