diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2010-11-04 17:55:29 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2010-11-04 17:55:29 +0000 |
commit | ee8d0dcb650dcd024bff514c11b95b9c4034f0cc (patch) | |
tree | 3191cb36503b748ddd43fc92450116ecc22c2d0f /usr.bin/aucat | |
parent | f93be0815e9576e63b278db9ccc4ae196c4b23f2 (diff) |
Replace ``short'' by a new ``adata_t'' typedef corresponding to
audio samples and cleanup ADATA_XXX macros. This allows easilly
switching to 24 bit fixed point arithmetic by simply redefining
the adata_t typedef to int and updating ADATA_XXX macros. No
object change.
Diffstat (limited to 'usr.bin/aucat')
-rw-r--r-- | usr.bin/aucat/aparams.c | 10 | ||||
-rw-r--r-- | usr.bin/aucat/aparams.h | 13 | ||||
-rw-r--r-- | usr.bin/aucat/aproc.c | 72 | ||||
-rw-r--r-- | usr.bin/aucat/aproc.h | 4 | ||||
-rw-r--r-- | usr.bin/aucat/sock.c | 6 |
5 files changed, 53 insertions, 52 deletions
diff --git a/usr.bin/aucat/aparams.c b/usr.bin/aucat/aparams.c index ad3c2a1abda..14047ec20f8 100644 --- a/usr.bin/aucat/aparams.c +++ b/usr.bin/aucat/aparams.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aparams.c,v 1.10 2010/01/10 21:47:41 ratchov Exp $ */ +/* $OpenBSD: aparams.c,v 1.11 2010/11/04 17:55:28 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -174,11 +174,11 @@ done: void aparams_init(struct aparams *par, unsigned cmin, unsigned cmax, unsigned rate) { - par->bps = 2; /* 2 bytes per sample */ - par->bits = 16; /* 16 significant bits per sample */ - par->sig = 1; /* samples are signed */ + par->bps = sizeof(adata_t); + par->bits = ADATA_BITS; + par->sig = 1; par->le = NATIVE_LE; - par->msb = 1; /* msb justified */ + par->msb = ADATA_MSB; par->cmin = cmin; par->cmax = cmax; par->rate = rate; diff --git a/usr.bin/aucat/aparams.h b/usr.bin/aucat/aparams.h index c36195e642a..d96dc0677bf 100644 --- a/usr.bin/aucat/aparams.h +++ b/usr.bin/aucat/aparams.h @@ -1,4 +1,4 @@ -/* $OpenBSD: aparams.h,v 1.8 2009/09/27 11:51:20 ratchov Exp $ */ +/* $OpenBSD: aparams.h,v 1.9 2010/11/04 17:55:28 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -63,14 +63,17 @@ struct aparams { * numbers, so that we can do all multiplications and divisions in * 32-bit precision without having to deal with overflows. */ +typedef short adata_t; +#define ADATA_BITS 16 +#define ADATA_MSB 1 +#define ADATA_MUL(x,y) (((int)(x) * (int)(y)) >> (ADATA_BITS - 1)) +#define ADATA_MULDIV(x,y,z) ((int)(x) * (int)(y) / (int)(z)) -#define ADATA_SHIFT (8 * sizeof(short) - 1) -#define ADATA_UNIT (1 << ADATA_SHIFT) +#define ADATA_UNIT (1 << (ADATA_BITS - 1)) #define ADATA_MAX (ADATA_UNIT - 1) -#define ADATA_MUL(x,y) (((x) * (y)) >> ADATA_SHIFT) #define MIDI_MAXCTL 127 -#define MIDI_TO_ADATA(m) (aparams_ctltovol[m]) +#define MIDI_TO_ADATA(m) (aparams_ctltovol[m] << (ADATA_BITS - 16)) extern int aparams_ctltovol[128]; extern struct aparams aparams_none; diff --git a/usr.bin/aucat/aproc.c b/usr.bin/aucat/aproc.c index 316872ac459..f74beb4ae32 100644 --- a/usr.bin/aucat/aproc.c +++ b/usr.bin/aucat/aproc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aproc.c,v 1.62 2010/10/21 21:42:46 ratchov Exp $ */ +/* $OpenBSD: aproc.c,v 1.63 2010/11/04 17:55:28 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -583,13 +583,13 @@ mix_drop(struct abuf *buf, int extra) void mix_bzero(struct abuf *obuf, unsigned maxtodo) { - short *odata; + adata_t *odata; unsigned ocount, todo; if (obuf->w.mix.todo >= maxtodo) return; todo = maxtodo - obuf->w.mix.todo; - odata = (short *)abuf_wgetblk(obuf, &ocount, obuf->w.mix.todo); + odata = (adata_t *)abuf_wgetblk(obuf, &ocount, obuf->w.mix.todo); if (ocount > todo) ocount = todo; if (ocount == 0) @@ -612,7 +612,7 @@ mix_bzero(struct abuf *obuf, unsigned maxtodo) unsigned mix_badd(struct abuf *ibuf, struct abuf *obuf) { - short *idata, *odata; + adata_t *idata, *odata; unsigned cmin, cmax; unsigned i, j, cc, istart, inext, onext, ostart; unsigned scount, icount, ocount; @@ -647,21 +647,21 @@ mix_badd(struct abuf *ibuf, struct abuf *obuf) /* * Calculate the maximum we can read. */ - idata = (short *)abuf_rgetblk(ibuf, &icount, 0); + idata = (adata_t *)abuf_rgetblk(ibuf, &icount, 0); if (icount == 0) return 0; /* * Calculate the maximum we can write. */ - odata = (short *)abuf_wgetblk(obuf, &ocount, ibuf->r.mix.done); + odata = (adata_t *)abuf_wgetblk(obuf, &ocount, ibuf->r.mix.done); if (ocount == 0) return 0; scount = (icount < ocount) ? icount : ocount; mix_bzero(obuf, scount + ibuf->r.mix.done); - vol = (ibuf->r.mix.weight * ibuf->r.mix.vol) >> ADATA_SHIFT; + vol = ADATA_MUL(ibuf->r.mix.weight, ibuf->r.mix.vol); cmin = obuf->cmin > ibuf->cmin ? obuf->cmin : ibuf->cmin; cmax = obuf->cmax < ibuf->cmax ? obuf->cmax : ibuf->cmax; ostart = cmin - obuf->cmin; @@ -673,7 +673,7 @@ mix_badd(struct abuf *ibuf, struct abuf *obuf) idata += istart; for (i = scount; i > 0; i--) { for (j = cc; j > 0; j--) { - *odata += (*idata * vol) >> ADATA_SHIFT; + *odata += ADATA_MUL(*idata, vol); idata++; odata++; } @@ -1155,7 +1155,7 @@ sub_silence(struct abuf *buf, int extra) void sub_bcopy(struct abuf *ibuf, struct abuf *obuf) { - short *idata, *odata; + adata_t *idata, *odata; unsigned cmin, cmax; unsigned i, j, cc, istart, inext, onext, ostart; unsigned icount, ocount, scount; @@ -1171,10 +1171,10 @@ sub_bcopy(struct abuf *ibuf, struct abuf *obuf) obuf->w.sub.silence += scount; } - idata = (short *)abuf_rgetblk(ibuf, &icount, obuf->w.sub.done); + idata = (adata_t *)abuf_rgetblk(ibuf, &icount, obuf->w.sub.done); if (icount == 0) return; - odata = (short *)abuf_wgetblk(obuf, &ocount, 0); + odata = (adata_t *)abuf_wgetblk(obuf, &ocount, 0); if (ocount == 0) return; cmin = obuf->cmin > ibuf->cmin ? obuf->cmin : ibuf->cmin; @@ -1459,26 +1459,26 @@ void resamp_bcopy(struct aproc *p, struct abuf *ibuf, struct abuf *obuf) { unsigned inch; - short *idata; + adata_t *idata; unsigned oblksz; unsigned ifr; unsigned onch; - int s1, s2, diff; - short *odata; + int s, ds, diff; + adata_t *odata; unsigned iblksz; unsigned ofr; unsigned c; - short *ctxbuf, *ctx; + adata_t *ctxbuf, *ctx; unsigned ctx_start; unsigned icount, ocount; /* * Calculate max frames readable at once from the input buffer. */ - idata = (short *)abuf_rgetblk(ibuf, &icount, 0); + idata = (adata_t *)abuf_rgetblk(ibuf, &icount, 0); ifr = icount; - odata = (short *)abuf_wgetblk(obuf, &ocount, 0); + odata = (adata_t *)abuf_wgetblk(obuf, &ocount, 0); ofr = ocount; /* @@ -1526,10 +1526,10 @@ resamp_bcopy(struct aproc *p, struct abuf *ibuf, struct abuf *obuf) break; ctx = ctxbuf; for (c = onch; c > 0; c--) { - s1 = ctx[ctx_start]; - s2 = ctx[ctx_start ^ 1]; + s = ctx[ctx_start]; + ds = ctx[ctx_start ^ 1] - s; ctx += RESAMP_NCTX; - *odata++ = s1 + (s2 - s1) * diff / (int)oblksz; + *odata++ = s + ADATA_MULDIV(ds, diff, oblksz); } diff -= iblksz; ofr--; @@ -1685,7 +1685,7 @@ enc_bcopy(struct aproc *p, struct abuf *ibuf, struct abuf *obuf) { unsigned nch, scount, icount, ocount; unsigned f; - short *idata; + adata_t *idata; int s; unsigned oshift; int osigbit; @@ -1698,7 +1698,7 @@ enc_bcopy(struct aproc *p, struct abuf *ibuf, struct abuf *obuf) /* * Calculate max frames readable at once from the input buffer. */ - idata = (short *)abuf_rgetblk(ibuf, &icount, 0); + idata = (adata_t *)abuf_rgetblk(ibuf, &icount, 0); if (icount == 0) return; odata = abuf_wgetblk(obuf, &ocount, 0); @@ -1733,7 +1733,7 @@ enc_bcopy(struct aproc *p, struct abuf *ibuf, struct abuf *obuf) odata += p->u.conv.bfirst; for (f = scount * nch; f > 0; f--) { s = *idata++; - s <<= 16; + s <<= 32 - ADATA_BITS; s >>= oshift; s ^= osigbit; for (i = obps; i > 0; i--) { @@ -1851,7 +1851,7 @@ dec_bcopy(struct aproc *p, struct abuf *ibuf, struct abuf *obuf) int isnext; int isigbit; unsigned ishift; - short *odata; + adata_t *odata; /* * Calculate max frames readable at once from the input buffer. @@ -1859,7 +1859,7 @@ dec_bcopy(struct aproc *p, struct abuf *ibuf, struct abuf *obuf) idata = abuf_rgetblk(ibuf, &icount, 0); if (icount == 0) return; - odata = (short *)abuf_wgetblk(obuf, &ocount, 0); + odata = (adata_t *)abuf_wgetblk(obuf, &ocount, 0); if (ocount == 0) return; scount = (icount < ocount) ? icount : ocount; @@ -1898,7 +1898,7 @@ dec_bcopy(struct aproc *p, struct abuf *ibuf, struct abuf *obuf) idata += isnext; s ^= isigbit; s <<= ishift; - s >>= 16; + s >>= 32 - ADATA_BITS; *odata++ = s; } @@ -2001,19 +2001,19 @@ join_bcopy(struct aproc *p, struct abuf *ibuf, struct abuf *obuf) { unsigned h, hops; unsigned inch, inext; - short *idata; + adata_t *idata; unsigned onch, onext; - short *odata; + adata_t *odata; int scale; unsigned c, f, scount, icount, ocount; /* * Calculate max frames readable at once from the input buffer. */ - idata = (short *)abuf_rgetblk(ibuf, &icount, 0); + idata = (adata_t *)abuf_rgetblk(ibuf, &icount, 0); if (icount == 0) return; - odata = (short *)abuf_wgetblk(obuf, &ocount, 0); + odata = (adata_t *)abuf_wgetblk(obuf, &ocount, 0); if (ocount == 0) return; scount = icount < ocount ? icount : ocount; @@ -2043,13 +2043,11 @@ join_bcopy(struct aproc *p, struct abuf *ibuf, struct abuf *obuf) hops--; for (f = scount; f > 0; f--) { for (c = onch; c > 0; c--) - *odata++ = (*idata++ * scale) - >> ADATA_SHIFT; + *odata++ = ADATA_MUL(*idata++, scale); for (h = hops; h > 0; h--) { odata -= onch; for (c = onch; c > 0; c--) - *odata++ += (*idata++ * scale) - >> ADATA_SHIFT; + *odata++ += ADATA_MUL(*idata++, scale); } idata += inext; } @@ -2178,7 +2176,7 @@ mon_snoop(struct aproc *p, struct abuf *ibuf, unsigned pos, unsigned todo) { struct abuf *obuf = LIST_FIRST(&p->outs); unsigned scount, icount, ocount; - short *idata, *odata; + adata_t *idata, *odata; #ifdef DEBUG if (debug_level >= 4) { @@ -2197,8 +2195,8 @@ mon_snoop(struct aproc *p, struct abuf *ibuf, unsigned pos, unsigned todo) /* * Calculate max frames readable at once from the input buffer. */ - idata = (short *)abuf_rgetblk(ibuf, &icount, pos); - odata = (short *)abuf_wgetblk(obuf, &ocount, p->u.mon.pending); + idata = (adata_t *)abuf_rgetblk(ibuf, &icount, pos); + odata = (adata_t *)abuf_wgetblk(obuf, &ocount, p->u.mon.pending); scount = (icount < ocount) ? icount : ocount; #ifdef DEBUG if (debug_level >= 4) { diff --git a/usr.bin/aucat/aproc.h b/usr.bin/aucat/aproc.h index 16b6e48dbfe..ee6233cd463 100644 --- a/usr.bin/aucat/aproc.h +++ b/usr.bin/aucat/aproc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: aproc.h,v 1.37 2010/06/04 06:15:28 ratchov Exp $ */ +/* $OpenBSD: aproc.h,v 1.38 2010/11/04 17:55:28 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -157,7 +157,7 @@ struct aproc { struct { #define RESAMP_NCTX 2 unsigned ctx_start; - short ctx[NCHAN_MAX * RESAMP_NCTX]; + adata_t ctx[NCHAN_MAX * RESAMP_NCTX]; unsigned iblksz, oblksz; int diff; int idelta, odelta; /* remainder of resamp_xpos */ diff --git a/usr.bin/aucat/sock.c b/usr.bin/aucat/sock.c index 02661970bed..bec68404846 100644 --- a/usr.bin/aucat/sock.c +++ b/usr.bin/aucat/sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sock.c,v 1.52 2010/10/21 19:10:52 ratchov Exp $ */ +/* $OpenBSD: sock.c,v 1.53 2010/11/04 17:55:28 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -1326,8 +1326,8 @@ sock_execmsg(struct sock *f) (f->opt->rpar.cmax - f->opt->rpar.cmin + 1) : 0; m->u.cap.rchan = (f->opt->mode & (MODE_PLAY | MODE_REC)) ? (f->opt->wpar.cmax - f->opt->wpar.cmin + 1) : 0; - m->u.cap.bits = sizeof(short) * 8; - m->u.cap.bps = sizeof(short); + m->u.cap.bits = ADATA_BITS; + m->u.cap.bps = sizeof(adata_t); f->rstate = SOCK_RRET; f->rtodo = sizeof(struct amsg); break; |