# dsp::DelayLine feedback?

**URL:** <https://forum.juce.com/t/dsp-delayline-feedback/42566>\
**Category:** Audio Plugins\
**Created:** [November 4, 2020, 3:03am UTC](https://forum.juce.com/t/dsp-delayline-feedback/42566 "2020-11-04T03:03:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![erthal11](https://avatars.discourse-cdn.com/v4/letter/e/ac8455/32.png) [@erthal11](https://forum.juce.com/u/erthal11)\
**Post date:** [November 4, 2020, 3:03am UTC](https://forum.juce.com/t/dsp-delayline-feedback/42566/1 "2020-11-04T03:03:48Z")

</div>

So i’m trying to add a feedback functionality to my plugin using the delayLine dsp module, although i’m sure i’m doing it wrong… I was able to set the delay rate, yet now that i’m trying different ways for feeding back using that inner-loop i get some really weird yet interesting noises… (Volume Caution):  
[https://drive.google.com/file/d/1t2vytVAAifeuGNClVgwVxi6\_8xAPnaPR/view?usp=sharing](https://drive.google.com/file/d/1t2vytVAAifeuGNClVgwVxi6_8xAPnaPR/view?usp=sharing))  
At least that last bit at the end i though was pretty cool lol.  
At one point i thought i even blew out my speakers…  
Anyway, any advice on how to do this? I know i should be popping back out all those samples

```
    for (int sample = 0; sample<buffer.getNumSamples(); ++sample)
    {
        
        delayLine.setDelay(noteMult(sliderRateValue->load()) * sixtyFourthNote);
        delayLine.pushSample(channel, channelData[sample]);
        
        //samplesToPop initialized at 1
        for (int i=0; i<samplesToPop; i++)
        {
        channelData[sample] += delayLine.popSample(channel);
        }
        
        samplesToPop = 0;
        
        for (int fb = 0; fb<feedBackValue->load(); ++ fb)
        {
            delayLine.pushSample(channel, channelData[sample]);
            samplesToPop ++;
        }
        
    }
```

---

<div class="post-metadata">

**Author:** ![ujam](https://avatars.discourse-cdn.com/v4/letter/u/2bfe46/32.png) [@ujam](https://forum.juce.com/u/ujam)\
**Post date:** [November 4, 2020, 8:25am UTC](https://forum.juce.com/t/dsp-delayline-feedback/42566/2 "2020-11-04T08:25:42Z")

</div>

First, you can probably call setDelay() once at the start as it’s not changing so often.

Then for each sample you only want to push one sample into the delay line (including the feedback) and pop one out, so something like:

```
float output;
float feedback = feedBackValue->load(); //needs scaling 0.0 to 1.0?

for (int sample = 0; sample<buffer.getNumSamples(); ++sample)
{
    output = delayLine.popSample(channel);
    delayLine.pushSample(channel, channelData[sample] + feedback * output);
    channelData[sample] += output;
}
```

---

<div class="post-metadata">

**Author:** ![erthal11](https://avatars.discourse-cdn.com/v4/letter/e/ac8455/32.png) [@erthal11](https://forum.juce.com/u/erthal11)\
**Post date:** [November 4, 2020, 5:29pm UTC](https://forum.juce.com/t/dsp-delayline-feedback/42566/3 "2020-11-04T17:29:31Z")

</div>

I get your logic, but i’m still not getting the right sound with that although it’s definitely in the right path.

> **[error2.mp3](https://drive.google.com/file/d/15orEwyyCZpkksQZW29dVXB1H_Rr-W9eH/view?usp=sharing)**
>
> Google Drive file.

  
I also tried looking at Joshua’s basic delay implementation on his git but i don’t entirely understand his code

---

<div class="post-metadata">

**Author:** ![erthal11](https://avatars.discourse-cdn.com/v4/letter/e/ac8455/32.png) [@erthal11](https://forum.juce.com/u/erthal11)\
**Post date:** [November 5, 2020, 2:43am UTC](https://forum.juce.com/t/dsp-delayline-feedback/42566/4 "2020-11-05T02:43:44Z")

</div>

Update: You were correct, problem was i had implemented my delay rate wrong for the value at 1, i had it return 0 delay and that was messing things up. Thanks!
