The current code to set PCM sw-params is both broken (uninitialized use
of buffer_size) and uses a deprecated interface (xfer_align). Update it
according to the alsa's test/pcm.c (please note that I'm no alsa expert,
but the original code looked like being derived from the example, too).

This unbreaks Qutecom's sound effects on my Linux box.

diff --git a/libs/sound/src/linux/alsa_sndfile.cpp 
b/libs/sound/src/linux/alsa_sndfile.cpp
--- a/libs/sound/src/linux/alsa_sndfile.cpp
+++ b/libs/sound/src/linux/alsa_sndfile.cpp
@@ -420,7 +420,7 @@
  * set ctx->sw_params, update the alsa device.
  */
 static void set_sw_params( play_context* ctx, jmp_buf exc ) {
-       snd_pcm_uframes_t buffer_size, xfer_align, start_threshold;
+       snd_pcm_uframes_t buffer_size, period_size, start_threshold;
        int err;
 
        err = snd_pcm_sw_params_malloc( &(ctx->sw_params) );
@@ -429,22 +429,21 @@
        err = snd_pcm_sw_params_current (ctx->device, ctx->sw_params);
        check_alsa( err, exc, "snd_pcm_sw_params_current" );
 
-       /* note: set start threshold to delay start until the
-         *ring buffer is full
-        */
-       err = snd_pcm_sw_params_get_xfer_align (ctx->sw_params, &xfer_align);
-       check_alsa( err, exc, "cannot get xfer align" );
+       snd_pcm_hw_params_get_period_size(ctx->hw_params, &period_size, 0 );
+       snd_pcm_hw_params_get_buffer_size(ctx->hw_params, &buffer_size );
 
-       /* round up to closest transfer boundary */
-       start_threshold = (buffer_size / xfer_align) * xfer_align;
-       if (start_threshold < 1) {
-               start_threshold = 1;
-       }
+       /* start the transfer when the buffer is almost full: */
+       /* (buffer_size / avail_min) * avail_min */
+       start_threshold = (buffer_size / period_size) * period_size;
 
        err = snd_pcm_sw_params_set_start_threshold (ctx->device,
                                                     ctx->sw_params,
                                                     start_threshold);
        check_alsa( err, exc, "cannot set start threshold" );
+
+        /* allow the transfer when at least period_size samples can be 
processed */
+       err = snd_pcm_sw_params_set_avail_min(ctx->device, ctx->sw_params, 
period_size);
+       check_alsa( err, exc, "cannot set avail min" );
 
        err = snd_pcm_sw_params (ctx->device, ctx->sw_params);
        check_alsa( err, exc, "snd_pcm_sw_params" );

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
QuteCom-dev mailing list
[email protected]
http://lists.qutecom.org/mailman/listinfo/qutecom-dev

Reply via email to