From cbecd3ea8dac9acf4a3659475da410cc68e7655a Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Tue, 4 Mar 2014 23:24:52 +0100 Subject: [PATCH] Fix confusion between processed samples by the hardware (as reported by GET{I,O}OFFS) and samples played as reported by GETINFO(). Fixes incorrect delta propagated after xruns. --- libsndio/sio_sun.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libsndio/sio_sun.c b/libsndio/sio_sun.c index bd6139f..e24733d 100644 --- a/libsndio/sio_sun.c +++ b/libsndio/sio_sun.c @@ -877,16 +877,22 @@ sio_sun_revents(struct sio_hdl *sh, struct pollfd *pfd) if (dierr > 0) DPRINTFN(2, "rec xrun %d\n", dierr); } + + /* + * GET{I,O}OFFS report positions including xruns, + * so we have to substract to get the real position + */ + hdl->idelta -= dierr; + hdl->odelta -= doerr; + offset = doerr - dierr; if (offset > 0) { hdl->sio.rdrop += offset * hdl->ibpf; - hdl->idelta -= doerr; - hdl->odelta -= doerr; + hdl->idelta -= offset; DPRINTFN(2, "will drop %d and pause %d\n", offset, doerr); } else if (offset < 0) { hdl->sio.wsil += -offset * hdl->obpf; - hdl->idelta -= dierr; - hdl->odelta -= dierr; + hdl->odelta -= offset; DPRINTFN(2, "will insert %d and pause %d\n", -offset, dierr); }