osci-render/Source/audio/DelayEffect.cpp

40 wiersze
956 B
C++

#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) {
double decay = values[0];
double decayLength = values[1];
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(
vector.x + echo.x * decay,
vector.y + echo.y * decay,
vector.z + echo.z * decay
);
delayBuffer[head] = vector;
head++;
position++;
samplesSinceLastDelay++;
return vector;
}