Ported ALSA minimum-sample-count fix from 1.2 branch to 1.3.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 21 Aug 2011 11:52:21 -0400
changeset 5622 08e941dad8e9
parent 5615 5e060b67c73d
child 5624 84d302e859d1
Ported ALSA minimum-sample-count fix from 1.2 branch to 1.3.
src/audio/alsa/SDL_alsa_audio.c
--- a/src/audio/alsa/SDL_alsa_audio.c	Sun Aug 21 02:35:13 2011 -0400
+++ b/src/audio/alsa/SDL_alsa_audio.c	Sun Aug 21 11:52:21 2011 -0400
@@ -81,7 +81,8 @@
 static int (*ALSA_snd_pcm_sw_params) (snd_pcm_t *, snd_pcm_sw_params_t *);
 static int (*ALSA_snd_pcm_nonblock) (snd_pcm_t *, int);
 static int (*ALSA_snd_pcm_wait)(snd_pcm_t *, int);
-
+static int (*ALSA_snd_pcm_sw_params_set_avail_min)
+  (snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t);
 
 #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
 #define snd_pcm_hw_params_sizeof ALSA_snd_pcm_hw_params_sizeof
@@ -140,6 +141,7 @@
     SDL_ALSA_SYM(snd_pcm_sw_params);
     SDL_ALSA_SYM(snd_pcm_nonblock);
     SDL_ALSA_SYM(snd_pcm_wait);
+    SDL_ALSA_SYM(snd_pcm_sw_params_set_avail_min);
     return 0;
 }
 
@@ -618,6 +620,13 @@
                      ALSA_snd_strerror(status));
         return 0;
     }
+    status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples);
+    if (status < 0) {
+        ALSA_CloseDevice(this);
+        SDL_SetError("Couldn't set minimum available samples: %s",
+                     ALSA_snd_strerror(status));
+        return 0;
+    }
     status =
         ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);
     if (status < 0) {