-/* $OpenBSD: sun.c,v 1.39 2010/07/21 23:00:16 ratchov Exp $ */
+/* $OpenBSD: sun.c,v 1.40 2010/08/06 06:52:17 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
{
struct sun_hdl *hdl = (struct sun_hdl *)sh;
struct audio_offset ao;
- int xrun, dmove, dierr = 0, doerr = 0, doffset = 0;
+ int xrun, dmove, dierr = 0, doerr = 0, delta;
int revents = pfd->revents;
if (hdl->sio.mode & SIO_PLAY) {
}
doerr = xrun - hdl->oerr;
hdl->oerr = xrun;
- if (hdl->sio.mode & SIO_REC)
- doffset += doerr;
+ if (!(hdl->sio.mode & SIO_REC))
+ dierr = doerr;
}
if (hdl->sio.mode & SIO_REC) {
if (ioctl(hdl->fd, AUDIO_RERROR, &xrun) < 0) {
}
dierr = xrun - hdl->ierr;
hdl->ierr = xrun;
- if (hdl->sio.mode & SIO_PLAY)
- doffset -= dierr;
+ if (!(hdl->sio.mode & SIO_PLAY))
+ doerr = dierr;
}
- hdl->offset += doffset;
+ hdl->offset += doerr - dierr;
dmove = dierr > doerr ? dierr : doerr;
hdl->idelta -= dmove;
hdl->odelta -= dmove;
hdl->sio.eof = 1;
return POLLHUP;
}
- hdl->odelta += (ao.samples - hdl->obytes) / hdl->obpf;
+ delta = (ao.samples - hdl->obytes) / hdl->obpf;
hdl->obytes = ao.samples;
- if (hdl->odelta > 0) {
- sio_onmove_cb(&hdl->sio, hdl->odelta);
- hdl->odelta = 0;
- }
+ hdl->odelta += delta;
+ if (!(hdl->sio.mode & SIO_REC))
+ hdl->idelta += delta;
}
- if ((revents & POLLIN) && !(hdl->sio.mode & SIO_PLAY)) {
+ if ((revents & POLLIN) && (hdl->sio.mode & SIO_REC)) {
if (ioctl(hdl->fd, AUDIO_GETIOFFS, &ao) < 0) {
DPERROR("sun_revents: GETIOFFS");
hdl->sio.eof = 1;
return POLLHUP;
}
- hdl->idelta += (ao.samples - hdl->ibytes) / hdl->ibpf;
+ delta = (ao.samples - hdl->ibytes) / hdl->ibpf;
hdl->ibytes = ao.samples;
- if (hdl->idelta > 0) {
- sio_onmove_cb(&hdl->sio, hdl->idelta);
- hdl->idelta = 0;
- }
+ hdl->idelta += delta;
+ if (!(hdl->sio.mode & SIO_PLAY))
+ hdl->odelta += delta;
+ }
+ delta = (hdl->idelta > hdl->odelta) ? hdl->idelta : hdl->odelta;
+ if (delta > 0) {
+ sio_onmove_cb(&hdl->sio, delta);
+ hdl->idelta -= delta;
+ hdl->odelta -= delta;
}
/*