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.
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
@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:
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.
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 https://www.learncpp.com. Or, if you want 1-on-1 help with tons of code reviews of your code, you can check out https://www.programmingformusicians.com/
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
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.