diff options
| author | Marcel Holtmann <marcel@holtmann.org> | 2007-02-21 14:23:25 +0000 | 
|---|---|---|
| committer | Marcel Holtmann <marcel@holtmann.org> | 2007-02-21 14:23:25 +0000 | 
| commit | ec31984c45d9b3dd272ec3ecb9a5270a00494699 (patch) | |
| tree | 12d36225b1259a20edde36fe2fd58d6d8b9e7745 /sbc/sbc_math.h | |
| parent | 5430ca31bc276a9d07c932383910ef600ef08c87 (diff) | |
Add SBC helper includes
Diffstat (limited to 'sbc/sbc_math.h')
| -rw-r--r-- | sbc/sbc_math.h | 65 | 
1 files changed, 65 insertions, 0 deletions
diff --git a/sbc/sbc_math.h b/sbc/sbc_math.h new file mode 100644 index 00000000..c427bee3 --- /dev/null +++ b/sbc/sbc_math.h @@ -0,0 +1,65 @@ +/* + * + *  Bluetooth low-complexity, subband codec (SBC) library + * + *  Copyright (C) 2004-2007  Marcel Holtmann <marcel@holtmann.org> + * + * + *  This library is free software; you can redistribute it and/or + *  modify it under the terms of the GNU Lesser General Public + *  License as published by the Free Software Foundation; either + *  version 2.1 of the License, or (at your option) any later version. + * + *  This library is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + *  Lesser General Public License for more details. + * + *  You should have received a copy of the GNU Lesser General Public + *  License along with this library; if not, write to the Free Software + *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA + * + */ + +#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))) + +#define SCALE_PROTO4_TBL	15 +#define SCALE_ANA4_TBL		16 +#define SCALE_PROTO8_TBL	15 +#define SCALE_ANA8_TBL		16 +#define SCALE_SPROTO4_TBL	16 +#define SCALE_SPROTO8_TBL	16 +#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 + +typedef int32_t sbc_fixed_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 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 DIV2(dst, src)   { dst = ASR(src, 1); }  | 
