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 /***************************** MPEG-4 AAC Decoder **************************
86 Author(s): Josef Hoepfl
87 Description: long/short-block decoding
89 ******************************************************************************/
94 #include "FDK_bitstream.h"
95 #include "FDK_tools_rom.h"
100 #include "aacdec_hcr.h"
105 #include "arm/block_arm.cpp"
109 \brief Read escape sequence of codeword
111 The function reads the escape sequence from the bitstream,
112 if the absolute value of the quantized coefficient has the
115 \return quantized coefficient
117 LONG
CBlock_GetEscape(HANDLE_FDK_BITSTREAM bs
, /*!< pointer to bitstream */
118 const LONG q
) /*!< quantized coefficient */
124 if (q
!= -16) return q
;
129 if (q
!= +16) return q
;
135 if (FDKreadBits(bs
,1) == 0)
141 if (i
- 16 > CACHE_BITS
) { /* cannot read more than "CACHE_BITS" bits at once in the function FDKreadBits() */
142 return (MAX_QUANTIZED_VALUE
+ 1); /* returning invalid value that will be captured later */
145 off
= FDKreadBits(bs
,i
-16) << 16;
146 off
|= FDKreadBits(bs
,16);
150 off
= FDKreadBits(bs
,i
);
160 AAC_DECODER_ERROR
CBlock_ReadScaleFactorData(
161 CAacDecoderChannelInfo
*pAacDecoderChannelInfo
,
162 HANDLE_FDK_BITSTREAM bs
,
169 int position
= 0; /* accu for intensity delta coding */
170 int factor
= pAacDecoderChannelInfo
->pDynData
->RawDataInfo
.GlobalGain
; /* accu for scale factor delta coding */
171 UCHAR
*pCodeBook
= pAacDecoderChannelInfo
->pDynData
->aCodeBook
;
172 SHORT
*pScaleFactor
= pAacDecoderChannelInfo
->pDynData
->aScaleFactor
;
173 const CodeBookDescription
*hcb
=&AACcodeBookDescriptionTable
[BOOKSCL
];
175 int ScaleFactorBandsTransmitted
= GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo
->icsInfo
);
176 for (group
=0; group
< GetWindowGroups(&pAacDecoderChannelInfo
->icsInfo
); group
++)
178 for (band
=0; band
< ScaleFactorBandsTransmitted
; band
++)
180 switch (pCodeBook
[group
*16+band
]) {
182 case ZERO_HCB
: /* zero book */
183 pScaleFactor
[group
*16+band
] = 0;
186 default: /* decode scale factor */
188 temp
= CBlock_DecodeHuffmanWord(bs
,hcb
);
189 factor
+= temp
- 60; /* MIDFAC 1.5 dB */
191 pScaleFactor
[group
*16+band
] = factor
- 100;
194 case INTENSITY_HCB
: /* intensity steering */
196 temp
= CBlock_DecodeHuffmanWord(bs
,hcb
);
197 position
+= temp
- 60;
198 pScaleFactor
[group
*16+band
] = position
- 100;
201 case NOISE_HCB
: /* PNS */
202 if (flags
& (AC_MPS_RES
|AC_USAC
|AC_RSVD50
)) {
203 return AAC_DEC_PARSE_ERROR
;
205 CPns_Read( &pAacDecoderChannelInfo
->data
.aac
.PnsData
, bs
, hcb
, pAacDecoderChannelInfo
->pDynData
->aScaleFactor
, pAacDecoderChannelInfo
->pDynData
->RawDataInfo
.GlobalGain
, band
, group
);
214 void CBlock_ScaleSpectralData(CAacDecoderChannelInfo
*pAacDecoderChannelInfo
, SamplingRateInfo
*pSamplingRateInfo
)
218 const SHORT
* RESTRICT pSfbScale
= pAacDecoderChannelInfo
->pDynData
->aSfbScale
;
219 SHORT
* RESTRICT pSpecScale
= pAacDecoderChannelInfo
->specScale
;
221 const SHORT
* RESTRICT BandOffsets
= GetScaleFactorBandOffsets(&pAacDecoderChannelInfo
->icsInfo
, pSamplingRateInfo
);
222 SPECTRAL_PTR RESTRICT pSpectralCoefficient
= pAacDecoderChannelInfo
->pSpectralCoefficient
;
225 FDKmemclear(pSpecScale
, 8*sizeof(SHORT
));
227 int max_band
= GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo
->icsInfo
);
228 for (window
=0, group
=0; group
< GetWindowGroups(&pAacDecoderChannelInfo
->icsInfo
); group
++)
230 for (groupwin
=0; groupwin
< GetWindowGroupLength(&pAacDecoderChannelInfo
->icsInfo
,group
); groupwin
++, window
++)
232 int SpecScale_window
= pSpecScale
[window
];
233 FIXP_DBL
*pSpectrum
= SPEC(pSpectralCoefficient
, window
, pAacDecoderChannelInfo
->granuleLength
);
235 /* find scaling for current window */
236 for (band
=0; band
< max_band
; band
++)
238 SpecScale_window
= fMax(SpecScale_window
, (int)pSfbScale
[window
*16+band
]);
241 if (pAacDecoderChannelInfo
->pDynData
->TnsData
.Active
) {
242 SpecScale_window
+= TNS_SCALE
;
245 /* store scaling of current window */
246 pSpecScale
[window
] = SpecScale_window
;
248 #ifdef FUNCTION_CBlock_ScaleSpectralData_func1
250 CBlock_ScaleSpectralData_func1(pSpectrum
, max_band
, BandOffsets
, SpecScale_window
, pSfbScale
, window
);
252 #else /* FUNCTION_CBlock_ScaleSpectralData_func1 */
253 for (band
=0; band
< max_band
; band
++)
255 int scale
= SpecScale_window
- pSfbScale
[window
*16+band
];
258 /* following relation can be used for optimizations: (BandOffsets[i]%4) == 0 for all i */
259 int max_index
= BandOffsets
[band
+1];
260 for (int index
= BandOffsets
[band
]; index
< max_index
; index
++)
262 pSpectrum
[index
] >>= scale
;
266 #endif /* FUNCTION_CBlock_ScaleSpectralData_func1 */
272 AAC_DECODER_ERROR
CBlock_ReadSectionData(HANDLE_FDK_BITSTREAM bs
,
273 CAacDecoderChannelInfo
*pAacDecoderChannelInfo
,
274 const SamplingRateInfo
*pSamplingRateInfo
,
278 int sect_len
, sect_len_incr
;
281 UCHAR
*pCodeBook
= pAacDecoderChannelInfo
->pDynData
->aCodeBook
;
282 /* HCR input (long) */
283 SHORT
*pNumLinesInSec
= pAacDecoderChannelInfo
->pDynData
->specificTo
.aac
.aNumLineInSec4Hcr
;
284 int numLinesInSecIdx
= 0;
285 UCHAR
*pHcrCodeBook
= pAacDecoderChannelInfo
->pDynData
->specificTo
.aac
.aCodeBooks4Hcr
;
286 const SHORT
*BandOffsets
= GetScaleFactorBandOffsets(&pAacDecoderChannelInfo
->icsInfo
, pSamplingRateInfo
);
287 pAacDecoderChannelInfo
->pDynData
->specificTo
.aac
.numberSection
= 0;
288 AAC_DECODER_ERROR ErrorStatus
= AAC_DEC_OK
;
290 FDKmemclear(pCodeBook
, sizeof(UCHAR
)*(8*16));
292 const int nbits
= (IsLongBlock(&pAacDecoderChannelInfo
->icsInfo
) == 1) ? 5 : 3;
294 int sect_esc_val
= (1 << nbits
) - 1 ;
296 UCHAR ScaleFactorBandsTransmitted
= GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo
->icsInfo
);
297 for (group
=0; group
<GetWindowGroups(&pAacDecoderChannelInfo
->icsInfo
); group
++)
299 for (band
=0; band
< ScaleFactorBandsTransmitted
; )
302 if ( flags
& AC_ER_VCB11
) {
303 sect_cb
= (UCHAR
) FDKreadBits(bs
,5);
306 sect_cb
= (UCHAR
) FDKreadBits(bs
,4);
308 if ( ((flags
& AC_ER_VCB11
) == 0) || ( sect_cb
< 11 ) || ((sect_cb
> 11) && (sect_cb
< 16)) ) {
309 sect_len_incr
= FDKreadBits(bs
, nbits
);
310 while (sect_len_incr
== sect_esc_val
)
312 sect_len
+= sect_esc_val
;
313 sect_len_incr
= FDKreadBits(bs
, nbits
);
320 sect_len
+= sect_len_incr
;
323 top
= band
+ sect_len
;
325 if (flags
& AC_ER_HCR
) {
326 /* HCR input (long) -- collecting sideinfo (for HCR-_long_ only) */
327 pNumLinesInSec
[numLinesInSecIdx
] = BandOffsets
[top
] - BandOffsets
[band
];
329 if (numLinesInSecIdx
>= MAX_SFB_HCR
) {
330 return AAC_DEC_PARSE_ERROR
;
333 (sect_cb
== BOOKSCL
) )
335 return AAC_DEC_INVALID_CODE_BOOK
;
337 *pHcrCodeBook
++ = sect_cb
;
339 pAacDecoderChannelInfo
->pDynData
->specificTo
.aac
.numberSection
++;
342 /* Check spectral line limits */
343 if (IsLongBlock( &(pAacDecoderChannelInfo
->icsInfo
) ))
346 return AAC_DEC_DECODE_FRAME_ERROR
;
348 } else { /* short block */
349 if (top
+ group
*16 > (8 * 16)) {
350 return AAC_DEC_DECODE_FRAME_ERROR
;
354 /* Check if decoded codebook index is feasible */
355 if ( (sect_cb
== BOOKSCL
)
356 || ( (sect_cb
== INTENSITY_HCB
|| sect_cb
== INTENSITY_HCB2
) && pAacDecoderChannelInfo
->pDynData
->RawDataInfo
.CommonWindow
== 0)
359 return AAC_DEC_INVALID_CODE_BOOK
;
362 /* Store codebook index */
363 for (; band
< top
; band
++)
365 pCodeBook
[group
*16+band
] = sect_cb
;
374 /* mso: provides a faster way to i-quantize a whole band in one go */
377 * \brief inverse quantize one sfb. Each value of the sfb is processed according to the
378 * formula: spectrum[i] = Sign(spectrum[i]) * Matissa(spectrum[i])^(4/3) * 2^(lsb/4).
379 * \param spectrum pointer to first line of the sfb to be inverse quantized.
380 * \param noLines number of lines belonging to the sfb.
381 * \param lsb last 2 bits of the scale factor of the sfb.
382 * \param scale max allowed shift scale for the sfb.
385 void InverseQuantizeBand( FIXP_DBL
* RESTRICT spectrum
,
390 const FIXP_DBL
* RESTRICT InverseQuantTabler
=(FIXP_DBL
*)InverseQuantTable
;
391 const FIXP_DBL
* RESTRICT MantissaTabler
=(FIXP_DBL
*)MantissaTable
[lsb
];
392 const SCHAR
* RESTRICT ExponentTabler
=(SCHAR
*)ExponentTable
[lsb
];
394 FIXP_DBL
*ptr
= spectrum
;
395 FIXP_DBL signedValue
;
397 FDK_ASSERT(noLines
>2);
398 for (INT i
=noLines
; i
--; )
400 if ((signedValue
= *ptr
++) != FL2FXCONST_DBL(0))
402 FIXP_DBL value
= fAbs(signedValue
);
403 UINT freeBits
= CntLeadingZeros(value
);
404 UINT exponent
= 32 - freeBits
;
406 UINT x
= (UINT
) (LONG
)value
<< (INT
) freeBits
;
407 x
<<= 1; /* shift out sign bit to avoid masking later on */
408 UINT tableIndex
= x
>> 24;
409 x
= (x
>> 20) & 0x0F;
411 UINT r0
=(UINT
)(LONG
)InverseQuantTabler
[tableIndex
+0];
412 UINT r1
=(UINT
)(LONG
)InverseQuantTabler
[tableIndex
+1];
413 UINT temp
= (r1
- r0
)*x
+ (r0
<< 4);
415 value
= fMultDiv2((FIXP_DBL
)temp
, MantissaTabler
[exponent
]);
417 /* + 1 compensates fMultDiv2() */
418 scaleValueInPlace(&value
, scale
+ ExponentTabler
[exponent
] + 1);
420 signedValue
= (signedValue
< (FIXP_DBL
)0) ? -value
: value
;
421 ptr
[-1] = signedValue
;
426 AAC_DECODER_ERROR
CBlock_InverseQuantizeSpectralData(CAacDecoderChannelInfo
*pAacDecoderChannelInfo
, SamplingRateInfo
*pSamplingRateInfo
)
428 int window
, group
, groupwin
, band
;
429 int ScaleFactorBandsTransmitted
= GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo
->icsInfo
);
430 UCHAR
*RESTRICT pCodeBook
= pAacDecoderChannelInfo
->pDynData
->aCodeBook
;
431 SHORT
*RESTRICT pSfbScale
= pAacDecoderChannelInfo
->pDynData
->aSfbScale
;
432 SHORT
*RESTRICT pScaleFactor
= pAacDecoderChannelInfo
->pDynData
->aScaleFactor
;
433 const SHORT
*RESTRICT BandOffsets
= GetScaleFactorBandOffsets(&pAacDecoderChannelInfo
->icsInfo
, pSamplingRateInfo
);
435 FDKmemclear(pAacDecoderChannelInfo
->pDynData
->aSfbScale
, (8*16)*sizeof(SHORT
));
437 for (window
=0, group
=0; group
< GetWindowGroups(&pAacDecoderChannelInfo
->icsInfo
); group
++)
439 for (groupwin
=0; groupwin
< GetWindowGroupLength(&pAacDecoderChannelInfo
->icsInfo
,group
); groupwin
++, window
++)
441 /* inverse quantization */
442 for (band
=0; band
< ScaleFactorBandsTransmitted
; band
++)
444 FIXP_DBL
*pSpectralCoefficient
= SPEC(pAacDecoderChannelInfo
->pSpectralCoefficient
, window
, pAacDecoderChannelInfo
->granuleLength
) + BandOffsets
[band
];
446 int noLines
= BandOffsets
[band
+1] - BandOffsets
[band
];
447 int bnds
= group
*16+band
;
450 if ((pCodeBook
[bnds
] == ZERO_HCB
)
451 || (pCodeBook
[bnds
] == INTENSITY_HCB
)
452 || (pCodeBook
[bnds
] == INTENSITY_HCB2
)
456 if (pCodeBook
[bnds
] == NOISE_HCB
)
458 /* Leave headroom for PNS values. + 1 because ceil(log2(2^(0.25*3))) = 1,
459 worst case of additional headroom required because of the scalefactor. */
460 pSfbScale
[window
*16+band
] = (pScaleFactor
[bnds
] >> 2) + 1 ;
464 /* Find max spectral line value of the current sfb */
465 FIXP_DBL locMax
= (FIXP_DBL
)0;
467 for (i
= noLines
; i
-- ; ) {
468 /* Expensive memory access */
469 locMax
= fMax(fixp_abs(pSpectralCoefficient
[i
]), locMax
);
472 /* Cheap robustness improvement - Do not remove!!! */
473 if (fixp_abs(locMax
) > (FIXP_DBL
)MAX_QUANTIZED_VALUE
) {
474 return AAC_DEC_DECODE_FRAME_ERROR
;
478 The inverse quantized spectral lines are defined by:
479 pSpectralCoefficient[i] = Sign(pSpectralCoefficient[i]) * 2^(0.25*pScaleFactor[bnds]) * pSpectralCoefficient[i]^(4/3)
480 This is equivalent to:
481 pSpectralCoefficient[i] = Sign(pSpectralCoefficient[i]) * (2^(pScaleFactor[bnds] % 4) * pSpectralCoefficient[i]^(4/3))
482 pSpectralCoefficient_e[i] += pScaleFactor[bnds]/4
485 int msb
= pScaleFactor
[bnds
] >> 2 ;
486 int lsb
= pScaleFactor
[bnds
] & 0x03 ;
488 int scale
= GetScaleFromValue(locMax
, lsb
);
490 pSfbScale
[window
*16+band
] = msb
- scale
;
491 InverseQuantizeBand(pSpectralCoefficient
, noLines
, lsb
, scale
);
502 AAC_DECODER_ERROR
CBlock_ReadSpectralData(HANDLE_FDK_BITSTREAM bs
,
503 CAacDecoderChannelInfo
*pAacDecoderChannelInfo
,
504 const SamplingRateInfo
*pSamplingRateInfo
,
508 int window
,group
,groupwin
,groupoffset
,band
;
509 UCHAR
*RESTRICT pCodeBook
= pAacDecoderChannelInfo
->pDynData
->aCodeBook
;
510 const SHORT
*RESTRICT BandOffsets
= GetScaleFactorBandOffsets(&pAacDecoderChannelInfo
->icsInfo
, pSamplingRateInfo
);
512 SPECTRAL_PTR pSpectralCoefficient
= pAacDecoderChannelInfo
->pSpectralCoefficient
;
515 int ScaleFactorBandsTransmitted
= GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo
->icsInfo
);
517 FDK_ASSERT(BandOffsets
!= NULL
);
519 FDKmemclear(pSpectralCoefficient
, sizeof(SPECTRUM
));
521 if ( (flags
& AC_ER_HCR
) == 0 )
525 /* plain huffman decoder short */
526 for (group
=0; group
< GetWindowGroups(&pAacDecoderChannelInfo
->icsInfo
); group
++)
528 for (band
=0; band
< ScaleFactorBandsTransmitted
; band
++)
530 int bnds
= group
*16+band
;
531 UCHAR currentCB
= pCodeBook
[bnds
];
533 /* patch to run plain-huffman-decoder with vcb11 input codebooks (LAV-checking might be possible below using the virtual cb and a LAV-table) */
534 if ((currentCB
>= 16) && (currentCB
<= 31)) {
535 pCodeBook
[bnds
] = currentCB
= 11;
537 if ( !((currentCB
== ZERO_HCB
)
538 || (currentCB
== NOISE_HCB
)
539 || (currentCB
== INTENSITY_HCB
)
540 || (currentCB
== INTENSITY_HCB2
)) )
542 const CodeBookDescription
*hcb
= &AACcodeBookDescriptionTable
[currentCB
];
543 int step
= hcb
->Dimension
;
544 int offset
= hcb
->Offset
;
545 int bits
= hcb
->numBits
;
546 int mask
= (1<<bits
)-1;
548 for (groupwin
=0; groupwin
< GetWindowGroupLength(&pAacDecoderChannelInfo
->icsInfo
,group
); groupwin
++)
550 window
= groupoffset
+ groupwin
;
552 FIXP_DBL
*mdctSpectrum
= SPEC(pSpectralCoefficient
, window
, pAacDecoderChannelInfo
->granuleLength
);
554 locMax
= (FIXP_DBL
)0 ;
556 for (index
=BandOffsets
[band
]; index
< BandOffsets
[band
+1]; index
+=step
)
558 int idx
= CBlock_DecodeHuffmanWord(bs
,hcb
);
560 for (i
=0; i
<step
; i
++) {
563 tmp
= (FIXP_DBL
)((idx
& mask
)-offset
);
567 if (tmp
!= FIXP_DBL(0))
568 tmp
= (FDKreadBits(bs
,1))? -tmp
: tmp
;
570 mdctSpectrum
[index
+i
] = tmp
;
573 if (currentCB
== ESCBOOK
)
575 mdctSpectrum
[index
+0] = (FIXP_DBL
)CBlock_GetEscape(bs
, (LONG
)mdctSpectrum
[index
+0]);
576 mdctSpectrum
[index
+1] = (FIXP_DBL
)CBlock_GetEscape(bs
, (LONG
)mdctSpectrum
[index
+1]);
583 groupoffset
+= GetWindowGroupLength(&pAacDecoderChannelInfo
->icsInfo
,group
);
585 /* plain huffman decoding (short) finished */
587 /* HCR - Huffman Codeword Reordering short */
588 else /* if ( flags & AC_ER_HCR ) */
590 H_HCR_INFO hHcr
= &pAacDecoderChannelInfo
->pComData
->overlay
.aac
.erHcrInfo
;
593 /* advanced Huffman decoding starts here (HCR decoding :) */
594 if ( pAacDecoderChannelInfo
->pDynData
->specificTo
.aac
.lenOfReorderedSpectralData
!= 0 ) {
596 /* HCR initialization short */
597 hcrStatus
= HcrInit(hHcr
, pAacDecoderChannelInfo
, pSamplingRateInfo
, bs
);
599 if (hcrStatus
!= 0) {
600 return AAC_DEC_DECODE_FRAME_ERROR
;
603 /* HCR decoding short */
604 hcrStatus
= HcrDecoder(hHcr
, pAacDecoderChannelInfo
, pSamplingRateInfo
, bs
);
606 if (hcrStatus
!= 0) {
607 #if HCR_ERROR_CONCEALMENT
608 HcrMuteErroneousLines(hHcr
);
610 return AAC_DEC_DECODE_FRAME_ERROR
;
611 #endif /* HCR_ERROR_CONCEALMENT */
614 FDKpushFor (bs
, pAacDecoderChannelInfo
->pDynData
->specificTo
.aac
.lenOfReorderedSpectralData
);
617 /* HCR - Huffman Codeword Reordering short finished */
621 if ( IsLongBlock(&pAacDecoderChannelInfo
->icsInfo
) && !(flags
& (AC_ELD
|AC_SCALABLE
)) )
623 /* apply pulse data */
624 CPulseData_Apply(&pAacDecoderChannelInfo
->pDynData
->specificTo
.aac
.PulseData
,
625 GetScaleFactorBandOffsets(&pAacDecoderChannelInfo
->icsInfo
, pSamplingRateInfo
),
626 SPEC_LONG(pSpectralCoefficient
));
635 void ApplyTools ( CAacDecoderChannelInfo
*pAacDecoderChannelInfo
[],
636 const SamplingRateInfo
*pSamplingRateInfo
,
641 if ( !(flags
& (AC_USAC
|AC_RSVD50
|AC_MPS_RES
)) ) {
643 &pAacDecoderChannelInfo
[channel
]->data
.aac
.PnsData
,
644 &pAacDecoderChannelInfo
[channel
]->icsInfo
,
645 pAacDecoderChannelInfo
[channel
]->pSpectralCoefficient
,
646 pAacDecoderChannelInfo
[channel
]->specScale
,
647 pAacDecoderChannelInfo
[channel
]->pDynData
->aScaleFactor
,
649 pAacDecoderChannelInfo
[channel
]->granuleLength
,
655 &pAacDecoderChannelInfo
[channel
]->pDynData
->TnsData
,
656 &pAacDecoderChannelInfo
[channel
]->icsInfo
,
657 pAacDecoderChannelInfo
[channel
]->pSpectralCoefficient
,
659 pAacDecoderChannelInfo
[channel
]->granuleLength
664 int getWindow2Nr(int length
, int shape
)
669 /* Low Overlap, 3/4 zeroed */
670 nr
= (length
* 3)>>2;
676 void CBlock_FrequencyToTime(CAacDecoderStaticChannelInfo
*pAacDecoderStaticChannelInfo
,
677 CAacDecoderChannelInfo
*pAacDecoderChannelInfo
,
678 INT_PCM outSamples
[],
679 const SHORT frameLen
,
682 FIXP_DBL
*pWorkBuffer1
)
684 int fr
, fl
, tl
, nSamples
, nSpec
;
686 /* Determine left slope length (fl), right slope length (fr) and transform length (tl).
687 USAC: The slope length may mismatch with the previous frame in case of LPD / FD
688 transitions. The adjustment is handled by the imdct implementation.
693 switch( pAacDecoderChannelInfo
->icsInfo
.WindowSequence
) {
695 case OnlyLongSequence
:
697 fr
= frameLen
- getWindow2Nr(frameLen
, GetWindowShape(&pAacDecoderChannelInfo
->icsInfo
));
699 case LongStopSequence
:
703 case LongStartSequence
: /* or StopStartSequence */
707 case EightShortSequence
:
708 fl
= fr
= frameLen
>> 3;
718 FIXP_DBL
*tmp
= pAacDecoderChannelInfo
->pComData
->workBufferCore1
->mdctOutTemp
;
720 nSamples
= imdct_block(
721 &pAacDecoderStaticChannelInfo
->IMdct
,
723 SPEC_LONG(pAacDecoderChannelInfo
->pSpectralCoefficient
),
724 pAacDecoderChannelInfo
->specScale
,
728 FDKgetWindowSlope(fl
, GetWindowShape(&pAacDecoderChannelInfo
->icsInfo
)),
730 FDKgetWindowSlope(fr
, GetWindowShape(&pAacDecoderChannelInfo
->icsInfo
)),
734 for (i
=0; i
<frameLen
; i
++) {
735 outSamples
[i
*stride
] = IMDCT_SCALE(tmp
[i
]);
740 FDK_ASSERT(nSamples
== frameLen
);
744 #include "ldfiltbank.h"
745 void CBlock_FrequencyToTimeLowDelay( CAacDecoderStaticChannelInfo
*pAacDecoderStaticChannelInfo
,
746 CAacDecoderChannelInfo
*pAacDecoderChannelInfo
,
747 INT_PCM outSamples
[],
748 const short frameLen
,
751 InvMdctTransformLowDelay_fdk (
752 SPEC_LONG(pAacDecoderChannelInfo
->pSpectralCoefficient
),
753 pAacDecoderChannelInfo
->specScale
[0],
755 pAacDecoderStaticChannelInfo
->pOverlapBuffer
,