fix audout events being missed. #683
Open
+14
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
audout has always suffered from a bug where the playback would become messed up when resuming from sleep.
Looking into the issue, i noticed that the distorted playback sounds exactly like samples being dropped, as if we are working with a single audio buffer.
Looking at
audoutWaitPlayFinish
, the bug is very clear. Basically, when the switch goes to sleep, both (or all) audio buffers have finished playing, so the event is fired multiple times. In the next call toaudoutWaitPlayFinish
, the event is waited on, which returns immediately because the event was already fired. However, this clears the event, so the next call will actually block until that single buffer has finished, which results in dropped samples. Another way of looking at the bug is like this.The fix is to first change the event to not auto clear (so that we can clear it ourselves) and then poll
audoutGetReleasedAudioOutBuffer
before waiting on the event. In the above example, this would return immediately to the first 2 calls after the sleep, which fixes the issue. IfaudoutGetReleasedAudioOutBuffer
fails, then we wait on the event, and the code functions the same as before.Also, if this fix gets merged, could we merge back audout into SDL2 rather than using audren? As i understand, audren was added because of this bug, however audren has its own limitations such as session limits. I would open an issue / PR for that repo, but i am still for no reason banned.