Repository navigation
AUv2: deliver queued parameter sets before a state save or restore - #656
drbafflegab wants to merge 2 commits into
Conversation
SetParameter queues values that only Render() and onIdle() deliver, so a save could miss a recent set and a queued set could override a restored state. SaveState and RestoreState now drain the queue first, when onIdle() would, holding _processLock only for the drain.
| const bool rendering = | ||
| _initialized && (_renderedSinceIdle || _idleTicksSinceRender < _idleTicksBeforeFlush); | ||
| if (!_requestedFlush || rendering) return; |
There was a problem hiding this comment.
One gap worth noting: drainParameterEvents() skips the drain while the host is rendering, so both halves of the original bug still happen during playback, not just the restore half the description mentions.
- Save: a
ClassInfoget right after aSetParametersaves the old value, because the set is still queued until the next render. - Restore: values queued before the restore reach the plugin one buffer after
state->load()and overwrite the restored state.
Could you add the save case to the description, and maybe to the comment on drainParameterEvents()?
For restore, a follow-up could throw the pending host parameter events away instead of delivering them. The load supersedes them anyway, and dropping them runs no plugin code, so it could also be done while rendering. The cost is that it still needs _processLock for a moment, and since Render() only try-locks, a render that collides with it outputs one silent block. So it's a trade-off, not a clear win, and I don't think it needs to block this PR.
There was a problem hiding this comment.
Good point! I'v updated the PR description and the comment on drainParameterEvents(). Dropping the queued events on restore sounds like a good follow-up.
When a host sets a parameter, the AUv2 wrapper queues the value. The plugin only gets it on the next render or idle flush.
SaveStateandRestoreStatedon't flush the queue first, so:To reproduce, set a parameter and save the state (
kAudioUnitProperty_ClassInfo) without rendering in between. The saved state has the old value.This PR adds
drainParameterEvents(), which does whatonIdle()does for a pending flush, and only whenonIdle()would: when the plugin is deactivated, or when the host hasn't rendered for a few blocks.SaveStateandRestoreStatecall it before they call the plugin's state extension. It holds_processLockonly for the drain, not across the save or load, so neitherRender()norScheduleParameter()on the audio thread waits for the plugin's state code._idleTicksSinceRendernow starts saturated, so a new instance that hasn't rendered yet counts as stopped.While the host is rendering, the drain is skipped and the next render delivers the queue instead. So during playback, a save can still miss a set made in the last buffer, and a set made just before a restore can still land after it.
Tested with
auval -strict, pluginval (strictness 10, including AU state restoration) and a small AU host that fails without this change and also checks that saving state while rendering costs no block.