Mercurial > sdl-ios-xcode
changeset 4360:be2dff2f79c0 SDL-1.2
Getting as close as you can with periods is better than the default parameters.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 19 Oct 2009 03:18:15 +0000 |
parents | 4b582c04ec1d |
children | 991e4bcfc7a8 |
files | src/audio/alsa/SDL_alsa_audio.c |
diffstat | 1 files changed, 20 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/audio/alsa/SDL_alsa_audio.c Mon Oct 19 02:36:02 2009 +0000 +++ b/src/audio/alsa/SDL_alsa_audio.c Mon Oct 19 03:18:15 2009 +0000 @@ -380,11 +380,10 @@ return(0); } -static int ALSA_set_period_size(_THIS, SDL_AudioSpec *spec, snd_pcm_hw_params_t *params) +static int ALSA_set_period_size(_THIS, SDL_AudioSpec *spec, snd_pcm_hw_params_t *params, int override) { const char *env; int status; - int override = 0; snd_pcm_hw_params_t *hwparams; snd_pcm_uframes_t frames; unsigned int periods; @@ -393,11 +392,13 @@ snd_pcm_hw_params_alloca(&hwparams); SDL_NAME(snd_pcm_hw_params_copy)(hwparams, params); - env = getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE"); - if ( env ) { - override = SDL_atoi(env); - if ( override == 0 ) { - return(-1); + if ( !override ) { + env = getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE"); + if ( env ) { + override = SDL_atoi(env); + if ( override == 0 ) { + return(-1); + } } } @@ -416,11 +417,10 @@ return ALSA_finalize_hardware(this, spec, hwparams, override); } -static int ALSA_set_buffer_size(_THIS, SDL_AudioSpec *spec, snd_pcm_hw_params_t *params) +static int ALSA_set_buffer_size(_THIS, SDL_AudioSpec *spec, snd_pcm_hw_params_t *params, int override) { const char *env; int status; - int override = 0; snd_pcm_hw_params_t *hwparams; snd_pcm_uframes_t frames; @@ -428,11 +428,13 @@ snd_pcm_hw_params_alloca(&hwparams); SDL_NAME(snd_pcm_hw_params_copy)(hwparams, params); - env = getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE"); - if ( env ) { - override = SDL_atoi(env); - if ( override == 0 ) { - return(-1); + if ( !override ) { + env = getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE"); + if ( env ) { + override = SDL_atoi(env); + if ( override == 0 ) { + return(-1); + } } } @@ -548,10 +550,10 @@ spec->freq = rate; /* Set the buffer size, in samples */ - if ( ALSA_set_period_size(this, spec, hwparams) < 0 && - ALSA_set_buffer_size(this, spec, hwparams) < 0 ) { - /* Failed to set buffer size, try to just use the defaults */ - if ( ALSA_finalize_hardware(this, spec, hwparams, 1) < 0 ) { + if ( ALSA_set_period_size(this, spec, hwparams, 0) < 0 && + ALSA_set_buffer_size(this, spec, hwparams, 0) < 0 ) { + /* Failed to set desired buffer size, do the best you can... */ + if ( ALSA_set_period_size(this, spec, hwparams, 1) < 0 ) { SDL_SetError("Couldn't set hardware audio parameters: %s", SDL_NAME(snd_strerror)(status)); ALSA_CloseAudio(this); return(-1);