Hey there, I’m quite new to the realm of audio development and still am trying to learn the basics, I made this simple delay plugin in JUCE here is the core processBlock code:
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
float* channelData = buffer.getWritePointer(channel);
const int bufferLength = buffer.getNumSamples();
const int circBuffLength = circBuff.getNumSamples();
const float* mainReadPointer = buffer.getReadPointer(channel);
const float* circBufferReadPointer = circBuff.getReadPointer(channel);
float* circBuffWrite = circBuff.getWritePointer(channel);
const float delayInSamples = delayTime * getSampleRate() / 1000;
for (int i = 0; i < bufferLength; ++i)
{
float fIndx = writePosish - delayInSamples;
if (fIndx < 0)
fIndx+= circBuffLength;
float sIndx = writePosish - (delayInSamples+1);
if (sIndx< 0)
sIndx += circBuffLength;
float frac = delayInSamples - int(delayInSamples);
circBuffWrite[writePosish] = (float(50.0 / 100.0)*((frac*circBufferReadPointer[int(sIndx)]) + (float(1.0-frac)* circBufferReadPointer[int(fIndx)])))+mainReadPointer[i];
writePosish++;
if (writePosish == delayBuffLength)
writePosish = 0;
channelData[i] = (float(50.0 / 100.0) * ((frac * circBufferReadPointer[int(sIndx)]) + (float(1.0 - frac) * circBufferReadPointer[int(fIndx)]))) + mainReadPointer[i];
}
}
and prepareToPlay:
void PluginPrototypeAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
const int numInputChannels = getTotalNumInputChannels();
// Use this method as the place to do any pre-playback
// initialisation that you need..
writePosish = 0;
delayBuffLength = 2 * sampleRate;
circBuff.setSize(numInputChannels, delayBuffLength);
circBuff.clear();
}
the delay seems to be working fine on some millisecond values and not in others, for instance 720 works fine but 714 gives me bit reduced filthy noise like delay tails, also every value seems to be working half the value it shows, like 200 milliseconds produces a 100 milliseconds delay, I was wondering if anyone would be kind enough to point out the errors and bugs in my poorly written beginner code, thanks in advance!
