From 5e033425c0f8db4192abd6d744831d0e498a309d Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Wed, 18 Sep 2019 09:34:59 +0200 Subject: [PATCH] Move slot convertions setup in its own routine. --- sndiod/dev.c | 56 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/sndiod/dev.c b/sndiod/dev.c index 1105e8d..668cda8 100644 --- a/sndiod/dev.c +++ b/sndiod/dev.c @@ -83,6 +83,7 @@ void slot_attach(struct slot *); void slot_ready(struct slot *); void slot_allocbufs(struct slot *); void slot_freebufs(struct slot *); +void slot_initconv(struct slot *); void slot_start(struct slot *); void slot_detach(struct slot *); void slot_stop(struct slot *); @@ -1432,15 +1433,12 @@ dev_mmcloc(struct dev *d, unsigned int origin) * allocate buffers & conversion chain */ void -slot_allocbufs(struct slot *s) +slot_initconv(struct slot *s) { unsigned int dev_nch; struct dev *d = s->dev; if (s->mode & MODE_PLAY) { - s->mix.bpf = s->par.bps * s->mix.nch; - abuf_init(&s->mix.buf, s->appbufsz * s->mix.bpf); - dev_nch = s->opt->pmax - s->opt->pmin + 1; s->mix.decbuf = NULL; s->mix.resampbuf = NULL; @@ -1459,21 +1457,14 @@ slot_allocbufs(struct slot *s) s->opt->pmin, s->opt->pmax); if (!aparams_native(&s->par)) { dec_init(&s->mix.dec, &s->par, s->mix.nch); - s->mix.decbuf = - xmalloc(s->round * s->mix.nch * sizeof(adata_t)); } if (s->rate != d->rate) { resamp_init(&s->mix.resamp, s->round, d->round, s->mix.nch); - s->mix.resampbuf = - xmalloc(d->round * s->mix.nch * sizeof(adata_t)); } } if (s->mode & MODE_RECMASK) { - s->sub.bpf = s->par.bps * s->sub.nch; - abuf_init(&s->sub.buf, s->appbufsz * s->sub.bpf); - dev_nch = s->opt->rmax - s->opt->rmin + 1; s->sub.encbuf = NULL; s->sub.resampbuf = NULL; @@ -1493,13 +1484,9 @@ slot_allocbufs(struct slot *s) if (s->rate != d->rate) { resamp_init(&s->sub.resamp, d->round, s->round, s->sub.nch); - s->sub.resampbuf = - xmalloc(d->round * s->sub.nch * sizeof(adata_t)); } if (!aparams_native(&s->par)) { enc_init(&s->sub.enc, &s->par, s->sub.nch); - s->sub.encbuf = - xmalloc(s->round * s->sub.nch * sizeof(adata_t)); } /* @@ -1519,6 +1506,45 @@ slot_allocbufs(struct slot *s) s->appbufsz * s->sub.nch * sizeof(adata_t)); } } +} + +/* + * allocate buffers & conversion chain + */ +void +slot_allocbufs(struct slot *s) +{ + struct dev *d = s->dev; + + if (s->mode & MODE_PLAY) { + s->mix.bpf = s->par.bps * s->mix.nch; + abuf_init(&s->mix.buf, s->appbufsz * s->mix.bpf); + + if (!aparams_native(&s->par)) { + s->mix.decbuf = + xmalloc(s->round * s->mix.nch * sizeof(adata_t)); + } + if (s->rate != d->rate) { + s->mix.resampbuf = + xmalloc(d->round * s->mix.nch * sizeof(adata_t)); + } + } + + if (s->mode & MODE_RECMASK) { + s->sub.bpf = s->par.bps * s->sub.nch; + abuf_init(&s->sub.buf, s->appbufsz * s->sub.bpf); + + if (s->rate != d->rate) { + s->sub.resampbuf = + xmalloc(d->round * s->sub.nch * sizeof(adata_t)); + } + if (!aparams_native(&s->par)) { + s->sub.encbuf = + xmalloc(s->round * s->sub.nch * sizeof(adata_t)); + } + } + + slot_initconv(s); #ifdef DEBUG if (log_level >= 3) {