From 6cfabd35363c3ef5e3b209b867169a500b3ccc3c Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Mon, 26 Feb 2018 20:17:00 +0100 Subject: Upgrade to FDKv2 Bug: 71430241 Test: CTS DecoderTest and DecoderTestAacDrc original-Change-Id: Iaa20f749b8a04d553b20247cfe1a8930ebbabe30 Apply clang-format also on header files. original-Change-Id: I14de1ef16bbc79ec0283e745f98356a10efeb2e4 Fixes for MPEG-D DRC original-Change-Id: If1de2d74bbbac84b3f67de3b88b83f6a23b8a15c Catch unsupported tw_mdct at an early stage original-Change-Id: Ied9dd00d754162a0e3ca1ae3e6b854315d818afe Fixing PVC transition frames original-Change-Id: Ib75725abe39252806c32d71176308f2c03547a4e Move qmf bands sanity check original-Change-Id: Iab540c3013c174d9490d2ae100a4576f51d8dbc4 Initialize scaling variable original-Change-Id: I3c4087101b70e998c71c1689b122b0d7762e0f9e Add 16 qmf band configuration to getSlotNrgHQ() original-Change-Id: I49a5d30f703a1b126ff163df9656db2540df21f1 Always apply byte alignment at the end of the AudioMuxElement original-Change-Id: I42d560287506d65d4c3de8bfe3eb9a4ebeb4efc7 Setup SBR element only if no parse error exists original-Change-Id: I1915b73704bc80ab882b9173d6bec59cbd073676 Additional array index check in HCR original-Change-Id: I18cc6e501ea683b5009f1bbee26de8ddd04d8267 Fix fade-in index selection in concealment module original-Change-Id: Ibf802ed6ed8c05e9257e1f3b6d0ac1162e9b81c1 Enable explicit backward compatible parser for AAC_LD original-Change-Id: I27e9c678dcb5d40ed760a6d1e06609563d02482d Skip spatial specific config in explicit backward compatible ASC original-Change-Id: Iff7cc365561319e886090cedf30533f562ea4d6e Update flags description in decoder API original-Change-Id: I9a5b4f8da76bb652f5580cbd3ba9760425c43830 Add QMF domain reset function original-Change-Id: I4f89a8a2c0277d18103380134e4ed86996e9d8d6 DRC upgrade v2.1.0 original-Change-Id: I5731c0540139dab220094cd978ef42099fc45b74 Fix integer overflow in sqrtFixp_lookup() original-Change-Id: I429a6f0d19aa2cc957e0f181066f0ca73968c914 Fix integer overflow in invSqrtNorm2() original-Change-Id: I84de5cbf9fb3adeb611db203fe492fabf4eb6155 Fix integer overflow in GenerateRandomVector() original-Change-Id: I3118a641008bd9484d479e5b0b1ee2b5d7d44d74 Fix integer overflow in adjustTimeSlot_EldGrid() original-Change-Id: I29d503c247c5c8282349b79df940416a512fb9d5 Fix integer overflow in FDKsbrEnc_codeEnvelope() original-Change-Id: I6b34b61ebb9d525b0c651ed08de2befc1f801449 Follow-up on: Fix integer overflow in adjustTimeSlot_EldGrid() original-Change-Id: I6f8f578cc7089e5eb7c7b93e580b72ca35ad689a Fix integer overflow in get_pk_v2() original-Change-Id: I63375bed40d45867f6eeaa72b20b1f33e815938c Fix integer overflow in Syn_filt_zero() original-Change-Id: Ie0c02fdfbe03988f9d3b20d10cd9fe4c002d1279 Fix integer overflow in CFac_CalcFacSignal() original-Change-Id: Id2d767c40066c591b51768e978eb8af3b803f0c5 Fix integer overflow in FDKaacEnc_FDKaacEnc_calcPeNoAH() original-Change-Id: Idcbd0f4a51ae2550ed106aa6f3d678d1f9724841 Fix integer overflow in sbrDecoder_calculateGainVec() original-Change-Id: I7081bcbe29c5cede9821b38d93de07c7add2d507 Fix integer overflow in CLpc_SynthesisLattice() original-Change-Id: I4a95ddc18de150102352d4a1845f06094764c881 Fix integer overflow in Pred_Lt4() original-Change-Id: I4dbd012b2de7d07c3e70a47b92e3bfae8dbc750a Fix integer overflow in FDKsbrEnc_InitSbrFastTransientDetector() original-Change-Id: I788cbec1a4a00f44c2f3a72ad7a4afa219807d04 Fix unsigned integer overflow in FDKaacEnc_WriteBitstream() original-Change-Id: I68fc75166e7d2cd5cd45b18dbe3d8c2a92f1822a Fix unsigned integer overflow in FDK_MetadataEnc_Init() original-Change-Id: Ie8d025f9bcdb2442c704bd196e61065c03c10af4 Fix overflow in pseudo random number generators original-Change-Id: I3e2551ee01356297ca14e3788436ede80bd5513c Fix unsigned integer overflow in sbrDecoder_Parse() original-Change-Id: I3f231b2f437e9c37db4d5b964164686710eee971 Fix unsigned integer overflow in longsub() original-Change-Id: I73c2bc50415cac26f1f5a29e125bbe75f9180a6e Fix unsigned integer overflow in CAacDecoder_DecodeFrame() original-Change-Id: Ifce2db4b1454b46fa5f887e9d383f1cc43b291e4 Fix overflow at CLpdChannelStream_Read() original-Change-Id: Idb9d822ce3a4272e4794b643644f5434e2d4bf3f Fix unsigned integer overflow in Hcr_State_BODY_SIGN_ESC__ESC_WORD() original-Change-Id: I1ccf77c0015684b85534c5eb97162740a870b71c Fix unsigned integer overflow in UsacConfig_Parse() original-Change-Id: Ie6d27f84b6ae7eef092ecbff4447941c77864d9f Fix unsigned integer overflow in aacDecoder_drcParse() original-Change-Id: I713f28e883eea3d70b6fa56a7b8f8c22bcf66ca0 Fix unsigned integer overflow in aacDecoder_drcReadCompression() original-Change-Id: Ia34dfeb88c4705c558bce34314f584965cafcf7a Fix unsigned integer overflow in CDataStreamElement_Read() original-Change-Id: Iae896cc1d11f0a893d21be6aa90bd3e60a2c25f0 Fix unsigned integer overflow in transportDec_AdjustEndOfAccessUnit() original-Change-Id: I64cf29a153ee784bb4a16fdc088baabebc0007dc Fix unsigned integer overflow in transportDec_GetAuBitsRemaining() original-Change-Id: I975b3420faa9c16a041874ba0db82e92035962e4 Fix unsigned integer overflow in extractExtendedData() original-Change-Id: I2a59eb09e2053cfb58dfb75fcecfad6b85a80a8f Fix signed integer overflow in CAacDecoder_ExtPayloadParse() original-Change-Id: I4ad5ca4e3b83b5d964f1c2f8c5e7b17c477c7929 Fix unsigned integer overflow in CAacDecoder_DecodeFrame() original-Change-Id: I29a39df77d45c52a0c9c5c83c1ba81f8d0f25090 Follow-up on: Fix integer overflow in CLpc_SynthesisLattice() original-Change-Id: I8fb194ffc073a3432a380845be71036a272d388f Fix signed integer overflow in _interpolateDrcGain() original-Change-Id: I879ec9ab14005069a7c47faf80e8bc6e03d22e60 Fix unsigned integer overflow in FDKreadBits() original-Change-Id: I1f47a6a8037ff70375aa8844947d5681bb4287ad Fix unsigned integer overflow in FDKbyteAlign() original-Change-Id: Id5f3a11a0c9e50fc6f76ed6c572dbd4e9f2af766 Fix unsigned integer overflow in FDK_get32() original-Change-Id: I9d33b8e97e3d38cbb80629cb859266ca0acdce96 Fix unsigned integer overflow in FDK_pushBack() original-Change-Id: Ic87f899bc8c6acf7a377a8ca7f3ba74c3a1e1c19 Fix unsigned integer overflow in FDK_pushForward() original-Change-Id: I3b754382f6776a34be1602e66694ede8e0b8effc Fix unsigned integer overflow in ReadPsData() original-Change-Id: I25361664ba8139e32bbbef2ca8c106a606ce9c37 Fix signed integer overflow in E_UTIL_residu() original-Change-Id: I8c3abd1f437ee869caa8fb5903ce7d3d641b6aad REVERT: Follow-up on: Integer overflow in CLpc_SynthesisLattice(). original-Change-Id: I3d340099acb0414795c8dfbe6362bc0a8f045f9b Follow-up on: Fix integer overflow in CLpc_SynthesisLattice() original-Change-Id: I4aedb8b3a187064e9f4d985175aa55bb99cc7590 Follow-up on: Fix unsigned integer overflow in aacDecoder_drcParse() original-Change-Id: I2aa2e13916213bf52a67e8b0518e7bf7e57fb37d Fix integer overflow in acelp original-Change-Id: Ie6390c136d84055f8b728aefbe4ebef6e029dc77 Fix unsigned integer overflow in aacDecoder_UpdateBitStreamCounters() original-Change-Id: I391ffd97ddb0b2c184cba76139bfb356a3b4d2e2 Adjust concealment default settings original-Change-Id: I6a95db935a327c47df348030bcceafcb29f54b21 Saturate estimatedStartPos original-Change-Id: I27be2085e0ae83ec9501409f65e003f6bcba1ab6 Negative shift exponent in _interpolateDrcGain() original-Change-Id: I18edb26b26d002aafd5e633d4914960f7a359c29 Negative shift exponent in calculateICC() original-Change-Id: I3dcd2ae98d2eb70ee0d59750863cbb2a6f4f8aba Too large shift exponent in FDK_put() original-Change-Id: Ib7d9aaa434d2d8de4a13b720ca0464b31ca9b671 Too large shift exponent in CalcInvLdData() original-Change-Id: I43e6e78d4cd12daeb1dcd5d82d1798bdc2550262 Member access within null pointer of type SBR_CHANNEL original-Change-Id: Idc5e4ea8997810376d2f36bbdf628923b135b097 Member access within null pointer of type CpePersistentData original-Change-Id: Ib6c91cb0d37882768e5baf63324e429589de0d9d Member access within null pointer FDKaacEnc_psyMain() original-Change-Id: I7729b7f4479970531d9dc823abff63ca52e01997 Member access within null pointer FDKaacEnc_GetPnsParam() original-Change-Id: I9aa3b9f3456ae2e0f7483dbd5b3dde95fc62da39 Member access within null pointer FDKsbrEnc_EnvEncodeFrame() original-Change-Id: I67936f90ea714e90b3e81bc0dd1472cc713eb23a Add HCR sanity check original-Change-Id: I6c1d9732ebcf6af12f50b7641400752f74be39f7 Fix memory issue for HBE edge case with 8:3 SBR original-Change-Id: I11ea58a61e69fbe8bf75034b640baee3011e63e9 Additional SBR parametrization sanity check for ELD original-Change-Id: Ie26026fbfe174c2c7b3691f6218b5ce63e322140 Add MPEG-D DRC channel layout check original-Change-Id: Iea70a74f171b227cce636a9eac4ba662777a2f72 Additional out-of-bounds checks in MPEG-D DRC original-Change-Id: Ife4a8c3452c6fde8a0a09e941154a39a769777d4 Change-Id: Ic63cb2f628720f54fe9b572b0cb528e2599c624e --- libAACdec/src/channel.cpp | 1063 ++++++++++++++++++++++++++++++++------------- 1 file changed, 766 insertions(+), 297 deletions(-) (limited to 'libAACdec/src/channel.cpp') diff --git a/libAACdec/src/channel.cpp b/libAACdec/src/channel.cpp index 5475079..dbbf58a 100644 --- a/libAACdec/src/channel.cpp +++ b/libAACdec/src/channel.cpp @@ -1,74 +1,85 @@ - -/* ----------------------------------------------------------------------------------------------------------- +/* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. - All rights reserved. +© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +Forschung e.V. All rights reserved. 1. INTRODUCTION -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements -the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio. -This FDK AAC Codec software is intended to be used on a wide variety of Android devices. - -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual -audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by -independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part -of the MPEG specifications. - -Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer) -may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners -individually for the purpose of encoding or decoding bit streams in products that are compliant with -the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license -these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec -software may already be covered under those patent licenses when it is used for those licensed purposes only. - -Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality, -are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional -applications information and documentation. +The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software +that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding +scheme for digital audio. This FDK AAC Codec software is intended to be used on +a wide variety of Android devices. + +AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient +general perceptual audio codecs. AAC-ELD is considered the best-performing +full-bandwidth communications codec by independent studies and is widely +deployed. AAC has been standardized by ISO and IEC as part of the MPEG +specifications. + +Patent licenses for necessary patent claims for the FDK AAC Codec (including +those of Fraunhofer) may be obtained through Via Licensing +(www.vialicensing.com) or through the respective patent owners individually for +the purpose of encoding or decoding bit streams in products that are compliant +with the ISO/IEC MPEG audio standards. Please note that most manufacturers of +Android devices already license these patent claims through Via Licensing or +directly from the patent owners, and therefore FDK AAC Codec software may +already be covered under those patent licenses when it is used for those +licensed purposes only. + +Commercially-licensed AAC software libraries, including floating-point versions +with enhanced sound quality, are also available from Fraunhofer. Users are +encouraged to check the Fraunhofer website for additional applications +information and documentation. 2. COPYRIGHT LICENSE -Redistribution and use in source and binary forms, with or without modification, are permitted without -payment of copyright license fees provided that you satisfy the following conditions: +Redistribution and use in source and binary forms, with or without modification, +are permitted without payment of copyright license fees provided that you +satisfy the following conditions: -You must retain the complete text of this software license in redistributions of the FDK AAC Codec or -your modifications thereto in source code form. +You must retain the complete text of this software license in redistributions of +the FDK AAC Codec or your modifications thereto in source code form. -You must retain the complete text of this software license in the documentation and/or other materials -provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form. -You must make available free of charge copies of the complete source code of the FDK AAC Codec and your +You must retain the complete text of this software license in the documentation +and/or other materials provided with redistributions of the FDK AAC Codec or +your modifications thereto in binary form. You must make available free of +charge copies of the complete source code of the FDK AAC Codec and your modifications thereto to recipients of copies in binary form. -The name of Fraunhofer may not be used to endorse or promote products derived from this library without -prior written permission. +The name of Fraunhofer may not be used to endorse or promote products derived +from this library without prior written permission. -You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec -software or your modifications thereto. +You may not charge copyright license fees for anyone to use, copy or distribute +the FDK AAC Codec software or your modifications thereto. -Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software -and the date of any change. For modified versions of the FDK AAC Codec, the term -"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term -"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android." +Your modified versions of the FDK AAC Codec must carry prominent notices stating +that you changed the software and the date of any change. For modified versions +of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android" +must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK +AAC Codec Library for Android." 3. NO PATENT LICENSE -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer, -ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with -respect to this software. +NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without +limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE. +Fraunhofer provides no warranty of patent non-infringement with respect to this +software. -You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized -by appropriate patent licenses. +You may use this FDK AAC Codec software or modifications thereto only for +purposes that are authorized by appropriate patent licenses. 4. DISCLAIMER -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors -"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties -of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages, -including but not limited to procurement of substitute goods or services; loss of use, data, or profits, -or business interruption, however caused and on any theory of liability, whether in contract, strict -liability, or tort (including negligence), arising in any way out of the use of this software, even if -advised of the possibility of such damage. +This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright +holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, +including but not limited to the implied warranties of merchantability and +fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, +or consequential damages, including but not limited to procurement of substitute +goods or services; loss of use, data, or profits, or business interruption, +however caused and on any theory of liability, whether in contract, strict +liability, or tort (including negligence), arising in any way out of the use of +this software, even if advised of the possibility of such damage. 5. CONTACT INFORMATION @@ -79,21 +90,21 @@ Am Wolfsmantel 33 www.iis.fraunhofer.de/amm amm-info@iis.fraunhofer.de ------------------------------------------------------------------------------------------------------------ */ +----------------------------------------------------------------------------- */ -/***************************** MPEG-4 AAC Decoder ************************** +/**************************** AAC decoder library ****************************** Author(s): Josef Hoepfl + Description: -******************************************************************************/ +*******************************************************************************/ #include "channel.h" #include "aacdecoder.h" #include "block.h" #include "aacdec_tns.h" #include "FDK_bitstream.h" -#include "FDK_tools_rom.h" #include "conceal.h" @@ -101,27 +112,46 @@ amm-info@iis.fraunhofer.de #include "aacdec_hcr.h" +#include "usacdec_lpd.h" +#include "usacdec_fac.h" -static -void MapMidSideMaskToPnsCorrelation (CAacDecoderChannelInfo *pAacDecoderChannelInfo[2]) -{ +static void MapMidSideMaskToPnsCorrelation( + CAacDecoderChannelInfo *pAacDecoderChannelInfo[2]) { int group; - for (group = 0 ; group < pAacDecoderChannelInfo[L]->icsInfo.WindowGroups; group++) { + for (group = 0; group < pAacDecoderChannelInfo[L]->icsInfo.WindowGroups; + group++) { UCHAR groupMask = 1 << group; - for (UCHAR band = 0 ; band < pAacDecoderChannelInfo[L]->icsInfo.MaxSfBands; band++) { - if (pAacDecoderChannelInfo[L]->pComData->jointStereoData.MsUsed[band] & groupMask) { /* channels are correlated */ - CPns_SetCorrelation(&pAacDecoderChannelInfo[L]->data.aac.PnsData, group, band, 0); - - if (CPns_IsPnsUsed(&pAacDecoderChannelInfo[L]->data.aac.PnsData, group, band) && - CPns_IsPnsUsed(&pAacDecoderChannelInfo[R]->data.aac.PnsData, group, band)) - pAacDecoderChannelInfo[L]->pComData->jointStereoData.MsUsed[band] ^= groupMask; /* clear the groupMask-bit */ + for (UCHAR band = 0; band < pAacDecoderChannelInfo[L]->icsInfo.MaxSfBands; + band++) { + if (pAacDecoderChannelInfo[L]->pComData->jointStereoData.MsUsed[band] & + groupMask) { /* channels are correlated */ + CPns_SetCorrelation(&pAacDecoderChannelInfo[L]->data.aac.PnsData, group, + band, 0); + + if (CPns_IsPnsUsed(&pAacDecoderChannelInfo[L]->data.aac.PnsData, group, + band) && + CPns_IsPnsUsed(&pAacDecoderChannelInfo[R]->data.aac.PnsData, group, + band)) + pAacDecoderChannelInfo[L]->pComData->jointStereoData.MsUsed[band] ^= + groupMask; /* clear the groupMask-bit */ } } } } +static void Clean_Complex_Prediction_coefficients( + CJointStereoPersistentData *pJointStereoPersistentData, int windowGroups, + const int low_limit, const int high_limit) { + for (int group = 0; group < windowGroups; group++) { + for (int sfb = low_limit; sfb < high_limit; sfb++) { + pJointStereoPersistentData->alpha_q_re_prev[group][sfb] = 0; + pJointStereoPersistentData->alpha_q_im_prev[group][sfb] = 0; + } + } +} + /*! \brief Decode channel pair element @@ -129,79 +159,232 @@ void MapMidSideMaskToPnsCorrelation (CAacDecoderChannelInfo *pAacDecoderChannelI \return none */ -void CChannelElement_Decode( CAacDecoderChannelInfo *pAacDecoderChannelInfo[2], /*!< pointer to aac decoder channel info */ - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[2], - SamplingRateInfo *pSamplingRateInfo, - UINT flags, - int el_channels) -{ - int ch, maybe_jstereo = 0; +void CChannelElement_Decode( + CAacDecoderChannelInfo + *pAacDecoderChannelInfo[2], /*!< pointer to aac decoder channel info */ + CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[2], + SamplingRateInfo *pSamplingRateInfo, UINT flags, UINT elFlags, + int el_channels) { + int ch = 0; + + int maxSfBandsL = 0, maxSfBandsR = 0; + int maybe_jstereo = (el_channels > 1); + + if (flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA) && el_channels == 2) { + if (pAacDecoderChannelInfo[L]->data.usac.core_mode || + pAacDecoderChannelInfo[R]->data.usac.core_mode) { + maybe_jstereo = 0; + } + } - maybe_jstereo = (el_channels > 1); + if (maybe_jstereo) { + maxSfBandsL = + GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[L]->icsInfo); + maxSfBandsR = + GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[R]->icsInfo); - for (ch = 0; ch < el_channels; ch++) { - if ( pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_IMDCT - || pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_ELDFB ) - { - CBlock_InverseQuantizeSpectralData(pAacDecoderChannelInfo[ch], pSamplingRateInfo); + /* apply ms */ + if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow) { + if (!(flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA))) { + if (pAacDecoderChannelInfo[L]->data.aac.PnsData.PnsActive || + pAacDecoderChannelInfo[R]->data.aac.PnsData.PnsActive) { + MapMidSideMaskToPnsCorrelation(pAacDecoderChannelInfo); + } + } + /* if tns_on_lr == 1 run MS */ /* && + (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_active + == 1) */ + if (((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) && + (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_on_lr == + 1)) || + ((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) == 0)) { + int max_sfb_ste = (INT)(pAacDecoderChannelInfo[L]->icsInfo.max_sfb_ste); + + CJointStereo_ApplyMS( + pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo, + pAacDecoderChannelInfo[L]->pSpectralCoefficient, + pAacDecoderChannelInfo[R]->pSpectralCoefficient, + pAacDecoderChannelInfo[L]->pDynData->aSfbScale, + pAacDecoderChannelInfo[R]->pDynData->aSfbScale, + pAacDecoderChannelInfo[L]->specScale, + pAacDecoderChannelInfo[R]->specScale, + GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, + pSamplingRateInfo), + GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), + GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), max_sfb_ste, + maxSfBandsL, maxSfBandsR, + pAacDecoderChannelInfo[L] + ->pComData->jointStereoData.store_dmx_re_prev, + &(pAacDecoderChannelInfo[L] + ->pComData->jointStereoData.store_dmx_re_prev_e), + 1); + + } /* if ( ((elFlags & AC_EL_USAC_CP_POSSIBLE).... */ + } /* if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow)*/ + + /* apply intensity stereo */ /* modifies pAacDecoderChannelInfo[]->aSpecSfb + */ + if (!(flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA))) { + CJointStereo_ApplyIS( + pAacDecoderChannelInfo, + GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, + pSamplingRateInfo), + GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), + GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), + GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[L]->icsInfo), + pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow ? 1 + : 0); } - } + } /* maybe_stereo */ + for (ch = 0; ch < el_channels; ch++) { + if (pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_LPD) { + /* Decode LPD data */ + CLpdChannelStream_Decode(pAacDecoderChannelInfo[ch], + pAacDecoderStaticChannelInfo[ch], flags); + } else { + UCHAR noSfbs = + GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[ch]->icsInfo); + /* For USAC common window: max_sfb of both channels may differ + * (common_max_sfb == 0). */ + if ((maybe_jstereo == 1) && + (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow == + 1)) { + noSfbs = fMax(maxSfBandsL, maxSfBandsR); + } + int CP_active = 0; + if (elFlags & AC_EL_USAC_CP_POSSIBLE) { + CP_active = pAacDecoderChannelInfo[ch] + ->pComData->jointStereoData.cplx_pred_flag; + } + /* Omit writing of pAacDecoderChannelInfo[ch]->specScale for complex + stereo prediction since scaling has already been carried out. */ + int max_sfb_ste = (INT)(pAacDecoderChannelInfo[L]->icsInfo.max_sfb_ste); + + if ((!CP_active) || (CP_active && (max_sfb_ste < noSfbs)) || + ((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) && + (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_on_lr == + 0))) { + CBlock_ScaleSpectralData(pAacDecoderChannelInfo[ch], noSfbs, + pSamplingRateInfo); + + /*Active for the case of TNS applied before MS/CP*/ + if ((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) && + (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_on_lr == + 0)) { + if (IsLongBlock(&pAacDecoderChannelInfo[ch]->icsInfo)) { + for (int i = 0; i < noSfbs; i++) { + pAacDecoderChannelInfo[ch]->pDynData->aSfbScale[i] = + pAacDecoderChannelInfo[ch]->specScale[0]; + } + } else { + for (int i = 0; i < 8; i++) { + for (int j = 0; j < noSfbs; j++) { + pAacDecoderChannelInfo[ch]->pDynData->aSfbScale[i * 16 + j] = + pAacDecoderChannelInfo[ch]->specScale[i]; + } + } + } + } + } + } + } /* End "for (ch = 0; ch < el_channels; ch++)" */ if (maybe_jstereo) { /* apply ms */ if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow) { - int maxSfBandsL = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[L]->icsInfo); - int maxSfBandsR = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[R]->icsInfo); - if (pAacDecoderChannelInfo[L]->data.aac.PnsData.PnsActive || pAacDecoderChannelInfo[R]->data.aac.PnsData.PnsActive) { - MapMidSideMaskToPnsCorrelation(pAacDecoderChannelInfo); + } /* CommonWindow */ + else { + if (elFlags & AC_EL_USAC_CP_POSSIBLE) { + FDKmemclear( + pAacDecoderStaticChannelInfo[L] + ->pCpeStaticData->jointStereoPersistentData.alpha_q_re_prev, + JointStereoMaximumGroups * JointStereoMaximumBands * sizeof(SHORT)); + FDKmemclear( + pAacDecoderStaticChannelInfo[L] + ->pCpeStaticData->jointStereoPersistentData.alpha_q_im_prev, + JointStereoMaximumGroups * JointStereoMaximumBands * sizeof(SHORT)); } - - CJointStereo_ApplyMS(pAacDecoderChannelInfo, - GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, pSamplingRateInfo), - GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), - GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), - maxSfBandsL, - maxSfBandsR); } - /* apply intensity stereo */ /* modifies pAacDecoderChannelInfo[]->aSpecSfb */ - CJointStereo_ApplyIS(pAacDecoderChannelInfo, - GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, pSamplingRateInfo), - GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), - GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), - GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[L]->icsInfo), - pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow ? 1 : 0); + } /* if (maybe_jstereo) */ - } + for (ch = 0; ch < el_channels; ch++) { + if (pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_LPD) { + } else { + if (!(flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA))) { + /* Use same seed for coupled channels (CPE) */ + int pnsCh = (ch > 0) ? L : ch; + CPns_UpdateNoiseState( + &pAacDecoderChannelInfo[ch]->data.aac.PnsData, + pAacDecoderChannelInfo[pnsCh]->data.aac.PnsData.currentSeed, + pAacDecoderChannelInfo[ch]->pComData->pnsRandomSeed); + } - for (ch = 0; ch < el_channels; ch++) - { - { - /* write pAacDecoderChannelInfo[ch]->specScale */ - CBlock_ScaleSpectralData(pAacDecoderChannelInfo[ch], pSamplingRateInfo); + if ((!(flags & (AC_USAC))) || + ((flags & (AC_USAC)) && + (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_active == + 1)) || + (maybe_jstereo == 0)) { + ApplyTools( + pAacDecoderChannelInfo, pSamplingRateInfo, flags, elFlags, ch, + pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow); + } + } /* End "} else" */ + } /* End "for (ch = 0; ch < el_channels; ch++)" */ - ApplyTools (pAacDecoderChannelInfo, pSamplingRateInfo, flags, ch); - } + if (maybe_jstereo) { + /* apply ms */ + if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow) { + /* if tns_on_lr == 0 run MS */ + if ((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) && + (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_on_lr == + 0)) { + int max_sfb_ste = (INT)(pAacDecoderChannelInfo[L]->icsInfo.max_sfb_ste); + + CJointStereo_ApplyMS( + pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo, + pAacDecoderChannelInfo[L]->pSpectralCoefficient, + pAacDecoderChannelInfo[R]->pSpectralCoefficient, + pAacDecoderChannelInfo[L]->pDynData->aSfbScale, + pAacDecoderChannelInfo[R]->pDynData->aSfbScale, + pAacDecoderChannelInfo[L]->specScale, + pAacDecoderChannelInfo[R]->specScale, + GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, + pSamplingRateInfo), + GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), + GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), max_sfb_ste, + maxSfBandsL, maxSfBandsR, + pAacDecoderChannelInfo[L] + ->pComData->jointStereoData.store_dmx_re_prev, + &(pAacDecoderChannelInfo[L] + ->pComData->jointStereoData.store_dmx_re_prev_e), + 1); + } + + } /* if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow) */ + + } /* if (maybe_jstereo) */ + for (ch = 0; ch < el_channels; ch++) { + if (elFlags & AC_EL_USAC_CP_POSSIBLE) { + pAacDecoderStaticChannelInfo[L] + ->pCpeStaticData->jointStereoPersistentData.clearSpectralCoeffs = 0; + } } - CRvlc_ElementCheck( - pAacDecoderChannelInfo, - pAacDecoderStaticChannelInfo, - flags, - el_channels - ); + CRvlc_ElementCheck(pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo, + flags, el_channels); } -void CChannel_CodebookTableInit(CAacDecoderChannelInfo *pAacDecoderChannelInfo) -{ +void CChannel_CodebookTableInit( + CAacDecoderChannelInfo *pAacDecoderChannelInfo) { int b, w, maxBands, maxWindows; int maxSfb = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo); UCHAR *pCodeBook = pAacDecoderChannelInfo->pDynData->aCodeBook; - if ( IsLongBlock(&pAacDecoderChannelInfo->icsInfo) ) { + if (IsLongBlock(&pAacDecoderChannelInfo->icsInfo)) { maxBands = 64; maxWindows = 1; } else { @@ -209,60 +392,69 @@ void CChannel_CodebookTableInit(CAacDecoderChannelInfo *pAacDecoderChannelInfo) maxWindows = 8; } - for (w = 0; wpDynData->TnsData); + /* Set common window to 0 by default. If signalized in the bit stream it will + * be overwritten later explicitely */ + pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow = 0; + if (flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) { + pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_active = 0; + pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_on_lr = 0; + } if (numberOfChannels == 2) { CTns_Reset(&pAacDecoderChannelInfo[1]->pDynData->TnsData); + pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = 0; } - if (flags & (AC_ELD|AC_SCALABLE)) { - pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow = 1; - if (numberOfChannels == 2) { - pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow; + cplxPred = 0; + if (pAacDecoderStaticChannelInfo != NULL) { + if (elFlags & AC_EL_USAC_CP_POSSIBLE) { + pAacDecoderChannelInfo[0]->pComData->jointStereoData.cplx_pred_flag = 0; + cplxPred = 1; } + } + + if (0 || (flags & (AC_ELD | AC_SCALABLE))) { + pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow = 1; if (numberOfChannels == 2) { - pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow; + pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = + pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow; } } @@ -272,170 +464,413 @@ AAC_DECODER_ERROR CChannelElement_Read(HANDLE_FDK_BITSTREAM hBs, decision_bit = 0; do { switch (list->id[i]) { - case element_instance_tag: - pAacDecoderChannelInfo[0]->ElementInstanceTag = FDKreadBits(hBs, 4); - if (numberOfChannels == 2) { - pAacDecoderChannelInfo[1]->ElementInstanceTag = pAacDecoderChannelInfo[0]->ElementInstanceTag; - } - break; - case common_window: - decision_bit = pAacDecoderChannelInfo[ch]->pDynData->RawDataInfo.CommonWindow = FDKreadBits(hBs, 1); - if (numberOfChannels == 2) { - pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow; - } - break; - case ics_info: - /* Read individual channel info */ - error = IcsRead( hBs, - &pAacDecoderChannelInfo[ch]->icsInfo, - pSamplingRateInfo, - flags ); - - if (numberOfChannels == 2 && pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow) { - pAacDecoderChannelInfo[1]->icsInfo = pAacDecoderChannelInfo[0]->icsInfo; - } - break; - - - case ltp_data_present: - if (FDKreadBits(hBs, 1) != 0) { - error = AAC_DEC_UNSUPPORTED_PREDICTION; - } - break; - - case ms: - if ( CJointStereo_Read( - hBs, - &pAacDecoderChannelInfo[0]->pComData->jointStereoData, - GetWindowGroups(&pAacDecoderChannelInfo[0]->icsInfo), - GetScaleMaxFactorBandsTransmitted(&pAacDecoderChannelInfo[0]->icsInfo, - &pAacDecoderChannelInfo[1]->icsInfo), - flags) ) - { - error = AAC_DEC_PARSE_ERROR; - } - break; - - case global_gain: - pAacDecoderChannelInfo[ch]->pDynData->RawDataInfo.GlobalGain = (UCHAR) FDKreadBits(hBs,8); - break; - - case section_data: - error = CBlock_ReadSectionData( hBs, - pAacDecoderChannelInfo[ch], - pSamplingRateInfo, - flags ); - break; - + case element_instance_tag: + pAacDecoderChannelInfo[0]->ElementInstanceTag = FDKreadBits(hBs, 4); + if (numberOfChannels == 2) { + pAacDecoderChannelInfo[1]->ElementInstanceTag = + pAacDecoderChannelInfo[0]->ElementInstanceTag; + } + break; + case common_window: + decision_bit = + pAacDecoderChannelInfo[ch]->pDynData->RawDataInfo.CommonWindow = + FDKreadBits(hBs, 1); + if (numberOfChannels == 2) { + pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = + pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow; + } + break; + case ics_info: + /* store last window sequence (utilized in complex stereo prediction) + * before reading new channel-info */ + if (cplxPred) { + if (pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow) { + pAacDecoderStaticChannelInfo[0] + ->pCpeStaticData->jointStereoPersistentData.winSeqPrev = + pAacDecoderChannelInfo[0]->icsInfo.WindowSequence; + pAacDecoderStaticChannelInfo[0] + ->pCpeStaticData->jointStereoPersistentData.winShapePrev = + pAacDecoderChannelInfo[0]->icsInfo.WindowShape; + } + } + /* Read individual channel info */ + error = IcsRead(hBs, &pAacDecoderChannelInfo[ch]->icsInfo, + pSamplingRateInfo, flags); + + if (elFlags & AC_EL_LFE && + GetWindowSequence(&pAacDecoderChannelInfo[ch]->icsInfo) != + BLOCK_LONG) { + error = AAC_DEC_PARSE_ERROR; + break; + } + + if (numberOfChannels == 2 && + pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow) { + pAacDecoderChannelInfo[1]->icsInfo = + pAacDecoderChannelInfo[0]->icsInfo; + } + break; + + case common_max_sfb: + if (FDKreadBit(hBs) == 0) { + error = IcsReadMaxSfb(hBs, &pAacDecoderChannelInfo[1]->icsInfo, + pSamplingRateInfo); + } + break; + + case ltp_data_present: + if (FDKreadBits(hBs, 1) != 0) { + error = AAC_DEC_UNSUPPORTED_PREDICTION; + } + break; + + case ms: + + INT max_sfb_ste; + INT max_sfb_ste_clear; + + max_sfb_ste = GetScaleMaxFactorBandsTransmitted( + &pAacDecoderChannelInfo[0]->icsInfo, + &pAacDecoderChannelInfo[1]->icsInfo); + + max_sfb_ste_clear = 64; + + pAacDecoderChannelInfo[0]->icsInfo.max_sfb_ste = (UCHAR)max_sfb_ste; + pAacDecoderChannelInfo[1]->icsInfo.max_sfb_ste = (UCHAR)max_sfb_ste; + + if (flags & (AC_USAC | AC_RSV603DA) && + pAacDecoderChannelInfo[ch]->pDynData->RawDataInfo.CommonWindow == + 0) { + Clean_Complex_Prediction_coefficients( + &pAacDecoderStaticChannelInfo[0] + ->pCpeStaticData->jointStereoPersistentData, + GetWindowGroups(&pAacDecoderChannelInfo[0]->icsInfo), 0, 64); + } + + if (CJointStereo_Read( + hBs, &pAacDecoderChannelInfo[0]->pComData->jointStereoData, + GetWindowGroups(&pAacDecoderChannelInfo[0]->icsInfo), + max_sfb_ste, max_sfb_ste_clear, + /* jointStereoPersistentData and cplxPredictionData are only + available/allocated if cplxPred is active. */ + ((cplxPred == 0) || (pAacDecoderStaticChannelInfo == NULL)) + ? NULL + : &pAacDecoderStaticChannelInfo[0] + ->pCpeStaticData->jointStereoPersistentData, + ((cplxPred == 0) || (pAacDecoderChannelInfo[0] == NULL)) + ? NULL + : pAacDecoderChannelInfo[0] + ->pComStaticData->cplxPredictionData, + cplxPred, + GetScaleFactorBandsTotal(&pAacDecoderChannelInfo[0]->icsInfo), + GetWindowSequence(&pAacDecoderChannelInfo[0]->icsInfo), + flags)) { + error = AAC_DEC_PARSE_ERROR; + } + + break; + + case global_gain: + pAacDecoderChannelInfo[ch]->pDynData->RawDataInfo.GlobalGain = + (UCHAR)FDKreadBits(hBs, 8); + break; + + case section_data: + error = CBlock_ReadSectionData(hBs, pAacDecoderChannelInfo[ch], + pSamplingRateInfo, flags); + break; + + case scale_factor_data_usac: + pAacDecoderChannelInfo[ch]->currAliasingSymmetry = 0; + /* Set active sfb codebook indexes to HCB_ESC to make them "active" */ + CChannel_CodebookTableInit( + pAacDecoderChannelInfo[ch]); /* equals ReadSectionData(self, + bs) in float soft. block.c + line: ~599 */ + /* Note: The missing "break" is intentional here, since we need to call + * CBlock_ReadScaleFactorData(). */ + + case scale_factor_data: + if (flags & AC_ER_RVLC) { + /* read RVLC data from bitstream (error sens. cat. 1) */ + CRvlc_Read(pAacDecoderChannelInfo[ch], hBs); + } else { + error = CBlock_ReadScaleFactorData(pAacDecoderChannelInfo[ch], hBs, + flags); + } + break; + + case pulse: + if (CPulseData_Read( + hBs, + &pAacDecoderChannelInfo[ch]->pDynData->specificTo.aac.PulseData, + pSamplingRateInfo->ScaleFactorBands_Long, /* pulse data is only + allowed to be + present in long + blocks! */ + (void *)&pAacDecoderChannelInfo[ch]->icsInfo, + frame_length) != 0) { + error = AAC_DEC_DECODE_FRAME_ERROR; + } + break; + case tns_data_present: + CTns_ReadDataPresentFlag( + hBs, &pAacDecoderChannelInfo[ch]->pDynData->TnsData); + if (elFlags & AC_EL_LFE && + pAacDecoderChannelInfo[ch]->pDynData->TnsData.DataPresent) { + error = AAC_DEC_PARSE_ERROR; + } + break; + case tns_data: + /* tns_data_present is checked inside CTns_Read(). */ + error = CTns_Read(hBs, &pAacDecoderChannelInfo[ch]->pDynData->TnsData, + &pAacDecoderChannelInfo[ch]->icsInfo, flags); + + break; + + case gain_control_data: + break; + + case gain_control_data_present: + if (FDKreadBits(hBs, 1)) { + error = AAC_DEC_UNSUPPORTED_GAIN_CONTROL_DATA; + } + break; + + case tw_data: + break; + case common_tw: + break; + case tns_data_present_usac: + if (pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_active) { + CTns_ReadDataPresentUsac( + hBs, &pAacDecoderChannelInfo[0]->pDynData->TnsData, + &pAacDecoderChannelInfo[1]->pDynData->TnsData, + &pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_on_lr, + &pAacDecoderChannelInfo[0]->icsInfo, flags, elFlags, + pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow); + } else { + pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_on_lr = + (UCHAR)1; + } + break; + case core_mode: + decision_bit = FDKreadBits(hBs, 1); + pAacDecoderChannelInfo[ch]->data.usac.core_mode = decision_bit; + if ((ch == 1) && (pAacDecoderChannelInfo[0]->data.usac.core_mode != + pAacDecoderChannelInfo[1]->data.usac.core_mode)) { + /* StereoCoreToolInfo(core_mode[ch] ) */ + pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow = 0; + pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = 0; + } + break; + case tns_active: + pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_active = + FDKreadBit(hBs); + break; + case noise: + if (elFlags & AC_EL_USAC_NOISE) { + pAacDecoderChannelInfo[ch] + ->pDynData->specificTo.usac.fd_noise_level_and_offset = + FDKreadBits(hBs, 3 + 5); /* Noise level */ + } + break; + case lpd_channel_stream: - case scale_factor_data: - if (flags & AC_ER_RVLC) { - /* read RVLC data from bitstream (error sens. cat. 1) */ - CRvlc_Read(pAacDecoderChannelInfo[ch], hBs); - } - else - { - error = CBlock_ReadScaleFactorData(pAacDecoderChannelInfo[ch], hBs, flags); - } - break; - - case pulse: - if ( CPulseData_Read( hBs, - &pAacDecoderChannelInfo[ch]->pDynData->specificTo.aac.PulseData, - pSamplingRateInfo->ScaleFactorBands_Long, /* pulse data is only allowed to be present in long blocks! */ - (void*)&pAacDecoderChannelInfo[ch]->icsInfo, - frame_length - ) != 0 ) { - error = AAC_DEC_DECODE_FRAME_ERROR; - } - break; - case tns_data_present: - CTns_ReadDataPresentFlag(hBs, &pAacDecoderChannelInfo[ch]->pDynData->TnsData); - break; - case tns_data: - /* tns_data_present is checked inside CTns_Read(). */ - error = CTns_Read(hBs, &pAacDecoderChannelInfo[ch]->pDynData->TnsData, &pAacDecoderChannelInfo[ch]->icsInfo, flags); - break; - - case gain_control_data: - break; - - case gain_control_data_present: - if (FDKreadBits(hBs, 1)) { - error = AAC_DEC_UNSUPPORTED_GAIN_CONTROL_DATA; - } - break; - - case esc2_rvlc: - if (flags & AC_ER_RVLC) { - CRvlc_Decode( - pAacDecoderChannelInfo[ch], - pAacDecoderStaticChannelInfo[ch], - hBs - ); + error = CLpdChannelStream_Read(/* = lpd_channel_stream() */ + hBs, pAacDecoderChannelInfo[ch], + pAacDecoderStaticChannelInfo[ch], + pSamplingRateInfo, flags); } - break; - case esc1_hcr: - if (flags & AC_ER_HCR) { - CHcr_Read(hBs, pAacDecoderChannelInfo[ch] ); - } - break; - - case spectral_data: - error = CBlock_ReadSpectralData( hBs, - pAacDecoderChannelInfo[ch], - pSamplingRateInfo, - flags ); - if (flags & AC_ELD) { - pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_ELDFB; - } else { + pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_LPD; + break; + case fac_data: { + int fFacDatPresent = FDKreadBit(hBs); + + /* Wee need a valid fac_data[0] even if no FAC data is present (as + * temporal buffer) */ + pAacDecoderChannelInfo[ch]->data.usac.fac_data[0] = + pAacDecoderChannelInfo[ch]->data.usac.fac_data0; + + if (fFacDatPresent) { + if (elFlags & AC_EL_LFE) { + error = AAC_DEC_PARSE_ERROR; + break; + } + /* FAC data present, this frame is FD, so the last mode had to be + * ACELP. */ + if (pAacDecoderStaticChannelInfo[ch]->last_core_mode != LPD || + pAacDecoderStaticChannelInfo[ch]->last_lpd_mode != 0) { + pAacDecoderChannelInfo[ch]->data.usac.core_mode_last = LPD; + pAacDecoderChannelInfo[ch]->data.usac.lpd_mode_last = 0; + /* We can't change the past! So look to the future and go ahead! */ + } + CLpd_FAC_Read(hBs, pAacDecoderChannelInfo[ch]->data.usac.fac_data[0], + pAacDecoderChannelInfo[ch]->data.usac.fac_data_e, + CLpd_FAC_getLength( + IsLongBlock(&pAacDecoderChannelInfo[ch]->icsInfo), + pAacDecoderChannelInfo[ch]->granuleLength), + 1, 0); + } else { + if (pAacDecoderStaticChannelInfo[ch]->last_core_mode == LPD && + pAacDecoderStaticChannelInfo[ch]->last_lpd_mode == 0) { + /* ACELP to FD transitons without FAC are possible. That is why we + zero it out (i.e FAC will not be considered in the subsequent + calculations */ + FDKmemclear(pAacDecoderChannelInfo[ch]->data.usac.fac_data0, + LFAC * sizeof(FIXP_DBL)); + } + } + } break; + case esc2_rvlc: + if (flags & AC_ER_RVLC) { + CRvlc_Decode(pAacDecoderChannelInfo[ch], + pAacDecoderStaticChannelInfo[ch], hBs); + } + break; + + case esc1_hcr: + if (flags & AC_ER_HCR) { + CHcr_Read(hBs, pAacDecoderChannelInfo[ch], + numberOfChannels == 2 ? ID_CPE : ID_SCE); + } + break; + + case spectral_data: + error = CBlock_ReadSpectralData(hBs, pAacDecoderChannelInfo[ch], + pSamplingRateInfo, flags); + if (flags & AC_ELD) { + pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_ELDFB; + } else { + if (flags & AC_HDAAC) { + pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_INTIMDCT; + } else { + pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_IMDCT; + } + } + break; + + case ac_spectral_data: + error = CBlock_ReadAcSpectralData( + hBs, pAacDecoderChannelInfo[ch], pAacDecoderStaticChannelInfo[ch], + pSamplingRateInfo, frame_length, flags); pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_IMDCT; - } - break; - - - /* CRC handling */ - case adtscrc_start_reg1: - if (pTpDec != NULL) { - crcReg1 = transportDec_CrcStartReg(pTpDec, 192); - } - break; - case adtscrc_start_reg2: - if (pTpDec != NULL) { - crcReg2 = transportDec_CrcStartReg(pTpDec, 128); - } - break; - case adtscrc_end_reg1: - case drmcrc_end_reg: - if (pTpDec != NULL) { - transportDec_CrcEndReg(pTpDec, crcReg1); - } - break; - case adtscrc_end_reg2: - if (pTpDec != NULL) { - transportDec_CrcEndReg(pTpDec, crcReg2); - } - break; - case drmcrc_start_reg: - if (pTpDec != NULL) { - crcReg1 = transportDec_CrcStartReg(pTpDec, 0); - } - break; - - /* Non data cases */ - case next_channel: - ch = (ch + 1) % numberOfChannels; - break; - case link_sequence: - list = list->next[decision_bit]; - i=-1; - break; - - default: - error = AAC_DEC_UNSUPPORTED_FORMAT; - break; + break; + + case coupled_elements: { + int num_coupled_elements, c; + + ind_sw_cce_flag = FDKreadBit(hBs); + num_coupled_elements = FDKreadBits(hBs, 3); + + for (c = 0; c < (num_coupled_elements + 1); c++) { + int cc_target_is_cpe; + + num_gain_element_lists++; + cc_target_is_cpe = FDKreadBit(hBs); /* cc_target_is_cpe[c] */ + FDKreadBits(hBs, 4); /* cc_target_tag_select[c] */ + + if (cc_target_is_cpe) { + int cc_l, cc_r; + + cc_l = FDKreadBit(hBs); /* cc_l[c] */ + cc_r = FDKreadBit(hBs); /* cc_r[c] */ + + if (cc_l && cc_r) { + num_gain_element_lists++; + } + } + } + FDKreadBit(hBs); /* cc_domain */ + FDKreadBit(hBs); /* gain_element_sign */ + FDKreadBits(hBs, 2); /* gain_element_scale */ + } break; + + case gain_element_lists: { + const CodeBookDescription *hcb; + UCHAR *pCodeBook; + int c; + + hcb = &AACcodeBookDescriptionTable[BOOKSCL]; + pCodeBook = pAacDecoderChannelInfo[ch]->pDynData->aCodeBook; + + for (c = 1; c < num_gain_element_lists; c++) { + int cge; + if (ind_sw_cce_flag) { + cge = 1; + } else { + cge = FDKreadBits(hBs, 1); /* common_gain_element_present[c] */ + } + if (cge) { + /* Huffman */ + CBlock_DecodeHuffmanWord( + hBs, hcb); /* hcod_sf[common_gain_element[c]] 1..19 */ + } else { + int g, sfb; + for (g = 0; + g < GetWindowGroups(&pAacDecoderChannelInfo[ch]->icsInfo); + g++) { + for (sfb = 0; sfb < GetScaleFactorBandsTransmitted( + &pAacDecoderChannelInfo[ch]->icsInfo); + sfb++) { + if (pCodeBook[sfb] != ZERO_HCB) { + /* Huffman */ + CBlock_DecodeHuffmanWord( + hBs, + hcb); /* hcod_sf[dpcm_gain_element[c][g][sfb]] 1..19 */ + } + } + } + } + } + } break; + + /* CRC handling */ + case adtscrc_start_reg1: + if (pTpDec != NULL) { + crcReg1 = transportDec_CrcStartReg(pTpDec, 192); + } + break; + case adtscrc_start_reg2: + if (pTpDec != NULL) { + crcReg2 = transportDec_CrcStartReg(pTpDec, 128); + } + break; + case adtscrc_end_reg1: + case drmcrc_end_reg: + if (pTpDec != NULL) { + transportDec_CrcEndReg(pTpDec, crcReg1); + crcReg1 = -1; + } + break; + case adtscrc_end_reg2: + if (crcReg1 != -1) { + error = AAC_DEC_DECODE_FRAME_ERROR; + } else if (pTpDec != NULL) { + transportDec_CrcEndReg(pTpDec, crcReg2); + crcReg2 = -1; + } + break; + case drmcrc_start_reg: + if (pTpDec != NULL) { + crcReg1 = transportDec_CrcStartReg(pTpDec, 0); + } + break; + + /* Non data cases */ + case next_channel: + ch = (ch + 1) % numberOfChannels; + break; + case link_sequence: + list = list->next[decision_bit]; + i = -1; + break; + + default: + error = AAC_DEC_UNSUPPORTED_FORMAT; + break; } if (error != AAC_DEC_OK) { @@ -446,6 +881,40 @@ AAC_DECODER_ERROR CChannelElement_Read(HANDLE_FDK_BITSTREAM hBs, } while (list->id[i] != end_of_sequence); + for (ch = 0; ch < numberOfChannels; ch++) { + if (pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_IMDCT || + pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_ELDFB) { + /* Shows which bands are empty. */ + UCHAR *band_is_noise = + pAacDecoderChannelInfo[ch]->pDynData->band_is_noise; + FDKmemset(band_is_noise, (UCHAR)1, sizeof(UCHAR) * (8 * 16)); + + error = CBlock_InverseQuantizeSpectralData( + pAacDecoderChannelInfo[ch], pSamplingRateInfo, band_is_noise, 1); + if (error != AAC_DEC_OK) { + return error; + } + + if (elFlags & AC_EL_USAC_NOISE) { + CBlock_ApplyNoise(pAacDecoderChannelInfo[ch], pSamplingRateInfo, + &pAacDecoderStaticChannelInfo[ch]->nfRandomSeed, + band_is_noise); + + } /* if (elFlags & AC_EL_USAC_NOISE) */ + } + } + bail: + if (crcReg1 != -1 || crcReg2 != -1) { + if (error == AAC_DEC_OK) { + error = AAC_DEC_DECODE_FRAME_ERROR; + } + if (crcReg1 != -1) { + transportDec_CrcEndReg(pTpDec, crcReg1); + } + if (crcReg2 != -1) { + transportDec_CrcEndReg(pTpDec, crcReg2); + } + } return error; } -- cgit v1.2.3 From 9ab67882eca7454dc001e158bc1e6e2219d6650b Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 4 May 2018 15:51:23 +0200 Subject: FDKv2 additional fixes Bug: 71430241 Bug: 79220129 Test: cts-tradefed run commandAndExit cts-dev -m CtsMediaTestCases -t android.media.cts.DecoderTestXheAac cts-tradefed run commandAndExit cts-dev -m CtsMediaTestCases -t android.media.cts.DecoderTestAacDrc Add restriction to call intensity stereo tool only for applicable configurations Change-Id: I30ec6640bd484c56cc9d5b8b35186fc1c875e021 Fix high band energy calculation in sbr encoder Change-Id: I964dd46fab2ed797c440a983512bbab7e1aff98a Fix out-of-bounds read access in noiseless coder Change-Id: I9a669435dbdca421ff9e4affec57811002d75b3b Use temporary buffer for dummy parsing to check presence of audioPreroll data Change-Id: I2d42c5c8deddde34351c3d2858b9fe196b3a0906 Set applyAsc to 1 in case that the ASC parsing fails Change-Id: I552a8b960270bc18cae459ad28a3ba241035668e Parametric stereo together with mps not supported Change-Id: Icde14a2774a4303bb0c41046861a59d04b624365 Align ssc callback error path for drm Change-Id: Ie8ecbfa42c702e6df81c1aec532a9ff1e653dac9 Ensure that the bit counter starts at a multiple of TPDEC_SYNCSKIP Change-Id: I08d69ec361b2e2ed800282e333fd248b4b3ca245 Allow flushing only when audioPreroll is enabled in current and new config Change-Id: I52e95d75de4bbed692be922a59a23bda58870625 Omit reverse channel mapping in pass through mode Change-Id: I335e209c29a700cc091be069f1d08e4288b40793 --- libAACdec/src/aacdecoder_lib.cpp | 11 ++++++----- libAACdec/src/channel.cpp | 21 ++++++++++++--------- libAACdec/src/channelinfo.h | 4 +--- libAACdec/src/stereo.cpp | 5 ++--- libMpegTPDec/src/tpdec_asc.cpp | 2 +- libMpegTPDec/src/tpdec_latm.cpp | 10 +++++++--- libMpegTPDec/src/tpdec_lib.cpp | 6 ++++++ libSACdec/src/sac_dec_lib.cpp | 15 +++++++++++---- libSACenc/src/sacenc_nlc_enc.cpp | 10 ++++++++-- libSBRenc/src/tran_det.cpp | 2 +- 10 files changed, 55 insertions(+), 31 deletions(-) (limited to 'libAACdec/src/channel.cpp') diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp index b7ea8df..e62d187 100644 --- a/libAACdec/src/aacdecoder_lib.cpp +++ b/libAACdec/src/aacdecoder_lib.cpp @@ -396,7 +396,8 @@ static INT aacDecoder_SscCallback(void *handle, HANDLE_FDK_BITSTREAM hBs, /* MPS found but invalid or not decodable by this instance */ hAacDecoder->mpsEnableCurr = 0; hAacDecoder->mpsApplicable = 0; - if ((coreCodec == AOT_USAC) || IS_LOWDELAY(coreCodec)) { + if ((coreCodec == AOT_USAC) || (coreCodec == AOT_DRM_USAC) || + IS_LOWDELAY(coreCodec)) { errTp = TRANSPORTDEC_PARSE_ERROR; } else { errTp = TRANSPORTDEC_OK; @@ -1654,14 +1655,14 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern, self->streamInfo.frameSize; for (ch = 0; ch < self->streamInfo.numChannels; ch++) { - int mapValue = FDK_chMapDescr_getMapValue( + UCHAR mapValue = FDK_chMapDescr_getMapValue( &self->mapDescr, (UCHAR)ch, self->chMapIndex); - reverseInChannelMap[mapValue] = ch; + if (mapValue < (8)) reverseInChannelMap[mapValue] = ch; } for (ch = 0; ch < (int)numDrcOutChannels; ch++) { - int mapValue = FDK_chMapDescr_getMapValue( + UCHAR mapValue = FDK_chMapDescr_getMapValue( &self->mapDescr, (UCHAR)ch, numDrcOutChannels); - reverseOutChannelMap[mapValue] = ch; + if (mapValue < (8)) reverseOutChannelMap[mapValue] = ch; } /* The output of SBR and MPS is interleaved. Deinterleaving may be diff --git a/libAACdec/src/channel.cpp b/libAACdec/src/channel.cpp index dbbf58a..cfffd57 100644 --- a/libAACdec/src/channel.cpp +++ b/libAACdec/src/channel.cpp @@ -225,15 +225,18 @@ void CChannelElement_Decode( /* apply intensity stereo */ /* modifies pAacDecoderChannelInfo[]->aSpecSfb */ if (!(flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA))) { - CJointStereo_ApplyIS( - pAacDecoderChannelInfo, - GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, - pSamplingRateInfo), - GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), - GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), - GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[L]->icsInfo), - pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow ? 1 - : 0); + if ((pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow == + 1) && + (el_channels == 2)) { + CJointStereo_ApplyIS( + pAacDecoderChannelInfo, + GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, + pSamplingRateInfo), + GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), + GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), + GetScaleFactorBandsTransmitted( + &pAacDecoderChannelInfo[L]->icsInfo)); + } } } /* maybe_stereo */ diff --git a/libAACdec/src/channelinfo.h b/libAACdec/src/channelinfo.h index 7c95e12..45a288f 100644 --- a/libAACdec/src/channelinfo.h +++ b/libAACdec/src/channelinfo.h @@ -478,15 +478,13 @@ void CJointStereo_ApplyMS( \param pWindowGroupLength pointer to window group length array. \param windowGroups number of window groups. \param scaleFactorBandsTransmitted number of transmitted scalefactor bands. - \param CommonWindow common window bit. \return none */ void CJointStereo_ApplyIS(CAacDecoderChannelInfo *pAacDecoderChannelInfo[2], const short *pScaleFactorBandOffsets, const UCHAR *pWindowGroupLength, const int windowGroups, - const int scaleFactorBandsTransmitted, - const UINT CommonWindow); + const int scaleFactorBandsTransmitted); /* aacdec_pns.cpp */ int CPns_IsPnsUsed(const CPnsData *pPnsData, const int group, const int band); diff --git a/libAACdec/src/stereo.cpp b/libAACdec/src/stereo.cpp index bb4f050..eed826b 100644 --- a/libAACdec/src/stereo.cpp +++ b/libAACdec/src/stereo.cpp @@ -1177,8 +1177,7 @@ void CJointStereo_ApplyIS(CAacDecoderChannelInfo *pAacDecoderChannelInfo[2], const SHORT *pScaleFactorBandOffsets, const UCHAR *pWindowGroupLength, const int windowGroups, - const int scaleFactorBandsTransmitted, - const UINT CommonWindow) { + const int scaleFactorBandsTransmitted) { CJointStereoData *pJointStereoData = &pAacDecoderChannelInfo[L]->pComData->jointStereoData; @@ -1228,7 +1227,7 @@ void CJointStereo_ApplyIS(CAacDecoderChannelInfo *pAacDecoderChannelInfo[2], rightScale[band] = leftScale[band] + msb + 1; - if (CommonWindow && (pJointStereoData->MsUsed[band] & groupMask)) { + if (pJointStereoData->MsUsed[band] & groupMask) { if (CodeBook[band] == INTENSITY_HCB) /* _NOT_ in-phase */ { scale = -scale; diff --git a/libMpegTPDec/src/tpdec_asc.cpp b/libMpegTPDec/src/tpdec_asc.cpp index abe66e5..74beaa6 100644 --- a/libMpegTPDec/src/tpdec_asc.cpp +++ b/libMpegTPDec/src/tpdec_asc.cpp @@ -2488,7 +2488,7 @@ TRANSPORTDEC_ERROR DrmRawSdcAudioConfig_Parse( switch (audioCoding) { case 0: /* AAC */ - if (coderField >> 2) { + if ((coderField >> 2) && (audioMode != 1)) { self->m_aot = AOT_DRM_SURROUND; /* Set pseudo AOT for Drm Surround */ } else { self->m_aot = AOT_DRM_AAC; /* Set pseudo AOT for Drm AAC */ diff --git a/libMpegTPDec/src/tpdec_latm.cpp b/libMpegTPDec/src/tpdec_latm.cpp index b4f7372..2edf055 100644 --- a/libMpegTPDec/src/tpdec_latm.cpp +++ b/libMpegTPDec/src/tpdec_latm.cpp @@ -126,7 +126,6 @@ static TRANSPORTDEC_ERROR CLatmDemux_ReadAudioMuxElement( CSTpCallBacks *pTpDecCallbacks, CSAudioSpecificConfig *pAsc, int *pfConfigFound) { TRANSPORTDEC_ERROR ErrorStatus = TRANSPORTDEC_OK; - UCHAR applyAsc = pLatmDemux->applyAsc; if (m_muxConfigPresent) { pLatmDemux->m_useSameStreamMux = FDKreadBits(bs, 1); @@ -152,7 +151,12 @@ static TRANSPORTDEC_ERROR CLatmDemux_ReadAudioMuxElement( goto bail; } - if (pLatmDemux->newCfgHasAudioPreRoll) { + /* Allow flushing only when audioPreroll functionality is enabled in + * current and new config otherwise the new config can be applied + * immediately. */ + if (pAsc->m_sc.m_usacConfig.element[0] + .extElement.usacExtElementHasAudioPreRoll && + pLatmDemux->newCfgHasAudioPreRoll) { pLatmDemux->newCfgHasAudioPreRoll = 0; /* with audioPreRoll we must flush before applying new cfg */ pLatmDemux->applyAsc = 0; @@ -223,7 +227,7 @@ static TRANSPORTDEC_ERROR CLatmDemux_ReadAudioMuxElement( bail: if (ErrorStatus != TRANSPORTDEC_OK) { - pLatmDemux->applyAsc = applyAsc; + pLatmDemux->applyAsc = 1; } return (ErrorStatus); diff --git a/libMpegTPDec/src/tpdec_lib.cpp b/libMpegTPDec/src/tpdec_lib.cpp index 10e3352..306bec0 100644 --- a/libMpegTPDec/src/tpdec_lib.cpp +++ b/libMpegTPDec/src/tpdec_lib.cpp @@ -1151,6 +1151,12 @@ static TRANSPORTDEC_ERROR synchronization(HANDLE_TRANSPORTDEC hTp, &syncLayerFrameBits, &fConfigFound, &headerBits); if (TPDEC_IS_FATAL_ERROR(err)) { + /* Rewind - TPDEC_SYNCSKIP, in order to look for a synch one bit ahead + * next time. Ensure that the bit amount lands at a multiple of + * TPDEC_SYNCSKIP. */ + FDKpushBiDirectional( + hBs, -headerBits + TPDEC_SYNCSKIP + (bitsAvail % TPDEC_SYNCSKIP)); + goto bail; } } diff --git a/libSACdec/src/sac_dec_lib.cpp b/libSACdec/src/sac_dec_lib.cpp index 56d8693..ebf9bee 100644 --- a/libSACdec/src/sac_dec_lib.cpp +++ b/libSACdec/src/sac_dec_lib.cpp @@ -698,6 +698,7 @@ SACDEC_ERROR mpegSurroundDecoder_Config( INT coreSbrFrameLengthIndex, INT configBytes, const UCHAR configMode, UCHAR *configChanged) { SACDEC_ERROR err = MPS_OK; + SPATIAL_SPECIFIC_CONFIG spatialSpecificConfig; switch (coreCodec) { case AOT_DRM_USAC: @@ -705,7 +706,6 @@ SACDEC_ERROR mpegSurroundDecoder_Config( if (configMode == AC_CM_DET_CFG_CHANGE) { /* In config detection mode write spatial specific config parameters * into temporarily allocated structure */ - SPATIAL_SPECIFIC_CONFIG spatialSpecificConfig; err = SpatialDecParseMps212Config( hBs, &spatialSpecificConfig, samplingRate, coreCodec, stereoConfigIndex, coreSbrFrameLengthIndex); @@ -718,9 +718,16 @@ SACDEC_ERROR mpegSurroundDecoder_Config( break; case AOT_ER_AAC_ELD: case AOT_ER_AAC_LD: - err = SpatialDecParseSpecificConfig( - hBs, &pMpegSurroundDecoder->spatialSpecificConfigBackup, configBytes, - coreCodec); + if (configMode == AC_CM_DET_CFG_CHANGE) { + /* In config detection mode write spatial specific config parameters + * into temporarily allocated structure */ + err = SpatialDecParseSpecificConfig(hBs, &spatialSpecificConfig, + configBytes, coreCodec); + } else { + err = SpatialDecParseSpecificConfig( + hBs, &pMpegSurroundDecoder->spatialSpecificConfigBackup, + configBytes, coreCodec); + } break; default: err = MPS_UNSUPPORTED_FORMAT; diff --git a/libSACenc/src/sacenc_nlc_enc.cpp b/libSACenc/src/sacenc_nlc_enc.cpp index ecb89b7..0ba6cc9 100644 --- a/libSACenc/src/sacenc_nlc_enc.cpp +++ b/libSACenc/src/sacenc_nlc_enc.cpp @@ -379,16 +379,22 @@ static UINT huff_enc_1D(HANDLE_FDK_BITSTREAM strm, const DATA_TYPE data_type, switch (data_type) { case t_CLD: - part0 = fdk_sacenc_huffPart0Tab.cld[in_data[0]]; pHuffTab = fdk_sacenc_huffCLDTab.h1D[dim1]; break; case t_ICC: - part0 = fdk_sacenc_huffPart0Tab.icc[in_data[0]]; pHuffTab = fdk_sacenc_huffICCTab.h1D[dim1]; break; } if (p0_flag) { + switch (data_type) { + case t_CLD: + part0 = fdk_sacenc_huffPart0Tab.cld[in_data[0]]; + break; + case t_ICC: + part0 = fdk_sacenc_huffPart0Tab.icc[in_data[0]]; + break; + } huffBits += FDKwriteBits(strm, HUFF_VALUE(part0), HUFF_LENGTH(part0)); offset = 1; } diff --git a/libSBRenc/src/tran_det.cpp b/libSBRenc/src/tran_det.cpp index ba9ae68..b6f1b9f 100644 --- a/libSBRenc/src/tran_det.cpp +++ b/libSBRenc/src/tran_det.cpp @@ -366,7 +366,7 @@ static FIXP_DBL addHighbandEnergies( accu += (EnergiesM[slotOut][j] >> scale[0]); } } - nrgTotal = accu >> (scaleEnergies[1] - scale[1]); + nrgTotal = fAddSaturate(nrgTotal, accu >> (scaleEnergies[1] - scale[1])); } return (nrgTotal); -- cgit v1.2.3