ViPERFX_RE/src/cpp/viper/utils/TimeConstDelay.cpp

32 lines
836 B
C++
Raw Normal View History

2021-07-27 09:47:15 +02:00
#include <cstdlib>
#include <cstring>
#include "TimeConstDelay.h"
TimeConstDelay::TimeConstDelay() {
this->samples = nullptr;
this->offset = 0;
this->sampleCount = 0;
}
TimeConstDelay::~TimeConstDelay() {
delete this->samples;
this->samples = nullptr;
2021-07-27 09:47:15 +02:00
}
float TimeConstDelay::ProcessSample(float sample) {
if (this->samples != nullptr) {
float val = this->samples[this->offset];
this->samples[this->offset] = sample;
this->offset = (int) modf((float) this->offset + 1, (float *) &this->sampleCount);
2021-07-27 09:47:15 +02:00
return val;
}
return 0.f;
}
void TimeConstDelay::SetParameters(uint32_t samplerate, float delay) {
this->sampleCount = (int) ((float) samplerate * delay * 0.5f);
delete this->samples;
this->samples = new float[this->sampleCount]();
2021-07-27 09:47:15 +02:00
this->offset = 0;
}