1 2/* ----------------------------------------------------------------------------------------------------------- 3Software License for The Fraunhofer FDK AAC Codec Library for Android 4 5© Copyright 1995 - 2012 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. 6 All rights reserved. 7 8 1. INTRODUCTION 9The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements 10the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio. 11This FDK AAC Codec software is intended to be used on a wide variety of Android devices. 12 13AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual 14audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by 15independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part 16of the MPEG specifications. 17 18Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer) 19may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners 20individually for the purpose of encoding or decoding bit streams in products that are compliant with 21the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license 22these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec 23software may already be covered under those patent licenses when it is used for those licensed purposes only. 24 25Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality, 26are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional 27applications information and documentation. 28 292. COPYRIGHT LICENSE 30 31Redistribution and use in source and binary forms, with or without modification, are permitted without 32payment of copyright license fees provided that you satisfy the following conditions: 33 34You must retain the complete text of this software license in redistributions of the FDK AAC Codec or 35your modifications thereto in source code form. 36 37You must retain the complete text of this software license in the documentation and/or other materials 38provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form. 39You must make available free of charge copies of the complete source code of the FDK AAC Codec and your 40modifications thereto to recipients of copies in binary form. 41 42The name of Fraunhofer may not be used to endorse or promote products derived from this library without 43prior written permission. 44 45You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec 46software or your modifications thereto. 47 48Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software 49and the date of any change. For modified versions of the FDK AAC Codec, the term 50"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term 51"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android." 52 533. NO PATENT LICENSE 54 55NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer, 56ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with 57respect to this software. 58 59You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized 60by appropriate patent licenses. 61 624. DISCLAIMER 63 64This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors 65"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties 66of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 67CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages, 68including but not limited to procurement of substitute goods or services; loss of use, data, or profits, 69or business interruption, however caused and on any theory of liability, whether in contract, strict 70liability, or tort (including negligence), arising in any way out of the use of this software, even if 71advised of the possibility of such damage. 72 735. CONTACT INFORMATION 74 75Fraunhofer Institute for Integrated Circuits IIS 76Attention: Audio and Multimedia Departments - FDK AAC LL 77Am Wolfsmantel 33 7891058 Erlangen, Germany 79 80www.iis.fraunhofer.de/amm 81amm-info@iis.fraunhofer.de 82----------------------------------------------------------------------------------------------------------- */ 83 84/*************************** Fraunhofer IIS FDK Tools ********************** 85 86 Author(s): M. Lohwasser, M. Gayer 87 Description: Flexible fixpoint library configuration 88 89******************************************************************************/ 90 91#ifndef _COMMON_FIX_H 92#define _COMMON_FIX_H 93 94#include "FDK_archdef.h" 95#include "machine_type.h" 96 97/* ***** Start of former fix.h ****** */ 98 99/* Configure fractional or integer arithmetic */ 100 #define FIX_FRACT 0 /* Define this to "1" to use fractional arithmetic simulation in class fract instead of integer arithmetic */ 101 /* 1 for debug with extra runtime overflow checking. */ 102 103/* Define bit sizes of integer fixpoint fractional data types */ 104#define FRACT_BITS 16 /* single precision */ 105#define DFRACT_BITS 32 /* double precision */ 106#define ACCU_BITS 40 /* double precision plus overflow */ 107 108/* Fixpoint equivalent type fot PCM audio time domain data. */ 109#if defined(SAMPLE_BITS) 110#if (SAMPLE_BITS == DFRACT_BITS) 111 #define FIXP_PCM FIXP_DBL 112 #define FX_PCM2FX_DBL(x) ((FIXP_DBL)(x)) 113 #define FX_DBL2FX_PCM(x) ((INT_PCM)(x)) 114#elif (SAMPLE_BITS == FRACT_BITS) 115 #define FIXP_PCM FIXP_SGL 116 #define FX_PCM2FX_DBL(x) FX_SGL2FX_DBL((FIXP_SGL)(x)) 117 #define FX_DBL2FX_PCM(x) FX_DBL2FX_SGL(x) 118#else 119 #error SAMPLE_BITS different from FRACT_BITS or DFRACT_BITS not implemented! 120#endif 121#endif 122 123/* ****** End of former fix.h ****** */ 124 125#define SGL_MASK ((1UL<<FRACT_BITS)-1) /* 16bit: (2^16)-1 = 0xFFFF */ 126 127#define MAX_SHIFT_SGL (FRACT_BITS-1) /* maximum possible shift for FIXP_SGL values */ 128#define MAX_SHIFT_DBL (DFRACT_BITS-1) /* maximum possible shift for FIXP_DBL values */ 129 130/* Scale factor from/to float/fixpoint values. DO NOT USE THESE VALUES AS SATURATION LIMITS !! */ 131#define FRACT_FIX_SCALE ((INT64(1)<<(FRACT_BITS-1))) 132#define DFRACT_FIX_SCALE ((INT64(1)<<(DFRACT_BITS-1))) 133 134/* Max and Min values for saturation purposes. DO NOT USE THESE VALUES AS SCALE VALUES !! */ 135#define MAXVAL_SGL ((signed)0x00007FFF) /* this has to be synchronized to FRACT_BITS */ 136#define MINVAL_SGL ((signed)0xFFFF8000) /* this has to be synchronized to FRACT_BITS */ 137#define MAXVAL_DBL ((signed)0x7FFFFFFF) /* this has to be synchronized to DFRACT_BITS */ 138#define MINVAL_DBL ((signed)0x80000000) /* this has to be synchronized to DFRACT_BITS */ 139 140 141#define FX_DBL2FXCONST_SGL(val) ( ( ((((val) >> (DFRACT_BITS-FRACT_BITS-1)) + 1) > (((LONG)1<<FRACT_BITS)-1)) && ((LONG)(val) > 0) ) ? \ 142 (FIXP_SGL)(SHORT)(((LONG)1<<(FRACT_BITS-1))-1):(FIXP_SGL)(SHORT)((((val) >> (DFRACT_BITS-FRACT_BITS-1)) + 1) >> 1) ) 143 144 145 146#define shouldBeUnion union /* unions are possible */ 147 148 typedef SHORT FIXP_SGL; 149 typedef LONG FIXP_DBL; 150 151/* macros for compile-time conversion of constant float values to fixedpoint */ 152#define FL2FXCONST_SPC FL2FXCONST_DBL 153 154#define MINVAL_DBL_CONST MINVAL_DBL 155#define MINVAL_SGL_CONST MINVAL_SGL 156 157#define FL2FXCONST_SGL(val) \ 158(FIXP_SGL)( ( (val) >= 0) ? \ 159((( (double)(val) * (FRACT_FIX_SCALE) + 0.5 ) >= (double)(MAXVAL_SGL) ) ? (SHORT)(MAXVAL_SGL) : (SHORT)( (double)(val) * (double)(FRACT_FIX_SCALE) + 0.5)) : \ 160((( (double)(val) * (FRACT_FIX_SCALE) - 0.5) <= (double)(MINVAL_SGL_CONST) ) ? (SHORT)(MINVAL_SGL_CONST) : (SHORT)( (double)(val) * (double)(FRACT_FIX_SCALE) - 0.5)) ) 161 162#define FL2FXCONST_DBL(val) \ 163(FIXP_DBL)( ( (val) >= 0) ? \ 164((( (double)(val) * (DFRACT_FIX_SCALE) + 0.5 ) >= (double)(MAXVAL_DBL) ) ? (LONG)(MAXVAL_DBL) : (LONG)( (double)(val) * (double)(DFRACT_FIX_SCALE) + 0.5)) : \ 165((( (double)(val) * (DFRACT_FIX_SCALE) - 0.5) <= (double)(MINVAL_DBL_CONST) ) ? (LONG)(MINVAL_DBL_CONST) : (LONG)( (double)(val) * (double)(DFRACT_FIX_SCALE) - 0.5)) ) 166 167/* macros for runtime conversion of float values to integer fixedpoint. NO OVERFLOW CHECK!!! */ 168#define FL2FX_SPC FL2FX_DBL 169#define FL2FX_SGL(val) ( (val)>0.0f ? (SHORT)( (val)*(float)(FRACT_FIX_SCALE)+0.5f ) : (SHORT)( (val)*(float)(FRACT_FIX_SCALE)-0.5f ) ) 170#define FL2FX_DBL(val) ( (val)>0.0f ? (LONG)( (val)*(float)(DFRACT_FIX_SCALE)+0.5f ) : (LONG)( (val)*(float)(DFRACT_FIX_SCALE)-0.5f ) ) 171 172/* macros for runtime conversion of fixedpoint values to other fixedpoint. NO ROUNDING!!! */ 173#define FX_ACC2FX_SGL(val) ((FIXP_SGL)((val)>>(ACCU_BITS-FRACT_BITS))) 174#define FX_ACC2FX_DBL(val) ((FIXP_DBL)((val)>>(ACCU_BITS-DFRACT_BITS))) 175#define FX_SGL2FX_ACC(val) ((FIXP_ACC)((LONG)(val)<<(ACCU_BITS-FRACT_BITS))) 176#define FX_SGL2FX_DBL(val) ((FIXP_DBL)((LONG)(val)<<(DFRACT_BITS-FRACT_BITS))) 177#define FX_DBL2FX_SGL(val) ((FIXP_SGL)((val)>>(DFRACT_BITS-FRACT_BITS))) 178 179/* ############################################################# */ 180 181/* macros for runtime conversion of integer fixedpoint values to float. */ 182/* This is just for temporary use and should not be required in a final version! */ 183 184/* #define FX_DBL2FL(val) ((float)(pow(2.,-31.)*(float)val)) */ /* version #1 */ 185#define FX_DBL2FL(val) ((float)((double)(val)/(double)DFRACT_FIX_SCALE)) /* version #2 - identical to class dfract cast from dfract to float */ 186 187/* ############################################################# */ 188#include "fixmul.h" 189 190FDK_INLINE LONG fMult(SHORT a, SHORT b) { return fixmul_SS(a, b); } 191FDK_INLINE LONG fMult(SHORT a, LONG b) { return fixmul_SD(a, b); } 192FDK_INLINE LONG fMult(LONG a, SHORT b) { return fixmul_DS(a, b); } 193FDK_INLINE LONG fMult(LONG a, LONG b) { return fixmul_DD(a, b); } 194FDK_INLINE LONG fPow2(LONG a) { return fixpow2_D(a); } 195FDK_INLINE LONG fPow2(SHORT a) { return fixpow2_S(a); } 196 197FDK_INLINE INT fMultI(LONG a, SHORT b) { return ( (INT)(((1<<(FRACT_BITS-2)) + 198 fixmuldiv2_DD(a,((INT)b<<FRACT_BITS)))>>(FRACT_BITS-1)) ); } 199 200FDK_INLINE INT fMultIfloor(LONG a, INT b) { return ( (INT)((1 + 201 fixmuldiv2_DD(a,(b<<FRACT_BITS))) >> (FRACT_BITS-1)) ); } 202 203FDK_INLINE INT fMultIceil(LONG a, INT b) { return ( (INT)(((INT)0x7fff + 204 fixmuldiv2_DD(a,(b<<FRACT_BITS))) >> (FRACT_BITS-1)) ); } 205 206FDK_INLINE LONG fMultDiv2(SHORT a, SHORT b) { return fixmuldiv2_SS(a, b); } 207FDK_INLINE LONG fMultDiv2(SHORT a, LONG b) { return fixmuldiv2_SD(a, b); } 208FDK_INLINE LONG fMultDiv2(LONG a, SHORT b) { return fixmuldiv2_DS(a, b); } 209FDK_INLINE LONG fMultDiv2(LONG a, LONG b) { return fixmuldiv2_DD(a, b); } 210FDK_INLINE LONG fPow2Div2(LONG a) { return fixpow2div2_D(a); } 211FDK_INLINE LONG fPow2Div2(SHORT a) { return fixpow2div2_S(a); } 212 213FDK_INLINE LONG fMultDiv2BitExact(LONG a, LONG b) { return fixmuldiv2BitExact_DD(a, b); } 214FDK_INLINE LONG fMultDiv2BitExact(SHORT a, LONG b) { return fixmuldiv2BitExact_SD(a, b); } 215FDK_INLINE LONG fMultDiv2BitExact(LONG a, SHORT b) { return fixmuldiv2BitExact_DS(a, b); } 216FDK_INLINE LONG fMultBitExact(LONG a, LONG b) { return fixmulBitExact_DD(a, b); } 217FDK_INLINE LONG fMultBitExact(SHORT a, LONG b) { return fixmulBitExact_SD(a, b); } 218FDK_INLINE LONG fMultBitExact(LONG a, SHORT b) { return fixmulBitExact_DS(a, b); } 219 220/* ******************************************************************************** */ 221#include "abs.h" 222 223FDK_INLINE FIXP_DBL fAbs(FIXP_DBL x) 224 { return fixabs_D(x); } 225FDK_INLINE FIXP_SGL fAbs(FIXP_SGL x) 226 { return fixabs_S(x); } 227 228 229/* workaround for TI C6x compiler but not for TI ARM9E compiler */ 230#if (!defined(__TI_COMPILER_VERSION__) || defined(__TI_TMS470_V5__)) && !defined(__x86_64__) 231FDK_INLINE INT fAbs(INT x) 232 { return fixabs_I(x); } 233#endif 234 235/* ******************************************************************************** */ 236 237#include "clz.h" 238 239FDK_INLINE INT fNormz(FIXP_DBL x) 240 { return fixnormz_D(x); } 241FDK_INLINE INT fNormz(FIXP_SGL x) 242 { return fixnormz_S(x); } 243FDK_INLINE INT fNorm(FIXP_DBL x) 244 { return fixnorm_D(x); } 245FDK_INLINE INT fNorm(FIXP_SGL x) 246 { return fixnorm_S(x); } 247 248 249/* ******************************************************************************** */ 250/* ******************************************************************************** */ 251/* ******************************************************************************** */ 252 253#include "clz.h" 254#define fixp_abs(x) fAbs(x) 255#define fixMin(a,b) fMin(a,b) 256#define fixMax(a,b) fMax(a,b) 257#define CntLeadingZeros(x) fixnormz_D(x) 258#define CountLeadingBits(x) fixnorm_D(x) 259 260#include "fixmadd.h" 261 262/* y = (x+0.5*a*b) */ 263FDK_INLINE FIXP_DBL fMultAddDiv2(FIXP_DBL x, FIXP_DBL a, FIXP_DBL b) 264 { return fixmadddiv2_DD(x, a, b); } 265FDK_INLINE FIXP_DBL fMultAddDiv2(FIXP_DBL x, FIXP_SGL a, FIXP_DBL b) 266 { return fixmadddiv2_SD(x, a, b); } 267FDK_INLINE FIXP_DBL fMultAddDiv2(FIXP_DBL x, FIXP_DBL a, FIXP_SGL b) 268 { return fixmadddiv2_DS(x, a, b); } 269FDK_INLINE FIXP_DBL fMultAddDiv2(FIXP_DBL x, FIXP_SGL a, FIXP_SGL b) 270 { return fixmadddiv2_SS(x, a, b); } 271 272FDK_INLINE FIXP_DBL fPow2AddDiv2(FIXP_DBL x, FIXP_DBL a) 273 { return fixpadddiv2_D(x, a); } 274FDK_INLINE FIXP_DBL fPow2AddDiv2(FIXP_DBL x, FIXP_SGL a) 275 { return fixpadddiv2_S(x, a); } 276 277 278/* y = 2*(x+0.5*a*b) = (2x+a*b) */ 279FDK_INLINE FIXP_DBL fMultAdd(FIXP_DBL x, FIXP_DBL a, FIXP_DBL b) 280 { return fixmadd_DD(x, a, b); } 281inline FIXP_DBL fMultAdd(FIXP_DBL x, FIXP_SGL a, FIXP_DBL b) 282 { return fixmadd_SD(x, a, b); } 283inline FIXP_DBL fMultAdd(FIXP_DBL x, FIXP_DBL a, FIXP_SGL b) 284 { return fixmadd_DS(x, a, b); } 285inline FIXP_DBL fMultAdd(FIXP_DBL x, FIXP_SGL a, FIXP_SGL b) 286 { return fixmadd_SS(x, a, b); } 287 288inline FIXP_DBL fPow2Add(FIXP_DBL x, FIXP_DBL a) 289 { return fixpadd_D(x, a); } 290inline FIXP_DBL fPow2Add(FIXP_DBL x, FIXP_SGL a) 291 { return fixpadd_S(x, a); } 292 293 294/* y = (x-0.5*a*b) */ 295inline FIXP_DBL fMultSubDiv2(FIXP_DBL x, FIXP_DBL a, FIXP_DBL b) 296 { return fixmsubdiv2_DD(x, a, b); } 297inline FIXP_DBL fMultSubDiv2(FIXP_DBL x, FIXP_SGL a, FIXP_DBL b) 298 { return fixmsubdiv2_SD(x, a, b); } 299inline FIXP_DBL fMultSubDiv2(FIXP_DBL x, FIXP_DBL a, FIXP_SGL b) 300 { return fixmsubdiv2_DS(x, a, b); } 301inline FIXP_DBL fMultSubDiv2(FIXP_DBL x, FIXP_SGL a, FIXP_SGL b) 302 { return fixmsubdiv2_SS(x, a, b); } 303 304/* y = 2*(x-0.5*a*b) = (2*x-a*b) */ 305FDK_INLINE FIXP_DBL fMultSub(FIXP_DBL x, FIXP_DBL a, FIXP_DBL b) 306 { return fixmsub_DD(x, a, b); } 307inline FIXP_DBL fMultSub(FIXP_DBL x, FIXP_SGL a, FIXP_DBL b) 308 { return fixmsub_SD(x, a, b); } 309inline FIXP_DBL fMultSub(FIXP_DBL x, FIXP_DBL a, FIXP_SGL b) 310 { return fixmsub_DS(x, a, b); } 311inline FIXP_DBL fMultSub(FIXP_DBL x, FIXP_SGL a, FIXP_SGL b) 312 { return fixmsub_SS(x, a, b); } 313 314FDK_INLINE FIXP_DBL fMultAddDiv2BitExact(FIXP_DBL x, FIXP_DBL a, FIXP_DBL b) 315 { return fixmadddiv2BitExact_DD(x, a, b); } 316FDK_INLINE FIXP_DBL fMultAddDiv2BitExact(FIXP_DBL x, FIXP_SGL a, FIXP_DBL b) 317 { return fixmadddiv2BitExact_SD(x, a, b); } 318FDK_INLINE FIXP_DBL fMultAddDiv2BitExact(FIXP_DBL x, FIXP_DBL a, FIXP_SGL b) 319 { return fixmadddiv2BitExact_DS(x, a, b); } 320FDK_INLINE FIXP_DBL fMultSubDiv2BitExact(FIXP_DBL x, FIXP_DBL a, FIXP_DBL b) 321 { return fixmsubdiv2BitExact_DD(x, a, b); } 322FDK_INLINE FIXP_DBL fMultSubDiv2BitExact(FIXP_DBL x, FIXP_SGL a, FIXP_DBL b) 323 { return fixmsubdiv2BitExact_SD(x, a, b); } 324FDK_INLINE FIXP_DBL fMultSubDiv2BitExact(FIXP_DBL x, FIXP_DBL a, FIXP_SGL b) 325 { return fixmsubdiv2BitExact_DS(x, a, b); } 326 327#include "fixminmax.h" 328 329FDK_INLINE FIXP_DBL fMin(FIXP_DBL a, FIXP_DBL b) 330 { return fixmin_D(a,b); } 331FDK_INLINE FIXP_DBL fMax(FIXP_DBL a, FIXP_DBL b) 332 { return fixmax_D(a,b); } 333 334FDK_INLINE FIXP_SGL fMin(FIXP_SGL a, FIXP_SGL b) 335 { return fixmin_S(a,b); } 336FDK_INLINE FIXP_SGL fMax(FIXP_SGL a, FIXP_SGL b) 337 { return fixmax_S(a,b); } 338 339 340/* workaround for TI C6x compiler but not for TI ARM9E */ 341#if ((!defined(__TI_COMPILER_VERSION__) || defined(__TI_TMS470_V5__)) && !defined(__x86_64__)) || (FIX_FRACT == 1) 342FDK_INLINE INT fMax(INT a, INT b) 343 { return fixmax_I(a,b); } 344FDK_INLINE INT fMin(INT a, INT b) 345 { return fixmin_I(a,b); } 346#endif 347 348inline UINT fMax(UINT a, UINT b) 349 { return fixmax_UI(a,b); } 350inline UINT fMin(UINT a, UINT b) 351 { return fixmin_UI(a,b); } 352 353/* Complex data types */ 354typedef shouldBeUnion { 355 /* vector representation for arithmetic */ 356 struct { 357 FIXP_SGL re; 358 FIXP_SGL im; 359 } v; 360 /* word representation for memory move */ 361 LONG w; 362} FIXP_SPK; 363 364typedef shouldBeUnion { 365 /* vector representation for arithmetic */ 366 struct { 367 FIXP_DBL re; 368 FIXP_DBL im; 369 } v; 370 /* word representation for memory move */ 371 INT64 w; 372} FIXP_DPK; 373 374#include "fixmul.h" 375#include "fixmadd.h" 376#include "cplx_mul.h" 377#include "scale.h" 378#include "fixpoint_math.h" 379 380#endif 381