From 7cd9c4b0a9e9eb361f4011b1e6637aa339e1ebdb Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Wed, 18 Sep 2019 09:36:33 +0200 Subject: [PATCH] Don't attempt to join/expand nonexistent channels. If the (hardware) device has fewer channels than the exposed sub-device and -jon is used, then mix the samples only to channels that exist on the device. --- sndiod/dev.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sndiod/dev.c b/sndiod/dev.c index 668cda8..eb364e6 100644 --- a/sndiod/dev.c +++ b/sndiod/dev.c @@ -1435,11 +1435,13 @@ dev_mmcloc(struct dev *d, unsigned int origin) void slot_initconv(struct slot *s) { - unsigned int dev_nch; + unsigned int dev_nch, max_nch; struct dev *d = s->dev; if (s->mode & MODE_PLAY) { dev_nch = s->opt->pmax - s->opt->pmin + 1; + if (dev_nch > d->pchan) + dev_nch = d->pchan; s->mix.decbuf = NULL; s->mix.resampbuf = NULL; s->mix.join = 1; @@ -1465,7 +1467,10 @@ slot_initconv(struct slot *s) } if (s->mode & MODE_RECMASK) { + max_nch = (s->mode & MODE_MON) ? d->pchan : d->rchan; dev_nch = s->opt->rmax - s->opt->rmin + 1; + if (dev_nch > max_nch) + dev_nch = max_nch; s->sub.encbuf = NULL; s->sub.resampbuf = NULL; s->sub.join = 1; @@ -1477,8 +1482,8 @@ slot_initconv(struct slot *s) s->sub.expand = s->sub.nch / dev_nch; } cmap_init(&s->sub.cmap, - 0, ((s->mode & MODE_MON) ? d->pchan : d->rchan) - 1, - s->opt->rmin, s->opt->rmax, + 0, max_nch - 1, + s->opt->rmin, s->opt->rmin + dev_nch - 1, s->opt->rmin, s->opt->rmin + s->sub.nch - 1, s->opt->rmin, s->opt->rmin + s->sub.nch - 1); if (s->rate != d->rate) {