diff options
author | Brad Midgley <bmidgley@xmission.com> | 2007-03-17 13:37:31 +0000 |
---|---|---|
committer | Brad Midgley <bmidgley@xmission.com> | 2007-03-17 13:37:31 +0000 |
commit | ad868bd4137e86fbf141175f411898796287ff2a (patch) | |
tree | 85321330a17866bc08925f8fa3d4a40922fcfbda /sbc/sbc_math.h | |
parent | 1055292b83db7b5eb211a07d1d05c3450faaef20 (diff) |
update the sbc encoder from the working fixed-point code in the sbc project
I also tagged the sbc project with "copied-to-bluez-utils" at the same time.
We will do sbc work under bluez and sync it with the old sbc project if necessary.
Diffstat (limited to 'sbc/sbc_math.h')
-rw-r--r-- | sbc/sbc_math.h | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/sbc/sbc_math.h b/sbc/sbc_math.h index c427bee3..f6247ef8 100644 --- a/sbc/sbc_math.h +++ b/sbc/sbc_math.h @@ -2,7 +2,9 @@ * * Bluetooth low-complexity, subband codec (SBC) library * - * Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org> + * Copyright (C) 2004-2006 Marcel Holtmann <marcel@holtmann.org> + * Copyright (C) 2004-2005 Henryk Ploetz <henryk@ploetzli.ch> + * Copyright (C) 2005-2006 Brad Midgley <bmidgley@xmission.com> * * * This library is free software; you can redistribute it and/or @@ -22,11 +24,12 @@ */ #define fabs(x) ((x) < 0 ? -(x) : (x)) - /* C does not provide an explicit arithmetic shift right but this will always be correct and every compiler *should* generate optimal code */ #define ASR(val, bits) ((-2 >> 1 == -1) ? \ - ((int32_t) (val)) >> (bits) : ((int32_t) (val)) / (1 << (bits))) + ((int32_t)(val)) >> (bits) : ((int32_t) (val)) / (1 << (bits))) +#define ASR_64(val, bits) ((-2 >> 1 == -1) ? \ + ((long long)(val)) >> (bits) : ((long long) (val)) / (1 << (bits))) #define SCALE_PROTO4_TBL 15 #define SCALE_ANA4_TBL 16 @@ -37,29 +40,30 @@ #define SCALE_NPROTO4_TBL 10 #define SCALE_NPROTO8_TBL 12 #define SCALE_SAMPLES 14 -#define SCALE4_STAGE1_BITS 16 -#define SCALE4_STAGE2_BITS 18 -#define SCALE4_STAGED1_BITS 15 -#define SCALE4_STAGED2_BITS 15 -#define SCALE8_STAGE1_BITS 16 -#define SCALE8_STAGE2_BITS 18 -#define SCALE8_STAGED1_BITS 15 -#define SCALE8_STAGED2_BITS 15 +#define SCALE4_STAGE1_BITS 10 +#define SCALE4_STAGE2_BITS 21 +#define SCALE4_STAGED1_BITS 18 +#define SCALE4_STAGED2_BITS 23 +#define SCALE8_STAGE1_BITS 8 +#define SCALE8_STAGE2_BITS 24 +#define SCALE8_STAGED1_BITS 18 +#define SCALE8_STAGED2_BITS 23 typedef int32_t sbc_fixed_t; +typedef long long sbc_extended_t; -#define SCALE4_STAGE1(src) ASR(src, SCALE4_STAGE1_BITS) -#define SCALE4_STAGE2(src) ASR(src, SCALE4_STAGE2_BITS) -#define SCALE4_STAGED1(src) ASR(src, SCALE4_STAGED1_BITS) -#define SCALE4_STAGED2(src) ASR(src, SCALE4_STAGED2_BITS) -#define SCALE8_STAGE1(src) ASR(src, SCALE8_STAGE1_BITS) -#define SCALE8_STAGE2(src) ASR(src, SCALE8_STAGE2_BITS) -#define SCALE8_STAGED1(src) ASR(src, SCALE8_STAGED1_BITS) -#define SCALE8_STAGED2(src) ASR(src, SCALE8_STAGED2_BITS) +#define SCALE4_STAGE1(src) ASR_64(src, SCALE4_STAGE1_BITS) +#define SCALE4_STAGE2(src) ASR_64(src, SCALE4_STAGE2_BITS) +#define SCALE4_STAGED1(src) ASR_64(src, SCALE4_STAGED1_BITS) +#define SCALE4_STAGED2(src) ASR_64(src, SCALE4_STAGED2_BITS) +#define SCALE8_STAGE1(src) ASR_64(src, SCALE8_STAGE1_BITS) +#define SCALE8_STAGE2(src) ASR_64(src, SCALE8_STAGE2_BITS) +#define SCALE8_STAGED1(src) ASR_64(src, SCALE8_STAGED1_BITS) +#define SCALE8_STAGED2(src) ASR_64(src, SCALE8_STAGED2_BITS) #define SBC_FIXED_0(val) { val = 0; } #define ADD(dst, src) { dst += src; } #define SUB(dst, src) { dst -= src; } #define MUL(dst, a, b) { dst = (sbc_fixed_t) a * b; } -#define MULA(dst, a, b) { dst += (sbc_fixed_t) a * b; } +#define MULA(dst, a, b) { dst += (sbc_extended_t) a * b; } #define DIV2(dst, src) { dst = ASR(src, 1); } |