[xiph-commits] r18780 - trunk/ao/src/plugins/alsa

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Tue Jan 22 00:25:17 PST 2013


Author: xiphmont
Date: 2013-01-22 00:25:17 -0800 (Tue, 22 Jan 2013)
New Revision: 18780

Modified:
   trunk/ao/src/plugins/alsa/ao_alsa.c
Log:
Correction to ALSA beahior: when requesting low-latency behavior, set
the period size first, and potentially base other params off the
minimum period.  Some of the plug devices will have rather high
minimum periods, and ending up with too small a buffer in relation (2x
or smaller) guarantees skipping.



Modified: trunk/ao/src/plugins/alsa/ao_alsa.c
===================================================================
--- trunk/ao/src/plugins/alsa/ao_alsa.c	2013-01-22 04:41:11 UTC (rev 18779)
+++ trunk/ao/src/plugins/alsa/ao_alsa.c	2013-01-22 08:25:17 UTC (rev 18780)
@@ -353,14 +353,6 @@
                 "by the hardware, using %u\n", format->rate, rate);
 	}
 
-	/* set the length of the hardware sample buffer in microseconds */
-	err = snd_pcm_hw_params_set_buffer_time_near(internal->pcm_handle,
-			params, &(internal->buffer_time), 0);
-	if (err < 0){
-          adebug("snd_pcm_hw_params_set_buffer_time_near() failed.\n");
-          return err;
-        }
-
 	/* set the time per hardware sample transfer */
         if(internal->period_time==0)
           internal->period_time=internal->buffer_time/4;
@@ -372,6 +364,19 @@
           return err;
         }
 
+	/* set the length of the hardware sample buffer in microseconds */
+        /* some plug devices have very high minimum periods; don't
+           allow a buffer size small enough that it's ~ guaranteed to
+           skip */
+        if(internal->buffer_time<internal->period_time*3)
+          internal->buffer_time=internal->period_time*3;
+	err = snd_pcm_hw_params_set_buffer_time_near(internal->pcm_handle,
+			params, &(internal->buffer_time), 0);
+	if (err < 0){
+          adebug("snd_pcm_hw_params_set_buffer_time_near() failed.\n");
+          return err;
+        }
+
 	/* commit the params structure to the hardware via ALSA */
 	err = snd_pcm_hw_params(internal->pcm_handle, params);
 	if (err < 0){



More information about the commits mailing list