Added delay implementation

pull/764/head
jnonis 7 months ago
parent 7bcba9183a
commit 75f4333831
  1. 44
      src/effect_delay.cpp
  2. 20
      src/effect_delay.h

@ -5,10 +5,26 @@ LOGMODULE ("fx chorus");
AudioEffectDelay::AudioEffectDelay(float32_t samplerate) : AudioEffect(samplerate) AudioEffectDelay::AudioEffectDelay(float32_t samplerate) : AudioEffect(samplerate)
{ {
bufferSize = (int) samplerate * MAX_DELAY_TIME;
bufferL = new float32_t[this->bufferSize];
bufferR = new float32_t[this->bufferSize];
index = 0;
for (size_t i = 0; i < bufferSize; i++)
{
bufferL[i] = 0.0f;
bufferR[i] = 0.0f;
}
timeL = 0.36f;
timeR = 0.36f;
feedback = 0.3f;
} }
AudioEffectDelay::~AudioEffectDelay() AudioEffectDelay::~AudioEffectDelay()
{ {
delete bufferL;
delete bufferR;
} }
unsigned AudioEffectDelay::getId() unsigned AudioEffectDelay::getId()
@ -20,7 +36,31 @@ void AudioEffectDelay::doProcess(const float32_t* inblockL, const float32_t* inb
{ {
for (uint16_t i=0; i < len; i++) for (uint16_t i=0; i < len; i++)
{ {
outblockL[i] = inblockL[i]; // Update buffers
outblockR[i] = inblockR[i]; bufferL[index] = inblockL[i];
bufferR[index] = inblockR[i];
// Calculate offsets
int offsetL = index - (timeL * samplerate);
if (offsetL < 0) {
offsetL = bufferSize + offsetL;
}
int offsetR = index - (timeR * samplerate);
if (offsetR < 0) {
offsetR = bufferSize + offsetR;
}
bufferL[index] += bufferL[offsetL] * feedback;
bufferR[index] += bufferR[offsetR] * feedback;
outblockL[i] = bufferL[index];
outblockR[i] = bufferR[index];
// Update index
index++;
if (index >= bufferSize)
{
index = 0;
}
} }
} }

@ -3,6 +3,8 @@
#include "effect_base.h" #include "effect_base.h"
#define MAX_DELAY_TIME 1
class AudioEffectDelay : public AudioEffect class AudioEffectDelay : public AudioEffect
{ {
public: public:
@ -12,15 +14,15 @@ public:
virtual unsigned getId(); virtual unsigned getId();
protected: protected:
virtual void doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len); virtual void doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len);
// private: private:
// const size_t MaxSampleDelayTime; size_t bufferSize;
// unsigned write_pos_L_; float32_t* bufferL;
// unsigned write_pos_R_; float32_t* bufferR;
// float32_t* buffer_L_; unsigned index;
// float32_t* buffer_R_;
// float32_t delay_time_L_; // Left delay time in seconds (0.0 - 2.0) float32_t timeL; // Left delay time in seconds (0.0 - 2.0)
// float32_t delay_time_R_; // Right delay time in seconds (0.0 - 2.0) float32_t timeR; // Right delay time in seconds (0.0 - 2.0)
// float32_t feedback_; // Feedback (0.0 - 1.0) float32_t feedback; // Feedback (0.0 - 1.0)
}; };
#endif // _EFFECT_DELAY_H #endif // _EFFECT_DELAY_H
Loading…
Cancel
Save