1 2 /* ----------------------------------------------------------------------------------------------------------- 3 Software License for The Fraunhofer FDK AAC Codec Library for Android 4 5 Copyright 1995 - 2012 Fraunhofer-Gesellschaft zur Frderung der angewandten Forschung e.V. 6 All rights reserved. 7 8 1. INTRODUCTION 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. 12 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. 17 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. 24 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. 28 29 2. COPYRIGHT LICENSE 30 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: 33 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. 36 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. 41 42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without 43 prior written permission. 44 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. 47 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." 52 53 3. NO PATENT LICENSE 54 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. 58 59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized 60 by appropriate patent licenses. 61 62 4. DISCLAIMER 63 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. 72 73 5. CONTACT INFORMATION 74 75 Fraunhofer Institute for Integrated Circuits IIS 76 Attention: Audio and Multimedia Departments - FDK AAC LL 77 Am Wolfsmantel 33 78 91058 Erlangen, Germany 79 80 www.iis.fraunhofer.de/amm 81 amm-info (at) iis.fraunhofer.de 82 ----------------------------------------------------------------------------------------------------------- */ 83 84 /***************************** MPEG-4 AAC Decoder ************************** 85 86 Author(s): Josef Hoepfl 87 Description: individual channel stream info 88 89 ******************************************************************************/ 90 91 #ifndef CHANNELINFO_H 92 #define CHANNELINFO_H 93 94 #include "common_fix.h" 95 96 #include "aac_rom.h" 97 #include "aacdecoder_lib.h" 98 #include "FDK_bitstream.h" 99 #include "overlapadd.h" 100 101 #include "mdct.h" 102 #include "stereo.h" 103 #include "pulsedata.h" 104 #include "aacdec_tns.h" 105 106 #include "aacdec_pns.h" 107 108 #include "aacdec_hcr_types.h" 109 #include "rvlc_info.h" 110 111 112 #include "conceal_types.h" 113 114 #include "aacdec_drc_types.h" 115 116 /* Output rendering mode */ 117 typedef enum { 118 AACDEC_RENDER_INVALID = 0, 119 AACDEC_RENDER_IMDCT, 120 AACDEC_RENDER_ELDFB, 121 AACDEC_RENDER_LPD, 122 AACDEC_RENDER_INTIMDCT 123 } AACDEC_RENDER_MODE; 124 125 enum { 126 MAX_QUANTIZED_VALUE = 8191 127 }; 128 129 enum 130 { 131 OnlyLongSequence = 0, 132 LongStartSequence, 133 EightShortSequence, 134 LongStopSequence 135 }; 136 137 138 typedef struct 139 { 140 const SHORT *ScaleFactorBands_Long; 141 const SHORT *ScaleFactorBands_Short; 142 UCHAR NumberOfScaleFactorBands_Long; 143 UCHAR NumberOfScaleFactorBands_Short; 144 UINT samplingRateIndex; 145 UINT samplingRate; 146 } SamplingRateInfo; 147 148 typedef struct 149 { 150 UCHAR CommonWindow; 151 UCHAR GlobalGain; 152 153 } CRawDataInfo; 154 155 typedef struct 156 { 157 UCHAR WindowGroupLength[8]; 158 UCHAR WindowGroups; 159 UCHAR Valid; 160 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 */ 163 UCHAR MaxSfBands; 164 UCHAR ScaleFactorGrouping; 165 166 UCHAR TotalSfBands; 167 168 } CIcsInfo; 169 170 171 enum 172 { 173 ZERO_HCB = 0, 174 ESCBOOK = 11, 175 NSPECBOOKS = ESCBOOK + 1, 176 BOOKSCL = NSPECBOOKS, 177 NOISE_HCB = 13, 178 INTENSITY_HCB2 = 14, 179 INTENSITY_HCB = 15, 180 LAST_HCB 181 }; 182 183 #define TNS_SCALE 3 184 185 /* 186 * This struct must be allocated one for every channel and must be persistent. 187 */ 188 typedef struct 189 { 190 FIXP_DBL *pOverlapBuffer; 191 mdct_t IMdct; 192 193 194 195 CDrcChannelData drcData; 196 CConcealmentInfo concealmentInfo; 197 198 } CAacDecoderStaticChannelInfo; 199 200 201 /* 202 * This union must be allocated for every element (up to 2 channels). 203 */ 204 typedef struct { 205 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. */ 210 CTnsData TnsData; 211 CRawDataInfo RawDataInfo; 212 213 shouldBeUnion { 214 215 struct { 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; 221 SCHAR numberSection; 222 SCHAR rvlcCurrentScaleFactorOK; 223 SCHAR rvlcIntensityUsed; 224 } aac; 225 } specificTo; 226 227 } CAacDecoderDynamicData; 228 229 typedef shouldBeUnion { 230 CAacDecoderDynamicData pAacDecoderDynamicData[2]; 231 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]; 235 236 } CWorkBufferCore1; 237 238 /* Common data referenced by all channels */ 239 typedef struct { 240 241 CWorkBufferCore1 *workBufferCore1; 242 FIXP_DBL* workBufferCore2; 243 244 CPnsInterChannelData pnsInterChannelData; 245 INT pnsCurrentSeed; 246 INT pnsRandomSeed[(8*16)]; 247 248 CJointStereoData jointStereoData; /* One for one element */ 249 250 shouldBeUnion { 251 struct { 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 */ 257 } aac; 258 259 } overlay; 260 261 } CAacDecoderCommonData; 262 263 264 /* 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.. 271 */ 272 typedef struct 273 { 274 SPECTRAL_PTR pSpectralCoefficient; /* Spectral coefficients of each window */ 275 SHORT specScale[8]; /* Scale shift values of each spectrum window */ 276 CIcsInfo icsInfo; 277 INT granuleLength; /* Size of smallest spectrum piece */ 278 UCHAR ElementInstanceTag; 279 280 AACDEC_RENDER_MODE renderMode; /* Output signal rendering mode */ 281 282 shouldBeUnion { 283 struct { 284 CPnsData PnsData; /* Not required for USAC */ 285 } aac; 286 287 struct { 288 } usac; 289 } data; 290 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 */ 293 294 } CAacDecoderChannelInfo; 295 296 /* channelinfo.cpp */ 297 298 AAC_DECODER_ERROR getSamplingRateInfo(SamplingRateInfo *t, UINT samplesPerFrame, UINT samplingRateIndex, UINT samplingRate); 299 300 /** 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 306 */ 307 AAC_DECODER_ERROR IcsReadMaxSfb ( 308 HANDLE_FDK_BITSTREAM hBs, 309 CIcsInfo *pIcsInfo, 310 const SamplingRateInfo *pSamplingRateInfo 311 ); 312 313 AAC_DECODER_ERROR IcsRead( 314 HANDLE_FDK_BITSTREAM bs, 315 CIcsInfo *pIcsInfo, 316 const SamplingRateInfo* SamplingRateInfoTable, 317 const UINT flags 318 ); 319 320 /* stereo.cpp, only called from this file */ 321 322 /*! 323 \brief Applies MS stereo. 324 325 The function applies MS stereo. 326 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. 334 \return none 335 */ 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); 342 343 /*! 344 \brief Applies intensity stereo 345 346 The function applies intensity stereo. 347 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. 354 \return none 355 */ 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); 362 363 364 /* aacdec_pns.cpp */ 365 int CPns_IsPnsUsed (const CPnsData *pPnsData, 366 const int group, 367 const int band); 368 369 void CPns_SetCorrelation(CPnsData *pPnsData, 370 const int group, 371 const int band, 372 const int outofphase); 373 374 /****************** inline functions ******************/ 375 376 inline UCHAR IsValid(const CIcsInfo *pIcsInfo) 377 { 378 return pIcsInfo->Valid; 379 } 380 381 inline UCHAR IsLongBlock(const CIcsInfo *pIcsInfo) 382 { 383 return (pIcsInfo->WindowSequence != EightShortSequence); 384 } 385 386 inline UCHAR GetWindowShape(const CIcsInfo *pIcsInfo) 387 { 388 return pIcsInfo->WindowShape; 389 } 390 391 inline UCHAR GetWindowSequence(const CIcsInfo *pIcsInfo) 392 { 393 return pIcsInfo->WindowSequence; 394 } 395 396 inline const SHORT *GetScaleFactorBandOffsets(const CIcsInfo *pIcsInfo, const SamplingRateInfo* samplingRateInfo) 397 { 398 if (IsLongBlock(pIcsInfo)) 399 { 400 return samplingRateInfo->ScaleFactorBands_Long; 401 } 402 else 403 { 404 return samplingRateInfo->ScaleFactorBands_Short; 405 } 406 } 407 408 inline int GetWindowsPerFrame(const CIcsInfo *pIcsInfo) 409 { 410 return (pIcsInfo->WindowSequence == EightShortSequence) ? 8 : 1; 411 } 412 413 inline UCHAR GetWindowGroups(const CIcsInfo *pIcsInfo) 414 { 415 return pIcsInfo->WindowGroups; 416 } 417 418 inline UCHAR GetWindowGroupLength(const CIcsInfo *pIcsInfo, const INT index) 419 { 420 return pIcsInfo->WindowGroupLength[index]; 421 } 422 423 inline const UCHAR *GetWindowGroupLengthTable(const CIcsInfo *pIcsInfo) 424 { 425 return pIcsInfo->WindowGroupLength; 426 } 427 428 inline UCHAR GetScaleFactorBandsTransmitted(const CIcsInfo *pIcsInfo) 429 { 430 return pIcsInfo->MaxSfBands; 431 } 432 433 inline UCHAR GetScaleMaxFactorBandsTransmitted(const CIcsInfo *pIcsInfo0, const CIcsInfo *pIcsInfo1) 434 { 435 return fMax(pIcsInfo0->MaxSfBands, pIcsInfo1->MaxSfBands); 436 } 437 438 inline UCHAR GetScaleFactorBandsTotal(const CIcsInfo *pIcsInfo) 439 { 440 return pIcsInfo->TotalSfBands; 441 } 442 443 /* Note: This function applies to AAC-LC only ! */ 444 inline UCHAR GetMaximumTnsBands(const CIcsInfo *pIcsInfo, const int samplingRateIndex) 445 { 446 return tns_max_bands_tbl[samplingRateIndex][!IsLongBlock(pIcsInfo)]; 447 } 448 449 #endif /* #ifndef CHANNELINFO_H */ 450 451