9a29aa1381ce6436a17cbb41560ed001848f3930
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 **********************
86 Author(s): Josef Hoepfl, Manuel Jander
87 Description: MDCT routines
89 ******************************************************************************/
94 #include "FDK_tools_rom.h"
96 #include "fixpoint_math.h"
99 void mdct_init( H_MDCT hMdct
,
101 INT overlapBufferSize
)
103 hMdct
->overlap
.freq
= overlap
;
104 //FDKmemclear(overlap, overlapBufferSize*sizeof(FIXP_DBL));
108 hMdct
->ov_size
= overlapBufferSize
;
112 void imdct_gain(FIXP_DBL
*pGain_m
, int *pGain_e
, int tl
)
114 FIXP_DBL gain_m
= *pGain_m
;
115 int gain_e
= *pGain_e
;
118 log2_tl
= DFRACT_BITS
-1-fNormz((FIXP_DBL
)tl
);
120 gain_e
+= -MDCT_OUTPUT_GAIN
- log2_tl
- MDCT_OUT_HEADROOM
+ 1;
122 /* Detect non-radix 2 transform length and add amplitude compensation factor
123 which cannot be included into the exponent above */
124 switch ( (tl
) >> (log2_tl
- 2) ) {
125 case 0x7: /* 10 ms, 1/tl = 1.0/(FDKpow(2.0, -log2_tl) * 0.53333333333333333333) */
126 if (gain_m
== (FIXP_DBL
)0) {
127 gain_m
= FL2FXCONST_DBL(0.53333333333333333333f
);
129 gain_m
= fMult(gain_m
, FL2FXCONST_DBL(0.53333333333333333333f
));
132 case 0x6: /* 3/4 of radix 2, 1/tl = 1.0/(FDKpow(2.0, -log2_tl) * 2.0/3.0) */
133 if (gain_m
== (FIXP_DBL
)0) {
134 gain_m
= FL2FXCONST_DBL(2.0/3.0f
);
136 gain_m
= fMult(gain_m
, FL2FXCONST_DBL(2.0/3.0f
));
140 /* radix 2, nothing to do. */
158 int buffered_samples
= 0;
160 if (nrSamplesRoom
> 0) {
161 buffered_samples
= hMdct
->ov_offset
;
163 FDK_ASSERT(buffered_samples
<= nrSamplesRoom
);
165 if (buffered_samples
> 0) {
166 FDKmemcpy(output
, hMdct
->overlap
.time
, buffered_samples
*sizeof(FIXP_DBL
));
167 hMdct
->ov_offset
= 0;
170 return buffered_samples
;
173 INT
imdct_copy_ov_and_nr(
175 FIXP_DBL
* pTimeData
,
182 nt
= fMin(hMdct
->ov_offset
, nrSamples
);
184 nf
= fMin(hMdct
->prev_nr
, nrSamples
);
186 FDKmemcpy(pTimeData
, hMdct
->overlap
.time
, nt
*sizeof(FIXP_DBL
));
189 pOvl
= hMdct
->overlap
.freq
+ hMdct
->ov_size
- 1;
190 for (i
=0; i
<nf
; i
++) {
191 FIXP_DBL x
= - (*pOvl
--);
192 *pTimeData
= IMDCT_SCALE_DBL(x
);
199 void imdct_adapt_parameters(H_MDCT hMdct
, int *pfl
, int *pnl
, int tl
, const FIXP_WTP
*wls
, int noOutSamples
)
201 int fl
= *pfl
, nl
= *pnl
;
202 int window_diff
, use_current
= 0, use_previous
= 0;
203 if (hMdct
->prev_tl
== 0) {
204 hMdct
->prev_wrs
= wls
;
206 hMdct
->prev_nr
= (noOutSamples
-fl
)>>1;
207 hMdct
->prev_tl
= noOutSamples
;
208 hMdct
->ov_offset
= 0;
212 window_diff
= (hMdct
->prev_fr
- fl
)>>1;
214 /* check if the previous window slope can be adjusted to match the current window slope */
215 if (hMdct
->prev_nr
+ window_diff
> 0) {
218 /* check if the current window slope can be adjusted to match the previous window slope */
219 if (nl
- window_diff
> 0 ) {
223 /* if both is possible choose the larger of both window slope lengths */
224 if (use_current
&& use_previous
) {
225 if (fl
< hMdct
->prev_fr
) {
232 * If the previous transform block is big enough, enlarge previous window overlap,
233 * if not, then shrink current window overlap.
236 hMdct
->prev_nr
+= window_diff
;
238 hMdct
->prev_wrs
= wls
;
252 const SHORT scalefactor
[],
254 const INT noOutSamples
,
264 FIXP_DBL
*pOut0
= output
, *pOut1
;
266 int w
, i
, nrSamples
= 0, specShiftScale
, transform_gain_e
= 0;
268 /* Derive NR and NL */
272 /* Include 2/N IMDCT gain into gain factor and exponent. */
273 imdct_gain(&gain
, &transform_gain_e
, tl
);
275 /* Detect FRprevious / FL mismatches and override parameters accordingly */
276 if (hMdct
->prev_fr
!= fl
) {
277 imdct_adapt_parameters(hMdct
, &fl
, &nl
, tl
, wls
, noOutSamples
);
280 pOvl
= hMdct
->overlap
.freq
+ hMdct
->ov_size
- 1;
282 if ( noOutSamples
> nrSamples
) {
283 /* Purge buffered output. */
284 for (i
=0; i
<hMdct
->ov_offset
; i
++) {
285 *pOut0
= hMdct
->overlap
.time
[i
];
288 nrSamples
= hMdct
->ov_offset
;
289 hMdct
->ov_offset
= 0;
292 for (w
=0; w
<nSpec
; w
++)
294 FIXP_DBL
*pSpec
, *pCurr
;
295 const FIXP_WTP
*pWindow
;
297 specShiftScale
= transform_gain_e
;
299 /* Setup window pointers */
300 pWindow
= hMdct
->prev_wrs
;
302 /* Current spectrum */
303 pSpec
= spectrum
+w
*tl
;
305 /* DCT IV of current spectrum. */
306 dct_IV(pSpec
, tl
, &specShiftScale
);
308 /* Optional scaling of time domain - no yet windowed - of current spectrum */
309 /* and de-scale current spectrum signal (time domain, no yet windowed) */
310 if (gain
!= (FIXP_DBL
)0) {
311 scaleValuesWithFactor(pSpec
, gain
, tl
, scalefactor
[w
] + specShiftScale
);
313 scaleValues(pSpec
, tl
, scalefactor
[w
] + specShiftScale
);
316 if ( noOutSamples
<= nrSamples
) {
317 /* Divert output first half to overlap buffer if we already got enough output samples. */
318 pOut0
= hMdct
->overlap
.time
+ hMdct
->ov_offset
;
319 hMdct
->ov_offset
+= hMdct
->prev_nr
+ fl
/2;
321 /* Account output samples */
322 nrSamples
+= hMdct
->prev_nr
+ fl
/2;
325 /* NR output samples 0 .. NR. -overlap[TL/2..TL/2-NR] */
326 for (i
=0; i
<hMdct
->prev_nr
; i
++) {
327 FIXP_DBL x
= - (*pOvl
--);
328 *pOut0
= IMDCT_SCALE_DBL(x
);
332 if ( noOutSamples
<= nrSamples
) {
333 /* Divert output second half to overlap buffer if we already got enough output samples. */
334 pOut1
= hMdct
->overlap
.time
+ hMdct
->ov_offset
+ fl
/2 - 1;
335 hMdct
->ov_offset
+= fl
/2 + nl
;
337 pOut1
= pOut0
+ (fl
- 1);
338 nrSamples
+= fl
/2 + nl
;
341 /* output samples before window crossing point NR .. TL/2. -overlap[TL/2-NR..TL/2-NR-FL/2] + current[NR..TL/2] */
342 /* output samples after window crossing point TL/2 .. TL/2+FL/2. -overlap[0..FL/2] - current[TL/2..FL/2] */
343 pCurr
= pSpec
+ tl
- fl
/2;
344 for (i
=0; i
<fl
/2; i
++) {
347 cplxMult(&x1
, &x0
, *pCurr
++, - *pOvl
--, pWindow
[i
]);
348 *pOut0
= IMDCT_SCALE_DBL(x0
);
349 *pOut1
= IMDCT_SCALE_DBL(-x1
);
355 /* NL output samples TL/2+FL/2..TL. - current[FL/2..0] */
357 pCurr
= pSpec
+ tl
- fl
/2 - 1;
358 for (i
=0; i
<nl
; i
++) {
359 FIXP_DBL x
= - (*pCurr
--);
360 *pOut1
= IMDCT_SCALE_DBL(x
);
364 /* Set overlap source pointer for next window pOvl = pSpec + tl/2 - 1; */
365 pOvl
= pSpec
+ tl
/2 - 1;
367 /* Previous window values. */
371 hMdct
->prev_wrs
= wrs
;
376 pOvl
= hMdct
->overlap
.freq
+ hMdct
->ov_size
- tl
/2;
377 FDK_ASSERT(pOvl
>= hMdct
->overlap
.time
+ hMdct
->ov_offset
);
378 FDK_ASSERT(tl
/2 <= hMdct
->ov_size
);
379 for (i
=0; i
<tl
/2; i
++) {
380 pOvl
[i
] = spectrum
[i
+(nSpec
-1)*tl
];