snd_sdl.c: pass NULL as the 'obtained' spec to SDL_OpenAudio():

this way, SDL will convert to hardware format for us if needed.
most of the times we do get what we want. however, for example,
the WASAPI backend of SDL2 returns AUDIO_F32LSB as the obtained
format (which is not an SDL thing but a WASAPI thing) and we do
not support that. the SDL2.dll we ship with has WASAPI disabled,
but if the user replaces our dll with a one with WASAPI enabled
(official libsdl.org build or his own build) then we refuse the
obtained AUDIO_F32LSB format and run without sound.  after this
patch, such a thing is transparent to us.

git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1639 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Ozkan Sezer 2019-09-20 18:40:00 +00:00
parent e04c0b49af
commit 21915e956c

View file

@ -80,7 +80,7 @@ static void SDLCALL paint_audio (void *unused, Uint8 *stream, int len)
qboolean SNDDMA_Init (dma_t *dma)
{
SDL_AudioSpec desired, obtained;
SDL_AudioSpec desired;
int tmp, val;
char drivername[128];
@ -91,7 +91,7 @@ qboolean SNDDMA_Init (dma_t *dma)
}
/* Set up the desired format */
desired.freq = tmp = snd_mixspeed.value;
desired.freq = snd_mixspeed.value;
desired.format = (loadas8bit.value) ? AUDIO_U8 : AUDIO_S16SYS;
desired.channels = 2; /* = desired_channels; */
if (desired.freq <= 11025)
@ -108,39 +108,25 @@ qboolean SNDDMA_Init (dma_t *dma)
desired.userdata = NULL;
/* Open the audio device */
if (SDL_OpenAudio(&desired, &obtained) == -1)
if (SDL_OpenAudio(&desired, NULL) == -1)
{
Con_Printf("Couldn't open SDL audio: %s\n", SDL_GetError());
SDL_QuitSubSystem(SDL_INIT_AUDIO);
return false;
}
/* Make sure we can support the audio format */
switch (obtained.format)
{
case AUDIO_S8: /* maybe needed by AHI */
case AUDIO_U8:
case AUDIO_S16SYS:
/* Supported */
break;
default:
Con_Printf ("Unsupported audio format received (%u)\n", obtained.format);
SDL_CloseAudio();
SDL_QuitSubSystem(SDL_INIT_AUDIO);
return false;
}
memset ((void *) dma, 0, sizeof(dma_t));
shm = dma;
/* Fill the audio DMA information block */
shm->samplebits = (obtained.format & 0xFF); /* first byte of format is bits */
shm->signed8 = (obtained.format == AUDIO_S8);
if (obtained.freq != tmp)
Con_Printf ("Warning: Rate set (%d) didn't match requested rate (%d)!\n", obtained.freq, tmp);
shm->speed = obtained.freq;
shm->channels = obtained.channels;
tmp = (obtained.samples * obtained.channels) * 10;
/* Since we passed NULL as the 'obtained' spec to SDL_OpenAudio(),
* SDL will convert to hardware format for us if needed, hence we
* directly use the desired values here. */
shm->samplebits = (desired.format & 0xFF); /* first byte of format is bits */
shm->signed8 = (desired.format == AUDIO_S8);
shm->speed = desired.freq;
shm->channels = desired.channels;
tmp = (desired.samples * desired.channels) * 10;
if (tmp & (tmp - 1))
{ /* make it a power of two */
val = 1;
@ -154,7 +140,7 @@ qboolean SNDDMA_Init (dma_t *dma)
shm->submission_chunk = 1;
Con_Printf ("SDL audio spec : %d Hz, %d samples, %d channels\n",
obtained.freq, obtained.samples, obtained.channels);
desired.freq, desired.samples, desired.channels);
#if defined(USE_SDL2)
{
const char *driver = SDL_GetCurrentAudioDriver();