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 --- libSACenc/src/sacenc_nlc_enc.cpp | 1436 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 1436 insertions(+) create mode 100644 libSACenc/src/sacenc_nlc_enc.cpp (limited to 'libSACenc/src/sacenc_nlc_enc.cpp') diff --git a/libSACenc/src/sacenc_nlc_enc.cpp b/libSACenc/src/sacenc_nlc_enc.cpp new file mode 100644 index 0000000..ecb89b7 --- /dev/null +++ b/libSACenc/src/sacenc_nlc_enc.cpp @@ -0,0 +1,1436 @@ +/* ----------------------------------------------------------------------------- +Software License for The Fraunhofer FDK AAC Codec Library for Android + +© 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. + +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: + +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 +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. + +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." + +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. + +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. + +5. CONTACT INFORMATION + +Fraunhofer Institute for Integrated Circuits IIS +Attention: Audio and Multimedia Departments - FDK AAC LL +Am Wolfsmantel 33 +91058 Erlangen, Germany + +www.iis.fraunhofer.de/amm +amm-info@iis.fraunhofer.de +----------------------------------------------------------------------------- */ + +/*********************** MPEG surround encoder library ************************* + + Author(s): Karsten Linzmeier + + Description: Noiseless Coding + Huffman encoder + +*******************************************************************************/ + +/* Includes ******************************************************************/ +#include "sacenc_nlc_enc.h" + +#include "genericStds.h" +#include "fixpoint_math.h" + +#include "sacenc_const.h" +#include "sacenc_huff_tab.h" +#include "sacenc_paramextract.h" + +/* Defines *******************************************************************/ +#define PAIR_SHIFT 4 +#define PAIR_MASK 0xf + +#define PBC_MIN_BANDS 5 + +typedef enum { + BACKWARDS = 0x0, + FORWARDS = 0x1 + +} DIRECTION; + +typedef enum { + DIFF_FREQ = 0x0, + DIFF_TIME = 0x1 + +} DIFF_TYPE; + +typedef enum { + HUFF_1D = 0x0, + HUFF_2D = 0x1 + +} CODING_SCHEME; + +typedef enum { + FREQ_PAIR = 0x0, + TIME_PAIR = 0x1 + +} PAIRING; + +/* Data Types ****************************************************************/ + +/* Constants *****************************************************************/ +static const UCHAR lavHuffVal[4] = {0, 2, 6, 7}; +static const UCHAR lavHuffLen[4] = {1, 2, 3, 3}; + +static const UCHAR lav_step_CLD[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3}; +static const UCHAR lav_step_ICC[] = {0, 0, 1, 1, 2, 2, 3, 3}; + +/* Function / Class Declarations *********************************************/ + +/* Function / Class Definition ***********************************************/ +static void split_lsb(const SHORT *const in_data, SHORT offset, + const INT num_val, SHORT *const out_data_lsb, + SHORT *const out_data_msb) { + int i; + + for (i = 0; i < num_val; i++) { + SHORT val = in_data[i] + offset; + if (out_data_lsb != NULL) out_data_lsb[i] = val & 0x0001; + if (out_data_msb != NULL) out_data_msb[i] = val >> 1; + } +} + +static void apply_lsb_coding(HANDLE_FDK_BITSTREAM strm, + const SHORT *const in_data_lsb, const UINT num_lsb, + const INT num_val) { + int i; + + for (i = 0; i < num_val; i++) { + FDKwriteBits(strm, in_data_lsb[i], num_lsb); + } +} + +static void calc_diff_freq(const SHORT *const in_data, SHORT *const out_data, + const INT num_val) { + int i; + out_data[0] = in_data[0]; + + for (i = 1; i < num_val; i++) { + out_data[i] = in_data[i] - in_data[i - 1]; + } +} + +static void calc_diff_time(const SHORT *const in_data, + const SHORT *const prev_data, SHORT *const out_data, + const INT num_val) { + int i; + out_data[0] = in_data[0]; + out_data[1] = prev_data[0]; + + for (i = 0; i < num_val; i++) { + out_data[i + 2] = in_data[i] - prev_data[i]; + } +} + +static INT sym_check(SHORT data[2], const INT lav, SHORT *const pSym_bits) { + UCHAR symBits = 0; + int sum_val = data[0] + data[1]; + int diff_val = data[0] - data[1]; + int num_sbits = 0; + + if (sum_val != 0) { + int sum_neg = (sum_val < 0) ? 1 : 0; + if (sum_neg) { + sum_val = -sum_val; + diff_val = -diff_val; + } + symBits = (symBits << 1) | sum_neg; + num_sbits++; + } + + if (diff_val != 0) { + int diff_neg = (diff_val < 0) ? 1 : 0; + if (diff_neg) { + diff_val = -diff_val; + } + symBits = (symBits << 1) | diff_neg; + num_sbits++; + } + + if (pSym_bits != NULL) { + *pSym_bits = symBits; + } + + if (sum_val % 2) { + data[0] = lav - sum_val / 2; + data[1] = lav - diff_val / 2; + } else { + data[0] = sum_val / 2; + data[1] = diff_val / 2; + } + + return num_sbits; +} + +static INT ilog2(UINT i) { + int l = 0; + + if (i) i--; + while (i > 0) { + i >>= 1; + l++; + } + + return l; +} + +static SHORT calc_pcm_bits(const SHORT num_val, const SHORT num_levels) { + SHORT num_complete_chunks = 0, rest_chunk_size = 0; + SHORT max_grp_len = 0, bits_pcm = 0; + int chunk_levels, i; + + switch (num_levels) { + case 3: + max_grp_len = 5; + break; + case 6: + max_grp_len = 5; + break; + case 7: + max_grp_len = 6; + break; + case 11: + max_grp_len = 2; + break; + case 13: + max_grp_len = 4; + break; + case 19: + max_grp_len = 4; + break; + case 25: + max_grp_len = 3; + break; + case 51: + max_grp_len = 4; + break; + default: + max_grp_len = 1; + } + + num_complete_chunks = num_val / max_grp_len; + rest_chunk_size = num_val % max_grp_len; + + chunk_levels = 1; + for (i = 1; i <= max_grp_len; i++) { + chunk_levels *= num_levels; + } + + bits_pcm = (SHORT)(ilog2(chunk_levels) * num_complete_chunks); + bits_pcm += (SHORT)(ilog2(num_levels) * rest_chunk_size); + + return bits_pcm; +} + +static void apply_pcm_coding(HANDLE_FDK_BITSTREAM strm, + const SHORT *const in_data_1, + const SHORT *const in_data_2, const SHORT offset, + const SHORT num_val, const SHORT num_levels) { + SHORT i = 0, j = 0, idx = 0; + SHORT max_grp_len = 0, grp_len = 0, next_val = 0; + int grp_val = 0, chunk_levels = 0; + + SHORT pcm_chunk_size[7] = {0}; + + switch (num_levels) { + case 3: + max_grp_len = 5; + break; + case 5: + max_grp_len = 3; + break; + case 6: + max_grp_len = 5; + break; + case 7: + max_grp_len = 6; + break; + case 9: + max_grp_len = 5; + break; + case 11: + max_grp_len = 2; + break; + case 13: + max_grp_len = 4; + break; + case 19: + max_grp_len = 4; + break; + case 25: + max_grp_len = 3; + break; + case 51: + max_grp_len = 4; + break; + default: + max_grp_len = 1; + } + + chunk_levels = 1; + for (i = 1; i <= max_grp_len; i++) { + chunk_levels *= num_levels; + pcm_chunk_size[i] = ilog2(chunk_levels); + } + + for (i = 0; i < num_val; i += max_grp_len) { + grp_len = FDKmin(max_grp_len, num_val - i); + grp_val = 0; + for (j = 0; j < grp_len; j++) { + idx = i + j; + if (in_data_2 == NULL) { + next_val = in_data_1[idx]; + } else if (in_data_1 == NULL) { + next_val = in_data_2[idx]; + } else { + next_val = ((idx % 2) ? in_data_2[idx / 2] : in_data_1[idx / 2]); + } + next_val += offset; + grp_val = grp_val * num_levels + next_val; + } + + FDKwriteBits(strm, grp_val, pcm_chunk_size[grp_len]); + } +} + +static UINT huff_enc_1D(HANDLE_FDK_BITSTREAM strm, const DATA_TYPE data_type, + const INT dim1, SHORT *const in_data, + const SHORT num_val, const SHORT p0_flag) { + int i, offset = 0; + UINT huffBits = 0; + + HUFF_ENTRY part0 = {0}; + const HUFF_ENTRY *pHuffTab = NULL; + + 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) { + huffBits += FDKwriteBits(strm, HUFF_VALUE(part0), HUFF_LENGTH(part0)); + offset = 1; + } + + for (i = offset; i < num_val; i++) { + int id_sign = 0; + int id = in_data[i]; + + if (id != 0) { + id_sign = 0; + if (id < 0) { + id = -id; + id_sign = 1; + } + } + + huffBits += + FDKwriteBits(strm, HUFF_VALUE(pHuffTab[id]), HUFF_LENGTH(pHuffTab[id])); + + if (id != 0) { + huffBits += FDKwriteBits(strm, id_sign, 1); + } + } /* for i */ + + return huffBits; +} + +static void getHuffEntry(const INT lav, const DATA_TYPE data_type, const INT i, + const SHORT tab_idx_2D[2], const SHORT in_data[][2], + HUFF_ENTRY *const pEntry, HUFF_ENTRY *const pEscape) { + const HUFF_CLD_TAB_2D *pCLD2dTab = + &fdk_sacenc_huffCLDTab.h2D[tab_idx_2D[0]][tab_idx_2D[1]]; + const HUFF_ICC_TAB_2D *pICC2dTab = + &fdk_sacenc_huffICCTab.h2D[tab_idx_2D[0]][tab_idx_2D[1]]; + + switch (lav) { + case 1: { + const LAV1_2D *pLav1 = NULL; + switch (data_type) { + case t_CLD: + pLav1 = NULL; + break; + case t_ICC: + pLav1 = &pICC2dTab->lav1; + break; + } + if (pLav1 != NULL) { + *pEntry = pLav1->entry[in_data[i][0]][in_data[i][1]]; + *pEscape = pLav1->escape; + } + } break; + case 3: { + const LAV3_2D *pLav3 = NULL; + switch (data_type) { + case t_CLD: + pLav3 = &pCLD2dTab->lav3; + break; + case t_ICC: + pLav3 = &pICC2dTab->lav3; + break; + } + if (pLav3 != NULL) { + *pEntry = pLav3->entry[in_data[i][0]][in_data[i][1]]; + *pEscape = pLav3->escape; + } + } break; + case 5: { + const LAV5_2D *pLav5 = NULL; + switch (data_type) { + case t_CLD: + pLav5 = &pCLD2dTab->lav5; + break; + case t_ICC: + pLav5 = &pICC2dTab->lav5; + break; + } + if (pLav5 != NULL) { + *pEntry = pLav5->entry[in_data[i][0]][in_data[i][1]]; + *pEscape = pLav5->escape; + } + } break; + case 7: { + const LAV7_2D *pLav7 = NULL; + switch (data_type) { + case t_CLD: + pLav7 = &pCLD2dTab->lav7; + break; + case t_ICC: + pLav7 = &pICC2dTab->lav7; + break; + } + if (pLav7 != NULL) { + *pEntry = pLav7->entry[in_data[i][0]][in_data[i][1]]; + *pEscape = pLav7->escape; + } + } break; + case 9: { + const LAV9_2D *pLav9 = NULL; + switch (data_type) { + case t_CLD: + pLav9 = &pCLD2dTab->lav9; + break; + case t_ICC: + pLav9 = NULL; + break; + } + if (pLav9 != NULL) { + *pEntry = pLav9->entry[in_data[i][0]][in_data[i][1]]; + *pEscape = pLav9->escape; + } + } break; + } +} + +static UINT huff_enc_2D(HANDLE_FDK_BITSTREAM strm, const DATA_TYPE data_type, + SHORT tab_idx_2D[2], SHORT lav_idx, SHORT in_data[][2], + SHORT num_val, SHORT stride, SHORT *p0_data[2]) { + SHORT i = 0, lav = 0, num_sbits = 0, sym_bits = 0, escIdx = 0; + SHORT esc_data[2][MAXBANDS] = {{0}}; + + UINT huffBits = 0; + + const HUFF_ENTRY *pHuffEntry = NULL; + + switch (data_type) { + case t_CLD: + lav = 2 * lav_idx + 3; /* LAV */ + pHuffEntry = fdk_sacenc_huffPart0Tab.cld; + break; + case t_ICC: + lav = 2 * lav_idx + 1; /* LAV */ + pHuffEntry = fdk_sacenc_huffPart0Tab.icc; + break; + } + + /* Partition 0 */ + if (p0_data[0] != NULL) { + HUFF_ENTRY entry = pHuffEntry[*p0_data[0]]; + huffBits += FDKwriteBits(strm, HUFF_VALUE(entry), HUFF_LENGTH(entry)); + } + if (p0_data[1] != NULL) { + HUFF_ENTRY entry = pHuffEntry[*p0_data[1]]; + huffBits += FDKwriteBits(strm, HUFF_VALUE(entry), HUFF_LENGTH(entry)); + } + + for (i = 0; i < num_val; i += stride) { + HUFF_ENTRY entry = {0}; + HUFF_ENTRY escape = {0}; + + esc_data[0][escIdx] = in_data[i][0] + lav; + esc_data[1][escIdx] = in_data[i][1] + lav; + + num_sbits = sym_check(in_data[i], lav, &sym_bits); + + getHuffEntry(lav, data_type, i, tab_idx_2D, in_data, &entry, &escape); + + huffBits += FDKwriteBits(strm, HUFF_VALUE(entry), HUFF_LENGTH(entry)); + + if ((HUFF_VALUE(entry) == HUFF_VALUE(escape)) && + (HUFF_LENGTH(entry) == HUFF_LENGTH(escape))) { + escIdx++; + } else { + huffBits += FDKwriteBits(strm, sym_bits, num_sbits); + } + } /* for i */ + + if (escIdx > 0) { + huffBits += calc_pcm_bits(2 * escIdx, (2 * lav + 1)); + if (strm != NULL) { + apply_pcm_coding(strm, esc_data[0], esc_data[1], 0 /*offset*/, 2 * escIdx, + (2 * lav + 1)); + } + } + + return huffBits; +} + +static SCHAR get_next_lav_step(const INT lav, const DATA_TYPE data_type) { + SCHAR lav_step = 0; + + switch (data_type) { + case t_CLD: + lav_step = (lav > 9) ? -1 : lav_step_CLD[lav]; + break; + case t_ICC: + lav_step = (lav > 7) ? -1 : lav_step_ICC[lav]; + break; + } + + return lav_step; +} + +static INT diff_type_offset(const DIFF_TYPE diff_type) { + int offset = 0; + switch (diff_type) { + case DIFF_FREQ: + offset = 0; + break; + case DIFF_TIME: + offset = 2; + break; + } + return offset; +} + +static SHORT calc_huff_bits(SHORT *in_data_1, SHORT *in_data_2, + const DATA_TYPE data_type, + const DIFF_TYPE diff_type_1, + const DIFF_TYPE diff_type_2, const SHORT num_val, + SHORT *const lav_idx, SHORT *const cdg_scheme) { + SHORT tab_idx_2D[2][2] = {{0}}; + SHORT tab_idx_1D[2] = {0}; + SHORT df_rest_flag[2] = {0}; + SHORT p0_flag[2] = {0}; + + SHORT pair_vec[MAXBANDS][2] = {{0}}; + + SHORT *p0_data_1[2] = {NULL}; + SHORT *p0_data_2[2] = {NULL}; + + SHORT i = 0; + SHORT lav_fp[2] = {0}; + + SHORT bit_count_1D = 0; + SHORT bit_count_2D_freq = 0; + SHORT bit_count_min = 0; + + SHORT num_val_1_short = 0; + SHORT num_val_2_short = 0; + + SHORT *in_data_1_short = NULL; + SHORT *in_data_2_short = NULL; + + /* 1D Huffman coding */ + bit_count_1D = 1; /* HUFF_1D */ + + num_val_1_short = num_val; + num_val_2_short = num_val; + + if (in_data_1 != NULL) { + in_data_1_short = in_data_1 + diff_type_offset(diff_type_1); + } + if (in_data_2 != NULL) { + in_data_2_short = in_data_2 + diff_type_offset(diff_type_2); + } + + p0_flag[0] = (diff_type_1 == DIFF_FREQ); + p0_flag[1] = (diff_type_2 == DIFF_FREQ); + + tab_idx_1D[0] = (diff_type_1 == DIFF_FREQ) ? 0 : 1; + tab_idx_1D[1] = (diff_type_2 == DIFF_FREQ) ? 0 : 1; + + if (in_data_1 != NULL) { + bit_count_1D += huff_enc_1D(NULL, data_type, tab_idx_1D[0], in_data_1_short, + num_val_1_short, p0_flag[0]); + } + if (in_data_2 != NULL) { + bit_count_1D += huff_enc_1D(NULL, data_type, tab_idx_1D[1], in_data_2_short, + num_val_2_short, p0_flag[1]); + } + + bit_count_min = bit_count_1D; + *cdg_scheme = HUFF_1D << PAIR_SHIFT; + lav_idx[0] = lav_idx[1] = -1; + + /* Huffman 2D frequency pairs */ + bit_count_2D_freq = 1; /* HUFF_2D */ + + num_val_1_short = num_val; + num_val_2_short = num_val; + + if (in_data_1 != NULL) { + in_data_1_short = in_data_1 + diff_type_offset(diff_type_1); + } + if (in_data_2 != NULL) { + in_data_2_short = in_data_2 + diff_type_offset(diff_type_2); + } + + lav_fp[0] = lav_fp[1] = 0; + + p0_data_1[0] = NULL; + p0_data_1[1] = NULL; + p0_data_2[0] = NULL; + p0_data_2[1] = NULL; + + if (in_data_1 != NULL) { + if (diff_type_1 == DIFF_FREQ) { + p0_data_1[0] = &in_data_1[0]; + p0_data_1[1] = NULL; + + num_val_1_short -= 1; + in_data_1_short += 1; + } + + df_rest_flag[0] = num_val_1_short % 2; + + if (df_rest_flag[0]) num_val_1_short -= 1; + + for (i = 0; i < num_val_1_short - 1; i += 2) { + pair_vec[i][0] = in_data_1_short[i]; + pair_vec[i][1] = in_data_1_short[i + 1]; + + lav_fp[0] = FDKmax(lav_fp[0], fAbs(pair_vec[i][0])); + lav_fp[0] = FDKmax(lav_fp[0], fAbs(pair_vec[i][1])); + } + + tab_idx_2D[0][0] = (diff_type_1 == DIFF_TIME) ? 1 : 0; + tab_idx_2D[0][1] = 0; + + tab_idx_1D[0] = (diff_type_1 == DIFF_FREQ) ? 0 : 1; + + lav_fp[0] = get_next_lav_step(lav_fp[0], data_type); + + if (lav_fp[0] != -1) bit_count_2D_freq += lavHuffLen[lav_fp[0]]; + } + + if (in_data_2 != NULL) { + if (diff_type_2 == DIFF_FREQ) { + p0_data_2[0] = NULL; + p0_data_2[1] = &in_data_2[0]; + + num_val_2_short -= 1; + in_data_2_short += 1; + } + + df_rest_flag[1] = num_val_2_short % 2; + + if (df_rest_flag[1]) num_val_2_short -= 1; + + for (i = 0; i < num_val_2_short - 1; i += 2) { + pair_vec[i + 1][0] = in_data_2_short[i]; + pair_vec[i + 1][1] = in_data_2_short[i + 1]; + + lav_fp[1] = FDKmax(lav_fp[1], fAbs(pair_vec[i + 1][0])); + lav_fp[1] = FDKmax(lav_fp[1], fAbs(pair_vec[i + 1][1])); + } + + tab_idx_2D[1][0] = (diff_type_2 == DIFF_TIME) ? 1 : 0; + tab_idx_2D[1][1] = 0; + + tab_idx_1D[1] = (diff_type_2 == DIFF_FREQ) ? 0 : 1; + + lav_fp[1] = get_next_lav_step(lav_fp[1], data_type); + + if (lav_fp[1] != -1) bit_count_2D_freq += lavHuffLen[lav_fp[1]]; + } + + if ((lav_fp[0] != -1) && (lav_fp[1] != -1)) { + if (in_data_1 != NULL) { + bit_count_2D_freq += + huff_enc_2D(NULL, data_type, tab_idx_2D[0], lav_fp[0], pair_vec, + num_val_1_short, 2, p0_data_1); + } + if (in_data_2 != NULL) { + bit_count_2D_freq += + huff_enc_2D(NULL, data_type, tab_idx_2D[1], lav_fp[1], pair_vec + 1, + num_val_2_short, 2, p0_data_2); + } + if (in_data_1 != NULL) { + if (df_rest_flag[0]) + bit_count_2D_freq += + huff_enc_1D(NULL, data_type, tab_idx_1D[0], + in_data_1_short + num_val_1_short, 1, 0); + } + if (in_data_2 != NULL) { + if (df_rest_flag[1]) + bit_count_2D_freq += + huff_enc_1D(NULL, data_type, tab_idx_1D[1], + in_data_2_short + num_val_2_short, 1, 0); + } + + if (bit_count_2D_freq < bit_count_min) { + bit_count_min = bit_count_2D_freq; + *cdg_scheme = HUFF_2D << PAIR_SHIFT | FREQ_PAIR; + lav_idx[0] = lav_fp[0]; + lav_idx[1] = lav_fp[1]; + } + } + + return bit_count_min; +} + +static void apply_huff_coding(HANDLE_FDK_BITSTREAM strm, SHORT *const in_data_1, + SHORT *const in_data_2, const DATA_TYPE data_type, + const DIFF_TYPE diff_type_1, + const DIFF_TYPE diff_type_2, const SHORT num_val, + const SHORT *const lav_idx, + const SHORT cdg_scheme) { + SHORT tab_idx_2D[2][2] = {{0}}; + SHORT tab_idx_1D[2] = {0}; + SHORT df_rest_flag[2] = {0}; + SHORT p0_flag[2] = {0}; + + SHORT pair_vec[MAXBANDS][2] = {{0}}; + + SHORT *p0_data_1[2] = {NULL}; + SHORT *p0_data_2[2] = {NULL}; + + SHORT i = 0; + + SHORT num_val_1_short = num_val; + SHORT num_val_2_short = num_val; + + SHORT *in_data_1_short = NULL; + SHORT *in_data_2_short = NULL; + + /* Offset */ + if (in_data_1 != NULL) { + in_data_1_short = in_data_1 + diff_type_offset(diff_type_1); + } + if (in_data_2 != NULL) { + in_data_2_short = in_data_2 + diff_type_offset(diff_type_2); + } + + /* Signalize coding scheme */ + FDKwriteBits(strm, cdg_scheme >> PAIR_SHIFT, 1); + + switch (cdg_scheme >> PAIR_SHIFT) { + case HUFF_1D: + + p0_flag[0] = (diff_type_1 == DIFF_FREQ); + p0_flag[1] = (diff_type_2 == DIFF_FREQ); + + tab_idx_1D[0] = (diff_type_1 == DIFF_FREQ) ? 0 : 1; + tab_idx_1D[1] = (diff_type_2 == DIFF_FREQ) ? 0 : 1; + + if (in_data_1 != NULL) { + huff_enc_1D(strm, data_type, tab_idx_1D[0], in_data_1_short, + num_val_1_short, p0_flag[0]); + } + if (in_data_2 != NULL) { + huff_enc_1D(strm, data_type, tab_idx_1D[1], in_data_2_short, + num_val_2_short, p0_flag[1]); + } + break; /* HUFF_1D */ + + case HUFF_2D: + + switch (cdg_scheme & PAIR_MASK) { + case FREQ_PAIR: + + if (in_data_1 != NULL) { + if (diff_type_1 == DIFF_FREQ) { + p0_data_1[0] = &in_data_1[0]; + p0_data_1[1] = NULL; + + num_val_1_short -= 1; + in_data_1_short += 1; + } + + df_rest_flag[0] = num_val_1_short % 2; + + if (df_rest_flag[0]) num_val_1_short -= 1; + + for (i = 0; i < num_val_1_short - 1; i += 2) { + pair_vec[i][0] = in_data_1_short[i]; + pair_vec[i][1] = in_data_1_short[i + 1]; + } + + tab_idx_2D[0][0] = (diff_type_1 == DIFF_TIME) ? 1 : 0; + tab_idx_2D[0][1] = 0; + + tab_idx_1D[0] = (diff_type_1 == DIFF_FREQ) ? 0 : 1; + } /* if( in_data_1 != NULL ) */ + + if (in_data_2 != NULL) { + if (diff_type_2 == DIFF_FREQ) { + p0_data_2[0] = NULL; + p0_data_2[1] = &in_data_2[0]; + + num_val_2_short -= 1; + in_data_2_short += 1; + } + + df_rest_flag[1] = num_val_2_short % 2; + + if (df_rest_flag[1]) num_val_2_short -= 1; + + for (i = 0; i < num_val_2_short - 1; i += 2) { + pair_vec[i + 1][0] = in_data_2_short[i]; + pair_vec[i + 1][1] = in_data_2_short[i + 1]; + } + + tab_idx_2D[1][0] = (diff_type_2 == DIFF_TIME) ? 1 : 0; + tab_idx_2D[1][1] = 0; + + tab_idx_1D[1] = (diff_type_2 == DIFF_FREQ) ? 0 : 1; + } /* if( in_data_2 != NULL ) */ + + if (in_data_1 != NULL) { + FDKwriteBits(strm, lavHuffVal[lav_idx[0]], lavHuffLen[lav_idx[0]]); + huff_enc_2D(strm, data_type, tab_idx_2D[0], lav_idx[0], pair_vec, + num_val_1_short, 2, p0_data_1); + if (df_rest_flag[0]) { + huff_enc_1D(strm, data_type, tab_idx_1D[0], + in_data_1_short + num_val_1_short, 1, 0); + } + } + if (in_data_2 != NULL) { + FDKwriteBits(strm, lavHuffVal[lav_idx[1]], lavHuffLen[lav_idx[1]]); + huff_enc_2D(strm, data_type, tab_idx_2D[1], lav_idx[1], + pair_vec + 1, num_val_2_short, 2, p0_data_2); + if (df_rest_flag[1]) { + huff_enc_1D(strm, data_type, tab_idx_1D[1], + in_data_2_short + num_val_2_short, 1, 0); + } + } + break; /* FREQ_PAIR */ + + case TIME_PAIR: + + if ((diff_type_1 == DIFF_FREQ) || (diff_type_2 == DIFF_FREQ)) { + p0_data_1[0] = &in_data_1[0]; + p0_data_1[1] = &in_data_2[0]; + + in_data_1_short += 1; + in_data_2_short += 1; + + num_val_1_short -= 1; + } + + for (i = 0; i < num_val_1_short; i++) { + pair_vec[i][0] = in_data_1_short[i]; + pair_vec[i][1] = in_data_2_short[i]; + } + + tab_idx_2D[0][0] = + ((diff_type_1 == DIFF_TIME) || (diff_type_2 == DIFF_TIME)) ? 1 + : 0; + tab_idx_2D[0][1] = 1; + + FDKwriteBits(strm, lavHuffVal[lav_idx[0]], lavHuffLen[lav_idx[0]]); + + huff_enc_2D(strm, data_type, tab_idx_2D[0], lav_idx[0], pair_vec, + num_val_1_short, 1, p0_data_1); + + break; /* TIME_PAIR */ + } /* switch( cdg_scheme & PAIR_MASK ) */ + + break; /* HUFF_2D */ + + default: + break; + } /* switch( cdg_scheme >> PAIR_SHIFT ) */ +} + +INT fdk_sacenc_ecDataPairEnc(HANDLE_FDK_BITSTREAM strm, + SHORT aaInData[][MAXBANDS], + SHORT aHistory[MAXBANDS], + const DATA_TYPE data_type, const INT setIdx, + const INT startBand, const INT dataBands, + const INT coarse_flag, + const INT independency_flag) { + SHORT reset = 0, pb = 0; + SHORT quant_levels = 0, quant_offset = 0, num_pcm_val = 0; + + SHORT splitLsb_flag = 0; + SHORT pcmCoding_flag = 0; + + SHORT allowDiffTimeBack_flag = !independency_flag || (setIdx > 0); + + SHORT num_lsb_bits = -1; + SHORT num_pcm_bits = -1; + + SHORT quant_data_lsb[2][MAXBANDS]; + SHORT quant_data_msb[2][MAXBANDS]; + + SHORT quant_data_hist_lsb[MAXBANDS]; + SHORT quant_data_hist_msb[MAXBANDS]; + + SHORT data_diff_freq[2][MAXBANDS]; + SHORT data_diff_time[2][MAXBANDS + 2]; + + SHORT *p_quant_data_msb[2]; + SHORT *p_quant_data_hist_msb = NULL; + + SHORT min_bits_all = 0; + SHORT min_found = 0; + + SHORT min_bits_df_df = -1; + SHORT min_bits_df_dt = -1; + SHORT min_bits_dtbw_df = -1; + SHORT min_bits_dt_dt = -1; + + SHORT lav_df_df[2] = {-1, -1}; + SHORT lav_df_dt[2] = {-1, -1}; + SHORT lav_dtbw_df[2] = {-1, -1}; + SHORT lav_dt_dt[2] = {-1, -1}; + + SHORT coding_scheme_df_df = 0; + SHORT coding_scheme_df_dt = 0; + SHORT coding_scheme_dtbw_df = 0; + SHORT coding_scheme_dt_dt = 0; + + switch (data_type) { + case t_CLD: + if (coarse_flag) { + splitLsb_flag = 0; + quant_levels = 15; + quant_offset = 7; + } else { + splitLsb_flag = 0; + quant_levels = 31; + quant_offset = 15; + } + break; + case t_ICC: + if (coarse_flag) { + splitLsb_flag = 0; + quant_levels = 4; + quant_offset = 0; + } else { + splitLsb_flag = 0; + quant_levels = 8; + quant_offset = 0; + } + break; + } /* switch( data_type ) */ + + /* Split off LSB */ + if (splitLsb_flag) { + split_lsb(aaInData[setIdx] + startBand, quant_offset, dataBands, + quant_data_lsb[0], quant_data_msb[0]); + + split_lsb(aaInData[setIdx + 1] + startBand, quant_offset, dataBands, + quant_data_lsb[1], quant_data_msb[1]); + + p_quant_data_msb[0] = quant_data_msb[0]; + p_quant_data_msb[1] = quant_data_msb[1]; + + num_lsb_bits = 2 * dataBands; + } else if (quant_offset != 0) { + for (pb = 0; pb < dataBands; pb++) { + quant_data_msb[0][pb] = aaInData[setIdx][startBand + pb] + quant_offset; + quant_data_msb[1][pb] = + aaInData[setIdx + 1][startBand + pb] + quant_offset; + } + + p_quant_data_msb[0] = quant_data_msb[0]; + p_quant_data_msb[1] = quant_data_msb[1]; + + num_lsb_bits = 0; + } else { + p_quant_data_msb[0] = aaInData[setIdx] + startBand; + p_quant_data_msb[1] = aaInData[setIdx + 1] + startBand; + + num_lsb_bits = 0; + } + + if (allowDiffTimeBack_flag) { + if (splitLsb_flag) { + split_lsb(aHistory + startBand, quant_offset, dataBands, + quant_data_hist_lsb, quant_data_hist_msb); + + p_quant_data_hist_msb = quant_data_hist_msb; + } else if (quant_offset != 0) { + for (pb = 0; pb < dataBands; pb++) { + quant_data_hist_msb[pb] = aHistory[startBand + pb] + quant_offset; + } + p_quant_data_hist_msb = quant_data_hist_msb; + } else { + p_quant_data_hist_msb = aHistory + startBand; + } + } + + /* Calculate frequency differences */ + calc_diff_freq(p_quant_data_msb[0], data_diff_freq[0], dataBands); + + calc_diff_freq(p_quant_data_msb[1], data_diff_freq[1], dataBands); + + /* Calculate time differences */ + if (allowDiffTimeBack_flag) { + calc_diff_time(p_quant_data_msb[0], p_quant_data_hist_msb, + data_diff_time[0], dataBands); + } + + calc_diff_time(p_quant_data_msb[1], p_quant_data_msb[0], data_diff_time[1], + dataBands); + + /* Calculate coding scheme with minumum bit consumption */ + + /**********************************************************/ + num_pcm_bits = calc_pcm_bits(2 * dataBands, quant_levels); + num_pcm_val = 2 * dataBands; + + /**********************************************************/ + + min_bits_all = num_pcm_bits; + + /**********************************************************/ + /**********************************************************/ + + /**********************************************************/ + min_bits_df_df = + calc_huff_bits(data_diff_freq[0], data_diff_freq[1], data_type, DIFF_FREQ, + DIFF_FREQ, dataBands, lav_df_df, &coding_scheme_df_df); + + min_bits_df_df += 2; + + min_bits_df_df += num_lsb_bits; + + if (min_bits_df_df < min_bits_all) { + min_bits_all = min_bits_df_df; + } + /**********************************************************/ + + /**********************************************************/ + min_bits_df_dt = + calc_huff_bits(data_diff_freq[0], data_diff_time[1], data_type, DIFF_FREQ, + DIFF_TIME, dataBands, lav_df_dt, &coding_scheme_df_dt); + + min_bits_df_dt += 2; + + min_bits_df_dt += num_lsb_bits; + + if (min_bits_df_dt < min_bits_all) { + min_bits_all = min_bits_df_dt; + } + /**********************************************************/ + + /**********************************************************/ + /**********************************************************/ + + if (allowDiffTimeBack_flag) { + /**********************************************************/ + min_bits_dtbw_df = calc_huff_bits( + data_diff_time[0], data_diff_freq[1], data_type, DIFF_TIME, DIFF_FREQ, + dataBands, lav_dtbw_df, &coding_scheme_dtbw_df); + + min_bits_dtbw_df += 2; + + min_bits_dtbw_df += num_lsb_bits; + + if (min_bits_dtbw_df < min_bits_all) { + min_bits_all = min_bits_dtbw_df; + } + /**********************************************************/ + + /**********************************************************/ + min_bits_dt_dt = calc_huff_bits(data_diff_time[0], data_diff_time[1], + data_type, DIFF_TIME, DIFF_TIME, dataBands, + lav_dt_dt, &coding_scheme_dt_dt); + + min_bits_dt_dt += 2; + + min_bits_dt_dt += num_lsb_bits; + + if (min_bits_dt_dt < min_bits_all) { + min_bits_all = min_bits_dt_dt; + } + /**********************************************************/ + + } /* if( allowDiffTimeBack_flag ) */ + + /***************************/ + /* Start actual coding now */ + /***************************/ + + /* PCM or Diff/Huff Coding? */ + pcmCoding_flag = (min_bits_all == num_pcm_bits); + + FDKwriteBits(strm, pcmCoding_flag, 1); + + if (pcmCoding_flag) { + /* Grouped PCM Coding */ + apply_pcm_coding(strm, aaInData[setIdx] + startBand, + aaInData[setIdx + 1] + startBand, quant_offset, + num_pcm_val, quant_levels); + } else { + /* Diff/Huff Coding */ + + min_found = 0; + + /*******************************************/ + if (min_bits_all == min_bits_df_df) { + FDKwriteBits(strm, DIFF_FREQ, 1); + FDKwriteBits(strm, DIFF_FREQ, 1); + + apply_huff_coding(strm, data_diff_freq[0], data_diff_freq[1], data_type, + DIFF_FREQ, DIFF_FREQ, dataBands, lav_df_df, + coding_scheme_df_df); + + min_found = 1; + } + /*******************************************/ + + /*******************************************/ + if (!min_found && (min_bits_all == min_bits_df_dt)) { + FDKwriteBits(strm, DIFF_FREQ, 1); + FDKwriteBits(strm, DIFF_TIME, 1); + + apply_huff_coding(strm, data_diff_freq[0], data_diff_time[1], data_type, + DIFF_FREQ, DIFF_TIME, dataBands, lav_df_dt, + coding_scheme_df_dt); + + min_found = 1; + } + /*******************************************/ + + /*******************************************/ + /*******************************************/ + + if (allowDiffTimeBack_flag) { + /*******************************************/ + if (!min_found && (min_bits_all == min_bits_dtbw_df)) { + FDKwriteBits(strm, DIFF_TIME, 1); + FDKwriteBits(strm, DIFF_FREQ, 1); + + apply_huff_coding(strm, data_diff_time[0], data_diff_freq[1], data_type, + DIFF_TIME, DIFF_FREQ, dataBands, lav_dtbw_df, + coding_scheme_dtbw_df); + + min_found = 1; + } + /*******************************************/ + + /*******************************************/ + if (!min_found && (min_bits_all == min_bits_dt_dt)) { + FDKwriteBits(strm, DIFF_TIME, 1); + FDKwriteBits(strm, DIFF_TIME, 1); + + apply_huff_coding(strm, data_diff_time[0], data_diff_time[1], data_type, + DIFF_TIME, DIFF_TIME, dataBands, lav_dt_dt, + coding_scheme_dt_dt); + } + /*******************************************/ + + } /* if( allowDiffTimeBack_flag ) */ + + /* LSB coding */ + if (splitLsb_flag) { + apply_lsb_coding(strm, quant_data_lsb[0], 1, dataBands); + + apply_lsb_coding(strm, quant_data_lsb[1], 1, dataBands); + } + + } /* Diff/Huff/LSB coding */ + + return reset; +} + +INT fdk_sacenc_ecDataSingleEnc(HANDLE_FDK_BITSTREAM strm, + SHORT aaInData[][MAXBANDS], + SHORT aHistory[MAXBANDS], + const DATA_TYPE data_type, const INT setIdx, + const INT startBand, const INT dataBands, + const INT coarse_flag, + const INT independency_flag) { + SHORT reset = 0, pb = 0; + SHORT quant_levels = 0, quant_offset = 0, num_pcm_val = 0; + + SHORT splitLsb_flag = 0; + SHORT pcmCoding_flag = 0; + + SHORT allowDiffTimeBack_flag = !independency_flag || (setIdx > 0); + + SHORT num_lsb_bits = -1; + SHORT num_pcm_bits = -1; + + SHORT quant_data_lsb[MAXBANDS]; + SHORT quant_data_msb[MAXBANDS]; + + SHORT quant_data_hist_lsb[MAXBANDS]; + SHORT quant_data_hist_msb[MAXBANDS]; + + SHORT data_diff_freq[MAXBANDS]; + SHORT data_diff_time[MAXBANDS + 2]; + + SHORT *p_quant_data_msb; + SHORT *p_quant_data_hist_msb = NULL; + + SHORT min_bits_all = 0; + SHORT min_found = 0; + + SHORT min_bits_df = -1; + SHORT min_bits_dt = -1; + + SHORT lav_df[2] = {-1, -1}; + SHORT lav_dt[2] = {-1, -1}; + + SHORT coding_scheme_df = 0; + SHORT coding_scheme_dt = 0; + + switch (data_type) { + case t_CLD: + if (coarse_flag) { + splitLsb_flag = 0; + quant_levels = 15; + quant_offset = 7; + } else { + splitLsb_flag = 0; + quant_levels = 31; + quant_offset = 15; + } + break; + case t_ICC: + if (coarse_flag) { + splitLsb_flag = 0; + quant_levels = 4; + quant_offset = 0; + } else { + splitLsb_flag = 0; + quant_levels = 8; + quant_offset = 0; + } + break; + } /* switch( data_type ) */ + + /* Split off LSB */ + if (splitLsb_flag) { + split_lsb(aaInData[setIdx] + startBand, quant_offset, dataBands, + quant_data_lsb, quant_data_msb); + + p_quant_data_msb = quant_data_msb; + num_lsb_bits = dataBands; + } else if (quant_offset != 0) { + for (pb = 0; pb < dataBands; pb++) { + quant_data_msb[pb] = aaInData[setIdx][startBand + pb] + quant_offset; + } + + p_quant_data_msb = quant_data_msb; + num_lsb_bits = 0; + } else { + p_quant_data_msb = aaInData[setIdx] + startBand; + num_lsb_bits = 0; + } + + if (allowDiffTimeBack_flag) { + if (splitLsb_flag) { + split_lsb(aHistory + startBand, quant_offset, dataBands, + quant_data_hist_lsb, quant_data_hist_msb); + + p_quant_data_hist_msb = quant_data_hist_msb; + } else if (quant_offset != 0) { + for (pb = 0; pb < dataBands; pb++) { + quant_data_hist_msb[pb] = aHistory[startBand + pb] + quant_offset; + } + p_quant_data_hist_msb = quant_data_hist_msb; + } else { + p_quant_data_hist_msb = aHistory + startBand; + } + } + + /* Calculate frequency differences */ + calc_diff_freq(p_quant_data_msb, data_diff_freq, dataBands); + + /* Calculate time differences */ + if (allowDiffTimeBack_flag) { + calc_diff_time(p_quant_data_msb, p_quant_data_hist_msb, data_diff_time, + dataBands); + } + + /* Calculate coding scheme with minumum bit consumption */ + + /**********************************************************/ + num_pcm_bits = calc_pcm_bits(dataBands, quant_levels); + num_pcm_val = dataBands; + + /**********************************************************/ + + min_bits_all = num_pcm_bits; + + /**********************************************************/ + /**********************************************************/ + + /**********************************************************/ + min_bits_df = calc_huff_bits(data_diff_freq, NULL, data_type, DIFF_FREQ, + DIFF_FREQ, dataBands, lav_df, &coding_scheme_df); + + if (allowDiffTimeBack_flag) min_bits_df += 1; + + min_bits_df += num_lsb_bits; + + if (min_bits_df < min_bits_all) { + min_bits_all = min_bits_df; + } + /**********************************************************/ + + /**********************************************************/ + if (allowDiffTimeBack_flag) { + min_bits_dt = + calc_huff_bits(data_diff_time, NULL, data_type, DIFF_TIME, DIFF_TIME, + dataBands, lav_dt, &coding_scheme_dt); + + min_bits_dt += 1; + min_bits_dt += num_lsb_bits; + + if (min_bits_dt < min_bits_all) { + min_bits_all = min_bits_dt; + } + } /* if( allowDiffTimeBack_flag ) */ + + /***************************/ + /* Start actual coding now */ + /***************************/ + + /* PCM or Diff/Huff Coding? */ + pcmCoding_flag = (min_bits_all == num_pcm_bits); + + FDKwriteBits(strm, pcmCoding_flag, 1); + + if (pcmCoding_flag) { + /* Grouped PCM Coding */ + apply_pcm_coding(strm, aaInData[setIdx] + startBand, NULL, quant_offset, + num_pcm_val, quant_levels); + } else { + /* Diff/Huff Coding */ + + min_found = 0; + + /*******************************************/ + if (min_bits_all == min_bits_df) { + if (allowDiffTimeBack_flag) { + FDKwriteBits(strm, DIFF_FREQ, 1); + } + + apply_huff_coding(strm, data_diff_freq, NULL, data_type, DIFF_FREQ, + DIFF_FREQ, dataBands, lav_df, coding_scheme_df); + + min_found = 1; + } /* if( min_bits_all == min_bits_df ) */ + /*******************************************/ + + /*******************************************/ + if (allowDiffTimeBack_flag) { + /*******************************************/ + if (!min_found && (min_bits_all == min_bits_dt)) { + FDKwriteBits(strm, DIFF_TIME, 1); + + apply_huff_coding(strm, data_diff_time, NULL, data_type, DIFF_TIME, + DIFF_TIME, dataBands, lav_dt, coding_scheme_dt); + } + /*******************************************/ + + } /* if( allowDiffTimeBack_flag ) */ + + /* LSB coding */ + if (splitLsb_flag) { + apply_lsb_coding(strm, quant_data_lsb, 1, dataBands); + } + + } /* Diff/Huff/LSB coding */ + + return reset; +} -- 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 'libSACenc/src/sacenc_nlc_enc.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