• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -----------------------------------------------------------------------------
2 Software License for The Fraunhofer FDK AAC Codec Library for Android
3 
4 © Copyright  1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
5 Forschung e.V. All rights reserved.
6 
7  1.    INTRODUCTION
8 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
9 that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
10 scheme for digital audio. This FDK AAC Codec software is intended to be used on
11 a wide variety of Android devices.
12 
13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
14 general perceptual audio codecs. AAC-ELD is considered the best-performing
15 full-bandwidth communications codec by independent studies and is widely
16 deployed. AAC has been standardized by ISO and IEC as part of the MPEG
17 specifications.
18 
19 Patent licenses for necessary patent claims for the FDK AAC Codec (including
20 those of Fraunhofer) may be obtained through Via Licensing
21 (www.vialicensing.com) or through the respective patent owners individually for
22 the purpose of encoding or decoding bit streams in products that are compliant
23 with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
24 Android devices already license these patent claims through Via Licensing or
25 directly from the patent owners, and therefore FDK AAC Codec software may
26 already be covered under those patent licenses when it is used for those
27 licensed purposes only.
28 
29 Commercially-licensed AAC software libraries, including floating-point versions
30 with enhanced sound quality, are also available from Fraunhofer. Users are
31 encouraged to check the Fraunhofer website for additional applications
32 information and documentation.
33 
34 2.    COPYRIGHT LICENSE
35 
36 Redistribution and use in source and binary forms, with or without modification,
37 are permitted without payment of copyright license fees provided that you
38 satisfy the following conditions:
39 
40 You must retain the complete text of this software license in redistributions of
41 the FDK AAC Codec or your modifications thereto in source code form.
42 
43 You must retain the complete text of this software license in the documentation
44 and/or other materials provided with redistributions of the FDK AAC Codec or
45 your modifications thereto in binary form. You must make available free of
46 charge copies of the complete source code of the FDK AAC Codec and your
47 modifications thereto to recipients of copies in binary form.
48 
49 The name of Fraunhofer may not be used to endorse or promote products derived
50 from this library without prior written permission.
51 
52 You may not charge copyright license fees for anyone to use, copy or distribute
53 the FDK AAC Codec software or your modifications thereto.
54 
55 Your modified versions of the FDK AAC Codec must carry prominent notices stating
56 that you changed the software and the date of any change. For modified versions
57 of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
58 must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
59 AAC Codec Library for Android."
60 
61 3.    NO PATENT LICENSE
62 
63 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
64 limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
65 Fraunhofer provides no warranty of patent non-infringement with respect to this
66 software.
67 
68 You may use this FDK AAC Codec software or modifications thereto only for
69 purposes that are authorized by appropriate patent licenses.
70 
71 4.    DISCLAIMER
72 
73 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
74 holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
75 including but not limited to the implied warranties of merchantability and
76 fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
77 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
78 or consequential damages, including but not limited to procurement of substitute
79 goods or services; loss of use, data, or profits, or business interruption,
80 however caused and on any theory of liability, whether in contract, strict
81 liability, or tort (including negligence), arising in any way out of the use of
82 this software, even if advised of the possibility of such damage.
83 
84 5.    CONTACT INFORMATION
85 
86 Fraunhofer Institute for Integrated Circuits IIS
87 Attention: Audio and Multimedia Departments - FDK AAC LL
88 Am Wolfsmantel 33
89 91058 Erlangen, Germany
90 
91 www.iis.fraunhofer.de/amm
92 amm-info@iis.fraunhofer.de
93 ----------------------------------------------------------------------------- */
94 
95 /**************************** SBR decoder library ******************************
96 
97    Author(s):
98 
99    Description:
100 
101 *******************************************************************************/
102 
103 /*!
104   \file
105   \brief  FDK Fixed Point Arithmetic Library Interface
106 */
107 
108 #ifndef TRANSCENDENT_H
109 #define TRANSCENDENT_H
110 
111 #include "sbrdecoder.h"
112 #include "sbr_rom.h"
113 
114 /************************************************************************/
115 /*!
116   \brief   Get number of octaves between frequencies a and b
117 
118   The Result is scaled with 1/8.
119   The valid range for a and b is 1 to LOG_DUALIS_TABLE_SIZE.
120 
121   \return   ld(a/b) / 8
122 */
123 /************************************************************************/
FDK_getNumOctavesDiv8(INT a,INT b)124 static inline FIXP_SGL FDK_getNumOctavesDiv8(INT a, /*!< lower band */
125                                              INT b) /*!< upper band */
126 {
127   return ((SHORT)((LONG)(CalcLdInt(b) - CalcLdInt(a)) >> (FRACT_BITS - 3)));
128 }
129 
130 /************************************************************************/
131 /*!
132   \brief   Add two values given by mantissa and exponent.
133 
134   Mantissas are in fract format with values between 0 and 1. <br>
135   The base for exponents is 2.  Example:  \f$  a = a\_m * 2^{a\_e}  \f$<br>
136 */
137 /************************************************************************/
FDK_add_MantExp(FIXP_SGL a_m,SCHAR a_e,FIXP_SGL b_m,SCHAR b_e,FIXP_SGL * ptrSum_m,SCHAR * ptrSum_e)138 inline void FDK_add_MantExp(FIXP_SGL a_m, /*!< Mantissa of 1st operand a */
139                             SCHAR a_e,    /*!< Exponent of 1st operand a */
140                             FIXP_SGL b_m, /*!< Mantissa of 2nd operand b */
141                             SCHAR b_e,    /*!< Exponent of 2nd operand b */
142                             FIXP_SGL *ptrSum_m, /*!< Mantissa of result */
143                             SCHAR *ptrSum_e)    /*!< Exponent of result */
144 {
145   FIXP_DBL accu;
146   int shift;
147   int shiftAbs;
148 
149   FIXP_DBL shiftedMantissa;
150   FIXP_DBL otherMantissa;
151 
152   /* Equalize exponents of the summands.
153      For the smaller summand, the exponent is adapted and
154      for compensation, the mantissa is shifted right. */
155 
156   shift = (int)(a_e - b_e);
157 
158   shiftAbs = (shift > 0) ? shift : -shift;
159   shiftAbs = (shiftAbs < DFRACT_BITS - 1) ? shiftAbs : DFRACT_BITS - 1;
160   shiftedMantissa = (shift > 0) ? (FX_SGL2FX_DBL(b_m) >> shiftAbs)
161                                 : (FX_SGL2FX_DBL(a_m) >> shiftAbs);
162   otherMantissa = (shift > 0) ? FX_SGL2FX_DBL(a_m) : FX_SGL2FX_DBL(b_m);
163   *ptrSum_e = (shift > 0) ? a_e : b_e;
164 
165   accu = (shiftedMantissa >> 1) + (otherMantissa >> 1);
166   /* shift by 1 bit to avoid overflow */
167 
168   if ((accu >= (FL2FXCONST_DBL(0.5f) - (FIXP_DBL)1)) ||
169       (accu <= FL2FXCONST_DBL(-0.5f)))
170     *ptrSum_e += 1;
171   else
172     accu = (shiftedMantissa + otherMantissa);
173 
174   *ptrSum_m = FX_DBL2FX_SGL(accu);
175 }
176 
FDK_add_MantExp(FIXP_DBL a,SCHAR a_e,FIXP_DBL b,SCHAR b_e,FIXP_DBL * ptrSum,SCHAR * ptrSum_e)177 inline void FDK_add_MantExp(FIXP_DBL a,       /*!< Mantissa of 1st operand a */
178                             SCHAR a_e,        /*!< Exponent of 1st operand a */
179                             FIXP_DBL b,       /*!< Mantissa of 2nd operand b */
180                             SCHAR b_e,        /*!< Exponent of 2nd operand b */
181                             FIXP_DBL *ptrSum, /*!< Mantissa of result */
182                             SCHAR *ptrSum_e)  /*!< Exponent of result */
183 {
184   FIXP_DBL accu;
185   int shift;
186   int shiftAbs;
187 
188   FIXP_DBL shiftedMantissa;
189   FIXP_DBL otherMantissa;
190 
191   /* Equalize exponents of the summands.
192      For the smaller summand, the exponent is adapted and
193      for compensation, the mantissa is shifted right. */
194 
195   shift = (int)(a_e - b_e);
196 
197   shiftAbs = (shift > 0) ? shift : -shift;
198   shiftAbs = (shiftAbs < DFRACT_BITS - 1) ? shiftAbs : DFRACT_BITS - 1;
199   shiftedMantissa = (shift > 0) ? (b >> shiftAbs) : (a >> shiftAbs);
200   otherMantissa = (shift > 0) ? a : b;
201   *ptrSum_e = (shift > 0) ? a_e : b_e;
202 
203   accu = (shiftedMantissa >> 1) + (otherMantissa >> 1);
204   /* shift by 1 bit to avoid overflow */
205 
206   if ((accu >= (FL2FXCONST_DBL(0.5f) - (FIXP_DBL)1)) ||
207       (accu <= FL2FXCONST_DBL(-0.5f)))
208     *ptrSum_e += 1;
209   else
210     accu = (shiftedMantissa + otherMantissa);
211 
212   *ptrSum = accu;
213 }
214 
215 /************************************************************************/
216 /*!
217   \brief   Divide two values given by mantissa and exponent.
218 
219   Mantissas are in fract format with values between 0 and 1. <br>
220   The base for exponents is 2.  Example:  \f$  a = a\_m * 2^{a\_e}  \f$<br>
221 
222   For performance reasons, the division is based on a table lookup
223   which limits accuracy.
224 */
225 /************************************************************************/
FDK_divide_MantExp(FIXP_SGL a_m,SCHAR a_e,FIXP_SGL b_m,SCHAR b_e,FIXP_SGL * ptrResult_m,SCHAR * ptrResult_e)226 static inline void FDK_divide_MantExp(
227     FIXP_SGL a_m,          /*!< Mantissa of dividend a */
228     SCHAR a_e,             /*!< Exponent of dividend a */
229     FIXP_SGL b_m,          /*!< Mantissa of divisor b */
230     SCHAR b_e,             /*!< Exponent of divisor b */
231     FIXP_SGL *ptrResult_m, /*!< Mantissa of quotient a/b */
232     SCHAR *ptrResult_e)    /*!< Exponent of quotient a/b */
233 
234 {
235   int preShift, postShift, index, shift;
236   FIXP_DBL ratio_m;
237   FIXP_SGL bInv_m = FL2FXCONST_SGL(0.0f);
238 
239   preShift = CntLeadingZeros(FX_SGL2FX_DBL(b_m));
240 
241   /*
242     Shift b into the range from 0..INV_TABLE_SIZE-1,
243 
244     E.g. 10 bits must be skipped for INV_TABLE_BITS 8:
245     - leave 8 bits as index for table
246     - skip sign bit,
247     - skip first bit of mantissa, because this is always the same (>0.5)
248 
249     We are dealing with energies, so we need not care
250     about negative numbers
251   */
252 
253   /*
254     The first interval has half width so the lowest bit of the index is
255     needed for a doubled resolution.
256   */
257   shift = (FRACT_BITS - 2 - INV_TABLE_BITS - preShift);
258 
259   index = (shift < 0) ? (LONG)b_m << (-shift) : (LONG)b_m >> shift;
260 
261   /* The index has INV_TABLE_BITS +1 valid bits here. Clear the other bits. */
262   index &= (1 << (INV_TABLE_BITS + 1)) - 1;
263 
264   /* Remove offset of half an interval */
265   index--;
266 
267   /* Now the lowest bit is shifted out */
268   index = index >> 1;
269 
270   /* Fetch inversed mantissa from table: */
271   bInv_m = (index < 0) ? bInv_m : FDK_sbrDecoder_invTable[index];
272 
273   /* Multiply a with the inverse of b: */
274   ratio_m = (index < 0) ? FX_SGL2FX_DBL(a_m >> 1) : fMultDiv2(bInv_m, a_m);
275 
276   postShift = CntLeadingZeros(ratio_m) - 1;
277 
278   *ptrResult_m = FX_DBL2FX_SGL(ratio_m << postShift);
279   *ptrResult_e = a_e - b_e + 1 + preShift - postShift;
280 }
281 
FDK_divide_MantExp(FIXP_DBL a_m,SCHAR a_e,FIXP_DBL b_m,SCHAR b_e,FIXP_DBL * ptrResult_m,SCHAR * ptrResult_e)282 static inline void FDK_divide_MantExp(
283     FIXP_DBL a_m,          /*!< Mantissa of dividend a */
284     SCHAR a_e,             /*!< Exponent of dividend a */
285     FIXP_DBL b_m,          /*!< Mantissa of divisor b */
286     SCHAR b_e,             /*!< Exponent of divisor b */
287     FIXP_DBL *ptrResult_m, /*!< Mantissa of quotient a/b */
288     SCHAR *ptrResult_e)    /*!< Exponent of quotient a/b */
289 
290 {
291   int preShift, postShift, index, shift;
292   FIXP_DBL ratio_m;
293   FIXP_SGL bInv_m = FL2FXCONST_SGL(0.0f);
294 
295   preShift = CntLeadingZeros(b_m);
296 
297   /*
298     Shift b into the range from 0..INV_TABLE_SIZE-1,
299 
300     E.g. 10 bits must be skipped for INV_TABLE_BITS 8:
301     - leave 8 bits as index for table
302     - skip sign bit,
303     - skip first bit of mantissa, because this is always the same (>0.5)
304 
305     We are dealing with energies, so we need not care
306     about negative numbers
307   */
308 
309   /*
310     The first interval has half width so the lowest bit of the index is
311     needed for a doubled resolution.
312   */
313   shift = (DFRACT_BITS - 2 - INV_TABLE_BITS - preShift);
314 
315   index = (shift < 0) ? (LONG)b_m << (-shift) : (LONG)b_m >> shift;
316 
317   /* The index has INV_TABLE_BITS +1 valid bits here. Clear the other bits. */
318   index &= (1 << (INV_TABLE_BITS + 1)) - 1;
319 
320   /* Remove offset of half an interval */
321   index--;
322 
323   /* Now the lowest bit is shifted out */
324   index = index >> 1;
325 
326   /* Fetch inversed mantissa from table: */
327   bInv_m = (index < 0) ? bInv_m : FDK_sbrDecoder_invTable[index];
328 
329   /* Multiply a with the inverse of b: */
330   ratio_m = (index < 0) ? (a_m >> 1) : fMultDiv2(bInv_m, a_m);
331 
332   postShift = CntLeadingZeros(ratio_m) - 1;
333 
334   *ptrResult_m = ratio_m << postShift;
335   *ptrResult_e = a_e - b_e + 1 + preShift - postShift;
336 }
337 
338 /*!
339   \brief   Calculate the squareroot of a number given by mantissa and exponent
340 
341   Mantissa is in fract format with values between 0 and 1. <br>
342   The base for the exponent is 2.  Example:  \f$  a = a\_m * 2^{a\_e}  \f$<br>
343   The operand is addressed via pointers and will be overwritten with the result.
344 
345   For performance reasons, the square root is based on a table lookup
346   which limits accuracy.
347 */
FDK_sqrt_MantExp(FIXP_DBL * mantissa,SCHAR * exponent,const SCHAR * destScale)348 static inline void FDK_sqrt_MantExp(
349     FIXP_DBL *mantissa, /*!< Pointer to mantissa */
350     SCHAR *exponent, const SCHAR *destScale) {
351   FIXP_DBL input_m = *mantissa;
352   int input_e = (int)*exponent;
353   FIXP_DBL result = FL2FXCONST_DBL(0.0f);
354   int result_e = -FRACT_BITS;
355 
356   /* Call lookup square root, which does internally normalization. */
357   result = sqrtFixp_lookup(input_m, &input_e);
358   result_e = input_e;
359 
360   /* Write result */
361   if (exponent == destScale) {
362     *mantissa = result;
363     *exponent = result_e;
364   } else {
365     int shift = result_e - *destScale;
366     *mantissa = (shift >= 0) ? result << (INT)fixMin(DFRACT_BITS - 1, shift)
367                              : result >> (INT)fixMin(DFRACT_BITS - 1, -shift);
368     *exponent = *destScale;
369   }
370 }
371 
372 #endif
373