On Fri, Jun 08, 2012 at 05:08:37PM +0200, Alexandre Ratchov wrote:
> On Fri, Jun 01, 2012 at 12:50:14AM +0600, Alexandr Shadchin wrote:
> >
> >  * Simplify sndio backend
> >    (+ fix sthen@ segfault, but resampling still does not work for him)
> > 
> 
> Hi,
> 
> The sndio backend is fine. Below are few -- mostly aesthetic --
> suggestions:
> 
>  - the device-side buffer is par.appbufsz frames, so it's not
>    necessary to allocate such a large buffer in deadbeef as well.
>    For instance a single block (par.round) would be ok.
> 
>  - sndiod and many devices use 48kHz as default sample rate, so it
>    could be used in .fmt.samplerate as well; but it seems this is
>    not used by deadbeef
> 
>  - Setting the volume in sndiod would save few cpu cycles and
>    allows deadbeef to update its slider whenever the volume is
>    changed externally.
> 

I noticed that with certain files, when deadbeef switches to the
next files it doesn't stop the audio device, but it doesn't provide
data to play either. This results in a busy loop, which in turn
puts deadbeef in a bad state causing stuttering. This might need to
be clarified with upstream developpers.

Meanwhile, inserting silence if there are no samples available
fixes stuttering. This is what pulse backend does as well.

-- Alexandre

--- sndio.c.old.2       Sat Jun  9 10:53:53 2012
+++ sndio.c     Sat Jun  9 11:09:50 2012
@@ -218,16 +218,15 @@ sndio_unpause(void)
 static void
 sndio_thread(void *context)
 {
-       int newvol, size, write_size;
+       int newvol;
+       size_t size;
 
        while (!sndio_terminate) {
-               if (state != OUTPUT_STATE_PLAYING ||
-                   !deadbeef->streamer_ok_to_read(-1)) {
+               if (state != OUTPUT_STATE_PLAYING) {
                        usleep(10000);
                        continue;
                }
 
-               write_size = 0;
                deadbeef->mutex_lock(sndio_mutex);
                newvol = (1 - deadbeef->volume_get_db() / min_db) * SIO_MAXVOL;
                if (newvol != vol) {
@@ -235,10 +234,10 @@ sndio_thread(void *context)
                        sio_setvol(hdl, vol);
                }
                size = sndio_callback(buf, bufsz);
-               if (size > 0)
-                       write_size = sio_write(hdl, buf, size);
+               memset(buf + size, 0, bufsz - size);
+               size = sio_write(hdl, buf, bufsz);
                deadbeef->mutex_unlock(sndio_mutex);
-               if (size != write_size) {
+               if (size != bufsz) {
                        fprintf(stderr, "sndio: failed to write buffer\n");
                        sndio_terminate = 1;
                        sndio_free();

Reply via email to