Try to add some delay to OutputChannel

I try to add some delay algotithm to OutputChannel that i will show in this code

void audioDeviceIOCallback (const float** inputChannelData, int numInputChannels,

                            float** outputChannelData, int numOutputChannels,

                            int numSamples) override

{

for (int i = 0; i < numSamples; ++i)

{  

    for (int i = 0; i < numSamples; ++i)

    {

        for (int chan = 0; chan < numOutputChannels; ++chan)

        {

            /// i try to add some delay algorithm around here//

            outputChannelData[chan][i]=inputChannelData[chan][i];

            ///////////////////////////////////////////////////

        }

    }    

}

} 

I try to add many delay algorithm to my code but none seem to work . It only gives a stange sound .

I don't sure that i can add delay algotithm to outputChannel like this or not?

 

 

 

 

 

now i thought that i should use "AudioProcessor" for make delay effect to my input ... am i right ?

ps. i always learn to use juce api with juce demo but there are no "Delay effect example" in juce demo ... and I know i should dig in api document more than this ... but after 2 days of digging , i still don't know how can i use AudioProcessor to make dalay effect for my inputchannel...

If you look at the demo audio plugin, that does contain a demonstration of adding a simple delay.

i have looked at that , but i still don't see the way to use AudioProcess with GuiApplication 

Oh i think i just got a lot of idea from AudioAppExample and Demo audio plugin 

 

thank you ,  Jules !

now i'm using delay algorithm at getNextAudioBlock , It doesnt give a delay sound but something like robot sound ...

 

void LIVESCREEN::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)

{

    

    const int numSamples = bufferToFill.buffer->getNumSamples();

    int channel, dp = 0;

   
    

    AudioSampleBuffer delayBuffer = *new AudioSampleBuffer(2, 48000);

    int delayPosition=0;

    float delay = 0.8;

   

        for (channel = 0; channel < bufferToFill.buffer->getNumChannels(); ++channel)

        {

            float* channelData =  bufferToFill.buffer->getWritePointer (channel);

            float* delayData = delayBuffer.getWritePointer (jmin (channel, delayBuffer.getNumChannels() - 1));

            

            dp = delayPosition;

            

            for (int i = 0; i < numSamples; ++i)

            {

                const float in = channelData[i];

                channelData[i] += delayData[dp];

                delayData[dp] = (delayData[dp] + in) * delay;

                if (++dp >= delayBuffer.getNumSamples())

                    dp = 0;

            }

        }

}