sndiod: Instead of the max, use the number of chans in the slot struct.

This commit is contained in:
Alexandre Ratchov 2018-06-11 19:53:17 +02:00
parent 8be24309cb
commit 35cff61693
3 changed files with 45 additions and 51 deletions

View File

@ -619,11 +619,12 @@ dev_mix_adjvol(struct dev *d)
{ {
unsigned int n; unsigned int n;
struct slot *i, *j; struct slot *i, *j;
int weight; int jcmax, icmax, weight;
for (i = d->slot_list; i != NULL; i = i->next) { for (i = d->slot_list; i != NULL; i = i->next) {
if (!(i->mode & MODE_PLAY)) if (!(i->mode & MODE_PLAY))
continue; continue;
icmax = i->opt->pmin + i->mix.nch - 1;
weight = ADATA_UNIT; weight = ADATA_UNIT;
if (d->autovol) { if (d->autovol) {
/* /*
@ -634,8 +635,9 @@ dev_mix_adjvol(struct dev *d)
for (j = d->slot_list; j != NULL; j = j->next) { for (j = d->slot_list; j != NULL; j = j->next) {
if (!(j->mode & MODE_PLAY)) if (!(j->mode & MODE_PLAY))
continue; continue;
if (i->opt->pmin <= j->mix.slot_cmax && jcmax = j->opt->pmin + j->mix.nch - 1;
i->mix.slot_cmax >= j->opt->pmin) if (i->opt->pmin <= jcmax &&
icmax >= j->opt->pmin)
n++; n++;
} }
weight /= n; weight /= n;
@ -1417,76 +1419,72 @@ dev_mmcloc(struct dev *d, unsigned int origin)
void void
slot_allocbufs(struct slot *s) slot_allocbufs(struct slot *s)
{ {
unsigned int slot_nch, dev_nch; unsigned int dev_nch;
struct dev *d = s->dev; struct dev *d = s->dev;
if (s->mode & MODE_PLAY) { if (s->mode & MODE_PLAY) {
s->mix.bpf = s->par.bps * s->mix.bpf = s->par.bps * s->mix.nch;
(s->mix.slot_cmax - s->opt->pmin + 1);
abuf_init(&s->mix.buf, s->appbufsz * s->mix.bpf); abuf_init(&s->mix.buf, s->appbufsz * s->mix.bpf);
slot_nch = s->mix.slot_cmax - s->opt->pmin + 1;
dev_nch = s->opt->pmax - s->opt->pmin + 1; dev_nch = s->opt->pmax - s->opt->pmin + 1;
s->mix.decbuf = NULL; s->mix.decbuf = NULL;
s->mix.resampbuf = NULL; s->mix.resampbuf = NULL;
s->mix.join = 1; s->mix.join = 1;
s->mix.expand = 1; s->mix.expand = 1;
if (s->opt->dup) { if (s->opt->dup) {
if (dev_nch > slot_nch) if (dev_nch > s->mix.nch)
s->mix.expand = dev_nch / slot_nch; s->mix.expand = dev_nch / s->mix.nch;
else if (dev_nch < slot_nch) else if (dev_nch < s->mix.nch)
s->mix.join = slot_nch / dev_nch; s->mix.join = s->mix.nch / dev_nch;
} }
cmap_init(&s->mix.cmap, cmap_init(&s->mix.cmap,
s->opt->pmin, s->mix.slot_cmax, s->opt->pmin, s->opt->pmin + s->mix.nch - 1,
s->opt->pmin, s->mix.slot_cmax, s->opt->pmin, s->opt->pmin + s->mix.nch - 1,
0, d->pchan - 1, 0, d->pchan - 1,
s->opt->pmin, s->opt->pmax); s->opt->pmin, s->opt->pmax);
if (!aparams_native(&s->par)) { if (!aparams_native(&s->par)) {
dec_init(&s->mix.dec, &s->par, slot_nch); dec_init(&s->mix.dec, &s->par, s->mix.nch);
s->mix.decbuf = s->mix.decbuf =
xmalloc(s->round * slot_nch * sizeof(adata_t)); xmalloc(s->round * s->mix.nch * sizeof(adata_t));
} }
if (s->rate != d->rate) { if (s->rate != d->rate) {
resamp_init(&s->mix.resamp, s->round, d->round, resamp_init(&s->mix.resamp, s->round, d->round,
slot_nch); s->mix.nch);
s->mix.resampbuf = s->mix.resampbuf =
xmalloc(d->round * slot_nch * sizeof(adata_t)); xmalloc(d->round * s->mix.nch * sizeof(adata_t));
} }
} }
if (s->mode & MODE_RECMASK) { if (s->mode & MODE_RECMASK) {
s->sub.bpf = s->par.bps * s->sub.bpf = s->par.bps * s->sub.nch;
(s->sub.slot_cmax - s->opt->rmin + 1);
abuf_init(&s->sub.buf, s->appbufsz * s->sub.bpf); abuf_init(&s->sub.buf, s->appbufsz * s->sub.bpf);
slot_nch = s->sub.slot_cmax - s->opt->rmin + 1;
dev_nch = s->opt->rmax - s->opt->rmin + 1; dev_nch = s->opt->rmax - s->opt->rmin + 1;
s->sub.encbuf = NULL; s->sub.encbuf = NULL;
s->sub.resampbuf = NULL; s->sub.resampbuf = NULL;
s->sub.join = 1; s->sub.join = 1;
s->sub.expand = 1; s->sub.expand = 1;
if (s->opt->dup) { if (s->opt->dup) {
if (dev_nch > slot_nch) if (dev_nch > s->sub.nch)
s->sub.join = dev_nch / slot_nch; s->sub.join = dev_nch / s->sub.nch;
else if (dev_nch < slot_nch) else if (dev_nch < s->sub.nch)
s->sub.expand = slot_nch / dev_nch; s->sub.expand = s->sub.nch / dev_nch;
} }
cmap_init(&s->sub.cmap, cmap_init(&s->sub.cmap,
0, ((s->mode & MODE_MON) ? d->pchan : d->rchan) - 1, 0, ((s->mode & MODE_MON) ? d->pchan : d->rchan) - 1,
s->opt->rmin, s->opt->rmax, s->opt->rmin, s->opt->rmax,
s->opt->rmin, s->sub.slot_cmax, s->opt->rmin, s->opt->rmin + s->sub.nch - 1,
s->opt->rmin, s->sub.slot_cmax); s->opt->rmin, s->opt->rmin + s->sub.nch - 1);
if (s->rate != d->rate) { if (s->rate != d->rate) {
resamp_init(&s->sub.resamp, d->round, s->round, resamp_init(&s->sub.resamp, d->round, s->round,
slot_nch); s->sub.nch);
s->sub.resampbuf = s->sub.resampbuf =
xmalloc(d->round * slot_nch * sizeof(adata_t)); xmalloc(d->round * s->sub.nch * sizeof(adata_t));
} }
if (!aparams_native(&s->par)) { if (!aparams_native(&s->par)) {
enc_init(&s->sub.enc, &s->par, slot_nch); enc_init(&s->sub.enc, &s->par, s->sub.nch);
s->sub.encbuf = s->sub.encbuf =
xmalloc(s->round * slot_nch * sizeof(adata_t)); xmalloc(s->round * s->sub.nch * sizeof(adata_t));
} }
/* /*
@ -1497,13 +1495,13 @@ slot_allocbufs(struct slot *s)
*/ */
if (s->sub.resampbuf) { if (s->sub.resampbuf) {
memset(s->sub.resampbuf, 0, memset(s->sub.resampbuf, 0,
d->round * slot_nch * sizeof(adata_t)); d->round * s->sub.nch * sizeof(adata_t));
} else if (s->sub.encbuf) { } else if (s->sub.encbuf) {
memset(s->sub.encbuf, 0, memset(s->sub.encbuf, 0,
s->round * slot_nch * sizeof(adata_t)); s->round * s->sub.nch * sizeof(adata_t));
} else { } else {
memset(s->sub.buf.data, 0, memset(s->sub.buf.data, 0,
s->appbufsz * slot_nch * sizeof(adata_t)); s->appbufsz * s->sub.nch * sizeof(adata_t));
} }
} }
@ -1671,9 +1669,9 @@ found:
s->mode = mode; s->mode = mode;
aparams_init(&s->par); aparams_init(&s->par);
if (s->mode & MODE_PLAY) if (s->mode & MODE_PLAY)
s->mix.slot_cmax = s->opt->pmax; s->mix.nch = s->opt->pmax - s->opt->pmin + 1;
if (s->mode & MODE_RECMASK) if (s->mode & MODE_RECMASK)
s->sub.slot_cmax = s->opt->rmax; s->sub.nch = s->opt->rmax - s->opt->rmin + 1;
if (s->opt->mmc) { if (s->opt->mmc) {
s->xrun = XRUN_SYNC; s->xrun = XRUN_SYNC;
s->tstate = MMC_STOP; s->tstate = MMC_STOP;

View File

@ -47,7 +47,7 @@ struct slot {
unsigned int vol; /* volume within the vol */ unsigned int vol; /* volume within the vol */
struct abuf buf; /* socket side buffer */ struct abuf buf; /* socket side buffer */
int bpf; /* byte per frame */ int bpf; /* byte per frame */
int slot_cmax; /* slot source chans */ int nch; /* number of play chans */
struct cmap cmap; /* channel mapper state */ struct cmap cmap; /* channel mapper state */
struct resamp resamp; /* resampler state */ struct resamp resamp; /* resampler state */
struct conv dec; /* format decoder params */ struct conv dec; /* format decoder params */
@ -59,7 +59,7 @@ struct slot {
struct abuf buf; /* socket side buffer */ struct abuf buf; /* socket side buffer */
int prime; /* initial cycles to skip */ int prime; /* initial cycles to skip */
int bpf; /* byte per frame */ int bpf; /* byte per frame */
int slot_cmax; /* slot destination chans */ int nch; /* number of rec chans */
struct cmap cmap; /* channel mapper state */ struct cmap cmap; /* channel mapper state */
struct resamp resamp; /* buffer for resampling */ struct resamp resamp; /* buffer for resampling */
struct conv enc; /* buffer for encoding */ struct conv enc; /* buffer for encoding */

View File

@ -627,7 +627,7 @@ sock_setpar(struct sock *f)
rchan = 1; rchan = 1;
else if (rchan > NCHAN_MAX) else if (rchan > NCHAN_MAX)
rchan = NCHAN_MAX; rchan = NCHAN_MAX;
s->sub.slot_cmax = s->opt->rmin + rchan - 1; s->sub.nch = rchan;
#ifdef DEBUG #ifdef DEBUG
if (log_level >= 3) { if (log_level >= 3) {
sock_log(f); sock_log(f);
@ -638,7 +638,7 @@ sock_setpar(struct sock *f)
log_puts(" -> "); log_puts(" -> ");
log_putu(s->opt->rmin); log_putu(s->opt->rmin);
log_puts(":"); log_puts(":");
log_putu(s->sub.slot_cmax); log_putu(s->opt->rmin + s->sub.nch - 1);
log_puts("\n"); log_puts("\n");
} }
#endif #endif
@ -648,14 +648,14 @@ sock_setpar(struct sock *f)
pchan = 1; pchan = 1;
else if (pchan > NCHAN_MAX) else if (pchan > NCHAN_MAX)
pchan = NCHAN_MAX; pchan = NCHAN_MAX;
s->mix.slot_cmax = s->opt->pmin + pchan - 1; s->mix.nch = pchan;
#ifdef DEBUG #ifdef DEBUG
if (log_level >= 3) { if (log_level >= 3) {
sock_log(f); sock_log(f);
log_puts(": playback channels "); log_puts(": playback channels ");
log_putu(s->opt->pmin); log_putu(s->opt->pmin);
log_puts(":"); log_puts(":");
log_putu(s->mix.slot_cmax); log_putu(s->opt->pmin + s->mix.nch - 1);
log_puts(" -> "); log_puts(" -> ");
log_putu(s->opt->pmin); log_putu(s->opt->pmin);
log_puts(":"); log_puts(":");
@ -1013,13 +1013,13 @@ sock_execmsg(struct sock *f)
log_puts(", play "); log_puts(", play ");
log_puti(s->opt->pmin); log_puti(s->opt->pmin);
log_puts(":"); log_puts(":");
log_puti(s->mix.slot_cmax); log_puti(s->opt->pmin + s->mix.nch - 1);
} }
if (s->mode & MODE_RECMASK) { if (s->mode & MODE_RECMASK) {
log_puts(", rec "); log_puts(", rec ");
log_puti(s->opt->rmin); log_puti(s->opt->rmin);
log_puts(":"); log_puts(":");
log_puti(s->sub.slot_cmax); log_puti(s->opt->rmin + s->sub.nch - 1);
} }
log_puts(", "); log_puts(", ");
log_putu(s->appbufsz / s->round); log_putu(s->appbufsz / s->round);
@ -1122,14 +1122,10 @@ sock_execmsg(struct sock *f)
m->u.par.sig = s->par.sig; m->u.par.sig = s->par.sig;
m->u.par.le = s->par.le; m->u.par.le = s->par.le;
m->u.par.msb = s->par.msb; m->u.par.msb = s->par.msb;
if (s->mode & MODE_PLAY) { if (s->mode & MODE_PLAY)
m->u.par.pchan = htons(s->mix.slot_cmax - m->u.par.pchan = htons(s->mix.nch);
s->opt->pmin + 1); if (s->mode & MODE_RECMASK)
} m->u.par.rchan = htons(s->sub.nch);
if (s->mode & MODE_RECMASK) {
m->u.par.rchan = htons(s->sub.slot_cmax -
s->opt->rmin + 1);
}
m->u.par.rate = htonl(s->rate); m->u.par.rate = htonl(s->rate);
m->u.par.appbufsz = htonl(s->appbufsz); m->u.par.appbufsz = htonl(s->appbufsz);
m->u.par.bufsz = htonl(SLOT_BUFSZ(s)); m->u.par.bufsz = htonl(SLOT_BUFSZ(s));