Set a minimum sample count in ALSA target. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Sun, 21 Aug 2011 11:42:47 -0400
branchSDL-1.2
changeset 5621 8b2b7f4009e5
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
--- a/src/audio/alsa/SDL_alsa_audio.c	Sun Aug 21 11:27:37 2011 -0400
+++ b/src/audio/alsa/SDL_alsa_audio.c	Sun Aug 21 11:42:47 2011 -0400
@@ -81,6 +81,7 @@
 static int (*SDL_NAME(snd_pcm_hw_params))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
 /*
 */
+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);
 static int (*SDL_NAME(snd_pcm_sw_params_current))(snd_pcm_t *pcm, snd_pcm_sw_params_t *swparams);
 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);
 static int (*SDL_NAME(snd_pcm_sw_params))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params);
@@ -117,6 +118,7 @@
 	{ "snd_pcm_hw_params_set_buffer_size_near",	(void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_buffer_size_near) },
 	{ "snd_pcm_hw_params_get_buffer_size",	(void**)(char*)&SDL_NAME(snd_pcm_hw_params_get_buffer_size) },
 	{ "snd_pcm_hw_params",	(void**)(char*)&SDL_NAME(snd_pcm_hw_params)	},
+	{ "snd_pcm_sw_params_set_avail_min",	(void**)(char*)&SDL_NAME(snd_pcm_sw_params_set_avail_min) },
 	{ "snd_pcm_sw_params_current",	(void**)(char*)&SDL_NAME(snd_pcm_sw_params_current)	},
 	{ "snd_pcm_sw_params_set_start_threshold",	(void**)(char*)&SDL_NAME(snd_pcm_sw_params_set_start_threshold)	},
 	{ "snd_pcm_sw_params",	(void**)(char*)&SDL_NAME(snd_pcm_sw_params)	},
@@ -578,6 +580,12 @@
 		ALSA_CloseAudio(this);
 		return(-1);
 	}
+	status = SDL_NAME(snd_pcm_sw_params_set_avail_min)(pcm_handle, swparams, spec->samples);
+	if ( status < 0 ) {
+		SDL_SetError("Couldn't set minimum available samples: %s", SDL_NAME(snd_strerror)(status));
+		ALSA_CloseAudio(this);
+		return(-1);
+	}
 	status = SDL_NAME(snd_pcm_sw_params_set_start_threshold)(pcm_handle, swparams, 1);
 	if ( status < 0 ) {
 		SDL_SetError("Couldn't set start threshold: %s", SDL_NAME(snd_strerror)(status));