I’ve seen topics around about setLatencySamples but not quite the one I’m running into exactly… There is a clause in the JUCE VST3 wrapper that I don’t quite understand the significance of, and it is causing a bug in my plugin where latency is not reported correctly when the sample rate is changed.
A summary–
In prepareToPlay, I am using the sample rate to calculate my plugin’s latency and report it to the host using setLatencySamples. I followed this call through to the VST3 wrapper and found this snippet in audioProcessorChanged:
if (! inSetupProcessing)
componentRestarter.restart (flags);
inSetupProcessing seems to be in place to avoid calling the restarter during prepareToPlay, which means my setLatencySamples gets ignored. (thus the bug on sample rate changes) But since my latency changes are directly dependent on sample rate changes, where else should I be calling setLatencySamples such that the change goes through? (note that the AAX and AU wrappers do not seem to behave this way)
I believe you can call setLatencySamples() from the processBlock() function, so you could calculate it in the prepareToPlay(), store it as a member, then later set it in the audio callback.
Yeah, the docs say "The processor should call this as soon as it can during initialisation, and can call it later if the value changes." but it doesn’t explicitly say whether or not it’s safe to call on the audio thread!
It’s not if it’s unsafe… if you look into the wrapper code, you’ll find it’s set asynchronously – I found it unreliable setting it synchronously from the audio thread in some hosts (Ableton Live)… but never experienced any crashes or anything.
Please could you let us know which host you’re using for testing? I tried modifying the DSPModulePluginDemo to set its latency to a fraction of the current sample rate inside its prepareToPlay. When I load the VST3 in REAPER, the latency is correctly reported after changing the host sample rate. It’s possible that the behaviour you’re seeing only affects certain DAWs.
Testing in Ableton, I can reproduce the buggy behaviour. It would still be useful to know which host is causing problems for you, so that I can verify that the fix for Ableton also works for you.
Having a problem, where using several FIIR filters, and processing all of them introduces an expected delay. Now I am trying to call setLatencySamples() to report this delay, but it does not seem to work.
On playback there is enough wait time between each audioBlock that it works fine, but if the audio is bounced offline then the filters’ processing is lost.
If I understand correctly, it sounds like the bug you are experiencing is that delay comp is working in your DAW in realtime processing, but not with offline processing, correct? If so, do you mind creating a new topic so that it will be easier for other folks to find when searching? (The original topic is a bit different, where setLatencySamples was specifically not working only when called from prepareToPlay) Happy to respond in your new topic to try and help if I can. (Or better yet, maybe you’ll get some of the JUCE experts in there as well!)