Getting as close as you can with periods is better than the default parameters. SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Mon, 19 Oct 2009 03:18:15 +0000
branchSDL-1.2
changeset 4360be2dff2f79c0
parent 4359 4b582c04ec1d
child 4361 991e4bcfc7a8
Getting as close as you can with periods is better than the default parameters.
src/audio/alsa/SDL_alsa_audio.c
     1.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Mon Oct 19 02:36:02 2009 +0000
     1.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Mon Oct 19 03:18:15 2009 +0000
     1.3 @@ -380,11 +380,10 @@
     1.4  	return(0);
     1.5  }
     1.6  
     1.7 -static int ALSA_set_period_size(_THIS, SDL_AudioSpec *spec, snd_pcm_hw_params_t *params)
     1.8 +static int ALSA_set_period_size(_THIS, SDL_AudioSpec *spec, snd_pcm_hw_params_t *params, int override)
     1.9  {
    1.10  	const char *env;
    1.11  	int status;
    1.12 -	int override = 0;
    1.13  	snd_pcm_hw_params_t *hwparams;
    1.14  	snd_pcm_uframes_t frames;
    1.15  	unsigned int periods;
    1.16 @@ -393,11 +392,13 @@
    1.17  	snd_pcm_hw_params_alloca(&hwparams);
    1.18  	SDL_NAME(snd_pcm_hw_params_copy)(hwparams, params);
    1.19  
    1.20 -	env = getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE");
    1.21 -	if ( env ) {
    1.22 -		override = SDL_atoi(env);
    1.23 -		if ( override == 0 ) {
    1.24 -			return(-1);
    1.25 +	if ( !override ) {
    1.26 +		env = getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE");
    1.27 +		if ( env ) {
    1.28 +			override = SDL_atoi(env);
    1.29 +			if ( override == 0 ) {
    1.30 +				return(-1);
    1.31 +			}
    1.32  		}
    1.33  	}
    1.34  
    1.35 @@ -416,11 +417,10 @@
    1.36  	return ALSA_finalize_hardware(this, spec, hwparams, override);
    1.37  }
    1.38  
    1.39 -static int ALSA_set_buffer_size(_THIS, SDL_AudioSpec *spec, snd_pcm_hw_params_t *params)
    1.40 +static int ALSA_set_buffer_size(_THIS, SDL_AudioSpec *spec, snd_pcm_hw_params_t *params, int override)
    1.41  {
    1.42  	const char *env;
    1.43  	int status;
    1.44 -	int override = 0;
    1.45  	snd_pcm_hw_params_t *hwparams;
    1.46  	snd_pcm_uframes_t frames;
    1.47  
    1.48 @@ -428,11 +428,13 @@
    1.49  	snd_pcm_hw_params_alloca(&hwparams);
    1.50  	SDL_NAME(snd_pcm_hw_params_copy)(hwparams, params);
    1.51  
    1.52 -	env = getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE");
    1.53 -	if ( env ) {
    1.54 -		override = SDL_atoi(env);
    1.55 -		if ( override == 0 ) {
    1.56 -			return(-1);
    1.57 +	if ( !override ) {
    1.58 +		env = getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE");
    1.59 +		if ( env ) {
    1.60 +			override = SDL_atoi(env);
    1.61 +			if ( override == 0 ) {
    1.62 +				return(-1);
    1.63 +			}
    1.64  		}
    1.65  	}
    1.66  
    1.67 @@ -548,10 +550,10 @@
    1.68  	spec->freq = rate;
    1.69  
    1.70  	/* Set the buffer size, in samples */
    1.71 -	if ( ALSA_set_period_size(this, spec, hwparams) < 0 &&
    1.72 -	     ALSA_set_buffer_size(this, spec, hwparams) < 0 ) {
    1.73 -		/* Failed to set buffer size, try to just use the defaults */
    1.74 -		if ( ALSA_finalize_hardware(this, spec, hwparams, 1) < 0 ) {
    1.75 +	if ( ALSA_set_period_size(this, spec, hwparams, 0) < 0 &&
    1.76 +	     ALSA_set_buffer_size(this, spec, hwparams, 0) < 0 ) {
    1.77 +		/* Failed to set desired buffer size, do the best you can... */
    1.78 +		if ( ALSA_set_period_size(this, spec, hwparams, 1) < 0 ) {
    1.79  			SDL_SetError("Couldn't set hardware audio parameters: %s", SDL_NAME(snd_strerror)(status));
    1.80  			ALSA_CloseAudio(this);
    1.81  			return(-1);