OSDN Git Service

sbc: Update copyright information
[android-x86/external-bluetooth-sbc.git] / sbc / sbc_math.h
1 /*
2  *
3  *  Bluetooth low-complexity, subband codec (SBC) library
4  *
5  *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
6  *  Copyright (C) 2004-2005  Henryk Ploetz <henryk@ploetzli.ch>
7  *  Copyright (C) 2005-2008  Brad Midgley <bmidgley@xmission.com>
8  *
9  *
10  *  This library is free software; you can redistribute it and/or
11  *  modify it under the terms of the GNU Lesser General Public
12  *  License as published by the Free Software Foundation; either
13  *  version 2.1 of the License, or (at your option) any later version.
14  *
15  *  This library is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  *  Lesser General Public License for more details.
19  *
20  *  You should have received a copy of the GNU Lesser General Public
21  *  License along with this library; if not, write to the Free Software
22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23  *
24  */
25
26 #define fabs(x) ((x) < 0 ? -(x) : (x))
27 /* C does not provide an explicit arithmetic shift right but this will
28    always be correct and every compiler *should* generate optimal code */
29 #define ASR(val, bits) ((-2 >> 1 == -1) ? \
30                  ((int32_t)(val)) >> (bits) : ((int32_t) (val)) / (1 << (bits)))
31
32 #define SCALE_SPROTO4_TBL       12
33 #define SCALE_SPROTO8_TBL       14
34 #define SCALE_NPROTO4_TBL       11
35 #define SCALE_NPROTO8_TBL       11
36 #define SCALE4_STAGED1_BITS     15
37 #define SCALE4_STAGED2_BITS     16
38 #define SCALE8_STAGED1_BITS     15
39 #define SCALE8_STAGED2_BITS     16
40
41 typedef int32_t sbc_fixed_t;
42
43 #define SCALE4_STAGED1(src) ASR(src, SCALE4_STAGED1_BITS)
44 #define SCALE4_STAGED2(src) ASR(src, SCALE4_STAGED2_BITS)
45 #define SCALE8_STAGED1(src) ASR(src, SCALE8_STAGED1_BITS)
46 #define SCALE8_STAGED2(src) ASR(src, SCALE8_STAGED2_BITS)
47
48 #define SBC_FIXED_0(val) { val = 0; }
49 #define MUL(a, b)        ((a) * (b))
50 #ifdef __arm__
51 #define MULA(a, b, res) ({                              \
52                 int tmp = res;                  \
53                 __asm__(                                \
54                         "mla %0, %2, %3, %0"            \
55                         : "=&r" (tmp)                   \
56                         : "0" (tmp), "r" (a), "r" (b)); \
57                 tmp; })
58 #else
59 #define MULA(a, b, res)  ((a) * (b) + (res))
60 #endif