• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -----------------------------------------------------------------------------
2 Software License for The Fraunhofer FDK AAC Codec Library for Android
3 
4 © Copyright  1995 - 2019 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 /******************* Library for basic calculation routines ********************
96 
97    Author(s):
98 
99    Description: Scaling operations
100 
101 *******************************************************************************/
102 
103 #ifndef SCALE_H
104 #define SCALE_H
105 
106 #include "common_fix.h"
107 #include "genericStds.h"
108 #include "fixminmax.h"
109 
110 #define SCALE_INLINE
111 
112 #if defined(__arm__)
113 #include "arm/scale_arm.h"
114 
115 #elif defined(__mips__)
116 #include "mips/scale_mips.h"
117 
118 #endif
119 
120 void scaleValues(FIXP_SGL *vector, INT len, INT scalefactor);
121 void scaleValues(FIXP_DBL *vector, INT len, INT scalefactor);
122 void scaleValues(FIXP_DBL *dst, const FIXP_DBL *src, INT len, INT scalefactor);
123 #if (SAMPLE_BITS == 16)
124 void scaleValues(FIXP_PCM *dst, const FIXP_DBL *src, INT len, INT scalefactor);
125 #endif
126 void scaleValues(FIXP_SGL *dst, const FIXP_SGL *src, INT len, INT scalefactor);
127 void scaleCplxValues(FIXP_DBL *r_dst, FIXP_DBL *i_dst, const FIXP_DBL *r_src,
128                      const FIXP_DBL *i_src, INT len, INT scalefactor);
129 void scaleValuesWithFactor(FIXP_DBL *vector, FIXP_DBL factor, INT len,
130                            INT scalefactor);
131 void scaleValuesSaturate(FIXP_DBL *vector, INT len, INT scalefactor);
132 void scaleValuesSaturate(FIXP_DBL *dst, const FIXP_DBL *src, INT len,
133                          INT scalefactor);
134 void scaleValuesSaturate(FIXP_SGL *dst, const FIXP_DBL *src, INT len,
135                          INT scalefactor);
136 void scaleValuesSaturate(FIXP_SGL *vector, INT len, INT scalefactor);
137 void scaleValuesSaturate(FIXP_SGL *dst, const FIXP_SGL *src, INT len,
138                          INT scalefactor);
139 INT getScalefactorShort(const SHORT *vector, INT len);
140 INT getScalefactorPCM(const INT_PCM *vector, INT len, INT stride);
141 INT getScalefactor(const FIXP_DBL *vector, INT len);
142 INT getScalefactor(const FIXP_SGL *vector, INT len);
143 
144 #ifndef FUNCTION_scaleValue
145 /*!
146  *
147  *  \brief Multiply input by \f$ 2^{scalefactor} \f$
148  *
149  *  \return Scaled input
150  *
151  */
152 #define FUNCTION_scaleValue
scaleValue(const FIXP_DBL value,INT scalefactor)153 inline FIXP_DBL scaleValue(const FIXP_DBL value, /*!< Value */
154                            INT scalefactor       /*!< Scalefactor */
155 ) {
156   if (scalefactor > 0)
157     return (value << scalefactor);
158   else
159     return (value >> (-scalefactor));
160 }
scaleValue(const FIXP_SGL value,INT scalefactor)161 inline FIXP_SGL scaleValue(const FIXP_SGL value, /*!< Value */
162                            INT scalefactor       /*!< Scalefactor */
163 ) {
164   if (scalefactor > 0)
165     return (value << scalefactor);
166   else
167     return (value >> (-scalefactor));
168 }
169 #endif
170 
171 #ifndef FUNCTION_scaleValueSaturate
172 /*!
173  *
174  *  \brief Multiply input by \f$ 2^{scalefactor} \f$
175  *  \param value The value to be scaled.
176  *  \param the shift amount
177  *  \return \f$ value * 2^scalefactor \f$
178  *
179  */
180 #define FUNCTION_scaleValueSaturate
scaleValueSaturate(const FIXP_DBL value,INT scalefactor)181 inline FIXP_DBL scaleValueSaturate(const FIXP_DBL value,
182                                    INT scalefactor /* in range -31 ... +31 */
183 ) {
184   int headroom = fixnormz_D(
185       (INT)value ^ (INT)((value >> 31))); /* headroom in range 1...32 */
186   if (scalefactor >= 0) {
187     /* shift left: saturate in case of headroom less/equal scalefactor */
188     if (headroom <= scalefactor) {
189       if (value > (FIXP_DBL)0)
190         return (FIXP_DBL)MAXVAL_DBL; /* 0x7FFF.FFFF */
191       else
192         return (FIXP_DBL)MINVAL_DBL + (FIXP_DBL)1; /* 0x8000.0001 */
193     } else {
194       return fMax((value << scalefactor), (FIXP_DBL)MINVAL_DBL + (FIXP_DBL)1);
195     }
196   } else {
197     scalefactor = -scalefactor;
198     /* shift right: clear in case of 32-headroom greater/equal -scalefactor */
199     if ((DFRACT_BITS - headroom) <= scalefactor) {
200       return (FIXP_DBL)0;
201     } else {
202       return fMax((value >> scalefactor), (FIXP_DBL)MINVAL_DBL + (FIXP_DBL)1);
203     }
204   }
205 }
206 #endif
207 
208 #ifndef FUNCTION_scaleValueInPlace
209 /*!
210  *
211  *  \brief Multiply input by \f$ 2^{scalefactor} \f$ in place
212  *
213  *  \return void
214  *
215  */
216 #define FUNCTION_scaleValueInPlace
scaleValueInPlace(FIXP_DBL * value,INT scalefactor)217 inline void scaleValueInPlace(FIXP_DBL *value, /*!< Value */
218                               INT scalefactor  /*!< Scalefactor */
219 ) {
220   INT newscale;
221   /* Note: The assignment inside the if conditional allows combining a load with
222    * the compare to zero (on ARM and maybe others) */
223   if ((newscale = (scalefactor)) >= 0) {
224     *(value) <<= newscale;
225   } else {
226     *(value) >>= -newscale;
227   }
228 }
229 #endif
230 
231   /*!
232    *
233    *  \brief  Scale input value by 2^{scale} and saturate output to 2^{dBits-1}
234    *  \return scaled and saturated value
235    *
236    *  This macro scales src value right or left and applies saturation to
237    * (2^dBits)-1 maxima output.
238    */
239 
240 #ifndef SATURATE_RIGHT_SHIFT
241 #define SATURATE_RIGHT_SHIFT(src, scale, dBits)                            \
242   ((((LONG)(src) >> (scale)) > (LONG)(((1U) << ((dBits)-1)) - 1))          \
243        ? (LONG)(((1U) << ((dBits)-1)) - 1)                                 \
244        : (((LONG)(src) >> (scale)) < ~((LONG)(((1U) << ((dBits)-1)) - 1))) \
245              ? ~((LONG)(((1U) << ((dBits)-1)) - 1))                        \
246              : ((LONG)(src) >> (scale)))
247 #endif
248 
249 #ifndef SATURATE_LEFT_SHIFT
250 #define SATURATE_LEFT_SHIFT(src, scale, dBits)                           \
251   (((LONG)(src) > ((LONG)(((1U) << ((dBits)-1)) - 1) >> (scale)))        \
252        ? (LONG)(((1U) << ((dBits)-1)) - 1)                               \
253        : ((LONG)(src) < ~((LONG)(((1U) << ((dBits)-1)) - 1) >> (scale))) \
254              ? ~((LONG)(((1U) << ((dBits)-1)) - 1))                      \
255              : ((LONG)(src) << (scale)))
256 #endif
257 
258 #ifndef SATURATE_SHIFT
259 #define SATURATE_SHIFT(src, scale, dBits)                        \
260   (((scale) < 0) ? SATURATE_LEFT_SHIFT((src), -(scale), (dBits)) \
261                  : SATURATE_RIGHT_SHIFT((src), (scale), (dBits)))
262 #endif
263 
264 /*
265  * Alternative shift and saturate left, saturates to -0.99999 instead of -1.0000
266  * to avoid problems when inverting the sign of the result.
267  */
268 #ifndef SATURATE_LEFT_SHIFT_ALT
269 #define SATURATE_LEFT_SHIFT_ALT(src, scale, dBits)                        \
270   (((LONG)(src) > ((LONG)(((1U) << ((dBits)-1)) - 1) >> (scale)))         \
271        ? (LONG)(((1U) << ((dBits)-1)) - 1)                                \
272        : ((LONG)(src) <= ~((LONG)(((1U) << ((dBits)-1)) - 1) >> (scale))) \
273              ? ~((LONG)(((1U) << ((dBits)-1)) - 2))                       \
274              : ((LONG)(src) << (scale)))
275 #endif
276 
277 #ifndef SATURATE_RIGHT_SHIFT_ALT
278 #define SATURATE_RIGHT_SHIFT_ALT(src, scale, dBits)                        \
279   ((((LONG)(src) >> (scale)) > (LONG)(((1U) << ((dBits)-1)) - 1))          \
280        ? (LONG)(((1U) << ((dBits)-1)) - 1)                                 \
281        : (((LONG)(src) >> (scale)) < ~((LONG)(((1U) << ((dBits)-1)) - 2))) \
282              ? ~((LONG)(((1U) << ((dBits)-1)) - 2))                        \
283              : ((LONG)(src) >> (scale)))
284 #endif
285 
286 #ifndef SATURATE_INT_PCM_RIGHT_SHIFT
287 #define SATURATE_INT_PCM_RIGHT_SHIFT(src, scale) \
288   SATURATE_RIGHT_SHIFT(src, scale, SAMPLE_BITS)
289 #endif
290 
291 #ifndef SATURATE_INT_PCM_LEFT_SHIFT
292 #define SATURATE_INT_PCM_LEFT_SHIFT(src, scale) \
293   SATURATE_LEFT_SHIFT(src, scale, SAMPLE_BITS)
294 #endif
295 
296 #endif /* #ifndef SCALE_H */
297