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

30 lines
820 B
C++
Raw Normal View History

2021-07-27 09:47:15 +02:00
#include "TimeConstDelay.h"
2022-09-23 04:15:43 +02:00
#include <cstdlib>
2021-07-27 09:47:15 +02:00
TimeConstDelay::TimeConstDelay() {
this->samples = nullptr;
this->offset = 0;
this->sampleCount = 0;
}
TimeConstDelay::~TimeConstDelay() {
delete this->samples;
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;
2022-09-18 03:38:22 +02:00
this->offset = (int) modf((float) this->offset + 1, (float *) &this->sampleCount); // TODO: check if this is correct
2021-07-27 09:47:15 +02:00
return val;
}
2022-09-23 04:15:43 +02:00
return 0.0;
2021-07-27 09:47:15 +02:00
}
2022-09-23 04:15:43 +02:00
void TimeConstDelay::SetParameters(uint32_t samplingRate, float delay) {
this->sampleCount = samplingRate * (uint32_t) ceil(delay);
delete this->samples;
this->samples = new float[this->sampleCount]();
2021-07-27 09:47:15 +02:00
this->offset = 0;
}