summaryrefslogtreecommitdiff
path: root/usr.bin/sndiod
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/sndiod')
-rw-r--r--usr.bin/sndiod/dsp.c58
1 files changed, 30 insertions, 28 deletions
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 <alex@caoua.org>
*
@@ -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 = ");