The bug in 'morse':

morse.d/beepPA.c opens a two-channel (stereo) PulseAudio stream, but then
mis-handles it as if it was just one channel of audio data, including
trying to write a non-mulitple of the (stereo) PulseAudio frame size via
pa_simple_write().  Earlier versions of PulseAudio silently ignored the
discrepancy, but newer versions rightly return a PulseAudio "Invalid
argument" error.

Attached patch to morse.d/beepPA.c fixes the bug.

 -Kamal
Author: Kamal Mostafa <ka...@whence.com
Bug-Debian: https://bugs.debian.org/784285
Description: fix pa_simple_write error with mono output
Bug-Debian: https://bugs.debian.org/784285
Bug-Ubuntu: https://launchpad.net/bugs/1461755

   * Open a mono (not stereo) PulseAudio output stream and hence avoid
     improperly passing non-multiples of the frame size to pa_simple_write
     (Closes: #784285, LP: #1461755).

--- morse-2.4.orig/morse.d/beepPA.c
+++ morse-2.4/morse.d/beepPA.c
@@ -33,7 +33,7 @@ static pthread_cond_t beep_cv = PTHREAD_
 static const pa_sample_spec sample_format = {
         .format = PA_SAMPLE_S16LE,
         .rate = 44100,
-        .channels = 2
+        .channels = 1
 };
 
 static pa_simple *snddev;
@@ -47,7 +47,7 @@ static struct {
 static void play_tone()
 {
     int c;
-    int len = (int)(sample_format.rate*beep_info.time/1000.0*2);
+    int len = (int)(sample_format.rate*beep_info.time/1000.0);
     double t, tt;
     double v;
     int16_t *sample;
@@ -61,7 +61,7 @@ static void play_tone()
     } else {
 	tt = beep_info.time/1000.0;
 	for (c=0; c<len; c+=2) {
-	    t = c/((double)sample_format.rate*2.0); /* Time in s from start */
+	    t = c/((double)sample_format.rate); /* Time in s from start */
 	    v = (beep_info.volume/100.0) * sin(M_PI * 2 * t * beep_info.pitch);
 	    if (t < 0.01) {
 		/* Fade in softly over the first 10 ms */

Reply via email to