X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=snd_sdl.c;h=cfeeb1b49905c5259e990d14e40d1662e81d22fa;hb=25cf76bf27999cd9142c0821ef55a64169896b41;hp=45b359ac716467c5e0a043cef011d69a5918d9ea;hpb=6068115093a24d125506e021ebc144d720553583;p=xonotic%2Fdarkplaces.git diff --git a/snd_sdl.c b/snd_sdl.c index 45b359ac..cfeeb1b4 100644 --- a/snd_sdl.c +++ b/snd_sdl.c @@ -17,16 +17,15 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "quakedef.h" +#include "snd_main.h" #include /* Info: -One SDL sample consists of x channel samples -The mixer supposes that the driver has one channel entry/sample though it has x channels/sample -like the SDL +SDL samples are really frames (full set of samples for all speakers) */ -#define AUDIO_SDL_SAMPLES 4096 +#define AUDIO_SDL_SAMPLEFRAMES 4096 #define AUDIO_LOCALFACTOR 4 typedef struct AudioState_s @@ -38,7 +37,6 @@ typedef struct AudioState_s } AudioState; -extern mempool_t *snd_mempool; static AudioState as; static void Buffer_Callback(void *userdata, Uint8 *stream, int len); @@ -81,56 +79,79 @@ Returns false if nothing is found. qboolean SNDDMA_Init(void) { - SDL_AudioSpec spec; + SDL_AudioSpec wantspec; int i; + int channels; // Init the SDL Audio subsystem if( SDL_InitSubSystem( SDL_INIT_AUDIO ) ) { - Con_SafePrint( "Initializing the SDL Audio subsystem failed!\n" ); + Con_Print( "Initializing the SDL Audio subsystem failed!\n" ); return false; } - // Init the shm structure - memset( (void*) shm, 0, sizeof(*shm) ); - - shm->format.channels = 2; //stereo - shm->format.width = 2; - - i = COM_CheckParm( "-sndspeed" ); - if( i && i != ( com_argc - 1 ) ) - shm->format.speed = atoi( com_argv[ i+1 ] ); - else - shm->format.speed = 44100; - - shm->samplepos = 0; - shm->samples = AUDIO_SDL_SAMPLES * AUDIO_LOCALFACTOR; - shm->bufferlength = shm->samples * shm->format.width; - shm->buffer = Mem_Alloc( snd_mempool, shm->bufferlength ); - - // Init the as structure - as.buffer = shm->buffer; - as.width = shm->format.width; - as.pos = 0; - as.size = shm->bufferlength; - - // Init the SDL Audio subsystem - spec.callback = Buffer_Callback; - spec.channels = shm->format.channels; - spec.format = AUDIO_S16LSB; - spec.freq = shm->format.speed; - spec.userdata = NULL; - spec.samples = AUDIO_SDL_SAMPLES; - - if( SDL_OpenAudio( &spec, NULL ) ) { - Con_SafePrint( "Failed to open the audio device!\n" ); - Con_DPrintf( + for (channels = 8;channels >= 1;channels--) + { + if ((channels & 1) && channels != 1) + continue; +// COMMANDLINEOPTION: SDL Sound: -sndmono sets sound output to mono + if ((i=COM_CheckParm("-sndmono")) != 0) + if (channels != 1) + continue; +// COMMANDLINEOPTION: SDL Sound: -sndstereo sets sound output to stereo + if ((i=COM_CheckParm("-sndstereo")) != 0) + if (channels != 2) + continue; +// COMMANDLINEOPTION: SDL Sound: -sndquad sets sound output to 4 channel surround + if ((i=COM_CheckParm("-sndquad")) != 0) + if (channels != 4) + continue; + // Init the SDL Audio subsystem + wantspec.callback = Buffer_Callback; + wantspec.userdata = NULL; + wantspec.freq = 44100; + // COMMANDLINEOPTION: SDL Sound: -sndspeed chooses sound output rate (try values such as 44100, 48000, 22050, 11025 (quake), 24000, 32000, 96000, 192000, etc) + i = COM_CheckParm( "-sndspeed" ); + if( i && i != ( com_argc - 1 ) ) + wantspec.freq = atoi( com_argv[ i+1 ] ); + wantspec.format = AUDIO_S16SYS; + wantspec.channels = channels; + wantspec.samples = AUDIO_SDL_SAMPLEFRAMES; + + if( SDL_OpenAudio( &wantspec, NULL ) ) + { + Con_Printf("%s\n", SDL_GetError()); + continue; + } + + // Init the shm structure + memset( (void*) shm, 0, sizeof(*shm) ); + shm->format.channels = wantspec.channels; + shm->format.width = 2; + shm->format.speed = wantspec.freq; + + shm->samplepos = 0; + shm->sampleframes = wantspec.samples * AUDIO_LOCALFACTOR; + shm->samples = shm->sampleframes * shm->format.channels; + shm->bufferlength = shm->samples * shm->format.width; + shm->buffer = (unsigned char *)Mem_Alloc( snd_mempool, shm->bufferlength ); + + // Init the as structure + as.buffer = shm->buffer; + as.width = shm->format.width; + as.pos = 0; + as.size = shm->bufferlength; + break; + } + if (channels < 1) + { + Con_Print( "Failed to open the audio device!\n" ); + Con_DPrintf( "Audio Specification:\n" "\tChannels : %i\n" "\tFormat : %x\n" "\tFrequency : %i\n" - "\tBuffersize: %i Bytes(%i Samples)\n", - spec.channels, spec.format, spec.freq, shm->bufferlength , spec.samples ); - Mem_Free( shm->buffer ); + "\tSamples : %i\n", + wantspec.channels, wantspec.format, wantspec.freq, wantspec.samples ); return false; }