I’m trying to create a simple delay plugin. It has a working feedback, input and output gain, dry/wet knob, but for some reason the sound distorts. Even when turning either gain knob, the signal becomes quieter but it still has the digital distortion sound.
This is my process block. Thanks in advance!
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
auto* channelData = buffer.getWritePointer (channel);
auto* delayData = delayBuffer.getWritePointer(juce::jmin(channel, delayBuffer.getNumChannels() - 1));
dpr = delayReadPosition;
dpw = delayWritePosition;
for (int i = 0; i < numSamples; ++i) {
const float dry = channelData[i];
const float in = applyGain(dry, inGain);
float wetSignal = 0.0;
float out = 0.0;
long rpi = (long)floor(delayData[dpr]); //linear interpolation
wetSignal = delayData[dpr] - (double)rpi;
double dryOut = dry * (1.0 - dryWet);
double wetOut = wetSignal * dryWet;
out = applyGain((dryOut + wetOut), outGain);
delayData[dpw] = in + (wetSignal * feedback);
if (++dpr >= delayBufferLength)
dpr = 0;
if (++dpw >= delayBufferLength)
dpw = 0;
channelData[i] = out;
}
}