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