diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2010-11-05 16:42:18 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2010-11-05 16:42:18 +0000 |
commit | 3d4aaf4cc1b60adf12d0ea4f9e586666523e35b3 (patch) | |
tree | 31bc7401bbf6bd99e5582f748cb73a22d9d1f339 /usr.bin | |
parent | 4c55428c95207083526364037a6695dbce63d5b7 (diff) |
Add experimental support for 24-bit arithmetic, meaning that full
dynamic range of 24-bit hardware can be used. Offline processing like
mixing and channel mapping is done with 24-bit precision too.
Since most hardware and audio programs use 16-bit precision, 24-bit
processing is a small waste of CPU time in many cases, so 24-bit
processing is not desirable and this is disabled by default.
Furthermore it's available on i386, amd64 and sparc64 only. To
experiment with it:
make COPTS="-DADATA_BITS=24"
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/aucat/aparams.h | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/usr.bin/aucat/aparams.h b/usr.bin/aucat/aparams.h index 1ff95473082..972b2a58db7 100644 --- a/usr.bin/aucat/aparams.h +++ b/usr.bin/aucat/aparams.h @@ -1,4 +1,4 @@ -/* $OpenBSD: aparams.h,v 1.10 2010/11/05 15:23:18 ratchov Exp $ */ +/* $OpenBSD: aparams.h,v 1.11 2010/11/05 16:42:17 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -54,15 +54,72 @@ struct aparams { * 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. */ +#ifndef ADATA_BITS #define ADATA_BITS 16 +#endif #define ADATA_LE (BYTE_ORDER == LITTLE_ENDIAN) #define ADATA_UNIT (1 << (ADATA_BITS - 1)) +#if ADATA_BITS == 16 + typedef short adata_t; #define ADATA_MUL(x,y) (((int)(x) * (int)(y)) >> (ADATA_BITS - 1)) #define ADATA_MULDIV(x,y,z) ((int)(x) * (int)(y) / (int)(z)) +#elif ADATA_BITS == 24 + +typedef int adata_t; + +#if defined(__i386__) && defined(__GNUC__) + +static inline int +fp24_mul(int x, int a) +{ + int res; + + asm volatile ( + "imull %2\n\t" + "shrdl $23, %%edx, %%eax\n\t" + : "=a" (res) + : "a" (x), "r" (a) + : "%edx" + ); + return res; +} + +static inline int +fp24_muldiv(int x, int a, int b) +{ + int res; + + asm volatile ( + "imull %2\n\t" + "idivl %3\n\t" + : "=a" (res) + : "a" (x), "d" (a), "r" (b) + ); + return res; +} + +#define ADATA_MUL(x,y) fp24_mul(x, y) +#define ADATA_MULDIV(x,y,z) fp24_muldiv(x, y, z); + +#elif defined(__amd64__) || defined(__sparc64__) + +#define ADATA_MUL(x,y) \ + ((int)(((long long)(x) * (long long)(y)) >> (ADATA_BITS - 1))) +#define ADATA_MULDIV(x,y,z) \ + ((int)((long long)(x) * (long long)(y) / (long long)(z))) + +#else +#error "no 24-bit code for this architecture" +#endif + +#else +#error "only 16-bit and 24-bit precisions are supported" +#endif + #define MIDI_MAXCTL 127 #define MIDI_TO_ADATA(m) (aparams_ctltovol[m] << (ADATA_BITS - 16)) |