2021-07-27 09:47:15 +02:00
|
|
|
//
|
|
|
|
// Created by mart on 7/26/21.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include "TimeConstDelay.h"
|
|
|
|
|
|
|
|
TimeConstDelay::TimeConstDelay() {
|
|
|
|
this->samples = nullptr;
|
|
|
|
this->offset = 0;
|
|
|
|
this->sampleCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeConstDelay::~TimeConstDelay() {
|
|
|
|
if (this->samples != nullptr) {
|
|
|
|
free(this->samples);
|
|
|
|
this->samples = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float TimeConstDelay::ProcessSample(float sample) {
|
|
|
|
if (this->samples != nullptr) {
|
|
|
|
float val = this->samples[this->offset];
|
|
|
|
this->samples[this->offset] = sample;
|
2022-08-23 00:26:44 +02:00
|
|
|
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) {
|
2022-08-23 00:26:44 +02:00
|
|
|
this->sampleCount = (int) ((float) samplerate * delay * 0.5f);
|
2021-07-27 09:47:15 +02:00
|
|
|
if (this->samples != nullptr) {
|
|
|
|
free(this->samples);
|
|
|
|
}
|
|
|
|
this->samples = new float[this->sampleCount * sizeof(float)];
|
|
|
|
this->offset = 0;
|
|
|
|
memset(this->samples, 0, this->sampleCount * sizeof(float));
|
|
|
|
}
|