sdl2-compat icon indicating copy to clipboard operation
sdl2-compat copied to clipboard

Counter-Strike Source: distorted audio

Open RevengeRip opened this issue 1 year ago • 1 comments

src.webm

RevengeRip avatar Jun 26 '24 17:06 RevengeRip

WARNING:EARRAPE SDL_AUDIODRIVER=alsa fixes the issue Game is also crashing from Alt+Tab

RevengeRip avatar Jun 26 '24 17:06 RevengeRip

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.

icculus avatar Jan 07 '25 08:01 icculus

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.

misyltoad avatar Jan 30 '25 00:01 misyltoad

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.

misyltoad avatar Jan 30 '25 00:01 misyltoad

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

misyltoad avatar Jan 30 '25 01:01 misyltoad

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

misyltoad avatar Jan 30 '25 01:01 misyltoad

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.

misyltoad avatar Jan 30 '25 01:01 misyltoad

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.

misyltoad avatar Jan 30 '25 01:01 misyltoad

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)

Jookia avatar Jan 30 '25 23:01 Jookia