2 /* -----------------------------------------------------------------------------------------------------------
3 Software License for The Fraunhofer FDK AAC Codec Library for Android
5 © Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
9 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
10 the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
11 This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
14 audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
15 independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
16 of the MPEG specifications.
18 Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
19 may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
20 individually for the purpose of encoding or decoding bit streams in products that are compliant with
21 the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
22 these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
23 software may already be covered under those patent licenses when it is used for those licensed purposes only.
25 Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
26 are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
27 applications information and documentation.
31 Redistribution and use in source and binary forms, with or without modification, are permitted without
32 payment of copyright license fees provided that you satisfy the following conditions:
34 You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
35 your modifications thereto in source code form.
37 You must retain the complete text of this software license in the documentation and/or other materials
38 provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
39 You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
40 modifications thereto to recipients of copies in binary form.
42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without
43 prior written permission.
45 You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
46 software or your modifications thereto.
48 Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
49 and 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."
55 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
56 ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
57 respect to this software.
59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60 by appropriate patent licenses.
64 This 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
66 of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
67 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
68 including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
69 or business interruption, however caused and on any theory of liability, whether in contract, strict
70 liability, or tort (including negligence), arising in any way out of the use of this software, even if
71 advised of the possibility of such damage.
73 5. CONTACT INFORMATION
75 Fraunhofer Institute for Integrated Circuits IIS
76 Attention: Audio and Multimedia Departments - FDK AAC LL
78 91058 Erlangen, Germany
80 www.iis.fraunhofer.de/amm
81 amm-info@iis.fraunhofer.de
82 ----------------------------------------------------------------------------------------------------------- */
86 \brief FDK Fixed Point Arithmetic Library Interface
89 #ifndef __TRANSCENDENT_H
90 #define __TRANSCENDENT_H
92 #include "sbrdecoder.h"
95 /************************************************************************/
97 \brief Get number of octaves between frequencies a and b
99 The Result is scaled with 1/8.
100 The valid range for a and b is 1 to LOG_DUALIS_TABLE_SIZE.
104 /************************************************************************/
105 static inline FIXP_SGL
FDK_getNumOctavesDiv8(INT a
, /*!< lower band */
106 INT b
) /*!< upper band */
108 return ( (SHORT
)((LONG
)(CalcLdInt(b
) - CalcLdInt(a
))>>(FRACT_BITS
-3)) );
112 /************************************************************************/
114 \brief Add two values given by mantissa and exponent.
116 Mantissas are in fract format with values between 0 and 1. <br>
117 The base for exponents is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$<br>
119 /************************************************************************/
120 inline void FDK_add_MantExp(FIXP_SGL a_m
, /*!< Mantissa of 1st operand a */
121 SCHAR a_e
, /*!< Exponent of 1st operand a */
122 FIXP_SGL b_m
, /*!< Mantissa of 2nd operand b */
123 SCHAR b_e
, /*!< Exponent of 2nd operand b */
124 FIXP_SGL
*ptrSum_m
, /*!< Mantissa of result */
125 SCHAR
*ptrSum_e
) /*!< Exponent of result */
131 FIXP_DBL shiftedMantissa
;
132 FIXP_DBL otherMantissa
;
134 /* Equalize exponents of the summands.
135 For the smaller summand, the exponent is adapted and
136 for compensation, the mantissa is shifted right. */
138 shift
= (int)(a_e
- b_e
);
140 shiftAbs
= (shift
>0)? shift
: -shift
;
141 shiftAbs
= (shiftAbs
< DFRACT_BITS
-1)? shiftAbs
: DFRACT_BITS
-1;
142 shiftedMantissa
= (shift
>0)? (FX_SGL2FX_DBL(b_m
) >> shiftAbs
) : (FX_SGL2FX_DBL(a_m
) >> shiftAbs
);
143 otherMantissa
= (shift
>0)? FX_SGL2FX_DBL(a_m
) : FX_SGL2FX_DBL(b_m
);
144 *ptrSum_e
= (shift
>0)? a_e
: b_e
;
146 accu
= (shiftedMantissa
>> 1) + (otherMantissa
>> 1);
147 /* shift by 1 bit to avoid overflow */
149 if ( (accu
>= (FL2FXCONST_DBL(0.5f
) - (FIXP_DBL
)1)) || (accu
<= FL2FXCONST_DBL(-0.5f
)) )
152 accu
= (shiftedMantissa
+ otherMantissa
);
154 *ptrSum_m
= FX_DBL2FX_SGL(accu
);
158 inline void FDK_add_MantExp(FIXP_DBL a
, /*!< Mantissa of 1st operand a */
159 SCHAR a_e
, /*!< Exponent of 1st operand a */
160 FIXP_DBL b
, /*!< Mantissa of 2nd operand b */
161 SCHAR b_e
, /*!< Exponent of 2nd operand b */
162 FIXP_DBL
*ptrSum
, /*!< Mantissa of result */
163 SCHAR
*ptrSum_e
) /*!< Exponent of result */
169 FIXP_DBL shiftedMantissa
;
170 FIXP_DBL otherMantissa
;
172 /* Equalize exponents of the summands.
173 For the smaller summand, the exponent is adapted and
174 for compensation, the mantissa is shifted right. */
176 shift
= (int)(a_e
- b_e
);
178 shiftAbs
= (shift
>0)? shift
: -shift
;
179 shiftAbs
= (shiftAbs
< DFRACT_BITS
-1)? shiftAbs
: DFRACT_BITS
-1;
180 shiftedMantissa
= (shift
>0)? (b
>> shiftAbs
) : (a
>> shiftAbs
);
181 otherMantissa
= (shift
>0)? a
: b
;
182 *ptrSum_e
= (shift
>0)? a_e
: b_e
;
184 accu
= (shiftedMantissa
>> 1) + (otherMantissa
>> 1);
185 /* shift by 1 bit to avoid overflow */
187 if ( (accu
>= (FL2FXCONST_DBL(0.5f
) - (FIXP_DBL
)1)) || (accu
<= FL2FXCONST_DBL(-0.5f
)) )
190 accu
= (shiftedMantissa
+ otherMantissa
);
196 /************************************************************************/
198 \brief Divide two values given by mantissa and exponent.
200 Mantissas are in fract format with values between 0 and 1. <br>
201 The base for exponents is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$<br>
203 For performance reasons, the division is based on a table lookup
204 which limits accuracy.
206 /************************************************************************/
207 static inline void FDK_divide_MantExp(FIXP_SGL a_m
, /*!< Mantissa of dividend a */
208 SCHAR a_e
, /*!< Exponent of dividend a */
209 FIXP_SGL b_m
, /*!< Mantissa of divisor b */
210 SCHAR b_e
, /*!< Exponent of divisor b */
211 FIXP_SGL
*ptrResult_m
, /*!< Mantissa of quotient a/b */
212 SCHAR
*ptrResult_e
) /*!< Exponent of quotient a/b */
215 int preShift
, postShift
, index
, shift
;
217 FIXP_SGL bInv_m
= FL2FXCONST_SGL(0.0f
);
219 preShift
= CntLeadingZeros(FX_SGL2FX_DBL(b_m
));
222 Shift b into the range from 0..INV_TABLE_SIZE-1,
224 E.g. 10 bits must be skipped for INV_TABLE_BITS 8:
225 - leave 8 bits as index for table
227 - skip first bit of mantissa, because this is always the same (>0.5)
229 We are dealing with energies, so we need not care
230 about negative numbers
234 The first interval has half width so the lowest bit of the index is
235 needed for a doubled resolution.
237 shift
= (FRACT_BITS
- 2 - INV_TABLE_BITS
- preShift
);
239 index
= (shift
<0)? (LONG
)b_m
<< (-shift
) : (LONG
)b_m
>> shift
;
242 /* The index has INV_TABLE_BITS +1 valid bits here. Clear the other bits. */
243 index
&= (1 << (INV_TABLE_BITS
+1)) - 1;
245 /* Remove offset of half an interval */
248 /* Now the lowest bit is shifted out */
251 /* Fetch inversed mantissa from table: */
252 bInv_m
= (index
<0)? bInv_m
: FDK_sbrDecoder_invTable
[index
];
254 /* Multiply a with the inverse of b: */
255 ratio_m
= (index
<0)? FX_SGL2FX_DBL(a_m
>> 1) : fMultDiv2(bInv_m
,a_m
);
257 postShift
= CntLeadingZeros(ratio_m
)-1;
259 *ptrResult_m
= FX_DBL2FX_SGL(ratio_m
<< postShift
);
260 *ptrResult_e
= a_e
- b_e
+ 1 + preShift
- postShift
;
263 static inline void FDK_divide_MantExp(FIXP_DBL a_m
, /*!< Mantissa of dividend a */
264 SCHAR a_e
, /*!< Exponent of dividend a */
265 FIXP_DBL b_m
, /*!< Mantissa of divisor b */
266 SCHAR b_e
, /*!< Exponent of divisor b */
267 FIXP_DBL
*ptrResult_m
, /*!< Mantissa of quotient a/b */
268 SCHAR
*ptrResult_e
) /*!< Exponent of quotient a/b */
271 int preShift
, postShift
, index
, shift
;
273 FIXP_SGL bInv_m
= FL2FXCONST_SGL(0.0f
);
275 preShift
= CntLeadingZeros(b_m
);
278 Shift b into the range from 0..INV_TABLE_SIZE-1,
280 E.g. 10 bits must be skipped for INV_TABLE_BITS 8:
281 - leave 8 bits as index for table
283 - skip first bit of mantissa, because this is always the same (>0.5)
285 We are dealing with energies, so we need not care
286 about negative numbers
290 The first interval has half width so the lowest bit of the index is
291 needed for a doubled resolution.
293 shift
= (DFRACT_BITS
- 2 - INV_TABLE_BITS
- preShift
);
295 index
= (shift
<0)? (LONG
)b_m
<< (-shift
) : (LONG
)b_m
>> shift
;
298 /* The index has INV_TABLE_BITS +1 valid bits here. Clear the other bits. */
299 index
&= (1 << (INV_TABLE_BITS
+1)) - 1;
301 /* Remove offset of half an interval */
304 /* Now the lowest bit is shifted out */
307 /* Fetch inversed mantissa from table: */
308 bInv_m
= (index
<0)? bInv_m
: FDK_sbrDecoder_invTable
[index
];
310 /* Multiply a with the inverse of b: */
311 ratio_m
= (index
<0)? (a_m
>> 1) : fMultDiv2(bInv_m
,a_m
);
313 postShift
= CntLeadingZeros(ratio_m
)-1;
315 *ptrResult_m
= ratio_m
<< postShift
;
316 *ptrResult_e
= a_e
- b_e
+ 1 + preShift
- postShift
;
320 \brief Calculate the squareroot of a number given by mantissa and exponent
322 Mantissa is in fract format with values between 0 and 1. <br>
323 The base for the exponent is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$<br>
324 The operand is addressed via pointers and will be overwritten with the result.
326 For performance reasons, the square root is based on a table lookup
327 which limits accuracy.
329 static inline void FDK_sqrt_MantExp(FIXP_DBL
*mantissa
, /*!< Pointer to mantissa */
331 const SCHAR
*destScale
)
333 FIXP_DBL input_m
= *mantissa
;
334 int input_e
= (int) *exponent
;
335 FIXP_DBL result
= FL2FXCONST_DBL(0.0f
);
336 int result_e
= -FRACT_BITS
;
338 /* Call lookup square root, which does internally normalization. */
339 result
= sqrtFixp_lookup(input_m
, &input_e
);
343 if (exponent
==destScale
) {
345 *exponent
= result_e
;
347 int shift
= result_e
- *destScale
;
348 *mantissa
= (shift
>=0) ? result
<< (INT
)fixMin(DFRACT_BITS
-1,shift
)
349 : result
>> (INT
)fixMin(DFRACT_BITS
-1,-shift
);
350 *exponent
= *destScale
;