Menu

#277 pulseaudio sound handler is buggy/inconsistent

closed-fixed
nobody
pulseaudio (1)
5
2020-08-04
2016-07-02
No

There is a bug in the SoX pulseaudio handler, that leads to an inconsistent behaviour of SoX: with ALSA, OSS etc. when a write of zero length is performed nothing happens, with PulseAudio instead SoX quits when a zero length write is performed. This is because pa_simple_write() returns an error whenever the input buffer length is zero.

As a result, example3.c from the SoX source code fails if one tries to substitute alsa with pulseaudio (tested with an ogg/vorbis file). The solution is to modify write_samples from pulseaudio.c so that it behaviours exactly like ALSA, i.e. it returns 0 when 0 is the length of the write. This can be achieved by simply adding something like if (nsamp == 0) return 0; before the call to pa_simple_write(). As far as I tested it there are not downturns to this approach.

NOTE: if one tries to perform a zero length write (i.e. len is zero) with the ALSA handler, the for cycle never executes its code, because the condition is (done = 0; done < len; done += n), so it reaches the end of the function where the line return len; is executed, i.e. it just returns zero when len is zero.

Discussion

  • Stefano Guidoni

    Stefano Guidoni - 2016-07-08

    A patch that solves the problem:

    --- old/src/pulseaudio.c        2015-02-27 04:48:40.000000000 +0100
    +++ new/src/pulseaudio.c        2016-07-08 20:33:45.608428058 +0200
    @@ -126,6 +126,9 @@
       size_t len;
       int rc, error;
    
    
    +  if (nsamp == 0)
    +    return 0;
    +  
       /* Pulse Audio buffer lengths are true buffer lengths and not
        * count of samples. */
       len = nsamp * sizeof(sox_sample_t);
    
     
  • Mans Rullgard

    Mans Rullgard - 2020-08-04
    • status: open --> closed-fixed
     
  • Mans Rullgard

    Mans Rullgard - 2020-08-04

    Fixed.

     

Log in to post a comment.

MongoDB Logo MongoDB