Skip to content

fix audout events being missed. #683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ITotalJustice
Copy link
Contributor

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 to audoutWaitPlayFinish, 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.

// push 2 buffers.
audoutAppendAudioOutBuffer(buf[0]) // push buf 0
audoutAppendAudioOutBuffer(buf[1]) // push buf 0

// sleep long enough for both buffers to finish (simulating sleep).
svcSleepThread(1e+9);

// audio dropouts here because it will only function on 1 buffer. 
for (;;) {
  AudioOutBuffer* released;
  audoutWaitPlayFinish(&released, -1);

  audoutAppendAudioOutBuffer(released);
}

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. If audoutGetReleasedAudioOutBuffer 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant