Basic Question: How to use the new JUCE 6 Delay Line? Giving me errors with simple use

I want to use the new JUCE 6 Delay Line class. I am having trouble figuring out the basic C++ of how to implement this though.

I just simply want to create a delay line, set the maximum number of samples, set the delay time, set the interpolation, and then put in and return a delayed sample. I am just doing in this in my Synth Voice, so it is a per sample process with only one channel.

Under private: for my synth voice, I put:

juce::dsp::DelayLine<float, juce::dsp::DelayLineInterpolationTypes::Linear> testDelay [5000]; 

This was meant to create a float delay line with 5000 max samples and linear interpolation.

Then in my voice where I initialize the voice, I thought I should fill the testDelay with zeros, so I did:

	for (int i = 0; i < 5000; i++) {
		testDelay->pushSample(0, 0);

Then in my per sample processing I tried:

testDelay->pushSample(0, testOscOutput);
testOscOutputDelayed = testDelay->popSample(0, 1.f);

This was supposed to be just a simple 1 sample delay. But it’s not working. When I try to pushSample either on initialization or per sample it just crashes my synth.

What am I supposed to be doing here? What am I doing wrong?


I haven’t used this class, but the first problem is that the square brackets indicate an array, not a passing of parameters to the constructor. you want paranthesis

juce::dsp::DelayLine<float, juce::dsp::DelayLineInterpolationTypes::Linear> testDelay (5000);


@cpr2323 is right about this – that’s probably your issue. It looks like you’re accidentally making an array of 5000 delay lines!

But just FYI, you don’t need to initialize the buffer to zeros – that happens when you call DelayLine::perpare() (or DelayLine::reset()).

By the way, it looks like you’re using the -> operator on the array of DelayLines because that’s probably what the compiler told you, but if you fix the issue with the brackets, you’ll need to use . instead.

The snippets you shared demonstrate that you’re missing a few fundamental C++ language concepts:

  1. pointer syntax vs. object syntax.
    the -> is used with pointers. Pointers are normally declared by naming the type, and then adding a * after it:
    juce::Component* for example.
    the . is used with objects. Objects are declared by writing the type and putting nothing after it:
    juce::Component for example.
    however, raw arrays can be treated like pointers, which is what the C programming language does.

  2. constructor parameters vs. arrays.
    You declared an array that holds 5000 instances of juce::dsp::DelayLine<> when you wrote juce::dsp::DelayLine<> testDelay [5000];
    that array is named testDelay
    each element in the array is one instance of that class.
    Arrays reduce to pointers, which is why the compiler was suggesting you use ->
    writing testDelay->pushSample is the same as writing testDelay[0].pushSample
    When first initialized, testDelay points to the first element in that array. whenever you increment testDelay, you increment which element it points to.
    As others have suggested, what you wanted to write was:
    juce::dsp::DelayLine<args> testDelay(5000);
    A side note: if the juce::dsp::DelayLine<> class did not have a default constructor, your code would have produced a compiler error.

I would recommend brushing up on some C++ basics before trying to use complex, heavily templated classes like those found in the juce::dsp namespace.
There are tons of free resources available these days, such as Or, if you want 1-on-1 help with tons of code reviews of your code, you can check out

Good luck! I hope you found the above information helpful.

Yeah I tried the () brackets initially but you can’t do that under the private section of a synth voice. Oh now I remember it was supposed to be the {} brackets. Haven’t done that in a while. Forgot which type to use. Thanks.

The pointer syntax was being forced on me by Visual Studio though I couldn’t understand why. Now I do - the [] brackets were making it think it was something other than it was. Using {} brackets put it back to normal. Simple mix up. Thanks

Thanks Zac. I think there were two problems.

  1. I didn’t use the right type of brackets (needs { 5000 } not ( 5000 ) or [ 5000 ]) on creation of the delay line.

  2. Then I also needed to still run prepare to tell the delay line how many channels it has.

So this works fine (at least it doesn’t crash):

	juce::dsp::ProcessSpec spec;
	spec.numChannels = 1;
	spec.sampleRate = mSampleRate;
	spec.maximumBlockSize = 5000;
	for (int i = 0; i < 5000; i++) {
		tempDelay.pushSample(0, 0);

And to create it under my private section:

juce::dsp::DelayLine<float, juce::dsp::DelayLineInterpolationTypes::Linear> tempDelay{ 5000 }; 

All good I think.

I know I don’t need to push zeros from your reply - prepare does it for me - but I was just testing. At least no ‘out of range’ vector errors now. So I presume I’m good.


1 Like