I have a filter that uses a large FFT that is not always needed depending on user settings. I notify the DAW of it’s latency in both OnReset() and OnActivate() but would like to eliminate this latency when the filter is not required (turned off by the user).
I am concerned from past experience that attempting to change latency after a plugin is constructed can cause the DAW to crash - but I see other plugins doing it successfully - even while the DAW transport is running - so there must be a “right way”.
What is the “right way”/safe way to change latency at run time in IPlug?
I have tried an approach that seems to work.
When I turn the filter On/Off I set a bool variable in OnParam change I named “ChangeLatency”. At the end of the ProcessBlock - outside the “for” loop - I check ChangeLatency and, if TRUE, I inform the host of the new latency like so:
if (GetLatency() != TotalLatency) SetLatency(TotalLatency);
ChangeLatency = false;
It seems to work OK and sets the correct latency even while the transport is running. It’s not efficient to check that variable on every ProcessBlock but the CPU cost, it seems, is negligible.
Does anyone see any potential problems with this - or does it look like the correct approach?
1 Like