No Audio Output When Running Delay Plugin

Hi, I’m currently using JUCE’s delay line class for a delay plugin. Everything compiles with no errors, and I’m able to run it, but no audio is output. I tested another plugin I wrote, and output audio is as expected, so it’s almost certainly an issue with my code pertaining to delay lines. I’m stumped, so any input is very much appreciated!

Below, I’ve included my code for prepareToPlay, processBlock, and declaring the delay lines. Also, my apologies for the atrocious way in which I deal with stereo input by duplicating everything.

    void prepareToPlay (double sampleRate, int samplesPerBlock) override
    {
        // Sets specs for a JUCE DSP processor
        juce::dsp::ProcessSpec spec;
        spec.maximumBlockSize = samplesPerBlock;
        spec.sampleRate = sampleRate;
        spec.numChannels = getTotalNumOutputChannels();
        
        // Initializes delay line processors
        delayCHNL1.prepare (spec);
        delayCHNL2.prepare (spec);
        
        // Since the delay parameter is limited to a maximum of 1s, the maximum possible delay in samples is sampleRate in samples/s * 1s
        delayCHNL1.setMaximumDelayInSamples (sampleRate);
        delayCHNL2.setMaximumDelayInSamples (sampleRate);
        
        // Delay in seconds is converted to delay in samples
        delayCHNL1.setDelay (delay->get() * sampleRate);
        delayCHNL2.setDelay (delay->get() * sampleRate);
    }
    void processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer&) override
    {
        gainFloat = gain->get();
        feedbackFloat = feedback->get();
        mixFloat = mix->get();
        totalNumInputChannels  = getTotalNumInputChannels();
        
        for (int channel = 0; channel < totalNumInputChannels; ++channel)
        {
            auto* channelData = buffer.getWritePointer (channel);
            
            if (channel == 0)
            {
                for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
                {
                    drySample = channelData[sample];
                    wetSample = delayCHNL1.popSample(channel, -1, true); // Second argument of popSample is -1 to use value from setDelay function
                    
                    // No feedback currently for testing purposes
                    delayCHNL1.pushSample(channel, channelData[sample]);
                    channelData[sample] = (drySample * (1.0f - mixFloat)) + (wetSample * mixFloat); // Mix dry sample with delayed sample
                    channelData[sample] *= gainFloat; // Gain
                }
            }
            else // Handles the second channel for stereo input but doesn't run for mono input
            {
                for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
                {    
                    drySample = channelData[sample];
                    wetSample = delayCHNL2.popSample(channel, -1, true);
                    
                    // No feedback currently for testing purposes
                    delayCHNL2.pushSample(channel, channelData[sample]);
                    
                    channelData[sample] = (drySample * (1.0f - mixFloat)) + (wetSample * mixFloat);
                    channelData[sample] *= gainFloat;
                }
            }
        }
    }
private:
    juce::dsp::DelayLine<float, juce::dsp::DelayLineInterpolationTypes::Thiran> delayCHNL1;
    juce::dsp::DelayLine<float, juce::dsp::DelayLineInterpolationTypes::Thiran> delayCHNL2;

In situations like these you’ll need to use a special skill called… debugging!

Disable things in your code until it starts working again. For example, I would comment out the line that does *= gainFloat; since perhaps that is zero or a really small value.

If that doesn’t make a difference, change the line channelData[sample] = ... to write just the drySample. If that works, write just the wetSample, and so on… until you find the cause of the issue.

Divide and conquer! :smiley: