summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/aucat/aparams.c8
-rw-r--r--usr.bin/aucat/aparams.h25
-rw-r--r--usr.bin/aucat/headers.c11
-rw-r--r--usr.bin/aucat/wav.c10
4 files changed, 23 insertions, 31 deletions
diff --git a/usr.bin/aucat/aparams.c b/usr.bin/aucat/aparams.c
index 14047ec20f8..f0e2cbb6ade 100644
--- a/usr.bin/aucat/aparams.c
+++ b/usr.bin/aucat/aparams.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aparams.c,v 1.11 2010/11/04 17:55:28 ratchov Exp $ */
+/* $OpenBSD: aparams.c,v 1.12 2010/11/05 15:23:18 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -116,7 +116,7 @@ aparams_strtoenc(struct aparams *par, char *istr)
return 0;
bps = APARAMS_BPS(bits);
msb = 1;
- le = NATIVE_LE;
+ le = ADATA_LE;
/*
* get (optional) endianness
@@ -176,9 +176,9 @@ aparams_init(struct aparams *par, unsigned cmin, unsigned cmax, unsigned rate)
{
par->bps = sizeof(adata_t);
par->bits = ADATA_BITS;
+ par->le = ADATA_LE;
par->sig = 1;
- par->le = NATIVE_LE;
- par->msb = ADATA_MSB;
+ par->msb = 0;
par->cmin = cmin;
par->cmax = cmax;
par->rate = rate;
diff --git a/usr.bin/aucat/aparams.h b/usr.bin/aucat/aparams.h
index d96dc0677bf..1ff95473082 100644
--- a/usr.bin/aucat/aparams.h
+++ b/usr.bin/aucat/aparams.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: aparams.h,v 1.9 2010/11/04 17:55:28 ratchov Exp $ */
+/* $OpenBSD: aparams.h,v 1.10 2010/11/05 15:23:18 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -31,14 +31,6 @@
*/
#define ENCMAX 10
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define NATIVE_LE 1
-#elif BYTE_ORDER == BIG_ENDIAN
-#define NATIVE_LE 0
-#else
-/* not defined */
-#endif
-
/*
* Default bytes per sample for the given bits per sample.
*/
@@ -59,19 +51,18 @@ struct aparams {
/*
* Samples are numbers in the interval [-1, 1[, note that 1, the upper
- * boundary is excluded. We represent them in 16-bit signed fixed point
- * numbers, so that we can do all multiplications and divisions in
- * 32-bit precision without having to deal with overflows.
+ * boundary is excluded. We represent them as signed fixed point numbers
+ * of ADATA_BITS. We also assume that 2^(ADATA_BITS - 1) fits in a int.
*/
+#define ADATA_BITS 16
+#define ADATA_LE (BYTE_ORDER == LITTLE_ENDIAN)
+#define ADATA_UNIT (1 << (ADATA_BITS - 1))
+
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_UNIT (1 << (ADATA_BITS - 1))
-#define ADATA_MAX (ADATA_UNIT - 1)
-
#define MIDI_MAXCTL 127
#define MIDI_TO_ADATA(m) (aparams_ctltovol[m] << (ADATA_BITS - 16))
diff --git a/usr.bin/aucat/headers.c b/usr.bin/aucat/headers.c
index 37594e2afc2..f53f3ef8b54 100644
--- a/usr.bin/aucat/headers.c
+++ b/usr.bin/aucat/headers.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: headers.c,v 1.18 2010/06/05 16:54:19 ratchov Exp $ */
+/* $OpenBSD: headers.c,v 1.19 2010/11/05 15:23:18 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -148,17 +148,18 @@ wav_readfmt(int fd, unsigned csize, struct aparams *par, short **map)
par->bits = bits;
par->le = 1;
par->sig = (bits <= 8) ? 0 : 1; /* ask microsoft why... */
+ par->msb = 1;
} else {
if (bits != 8) {
warnx("%u: mulaw/alaw encoding not 8-bit", bits);
return 0;
}
- par->bits = 8 * sizeof(short);
- par->bps = sizeof(short);
- par->le = NATIVE_LE;
+ par->bits = ADATA_BITS;
+ par->bps = sizeof(adata_t);
+ par->le = ADATA_LE;
par->sig = 1;
+ par->msb = 0;
}
- par->msb = 1;
par->cmax = cmax;
par->rate = rate;
return 1;
diff --git a/usr.bin/aucat/wav.c b/usr.bin/aucat/wav.c
index d901ad3f927..4ab6ba9a428 100644
--- a/usr.bin/aucat/wav.c
+++ b/usr.bin/aucat/wav.c
@@ -203,14 +203,14 @@ wav_conv(unsigned char *data, unsigned count, short *map)
{
unsigned i;
unsigned char *iptr;
- short *optr;
+ adata_t *optr;
iptr = data + count;
- optr = (short *)data + count;
+ optr = (adata_t *)data + count;
for (i = count; i > 0; i--) {
--optr;
--iptr;
- *optr = map[*iptr];
+ *optr = (adata_t)(map[*iptr]) << (ADATA_BITS - 16);
}
}
@@ -224,7 +224,7 @@ wav_read(struct file *file, unsigned char *data, unsigned count)
unsigned n;
if (f->map)
- count /= sizeof(short);
+ count /= sizeof(adata_t);
if (f->rbytes >= 0 && count > f->rbytes) {
count = f->rbytes; /* file->rbytes fits in count */
if (count == 0) {
@@ -246,7 +246,7 @@ wav_read(struct file *file, unsigned char *data, unsigned count)
f->rbytes -= n;
if (f->map) {
wav_conv(data, n, f->map);
- n *= sizeof(short);
+ n *= sizeof(adata_t);
}
return n;
}