Set a minimum sample count in ALSA target. SDL-1.2
authorRyan C. Gordon
Sun, 21 Aug 2011 11:42:47 -0400
branchSDL-1.2
changeset 56218b2b7f4009e5
parent 5620 ad4ed9f0336f
child 5623 181d53fc4e23
Set a minimum sample count in ALSA target.

This should reduce unnecessary hardware interrupts. Apparently improves the
ALSA target on some systems.

Fixes Bugzilla #1170.

Thanks to Paul Cercueil for the patch!
src/audio/alsa/SDL_alsa_audio.c
     1.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Sun Aug 21 11:27:37 2011 -0400
     1.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Sun Aug 21 11:42:47 2011 -0400
     1.3 @@ -81,6 +81,7 @@
     1.4  static int (*SDL_NAME(snd_pcm_hw_params))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
     1.5  /*
     1.6  */
     1.7 +static int (*SDL_NAME(snd_pcm_sw_params_set_avail_min))(snd_pcm_t *pcm, snd_pcm_sw_params_t *swparams, snd_pcm_uframes_t val);
     1.8  static int (*SDL_NAME(snd_pcm_sw_params_current))(snd_pcm_t *pcm, snd_pcm_sw_params_t *swparams);
     1.9  static int (*SDL_NAME(snd_pcm_sw_params_set_start_threshold))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
    1.10  static int (*SDL_NAME(snd_pcm_sw_params))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params);
    1.11 @@ -117,6 +118,7 @@
    1.12  	{ "snd_pcm_hw_params_set_buffer_size_near",	(void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_buffer_size_near) },
    1.13  	{ "snd_pcm_hw_params_get_buffer_size",	(void**)(char*)&SDL_NAME(snd_pcm_hw_params_get_buffer_size) },
    1.14  	{ "snd_pcm_hw_params",	(void**)(char*)&SDL_NAME(snd_pcm_hw_params)	},
    1.15 +	{ "snd_pcm_sw_params_set_avail_min",	(void**)(char*)&SDL_NAME(snd_pcm_sw_params_set_avail_min) },
    1.16  	{ "snd_pcm_sw_params_current",	(void**)(char*)&SDL_NAME(snd_pcm_sw_params_current)	},
    1.17  	{ "snd_pcm_sw_params_set_start_threshold",	(void**)(char*)&SDL_NAME(snd_pcm_sw_params_set_start_threshold)	},
    1.18  	{ "snd_pcm_sw_params",	(void**)(char*)&SDL_NAME(snd_pcm_sw_params)	},
    1.19 @@ -578,6 +580,12 @@
    1.20  		ALSA_CloseAudio(this);
    1.21  		return(-1);
    1.22  	}
    1.23 +	status = SDL_NAME(snd_pcm_sw_params_set_avail_min)(pcm_handle, swparams, spec->samples);
    1.24 +	if ( status < 0 ) {
    1.25 +		SDL_SetError("Couldn't set minimum available samples: %s", SDL_NAME(snd_strerror)(status));
    1.26 +		ALSA_CloseAudio(this);
    1.27 +		return(-1);
    1.28 +	}
    1.29  	status = SDL_NAME(snd_pcm_sw_params_set_start_threshold)(pcm_handle, swparams, 1);
    1.30  	if ( status < 0 ) {
    1.31  		SDL_SetError("Couldn't set start threshold: %s", SDL_NAME(snd_strerror)(status));