mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
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:
parent
e04c0b49af
commit
21915e956c
1 changed files with 12 additions and 26 deletions
|
@ -80,7 +80,7 @@ static void SDLCALL paint_audio (void *unused, Uint8 *stream, int len)
|
||||||
|
|
||||||
qboolean SNDDMA_Init (dma_t *dma)
|
qboolean SNDDMA_Init (dma_t *dma)
|
||||||
{
|
{
|
||||||
SDL_AudioSpec desired, obtained;
|
SDL_AudioSpec desired;
|
||||||
int tmp, val;
|
int tmp, val;
|
||||||
char drivername[128];
|
char drivername[128];
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ qboolean SNDDMA_Init (dma_t *dma)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up the desired format */
|
/* 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.format = (loadas8bit.value) ? AUDIO_U8 : AUDIO_S16SYS;
|
||||||
desired.channels = 2; /* = desired_channels; */
|
desired.channels = 2; /* = desired_channels; */
|
||||||
if (desired.freq <= 11025)
|
if (desired.freq <= 11025)
|
||||||
|
@ -108,39 +108,25 @@ qboolean SNDDMA_Init (dma_t *dma)
|
||||||
desired.userdata = NULL;
|
desired.userdata = NULL;
|
||||||
|
|
||||||
/* Open the audio device */
|
/* 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());
|
Con_Printf("Couldn't open SDL audio: %s\n", SDL_GetError());
|
||||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||||
return false;
|
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));
|
memset ((void *) dma, 0, sizeof(dma_t));
|
||||||
shm = dma;
|
shm = dma;
|
||||||
|
|
||||||
/* Fill the audio DMA information block */
|
/* Fill the audio DMA information block */
|
||||||
shm->samplebits = (obtained.format & 0xFF); /* first byte of format is bits */
|
/* Since we passed NULL as the 'obtained' spec to SDL_OpenAudio(),
|
||||||
shm->signed8 = (obtained.format == AUDIO_S8);
|
* SDL will convert to hardware format for us if needed, hence we
|
||||||
if (obtained.freq != tmp)
|
* directly use the desired values here. */
|
||||||
Con_Printf ("Warning: Rate set (%d) didn't match requested rate (%d)!\n", obtained.freq, tmp);
|
shm->samplebits = (desired.format & 0xFF); /* first byte of format is bits */
|
||||||
shm->speed = obtained.freq;
|
shm->signed8 = (desired.format == AUDIO_S8);
|
||||||
shm->channels = obtained.channels;
|
shm->speed = desired.freq;
|
||||||
tmp = (obtained.samples * obtained.channels) * 10;
|
shm->channels = desired.channels;
|
||||||
|
tmp = (desired.samples * desired.channels) * 10;
|
||||||
if (tmp & (tmp - 1))
|
if (tmp & (tmp - 1))
|
||||||
{ /* make it a power of two */
|
{ /* make it a power of two */
|
||||||
val = 1;
|
val = 1;
|
||||||
|
@ -154,7 +140,7 @@ qboolean SNDDMA_Init (dma_t *dma)
|
||||||
shm->submission_chunk = 1;
|
shm->submission_chunk = 1;
|
||||||
|
|
||||||
Con_Printf ("SDL audio spec : %d Hz, %d samples, %d channels\n",
|
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)
|
#if defined(USE_SDL2)
|
||||||
{
|
{
|
||||||
const char *driver = SDL_GetCurrentAudioDriver();
|
const char *driver = SDL_GetCurrentAudioDriver();
|
||||||
|
|
Loading…
Reference in a new issue