# JUCE 6 DelayLine processor

**URL:** <https://forum.juce.com/t/juce-6-delayline-processor/40651>\
**Category:** General JUCE discussion\
**Created:** [July 10, 2020, 2:07pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651 "2020-07-10T14:07:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![RDEvans](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@RDEvans](https://forum.juce.com/u/RDEvans)\
**Post date:** [July 10, 2020, 2:07pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651/1 "2020-07-10T14:07:31Z")

</div>

Hello, I am playing around with the new DSP modules from JUCE 6. I am trying to set the maxDelayTime using the explicit constructor of the DelayLine class, but with no avail. I don’t understand how to instantiate a templated explicit constructor.

Here are the constructors for the DelayLine

```auto
template <typename SampleType, typename InterpolationType = DelayLineInterpolationTypes::Linear>
class DelayLine
{
public:
    
    /** Default constructor. */
    DelayLine();

    /** Constructor. */
    explicit DelayLine (int maximumDelayInSamples);

```

I am doing this in a processorChain. I’ve never used an explicit constructor before, so the concept is a bit foggy. Couple that with instantiation within a processor chain as well as a templated type and I’m totally confused.

I am committed to JUCE 6 and I know I could accomplish this without the new DelayLine class, so I am really only interested in figuring this particular situation out.

Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![kamedin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kamedin/32/11711_2.png) [@kamedin](https://forum.juce.com/u/kamedin)\
**Post date:** [July 10, 2020, 3:23pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651/2 "2020-07-10T15:23:51Z")

</div>

[explicit](https://en.cppreference.com/w/cpp/language/explicit) just means you can’t use the constructor for implicit conversions. For example:

```auto
void someFunction (const DelayLine<float>& delay) ;
// ...
int a = 500;
someFunction(a); // error
someFunction(500); // error
someFunction(DelayLine<float>(a)); // ok
someFunction(DelayLine<float>(500)); // ok
DelayLine<float> delay = 500; // error
DelayLine<float> delay{ 500 }; // ok
someFunction(delay); // ok

```

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [July 10, 2020, 4:19pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651/3 "2020-07-10T16:19:42Z")

</div>

This is not very pretty but it does compile :

```auto
dsp::ProcessorChain<dsp::DelayLine<float>,dsp::Panner<float>> chain;
// to reset the maximum delay time, 
// assign a new instance of the DelayLine at the chain position 0
chain.get<0>() = dsp::DelayLine<float>(10 * 44100);
```

---

<div class="post-metadata">

**Author:** ![RDEvans](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@RDEvans](https://forum.juce.com/u/RDEvans)\
**Post date:** [July 10, 2020, 5:22pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651/4 "2020-07-10T17:22:27Z")

</div>

I can’t tell you how much each example you gave helped. Thank you!

---

<div class="post-metadata">

**Author:** ![RDEvans](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@RDEvans](https://forum.juce.com/u/RDEvans)\
**Post date:** [July 10, 2020, 5:22pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651/5 "2020-07-10T17:22:55Z")

</div>

Thank you, great to hear from one of the royalty of JUCE

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [November 2, 2021, 4:41pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651/6 "2021-11-02T16:41:37Z")

</div>

Hey guys, sorry for dragging up an old thread, but I’m having issues with this myself. I’ve only just started looking into the JUCE DSP classes, so be gentle!

I can easily and quickly create a` dsp::DelayLine` object and use it accordingly, but all attempts to use one within a dsp::ProcessChain have thwarted me. With a non chained `dsp::DelayLine` object I can process my signal as simple as this:

```auto
	void processBlock(AudioBuffer<float>& buffer, MidiBuffer& midiMessages) override
	{
		juce::dsp::AudioBlock<float> block(buffer);
		juce::dsp::ProcessContextReplacing<float> context(block);
		delay.process(context);
	}

```

But if I try this with a delay line that is part of a ProcessorChain I get caught here in the DelayLine::proess method:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/3/3b472b02bb0ccfca8a494fe994a51d2313ffd806.png)

So it works fine on it’s own, but causes an assert when part of a dsp::ProcessorChain. Here is my prepareToPlay() method:

```
void prepareToPlay(double newSampleRate, int blockSize) override
{
	juce::dsp::ProcessSpec spec{ newSampleRate, blockSize, 2 };
	fxChain.prepare(spec);
	fxChain.get<0>() = dsp::DelayLine<float>(44100);
}

```

My `processBlock()` function is the same as the one outlined above, only this time I’m calling `process(context)` on the `fxChain` object.

I’m obviously doing this all wrong so how is one supposed to do this?

p.s. I am not interested in popping and pushing samples to the delay line at this point…

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [November 2, 2021, 4:48pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651/7 "2021-11-02T16:48:04Z")

</div>

What are the values of `inputBlock.getNumChannels()` and `writePos.size()`? That should give you a clue what’s going on.

Your prepareToPlay looks a bit suspicious. If you assign a new delayline like that, it will no longer be “prepared”. Does it work if you assign the new delayline before calling `fxChain.prepare(spec)`?

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [November 2, 2021, 5:00pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651/8 "2021-11-02T17:00:40Z")

</div>

Thanks @reuk for the prompt reply!

> [@reuk](#):
>
> Your prepareToPlay looks a bit suspicious.

Suspicious indeed. It will work if I assign the new delay line before call prepare, so long as I also grab the newly assigned delay and call its `setDelay()` method:

```
void prepareToPlay(double newSampleRate, int blockSize) override
{
	fxChain.get<0>() = dsp::DelayLine<float>(44100);
	auto& del = fxChain.get<0>();
	del.setDelay(20000);
	juce::dsp::ProcessSpec spec{ newSampleRate, blockSize, 2 };
	fxChain.prepare(spec);	
}

```

So I guess this is a solution, but surely there is an easier way of adding a adding a `dsp::DelayLine` to a `dsp::ProcessorChain`? Can I not set the initial delay line when I declare my chain:

`dsp::ProcessorChain < juce::dsp::DelayLine<float>> fxChain;`

I’ve tried all manner of brackets and braces, but can’t seem to figure it out?

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [November 2, 2021, 5:13pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651/9 "2021-11-02T17:13:17Z")

</div>

> [@rory](#):
>
> I’ve tried all manner of brackets and braces, but can’t seem to figure it out?

As far as I was able to gather, there is no way. IMHO the whole ProcessorChain is unwieldy to use and inflexible and one might just as well not bother using it. (It is claimed by some people using it might result in performance optimizations, but I haven’t seen any concrete benchmark data about that.)

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [November 2, 2021, 6:13pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651/10 "2021-11-02T18:13:10Z")

</div>

Thanks @xenakios, if you haven’t figured out a way to do this, then I’ve no hope whatsoever! Not using it is not that big a deal as I’m using an AudioprocessorGraph anyway, so I can quickly set up signal chains there. Just so I’m clear, your criticism is directed at the `dsp::ProcessorChain` rather than the bulk of the DSP classes themselves?

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [November 2, 2021, 6:16pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651/11 "2021-11-02T18:16:03Z")

</div>

Right, I am this case criticizing only the ProcessorChain. Some of the DSP module classes are quite useful, but it’s just in some cases a pain to attempt to use them with the ProcessorChain. (And there are problems also with the ProcessorDuplicator.)

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [November 2, 2021, 6:17pm UTC](https://forum.juce.com/t/juce-6-delayline-processor/40651/12 "2021-11-02T18:17:11Z")

</div>

Thanks, this is good to know 😉
