summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2018-06-26 07:36:28 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2018-06-26 07:36:28 +0000
commit0786215f1a8a9de2d04953a3945d2354240dc5d6 (patch)
tree6fde76dd4eda65f2a550b0a5be46cfb1506801e0 /usr.bin
parente3898c4591e8147acad50d866487068cf572c1a8 (diff)
Convert all the slot_xxx() routines to use the number of channels
instead of the maximum channel number. This way the code is simpler. No behaviour change.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sndiod/dev.c70
-rw-r--r--usr.bin/sndiod/dev.h6
-rw-r--r--usr.bin/sndiod/sock.c26
3 files changed, 48 insertions, 54 deletions
diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c
index afdb635de7c..4e9c5536708 100644
--- a/usr.bin/sndiod/dev.c
+++ b/usr.bin/sndiod/dev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.c,v 1.41 2018/06/26 07:31:29 ratchov Exp $ */
+/* $OpenBSD: dev.c,v 1.42 2018/06/26 07:36:27 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -618,11 +618,12 @@ dev_mix_adjvol(struct dev *d)
{
unsigned int n;
struct slot *i, *j;
- int weight;
+ int jcmax, icmax, weight;
for (i = d->slot_list; i != NULL; i = i->next) {
if (!(i->mode & MODE_PLAY))
continue;
+ icmax = i->opt->pmin + i->mix.nch - 1;
weight = ADATA_UNIT;
if (d->autovol) {
/*
@@ -633,8 +634,9 @@ dev_mix_adjvol(struct dev *d)
for (j = d->slot_list; j != NULL; j = j->next) {
if (!(j->mode & MODE_PLAY))
continue;
- if (i->opt->pmin <= j->mix.slot_cmax &&
- i->mix.slot_cmax >= j->opt->pmin)
+ jcmax = j->opt->pmin + j->mix.nch - 1;
+ if (i->opt->pmin <= jcmax &&
+ icmax >= j->opt->pmin)
n++;
}
weight /= n;
@@ -1416,76 +1418,72 @@ dev_mmcloc(struct dev *d, unsigned int origin)
void
slot_allocbufs(struct slot *s)
{
- unsigned int slot_nch, dev_nch;
+ unsigned int dev_nch;
struct dev *d = s->dev;
if (s->mode & MODE_PLAY) {
- s->mix.bpf = s->par.bps *
- (s->mix.slot_cmax - s->opt->pmin + 1);
+ s->mix.bpf = s->par.bps * s->mix.nch;
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;
s->mix.decbuf = NULL;
s->mix.resampbuf = NULL;
s->mix.join = 1;
s->mix.expand = 1;
if (s->opt->dup) {
- if (dev_nch > slot_nch)
- s->mix.expand = dev_nch / slot_nch;
- else if (dev_nch < slot_nch)
- s->mix.join = slot_nch / dev_nch;
+ if (dev_nch > s->mix.nch)
+ s->mix.expand = dev_nch / s->mix.nch;
+ else if (dev_nch < s->mix.nch)
+ s->mix.join = s->mix.nch / dev_nch;
}
cmap_init(&s->mix.cmap,
- s->opt->pmin, s->mix.slot_cmax,
- s->opt->pmin, s->mix.slot_cmax,
+ s->opt->pmin, s->opt->pmin + s->mix.nch - 1,
+ s->opt->pmin, s->opt->pmin + s->mix.nch - 1,
0, d->pchan - 1,
s->opt->pmin, s->opt->pmax);
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 =
- xmalloc(s->round * slot_nch * sizeof(adata_t));
+ xmalloc(s->round * s->mix.nch * sizeof(adata_t));
}
if (s->rate != d->rate) {
resamp_init(&s->mix.resamp, s->round, d->round,
- slot_nch);
+ s->mix.nch);
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) {
- s->sub.bpf = s->par.bps *
- (s->sub.slot_cmax - s->opt->rmin + 1);
+ s->sub.bpf = s->par.bps * s->sub.nch;
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;
s->sub.encbuf = NULL;
s->sub.resampbuf = NULL;
s->sub.join = 1;
s->sub.expand = 1;
if (s->opt->dup) {
- if (dev_nch > slot_nch)
- s->sub.join = dev_nch / slot_nch;
- else if (dev_nch < slot_nch)
- s->sub.expand = slot_nch / dev_nch;
+ if (dev_nch > s->sub.nch)
+ s->sub.join = dev_nch / s->sub.nch;
+ else if (dev_nch < s->sub.nch)
+ 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,
- s->opt->rmin, s->sub.slot_cmax,
- s->opt->rmin, s->sub.slot_cmax);
+ 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) {
resamp_init(&s->sub.resamp, d->round, s->round,
- slot_nch);
+ s->sub.nch);
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)) {
- enc_init(&s->sub.enc, &s->par, slot_nch);
+ enc_init(&s->sub.enc, &s->par, s->sub.nch);
s->sub.encbuf =
- xmalloc(s->round * slot_nch * sizeof(adata_t));
+ xmalloc(s->round * s->sub.nch * sizeof(adata_t));
}
/*
@@ -1496,13 +1494,13 @@ slot_allocbufs(struct slot *s)
*/
if (s->sub.resampbuf) {
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) {
memset(s->sub.encbuf, 0,
- s->round * slot_nch * sizeof(adata_t));
+ s->round * s->sub.nch * sizeof(adata_t));
} else {
memset(s->sub.buf.data, 0,
- s->appbufsz * slot_nch * sizeof(adata_t));
+ s->appbufsz * s->sub.nch * sizeof(adata_t));
}
}
@@ -1670,9 +1668,9 @@ found:
s->mode = mode;
aparams_init(&s->par);
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)
- s->sub.slot_cmax = s->opt->rmax;
+ s->sub.nch = s->opt->rmax - s->opt->rmin + 1;
if (s->opt->mmc) {
s->xrun = XRUN_SYNC;
s->tstate = MMC_STOP;
diff --git a/usr.bin/sndiod/dev.h b/usr.bin/sndiod/dev.h
index 17be95363a7..685eb2928fb 100644
--- a/usr.bin/sndiod/dev.h
+++ b/usr.bin/sndiod/dev.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.h,v 1.18 2018/06/26 07:31:29 ratchov Exp $ */
+/* $OpenBSD: dev.h,v 1.19 2018/06/26 07:36:27 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -47,7 +47,7 @@ struct slot {
unsigned int vol; /* volume within the vol */
struct abuf buf; /* socket side buffer */
int bpf; /* byte per frame */
- int slot_cmax; /* slot source chans */
+ int nch; /* number of play chans */
struct cmap cmap; /* channel mapper state */
struct resamp resamp; /* resampler state */
struct conv dec; /* format decoder params */
@@ -59,7 +59,7 @@ struct slot {
struct abuf buf; /* socket side buffer */
int prime; /* initial cycles to skip */
int bpf; /* byte per frame */
- int slot_cmax; /* slot destination chans */
+ int nch; /* number of rec chans */
struct cmap cmap; /* channel mapper state */
struct resamp resamp; /* buffer for resampling */
struct conv enc; /* buffer for encoding */
diff --git a/usr.bin/sndiod/sock.c b/usr.bin/sndiod/sock.c
index 4060b8b2834..488a51bc4cd 100644
--- a/usr.bin/sndiod/sock.c
+++ b/usr.bin/sndiod/sock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sock.c,v 1.27 2018/06/26 07:31:29 ratchov Exp $ */
+/* $OpenBSD: sock.c,v 1.28 2018/06/26 07:36:27 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -626,7 +626,7 @@ sock_setpar(struct sock *f)
rchan = 1;
else if (rchan > NCHAN_MAX)
rchan = NCHAN_MAX;
- s->sub.slot_cmax = s->opt->rmin + rchan - 1;
+ s->sub.nch = rchan;
#ifdef DEBUG
if (log_level >= 3) {
sock_log(f);
@@ -637,7 +637,7 @@ sock_setpar(struct sock *f)
log_puts(" -> ");
log_putu(s->opt->rmin);
log_puts(":");
- log_putu(s->sub.slot_cmax);
+ log_putu(s->opt->rmin + s->sub.nch - 1);
log_puts("\n");
}
#endif
@@ -647,14 +647,14 @@ sock_setpar(struct sock *f)
pchan = 1;
else if (pchan > NCHAN_MAX)
pchan = NCHAN_MAX;
- s->mix.slot_cmax = s->opt->pmin + pchan - 1;
+ s->mix.nch = pchan;
#ifdef DEBUG
if (log_level >= 3) {
sock_log(f);
log_puts(": playback channels ");
log_putu(s->opt->pmin);
log_puts(":");
- log_putu(s->mix.slot_cmax);
+ log_putu(s->opt->pmin + s->mix.nch - 1);
log_puts(" -> ");
log_putu(s->opt->pmin);
log_puts(":");
@@ -1012,13 +1012,13 @@ sock_execmsg(struct sock *f)
log_puts(", play ");
log_puti(s->opt->pmin);
log_puts(":");
- log_puti(s->mix.slot_cmax);
+ log_puti(s->opt->pmin + s->mix.nch - 1);
}
if (s->mode & MODE_RECMASK) {
log_puts(", rec ");
log_puti(s->opt->rmin);
log_puts(":");
- log_puti(s->sub.slot_cmax);
+ log_puti(s->opt->rmin + s->sub.nch - 1);
}
log_puts(", ");
log_putu(s->appbufsz / s->round);
@@ -1121,14 +1121,10 @@ sock_execmsg(struct sock *f)
m->u.par.sig = s->par.sig;
m->u.par.le = s->par.le;
m->u.par.msb = s->par.msb;
- if (s->mode & MODE_PLAY) {
- m->u.par.pchan = htons(s->mix.slot_cmax -
- s->opt->pmin + 1);
- }
- if (s->mode & MODE_RECMASK) {
- m->u.par.rchan = htons(s->sub.slot_cmax -
- s->opt->rmin + 1);
- }
+ if (s->mode & MODE_PLAY)
+ m->u.par.pchan = htons(s->mix.nch);
+ if (s->mode & MODE_RECMASK)
+ m->u.par.rchan = htons(s->sub.nch);
m->u.par.rate = htonl(s->rate);
m->u.par.appbufsz = htonl(s->appbufsz);
m->u.par.bufsz = htonl(SLOT_BUFSZ(s));