I’ve made a simple delay plugin with a variable delay length (10-1000ms). I’ve noticed when adjusting the delLength in RT it produces some annoying distortion. I’m going to try adding some interpolation to move more smoothly between the adjusted delLength values, but, I wanted to post my algorithm to see if anyone had any thoughts as to why it might be distorting/possible approaches to fix it:
void OutputCollinDelayAudioProcessor::applyDelay (AudioBuffer<float>& buffer, AudioBuffer<float>& delayBuffer)
{
const int numSamples = buffer.getNumSamples();
int dpr, dpw;
int sampleRate = getSampleRate();
const float feedback = *parameters.getRawParameterValue ("feedback");
const float dryWetRatio = *parameters.getRawParameterValue ("wetDry");
const float delLength = *parameters.getRawParameterValue ("time");
delayReadPosition_ = (int)(delayWritePosition_ - (delLength * sampleRate) + delayBufferLen_) % delayBufferLen_;
float dryMix = (1.0-dryWetRatio);
float wetMix = dryWetRatio;
for (int channel = 0; channel < getTotalNumOutputChannels(); ++channel)
{
dpr = delayReadPosition_;
dpw = delayWritePosition_;
float* const channelData = buffer.getWritePointer (channel);
float* delayData = delayBuffer_.getWritePointer (jmin (channel, delayBuffer_.getNumChannels() - 1));
for (int i = 0; i < numSamples; ++i)
{
const float in = channelData[i];
float out = 0.0;
out = (dryMix * in + wetMix * delayData[dpr]);
delayData[dpw] = in + (delayData[dpr] * feedback);
++dpr %= delayBufferLen_;
++dpw %= delayBufferLen_;
channelData[i] = out;
}
}
delayReadPosition_ = dpr;
delayWritePosition_ = dpw;
}