From 0c70f95bd5447bab201c636210bc1a84280ef61c Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Mon, 17 Mar 2014 18:13:11 +0100 Subject: [PATCH] unbreak monitoring mode (was 1 block off) --- sndiod/dev.c | 23 +++++++++++++++-------- sndiod/dev.h | 1 + sndiod/siofile.c | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/sndiod/dev.c b/sndiod/dev.c index 18b2758..b1db05a 100644 --- a/sndiod/dev.c +++ b/sndiod/dev.c @@ -740,9 +740,15 @@ void dev_sub_bcopy(struct dev *d, struct slot *s) { adata_t *idata, *odata; - int ocount; + int ocount, moffs; - idata = (s->mode & MODE_MON) ? DEV_PBUF(d) : d->rbuf; + if (s->mode & MODE_MON) { + moffs = d->poffs + d->round; + if (moffs == d->psize) + moffs = 0; + idata = d->pbuf + moffs * d->pchan; + } else + idata = d->rbuf; odata = (adata_t *)abuf_wgetblk(&s->sub.buf, &ocount); #ifdef DEBUG if (ocount < s->round * s->sub.bpf) { @@ -864,11 +870,6 @@ dev_full_cycle(struct dev *d) } continue; } - if (s->mode & MODE_PLAY) { - dev_mix_badd(d, s); - if (s->pstate != SLOT_STOP) - s->ops->fill(s->arg); - } if ((s->mode & MODE_RECMASK) && !(s->pstate == SLOT_STOP)) { if (s->sub.prime == 0) { dev_sub_bcopy(d, s); @@ -885,6 +886,11 @@ dev_full_cycle(struct dev *d) s->sub.prime--; } } + if (s->mode & MODE_PLAY) { + dev_mix_badd(d, s); + if (s->pstate != SLOT_STOP) + s->ops->fill(s->arg); + } ps = &s->next; } if ((d->mode & MODE_PLAY) && d->encbuf) { @@ -1095,8 +1101,9 @@ dev_open(struct dev *d) /* * Create device <-> mixer buffer */ - d->pbuf = xmalloc(d->bufsz * d->pchan * sizeof(adata_t)); d->poffs = 0; + d->psize = d->bufsz + d->round; + d->pbuf = xmalloc(d->psize * d->pchan * sizeof(adata_t)); d->mode |= MODE_MON; /* diff --git a/sndiod/dev.h b/sndiod/dev.h index a91db35..01af7f2 100644 --- a/sndiod/dev.h +++ b/sndiod/dev.h @@ -113,6 +113,7 @@ struct dev { adata_t *pbuf; /* array of play buffers */ #define DEV_PBUF(d) ((d)->pbuf + (d)->poffs * (d)->pchan) int poffs; /* index of current play buf */ + int psize; /* size of play buffer */ struct conv enc; /* native->device format */ struct conv dec; /* device->native format */ unsigned char *encbuf; /* buffer for encoding */ diff --git a/sndiod/siofile.c b/sndiod/siofile.c index 23f3363..2fd0628 100644 --- a/sndiod/siofile.c +++ b/sndiod/siofile.c @@ -415,7 +415,7 @@ dev_sio_run(void *arg) } #endif d->poffs += d->round; - if (d->poffs == d->bufsz) + if (d->poffs == d->psize) d->poffs = 0; if ((d->mode & MODE_REC) && d->prime == 0) { d->sio.cstate = DEV_SIO_READ;