for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{ //Set a pointer to read from the main audio buffer.
auto* channelData = buffer.getWritePointer(channel);
//initialize a pointer to read past audio samples at audio.
auto* ringBuffptr = mRingBuf.getReadPointer(channel);
int readIndx; // the index of the samples being read from the buffer.
readIndx = mRingBufferWriteIdx;
//Copy over the block of audio from the main audio buffer to our ring buffer.
mRingBuf.copyFrom(channel, mRingBufferWriteIdx, buffer, channel, 0, buffer.getNumSamples());
int delayInSeconds = (3 * mSampleRate);
for (int i = 0; i < buffer.getNumSamples(); ++i, ++mRingBufferWriteIdx)
{
// advance the modulator signal angle by one increment for the next sample
float LFOsample = std::sin(mCurrentPhase);
//Scale the samples by 5ms of samples
LFOsample *= roundToInt(0.02 * mSampleRate);
LFOsample += roundToInt(0.005 * mSampleRate);
LFOsample *= mLFODepth;
//step back however many samples of audio.
readIndx = mRingBufferWriteIdx - LFOsample;
//wrap the pointer back to the begining of the buffer.
//This is a safety check.
if (readIndx < 0)
readIndx += mRingBufferSize;
readIndx %= mRingBufferSize;
//increment the readIndex to read the delayed samples into the main audio buffer.
channelData[i] = ringBuffptr[readIndx++];
}
// advance mCurrentAngle by N steps
mCurrentPhase += mPhaseChange* buffer.getNumSamples();
mCurrentPhase = fmod(mCurrentPhase, 2 * MathConstants<double>::pi);
}
}
the LFO phase should be updated sample by sample and not once per block. You actually update it numChannels times, each time you’ve processed a channel.
Do you update your ring buffers write index? I am missing the two-part write there, as it might wrap after some time.