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 ----------------------------------------------------------------------------------------------------------- */
84 /*************************** Fraunhofer IIS FDK Tools **********************
87 Description: Scaling operations
89 ******************************************************************************/
91 #include "common_fix.h"
93 #include "genericStds.h"
95 /**************************************************
97 **************************************************/
99 #define SCALE_INLINE inline
102 #if defined(__mips__) /* cppp replaced: elif */
103 #include "mips/scale.cpp"
105 #elif defined(__arm__)
106 #include "arm/scale_arm.cpp"
110 #ifndef FUNCTION_scaleValues_SGL
113 * \brief Multiply input vector by \f$ 2^{scalefactor} \f$
114 * \param len must be larger than 4
118 #define FUNCTION_scaleValues_SGL
120 void scaleValues(FIXP_SGL
*vector
, /*!< Vector */
121 INT len
, /*!< Length */
122 INT scalefactor
/*!< Scalefactor */
127 /* Return if scalefactor is Zero */
128 if (scalefactor
==0) return;
131 scalefactor
= fixmin_I(scalefactor
,(INT
)(DFRACT_BITS
-1));
132 for (i
= len
&3; i
--; )
134 *(vector
++) <<= scalefactor
;
136 for (i
= len
>>2; i
--; )
138 *(vector
++) <<= scalefactor
;
139 *(vector
++) <<= scalefactor
;
140 *(vector
++) <<= scalefactor
;
141 *(vector
++) <<= scalefactor
;
144 INT negScalefactor
= fixmin_I(-scalefactor
,(INT
)DFRACT_BITS
-1);
145 for (i
= len
&3; i
--; )
147 *(vector
++) >>= negScalefactor
;
149 for (i
= len
>>2; i
--; )
151 *(vector
++) >>= negScalefactor
;
152 *(vector
++) >>= negScalefactor
;
153 *(vector
++) >>= negScalefactor
;
154 *(vector
++) >>= negScalefactor
;
160 #ifndef FUNCTION_scaleValues_DBL
163 * \brief Multiply input vector by \f$ 2^{scalefactor} \f$
164 * \param len must be larger than 4
168 #define FUNCTION_scaleValues_DBL
170 void scaleValues(FIXP_DBL
*vector
, /*!< Vector */
171 INT len
, /*!< Length */
172 INT scalefactor
/*!< Scalefactor */
177 /* Return if scalefactor is Zero */
178 if (scalefactor
==0) return;
181 scalefactor
= fixmin_I(scalefactor
,(INT
)DFRACT_BITS
-1);
182 for (i
= len
&3; i
--; )
184 *(vector
++) <<= scalefactor
;
186 for (i
= len
>>2; i
--; )
188 *(vector
++) <<= scalefactor
;
189 *(vector
++) <<= scalefactor
;
190 *(vector
++) <<= scalefactor
;
191 *(vector
++) <<= scalefactor
;
194 INT negScalefactor
= fixmin_I(-scalefactor
,(INT
)DFRACT_BITS
-1);
195 for (i
= len
&3; i
--; )
197 *(vector
++) >>= negScalefactor
;
199 for (i
= len
>>2; i
--; )
201 *(vector
++) >>= negScalefactor
;
202 *(vector
++) >>= negScalefactor
;
203 *(vector
++) >>= negScalefactor
;
204 *(vector
++) >>= negScalefactor
;
210 #ifndef FUNCTION_scaleValues_DBLDBL
213 * \brief Multiply input vector src by \f$ 2^{scalefactor} \f$
214 * and place result into dst
215 * \param dst detination buffer
216 * \param src source buffer
217 * \param len must be larger than 4
218 * \param scalefactor amount of left shifts to be applied
222 #define FUNCTION_scaleValues_DBLDBL
224 void scaleValues(FIXP_DBL
*dst
, /*!< dst Vector */
225 const FIXP_DBL
*src
, /*!< src Vector */
226 INT len
, /*!< Length */
227 INT scalefactor
/*!< Scalefactor */
232 /* Return if scalefactor is Zero */
233 if (scalefactor
==0) {
235 FDKmemmove(dst
, src
, len
*sizeof(FIXP_DBL
));
240 scalefactor
= fixmin_I(scalefactor
,(INT
)DFRACT_BITS
-1);
241 for (i
= len
&3; i
--; )
243 *(dst
++) = *(src
++) << scalefactor
;
245 for (i
= len
>>2; i
--; )
247 *(dst
++) = *(src
++) << scalefactor
;
248 *(dst
++) = *(src
++) << scalefactor
;
249 *(dst
++) = *(src
++) << scalefactor
;
250 *(dst
++) = *(src
++) << scalefactor
;
253 INT negScalefactor
= fixmin_I(-scalefactor
,(INT
)DFRACT_BITS
-1);
254 for (i
= len
&3; i
--; )
256 *(dst
++) = *(src
++) >> negScalefactor
;
258 for (i
= len
>>2; i
--; )
260 *(dst
++) = *(src
++) >> negScalefactor
;
261 *(dst
++) = *(src
++) >> negScalefactor
;
262 *(dst
++) = *(src
++) >> negScalefactor
;
263 *(dst
++) = *(src
++) >> negScalefactor
;
270 #ifndef FUNCTION_scaleValuesWithFactor_DBL
273 * \brief Multiply input vector by \f$ 2^{scalefactor} \f$
274 * \param len must be larger than 4
278 #define FUNCTION_scaleValuesWithFactor_DBL
280 void scaleValuesWithFactor(
289 /* Compensate fMultDiv2 */
293 scalefactor
= fixmin_I(scalefactor
,(INT
)DFRACT_BITS
-1);
294 for (i
= len
&3; i
--; )
296 *vector
= fMultDiv2(*vector
, factor
) << scalefactor
;
299 for (i
= len
>>2; i
--; )
301 *vector
= fMultDiv2(*vector
, factor
) << scalefactor
; vector
++;
302 *vector
= fMultDiv2(*vector
, factor
) << scalefactor
; vector
++;
303 *vector
= fMultDiv2(*vector
, factor
) << scalefactor
; vector
++;
304 *vector
= fMultDiv2(*vector
, factor
) << scalefactor
; vector
++;
307 INT negScalefactor
= fixmin_I(-scalefactor
,(INT
)DFRACT_BITS
-1);
308 for (i
= len
&3; i
--; )
310 *vector
= fMultDiv2(*vector
, factor
) >> negScalefactor
;
313 for (i
= len
>>2; i
--; )
315 *vector
= fMultDiv2(*vector
, factor
) >> negScalefactor
; vector
++;
316 *vector
= fMultDiv2(*vector
, factor
) >> negScalefactor
; vector
++;
317 *vector
= fMultDiv2(*vector
, factor
) >> negScalefactor
; vector
++;
318 *vector
= fMultDiv2(*vector
, factor
) >> negScalefactor
; vector
++;
322 #endif /* FUNCTION_scaleValuesWithFactor_DBL */
325 /*******************************************
327 IMPORTANT NOTE for usage of getScalefactor()
329 If the input array contains negative values too, then these functions may sometimes return
330 the actual maximum value minus 1, due to the nature of the applied algorithm.
331 So be careful with possible fractional -1 values that may lead to overflows when being fPow2()'ed.
333 ********************************************/
337 #ifndef FUNCTION_getScalefactorShort
340 * \brief Calculate max possible scale factor for input vector of shorts
342 * \return Maximum scale factor / possible left shift
345 #define FUNCTION_getScalefactorShort
347 INT
getScalefactorShort(const SHORT
*vector
, /*!< Pointer to input vector */
348 INT len
/*!< Length of input vector */
352 SHORT temp
, maxVal
= 0;
355 temp
= (SHORT
)(*vector
++);
356 maxVal
|= (temp
^(temp
>>(SHORT_BITS
-1)));
359 return fixmax_I((INT
)0,(INT
)(fixnormz_D((INT
)maxVal
) - (INT
)1 - (INT
)(DFRACT_BITS
- SHORT_BITS
)));
363 #ifndef FUNCTION_getScalefactorPCM
366 * \brief Calculate max possible scale factor for input vector of shorts
368 * \return Maximum scale factor
371 #define FUNCTION_getScalefactorPCM
373 INT
getScalefactorPCM(const INT_PCM
*vector
, /*!< Pointer to input vector */
374 INT len
, /*!< Length of input vector */
379 INT_PCM temp
, maxVal
= 0;
382 temp
= (INT_PCM
)(*vector
); vector
+=stride
;
383 maxVal
|= (temp
^(temp
>>((sizeof(INT_PCM
)*8)-1)));
385 return fixmax_I((INT
)0,(INT
)(fixnormz_D((INT
)maxVal
) - (INT
)1 - (INT
)(DFRACT_BITS
- SAMPLE_BITS
)));
389 #ifndef FUNCTION_getScalefactorShort
392 * \brief Calculate max possible scale factor for input vector of shorts
393 * \param stride, item increment between vector members.
394 * \return Maximum scale factor
397 #define FUNCTION_getScalefactorShort
399 INT
getScalefactorShort(const SHORT
*vector
, /*!< Pointer to input vector */
400 INT len
, /*!< Length of input vector */
405 SHORT temp
, maxVal
= 0;
408 temp
= (SHORT
)(*vector
); vector
+=stride
;
409 maxVal
|= (temp
^(temp
>>(SHORT_BITS
-1)));
412 return fixmax_I((INT
)0,(INT
)(fixnormz_D((INT
)maxVal
) - (INT
)1 - (INT
)(DFRACT_BITS
- SHORT_BITS
)));
416 #ifndef FUNCTION_getScalefactor_DBL
419 * \brief Calculate max possible scale factor for input vector
421 * \return Maximum scale factor
423 * This function can constitute a significant amount of computational complexity - very much depending on the
424 * bitrate. Since it is a rather small function, effective assembler optimization might be possible.
427 #define FUNCTION_getScalefactor_DBL
429 INT
getScalefactor(const FIXP_DBL
*vector
, /*!< Pointer to input vector */
430 INT len
) /*!< Length of input vector */
433 FIXP_DBL temp
, maxVal
= (FIXP_DBL
)0;
436 temp
= (LONG
)(*vector
++);
437 maxVal
|= (FIXP_DBL
)((LONG
)temp
^(LONG
)(temp
>>(DFRACT_BITS
-1)));
440 return fixmax_I((INT
)0,(INT
)(fixnormz_D(maxVal
) - 1));
444 #ifndef FUNCTION_getScalefactor_SGL
445 #define FUNCTION_getScalefactor_SGL
447 INT
getScalefactor(const FIXP_SGL
*vector
, /*!< Pointer to input vector */
448 INT len
) /*!< Length of input vector */
451 SHORT temp
, maxVal
= (FIXP_SGL
)0;
454 temp
= (SHORT
)(*vector
++);
455 maxVal
|= (temp
^(temp
>>(FRACT_BITS
-1)));
458 return fixmax_I((INT
)0,(INT
)(fixnormz_D(FX_SGL2FX_DBL((FIXP_SGL
)maxVal
)) - 1));