If you leave out the sr assignment in your Csound header section, i.e, sr = 44100, which Cabbage leaves out by default, then sr will always be equal to the host SR. If you change the host SR, sr will also change. In fact, if you change the host SR, Csound get recompiled with the new SR. But you shouldn’t need to concern yourself with that. It should be seamless.
You won’t be able to dynamically change the latency as it needs to be broadcast to the host before you start playback. If you leave it out, the PDC should be equal to the ksmps, which should be enough to cope with most situations. If you set latency yourself you might be asking for trouble.
When you load your Cabbage plugin, the host will register the PDC and run everything accordingly. I don’t think there is any throttling taking place. Throttling plugins is not a great look for a host, but perhaps some do. I’m not aware of any, but I don’t live in that world
To be fair, I hadn’t even considered that I could calculate latency and communicate that to the DAW. But if I gave it the wrong value it could either incorrectly compensate (more likely, I guess?) or throttle performance so that the defined latency was realized.
I could imagine a plug-in having variable latency depending on what it is doing, but maybe that’s evidence of poor design.
Thank you. Then should I update dynamically ksmps based on sr?
I know the delay in my plugin is 20ms, so based on sr and this value I can convert it in a # of samples and change ksmps, without declaring the latency. I don’t know if changing the sample rate in a DAW will update this value but at least I know it will work when the project loads.
I think Kzz’s reply makes the most sense here. The reported plugin latency will assumedly be used by the host to delay all other tracks to come out phase synchronized with the sound from the track that the effect is on. Since it is difficult (within Csound/Cabbage) to get the host sr before the plugin starts Csound running (and by that time it is too late to modify the latency reported to the host). You could set a reported latency to be the maximum within a reasonable range of sr choices, and then adjust (with an extra delay at the end of your plugin processing) so that the actual latency matches the latency you have reported to the host. This way, your Cabbage plugin audio will come out phase synced to other tracks in the DAW project (assuming the user has enabled PDC - plugin latency compensation - in the DAW)