From: ratchov Date: Mon, 22 Apr 2024 14:11:35 +0000 (+0000) Subject: sndiod: Use the channel mapping code of aucat X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5c89abe42fcfd8245548906d5edd08030e568111;p=openbsd sndiod: Use the channel mapping code of aucat For now sndiod uses only a subset of the available channel mappings. It gives the same result as the previous one, but having the same in both programs makes code review and testing easier. --- diff --git a/usr.bin/sndiod/dsp.c b/usr.bin/sndiod/dsp.c index f3420d151cd..2aa1cb143fa 100644 --- a/usr.bin/sndiod/dsp.c +++ b/usr.bin/sndiod/dsp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsp.c,v 1.20 2024/04/22 11:07:42 ratchov Exp $ */ +/* $OpenBSD: dsp.c,v 1.21 2024/04/22 14:11:35 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -834,33 +834,35 @@ cmap_init(struct cmap *p, int imin, int imax, int isubmin, int isubmax, int omin, int omax, int osubmin, int osubmax) { - int cmin, cmax; - - cmin = -NCHAN_MAX; - if (osubmin > cmin) - cmin = osubmin; - if (omin > cmin) - cmin = omin; - if (isubmin > cmin) - cmin = isubmin; - if (imin > cmin) - cmin = imin; - - cmax = NCHAN_MAX; - if (osubmax < cmax) - cmax = osubmax; - if (omax < cmax) - cmax = omax; - if (isubmax < cmax) - cmax = isubmax; - if (imax < cmax) - cmax = imax; - - p->ostart = cmin - omin; - p->onext = omax - cmax; - p->istart = cmin - imin; - p->inext = imax - cmax; - p->nch = cmax - cmin + 1; + int inch, onch, nch; + + /* + * Ignore channels outside of the available sets + */ + if (isubmin < imin) + isubmin = imin; + if (isubmax > imax) + isubmax = imax; + if (osubmin < omin) + osubmin = omin; + if (osubmax > omax) + osubmax = omax; + + /* + * Shrink the input or the output subset to make both subsets of + * the same size + */ + inch = isubmax - isubmin + 1; + onch = osubmax - osubmin + 1; + nch = (inch < onch) ? inch : onch; + isubmax = isubmin + nch - 1; + osubmax = osubmin + nch - 1; + + p->ostart = osubmin - omin; + p->onext = omax - osubmax; + p->istart = isubmin - imin; + p->inext = imax - isubmax; + p->nch = nch; #ifdef DEBUG if (log_level >= 3) { log_puts("cmap: nch = ");