diff options
author | 2018-06-08 06:21:56 +0000 | |
---|---|---|
committer | 2018-06-08 06:21:56 +0000 | |
commit | be3cc2b47092cc368f1e708c6b09fc340bae715e (patch) | |
tree | 14b9f3f30759372fc6eddbc1f059d851af53ef9c | |
parent | The conversion chain processes exactly one block, so no need to (diff) | |
download | wireguard-openbsd-be3cc2b47092cc368f1e708c6b09fc340bae715e.tar.xz wireguard-openbsd-be3cc2b47092cc368f1e708c6b09fc340bae715e.zip |
Greatly simplify the resampling routine using the fact it processes
exactly one block.
-rw-r--r-- | usr.bin/sndiod/dsp.c | 70 | ||||
-rw-r--r-- | usr.bin/sndiod/dsp.h | 5 |
2 files changed, 21 insertions, 54 deletions
diff --git a/usr.bin/sndiod/dsp.c b/usr.bin/sndiod/dsp.c index 794e43ebffc..d0446f10793 100644 --- a/usr.bin/sndiod/dsp.c +++ b/usr.bin/sndiod/dsp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsp.c,v 1.12 2016/10/27 04:37:47 ratchov Exp $ */ +/* $OpenBSD: dsp.c,v 1.13 2018/06/08 06:21:56 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -200,21 +200,26 @@ aparams_native(struct aparams *par) /* * resample the given number of frames */ -int +void resamp_do(struct resamp *p, adata_t *in, adata_t *out, int todo) { unsigned int nch; adata_t *idata; unsigned int oblksz; - unsigned int ifr; int s, ds, diff; adata_t *odata; unsigned int iblksz; - unsigned int ofr; unsigned int c; adata_t *ctxbuf, *ctx; unsigned int ctx_start; +#ifdef DEBUG + if (todo % p->iblksz != 0) { + log_puts("resamp_do: partial blocks not supported\n"); + panic(); + } +#endif + /* * Partially copy structures into local variables, to avoid * unnecessary indirections; this also allows the compiler to @@ -222,30 +227,16 @@ resamp_do(struct resamp *p, adata_t *in, adata_t *out, int todo) */ idata = in; odata = out; - diff = p->diff; + diff = p->oblksz; iblksz = p->iblksz; oblksz = p->oblksz; ctxbuf = p->ctx; ctx_start = p->ctx_start; nch = p->nch; - ifr = todo; - ofr = oblksz; - /* - * Start conversion. - */ -#ifdef DEBUG - if (log_level >= 4) { - log_puts("resamp: copying "); - log_puti(todo); - log_puts(" frames, diff = "); - log_putu(diff); - log_puts("\n"); - } -#endif for (;;) { - if (diff < 0) { - if (ifr == 0) + if (diff >= oblksz) { + if (todo == 0) break; ctx_start ^= 1; ctx = ctxbuf + ctx_start; @@ -253,43 +244,21 @@ resamp_do(struct resamp *p, adata_t *in, adata_t *out, int todo) *ctx = *idata++; ctx += RESAMP_NCTX; } - diff += oblksz; - ifr--; - } else if (diff > 0) { - if (ofr == 0) - break; + diff -= oblksz; + todo--; + } else { ctx = ctxbuf; for (c = nch; c > 0; c--) { - s = ctx[ctx_start]; - ds = ctx[ctx_start ^ 1] - s; + s = ctx[ctx_start ^ 1]; + ds = ctx[ctx_start] - s; ctx += RESAMP_NCTX; *odata++ = s + ADATA_MULDIV(ds, diff, oblksz); } - diff -= iblksz; - ofr--; - } else { - if (ifr == 0 || ofr == 0) - break; - ctx = ctxbuf + ctx_start; - for (c = nch; c > 0; c--) { - *odata++ = *ctx; - ctx += RESAMP_NCTX; - } - ctx_start ^= 1; - ctx = ctxbuf + ctx_start; - for (c = nch; c > 0; c--) { - *ctx = *idata++; - ctx += RESAMP_NCTX; - } - diff -= iblksz; - diff += oblksz; - ifr--; - ofr--; + diff += iblksz; } } - p->diff = diff; + p->ctx_start = ctx_start; - return oblksz - ofr; } /* @@ -303,7 +272,6 @@ resamp_init(struct resamp *p, unsigned int iblksz, p->iblksz = iblksz; p->oblksz = oblksz; - p->diff = 0; p->nch = nch; p->ctx_start = 0; for (i = 0; i < NCHAN_MAX * RESAMP_NCTX; i++) diff --git a/usr.bin/sndiod/dsp.h b/usr.bin/sndiod/dsp.h index e5647b23ceb..3b75a13680f 100644 --- a/usr.bin/sndiod/dsp.h +++ b/usr.bin/sndiod/dsp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dsp.h,v 1.6 2016/10/20 05:29:55 ratchov Exp $ */ +/* $OpenBSD: dsp.h,v 1.7 2018/06/08 06:21:56 ratchov Exp $ */ /* * Copyright (c) 2012 Alexandre Ratchov <alex@caoua.org> * @@ -115,7 +115,6 @@ struct resamp { unsigned int ctx_start; adata_t ctx[NCHAN_MAX * RESAMP_NCTX]; unsigned int iblksz, oblksz; - int diff; int nch; }; @@ -146,7 +145,7 @@ int aparams_strtoenc(struct aparams *, char *); int aparams_enctostr(struct aparams *, char *); int aparams_native(struct aparams *); -int resamp_do(struct resamp *, adata_t *, adata_t *, int); +void resamp_do(struct resamp *, adata_t *, adata_t *, int); void resamp_init(struct resamp *, unsigned int, unsigned int, int); void enc_do(struct conv *, unsigned char *, unsigned char *, int); void enc_sil_do(struct conv *, unsigned char *, int); |