Lookahead

How do you implement lookahead?

For example to make sure your plugin is able to process a big number of samples (bigger than samplesPerBlock) before returning a result.

you create a buffer to gather enough input samples for your algorithm.
everytime the DAW call process, you add the incoming samples to the buffer.
Once you have enough samples in the buffer, process them into an output buffer.
take as many samples from the output buffer as the DAW is expecting, and output them gradually during each process call.

         ------------------------PLUGIN-------------
[DAW] -> [[INPUT BUFFER]->[PROCESS]->[OUTPUTBUFFER]]  -> [DAW]
1 Like

To clarify,
If you expect things to work properly, you should also report the host with the latency you need for the lookahead.

You can even test this initial building block just by creating 2 exact audio signals, inverting phase on one of them, then adding your audio plug-ins while just going through your buffer doing nothing.

If indeed you report and delay correctly, any host with delay compensation should null out.

2 Likes

Thank you so much Jeff and TTG.

It makes perfect sense. I will try it.

setLatencySamples() in the processor is used to define the latency of the plugin. i always call it at the end of prepareToPlay, because usually sampleRate has an influence on the latency. if your plugin has a dry/wet mix make sure to have a feed-forward delay on the dry signal that compensates for the latency, so that it aligns with the signal that you have when the plugin is deactivated. btw “feed forward delay” just means a delay that doesn’t have feedback. make sure to implement processBlockBypass too. a bypassed plugin still has latency and needs to compensate with a delay because of that. depending on your implementation your wet signal needs a feed forward delay too. your wet ff delay works if 50% mix on a gain matched signal is a sound without weird comb filter artefacts. have a wet gain parameter to make it easy to gain match the mix knob.

Following your advice I was able to implement lookahead, thanks.

I used an array as a circular buffer, double the size of the sample count to look ahead.

Andres

1 Like