-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDelay.cmajor
48 lines (41 loc) · 1.31 KB
/
Delay.cmajor
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
// Copyright (c) 2023 Alex M. Fink. All rights reserved.
// Licensed under the MIT License https://github.com/alexmfink/compufart
namespace Audolon::Delay (using FrameType, int MaxDelay)
{
//! This is a simple delay line that zeros the buffer on delay changes
struct DelayLine
{
// Note: All are init'ed to zero
FrameType[MaxDelay] m_buffer;
int m_delay;
wrap<MaxDelay> m_tapIndex;
FrameType GetNextOut()
{
return this.m_buffer[this.m_tapIndex];
}
FrameType Tick(FrameType inputSample)
{
FrameType outputSample = this.m_buffer[this.m_tapIndex];
this.m_buffer[this.m_tapIndex] = inputSample;
++this.m_tapIndex;
if (this.m_tapIndex >= this.m_delay)
{
this.m_tapIndex -= this.m_delay;
}
return outputSample;
}
void Reset()
{
for (wrap<MaxDelay> index)
{
this.m_buffer[index] = 0.0;
}
this.m_tapIndex = 0;
}
void SetDelayLength(int delayLength)
{
this.m_delay = Audolon::Utils::ClipValue(delayLength, 1, MaxDelay);
this.Reset();
}
}
}