How do I get the delay to be zero?

39 Views Asked by At

I'm making a ping ping delay plugin in JUCE. It works fine except when the time is set to zero there is a delay. If the time parameter is set to anything other than zero it works perfectly.

Here is the code from the process block:

void AAPDelayCWAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
    juce::ScopedNoDenormals noDenormals;
    auto totalNumInputChannels  = getTotalNumInputChannels();
    auto totalNumOutputChannels = getTotalNumOutputChannels();

    for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
        buffer.clear (i, 0, buffer.getNumSamples());

        // Create dry audio block
        juce::dsp::AudioBlock<float> dryBlock(buffer);

        // Push dry samples to dryWetMixer
        dryWetMixer.pushDrySamples(dryBlock);

        // Set mix value
        dryWetMixer.setWetMixProportion(mDryWet);

        // Access left and right channels seperately
        float* channelDataLEFT = buffer.getWritePointer(0);
        float* channelDataRIGHT = buffer.getWritePointer(1);

        
        for (int i = 0; i < buffer.getNumSamples(); i++)
        {
            // Smoothed Delay value
            float currentDelayTimeSamples = smoothedDelayTime.getNextValue();
            
            float tempLeft = mDelayLine.popSample(0, currentDelayTimeSamples);     
            float inLeft = channelDataLEFT[i];                                      

            float tempRight = mDelayLine.popSample(1, currentDelayTimeSamples);     
            float inRight = channelDataRIGHT[i];                                    

            mDelayLine.pushSample(0, inLeft + (tempRight * mFeedback));             
            mDelayLine.pushSample(1, inRight + (tempLeft * mFeedback));             

            channelDataLEFT[i] = tempRight;                                            
            channelDataRIGHT[i] = tempLeft;                                          

        }

        // Pass wet samples from buffer 
        dryWetMixer.mixWetSamples(buffer);
}

I have tried rearranging the delay loop. I have tried bypassing the value smoothing. I have used the debugger to check if the variable being fed to the popSample line is correct while the plugin is runnning. None of these have shown where the error could be occuring.

Any help would be appreciated. I am not experienced with JUCE or C++ so it could be an easy fix but I cannot find anything.

0

There are 0 best solutions below