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() {
|
2022-08-24 10:02:52 +02:00
|
|
|
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);
|
2022-08-24 10:02:52 +02:00
|
|
|
delete this->samples;
|
2022-08-24 11:07:15 +02:00
|
|
|
this->samples = new float[this->sampleCount]();
|
2021-07-27 09:47:15 +02:00
|
|
|
this->offset = 0;
|
|
|
|
}
|