Skip to content
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

Audio skipping in Emscripten #4679

Open
weirddan455 opened this issue Aug 22, 2021 · 1 comment
Open

Audio skipping in Emscripten #4679

weirddan455 opened this issue Aug 22, 2021 · 1 comment
Milestone

Comments

@weirddan455
Copy link
Contributor

I've been testing a web build of a game I'm developing. I've gotten things to work but the audio sometimes skips on my web build, especially when the FPS drops. On the native Linux build, there's no audio skipping even when I stress test the renderer and go to low FPS. I've read SDL handles audio on a separate thread so this makes sense.

However, this does not appear to be the case in Emscripten. Audio performance appears to be tied to the main thread in some way. Is this a limitation of Emscripten? Can this be improved on SDL's side? Or is there something special I need to do for Emscripten in my code?

@icculus
Copy link
Collaborator

icculus commented Sep 2, 2021

Emscripten (rather, web browsers generally) run one task at a time, single-threaded. There are exceptions to this, but generally that's true.

Which is to say: the audio upkeep code (which calls your SDL audio callback) doesn't run until your app returns from its mainloop function.

You have to return as fast as possible, but it's possible you can open the SDL audio device with more samples buffered to let the audio continue through drops in framerate.

Eventually we might be able to move audio to a web worker to solve this, but I don't think browsers are there atm.

@slouken slouken added this to the 3.x milestone Nov 7, 2023
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

No branches or pull requests

3 participants