-
Notifications
You must be signed in to change notification settings - Fork 185
/
TapDelay.cpp
87 lines (69 loc) · 2.58 KB
/
TapDelay.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
74
75
76
77
78
79
80
81
82
83
84
85
86
/***************************************************/
/*! \class TapDelay
\brief STK non-interpolating tapped delay line class.
This class implements a non-interpolating digital delay-line with
an arbitrary number of output "taps". If the maximum length and
tap delays are not specified during instantiation, a fixed maximum
length of 4095 and a single tap delay of zero is set.
A non-interpolating delay line is typically used in fixed
delay-length applications, such as for reverberation.
by Perry R. Cook and Gary P. Scavone, 1995--2023.
*/
/***************************************************/
#include "TapDelay.h"
namespace stk {
TapDelay :: TapDelay( std::vector<unsigned long> taps, unsigned long maxDelay )
{
// Writing before reading allows delays from 0 to length-1.
// If we want to allow a delay of maxDelay, we need a
// delayline of length = maxDelay+1.
if ( maxDelay < 1 ) {
oStream_ << "TapDelay::TapDelay: maxDelay must be > 0!\n";
handleError( StkError::FUNCTION_ARGUMENT );
}
for ( unsigned int i=0; i<taps.size(); i++ ) {
if ( taps[i] > maxDelay ) {
oStream_ << "TapDelay::TapDelay: maxDelay must be > than all tap delay values!\n";
handleError( StkError::FUNCTION_ARGUMENT );
}
}
if ( ( maxDelay + 1 ) > inputs_.size() )
inputs_.resize( maxDelay + 1, 1, 0.0 );
inPoint_ = 0;
this->setTapDelays( taps );
}
TapDelay :: ~TapDelay()
{
}
void TapDelay :: setMaximumDelay( unsigned long delay )
{
if ( delay < inputs_.size() ) return;
for ( unsigned int i=0; i<delays_.size(); i++ ) {
if ( delay < delays_[i] ) {
oStream_ << "TapDelay::setMaximumDelay: argument (" << delay << ") less than a current tap delay setting (" << delays_[i] << ")!\n";
handleError( StkError::WARNING ); return;
}
}
inputs_.resize( delay + 1 );
}
void TapDelay :: setTapDelays( std::vector<unsigned long> taps )
{
for ( unsigned int i=0; i<taps.size(); i++ ) {
if ( taps[i] > inputs_.size() - 1 ) { // The value is too big.
oStream_ << "TapDelay::setTapDelay: argument (" << taps[i] << ") greater than maximum!\n";
handleError( StkError::WARNING ); return;
}
}
if ( taps.size() != outPoint_.size() ) {
outPoint_.resize( taps.size() );
delays_.resize( taps.size() );
lastFrame_.resize( 1, (unsigned int)taps.size(), 0.0 );
}
for ( unsigned int i=0; i<taps.size(); i++ ) {
// read chases write
if ( inPoint_ >= taps[i] ) outPoint_[i] = inPoint_ - taps[i];
else outPoint_[i] = inputs_.size() + inPoint_ - taps[i];
delays_[i] = taps[i];
}
}
} // stk namespace