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.
This commit is contained in:
Yamagi 2024-08-07 11:51:11 +02:00
parent 3aa051c6d2
commit b3c47df0c8
2 changed files with 17 additions and 24 deletions

View file

@ -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 is much more reliable than the classic sound system, especially on
modern systems like Windows 10 or Linux with PulseAudio. 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_underwater**: Dampen sounds if submerged. Enabled by default.
* **s_occlusion_strength**: If set bigger than `0` sound occlusion effects * **s_occlusion_strength**: If set bigger than `0` sound occlusion effects

View file

@ -50,7 +50,6 @@
#define SDL_LOOPATTENUATE 0.003 #define SDL_LOOPATTENUATE 0.003
/* Globals */ /* Globals */
static cvar_t *s_sdldriver;
static int *snd_p; static int *snd_p;
static sound_t *backend; static sound_t *backend;
static portable_samplepair_t paintbuffer[SDL_PAINTBUFFER_SIZE]; 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 sndfreq = (Cvar_Get("s_khz", "44", CVAR_ARCHIVE))->value;
int sndchans = (Cvar_Get("sndchannels", "2", CVAR_ARCHIVE))->value; int sndchans = (Cvar_Get("sndchannels", "2", CVAR_ARCHIVE))->value;
#ifdef _WIN32 cvar_t *s_sdldriver = (Cvar_Get("s_sdldriver", "auto", CVAR_ARCHIVE));
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); if (strcmp(s_sdldriver->string, "auto") != 0)
putenv(reqdriver); {
snprintf(reqdriver, sizeof(reqdriver), "%s=%s", "SDL_AUDIODRIVER", s_sdldriver->string);
putenv(reqdriver);
}
Com_Printf("Starting SDL audio callback.\n"); Com_Printf("Starting SDL audio callback.\n");
@ -1518,19 +1512,13 @@ SDL_BackendInit(void)
int sndbits = (Cvar_Get("sndbits", "16", CVAR_ARCHIVE))->value; int sndbits = (Cvar_Get("sndbits", "16", CVAR_ARCHIVE))->value;
int sndfreq = (Cvar_Get("s_khz", "44", CVAR_ARCHIVE))->value; int sndfreq = (Cvar_Get("s_khz", "44", CVAR_ARCHIVE))->value;
int sndchans = (Cvar_Get("sndchannels", "2", 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 if (strcmp(s_sdldriver->string, "auto") != 0)
s_sdldriver = (Cvar_Get("s_sdldriver", "directsound", CVAR_ARCHIVE)); {
#elif __linux__ snprintf(reqdriver, sizeof(reqdriver), "%s=%s", "SDL_AUDIODRIVER", s_sdldriver->string);
s_sdldriver = (Cvar_Get("s_sdldriver", "alsa", CVAR_ARCHIVE)); putenv(reqdriver);
#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);
Com_Printf("Starting SDL audio callback.\n"); Com_Printf("Starting SDL audio callback.\n");