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

SDL3: Constant crackling sound in 02-simple-playback-callback on Debian with Chromium and Firefox #11930

Open
milq opened this issue Jan 12, 2025 · 8 comments
Assignees
Milestone

Comments

@milq
Copy link

milq commented Jan 12, 2025

Description:
When running in the web the 02-simple-playback-callback audio example from the SDL3 repository (link), a persistent crackling sound is heard.

Steps to reproduce:

  1. Navigate to the SDL3 audio example: 02-simple-playback-callback.
  2. Execute the example in the browser.
  3. Observe the constant crackling sound during audio playback.

Expected behavior:
Audio should play smoothly without any crackling or artifacts.

Actual behavior:
A constant crackling sound is present during audio playback.

Environment:

  • Operating System: Debian GNU/Linux 12 (Bookworm)
    • Kernel Version: 6.1.0-29
    • Custom Kernel Version: 6.1.123-1 (Debian customized)
  • Browsers Affected:
    • Chromium: Version 131.0.6778.264 (Official Build) built on Debian GNU/Linux 12 (Bookworm) (64-bit)
    • Firefox: Version 128.6.0esr (64-bit)
  • Hardware:
    • Desktop:
      • CPU: 11th Gen Intel® Core™ i5-11600 @ 2.80GHz
      • GPU: Integrated Graphics
      • RAM: 16 GB
    • Laptop:
      • CPU: 8th Gen Intel® Core™ i5-8365U @ 1.60GHz
      • GPU: Integrated Graphics
      • RAM: 16 GB

Additional Information:
The issue has been consistently reproduced on two separate machines with similar configurations. It is suspected that the threading implementation in Emscripten might be causing the crackling sound in the audio playback example.

@Semphriss
Copy link
Contributor

In case it helps with debugging: I tried on my device (Ubuntu 24.04, Linux 6.8.0-51-generic, Firefox 134.0) and the example works fine (a constant sine wave). I haven't tried with the exact same configuration, but it might probably be an OS-specific issue.

@icculus
Copy link
Collaborator

icculus commented Jan 13, 2025

Try the same example with a massive buffer size:

https://examples.libsdl.org/SDL3/audio/02-simple-playback-callback/?SDL_AUDIO_DEVICE_SAMPLE_FRAMES=8192

And let me know if it still crackles.

@milq
Copy link
Author

milq commented Jan 13, 2025

Try the same example with a massive buffer size:

https://examples.libsdl.org/SDL3/audio/02-simple-playback-callback/?SDL_AUDIO_DEVICE_SAMPLE_FRAMES=8192

And let me know if it still crackles.

No, the constant crackling sound isn't happening anymore! At first, it was a bit audible the crackling sound (both in Chromium and Firefox), but once it stabilized, it could be heard clearly.

Update: I am using Xfce 4.18.2.

@icculus icculus self-assigned this Jan 13, 2025
@icculus icculus added this to the 3.2.0 milestone Jan 13, 2025
@icculus icculus added the icculus-priority Things @icculus is looking at within a larger milestone. label Jan 13, 2025
icculus added a commit that referenced this issue Jan 13, 2025
Some systems seem to not keep up with the smaller buffer.

Reference Issue #11930.
@icculus
Copy link
Collaborator

icculus commented Jan 13, 2025

Try this one now, without any URL parameters added to it:

https://examples.libsdl.org/SDL3/audio/03-load-wav/

If it doesn't crackle, we're good to go here.

@milq
Copy link
Author

milq commented Jan 13, 2025

That example you attached worked without having to multiply the buffer size by two (although I always hear the crackling sound from time to time). Moreover, I'm currently testing starting from the original example 4, and I’m not having any issues in Emscripten (maybe because I'm running in localhost?). That is, audio examples 1, 3, and 4 worked fine for me without multiplying the buffer size by two. The problem lies with example 2, which uses a callback and a background thread. This one still fails for me now:

https://examples.libsdl.org/SDL3/audio/02-simple-playback-callback/

Perhaps it's just me, but it's specifically with this example and the configuration I shared.

@icculus
Copy link
Collaborator

icculus commented Jan 14, 2025

Hmm, yeah, I can trigger this if I cook all my CPU cores, like running a build with the web browser in the background.

(Obnoxious audio in this clip.)

trim.479390D0-AABF-4ECC-986F-BCBAF7C9EAA9.MOV

Even if I set the buffer size to be massive, it still has issues under external load. There's probably not much I can do about that.

@milq
Copy link
Author

milq commented Jan 14, 2025

I am trying to export the example to support threads on the web. However, the web requires a cross-origin isolated website. On itch.io, it allows the experimental Shared Buffed Array. If the exported example does not support threads, it is more prone to performance and audio issues. Right now, I'm trying to compile the example in Emscripten with SHELL:-s SHARED_MEMORY=1 to test if audio playback doesn't have the crackling sound using threads. But I cannot do that because --shared-memory is disallowed by SDL_atomic.c.o because it was not compiled with 'atomics' or 'bulk-memory' features. I will keep trying and testing with this and other things.

@icculus
Copy link
Collaborator

icculus commented Jan 15, 2025

(I think you just need -pthread on your compile and link command lines to enable it, but I could be misremembering.)

SDL works with threaded Emscripten, but even when built with thread support, it doesn't use a thread for audio, because the browser interface we use for it just runs in idle time in the main thread.

The "threaded" solution is to use an AudioWorklet, but it literally doesn't work with pthreads, so it was a non-starter for SDL (and almost everything else, too).

@icculus icculus removed the icculus-priority Things @icculus is looking at within a larger milestone. label Jan 15, 2025
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