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