For the last three days, I've been trying to figure out why there's intermittent popping noises in my browser audio piece. I looked at least ten different possible sources of trouble, like too much volume, too many expensive convolution nodes, or abrupt amplitude cut-offs.
I tried the WebAudio devtools extension and noticed there was high latency variance every time a pop happened. The
extension's documentation says:
If you see a large variance, it means that the system-level audio callback function has unstable timing that can lead to poor audio stream quality.
So, I tried it on Katt's Mac, and it was fine. Zero pops.
Good god.
So, I thought, the Curse of Linux strikes again!
But I had actually misinferred the cause of the "system-level audio callback function has unstable timing" bit. I thought this meant that my audio system was responding inconsistently. Then, I found
this hero's answer:
The likely issue for crackling sounds on Ubuntu 24.04 is that the distro has been switching over to pipewire and it runs a conversion service from pulse audio, namely pipewire-pulse.
The challenge is that many apps don't directly talk to piepewire, but do it through JACK and/or especially pulse itself, hence sound data needs to be moved though additional hops.
The default time buffers for pipewire-pulse is 2.7 ms, which means that an application needs to be able to fill sound content every 2.7 ms, otherwise pipewire will send to the audio device whatever was previously filled and potentially some random data, hence the crackling.
2.7 ms is quite a stringent time, especially for applications which don't have dedicated threads for audio (likely Proton/wine/games) and/or when running on old CPUs - hence one way to limit cracking is to tell pipewire-pulse to set a larger time buffer, albeit adding a delay to when the sound is sent to the audio device.
So, the issue was that Firefox and Chromium were not keeping up with the 2.7 ms callback asking for audio from the system, which that devtools extension seems to have interpreted as the callback from the system coming in inconsistently?
Either way, bumping the latency setting up to 5.6 ms took care of the pops.
Credit to Apple, though, for configuring their audio system in a reasonable way by default.