-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProceduralReverb.cpp
37 lines (30 loc) · 942 Bytes
/
ProceduralReverb.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
// ©2023 JDSherbert. All rights reserved.
#include "ProceduralReverb.h"
#include <cmath>
ProceduralReverb::ProceduralReverb(double decayFactor, int delayLength)
: decayFactor(decayFactor)
, delayLength(delayLength)
{
// Initialize delay buffer with 0
delayBuffer.resize(delayLength, 0.0);
}
// Apply reverb effect to an input signal
double ProceduralReverb::ProcessSample(double input)
{
// Add the input to the delay buffer
delayBuffer.push_back(input);
// Apply decay to existing samples in the delay buffer
for (int i = 0; i < delayBuffer.size(); ++i)
{
delayBuffer[i] *= decayFactor;
}
// Get the output by summing the delayed samples
double output = 0.0;
for (int i = 0; i < delayBuffer.size(); ++i)
{
output += delayBuffer[i];
}
// Remove the oldest sample from the delay buffer
delayBuffer.erase(delayBuffer.begin());
return output;
}