diff options
author | Fraunhofer IIS FDK <audio-fdk@iis.fraunhofer.de> | 2018-02-26 20:17:00 +0100 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2018-04-19 11:21:15 -0700 |
commit | 6cfabd35363c3ef5e3b209b867169a500b3ccc3c (patch) | |
tree | 01c0a19f2735e8b5d2407555fe992d4230d089eb /libAACenc/src/sf_estim.cpp | |
parent | 6288a1e34c4dede4c2806beb1736ece6580558c7 (diff) | |
download | fdk-aac-6cfabd35363c3ef5e3b209b867169a500b3ccc3c.tar.gz fdk-aac-6cfabd35363c3ef5e3b209b867169a500b3ccc3c.tar.bz2 fdk-aac-6cfabd35363c3ef5e3b209b867169a500b3ccc3c.zip |
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
Diffstat (limited to 'libAACenc/src/sf_estim.cpp')
-rw-r--r-- | libAACenc/src/sf_estim.cpp | 1170 |
1 files changed, 566 insertions, 604 deletions
diff --git a/libAACenc/src/sf_estim.cpp b/libAACenc/src/sf_estim.cpp index 1cb243b..17a8ae2 100644 --- a/libAACenc/src/sf_estim.cpp +++ b/libAACenc/src/sf_estim.cpp @@ -1,74 +1,85 @@ - -/* ----------------------------------------------------------------------------------------------------------- +/* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2015 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,33 +90,35 @@ Am Wolfsmantel 33 www.iis.fraunhofer.de/amm amm-info@iis.fraunhofer.de ------------------------------------------------------------------------------------------------------------ */ +----------------------------------------------------------------------------- */ + +/**************************** AAC encoder library ****************************** -/******************************** MPEG Audio Encoder ************************** + Author(s): M. Werner - Initial author: M. Werner - contents/description: Scale factor estimation + Description: Scale factor estimation -******************************************************************************/ +*******************************************************************************/ #include "sf_estim.h" #include "aacEnc_rom.h" #include "quantize.h" #include "bit_cnt.h" +#ifdef __arm__ +#endif - - +#define UPCOUNT_LIMIT 1 #define AS_PE_FAC_SHIFT 7 -#define DIST_FAC_SHIFT 3 +#define DIST_FAC_SHIFT 3 #define AS_PE_FAC_FLOAT (float)(1 << AS_PE_FAC_SHIFT) static const INT MAX_SCF_DELTA = 60; - -static const FIXP_DBL PE_C1 = FL2FXCONST_DBL(3.0f/AS_PE_FAC_FLOAT); /* (log(8.0)/log(2)) >> AS_PE_FAC_SHIFT */ -static const FIXP_DBL PE_C2 = FL2FXCONST_DBL(1.3219281f/AS_PE_FAC_FLOAT); /* (log(2.5)/log(2)) >> AS_PE_FAC_SHIFT */ -static const FIXP_DBL PE_C3 = FL2FXCONST_DBL(0.5593573f); /* 1-C2/C1 */ - +static const FIXP_DBL PE_C1 = FL2FXCONST_DBL( + 3.0f / AS_PE_FAC_FLOAT); /* (log(8.0)/log(2)) >> AS_PE_FAC_SHIFT */ +static const FIXP_DBL PE_C2 = FL2FXCONST_DBL( + 1.3219281f / AS_PE_FAC_FLOAT); /* (log(2.5)/log(2)) >> AS_PE_FAC_SHIFT */ +static const FIXP_DBL PE_C3 = FL2FXCONST_DBL(0.5593573f); /* 1-C2/C1 */ /* Function; FDKaacEnc_FDKaacEnc_CalcFormFactorChannel @@ -113,30 +126,32 @@ static const FIXP_DBL PE_C3 = FL2FXCONST_DBL(0.5593573f); /* Description: Calculates the formfactor sf: scale factor of the mdct spectrum - sfbFormFactorLdData is scaled with the factor 1/(((2^sf)^0.5) * (2^FORM_FAC_SHIFT)) + sfbFormFactorLdData is scaled with the factor 1/(((2^sf)^0.5) * + (2^FORM_FAC_SHIFT)) */ -static void -FDKaacEnc_FDKaacEnc_CalcFormFactorChannel(FIXP_DBL *RESTRICT sfbFormFactorLdData, - PSY_OUT_CHANNEL *RESTRICT psyOutChan) -{ +static void FDKaacEnc_FDKaacEnc_CalcFormFactorChannel( + FIXP_DBL *RESTRICT sfbFormFactorLdData, + PSY_OUT_CHANNEL *RESTRICT psyOutChan) { INT j, sfb, sfbGrp; FIXP_DBL formFactor; int tmp0 = psyOutChan->sfbCnt; int tmp1 = psyOutChan->maxSfbPerGroup; int step = psyOutChan->sfbPerGroup; - for(sfbGrp = 0; sfbGrp < tmp0; sfbGrp += step) { + for (sfbGrp = 0; sfbGrp < tmp0; sfbGrp += step) { for (sfb = 0; sfb < tmp1; sfb++) { formFactor = FL2FXCONST_DBL(0.0f); /* calc sum of sqrt(spec) */ - for(j=psyOutChan->sfbOffsets[sfbGrp+sfb]; j<psyOutChan->sfbOffsets[sfbGrp+sfb+1]; j++ ) { - formFactor += sqrtFixp(fixp_abs(psyOutChan->mdctSpectrum[j]))>>FORM_FAC_SHIFT; + for (j = psyOutChan->sfbOffsets[sfbGrp + sfb]; + j < psyOutChan->sfbOffsets[sfbGrp + sfb + 1]; j++) { + formFactor += + sqrtFixp(fixp_abs(psyOutChan->mdctSpectrum[j])) >> FORM_FAC_SHIFT; } - sfbFormFactorLdData[sfbGrp+sfb] = CalcLdData(formFactor); + sfbFormFactorLdData[sfbGrp + sfb] = CalcLdData(formFactor); } /* set sfbFormFactor for sfbs with zero spec to zero. Just for debugging. */ - for ( ; sfb < psyOutChan->sfbPerGroup; sfb++) { - sfbFormFactorLdData[sfbGrp+sfb] = FL2FXCONST_DBL(-1.0f); + for (; sfb < psyOutChan->sfbPerGroup; sfb++) { + sfbFormFactorLdData[sfbGrp + sfb] = FL2FXCONST_DBL(-1.0f); } } } @@ -144,17 +159,17 @@ FDKaacEnc_FDKaacEnc_CalcFormFactorChannel(FIXP_DBL *RESTRICT sfbFormFactorLdData /* Function: FDKaacEnc_CalcFormFactor - Description: Calls FDKaacEnc_FDKaacEnc_CalcFormFactorChannel() for each channel + Description: Calls FDKaacEnc_FDKaacEnc_CalcFormFactorChannel() for each + channel */ -void -FDKaacEnc_CalcFormFactor(QC_OUT_CHANNEL *qcOutChannel[(2)], - PSY_OUT_CHANNEL *psyOutChannel[(2)], - const INT nChannels) -{ +void FDKaacEnc_CalcFormFactor(QC_OUT_CHANNEL *qcOutChannel[(2)], + PSY_OUT_CHANNEL *psyOutChannel[(2)], + const INT nChannels) { INT j; - for (j=0; j<nChannels; j++) { - FDKaacEnc_FDKaacEnc_CalcFormFactorChannel(qcOutChannel[j]->sfbFormFactorLdData, psyOutChannel[j]); + for (j = 0; j < nChannels; j++) { + FDKaacEnc_FDKaacEnc_CalcFormFactorChannel( + qcOutChannel[j]->sfbFormFactorLdData, psyOutChannel[j]); } } @@ -165,40 +180,44 @@ FDKaacEnc_CalcFormFactor(QC_OUT_CHANNEL *qcOutChannel[(2)], sfbNRelevantLines is scaled with the factor 1/((2^FORM_FAC_SHIFT) * 2.0) */ -static void -FDKaacEnc_calcSfbRelevantLines( const FIXP_DBL *const sfbFormFactorLdData, - const FIXP_DBL *const sfbEnergyLdData, - const FIXP_DBL *const sfbThresholdLdData, - const INT *const sfbOffsets, - const INT sfbCnt, - const INT sfbPerGroup, - const INT maxSfbPerGroup, - FIXP_DBL *sfbNRelevantLines) -{ +static void FDKaacEnc_calcSfbRelevantLines( + const FIXP_DBL *const sfbFormFactorLdData, + const FIXP_DBL *const sfbEnergyLdData, + const FIXP_DBL *const sfbThresholdLdData, const INT *const sfbOffsets, + const INT sfbCnt, const INT sfbPerGroup, const INT maxSfbPerGroup, + FIXP_DBL *sfbNRelevantLines) { INT sfbOffs, sfb; FIXP_DBL sfbWidthLdData; - FIXP_DBL asPeFacLdData = FL2FXCONST_DBL(0.109375); /* AS_PE_FAC_SHIFT*ld64(2) */ + FIXP_DBL asPeFacLdData = + FL2FXCONST_DBL(0.109375); /* AS_PE_FAC_SHIFT*ld64(2) */ FIXP_DBL accu; - /* sfbNRelevantLines[i] = 2^( (sfbFormFactorLdData[i] - 0.25 * (sfbEnergyLdData[i] - ld64(sfbWidth[i]/(2^7)) - AS_PE_FAC_SHIFT*ld64(2)) * 64); */ + /* sfbNRelevantLines[i] = 2^( (sfbFormFactorLdData[i] - 0.25 * + * (sfbEnergyLdData[i] - ld64(sfbWidth[i]/(2^7)) - AS_PE_FAC_SHIFT*ld64(2)) * + * 64); */ FDKmemclear(sfbNRelevantLines, sfbCnt * sizeof(FIXP_DBL)); - for (sfbOffs=0; sfbOffs<sfbCnt; sfbOffs+=sfbPerGroup) { - for(sfb=0; sfb<maxSfbPerGroup; sfb++) { + for (sfbOffs = 0; sfbOffs < sfbCnt; sfbOffs += sfbPerGroup) { + for (sfb = 0; sfb < maxSfbPerGroup; sfb++) { /* calc sum of sqrt(spec) */ - if((FIXP_DBL)sfbEnergyLdData[sfbOffs+sfb] > (FIXP_DBL)sfbThresholdLdData[sfbOffs+sfb]) { - INT sfbWidth = sfbOffsets[sfbOffs+sfb+1] - sfbOffsets[sfbOffs+sfb]; - - /* avgFormFactorLdData = sqrtFixp(sqrtFixp(sfbEnergyLdData[sfbOffs+sfb]/sfbWidth)); */ - /* sfbNRelevantLines[sfbOffs+sfb] = sfbFormFactor[sfbOffs+sfb] / avgFormFactorLdData; */ - sfbWidthLdData = (FIXP_DBL)(sfbWidth << (DFRACT_BITS-1-AS_PE_FAC_SHIFT)); + if ((FIXP_DBL)sfbEnergyLdData[sfbOffs + sfb] > + (FIXP_DBL)sfbThresholdLdData[sfbOffs + sfb]) { + INT sfbWidth = + sfbOffsets[sfbOffs + sfb + 1] - sfbOffsets[sfbOffs + sfb]; + + /* avgFormFactorLdData = + * sqrtFixp(sqrtFixp(sfbEnergyLdData[sfbOffs+sfb]/sfbWidth)); */ + /* sfbNRelevantLines[sfbOffs+sfb] = sfbFormFactor[sfbOffs+sfb] / + * avgFormFactorLdData; */ + sfbWidthLdData = + (FIXP_DBL)(sfbWidth << (DFRACT_BITS - 1 - AS_PE_FAC_SHIFT)); sfbWidthLdData = CalcLdData(sfbWidthLdData); - accu = sfbEnergyLdData[sfbOffs+sfb] - sfbWidthLdData - asPeFacLdData; - accu = sfbFormFactorLdData[sfbOffs+sfb] - (accu >> 2); + accu = sfbEnergyLdData[sfbOffs + sfb] - sfbWidthLdData - asPeFacLdData; + accu = sfbFormFactorLdData[sfbOffs + sfb] - (accu >> 2); - sfbNRelevantLines[sfbOffs+sfb] = CalcInvLdData(accu) >> 1; + sfbNRelevantLines[sfbOffs + sfb] = CalcInvLdData(accu) >> 1; } } } @@ -211,14 +230,14 @@ FDKaacEnc_calcSfbRelevantLines( const FIXP_DBL *const sfbFormFactorLdData, scfBitsFract is scaled by 1/(2^(2*AS_PE_FAC_SHIFT)) */ -static FIXP_DBL FDKaacEnc_countSingleScfBits(INT scf, INT scfLeft, INT scfRight) -{ +static FIXP_DBL FDKaacEnc_countSingleScfBits(INT scf, INT scfLeft, + INT scfRight) { FIXP_DBL scfBitsFract; - scfBitsFract = (FIXP_DBL) ( FDKaacEnc_bitCountScalefactorDelta(scfLeft-scf) - + FDKaacEnc_bitCountScalefactorDelta(scf-scfRight) ); + scfBitsFract = (FIXP_DBL)(FDKaacEnc_bitCountScalefactorDelta(scfLeft - scf) + + FDKaacEnc_bitCountScalefactorDelta(scf - scfRight)); - scfBitsFract = scfBitsFract << (DFRACT_BITS-1-(2*AS_PE_FAC_SHIFT)); + scfBitsFract = scfBitsFract << (DFRACT_BITS - 1 - (2 * AS_PE_FAC_SHIFT)); return scfBitsFract; /* output scaled by 1/(2^(2*AS_PE_FAC)) */ } @@ -228,21 +247,21 @@ static FIXP_DBL FDKaacEnc_countSingleScfBits(INT scf, INT scfLeft, INT scfRight) specPe is scaled by 1/(2^(2*AS_PE_FAC_SHIFT)) */ -static FIXP_DBL FDKaacEnc_calcSingleSpecPe(INT scf, FIXP_DBL sfbConstPePart, FIXP_DBL nLines) -{ +static FIXP_DBL FDKaacEnc_calcSingleSpecPe(INT scf, FIXP_DBL sfbConstPePart, + FIXP_DBL nLines) { FIXP_DBL specPe = FL2FXCONST_DBL(0.0f); FIXP_DBL ldRatio; FIXP_DBL scfFract; - scfFract = (FIXP_DBL)(scf << (DFRACT_BITS-1-AS_PE_FAC_SHIFT)); + scfFract = (FIXP_DBL)(scf << (DFRACT_BITS - 1 - AS_PE_FAC_SHIFT)); - ldRatio = sfbConstPePart - fMult(FL2FXCONST_DBL(0.375f),scfFract); + ldRatio = sfbConstPePart - fMult(FL2FXCONST_DBL(0.375f), scfFract); if (ldRatio >= PE_C1) { - specPe = fMult(FL2FXCONST_DBL(0.7f),fMult(nLines,ldRatio)); - } - else { - specPe = fMult(FL2FXCONST_DBL(0.7f),fMult(nLines,(PE_C2 + fMult(PE_C3,ldRatio)))); + specPe = fMult(FL2FXCONST_DBL(0.7f), fMult(nLines, ldRatio)); + } else { + specPe = fMult(FL2FXCONST_DBL(0.7f), + fMult(nLines, (PE_C2 + fMult(PE_C3, ldRatio)))); } return specPe; /* output scaled by 1/(2^(2*AS_PE_FAC)) */ @@ -253,12 +272,8 @@ static FIXP_DBL FDKaacEnc_calcSingleSpecPe(INT scf, FIXP_DBL sfbConstPePart, FIX scfBitsDiff is scaled by 1/(2^(2*AS_PE_FAC_SHIFT)) */ -static FIXP_DBL FDKaacEnc_countScfBitsDiff(INT *scfOld, - INT *scfNew, - INT sfbCnt, - INT startSfb, - INT stopSfb) -{ +static FIXP_DBL FDKaacEnc_countScfBitsDiff(INT *scfOld, INT *scfNew, INT sfbCnt, + INT startSfb, INT stopSfb) { FIXP_DBL scfBitsFract; INT scfBitsDiff = 0; INT sfb = 0, sfbLast; @@ -266,32 +281,33 @@ static FIXP_DBL FDKaacEnc_countScfBitsDiff(INT *scfOld, /* search for first relevant sfb */ sfbLast = startSfb; - while ((sfbLast<stopSfb) && (scfOld[sfbLast]==FDK_INT_MIN)) - sfbLast++; + while ((sfbLast < stopSfb) && (scfOld[sfbLast] == FDK_INT_MIN)) sfbLast++; /* search for previous relevant sfb and count diff */ sfbPrev = startSfb - 1; - while ((sfbPrev>=0) && (scfOld[sfbPrev]==FDK_INT_MIN)) - sfbPrev--; - if (sfbPrev>=0) - scfBitsDiff += FDKaacEnc_bitCountScalefactorDelta(scfNew[sfbPrev]-scfNew[sfbLast]) - - FDKaacEnc_bitCountScalefactorDelta(scfOld[sfbPrev]-scfOld[sfbLast]); + while ((sfbPrev >= 0) && (scfOld[sfbPrev] == FDK_INT_MIN)) sfbPrev--; + if (sfbPrev >= 0) + scfBitsDiff += + FDKaacEnc_bitCountScalefactorDelta(scfNew[sfbPrev] - scfNew[sfbLast]) - + FDKaacEnc_bitCountScalefactorDelta(scfOld[sfbPrev] - scfOld[sfbLast]); /* now loop through all sfbs and count diffs of relevant sfbs */ - for (sfb=sfbLast+1; sfb<stopSfb; sfb++) { - if (scfOld[sfb]!=FDK_INT_MIN) { - scfBitsDiff += FDKaacEnc_bitCountScalefactorDelta(scfNew[sfbLast]-scfNew[sfb]) - - FDKaacEnc_bitCountScalefactorDelta(scfOld[sfbLast]-scfOld[sfb]); + for (sfb = sfbLast + 1; sfb < stopSfb; sfb++) { + if (scfOld[sfb] != FDK_INT_MIN) { + scfBitsDiff += + FDKaacEnc_bitCountScalefactorDelta(scfNew[sfbLast] - scfNew[sfb]) - + FDKaacEnc_bitCountScalefactorDelta(scfOld[sfbLast] - scfOld[sfb]); sfbLast = sfb; } } /* search for next relevant sfb and count diff */ sfbNext = stopSfb; - while ((sfbNext<sfbCnt) && (scfOld[sfbNext]==FDK_INT_MIN)) - sfbNext++; - if (sfbNext<sfbCnt) - scfBitsDiff += FDKaacEnc_bitCountScalefactorDelta(scfNew[sfbLast]-scfNew[sfbNext]) - - FDKaacEnc_bitCountScalefactorDelta(scfOld[sfbLast]-scfOld[sfbNext]); + while ((sfbNext < sfbCnt) && (scfOld[sfbNext] == FDK_INT_MIN)) sfbNext++; + if (sfbNext < sfbCnt) + scfBitsDiff += + FDKaacEnc_bitCountScalefactorDelta(scfNew[sfbLast] - scfNew[sfbNext]) - + FDKaacEnc_bitCountScalefactorDelta(scfOld[sfbLast] - scfOld[sfbNext]); - scfBitsFract = (FIXP_DBL) (scfBitsDiff << (DFRACT_BITS-1-(2*AS_PE_FAC_SHIFT))); + scfBitsFract = + (FIXP_DBL)(scfBitsDiff << (DFRACT_BITS - 1 - (2 * AS_PE_FAC_SHIFT))); return scfBitsFract; } @@ -301,48 +317,51 @@ static FIXP_DBL FDKaacEnc_countScfBitsDiff(INT *scfOld, specPeDiff is scaled by 1/(2^(2*AS_PE_FAC_SHIFT)) */ -static FIXP_DBL FDKaacEnc_calcSpecPeDiff(PSY_OUT_CHANNEL *psyOutChan, - QC_OUT_CHANNEL *qcOutChannel, - INT *scfOld, - INT *scfNew, - FIXP_DBL *sfbConstPePart, - FIXP_DBL *sfbFormFactorLdData, - FIXP_DBL *sfbNRelevantLines, - INT startSfb, - INT stopSfb) -{ +static FIXP_DBL FDKaacEnc_calcSpecPeDiff( + PSY_OUT_CHANNEL *psyOutChan, QC_OUT_CHANNEL *qcOutChannel, INT *scfOld, + INT *scfNew, FIXP_DBL *sfbConstPePart, FIXP_DBL *sfbFormFactorLdData, + FIXP_DBL *sfbNRelevantLines, INT startSfb, INT stopSfb) { FIXP_DBL specPeDiff = FL2FXCONST_DBL(0.0f); FIXP_DBL scfFract = FL2FXCONST_DBL(0.0f); INT sfb; /* loop through all sfbs and count pe difference */ - for (sfb=startSfb; sfb<stopSfb; sfb++) { - if (scfOld[sfb]!=FDK_INT_MIN) { + for (sfb = startSfb; sfb < stopSfb; sfb++) { + if (scfOld[sfb] != FDK_INT_MIN) { FIXP_DBL ldRatioOld, ldRatioNew, pOld, pNew; - /* sfbConstPePart[sfb] = (float)log(psyOutChan->sfbEnergy[sfb] * 6.75f / sfbFormFactor[sfb]) * LOG2_1; */ - /* 0.02152255861f = log(6.75)/log(2)/AS_PE_FAC_FLOAT; LOG2_1 is 1.0 for log2 */ + /* sfbConstPePart[sfb] = (float)log(psyOutChan->sfbEnergy[sfb] * 6.75f / + * sfbFormFactor[sfb]) * LOG2_1; */ + /* 0.02152255861f = log(6.75)/log(2)/AS_PE_FAC_FLOAT; LOG2_1 is 1.0 for + * log2 */ /* 0.09375f = log(64.0)/log(2.0)/64.0 = scale of sfbFormFactorLdData */ if (sfbConstPePart[sfb] == (FIXP_DBL)FDK_INT_MIN) - sfbConstPePart[sfb] = ((psyOutChan->sfbEnergyLdData[sfb] - sfbFormFactorLdData[sfb] - FL2FXCONST_DBL(0.09375f)) >> 1) + FL2FXCONST_DBL(0.02152255861f); + sfbConstPePart[sfb] = + ((psyOutChan->sfbEnergyLdData[sfb] - sfbFormFactorLdData[sfb] - + FL2FXCONST_DBL(0.09375f)) >> + 1) + + FL2FXCONST_DBL(0.02152255861f); - scfFract = (FIXP_DBL) (scfOld[sfb] << (DFRACT_BITS-1-AS_PE_FAC_SHIFT)); - ldRatioOld = sfbConstPePart[sfb] - fMult(FL2FXCONST_DBL(0.375f),scfFract); + scfFract = (FIXP_DBL)(scfOld[sfb] << (DFRACT_BITS - 1 - AS_PE_FAC_SHIFT)); + ldRatioOld = + sfbConstPePart[sfb] - fMult(FL2FXCONST_DBL(0.375f), scfFract); - scfFract = (FIXP_DBL) (scfNew[sfb] << (DFRACT_BITS-1-AS_PE_FAC_SHIFT)); - ldRatioNew = sfbConstPePart[sfb] - fMult(FL2FXCONST_DBL(0.375f),scfFract); + scfFract = (FIXP_DBL)(scfNew[sfb] << (DFRACT_BITS - 1 - AS_PE_FAC_SHIFT)); + ldRatioNew = + sfbConstPePart[sfb] - fMult(FL2FXCONST_DBL(0.375f), scfFract); if (ldRatioOld >= PE_C1) pOld = ldRatioOld; else - pOld = PE_C2 + fMult(PE_C3,ldRatioOld); + pOld = PE_C2 + fMult(PE_C3, ldRatioOld); if (ldRatioNew >= PE_C1) pNew = ldRatioNew; else - pNew = PE_C2 + fMult(PE_C3,ldRatioNew); + pNew = PE_C2 + fMult(PE_C3, ldRatioNew); - specPeDiff += fMult(FL2FXCONST_DBL(0.7f),fMult(sfbNRelevantLines[sfb],(pNew - pOld))); + specPeDiff += fMult(FL2FXCONST_DBL(0.7f), + fMult(sfbNRelevantLines[sfb], (pNew - pOld))); } } @@ -352,123 +371,96 @@ static FIXP_DBL FDKaacEnc_calcSpecPeDiff(PSY_OUT_CHANNEL *psyOutChan, /* Function: FDKaacEnc_improveScf - Description: Calculate the distortion by quantization and inverse quantization of the spectrum with - various scalefactors. The scalefactor which provides the best results will be used. + Description: Calculate the distortion by quantization and inverse quantization + of the spectrum with various scalefactors. The scalefactor which provides the + best results will be used. */ -static INT FDKaacEnc_improveScf(FIXP_DBL *spec, - SHORT *quantSpec, - SHORT *quantSpecTmp, - INT sfbWidth, - FIXP_DBL threshLdData, - INT scf, - INT minScf, - FIXP_DBL *distLdData, - INT *minScfCalculated, - INT dZoneQuantEnable - ) -{ - FIXP_DBL sfbDistLdData; - INT scfBest = scf; - INT k; - FIXP_DBL distFactorLdData = FL2FXCONST_DBL(-0.0050301265); /* ld64(1/1.25) */ - - /* calc real distortion */ - sfbDistLdData = FDKaacEnc_calcSfbDist(spec, - quantSpec, - sfbWidth, - scf, - dZoneQuantEnable); - *minScfCalculated = scf; - /* nmr > 1.25 -> try to improve nmr */ - if (sfbDistLdData > (threshLdData-distFactorLdData)) { - INT scfEstimated = scf; - FIXP_DBL sfbDistBestLdData = sfbDistLdData; - INT cnt; - /* improve by bigger scf ? */ - cnt = 0; - - while ((sfbDistLdData > (threshLdData-distFactorLdData)) && (cnt++ < 3)) { - scf++; - sfbDistLdData = FDKaacEnc_calcSfbDist(spec, - quantSpecTmp, - sfbWidth, - scf, - dZoneQuantEnable); - - if (sfbDistLdData < sfbDistBestLdData) { - scfBest = scf; - sfbDistBestLdData = sfbDistLdData; - for (k=0; k<sfbWidth; k++) - quantSpec[k] = quantSpecTmp[k]; - } +static INT FDKaacEnc_improveScf(const FIXP_DBL *spec, SHORT *quantSpec, + SHORT *quantSpecTmp, INT sfbWidth, + FIXP_DBL threshLdData, INT scf, INT minScf, + FIXP_DBL *distLdData, INT *minScfCalculated, + INT dZoneQuantEnable) { + FIXP_DBL sfbDistLdData; + INT scfBest = scf; + INT k; + FIXP_DBL distFactorLdData = FL2FXCONST_DBL(-0.0050301265); /* ld64(1/1.25) */ + + /* calc real distortion */ + sfbDistLdData = + FDKaacEnc_calcSfbDist(spec, quantSpec, sfbWidth, scf, dZoneQuantEnable); + *minScfCalculated = scf; + /* nmr > 1.25 -> try to improve nmr */ + if (sfbDistLdData > (threshLdData - distFactorLdData)) { + INT scfEstimated = scf; + FIXP_DBL sfbDistBestLdData = sfbDistLdData; + INT cnt; + /* improve by bigger scf ? */ + cnt = 0; + + while ((sfbDistLdData > (threshLdData - distFactorLdData)) && + (cnt++ < UPCOUNT_LIMIT)) { + scf++; + sfbDistLdData = FDKaacEnc_calcSfbDist(spec, quantSpecTmp, sfbWidth, scf, + dZoneQuantEnable); + + if (sfbDistLdData < sfbDistBestLdData) { + scfBest = scf; + sfbDistBestLdData = sfbDistLdData; + for (k = 0; k < sfbWidth; k++) quantSpec[k] = quantSpecTmp[k]; } - /* improve by smaller scf ? */ - cnt = 0; - scf = scfEstimated; - sfbDistLdData = sfbDistBestLdData; - while ((sfbDistLdData > (threshLdData-distFactorLdData)) && (cnt++ < 1) && (scf > minScf)) { - scf--; - sfbDistLdData = FDKaacEnc_calcSfbDist(spec, - quantSpecTmp, - sfbWidth, - scf, - dZoneQuantEnable); - - if (sfbDistLdData < sfbDistBestLdData) { - scfBest = scf; - sfbDistBestLdData = sfbDistLdData; - for (k=0; k<sfbWidth; k++) - quantSpec[k] = quantSpecTmp[k]; - } - *minScfCalculated = scf; + } + /* improve by smaller scf ? */ + cnt = 0; + scf = scfEstimated; + sfbDistLdData = sfbDistBestLdData; + while ((sfbDistLdData > (threshLdData - distFactorLdData)) && (cnt++ < 1) && + (scf > minScf)) { + scf--; + sfbDistLdData = FDKaacEnc_calcSfbDist(spec, quantSpecTmp, sfbWidth, scf, + dZoneQuantEnable); + + if (sfbDistLdData < sfbDistBestLdData) { + scfBest = scf; + sfbDistBestLdData = sfbDistLdData; + for (k = 0; k < sfbWidth; k++) quantSpec[k] = quantSpecTmp[k]; } - *distLdData = sfbDistBestLdData; - } - else { /* nmr <= 1.25 -> try to find bigger scf to use less bits */ - FIXP_DBL sfbDistBestLdData = sfbDistLdData; - FIXP_DBL sfbDistAllowedLdData = fixMin(sfbDistLdData-distFactorLdData,threshLdData); - int cnt; - for (cnt=0; cnt<3; cnt++) { - scf++; - sfbDistLdData = FDKaacEnc_calcSfbDist(spec, - quantSpecTmp, - sfbWidth, - scf, - dZoneQuantEnable); - - if (sfbDistLdData < sfbDistAllowedLdData) { - *minScfCalculated = scfBest+1; - scfBest = scf; - sfbDistBestLdData = sfbDistLdData; - for (k=0; k<sfbWidth; k++) - quantSpec[k] = quantSpecTmp[k]; - } + *minScfCalculated = scf; + } + *distLdData = sfbDistBestLdData; + } else { /* nmr <= 1.25 -> try to find bigger scf to use less bits */ + FIXP_DBL sfbDistBestLdData = sfbDistLdData; + FIXP_DBL sfbDistAllowedLdData = + fixMin(sfbDistLdData - distFactorLdData, threshLdData); + int cnt; + for (cnt = 0; cnt < UPCOUNT_LIMIT; cnt++) { + scf++; + sfbDistLdData = FDKaacEnc_calcSfbDist(spec, quantSpecTmp, sfbWidth, scf, + dZoneQuantEnable); + + if (sfbDistLdData < sfbDistAllowedLdData) { + *minScfCalculated = scfBest + 1; + scfBest = scf; + sfbDistBestLdData = sfbDistLdData; + for (k = 0; k < sfbWidth; k++) quantSpec[k] = quantSpecTmp[k]; } - *distLdData = sfbDistBestLdData; - } + } + *distLdData = sfbDistBestLdData; + } - /* return best scalefactor */ - return scfBest; + /* return best scalefactor */ + return scfBest; } /* Function: FDKaacEnc_assimilateSingleScf */ -static void FDKaacEnc_assimilateSingleScf(PSY_OUT_CHANNEL *psyOutChan, - QC_OUT_CHANNEL *qcOutChannel, - SHORT *quantSpec, - SHORT *quantSpecTmp, - INT dZoneQuantEnable, - INT *scf, - INT *minScf, - FIXP_DBL *sfbDist, - FIXP_DBL *sfbConstPePart, - FIXP_DBL *sfbFormFactorLdData, - FIXP_DBL *sfbNRelevantLines, - INT *minScfCalculated, - INT restartOnSuccess) -{ +static void FDKaacEnc_assimilateSingleScf( + const PSY_OUT_CHANNEL *psyOutChan, const QC_OUT_CHANNEL *qcOutChannel, + SHORT *quantSpec, SHORT *quantSpecTmp, INT dZoneQuantEnable, INT *scf, + const INT *minScf, FIXP_DBL *sfbDist, FIXP_DBL *sfbConstPePart, + const FIXP_DBL *sfbFormFactorLdData, const FIXP_DBL *sfbNRelevantLines, + INT *minScfCalculated, INT restartOnSuccess) { INT sfbLast, sfbAct, sfbNext; INT scfAct, *scfLast, *scfNext, scfMin, scfMax; INT sfbWidth, sfbOffs; @@ -483,77 +475,82 @@ static void FDKaacEnc_assimilateSingleScf(PSY_OUT_CHANNEL *psyOutChan, FIXP_DBL deltaPeLast[MAX_GROUPED_SFB]; INT updateMinScfCalculated; - for (i=0; i<psyOutChan->sfbCnt; i++) { + for (i = 0; i < psyOutChan->sfbCnt; i++) { prevScfLast[i] = FDK_INT_MAX; prevScfNext[i] = FDK_INT_MAX; deltaPeLast[i] = (FIXP_DBL)FDK_INT_MAX; } sfbLast = -1; - sfbAct = -1; + sfbAct = -1; sfbNext = -1; scfLast = 0; scfNext = 0; - scfMin = FDK_INT_MAX; - scfMax = FDK_INT_MAX; + scfMin = FDK_INT_MAX; + scfMax = FDK_INT_MAX; do { /* search for new relevant sfb */ sfbNext++; while ((sfbNext < psyOutChan->sfbCnt) && (scf[sfbNext] == FDK_INT_MIN)) sfbNext++; - if ((sfbLast>=0) && (sfbAct>=0) && (sfbNext<psyOutChan->sfbCnt)) { + if ((sfbLast >= 0) && (sfbAct >= 0) && (sfbNext < psyOutChan->sfbCnt)) { /* relevant scfs to the left and to the right */ - scfAct = scf[sfbAct]; + scfAct = scf[sfbAct]; scfLast = scf + sfbLast; scfNext = scf + sfbNext; - scfMin = fixMin(*scfLast, *scfNext); - scfMax = fixMax(*scfLast, *scfNext); - } - else if ((sfbLast==-1) && (sfbAct>=0) && (sfbNext<psyOutChan->sfbCnt)) { + scfMin = fixMin(*scfLast, *scfNext); + scfMax = fixMax(*scfLast, *scfNext); + } else if ((sfbLast == -1) && (sfbAct >= 0) && + (sfbNext < psyOutChan->sfbCnt)) { /* first relevant scf */ - scfAct = scf[sfbAct]; + scfAct = scf[sfbAct]; scfLast = &scfAct; scfNext = scf + sfbNext; - scfMin = *scfNext; - scfMax = *scfNext; - } - else if ((sfbLast>=0) && (sfbAct>=0) && (sfbNext==psyOutChan->sfbCnt)) { + scfMin = *scfNext; + scfMax = *scfNext; + } else if ((sfbLast >= 0) && (sfbAct >= 0) && + (sfbNext == psyOutChan->sfbCnt)) { /* last relevant scf */ - scfAct = scf[sfbAct]; + scfAct = scf[sfbAct]; scfLast = scf + sfbLast; scfNext = &scfAct; - scfMin = *scfLast; - scfMax = *scfLast; + scfMin = *scfLast; + scfMax = *scfLast; } - if (sfbAct>=0) - scfMin = fixMax(scfMin, minScf[sfbAct]); - - if ((sfbAct >= 0) && - (sfbLast>=0 || sfbNext<psyOutChan->sfbCnt) && - (scfAct > scfMin) && - (scfAct <= scfMin+MAX_SCF_DELTA) && - (scfAct >= scfMax-MAX_SCF_DELTA) && - (*scfLast != prevScfLast[sfbAct] || - *scfNext != prevScfNext[sfbAct] || + if (sfbAct >= 0) scfMin = fixMax(scfMin, minScf[sfbAct]); + + if ((sfbAct >= 0) && (sfbLast >= 0 || sfbNext < psyOutChan->sfbCnt) && + (scfAct > scfMin) && (scfAct <= scfMin + MAX_SCF_DELTA) && + (scfAct >= scfMax - MAX_SCF_DELTA) && + (scfAct <= + fixMin(scfMin, fixMin(*scfLast, *scfNext)) + MAX_SCF_DELTA) && + (*scfLast != prevScfLast[sfbAct] || *scfNext != prevScfNext[sfbAct] || deltaPe < deltaPeLast[sfbAct])) { /* bigger than neighbouring scf found, try to use smaller scf */ success = 0; - sfbWidth = psyOutChan->sfbOffsets[sfbAct+1] - psyOutChan->sfbOffsets[sfbAct]; + sfbWidth = + psyOutChan->sfbOffsets[sfbAct + 1] - psyOutChan->sfbOffsets[sfbAct]; sfbOffs = psyOutChan->sfbOffsets[sfbAct]; /* estimate required bits for actual scf */ enLdData = qcOutChannel->sfbEnergyLdData[sfbAct]; - /* sfbConstPePart[sfbAct] = (float)log(6.75f*en/sfbFormFactor[sfbAct]) * LOG2_1; */ - /* 0.02152255861f = log(6.75)/log(2)/AS_PE_FAC_FLOAT; LOG2_1 is 1.0 for log2 */ + /* sfbConstPePart[sfbAct] = (float)log(6.75f*en/sfbFormFactor[sfbAct]) * + * LOG2_1; */ + /* 0.02152255861f = log(6.75)/log(2)/AS_PE_FAC_FLOAT; LOG2_1 is 1.0 for + * log2 */ /* 0.09375f = log(64.0)/log(2.0)/64.0 = scale of sfbFormFactorLdData */ if (sfbConstPePart[sfbAct] == (FIXP_DBL)FDK_INT_MIN) { - sfbConstPePart[sfbAct] = ((enLdData - sfbFormFactorLdData[sfbAct] - FL2FXCONST_DBL(0.09375f)) >> 1) + FL2FXCONST_DBL(0.02152255861f); + sfbConstPePart[sfbAct] = ((enLdData - sfbFormFactorLdData[sfbAct] - + FL2FXCONST_DBL(0.09375f)) >> + 1) + + FL2FXCONST_DBL(0.02152255861f); } - sfbPeOld = FDKaacEnc_calcSingleSpecPe(scfAct,sfbConstPePart[sfbAct],sfbNRelevantLines[sfbAct]) - +FDKaacEnc_countSingleScfBits(scfAct, *scfLast, *scfNext); + sfbPeOld = FDKaacEnc_calcSingleSpecPe(scfAct, sfbConstPePart[sfbAct], + sfbNRelevantLines[sfbAct]) + + FDKaacEnc_countSingleScfBits(scfAct, *scfLast, *scfNext); deltaPeNew = deltaPe; updateMinScfCalculated = 1; @@ -562,10 +559,12 @@ static void FDKaacEnc_assimilateSingleScf(PSY_OUT_CHANNEL *psyOutChan, /* estimate required bits for smaller scf */ scfAct--; /* check only if the same check was not done before */ - if (scfAct < minScfCalculated[sfbAct] && scfAct>=scfMax-MAX_SCF_DELTA){ + if (scfAct < minScfCalculated[sfbAct] && + scfAct >= scfMax - MAX_SCF_DELTA) { /* estimate required bits for new scf */ - sfbPeNew = FDKaacEnc_calcSingleSpecPe(scfAct,sfbConstPePart[sfbAct],sfbNRelevantLines[sfbAct]) - +FDKaacEnc_countSingleScfBits(scfAct,*scfLast, *scfNext); + sfbPeNew = FDKaacEnc_calcSingleSpecPe(scfAct, sfbConstPePart[sfbAct], + sfbNRelevantLines[sfbAct]) + + FDKaacEnc_countSingleScfBits(scfAct, *scfLast, *scfNext); /* use new scf if no increase in pe and quantization error is smaller */ @@ -573,28 +572,24 @@ static void FDKaacEnc_assimilateSingleScf(PSY_OUT_CHANNEL *psyOutChan, /* 0.0006103515625f = 10.0f/(2^(2*AS_PE_FAC_SHIFT)) */ if (deltaPeTmp < FL2FXCONST_DBL(0.0006103515625f)) { /* distortion of new scf */ - sfbDistNew = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs, - quantSpecTmp+sfbOffs, - sfbWidth, - scfAct, - dZoneQuantEnable); + sfbDistNew = FDKaacEnc_calcSfbDist( + qcOutChannel->mdctSpectrum + sfbOffs, quantSpecTmp + sfbOffs, + sfbWidth, scfAct, dZoneQuantEnable); if (sfbDistNew < sfbDist[sfbAct]) { /* success, replace scf by new one */ scf[sfbAct] = scfAct; sfbDist[sfbAct] = sfbDistNew; - for (k=0; k<sfbWidth; k++) - quantSpec[sfbOffs+k] = quantSpecTmp[sfbOffs+k]; + for (k = 0; k < sfbWidth; k++) + quantSpec[sfbOffs + k] = quantSpecTmp[sfbOffs + k]; deltaPeNew = deltaPeTmp; success = 1; } /* mark as already checked */ - if (updateMinScfCalculated) - minScfCalculated[sfbAct] = scfAct; - } - else { + if (updateMinScfCalculated) minScfCalculated[sfbAct] = scfAct; + } else { /* from this scf value on not all new values have been checked */ updateMinScfCalculated = 0; } @@ -612,18 +607,17 @@ static void FDKaacEnc_assimilateSingleScf(PSY_OUT_CHANNEL *psyOutChan, if (success && restartOnSuccess) { /* start again at first sfb */ sfbLast = -1; - sfbAct = -1; + sfbAct = -1; sfbNext = -1; scfLast = 0; scfNext = 0; - scfMin = FDK_INT_MAX; - scfMax = FDK_INT_MAX; + scfMin = FDK_INT_MAX; + scfMax = FDK_INT_MAX; success = 0; - } - else { + } else { /* shift sfbs for next band */ sfbLast = sfbAct; - sfbAct = sfbNext; + sfbAct = sfbNext; } } while (sfbNext < psyOutChan->sfbCnt); } @@ -632,18 +626,11 @@ static void FDKaacEnc_assimilateSingleScf(PSY_OUT_CHANNEL *psyOutChan, Function: FDKaacEnc_assimilateMultipleScf */ -static void FDKaacEnc_assimilateMultipleScf(PSY_OUT_CHANNEL *psyOutChan, - QC_OUT_CHANNEL *qcOutChannel, - SHORT *quantSpec, - SHORT *quantSpecTmp, - INT dZoneQuantEnable, - INT *scf, - INT *minScf, - FIXP_DBL *sfbDist, - FIXP_DBL *sfbConstPePart, - FIXP_DBL *sfbFormFactorLdData, - FIXP_DBL *sfbNRelevantLines) -{ +static void FDKaacEnc_assimilateMultipleScf( + PSY_OUT_CHANNEL *psyOutChan, QC_OUT_CHANNEL *qcOutChannel, SHORT *quantSpec, + SHORT *quantSpecTmp, INT dZoneQuantEnable, INT *scf, const INT *minScf, + FIXP_DBL *sfbDist, FIXP_DBL *sfbConstPePart, FIXP_DBL *sfbFormFactorLdData, + FIXP_DBL *sfbNRelevantLines) { INT sfb, startSfb, stopSfb; INT scfTmp[MAX_GROUPED_SFB], scfMin, scfMax, scfAct; INT possibleRegionFound; @@ -658,31 +645,29 @@ static void FDKaacEnc_assimilateMultipleScf(PSY_OUT_CHANNEL *psyOutChan, /* calc min and max scalfactors */ scfMin = FDK_INT_MAX; scfMax = FDK_INT_MIN; - for (sfb=0; sfb<sfbCnt; sfb++) { - if (scf[sfb]!=FDK_INT_MIN) { + for (sfb = 0; sfb < sfbCnt; sfb++) { + if (scf[sfb] != FDK_INT_MIN) { scfMin = fixMin(scfMin, scf[sfb]); scfMax = fixMax(scfMax, scf[sfb]); } } - if (scfMax != FDK_INT_MIN && scfMax <= scfMin+MAX_SCF_DELTA) { - + if (scfMax != FDK_INT_MIN && scfMax <= scfMin + MAX_SCF_DELTA) { scfAct = scfMax; do { /* try smaller scf */ scfAct--; - for (i=0; i<MAX_GROUPED_SFB; i++) - scfTmp[i] = scf[i]; + for (i = 0; i < MAX_GROUPED_SFB; i++) scfTmp[i] = scf[i]; stopSfb = 0; do { /* search for region where all scfs are bigger than scfAct */ sfb = stopSfb; - while (sfb<sfbCnt && (scf[sfb]==FDK_INT_MIN || scf[sfb] <= scfAct)) + while (sfb < sfbCnt && (scf[sfb] == FDK_INT_MIN || scf[sfb] <= scfAct)) sfb++; startSfb = sfb; sfb++; - while (sfb<sfbCnt && (scf[sfb]==FDK_INT_MIN || scf[sfb] > scfAct)) + while (sfb < sfbCnt && (scf[sfb] == FDK_INT_MIN || scf[sfb] > scfAct)) sfb++; stopSfb = sfb; @@ -690,7 +675,7 @@ static void FDKaacEnc_assimilateMultipleScf(PSY_OUT_CHANNEL *psyOutChan, possibleRegionFound = 0; if (startSfb < sfbCnt) { possibleRegionFound = 1; - for (sfb=startSfb; sfb<stopSfb; sfb++) { + for (sfb = startSfb; sfb < stopSfb; sfb++) { if (scf[sfb] != FDK_INT_MIN) if (scfAct < minScf[sfb]) { possibleRegionFound = 0; @@ -702,40 +687,38 @@ static void FDKaacEnc_assimilateMultipleScf(PSY_OUT_CHANNEL *psyOutChan, if (possibleRegionFound) { /* region found */ /* replace scfs in region by scfAct */ - for (sfb=startSfb; sfb<stopSfb; sfb++) { - if (scfTmp[sfb] != FDK_INT_MIN) - scfTmp[sfb] = scfAct; + for (sfb = startSfb; sfb < stopSfb; sfb++) { + if (scfTmp[sfb] != FDK_INT_MIN) scfTmp[sfb] = scfAct; } /* estimate change in bit demand for new scfs */ - deltaScfBits = FDKaacEnc_countScfBitsDiff(scf,scfTmp,sfbCnt,startSfb,stopSfb); + deltaScfBits = FDKaacEnc_countScfBitsDiff(scf, scfTmp, sfbCnt, + startSfb, stopSfb); - deltaSpecPe = FDKaacEnc_calcSpecPeDiff(psyOutChan, qcOutChannel, scf, scfTmp, sfbConstPePart, - sfbFormFactorLdData, sfbNRelevantLines, - startSfb, stopSfb); + deltaSpecPe = FDKaacEnc_calcSpecPeDiff( + psyOutChan, qcOutChannel, scf, scfTmp, sfbConstPePart, + sfbFormFactorLdData, sfbNRelevantLines, startSfb, stopSfb); deltaPeNew = deltaPe + (FIXP_DBL)deltaScfBits + deltaSpecPe; /* new bit demand small enough ? */ /* 0.0006103515625f = 10.0f/(2^(2*AS_PE_FAC_SHIFT)) */ if (deltaPeNew < FL2FXCONST_DBL(0.0006103515625f)) { - /* quantize and calc sum of new distortion */ distOldSum = distNewSum = FL2FXCONST_DBL(0.0f); - for (sfb=startSfb; sfb<stopSfb; sfb++) { + for (sfb = startSfb; sfb < stopSfb; sfb++) { if (scfTmp[sfb] != FDK_INT_MIN) { distOldSum += CalcInvLdData(sfbDist[sfb]) >> DIST_FAC_SHIFT; - sfbWidth = psyOutChan->sfbOffsets[sfb+1] - psyOutChan->sfbOffsets[sfb]; + sfbWidth = psyOutChan->sfbOffsets[sfb + 1] - + psyOutChan->sfbOffsets[sfb]; sfbOffs = psyOutChan->sfbOffsets[sfb]; - sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs, - quantSpecTmp+sfbOffs, - sfbWidth, - scfAct, - dZoneQuantEnable); + sfbDistNew[sfb] = FDKaacEnc_calcSfbDist( + qcOutChannel->mdctSpectrum + sfbOffs, + quantSpecTmp + sfbOffs, sfbWidth, scfAct, dZoneQuantEnable); - if (sfbDistNew[sfb] >qcOutChannel->sfbThresholdLdData[sfb]) { + if (sfbDistNew[sfb] > qcOutChannel->sfbThresholdLdData[sfb]) { /* no improvement, skip further dist. calculations */ distNewSum = distOldSum << 1; break; @@ -746,20 +729,19 @@ static void FDKaacEnc_assimilateMultipleScf(PSY_OUT_CHANNEL *psyOutChan, /* distortion smaller ? -> use new scalefactors */ if (distNewSum < distOldSum) { deltaPe = deltaPeNew; - for (sfb=startSfb; sfb<stopSfb; sfb++) { + for (sfb = startSfb; sfb < stopSfb; sfb++) { if (scf[sfb] != FDK_INT_MIN) { - sfbWidth = psyOutChan->sfbOffsets[sfb+1] - + sfbWidth = psyOutChan->sfbOffsets[sfb + 1] - psyOutChan->sfbOffsets[sfb]; sfbOffs = psyOutChan->sfbOffsets[sfb]; scf[sfb] = scfAct; sfbDist[sfb] = sfbDistNew[sfb]; - for (k=0; k<sfbWidth; k++) - quantSpec[sfbOffs+k] = quantSpecTmp[sfbOffs+k]; + for (k = 0; k < sfbWidth; k++) + quantSpec[sfbOffs + k] = quantSpecTmp[sfbOffs + k]; } } } - } } @@ -773,18 +755,11 @@ static void FDKaacEnc_assimilateMultipleScf(PSY_OUT_CHANNEL *psyOutChan, Function: FDKaacEnc_FDKaacEnc_assimilateMultipleScf2 */ -static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutChan, - QC_OUT_CHANNEL *qcOutChannel, - SHORT *quantSpec, - SHORT *quantSpecTmp, - INT dZoneQuantEnable, - INT *scf, - INT *minScf, - FIXP_DBL *sfbDist, - FIXP_DBL *sfbConstPePart, - FIXP_DBL *sfbFormFactorLdData, - FIXP_DBL *sfbNRelevantLines) -{ +static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2( + PSY_OUT_CHANNEL *psyOutChan, QC_OUT_CHANNEL *qcOutChannel, SHORT *quantSpec, + SHORT *quantSpecTmp, INT dZoneQuantEnable, INT *scf, const INT *minScf, + FIXP_DBL *sfbDist, FIXP_DBL *sfbConstPePart, FIXP_DBL *sfbFormFactorLdData, + FIXP_DBL *sfbNRelevantLines) { INT sfb, startSfb, stopSfb; INT scfTmp[MAX_GROUPED_SFB], scfAct, scfNew; INT scfPrev, scfNext, scfPrevNextMin, scfPrevNextMax, scfLo, scfHi; @@ -798,13 +773,13 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh FIXP_DBL deltaPeNew = FL2FXCONST_DBL(0.0f); INT sfbCnt = psyOutChan->sfbCnt; INT bSuccess, bCheckScf; - INT i,k; + INT i, k; /* calc min and max scalfactors */ scfMin = FDK_INT_MAX; scfMax = FDK_INT_MIN; - for (sfb=0; sfb<sfbCnt; sfb++) { - if (scf[sfb]!=FDK_INT_MIN) { + for (sfb = 0; sfb < sfbCnt; sfb++) { + if (scf[sfb] != FDK_INT_MIN) { scfMin = fixMin(scfMin, scf[sfb]); scfMax = fixMax(scfMax, scf[sfb]); } @@ -817,12 +792,12 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh scfPrev = scfAct; sfb = stopSfb; - while (sfb<sfbCnt && (scf[sfb]==FDK_INT_MIN)) - sfb++; + while (sfb < sfbCnt && (scf[sfb] == FDK_INT_MIN)) sfb++; startSfb = sfb; scfAct = scf[startSfb]; sfb++; - while (sfb<sfbCnt && ((scf[sfb]==FDK_INT_MIN) || (scf[sfb]==scf[startSfb]))) + while (sfb < sfbCnt && + ((scf[sfb] == FDK_INT_MIN) || (scf[sfb] == scf[startSfb]))) sfb++; stopSfb = sfb; @@ -831,8 +806,7 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh else scfNext = scfAct; - if (scfPrev == FDK_INT_MIN) - scfPrev = scfAct; + if (scfPrev == FDK_INT_MIN) scfPrev = scfAct; scfPrevNextMax = fixMax(scfPrev, scfNext); scfPrevNextMin = fixMin(scfPrev, scfNext); @@ -847,39 +821,49 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh else scfLo = scfPrevNextMax; - if (startSfb < sfbCnt && scfHi-scfLo <= MAX_SCF_DELTA) { /* region found */ + if (startSfb < sfbCnt && + scfHi - scfLo <= MAX_SCF_DELTA) { /* region found */ /* 1. try to save bits by coarser quantization */ if (scfHi > scf[startSfb]) { /* calculate the allowed distortion */ - for (sfb=startSfb; sfb<stopSfb; sfb++) { + for (sfb = startSfb; sfb < stopSfb; sfb++) { if (scf[sfb] != FDK_INT_MIN) { - /* sfbDistMax[sfb] = (float)pow(qcOutChannel->sfbThreshold[sfb]*sfbDist[sfb]*sfbDist[sfb],1.0f/3.0f); */ - /* sfbDistMax[sfb] = fixMax(sfbDistMax[sfb],qcOutChannel->sfbEnergy[sfb]*FL2FXCONST_DBL(1.e-3f)); */ + /* sfbDistMax[sfb] = + * (float)pow(qcOutChannel->sfbThreshold[sfb]*sfbDist[sfb]*sfbDist[sfb],1.0f/3.0f); + */ + /* sfbDistMax[sfb] = + * fixMax(sfbDistMax[sfb],qcOutChannel->sfbEnergy[sfb]*FL2FXCONST_DBL(1.e-3f)); + */ /* -0.15571537944 = ld64(1.e-3f)*/ - sfbDistMax[sfb] = fMult(FL2FXCONST_DBL(1.0f/3.0f),qcOutChannel->sfbThresholdLdData[sfb])+fMult(FL2FXCONST_DBL(1.0f/3.0f),sfbDist[sfb])+fMult(FL2FXCONST_DBL(1.0f/3.0f),sfbDist[sfb]); - sfbDistMax[sfb] = fixMax(sfbDistMax[sfb],qcOutChannel->sfbEnergyLdData[sfb]-FL2FXCONST_DBL(0.15571537944)); - sfbDistMax[sfb] = fixMin(sfbDistMax[sfb],qcOutChannel->sfbThresholdLdData[sfb]); + sfbDistMax[sfb] = fMult(FL2FXCONST_DBL(1.0f / 3.0f), + qcOutChannel->sfbThresholdLdData[sfb]) + + fMult(FL2FXCONST_DBL(1.0f / 3.0f), sfbDist[sfb]) + + fMult(FL2FXCONST_DBL(1.0f / 3.0f), sfbDist[sfb]); + sfbDistMax[sfb] = + fixMax(sfbDistMax[sfb], qcOutChannel->sfbEnergyLdData[sfb] - + FL2FXCONST_DBL(0.15571537944)); + sfbDistMax[sfb] = + fixMin(sfbDistMax[sfb], qcOutChannel->sfbThresholdLdData[sfb]); } } /* loop over all possible scf values for this region */ bCheckScf = 1; - for (scfNew=scf[startSfb]+1; scfNew<=scfHi; scfNew++) { - for (k=0; k<MAX_GROUPED_SFB; k++) - scfTmp[k] = scf[k]; + for (scfNew = scf[startSfb] + 1; scfNew <= scfHi; scfNew++) { + for (k = 0; k < MAX_GROUPED_SFB; k++) scfTmp[k] = scf[k]; /* replace scfs in region by scfNew */ - for (sfb=startSfb; sfb<stopSfb; sfb++) { - if (scfTmp[sfb] != FDK_INT_MIN) - scfTmp[sfb] = scfNew; + for (sfb = startSfb; sfb < stopSfb; sfb++) { + if (scfTmp[sfb] != FDK_INT_MIN) scfTmp[sfb] = scfNew; } /* estimate change in bit demand for new scfs */ - deltaScfBits = FDKaacEnc_countScfBitsDiff(scf,scfTmp,sfbCnt,startSfb,stopSfb); + deltaScfBits = FDKaacEnc_countScfBitsDiff(scf, scfTmp, sfbCnt, + startSfb, stopSfb); - deltaSpecPe = FDKaacEnc_calcSpecPeDiff(psyOutChan, qcOutChannel, scf, scfTmp, sfbConstPePart, - sfbFormFactorLdData, sfbNRelevantLines, - startSfb, stopSfb); + deltaSpecPe = FDKaacEnc_calcSpecPeDiff( + psyOutChan, qcOutChannel, scf, scfTmp, sfbConstPePart, + sfbFormFactorLdData, sfbNRelevantLines, startSfb, stopSfb); deltaPeNew = deltaPe + (FIXP_DBL)deltaScfBits + deltaSpecPe; @@ -888,13 +872,12 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh bSuccess = 1; /* quantize and calc sum of new distortion */ - for (sfb=startSfb; sfb<stopSfb; sfb++) { + for (sfb = startSfb; sfb < stopSfb; sfb++) { if (scfTmp[sfb] != FDK_INT_MIN) { - sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs[sfb], - quantSpecTmp+sfbOffs[sfb], - sfbOffs[sfb+1]-sfbOffs[sfb], - scfNew, - dZoneQuantEnable); + sfbDistNew[sfb] = FDKaacEnc_calcSfbDist( + qcOutChannel->mdctSpectrum + sfbOffs[sfb], + quantSpecTmp + sfbOffs[sfb], + sfbOffs[sfb + 1] - sfbOffs[sfb], scfNew, dZoneQuantEnable); if (sfbDistNew[sfb] > sfbDistMax[sfb]) { /* no improvement, skip further dist. calculations */ @@ -908,18 +891,19 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh } } } - if (bCheckScf==0) /* further calculations useless ? */ - break; + if (bCheckScf == 0) /* further calculations useless ? */ + break; /* distortion small enough ? -> use new scalefactors */ if (bSuccess) { deltaPe = deltaPeNew; - for (sfb=startSfb; sfb<stopSfb; sfb++) { + for (sfb = startSfb; sfb < stopSfb; sfb++) { if (scf[sfb] != FDK_INT_MIN) { scf[sfb] = scfNew; sfbDist[sfb] = sfbDistNew[sfb]; - for (k=0; k<sfbOffs[sfb+1]-sfbOffs[sfb]; k++) - quantSpec[sfbOffs[sfb]+k] = quantSpecTmp[sfbOffs[sfb]+k]; + for (k = 0; k < sfbOffs[sfb + 1] - sfbOffs[sfb]; k++) + quantSpec[sfbOffs[sfb] + k] = + quantSpecTmp[sfbOffs[sfb] + k]; } } } @@ -930,52 +914,47 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh /* 2. only if coarser quantization was not successful, try to find a better solution by finer quantization and reducing bits for scalefactor coding */ - if (scfAct==scf[startSfb] && - scfLo < scfAct && - scfMax-scfMin <= MAX_SCF_DELTA) { - + if (scfAct == scf[startSfb] && scfLo < scfAct && + scfMax - scfMin <= MAX_SCF_DELTA) { int bminScfViolation = 0; - for (k=0; k<MAX_GROUPED_SFB; k++) - scfTmp[k] = scf[k]; + for (k = 0; k < MAX_GROUPED_SFB; k++) scfTmp[k] = scf[k]; scfNew = scfLo; /* replace scfs in region by scfNew and check if in all sfb scfNew >= minScf[sfb] */ - for (sfb=startSfb; sfb<stopSfb; sfb++) { + for (sfb = startSfb; sfb < stopSfb; sfb++) { if (scfTmp[sfb] != FDK_INT_MIN) { scfTmp[sfb] = scfNew; - if (scfNew < minScf[sfb]) - bminScfViolation = 1; + if (scfNew < minScf[sfb]) bminScfViolation = 1; } } if (!bminScfViolation) { /* estimate change in bit demand for new scfs */ - deltaScfBits = FDKaacEnc_countScfBitsDiff(scf,scfTmp,sfbCnt,startSfb,stopSfb); + deltaScfBits = FDKaacEnc_countScfBitsDiff(scf, scfTmp, sfbCnt, + startSfb, stopSfb); - deltaSpecPe = FDKaacEnc_calcSpecPeDiff(psyOutChan, qcOutChannel, scf, scfTmp, sfbConstPePart, - sfbFormFactorLdData, sfbNRelevantLines, - startSfb, stopSfb); + deltaSpecPe = FDKaacEnc_calcSpecPeDiff( + psyOutChan, qcOutChannel, scf, scfTmp, sfbConstPePart, + sfbFormFactorLdData, sfbNRelevantLines, startSfb, stopSfb); deltaPeNew = deltaPe + (FIXP_DBL)deltaScfBits + deltaSpecPe; } /* new bit demand small enough ? */ if (!bminScfViolation && deltaPeNew < FL2FXCONST_DBL(0.0f)) { - /* quantize and calc sum of new distortion */ distOldSum = distNewSum = FL2FXCONST_DBL(0.0f); - for (sfb=startSfb; sfb<stopSfb; sfb++) { + for (sfb = startSfb; sfb < stopSfb; sfb++) { if (scfTmp[sfb] != FDK_INT_MIN) { distOldSum += CalcInvLdData(sfbDist[sfb]) >> DIST_FAC_SHIFT; - sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs[sfb], - quantSpecTmp+sfbOffs[sfb], - sfbOffs[sfb+1]-sfbOffs[sfb], - scfNew, - dZoneQuantEnable); + sfbDistNew[sfb] = FDKaacEnc_calcSfbDist( + qcOutChannel->mdctSpectrum + sfbOffs[sfb], + quantSpecTmp + sfbOffs[sfb], sfbOffs[sfb + 1] - sfbOffs[sfb], + scfNew, dZoneQuantEnable); if (sfbDistNew[sfb] > qcOutChannel->sfbThresholdLdData[sfb]) { /* no improvement, skip further dist. calculations */ @@ -986,15 +965,15 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh } } /* distortion smaller ? -> use new scalefactors */ - if (distNewSum < fMult(FL2FXCONST_DBL(0.8f),distOldSum)) { + if (distNewSum < fMult(FL2FXCONST_DBL(0.8f), distOldSum)) { deltaPe = deltaPeNew; - for (sfb=startSfb; sfb<stopSfb; sfb++) { + for (sfb = startSfb; sfb < stopSfb; sfb++) { if (scf[sfb] != FDK_INT_MIN) { scf[sfb] = scfNew; sfbDist[sfb] = sfbDistNew[sfb]; - for (k=0; k<sfbOffs[sfb+1]-sfbOffs[sfb]; k++) - quantSpec[sfbOffs[sfb]+k] = quantSpecTmp[sfbOffs[sfb]+k]; + for (k = 0; k < sfbOffs[sfb + 1] - sfbOffs[sfb]; k++) + quantSpec[sfbOffs[sfb] + k] = quantSpecTmp[sfbOffs[sfb] + k]; } } } @@ -1003,43 +982,45 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh /* 3. try to find a better solution (save bits) by only reducing the scalefactor without new quantization */ - if (scfMax-scfMin <= MAX_SCF_DELTA-3) { /* 3 bec. scf is reduced 3 times, - see for loop below */ + if (scfMax - scfMin <= + MAX_SCF_DELTA - 3) { /* 3 bec. scf is reduced 3 times, + see for loop below */ - for (k=0; k<sfbCnt; k++) - scfTmp[k] = scf[k]; + for (k = 0; k < sfbCnt; k++) scfTmp[k] = scf[k]; - for (i=0; i<3; i++) { - scfNew = scfTmp[startSfb]-1; + for (i = 0; i < 3; i++) { + scfNew = scfTmp[startSfb] - 1; /* replace scfs in region by scfNew */ - for (sfb=startSfb; sfb<stopSfb; sfb++) { - if (scfTmp[sfb] != FDK_INT_MIN) - scfTmp[sfb] = scfNew; + for (sfb = startSfb; sfb < stopSfb; sfb++) { + if (scfTmp[sfb] != FDK_INT_MIN) scfTmp[sfb] = scfNew; } /* estimate change in bit demand for new scfs */ - deltaScfBits = FDKaacEnc_countScfBitsDiff(scf,scfTmp,sfbCnt,startSfb,stopSfb); + deltaScfBits = FDKaacEnc_countScfBitsDiff(scf, scfTmp, sfbCnt, + startSfb, stopSfb); deltaPeNew = deltaPe + (FIXP_DBL)deltaScfBits; /* new bit demand small enough ? */ if (deltaPeNew <= FL2FXCONST_DBL(0.0f)) { - bSuccess = 1; distOldSum = distNewSum = FL2FXCONST_DBL(0.0f); - for (sfb=startSfb; sfb<stopSfb; sfb++) { + for (sfb = startSfb; sfb < stopSfb; sfb++) { if (scfTmp[sfb] != FDK_INT_MIN) { FIXP_DBL sfbEnQ; /* calc the energy and distortion of the quantized spectrum for a smaller scf */ - FDKaacEnc_calcSfbQuantEnergyAndDist(qcOutChannel->mdctSpectrum+sfbOffs[sfb], - quantSpec+sfbOffs[sfb], - sfbOffs[sfb+1]-sfbOffs[sfb], scfNew, - &sfbEnQ, &sfbDistNew[sfb]); + FDKaacEnc_calcSfbQuantEnergyAndDist( + qcOutChannel->mdctSpectrum + sfbOffs[sfb], + quantSpec + sfbOffs[sfb], sfbOffs[sfb + 1] - sfbOffs[sfb], + scfNew, &sfbEnQ, &sfbDistNew[sfb]); distOldSum += CalcInvLdData(sfbDist[sfb]) >> DIST_FAC_SHIFT; distNewSum += CalcInvLdData(sfbDistNew[sfb]) >> DIST_FAC_SHIFT; /* 0.00259488556167 = ld64(1.122f) */ /* -0.00778722686652 = ld64(0.7079f) */ - if ((sfbDistNew[sfb] > (sfbDist[sfb]+FL2FXCONST_DBL(0.00259488556167f))) || (sfbEnQ < (qcOutChannel->sfbEnergyLdData[sfb] - FL2FXCONST_DBL(0.00778722686652f)))){ + if ((sfbDistNew[sfb] > + (sfbDist[sfb] + FL2FXCONST_DBL(0.00259488556167f))) || + (sfbEnQ < (qcOutChannel->sfbEnergyLdData[sfb] - + FL2FXCONST_DBL(0.00778722686652f)))) { bSuccess = 0; break; } @@ -1048,7 +1029,7 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh /* distortion smaller ? -> use new scalefactors */ if (distNewSum < distOldSum && bSuccess) { deltaPe = deltaPeNew; - for (sfb=startSfb; sfb<stopSfb; sfb++) { + for (sfb = startSfb; sfb < stopSfb; sfb++) { if (scf[sfb] != FDK_INT_MIN) { scf[sfb] = scfNew; sfbDist[sfb] = sfbDistNew[sfb]; @@ -1060,20 +1041,13 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh } } } while (stopSfb <= sfbCnt); - } -static void -FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(QC_OUT_CHANNEL *qcOutChannel, - PSY_OUT_CHANNEL *psyOutChannel, - INT *RESTRICT scf, - INT *RESTRICT globalGain, - FIXP_DBL *RESTRICT sfbFormFactorLdData - ,const INT invQuant, - SHORT *RESTRICT quantSpec, - const INT dZoneQuantEnable - ) -{ +static void FDKaacEnc_EstimateScaleFactorsChannel( + QC_OUT_CHANNEL *qcOutChannel, PSY_OUT_CHANNEL *psyOutChannel, + INT *RESTRICT scf, INT *RESTRICT globalGain, + FIXP_DBL *RESTRICT sfbFormFactorLdData, const INT invQuant, + SHORT *RESTRICT quantSpec, const INT dZoneQuantEnable) { INT i, j, sfb, sfbOffs; INT scfInt; INT maxSf; @@ -1084,46 +1058,45 @@ FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(QC_OUT_CHANNEL *qcOutChannel, FIXP_DBL thresholdPartLdData; FIXP_DBL scfFract; FIXP_DBL maxSpec; - FIXP_DBL absSpec; INT minScfCalculated[MAX_GROUPED_SFB]; FIXP_DBL sfbDistLdData[MAX_GROUPED_SFB]; - C_ALLOC_SCRATCH_START(quantSpecTmp, SHORT, (1024)); + C_ALLOC_SCRATCH_START(quantSpecTmp, SHORT, (1024)) INT minSfMaxQuant[MAX_GROUPED_SFB]; - FIXP_DBL threshConstLdData=FL2FXCONST_DBL(0.04304511722f); /* log10(6.75)/log10(2.0)/64.0 */ - FIXP_DBL convConst=FL2FXCONST_DBL(0.30102999566f); /* log10(2.0) */ - FIXP_DBL c1Const=FL2FXCONST_DBL(-0.27083183594f); /* C1 = -69.33295 => C1/2^8 */ - + FIXP_DBL threshConstLdData = + FL2FXCONST_DBL(0.04304511722f); /* log10(6.75)/log10(2.0)/64.0 */ + FIXP_DBL convConst = FL2FXCONST_DBL(0.30102999566f); /* log10(2.0) */ + FIXP_DBL c1Const = + FL2FXCONST_DBL(-0.27083183594f); /* C1 = -69.33295 => C1/2^8 */ - - if (invQuant>0) { - FDKmemclear(quantSpec, (1024)*sizeof(SHORT)); + if (invQuant > 0) { + FDKmemclear(quantSpec, (1024) * sizeof(SHORT)); } /* scfs without energy or with thresh>energy are marked with FDK_INT_MIN */ - for(i=0; i<psyOutChannel->sfbCnt; i++) { + for (i = 0; i < psyOutChannel->sfbCnt; i++) { scf[i] = FDK_INT_MIN; } - for (i=0; i<MAX_GROUPED_SFB; i++) { + for (i = 0; i < MAX_GROUPED_SFB; i++) { minSfMaxQuant[i] = FDK_INT_MIN; } - for (sfbOffs=0; sfbOffs<psyOutChannel->sfbCnt; sfbOffs+=psyOutChannel->sfbPerGroup) { - for(sfb=0; sfb<psyOutChannel->maxSfbPerGroup; sfb++) { - - threshLdData = qcOutChannel->sfbThresholdLdData[sfbOffs+sfb]; - energyLdData = qcOutChannel->sfbEnergyLdData[sfbOffs+sfb]; - - sfbDistLdData[sfbOffs+sfb] = energyLdData; + for (sfbOffs = 0; sfbOffs < psyOutChannel->sfbCnt; + sfbOffs += psyOutChannel->sfbPerGroup) { + for (sfb = 0; sfb < psyOutChannel->maxSfbPerGroup; sfb++) { + threshLdData = qcOutChannel->sfbThresholdLdData[sfbOffs + sfb]; + energyLdData = qcOutChannel->sfbEnergyLdData[sfbOffs + sfb]; + sfbDistLdData[sfbOffs + sfb] = energyLdData; if (energyLdData > threshLdData) { FIXP_DBL tmp; /* energyPart = (float)log10(sfbFormFactor[sfbOffs+sfb]); */ /* 0.09375f = log(64.0)/log(2.0)/64.0 = scale of sfbFormFactorLdData */ - energyPartLdData = sfbFormFactorLdData[sfbOffs+sfb] + FL2FXCONST_DBL(0.09375f); + energyPartLdData = + sfbFormFactorLdData[sfbOffs + sfb] + FL2FXCONST_DBL(0.09375f); /* influence of allowed distortion */ /* thresholdPart = (float)log10(6.75*thresh+FLT_MIN); */ @@ -1133,165 +1106,166 @@ FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(QC_OUT_CHANNEL *qcOutChannel, /* scfFloat = 8.8585f * (thresholdPart - energyPart); */ scfFract = thresholdPartLdData - energyPartLdData; /* conversion from log2 to log10 */ - scfFract = fMult(convConst,scfFract); + scfFract = fMult(convConst, scfFract); /* (8.8585f * scfFract)/8 = 8/8 * scfFract + 0.8585 * scfFract/8 */ - scfFract = scfFract + fMult(FL2FXCONST_DBL(0.8585f),scfFract >> 3); + scfFract = scfFract + fMult(FL2FXCONST_DBL(0.8585f), scfFract >> 3); /* integer scalefactor */ /* scfInt = (int)floor(scfFloat); */ - scfInt = (INT)(scfFract>>((DFRACT_BITS-1)-3-LD_DATA_SHIFT)); /* 3 bits => scfFract/8.0; 6 bits => ld64 */ + scfInt = + (INT)(scfFract >> + ((DFRACT_BITS - 1) - 3 - + LD_DATA_SHIFT)); /* 3 bits => scfFract/8.0; 6 bits => ld64 */ /* maximum of spectrum */ maxSpec = FL2FXCONST_DBL(0.0f); - for(j=psyOutChannel->sfbOffsets[sfbOffs+sfb]; j<psyOutChannel->sfbOffsets[sfbOffs+sfb+1]; j++ ){ - absSpec = fixp_abs(qcOutChannel->mdctSpectrum[j]); - maxSpec = (absSpec > maxSpec) ? absSpec : maxSpec; + /* Unroll by 4, allow dual memory access */ + DWORD_ALIGNED(qcOutChannel->mdctSpectrum); + for (j = psyOutChannel->sfbOffsets[sfbOffs + sfb]; + j < psyOutChannel->sfbOffsets[sfbOffs + sfb + 1]; j += 4) { + maxSpec = fMax(maxSpec, + fMax(fMax(fAbs(qcOutChannel->mdctSpectrum[j + 0]), + fAbs(qcOutChannel->mdctSpectrum[j + 1])), + fMax(fAbs(qcOutChannel->mdctSpectrum[j + 2]), + fAbs(qcOutChannel->mdctSpectrum[j + 3])))); } - /* lower scf limit to avoid quantized values bigger than MAX_QUANT */ /* C1 = -69.33295f, C2 = 5.77078f = 4/log(2) */ /* minSfMaxQuant[sfbOffs+sfb] = (int)ceil(C1 + C2*log(maxSpec)); */ - /* C1/2^8 + 4/log(2.0)*log(maxSpec)/2^8 => C1/2^8 + log(maxSpec)/log(2.0)*4/2^8 => C1/2^8 + log(maxSpec)/log(2.0)/64.0 */ + /* C1/2^8 + 4/log(2.0)*log(maxSpec)/2^8 => C1/2^8 + + * log(maxSpec)/log(2.0)*4/2^8 => C1/2^8 + log(maxSpec)/log(2.0)/64.0 */ - //minSfMaxQuant[sfbOffs+sfb] = ((INT) ((c1Const + CalcLdData(maxSpec)) >> ((DFRACT_BITS-1)-8))) + 1; + // minSfMaxQuant[sfbOffs+sfb] = ((INT) ((c1Const + CalcLdData(maxSpec)) + // >> ((DFRACT_BITS-1)-8))) + 1; tmp = CalcLdData(maxSpec); - if (c1Const>FL2FXCONST_DBL(-1.f)-tmp) { - minSfMaxQuant[sfbOffs+sfb] = ((INT) ((c1Const + tmp) >> ((DFRACT_BITS-1)-8))) + 1; + if (c1Const > FL2FXCONST_DBL(-1.f) - tmp) { + minSfMaxQuant[sfbOffs + sfb] = + ((INT)((c1Const + tmp) >> ((DFRACT_BITS - 1) - 8))) + 1; + } else { + minSfMaxQuant[sfbOffs + sfb] = + ((INT)(FL2FXCONST_DBL(-1.f) >> ((DFRACT_BITS - 1) - 8))) + 1; } - else { - minSfMaxQuant[sfbOffs+sfb] = ((INT) (FL2FXCONST_DBL(-1.f) >> ((DFRACT_BITS-1)-8))) + 1; - } - - scfInt = fixMax(scfInt, minSfMaxQuant[sfbOffs+sfb]); + scfInt = fixMax(scfInt, minSfMaxQuant[sfbOffs + sfb]); /* find better scalefactor with analysis by synthesis */ - if (invQuant>0) { - scfInt = FDKaacEnc_improveScf(qcOutChannel->mdctSpectrum+psyOutChannel->sfbOffsets[sfbOffs+sfb], - quantSpec+psyOutChannel->sfbOffsets[sfbOffs+sfb], - quantSpecTmp+psyOutChannel->sfbOffsets[sfbOffs+sfb], - psyOutChannel->sfbOffsets[sfbOffs+sfb+1]-psyOutChannel->sfbOffsets[sfbOffs+sfb], - threshLdData, scfInt, minSfMaxQuant[sfbOffs+sfb], - &sfbDistLdData[sfbOffs+sfb], &minScfCalculated[sfbOffs+sfb], - dZoneQuantEnable - ); + if (invQuant > 0) { + scfInt = FDKaacEnc_improveScf( + qcOutChannel->mdctSpectrum + + psyOutChannel->sfbOffsets[sfbOffs + sfb], + quantSpec + psyOutChannel->sfbOffsets[sfbOffs + sfb], + quantSpecTmp + psyOutChannel->sfbOffsets[sfbOffs + sfb], + psyOutChannel->sfbOffsets[sfbOffs + sfb + 1] - + psyOutChannel->sfbOffsets[sfbOffs + sfb], + threshLdData, scfInt, minSfMaxQuant[sfbOffs + sfb], + &sfbDistLdData[sfbOffs + sfb], &minScfCalculated[sfbOffs + sfb], + dZoneQuantEnable); } - scf[sfbOffs+sfb] = scfInt; + scf[sfbOffs + sfb] = scfInt; } } } - - if (invQuant>1) { + if (invQuant > 0) { /* try to decrease scf differences */ FIXP_DBL sfbConstPePart[MAX_GROUPED_SFB]; FIXP_DBL sfbNRelevantLines[MAX_GROUPED_SFB]; - for (i=0; i<psyOutChannel->sfbCnt; i++) + for (i = 0; i < psyOutChannel->sfbCnt; i++) sfbConstPePart[i] = (FIXP_DBL)FDK_INT_MIN; - FDKaacEnc_calcSfbRelevantLines( sfbFormFactorLdData, - qcOutChannel->sfbEnergyLdData, - qcOutChannel->sfbThresholdLdData, - psyOutChannel->sfbOffsets, - psyOutChannel->sfbCnt, - psyOutChannel->sfbPerGroup, - psyOutChannel->maxSfbPerGroup, - sfbNRelevantLines); - - - FDKaacEnc_assimilateSingleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, - dZoneQuantEnable, - scf, - minSfMaxQuant, sfbDistLdData, sfbConstPePart, - sfbFormFactorLdData, sfbNRelevantLines, minScfCalculated, 1); - - if(invQuant > 1) { - FDKaacEnc_assimilateMultipleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, - dZoneQuantEnable, - scf, - minSfMaxQuant, sfbDistLdData, sfbConstPePart, - sfbFormFactorLdData, sfbNRelevantLines); - - FDKaacEnc_assimilateMultipleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, - dZoneQuantEnable, - scf, - minSfMaxQuant, sfbDistLdData, sfbConstPePart, - sfbFormFactorLdData, sfbNRelevantLines); - - - FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, - dZoneQuantEnable, - scf, - minSfMaxQuant, sfbDistLdData, sfbConstPePart, - sfbFormFactorLdData, sfbNRelevantLines); + FDKaacEnc_calcSfbRelevantLines( + sfbFormFactorLdData, qcOutChannel->sfbEnergyLdData, + qcOutChannel->sfbThresholdLdData, psyOutChannel->sfbOffsets, + psyOutChannel->sfbCnt, psyOutChannel->sfbPerGroup, + psyOutChannel->maxSfbPerGroup, sfbNRelevantLines); + + FDKaacEnc_assimilateSingleScf( + psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, dZoneQuantEnable, + scf, minSfMaxQuant, sfbDistLdData, sfbConstPePart, sfbFormFactorLdData, + sfbNRelevantLines, minScfCalculated, 1); + + if (invQuant > 1) { + FDKaacEnc_assimilateMultipleScf( + psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, + dZoneQuantEnable, scf, minSfMaxQuant, sfbDistLdData, sfbConstPePart, + sfbFormFactorLdData, sfbNRelevantLines); + + FDKaacEnc_FDKaacEnc_assimilateMultipleScf2( + psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, + dZoneQuantEnable, scf, minSfMaxQuant, sfbDistLdData, sfbConstPePart, + sfbFormFactorLdData, sfbNRelevantLines); } } - /* get min scalefac */ minSf = FDK_INT_MAX; - for (sfbOffs=0; sfbOffs<psyOutChannel->sfbCnt; sfbOffs+=psyOutChannel->sfbPerGroup) { + for (sfbOffs = 0; sfbOffs < psyOutChannel->sfbCnt; + sfbOffs += psyOutChannel->sfbPerGroup) { for (sfb = 0; sfb < psyOutChannel->maxSfbPerGroup; sfb++) { - if (scf[sfbOffs+sfb]!=FDK_INT_MIN) - minSf = fixMin(minSf,scf[sfbOffs+sfb]); + if (scf[sfbOffs + sfb] != FDK_INT_MIN) + minSf = fixMin(minSf, scf[sfbOffs + sfb]); } } /* limit scf delta */ - for (sfbOffs=0; sfbOffs<psyOutChannel->sfbCnt; sfbOffs+=psyOutChannel->sfbPerGroup) { + for (sfbOffs = 0; sfbOffs < psyOutChannel->sfbCnt; + sfbOffs += psyOutChannel->sfbPerGroup) { for (sfb = 0; sfb < psyOutChannel->maxSfbPerGroup; sfb++) { - if ((scf[sfbOffs+sfb] != FDK_INT_MIN) && (minSf+MAX_SCF_DELTA) < scf[sfbOffs+sfb]) { - scf[sfbOffs+sfb] = minSf + MAX_SCF_DELTA; + if ((scf[sfbOffs + sfb] != FDK_INT_MIN) && + (minSf + MAX_SCF_DELTA) < scf[sfbOffs + sfb]) { + scf[sfbOffs + sfb] = minSf + MAX_SCF_DELTA; if (invQuant > 0) { /* changed bands need to be quantized again */ - sfbDistLdData[sfbOffs+sfb] = - FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+psyOutChannel->sfbOffsets[sfbOffs+sfb], - quantSpec+psyOutChannel->sfbOffsets[sfbOffs+sfb], - psyOutChannel->sfbOffsets[sfbOffs+sfb+1]-psyOutChannel->sfbOffsets[sfbOffs+sfb], - scf[sfbOffs+sfb], - dZoneQuantEnable - ); + sfbDistLdData[sfbOffs + sfb] = FDKaacEnc_calcSfbDist( + qcOutChannel->mdctSpectrum + + psyOutChannel->sfbOffsets[sfbOffs + sfb], + quantSpec + psyOutChannel->sfbOffsets[sfbOffs + sfb], + psyOutChannel->sfbOffsets[sfbOffs + sfb + 1] - + psyOutChannel->sfbOffsets[sfbOffs + sfb], + scf[sfbOffs + sfb], dZoneQuantEnable); } } } } - /* get max scalefac for global gain */ maxSf = FDK_INT_MIN; - for (sfbOffs=0; sfbOffs<psyOutChannel->sfbCnt; sfbOffs+=psyOutChannel->sfbPerGroup) { + for (sfbOffs = 0; sfbOffs < psyOutChannel->sfbCnt; + sfbOffs += psyOutChannel->sfbPerGroup) { for (sfb = 0; sfb < psyOutChannel->maxSfbPerGroup; sfb++) { - maxSf = fixMax(maxSf,scf[sfbOffs+sfb]); + maxSf = fixMax(maxSf, scf[sfbOffs + sfb]); } } /* calc loop scalefactors, if spec is not all zero (i.e. maxSf == -99) */ - if( maxSf > FDK_INT_MIN ) { + if (maxSf > FDK_INT_MIN) { *globalGain = maxSf; - for (sfbOffs=0; sfbOffs<psyOutChannel->sfbCnt; sfbOffs+=psyOutChannel->sfbPerGroup) { + for (sfbOffs = 0; sfbOffs < psyOutChannel->sfbCnt; + sfbOffs += psyOutChannel->sfbPerGroup) { for (sfb = 0; sfb < psyOutChannel->maxSfbPerGroup; sfb++) { - if( scf[sfbOffs+sfb] == FDK_INT_MIN ) { - scf[sfbOffs+sfb] = 0; + if (scf[sfbOffs + sfb] == FDK_INT_MIN) { + scf[sfbOffs + sfb] = 0; /* set band explicitely to zero */ - for(j=psyOutChannel->sfbOffsets[sfbOffs+sfb]; j<psyOutChannel->sfbOffsets[sfbOffs+sfb+1]; j++ ) { + for (j = psyOutChannel->sfbOffsets[sfbOffs + sfb]; + j < psyOutChannel->sfbOffsets[sfbOffs + sfb + 1]; j++) { qcOutChannel->mdctSpectrum[j] = FL2FXCONST_DBL(0.0f); } - } - else { - scf[sfbOffs+sfb] = maxSf - scf[sfbOffs+sfb]; + } else { + scf[sfbOffs + sfb] = maxSf - scf[sfbOffs + sfb]; } } } - } - else{ + } else { *globalGain = 0; /* set spectrum explicitely to zero */ - for (sfbOffs=0; sfbOffs<psyOutChannel->sfbCnt; sfbOffs+=psyOutChannel->sfbPerGroup) { + for (sfbOffs = 0; sfbOffs < psyOutChannel->sfbCnt; + sfbOffs += psyOutChannel->sfbPerGroup) { for (sfb = 0; sfb < psyOutChannel->maxSfbPerGroup; sfb++) { - scf[sfbOffs+sfb] = 0; + scf[sfbOffs + sfb] = 0; /* set band explicitely to zero */ - for(j=psyOutChannel->sfbOffsets[sfbOffs+sfb]; j<psyOutChannel->sfbOffsets[sfbOffs+sfb+1]; j++ ) { + for (j = psyOutChannel->sfbOffsets[sfbOffs + sfb]; + j < psyOutChannel->sfbOffsets[sfbOffs + sfb + 1]; j++) { qcOutChannel->mdctSpectrum[j] = FL2FXCONST_DBL(0.0f); } } @@ -1299,32 +1273,20 @@ FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(QC_OUT_CHANNEL *qcOutChannel, } /* free quantSpecTmp from scratch */ - C_ALLOC_SCRATCH_END(quantSpecTmp, SHORT, (1024)); - - + C_ALLOC_SCRATCH_END(quantSpecTmp, SHORT, (1024)) } -void -FDKaacEnc_EstimateScaleFactors(PSY_OUT_CHANNEL *psyOutChannel[], - QC_OUT_CHANNEL* qcOutChannel[], - const int invQuant, - const INT dZoneQuantEnable, - const int nChannels) -{ +void FDKaacEnc_EstimateScaleFactors(PSY_OUT_CHANNEL *psyOutChannel[], + QC_OUT_CHANNEL *qcOutChannel[], + const INT invQuant, + const INT dZoneQuantEnable, + const INT nChannels) { int ch; - for (ch = 0; ch < nChannels; ch++) - { - FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(qcOutChannel[ch], - psyOutChannel[ch], - qcOutChannel[ch]->scf, - &qcOutChannel[ch]->globalGain, - qcOutChannel[ch]->sfbFormFactorLdData - ,invQuant, - qcOutChannel[ch]->quantSpec, - dZoneQuantEnable - ); + for (ch = 0; ch < nChannels; ch++) { + FDKaacEnc_EstimateScaleFactorsChannel( + qcOutChannel[ch], psyOutChannel[ch], qcOutChannel[ch]->scf, + &qcOutChannel[ch]->globalGain, qcOutChannel[ch]->sfbFormFactorLdData, + invQuant, qcOutChannel[ch]->quantSpec, dZoneQuantEnable); } - } - |