2023-07-11 12:32:52 +00:00
|
|
|
#include "DelayEffect.h"
|
|
|
|
|
|
|
|
DelayEffect::DelayEffect() {}
|
|
|
|
|
|
|
|
DelayEffect::~DelayEffect() {}
|
|
|
|
|
2024-01-07 16:17:20 +00:00
|
|
|
Point DelayEffect::apply(int index, Point vector, const std::vector<double>& values, double sampleRate) {
|
2023-07-14 14:34:24 +00:00
|
|
|
double decay = values[0];
|
|
|
|
double decayLength = values[1];
|
2023-07-11 12:32:52 +00:00
|
|
|
int delayBufferLength = (int)(sampleRate * decayLength);
|
|
|
|
if (head >= delayBuffer.size()){
|
|
|
|
head = 0;
|
|
|
|
}
|
|
|
|
if (position >= delayBuffer.size()){
|
|
|
|
position = 0;
|
|
|
|
}
|
|
|
|
if (samplesSinceLastDelay >= delayBufferLength) {
|
|
|
|
samplesSinceLastDelay = 0;
|
|
|
|
position = head - delayBufferLength;
|
|
|
|
if (position < 0) {
|
|
|
|
position += delayBuffer.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-07 16:17:20 +00:00
|
|
|
Point echo = delayBuffer[position];
|
|
|
|
vector = Point(
|
2023-07-11 12:32:52 +00:00
|
|
|
vector.x + echo.x * decay,
|
2024-01-07 19:48:02 +00:00
|
|
|
vector.y + echo.y * decay,
|
|
|
|
vector.z + echo.z * decay
|
2023-07-11 12:32:52 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
delayBuffer[head] = vector;
|
|
|
|
|
|
|
|
head++;
|
|
|
|
position++;
|
|
|
|
samplesSinceLastDelay++;
|
|
|
|
|
|
|
|
return vector;
|
|
|
|
}
|