Counter-Strike Source: distorted audio
WARNING:EARRAPE
SDL_AUDIODRIVER=alsa fixes the issue
Game is also crashing from Alt+Tab
SDL_AUDIODRIVER=pulseaudio fixed it here, too. The culprit appears to be PipeWire, but it's not clear to me if this is a bug in sdl2-compat, SDL3, the Steam Runtime, or PipeWire itself...my guess is that it has something to do with CS:Source being a 32-bit process, but I don't have more information than that.
This mostly fixes Half-Life 1's audio, as well (#175), more details over there.
Hello, I had a quick look, and didn't see anything obviously wrong in our audio code...
I don't think its related to it being 32-bit, the issue also happens on 64-bit Team Fortress 2.
I found some parts of the desired SDL_AudioSpec were uninitialized, but that also didn't seem to be the culprit.
I don't think SDL_AUDIODRIVER=pulseaudio is the full solution either, as even with that, the audio in-game is higher pitched than with SDL2/Windows.
I wanted to get the output of soundinfo to see more of what the engine thought, but I also can't type with SDL2-compat... >.<
soundinfo on SDL3/sdl2-compat:
Channels: 2
Bits/Sample: 32
Rate: 48000
soundinfo on SDL2:
SDL Audio Device
Channels: 2
Bits/Sample: 16
Rate: 44100
This happens because we ask for AUDIO_S16SYS and we get back AUDIO_F32LSB which is definitely not what we asked for.
The Source Engine doesn't actually check that it got what it wanted, it just assumes that S16 will be everywhere, which honestly isn't that bad of an assumption, given Pipewire does support S16 everywhere...
Not sure why SDL3/SDL2-compat isn't giving us that back on that path.
Found the culprit! We pass in SDL_AUDIO_ALLOW_ANY_CHANGE which obviously we don't want to allow any change.
I will update our back catalogue MP games to remove this flag.
We've hit this in DOSBox-X https://github.com/joncampbell123/dosbox-x/issues/5444 for anyone else interested. I think it would be worth cutting a release just to fix this specific issue as in our case it creates unbearably loud audio. (I've done a PR to fix this upstream to not implicitly pass in SDL_AUDIO_ALLOW_ANY_CHANGE through SDL_OpenAudio)