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: individual channel stream info
89 ******************************************************************************/
94 #include "common_fix.h"
97 #include "aacdecoder_lib.h"
98 #include "FDK_bitstream.h"
99 #include "overlapadd.h"
103 #include "pulsedata.h"
104 #include "aacdec_tns.h"
106 #include "aacdec_pns.h"
108 #include "aacdec_hcr_types.h"
109 #include "rvlc_info.h"
112 #include "conceal_types.h"
114 #include "aacdec_drc_types.h"
116 /* Output rendering mode */
118 AACDEC_RENDER_INVALID
= 0,
122 AACDEC_RENDER_INTIMDCT
123 } AACDEC_RENDER_MODE
;
126 MAX_QUANTIZED_VALUE
= 8191
131 OnlyLongSequence
= 0,
140 const SHORT
*ScaleFactorBands_Long
;
141 const SHORT
*ScaleFactorBands_Short
;
142 UCHAR NumberOfScaleFactorBands_Long
;
143 UCHAR NumberOfScaleFactorBands_Short
;
144 UINT samplingRateIndex
;
157 UCHAR WindowGroupLength
[8];
161 UCHAR WindowShape
; /* 0: sine window, 1: KBD, 2: low overlap */
162 UCHAR WindowSequence
; /* See enum above, 0: long, 1: start, 2: short, 3: stop */
164 UCHAR ScaleFactorGrouping
;
175 NSPECBOOKS
= ESCBOOK
+ 1,
176 BOOKSCL
= NSPECBOOKS
,
186 * This struct must be allocated one for every channel and must be persistent.
190 FIXP_DBL
*pOverlapBuffer
;
195 CDrcChannelData drcData
;
196 CConcealmentInfo concealmentInfo
;
198 } CAacDecoderStaticChannelInfo
;
202 * This union must be allocated for every element (up to 2 channels).
206 /* Common bit stream data */
207 SHORT aScaleFactor
[(8*16)]; /* Spectral scale factors for each sfb in each window. */
208 SHORT aSfbScale
[(8*16)]; /* could be free after ApplyTools() */
209 UCHAR aCodeBook
[(8*16)]; /* section data: codebook for each window and sfb. */
211 CRawDataInfo RawDataInfo
;
216 CPulseData PulseData
;
217 SHORT aNumLineInSec4Hcr
[MAX_SFB_HCR
]; /* needed once for all channels except for Drm syntax */
218 UCHAR aCodeBooks4Hcr
[MAX_SFB_HCR
]; /* needed once for all channels except for Drm syntax. Same as "aCodeBook" ? */
219 SHORT lenOfReorderedSpectralData
;
220 SCHAR lenOfLongestCodeword
;
222 SCHAR rvlcCurrentScaleFactorOK
;
223 SCHAR rvlcIntensityUsed
;
227 } CAacDecoderDynamicData
;
229 typedef shouldBeUnion
{
230 CAacDecoderDynamicData pAacDecoderDynamicData
[2];
232 /* Common signal data, can be used once the bit stream data from above is not used anymore. */
233 FIXP_DBL mdctOutTemp
[1024];
234 FIXP_DBL sbrWorkBuffer
[1024*2];
238 /* Common data referenced by all channels */
241 CWorkBufferCore1
*workBufferCore1
;
242 FIXP_DBL
* workBufferCore2
;
244 CPnsInterChannelData pnsInterChannelData
;
246 INT pnsRandomSeed
[(8*16)];
248 CJointStereoData jointStereoData
; /* One for one element */
252 CErHcrInfo erHcrInfo
;
253 CErRvlcInfo erRvlcInfo
;
254 SHORT aRvlcScfEsc
[RVLC_MAX_SFB
]; /* needed once for all channels */
255 SHORT aRvlcScfFwd
[RVLC_MAX_SFB
]; /* needed once for all channels */
256 SHORT aRvlcScfBwd
[RVLC_MAX_SFB
]; /* needed once for all channels */
261 } CAacDecoderCommonData
;
265 * This struct must be allocated one for every channels of every element and must be persistent.
266 * Among its members, the following memory areas can be overwritten under the given conditions:
267 * - pSpectralCoefficient The memory pointed to can be overwritten after time signal rendering.
268 * - data can be overwritten after time signal rendering.
269 * - pDynData memory pointed to can be overwritten after each CChannelElement_Decode() call.
270 * - pComData->overlay memory pointed to can be overwritten after each CChannelElement_Decode() call..
274 SPECTRAL_PTR pSpectralCoefficient
; /* Spectral coefficients of each window */
275 SHORT specScale
[8]; /* Scale shift values of each spectrum window */
277 INT granuleLength
; /* Size of smallest spectrum piece */
278 UCHAR ElementInstanceTag
;
280 AACDEC_RENDER_MODE renderMode
; /* Output signal rendering mode */
284 CPnsData PnsData
; /* Not required for USAC */
291 CAacDecoderDynamicData
*pDynData
; /* Data required for one element and discarded after decoding */
292 CAacDecoderCommonData
*pComData
; /* Data required for one channel at a time during decode */
294 } CAacDecoderChannelInfo
;
296 /* channelinfo.cpp */
298 AAC_DECODER_ERROR
getSamplingRateInfo(SamplingRateInfo
*t
, UINT samplesPerFrame
, UINT samplingRateIndex
, UINT samplingRate
);
301 * \brief Read max SFB from bit stream and assign TotalSfBands according
302 * to the window sequence and sample rate.
303 * \param hBs bit stream handle as data source
304 * \param pIcsInfo IcsInfo structure to read the window sequence and store MaxSfBands and TotalSfBands
305 * \param pSamplingRateInfo read only
307 AAC_DECODER_ERROR
IcsReadMaxSfb (
308 HANDLE_FDK_BITSTREAM hBs
,
310 const SamplingRateInfo
*pSamplingRateInfo
313 AAC_DECODER_ERROR
IcsRead(
314 HANDLE_FDK_BITSTREAM bs
,
316 const SamplingRateInfo
* SamplingRateInfoTable
,
320 /* stereo.cpp, only called from this file */
323 \brief Applies MS stereo.
325 The function applies MS stereo.
327 \param pAacDecoderChannelInfo aac channel info.
328 \param pScaleFactorBandOffsets pointer to scalefactor band offsets.
329 \param pWindowGroupLength pointer to window group length array.
330 \param windowGroups number of window groups.
331 \param scaleFactorBandsTransmittedL number of transmitted scalefactor bands in left channel.
332 \param scaleFactorBandsTransmittedR number of transmitted scalefactor bands in right channel.
333 May differ from scaleFactorBandsTransmittedL only for USAC.
336 void CJointStereo_ApplyMS(CAacDecoderChannelInfo
*pAacDecoderChannelInfo
[2],
337 const short *pScaleFactorBandOffsets
,
338 const UCHAR
*pWindowGroupLength
,
339 const int windowGroups
,
340 const int scaleFactorBandsTransmittedL
,
341 const int scaleFactorBandsTransmittedR
);
344 \brief Applies intensity stereo
346 The function applies intensity stereo.
348 \param pAacDecoderChannelInfo aac channel info.
349 \param pScaleFactorBandOffsets pointer to scalefactor band offsets.
350 \param pWindowGroupLength pointer to window group length array.
351 \param windowGroups number of window groups.
352 \param scaleFactorBandsTransmitted number of transmitted scalefactor bands.
353 \param CommonWindow common window bit.
356 void CJointStereo_ApplyIS(CAacDecoderChannelInfo
*pAacDecoderChannelInfo
[2],
357 const short *pScaleFactorBandOffsets
,
358 const UCHAR
*pWindowGroupLength
,
359 const int windowGroups
,
360 const int scaleFactorBandsTransmitted
,
361 const UINT CommonWindow
);
365 int CPns_IsPnsUsed (const CPnsData
*pPnsData
,
369 void CPns_SetCorrelation(CPnsData
*pPnsData
,
372 const int outofphase
);
374 /****************** inline functions ******************/
376 inline UCHAR
IsValid(const CIcsInfo
*pIcsInfo
)
378 return pIcsInfo
->Valid
;
381 inline UCHAR
IsLongBlock(const CIcsInfo
*pIcsInfo
)
383 return (pIcsInfo
->WindowSequence
!= EightShortSequence
);
386 inline UCHAR
GetWindowShape(const CIcsInfo
*pIcsInfo
)
388 return pIcsInfo
->WindowShape
;
391 inline UCHAR
GetWindowSequence(const CIcsInfo
*pIcsInfo
)
393 return pIcsInfo
->WindowSequence
;
396 inline const SHORT
*GetScaleFactorBandOffsets(const CIcsInfo
*pIcsInfo
, const SamplingRateInfo
* samplingRateInfo
)
398 if (IsLongBlock(pIcsInfo
))
400 return samplingRateInfo
->ScaleFactorBands_Long
;
404 return samplingRateInfo
->ScaleFactorBands_Short
;
408 inline int GetWindowsPerFrame(const CIcsInfo
*pIcsInfo
)
410 return (pIcsInfo
->WindowSequence
== EightShortSequence
) ? 8 : 1;
413 inline UCHAR
GetWindowGroups(const CIcsInfo
*pIcsInfo
)
415 return pIcsInfo
->WindowGroups
;
418 inline UCHAR
GetWindowGroupLength(const CIcsInfo
*pIcsInfo
, const INT index
)
420 return pIcsInfo
->WindowGroupLength
[index
];
423 inline const UCHAR
*GetWindowGroupLengthTable(const CIcsInfo
*pIcsInfo
)
425 return pIcsInfo
->WindowGroupLength
;
428 inline UCHAR
GetScaleFactorBandsTransmitted(const CIcsInfo
*pIcsInfo
)
430 return pIcsInfo
->MaxSfBands
;
433 inline UCHAR
GetScaleMaxFactorBandsTransmitted(const CIcsInfo
*pIcsInfo0
, const CIcsInfo
*pIcsInfo1
)
435 return fMax(pIcsInfo0
->MaxSfBands
, pIcsInfo1
->MaxSfBands
);
438 inline UCHAR
GetScaleFactorBandsTotal(const CIcsInfo
*pIcsInfo
)
440 return pIcsInfo
->TotalSfBands
;
443 /* Note: This function applies to AAC-LC only ! */
444 inline UCHAR
GetMaximumTnsBands(const CIcsInfo
*pIcsInfo
, const int samplingRateIndex
)
446 return tns_max_bands_tbl
[samplingRateIndex
][!IsLongBlock(pIcsInfo
)];
449 #endif /* #ifndef CHANNELINFO_H */