From b3c47df0c8ac4202d66f4ff7a7c065b6ae46ff14 Mon Sep 17 00:00:00 2001 From: Yamagi Date: Wed, 7 Aug 2024 11:51:11 +0200 Subject: [PATCH] Don't overwrite SDLs audio driver selection. Hardcoding default driver for some of the supported platform is a remnant of SDL 1.2 and hasn't been necessary since SDL 2.0 a long time ago. In fact it has a high properbility to break things, SDL could easily end up with a non working driver. When `s_sdldriver` is set to the newly introduced value `auto` the driver is selected by SDL. In all other cases the string is the driver name which SDL will be forced to. This doesn't fix existing configs. Since the OpenAL sound backend has been the default for nearly 15 years and we haven't received bug reports for some other problem with the SDL sound backend in the past, I'm half sure that there are next to users out there. These can reset the cvar by hand if necessary. Closes #1132. --- doc/040_cvarlist.md | 5 +++++ src/client/sound/sdl.c | 36 ++++++++++++------------------------ 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/doc/040_cvarlist.md b/doc/040_cvarlist.md index db4bab1c..e8612c34 100644 --- a/doc/040_cvarlist.md +++ b/doc/040_cvarlist.md @@ -300,6 +300,11 @@ it's `+set busywait 0` (setting the `busywait` cvar) and `-portable` is much more reliable than the classic sound system, especially on modern systems like Windows 10 or Linux with PulseAudio. +* **s_sdldriver**: Can be set to the name of a SDL audio driver. If set + to `auto`, SDL chooses the driver. If set to anything else the given + driver is forced, regardless if supported by SDL or the platform or + not. + * **s_underwater**: Dampen sounds if submerged. Enabled by default. * **s_occlusion_strength**: If set bigger than `0` sound occlusion effects diff --git a/src/client/sound/sdl.c b/src/client/sound/sdl.c index 79af2d67..08110690 100644 --- a/src/client/sound/sdl.c +++ b/src/client/sound/sdl.c @@ -50,7 +50,6 @@ #define SDL_LOOPATTENUATE 0.003 /* Globals */ -static cvar_t *s_sdldriver; static int *snd_p; static sound_t *backend; static portable_samplepair_t paintbuffer[SDL_PAINTBUFFER_SIZE]; @@ -1352,18 +1351,13 @@ SDL_BackendInit(void) int sndfreq = (Cvar_Get("s_khz", "44", CVAR_ARCHIVE))->value; int sndchans = (Cvar_Get("sndchannels", "2", CVAR_ARCHIVE))->value; -#ifdef _WIN32 - s_sdldriver = (Cvar_Get("s_sdldriver", "directsound", CVAR_ARCHIVE)); -#elif __linux__ - s_sdldriver = (Cvar_Get("s_sdldriver", "alsa", CVAR_ARCHIVE)); -#elif __APPLE__ - s_sdldriver = (Cvar_Get("s_sdldriver", "CoreAudio", CVAR_ARCHIVE)); -#else - s_sdldriver = (Cvar_Get("s_sdldriver", "dsp", CVAR_ARCHIVE)); -#endif + cvar_t *s_sdldriver = (Cvar_Get("s_sdldriver", "auto", CVAR_ARCHIVE)); - snprintf(reqdriver, sizeof(reqdriver), "%s=%s", "SDL_AUDIODRIVER", s_sdldriver->string); - putenv(reqdriver); + if (strcmp(s_sdldriver->string, "auto") != 0) + { + snprintf(reqdriver, sizeof(reqdriver), "%s=%s", "SDL_AUDIODRIVER", s_sdldriver->string); + putenv(reqdriver); + } Com_Printf("Starting SDL audio callback.\n"); @@ -1518,19 +1512,13 @@ SDL_BackendInit(void) int sndbits = (Cvar_Get("sndbits", "16", CVAR_ARCHIVE))->value; int sndfreq = (Cvar_Get("s_khz", "44", CVAR_ARCHIVE))->value; int sndchans = (Cvar_Get("sndchannels", "2", CVAR_ARCHIVE))->value; + cvar_t *s_sdldriver = (Cvar_Get("s_sdldriver", "auto", CVAR_ARCHIVE)); -#ifdef _WIN32 - s_sdldriver = (Cvar_Get("s_sdldriver", "directsound", CVAR_ARCHIVE)); -#elif __linux__ - s_sdldriver = (Cvar_Get("s_sdldriver", "alsa", CVAR_ARCHIVE)); -#elif __APPLE__ - s_sdldriver = (Cvar_Get("s_sdldriver", "CoreAudio", CVAR_ARCHIVE)); -#else - s_sdldriver = (Cvar_Get("s_sdldriver", "dsp", CVAR_ARCHIVE)); -#endif - - snprintf(reqdriver, sizeof(reqdriver), "%s=%s", "SDL_AUDIODRIVER", s_sdldriver->string); - putenv(reqdriver); + if (strcmp(s_sdldriver->string, "auto") != 0) + { + snprintf(reqdriver, sizeof(reqdriver), "%s=%s", "SDL_AUDIODRIVER", s_sdldriver->string); + putenv(reqdriver); + } Com_Printf("Starting SDL audio callback.\n");