aboutsummaryrefslogtreecommitdiffstats
path: root/libSBRenc/src/ps_encode.cpp
diff options
context:
space:
mode:
authorFraunhofer IIS FDK <audio-fdk@iis.fraunhofer.de>2018-02-26 20:17:00 +0100
committerJean-Michel Trivi <jmtrivi@google.com>2018-04-19 11:21:15 -0700
commit6cfabd35363c3ef5e3b209b867169a500b3ccc3c (patch)
tree01c0a19f2735e8b5d2407555fe992d4230d089eb /libSBRenc/src/ps_encode.cpp
parent6288a1e34c4dede4c2806beb1736ece6580558c7 (diff)
downloadfdk-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 'libSBRenc/src/ps_encode.cpp')
-rw-r--r--libSBRenc/src/ps_encode.cpp1029
1 files changed, 503 insertions, 526 deletions
diff --git a/libSBRenc/src/ps_encode.cpp b/libSBRenc/src/ps_encode.cpp
index fec39e8..88d3131 100644
--- a/libSBRenc/src/ps_encode.cpp
+++ b/libSBRenc/src/ps_encode.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,121 +90,109 @@ Am Wolfsmantel 33
www.iis.fraunhofer.de/amm
amm-info@iis.fraunhofer.de
------------------------------------------------------------------------------------------------------------ */
+----------------------------------------------------------------------------- */
+
+/**************************** SBR encoder library ******************************
+
+ Author(s): M. Neuendorf, N. Rettelbach, M. Multrus
-/***************************** MPEG Audio Encoder ***************************
+ Description: PS parameter extraction, encoding
- Initial Authors: M. Neuendorf, N. Rettelbach, M. Multrus
- Contents/Description: PS parameter extraction, encoding
+*******************************************************************************/
-******************************************************************************/
/*!
\file
- \brief PS parameter extraction, encoding functions
+ \brief PS parameter extraction, encoding functions $Revision: 96441 $
*/
#include "ps_main.h"
-
-
-#include "sbr_ram.h"
#include "ps_encode.h"
-
#include "qmf.h"
-
-#include "ps_const.h"
#include "sbr_misc.h"
+#include "sbrenc_ram.h"
#include "genericStds.h"
-inline void FDKsbrEnc_addFIXP_DBL(const FIXP_DBL *X, const FIXP_DBL *Y, FIXP_DBL *Z, INT n)
-{
- for (INT i=0; i<n; i++)
- Z[i] = (X[i]>>1) + (Y[i]>>1);
+inline void FDKsbrEnc_addFIXP_DBL(const FIXP_DBL *X, const FIXP_DBL *Y,
+ FIXP_DBL *Z, INT n) {
+ for (INT i = 0; i < n; i++) Z[i] = (X[i] >> 1) + (Y[i] >> 1);
}
-#define LOG10_2_10 3.01029995664f /* 10.0f*log10(2.f) */
-
-static const INT iidGroupBordersLoRes[QMF_GROUPS_LO_RES + SUBQMF_GROUPS_LO_RES + 1] =
-{
- 0, 1, 2, 3, 4, 5, /* 6 subqmf subbands - 0th qmf subband */
- 6, 7, /* 2 subqmf subbands - 1st qmf subband */
- 8, 9, /* 2 subqmf subbands - 2nd qmf subband */
- 10, 11, 12, 13, 14, 15, 16, 18, 21, 25, 30, 42, 71
-};
+#define LOG10_2_10 3.01029995664f /* 10.0f*log10(2.f) */
-static const UCHAR iidGroupWidthLdLoRes[QMF_GROUPS_LO_RES + SUBQMF_GROUPS_LO_RES] =
-{
- 0, 0, 0, 0, 0, 0,
- 0, 0,
- 0, 0,
- 0, 0, 0, 0, 0, 0, 1, 2, 2, 3, 4, 5
-};
+static const INT
+ iidGroupBordersLoRes[QMF_GROUPS_LO_RES + SUBQMF_GROUPS_LO_RES + 1] = {
+ 0, 1, 2, 3, 4, 5, /* 6 subqmf subbands - 0th qmf subband */
+ 6, 7, /* 2 subqmf subbands - 1st qmf subband */
+ 8, 9, /* 2 subqmf subbands - 2nd qmf subband */
+ 10, 11, 12, 13, 14, 15, 16, 18, 21, 25, 30, 42, 71};
+static const UCHAR
+ iidGroupWidthLdLoRes[QMF_GROUPS_LO_RES + SUBQMF_GROUPS_LO_RES] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 3, 4, 5};
static const INT subband2parameter20[QMF_GROUPS_LO_RES + SUBQMF_GROUPS_LO_RES] =
-{
- 1, 0, 0, 1, 2, 3, /* 6 subqmf subbands - 0th qmf subband */
- 4, 5, /* 2 subqmf subbands - 1st qmf subband */
- 6, 7, /* 2 subqmf subbands - 2nd qmf subband */
- 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
-};
-
+ {1, 0, 0, 1, 2, 3, /* 6 subqmf subbands - 0th qmf subband */
+ 4, 5, /* 2 subqmf subbands - 1st qmf subband */
+ 6, 7, /* 2 subqmf subbands - 2nd qmf subband */
+ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
typedef enum {
MAX_TIME_DIFF_FRAMES = 20,
- MAX_PS_NOHEADER_CNT = 10,
- MAX_NOENV_CNT = 10,
+ MAX_PS_NOHEADER_CNT = 10,
+ MAX_NOENV_CNT = 10,
DO_NOT_USE_THIS_MODE = 0x7FFFFF
} __PS_CONSTANTS;
-
-
static const FIXP_DBL iidQuant_fx[15] = {
- (FIXP_DBL)0xce000000, (FIXP_DBL)0xdc000000, (FIXP_DBL)0xe4000000, (FIXP_DBL)0xec000000, (FIXP_DBL)0xf2000000, (FIXP_DBL)0xf8000000, (FIXP_DBL)0xfc000000, (FIXP_DBL)0x00000000,
- (FIXP_DBL)0x04000000, (FIXP_DBL)0x08000000, (FIXP_DBL)0x0e000000, (FIXP_DBL)0x14000000, (FIXP_DBL)0x1c000000, (FIXP_DBL)0x24000000, (FIXP_DBL)0x32000000
-};
+ (FIXP_DBL)0xce000000, (FIXP_DBL)0xdc000000, (FIXP_DBL)0xe4000000,
+ (FIXP_DBL)0xec000000, (FIXP_DBL)0xf2000000, (FIXP_DBL)0xf8000000,
+ (FIXP_DBL)0xfc000000, (FIXP_DBL)0x00000000, (FIXP_DBL)0x04000000,
+ (FIXP_DBL)0x08000000, (FIXP_DBL)0x0e000000, (FIXP_DBL)0x14000000,
+ (FIXP_DBL)0x1c000000, (FIXP_DBL)0x24000000, (FIXP_DBL)0x32000000};
static const FIXP_DBL iidQuantFine_fx[31] = {
- (FIXP_DBL)0x9c000001, (FIXP_DBL)0xa6000001, (FIXP_DBL)0xb0000001, (FIXP_DBL)0xba000001, (FIXP_DBL)0xc4000000, (FIXP_DBL)0xce000000, (FIXP_DBL)0xd4000000, (FIXP_DBL)0xda000000,
- (FIXP_DBL)0xe0000000, (FIXP_DBL)0xe6000000, (FIXP_DBL)0xec000000, (FIXP_DBL)0xf0000000, (FIXP_DBL)0xf4000000, (FIXP_DBL)0xf8000000, (FIXP_DBL)0xfc000000, (FIXP_DBL)0x00000000,
- (FIXP_DBL)0x04000000, (FIXP_DBL)0x08000000, (FIXP_DBL)0x0c000000, (FIXP_DBL)0x10000000, (FIXP_DBL)0x14000000, (FIXP_DBL)0x1a000000, (FIXP_DBL)0x20000000, (FIXP_DBL)0x26000000,
- (FIXP_DBL)0x2c000000, (FIXP_DBL)0x32000000, (FIXP_DBL)0x3c000000, (FIXP_DBL)0x45ffffff, (FIXP_DBL)0x4fffffff, (FIXP_DBL)0x59ffffff, (FIXP_DBL)0x63ffffff
-};
-
-
+ (FIXP_DBL)0x9c000001, (FIXP_DBL)0xa6000001, (FIXP_DBL)0xb0000001,
+ (FIXP_DBL)0xba000001, (FIXP_DBL)0xc4000000, (FIXP_DBL)0xce000000,
+ (FIXP_DBL)0xd4000000, (FIXP_DBL)0xda000000, (FIXP_DBL)0xe0000000,
+ (FIXP_DBL)0xe6000000, (FIXP_DBL)0xec000000, (FIXP_DBL)0xf0000000,
+ (FIXP_DBL)0xf4000000, (FIXP_DBL)0xf8000000, (FIXP_DBL)0xfc000000,
+ (FIXP_DBL)0x00000000, (FIXP_DBL)0x04000000, (FIXP_DBL)0x08000000,
+ (FIXP_DBL)0x0c000000, (FIXP_DBL)0x10000000, (FIXP_DBL)0x14000000,
+ (FIXP_DBL)0x1a000000, (FIXP_DBL)0x20000000, (FIXP_DBL)0x26000000,
+ (FIXP_DBL)0x2c000000, (FIXP_DBL)0x32000000, (FIXP_DBL)0x3c000000,
+ (FIXP_DBL)0x45ffffff, (FIXP_DBL)0x4fffffff, (FIXP_DBL)0x59ffffff,
+ (FIXP_DBL)0x63ffffff};
static const FIXP_DBL iccQuant[8] = {
- (FIXP_DBL)0x7fffffff, (FIXP_DBL)0x77ef9d7f, (FIXP_DBL)0x6babc97f, (FIXP_DBL)0x4ceaf27f, (FIXP_DBL)0x2f0ed3c0, (FIXP_DBL)0x00000000, (FIXP_DBL)0xb49ba601, (FIXP_DBL)0x80000000
-};
+ (FIXP_DBL)0x7fffffff, (FIXP_DBL)0x77ef9d7f, (FIXP_DBL)0x6babc97f,
+ (FIXP_DBL)0x4ceaf27f, (FIXP_DBL)0x2f0ed3c0, (FIXP_DBL)0x00000000,
+ (FIXP_DBL)0xb49ba601, (FIXP_DBL)0x80000000};
-static FDK_PSENC_ERROR InitPSData(
- HANDLE_PS_DATA hPsData
- )
-{
+static FDK_PSENC_ERROR InitPSData(HANDLE_PS_DATA hPsData) {
FDK_PSENC_ERROR error = PSENC_OK;
- if(hPsData == NULL) {
+ if (hPsData == NULL) {
error = PSENC_INVALID_HANDLE;
- }
- else {
+ } else {
int i, env;
- FDKmemclear(hPsData,sizeof(PS_DATA));
+ FDKmemclear(hPsData, sizeof(PS_DATA));
- for (i=0; i<PS_MAX_BANDS; i++) {
+ for (i = 0; i < PS_MAX_BANDS; i++) {
hPsData->iidIdxLast[i] = 0;
hPsData->iccIdxLast[i] = 0;
}
- hPsData->iidEnable = hPsData->iidEnableLast = 0;
- hPsData->iccEnable = hPsData->iccEnableLast = 0;
+ hPsData->iidEnable = hPsData->iidEnableLast = 0;
+ hPsData->iccEnable = hPsData->iccEnableLast = 0;
hPsData->iidQuantMode = hPsData->iidQuantModeLast = PS_IID_RES_COARSE;
hPsData->iccQuantMode = hPsData->iccQuantModeLast = PS_ICC_ROT_A;
- for(env=0; env<PS_MAX_ENVELOPES; env++) {
+ for (env = 0; env < PS_MAX_ENVELOPES; env++) {
hPsData->iccDiffMode[env] = PS_DELTA_FREQ;
hPsData->iccDiffMode[env] = PS_DELTA_FREQ;
- for (i=0; i<PS_MAX_BANDS; i++) {
+ for (i = 0; i < PS_MAX_BANDS; i++) {
hPsData->iidIdx[env][i] = 0;
hPsData->iccIdx[env][i] = 0;
}
@@ -201,94 +200,84 @@ static FDK_PSENC_ERROR InitPSData(
hPsData->nEnvelopesLast = 0;
- hPsData->headerCnt = MAX_PS_NOHEADER_CNT;
+ hPsData->headerCnt = MAX_PS_NOHEADER_CNT;
hPsData->iidTimeCnt = MAX_TIME_DIFF_FRAMES;
hPsData->iccTimeCnt = MAX_TIME_DIFF_FRAMES;
- hPsData->noEnvCnt = MAX_NOENV_CNT;
+ hPsData->noEnvCnt = MAX_NOENV_CNT;
}
return error;
}
-static FIXP_DBL quantizeCoef( const FIXP_DBL *RESTRICT input,
- const INT nBands,
- const FIXP_DBL *RESTRICT quantTable,
- const INT idxOffset,
- const INT nQuantSteps,
- INT *RESTRICT quantOut)
-{
+static FIXP_DBL quantizeCoef(const FIXP_DBL *RESTRICT input, const INT nBands,
+ const FIXP_DBL *RESTRICT quantTable,
+ const INT idxOffset, const INT nQuantSteps,
+ INT *RESTRICT quantOut) {
INT idx, band;
FIXP_DBL quantErr = FL2FXCONST_DBL(0.f);
- for (band=0; band<nBands;band++) {
- for(idx=0; idx<nQuantSteps-1; idx++){
- if( fixp_abs((input[band]>>1)-(quantTable[idx+1]>>1)) >
- fixp_abs((input[band]>>1)-(quantTable[idx]>>1)) )
- {
+ for (band = 0; band < nBands; band++) {
+ for (idx = 0; idx < nQuantSteps - 1; idx++) {
+ if (fixp_abs((input[band] >> 1) - (quantTable[idx + 1] >> 1)) >
+ fixp_abs((input[band] >> 1) - (quantTable[idx] >> 1))) {
break;
}
}
- quantErr += (fixp_abs(input[band]-quantTable[idx])>>PS_QUANT_SCALE); /* don't scale before subtraction; diff smaller (64-25)/64 */
+ quantErr += (fixp_abs(input[band] - quantTable[idx]) >>
+ PS_QUANT_SCALE); /* don't scale before subtraction; diff
+ smaller (64-25)/64 */
quantOut[band] = idx - idxOffset;
}
return quantErr;
}
-static INT getICCMode(const INT nBands,
- const INT rotType)
-{
+static INT getICCMode(const INT nBands, const INT rotType) {
INT mode = 0;
- switch(nBands) {
- case PS_BANDS_COARSE:
- mode = PS_RES_COARSE;
- break;
- case PS_BANDS_MID:
- mode = PS_RES_MID;
- break;
- default:
- mode = 0;
+ switch (nBands) {
+ case PS_BANDS_COARSE:
+ mode = PS_RES_COARSE;
+ break;
+ case PS_BANDS_MID:
+ mode = PS_RES_MID;
+ break;
+ default:
+ mode = 0;
}
- if(rotType==PS_ICC_ROT_B){
+ if (rotType == PS_ICC_ROT_B) {
mode += 3;
}
return mode;
}
-
-static INT getIIDMode(const INT nBands,
- const INT iidRes)
-{
+static INT getIIDMode(const INT nBands, const INT iidRes) {
INT mode = 0;
- switch(nBands) {
- case PS_BANDS_COARSE:
- mode = PS_RES_COARSE;
- break;
- case PS_BANDS_MID:
- mode = PS_RES_MID;
- break;
- default:
- mode = 0;
- break;
+ switch (nBands) {
+ case PS_BANDS_COARSE:
+ mode = PS_RES_COARSE;
+ break;
+ case PS_BANDS_MID:
+ mode = PS_RES_MID;
+ break;
+ default:
+ mode = 0;
+ break;
}
- if(iidRes == PS_IID_RES_FINE){
+ if (iidRes == PS_IID_RES_FINE) {
mode += 3;
}
return mode;
}
-
static INT envelopeReducible(FIXP_DBL iid[PS_MAX_ENVELOPES][PS_MAX_BANDS],
FIXP_DBL icc[PS_MAX_ENVELOPES][PS_MAX_BANDS],
- INT psBands,
- INT nEnvelopes)
-{
- #define THRESH_SCALE 7
+ INT psBands, INT nEnvelopes) {
+#define THRESH_SCALE 7
INT reducible = 1; /* true */
INT e = 0, b = 0;
@@ -299,31 +288,36 @@ static INT envelopeReducible(FIXP_DBL iid[PS_MAX_ENVELOPES][PS_MAX_BANDS],
FIXP_DBL iidMeanError, iccMeanError;
/* square values to prevent sqrt,
- multiply bands to prevent division; bands shifted DFRACT_BITS instead (DFRACT_BITS-1) because fMultDiv2 used*/
- iidErrThreshold = fMultDiv2 ( FL2FXCONST_DBL(6.5f*6.5f/(IID_SCALE_FT*IID_SCALE_FT)), (FIXP_DBL)(psBands<<((DFRACT_BITS)-THRESH_SCALE)) );
- iccErrThreshold = fMultDiv2 ( FL2FXCONST_DBL(0.75f*0.75f), (FIXP_DBL)(psBands<<((DFRACT_BITS)-THRESH_SCALE)) );
+ multiply bands to prevent division; bands shifted DFRACT_BITS instead
+ (DFRACT_BITS-1) because fMultDiv2 used*/
+ iidErrThreshold =
+ fMultDiv2(FL2FXCONST_DBL(6.5f * 6.5f / (IID_SCALE_FT * IID_SCALE_FT)),
+ (FIXP_DBL)(psBands << ((DFRACT_BITS)-THRESH_SCALE)));
+ iccErrThreshold =
+ fMultDiv2(FL2FXCONST_DBL(0.75f * 0.75f),
+ (FIXP_DBL)(psBands << ((DFRACT_BITS)-THRESH_SCALE)));
if (nEnvelopes <= 1) {
reducible = 0;
} else {
-
/* mean error criterion */
- for (e=0; (e < nEnvelopes/2) && (reducible!=0 ) ; e++) {
+ for (e = 0; (e < nEnvelopes / 2) && (reducible != 0); e++) {
iidMeanError = iccMeanError = FL2FXCONST_DBL(0.f);
- for(b=0; b<psBands; b++) {
- dIid = (iid[2*e][b]>>1) - (iid[2*e+1][b]>>1); /* scale 1 bit; squared -> 2 bit */
- dIcc = (icc[2*e][b]>>1) - (icc[2*e+1][b]>>1);
- iidMeanError += fPow2Div2(dIid)>>(5-1); /* + (bands=20) scale = 5 */
- iccMeanError += fPow2Div2(dIcc)>>(5-1);
- } /* --> scaling = 7 bit = THRESH_SCALE !! */
+ for (b = 0; b < psBands; b++) {
+ dIid = (iid[2 * e][b] >> 1) -
+ (iid[2 * e + 1][b] >> 1); /* scale 1 bit; squared -> 2 bit */
+ dIcc = (icc[2 * e][b] >> 1) - (icc[2 * e + 1][b] >> 1);
+ iidMeanError += fPow2Div2(dIid) >> (5 - 1); /* + (bands=20) scale = 5 */
+ iccMeanError += fPow2Div2(dIcc) >> (5 - 1);
+ } /* --> scaling = 7 bit = THRESH_SCALE !! */
/* instead sqrt values are squared!
instead of division, multiply threshold with psBands
scaling necessary!! */
/* quit as soon as threshold is reached */
- if ( (iidMeanError > (iidErrThreshold)) ||
- (iccMeanError > (iccErrThreshold)) ) {
+ if ((iidMeanError > (iidErrThreshold)) ||
+ (iccMeanError > (iccErrThreshold))) {
reducible = 0;
}
}
@@ -332,305 +326,314 @@ static INT envelopeReducible(FIXP_DBL iid[PS_MAX_ENVELOPES][PS_MAX_BANDS],
return reducible;
}
-
-static void processIidData(PS_DATA *psData,
- FIXP_DBL iid[PS_MAX_ENVELOPES][PS_MAX_BANDS],
- const INT psBands,
- const INT nEnvelopes,
- const FIXP_DBL quantErrorThreshold)
-{
- INT iidIdxFine [PS_MAX_ENVELOPES][PS_MAX_BANDS];
+static void processIidData(PS_DATA *psData,
+ FIXP_DBL iid[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+ const INT psBands, const INT nEnvelopes,
+ const FIXP_DBL quantErrorThreshold) {
+ INT iidIdxFine[PS_MAX_ENVELOPES][PS_MAX_BANDS];
INT iidIdxCoarse[PS_MAX_ENVELOPES][PS_MAX_BANDS];
FIXP_DBL errIID = FL2FXCONST_DBL(0.f);
FIXP_DBL errIIDFine = FL2FXCONST_DBL(0.f);
- INT bitsIidFreq = 0;
- INT bitsIidTime = 0;
- INT bitsFineTot = 0;
- INT bitsCoarseTot = 0;
- INT error = 0;
- INT env, band;
- INT diffMode[PS_MAX_ENVELOPES], diffModeFine[PS_MAX_ENVELOPES];
+ INT bitsIidFreq = 0;
+ INT bitsIidTime = 0;
+ INT bitsFineTot = 0;
+ INT bitsCoarseTot = 0;
+ INT error = 0;
+ INT env, band;
+ INT diffMode[PS_MAX_ENVELOPES], diffModeFine[PS_MAX_ENVELOPES];
INT loudnDiff = 0;
INT iidTransmit = 0;
- bitsIidFreq = bitsIidTime = 0;
-
/* Quantize IID coefficients */
- for(env=0;env<nEnvelopes; env++) {
- errIID += quantizeCoef(iid[env], psBands, iidQuant_fx, 7, 15, iidIdxCoarse[env]);
- errIIDFine += quantizeCoef(iid[env], psBands, iidQuantFine_fx, 15, 31, iidIdxFine[env]);
+ for (env = 0; env < nEnvelopes; env++) {
+ errIID +=
+ quantizeCoef(iid[env], psBands, iidQuant_fx, 7, 15, iidIdxCoarse[env]);
+ errIIDFine += quantizeCoef(iid[env], psBands, iidQuantFine_fx, 15, 31,
+ iidIdxFine[env]);
}
/* normalize error to number of envelopes, ps bands
errIID /= psBands*nEnvelopes;
errIIDFine /= psBands*nEnvelopes; */
-
/* Check if IID coefficients should be used in this frame */
psData->iidEnable = 0;
- for(env=0;env<nEnvelopes; env++) {
- for(band=0;band<psBands;band++) {
- loudnDiff += fixp_abs(iidIdxCoarse[env][band]);
- iidTransmit ++;
+ for (env = 0; env < nEnvelopes; env++) {
+ for (band = 0; band < psBands; band++) {
+ loudnDiff += fixp_abs(iidIdxCoarse[env][band]);
+ iidTransmit++;
}
}
- if(loudnDiff > fMultI(FL2FXCONST_DBL(0.7f),iidTransmit)){ /* 0.7f empiric value */
+ if (loudnDiff >
+ fMultI(FL2FXCONST_DBL(0.7f), iidTransmit)) { /* 0.7f empiric value */
psData->iidEnable = 1;
}
/* if iid not active -> RESET data */
- if(psData->iidEnable==0) {
+ if (psData->iidEnable == 0) {
psData->iidTimeCnt = MAX_TIME_DIFF_FRAMES;
- for(env=0;env<nEnvelopes; env++) {
+ for (env = 0; env < nEnvelopes; env++) {
psData->iidDiffMode[env] = PS_DELTA_FREQ;
- FDKmemclear(psData->iidIdx[env], sizeof(INT)*psBands);
+ FDKmemclear(psData->iidIdx[env], sizeof(INT) * psBands);
}
return;
}
/* count COARSE quantization bits for first envelope*/
- bitsIidFreq = FDKsbrEnc_EncodeIid(NULL, iidIdxCoarse[0], NULL, psBands, PS_IID_RES_COARSE, PS_DELTA_FREQ, &error);
+ bitsIidFreq = FDKsbrEnc_EncodeIid(NULL, iidIdxCoarse[0], NULL, psBands,
+ PS_IID_RES_COARSE, PS_DELTA_FREQ, &error);
- if( (psData->iidTimeCnt>=MAX_TIME_DIFF_FRAMES) || (psData->iidQuantModeLast==PS_IID_RES_FINE) ) {
- bitsIidTime = DO_NOT_USE_THIS_MODE;
- }
- else {
- bitsIidTime = FDKsbrEnc_EncodeIid(NULL, iidIdxCoarse[0], psData->iidIdxLast, psBands, PS_IID_RES_COARSE, PS_DELTA_TIME, &error);
+ if ((psData->iidTimeCnt >= MAX_TIME_DIFF_FRAMES) ||
+ (psData->iidQuantModeLast == PS_IID_RES_FINE)) {
+ bitsIidTime = DO_NOT_USE_THIS_MODE;
+ } else {
+ bitsIidTime =
+ FDKsbrEnc_EncodeIid(NULL, iidIdxCoarse[0], psData->iidIdxLast, psBands,
+ PS_IID_RES_COARSE, PS_DELTA_TIME, &error);
}
/* decision DELTA_FREQ vs DELTA_TIME */
- if(bitsIidTime>bitsIidFreq) {
- diffMode[0] = PS_DELTA_FREQ;
+ if (bitsIidTime > bitsIidFreq) {
+ diffMode[0] = PS_DELTA_FREQ;
bitsCoarseTot = bitsIidFreq;
- }
- else {
- diffMode[0] = PS_DELTA_TIME;
+ } else {
+ diffMode[0] = PS_DELTA_TIME;
bitsCoarseTot = bitsIidTime;
}
/* count COARSE quantization bits for following envelopes*/
- for(env=1;env<nEnvelopes; env++) {
- bitsIidFreq = FDKsbrEnc_EncodeIid(NULL, iidIdxCoarse[env], NULL, psBands, PS_IID_RES_COARSE, PS_DELTA_FREQ, &error);
- bitsIidTime = FDKsbrEnc_EncodeIid(NULL, iidIdxCoarse[env], iidIdxCoarse[env-1], psBands, PS_IID_RES_COARSE, PS_DELTA_TIME, &error);
+ for (env = 1; env < nEnvelopes; env++) {
+ bitsIidFreq = FDKsbrEnc_EncodeIid(NULL, iidIdxCoarse[env], NULL, psBands,
+ PS_IID_RES_COARSE, PS_DELTA_FREQ, &error);
+ bitsIidTime =
+ FDKsbrEnc_EncodeIid(NULL, iidIdxCoarse[env], iidIdxCoarse[env - 1],
+ psBands, PS_IID_RES_COARSE, PS_DELTA_TIME, &error);
/* decision DELTA_FREQ vs DELTA_TIME */
- if(bitsIidTime>bitsIidFreq) {
- diffMode[env] = PS_DELTA_FREQ;
+ if (bitsIidTime > bitsIidFreq) {
+ diffMode[env] = PS_DELTA_FREQ;
bitsCoarseTot += bitsIidFreq;
- }
- else {
- diffMode[env] = PS_DELTA_TIME;
+ } else {
+ diffMode[env] = PS_DELTA_TIME;
bitsCoarseTot += bitsIidTime;
}
}
-
/* count FINE quantization bits for first envelope*/
- bitsIidFreq = FDKsbrEnc_EncodeIid(NULL, iidIdxFine[0], NULL, psBands, PS_IID_RES_FINE, PS_DELTA_FREQ, &error);
+ bitsIidFreq = FDKsbrEnc_EncodeIid(NULL, iidIdxFine[0], NULL, psBands,
+ PS_IID_RES_FINE, PS_DELTA_FREQ, &error);
- if( (psData->iidTimeCnt>=MAX_TIME_DIFF_FRAMES) || (psData->iidQuantModeLast==PS_IID_RES_COARSE) ) {
+ if ((psData->iidTimeCnt >= MAX_TIME_DIFF_FRAMES) ||
+ (psData->iidQuantModeLast == PS_IID_RES_COARSE)) {
bitsIidTime = DO_NOT_USE_THIS_MODE;
- }
- else {
- bitsIidTime = FDKsbrEnc_EncodeIid(NULL, iidIdxFine[0], psData->iidIdxLast, psBands, PS_IID_RES_FINE, PS_DELTA_TIME, &error);
+ } else {
+ bitsIidTime =
+ FDKsbrEnc_EncodeIid(NULL, iidIdxFine[0], psData->iidIdxLast, psBands,
+ PS_IID_RES_FINE, PS_DELTA_TIME, &error);
}
/* decision DELTA_FREQ vs DELTA_TIME */
- if(bitsIidTime>bitsIidFreq) {
- diffModeFine[0] = PS_DELTA_FREQ;
- bitsFineTot = bitsIidFreq;
- }
- else {
- diffModeFine[0] = PS_DELTA_TIME;
- bitsFineTot = bitsIidTime;
+ if (bitsIidTime > bitsIidFreq) {
+ diffModeFine[0] = PS_DELTA_FREQ;
+ bitsFineTot = bitsIidFreq;
+ } else {
+ diffModeFine[0] = PS_DELTA_TIME;
+ bitsFineTot = bitsIidTime;
}
/* count FINE quantization bits for following envelopes*/
- for(env=1;env<nEnvelopes; env++) {
- bitsIidFreq = FDKsbrEnc_EncodeIid(NULL, iidIdxFine[env], NULL, psBands, PS_IID_RES_FINE, PS_DELTA_FREQ, &error);
- bitsIidTime = FDKsbrEnc_EncodeIid(NULL, iidIdxFine[env], iidIdxFine[env-1], psBands, PS_IID_RES_FINE, PS_DELTA_TIME, &error);
+ for (env = 1; env < nEnvelopes; env++) {
+ bitsIidFreq = FDKsbrEnc_EncodeIid(NULL, iidIdxFine[env], NULL, psBands,
+ PS_IID_RES_FINE, PS_DELTA_FREQ, &error);
+ bitsIidTime =
+ FDKsbrEnc_EncodeIid(NULL, iidIdxFine[env], iidIdxFine[env - 1], psBands,
+ PS_IID_RES_FINE, PS_DELTA_TIME, &error);
/* decision DELTA_FREQ vs DELTA_TIME */
- if(bitsIidTime>bitsIidFreq) {
- diffModeFine[env] = PS_DELTA_FREQ;
+ if (bitsIidTime > bitsIidFreq) {
+ diffModeFine[env] = PS_DELTA_FREQ;
bitsFineTot += bitsIidFreq;
- }
- else {
- diffModeFine[env] = PS_DELTA_TIME;
- bitsFineTot += bitsIidTime;
+ } else {
+ diffModeFine[env] = PS_DELTA_TIME;
+ bitsFineTot += bitsIidTime;
}
}
- if(bitsFineTot == bitsCoarseTot){
- /* if same number of bits is needed, use the quantization with lower error */
- if(errIIDFine < errIID){
+ if (bitsFineTot == bitsCoarseTot) {
+ /* if same number of bits is needed, use the quantization with lower error
+ */
+ if (errIIDFine < errIID) {
bitsCoarseTot = DO_NOT_USE_THIS_MODE;
} else {
bitsFineTot = DO_NOT_USE_THIS_MODE;
}
} else {
- /* const FIXP_DBL minThreshold = FL2FXCONST_DBL(0.2f/(IID_SCALE_FT*PS_QUANT_SCALE_FT)*(psBands*nEnvelopes)); */
- const FIXP_DBL minThreshold = (FIXP_DBL)((LONG)0x00019999 * (psBands*nEnvelopes));
+ /* const FIXP_DBL minThreshold =
+ * FL2FXCONST_DBL(0.2f/(IID_SCALE_FT*PS_QUANT_SCALE_FT)*(psBands*nEnvelopes));
+ */
+ const FIXP_DBL minThreshold =
+ (FIXP_DBL)((LONG)0x00019999 * (psBands * nEnvelopes));
/* decision RES_FINE vs RES_COARSE */
/* test if errIIDFine*quantErrorThreshold < errIID */
/* shiftVal 2 comes from scaling of quantErrorThreshold */
- if(fixMax(((errIIDFine>>1)+(minThreshold>>1))>>1, fMult(quantErrorThreshold,errIIDFine)) < (errIID>>2) ) {
+ if (fixMax(((errIIDFine >> 1) + (minThreshold >> 1)) >> 1,
+ fMult(quantErrorThreshold, errIIDFine)) < (errIID >> 2)) {
bitsCoarseTot = DO_NOT_USE_THIS_MODE;
- }
- else if(fixMax(((errIID>>1)+(minThreshold>>1))>>1, fMult(quantErrorThreshold,errIID)) < (errIIDFine>>2) ) {
+ } else if (fixMax(((errIID >> 1) + (minThreshold >> 1)) >> 1,
+ fMult(quantErrorThreshold, errIID)) < (errIIDFine >> 2)) {
bitsFineTot = DO_NOT_USE_THIS_MODE;
}
}
/* decision RES_FINE vs RES_COARSE */
- if(bitsFineTot<bitsCoarseTot) {
+ if (bitsFineTot < bitsCoarseTot) {
psData->iidQuantMode = PS_IID_RES_FINE;
- for(env=0;env<nEnvelopes; env++) {
+ for (env = 0; env < nEnvelopes; env++) {
psData->iidDiffMode[env] = diffModeFine[env];
- FDKmemcpy(psData->iidIdx[env], iidIdxFine[env], psBands*sizeof(INT));
+ FDKmemcpy(psData->iidIdx[env], iidIdxFine[env], psBands * sizeof(INT));
}
- }
- else {
+ } else {
psData->iidQuantMode = PS_IID_RES_COARSE;
- for(env=0;env<nEnvelopes; env++) {
+ for (env = 0; env < nEnvelopes; env++) {
psData->iidDiffMode[env] = diffMode[env];
- FDKmemcpy(psData->iidIdx[env], iidIdxCoarse[env], psBands*sizeof(INT));
+ FDKmemcpy(psData->iidIdx[env], iidIdxCoarse[env], psBands * sizeof(INT));
}
}
/* Count DELTA_TIME encoding streaks */
- for(env=0;env<nEnvelopes; env++) {
- if(psData->iidDiffMode[env]==PS_DELTA_TIME)
+ for (env = 0; env < nEnvelopes; env++) {
+ if (psData->iidDiffMode[env] == PS_DELTA_TIME)
psData->iidTimeCnt++;
else
- psData->iidTimeCnt=0;
+ psData->iidTimeCnt = 0;
}
}
-
-static INT similarIid(PS_DATA *psData,
- const INT psBands,
- const INT nEnvelopes)
-{
+static INT similarIid(PS_DATA *psData, const INT psBands,
+ const INT nEnvelopes) {
const INT diffThr = (psData->iidQuantMode == PS_IID_RES_COARSE) ? 2 : 3;
- const INT sumDiffThr = diffThr * psBands/4;
+ const INT sumDiffThr = diffThr * psBands / 4;
INT similar = 0;
- INT diff = 0;
+ INT diff = 0;
INT sumDiff = 0;
INT env = 0;
- INT b = 0;
- if ((nEnvelopes == psData->nEnvelopesLast) && (nEnvelopes==1)) {
+ INT b = 0;
+ if ((nEnvelopes == psData->nEnvelopesLast) && (nEnvelopes == 1)) {
similar = 1;
- for (env=0; env<nEnvelopes; env++) {
+ for (env = 0; env < nEnvelopes; env++) {
sumDiff = 0;
b = 0;
do {
diff = fixp_abs(psData->iidIdx[env][b] - psData->iidIdxLast[b]);
sumDiff += diff;
- if ( (diff > diffThr) /* more than x quantization steps in any band */
- || (sumDiff > sumDiffThr) ) { /* more than x quantisations steps overall difference */
+ if ((diff > diffThr) /* more than x quantization steps in any band */
+ || (sumDiff > sumDiffThr)) { /* more than x quantisations steps
+ overall difference */
similar = 0;
}
b++;
- } while ((b<psBands) && (similar>0));
+ } while ((b < psBands) && (similar > 0));
}
} /* nEnvelopes==1 */
return similar;
}
-
-static INT similarIcc(PS_DATA *psData,
- const INT psBands,
- const INT nEnvelopes)
-{
+static INT similarIcc(PS_DATA *psData, const INT psBands,
+ const INT nEnvelopes) {
const INT diffThr = 2;
- const INT sumDiffThr = diffThr * psBands/4;
+ const INT sumDiffThr = diffThr * psBands / 4;
INT similar = 0;
- INT diff = 0;
+ INT diff = 0;
INT sumDiff = 0;
INT env = 0;
- INT b = 0;
- if ((nEnvelopes == psData->nEnvelopesLast) && (nEnvelopes==1)) {
+ INT b = 0;
+ if ((nEnvelopes == psData->nEnvelopesLast) && (nEnvelopes == 1)) {
similar = 1;
- for (env=0; env<nEnvelopes; env++) {
+ for (env = 0; env < nEnvelopes; env++) {
sumDiff = 0;
b = 0;
do {
diff = fixp_abs(psData->iccIdx[env][b] - psData->iccIdxLast[b]);
sumDiff += diff;
- if ( (diff > diffThr) /* more than x quantisation step in any band */
- || (sumDiff > sumDiffThr) ) { /* more than x quantisations steps overall difference */
+ if ((diff > diffThr) /* more than x quantisation step in any band */
+ || (sumDiff > sumDiffThr)) { /* more than x quantisations steps
+ overall difference */
similar = 0;
}
b++;
- } while ((b<psBands) && (similar>0));
+ } while ((b < psBands) && (similar > 0));
}
} /* nEnvelopes==1 */
return similar;
}
-static void processIccData(PS_DATA *psData,
- FIXP_DBL icc[PS_MAX_ENVELOPES][PS_MAX_BANDS], /* const input values: unable to declare as const, since it does not poINT to const memory */
- const INT psBands,
- const INT nEnvelopes)
-{
+static void processIccData(
+ PS_DATA *psData,
+ FIXP_DBL icc[PS_MAX_ENVELOPES][PS_MAX_BANDS], /* const input values:
+ unable to declare as
+ const, since it does
+ not poINT to const
+ memory */
+ const INT psBands, const INT nEnvelopes) {
FIXP_DBL errICC = FL2FXCONST_DBL(0.f);
- INT env, band;
- INT bitsIccFreq, bitsIccTime;
- INT error = 0;
- INT inCoherence=0, iccTransmit=0;
- INT *iccIdxLast;
+ INT env, band;
+ INT bitsIccFreq, bitsIccTime;
+ INT error = 0;
+ INT inCoherence = 0, iccTransmit = 0;
+ INT *iccIdxLast;
iccIdxLast = psData->iccIdxLast;
/* Quantize ICC coefficients */
- for(env=0;env<nEnvelopes; env++) {
- errICC += quantizeCoef(icc[env], psBands, iccQuant, 0, 8, psData->iccIdx[env]);
+ for (env = 0; env < nEnvelopes; env++) {
+ errICC +=
+ quantizeCoef(icc[env], psBands, iccQuant, 0, 8, psData->iccIdx[env]);
}
/* Check if ICC coefficients should be used */
psData->iccEnable = 0;
- for(env=0;env<nEnvelopes; env++) {
- for(band=0;band<psBands;band++) {
+ for (env = 0; env < nEnvelopes; env++) {
+ for (band = 0; band < psBands; band++) {
inCoherence += psData->iccIdx[env][band];
- iccTransmit ++;
+ iccTransmit++;
}
}
- if(inCoherence > fMultI(FL2FXCONST_DBL(0.5f),iccTransmit)){ /* 0.5f empiric value */
+ if (inCoherence >
+ fMultI(FL2FXCONST_DBL(0.5f), iccTransmit)) { /* 0.5f empiric value */
psData->iccEnable = 1;
}
- if(psData->iccEnable==0) {
+ if (psData->iccEnable == 0) {
psData->iccTimeCnt = MAX_TIME_DIFF_FRAMES;
- for(env=0;env<nEnvelopes; env++) {
+ for (env = 0; env < nEnvelopes; env++) {
psData->iccDiffMode[env] = PS_DELTA_FREQ;
- FDKmemclear(psData->iccIdx[env], sizeof(INT)*psBands);
+ FDKmemclear(psData->iccIdx[env], sizeof(INT) * psBands);
}
return;
}
- for(env=0;env<nEnvelopes; env++) {
- bitsIccFreq = FDKsbrEnc_EncodeIcc(NULL, psData->iccIdx[env], NULL, psBands, PS_DELTA_FREQ, &error);
+ for (env = 0; env < nEnvelopes; env++) {
+ bitsIccFreq = FDKsbrEnc_EncodeIcc(NULL, psData->iccIdx[env], NULL, psBands,
+ PS_DELTA_FREQ, &error);
- if(psData->iccTimeCnt<MAX_TIME_DIFF_FRAMES) {
- bitsIccTime = FDKsbrEnc_EncodeIcc(NULL, psData->iccIdx[env], iccIdxLast, psBands, PS_DELTA_TIME, &error);
- }
- else {
- bitsIccTime = DO_NOT_USE_THIS_MODE;
+ if (psData->iccTimeCnt < MAX_TIME_DIFF_FRAMES) {
+ bitsIccTime = FDKsbrEnc_EncodeIcc(NULL, psData->iccIdx[env], iccIdxLast,
+ psBands, PS_DELTA_TIME, &error);
+ } else {
+ bitsIccTime = DO_NOT_USE_THIS_MODE;
}
- if(bitsIccFreq>bitsIccTime) {
+ if (bitsIccFreq > bitsIccTime) {
psData->iccDiffMode[env] = PS_DELTA_TIME;
psData->iccTimeCnt++;
- }
- else {
+ } else {
psData->iccDiffMode[env] = PS_DELTA_FREQ;
- psData->iccTimeCnt=0;
+ psData->iccTimeCnt = 0;
}
iccIdxLast = psData->iccIdx[env];
}
@@ -639,163 +642,148 @@ static void processIccData(PS_DATA *psData,
static void calculateIID(FIXP_DBL ldPwrL[PS_MAX_ENVELOPES][PS_MAX_BANDS],
FIXP_DBL ldPwrR[PS_MAX_ENVELOPES][PS_MAX_BANDS],
FIXP_DBL iid[PS_MAX_ENVELOPES][PS_MAX_BANDS],
- INT nEnvelopes,
- INT psBands)
-{
- INT i=0;
- INT env=0;
- for(env=0; env<nEnvelopes;env++) {
- for (i=0; i<psBands; i++) {
-
+ INT nEnvelopes, INT psBands) {
+ INT i = 0;
+ INT env = 0;
+ for (env = 0; env < nEnvelopes; env++) {
+ for (i = 0; i < psBands; i++) {
/* iid[env][i] = 10.0f*(float)log10(pwrL[env][i]/pwrR[env][i]);
- */
- FIXP_DBL IID = fMultDiv2( FL2FXCONST_DBL(LOG10_2_10/IID_SCALE_FT), (ldPwrL[env][i]-ldPwrR[env][i]) );
+ */
+ FIXP_DBL IID = fMultDiv2(FL2FXCONST_DBL(LOG10_2_10 / IID_SCALE_FT),
+ (ldPwrL[env][i] - ldPwrR[env][i]));
- IID = fixMin( IID, (FIXP_DBL)(MAXVAL_DBL>>(LD_DATA_SHIFT+1)) );
- IID = fixMax( IID, (FIXP_DBL)(MINVAL_DBL>>(LD_DATA_SHIFT+1)) );
- iid[env][i] = IID << (LD_DATA_SHIFT+1);
+ IID = fixMin(IID, (FIXP_DBL)(MAXVAL_DBL >> (LD_DATA_SHIFT + 1)));
+ IID = fixMax(IID, (FIXP_DBL)(MINVAL_DBL >> (LD_DATA_SHIFT + 1)));
+ iid[env][i] = IID << (LD_DATA_SHIFT + 1);
}
}
}
-static void calculateICC(FIXP_DBL ldPwrL[PS_MAX_ENVELOPES][PS_MAX_BANDS],
- FIXP_DBL ldPwrR[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+static void calculateICC(FIXP_DBL pwrL[PS_MAX_ENVELOPES][PS_MAX_BANDS],
+ FIXP_DBL pwrR[PS_MAX_ENVELOPES][PS_MAX_BANDS],
FIXP_DBL pwrCr[PS_MAX_ENVELOPES][PS_MAX_BANDS],
FIXP_DBL pwrCi[PS_MAX_ENVELOPES][PS_MAX_BANDS],
FIXP_DBL icc[PS_MAX_ENVELOPES][PS_MAX_BANDS],
- INT nEnvelopes,
- INT psBands)
-{
+ INT nEnvelopes, INT psBands) {
INT i = 0;
INT env = 0;
INT border = psBands;
switch (psBands) {
- case PS_BANDS_COARSE:
- border = 5;
- break;
- case PS_BANDS_MID:
- border = 11;
- break;
- default:
- break;
+ case PS_BANDS_COARSE:
+ border = 5;
+ break;
+ case PS_BANDS_MID:
+ border = 11;
+ break;
+ default:
+ break;
}
- for(env=0; env<nEnvelopes;env++) {
- for (i=0; i<border; i++) {
-
- /* icc[env][i] = min( pwrCr[env][i] / (float) sqrt(pwrL[env][i] * pwrR[env][i]) , 1.f);
- */
- FIXP_DBL ICC, invNrg = CalcInvLdData ( -((ldPwrL[env][i]>>1) + (ldPwrR[env][i]>>1) + (FIXP_DBL)1) );
- INT scale, invScale = CountLeadingBits(invNrg);
-
- scale = (DFRACT_BITS-1) - invScale;
- ICC = fMult(pwrCr[env][i], invNrg<<invScale) ;
- icc[env][i] = SATURATE_LEFT_SHIFT(ICC, scale, DFRACT_BITS);
+ for (env = 0; env < nEnvelopes; env++) {
+ for (i = 0; i < border; i++) {
+ /* icc[env][i] = min( pwrCr[env][i] / (float) sqrt(pwrL[env][i] *
+ * pwrR[env][i]) , 1.f);
+ */
+ int scale;
+ FIXP_DBL invNrg = invSqrtNorm2(
+ fMax(fMult(pwrL[env][i], pwrR[env][i]), (FIXP_DBL)1), &scale);
+ icc[env][i] =
+ SATURATE_LEFT_SHIFT(fMult(pwrCr[env][i], invNrg), scale, DFRACT_BITS);
}
- for (; i<psBands; i++) {
- INT sc1, sc2;
- FIXP_DBL cNrgR, cNrgI, ICC;
-
- sc1 = CountLeadingBits( fixMax(fixp_abs(pwrCr[env][i]),fixp_abs(pwrCi[env][i])) ) ;
- cNrgR = fPow2Div2((pwrCr[env][i]<<sc1)); /* squared nrg's expect explicit scaling */
- cNrgI = fPow2Div2((pwrCi[env][i]<<sc1));
-
- ICC = CalcInvLdData( (CalcLdData((cNrgR + cNrgI)>>1)>>1) - (FIXP_DBL)((sc1-1)<<(DFRACT_BITS-1-LD_DATA_SHIFT)) );
-
- FIXP_DBL invNrg = CalcInvLdData ( -((ldPwrL[env][i]>>1) + (ldPwrR[env][i]>>1) + (FIXP_DBL)1) );
- sc1 = CountLeadingBits(invNrg);
- invNrg <<= sc1;
-
- sc2 = CountLeadingBits(ICC);
- ICC = fMult(ICC<<sc2,invNrg);
-
- sc1 = ( (DFRACT_BITS-1) - sc1 - sc2 );
- if (sc1 < 0) {
- ICC >>= -sc1;
+ for (; i < psBands; i++) {
+ int denom_e;
+ FIXP_DBL denom_m = fMultNorm(pwrL[env][i], pwrR[env][i], &denom_e);
+
+ if (denom_m == (FIXP_DBL)0) {
+ icc[env][i] = (FIXP_DBL)MAXVAL_DBL;
+ } else {
+ int num_e, result_e;
+ FIXP_DBL num_m, result_m;
+
+ num_e = CountLeadingBits(
+ fixMax(fixp_abs(pwrCr[env][i]), fixp_abs(pwrCi[env][i])));
+ num_m = fPow2Div2((pwrCr[env][i] << num_e)) +
+ fPow2Div2((pwrCi[env][i] << num_e));
+
+ result_m = fDivNorm(num_m, denom_m, &result_e);
+ result_e += (-2 * num_e + 1) - denom_e;
+ icc[env][i] = scaleValueSaturate(sqrtFixp(result_m >> (result_e & 1)),
+ (result_e + (result_e & 1)) >> 1);
}
- else {
- if (ICC >= ((FIXP_DBL)MAXVAL_DBL>>sc1) )
- ICC = (FIXP_DBL)MAXVAL_DBL;
- else
- ICC <<= sc1;
- }
-
- icc[env][i] = ICC;
}
}
}
-void FDKsbrEnc_initPsBandNrgScale(HANDLE_PS_ENCODE hPsEncode)
-{
+void FDKsbrEnc_initPsBandNrgScale(HANDLE_PS_ENCODE hPsEncode) {
INT group, bin;
- INT nIidGroups = hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups;
+ INT nIidGroups = hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups;
- FDKmemclear(hPsEncode->psBandNrgScale, PS_MAX_BANDS*sizeof(SCHAR));
+ FDKmemclear(hPsEncode->psBandNrgScale, PS_MAX_BANDS * sizeof(SCHAR));
- for (group=0; group < nIidGroups; group++) {
+ for (group = 0; group < nIidGroups; group++) {
/* Translate group to bin */
bin = hPsEncode->subband2parameterIndex[group];
/* Translate from 20 bins to 10 bins */
if (hPsEncode->psEncMode == PS_BANDS_COARSE) {
- bin = bin>>1;
+ bin = bin >> 1;
}
- hPsEncode->psBandNrgScale[bin] = (hPsEncode->psBandNrgScale[bin]==0)
- ? (hPsEncode->iidGroupWidthLd[group] + 5)
- : (fixMax(hPsEncode->iidGroupWidthLd[group],hPsEncode->psBandNrgScale[bin]) + 1) ;
-
+ hPsEncode->psBandNrgScale[bin] =
+ (hPsEncode->psBandNrgScale[bin] == 0)
+ ? (hPsEncode->iidGroupWidthLd[group] + 5)
+ : (fixMax(hPsEncode->iidGroupWidthLd[group],
+ hPsEncode->psBandNrgScale[bin]) +
+ 1);
}
}
-FDK_PSENC_ERROR FDKsbrEnc_CreatePSEncode(
- HANDLE_PS_ENCODE *phPsEncode
- )
-{
+FDK_PSENC_ERROR FDKsbrEnc_CreatePSEncode(HANDLE_PS_ENCODE *phPsEncode) {
FDK_PSENC_ERROR error = PSENC_OK;
- if (phPsEncode==NULL) {
+ if (phPsEncode == NULL) {
error = PSENC_INVALID_HANDLE;
- }
- else {
+ } else {
HANDLE_PS_ENCODE hPsEncode = NULL;
- if (NULL==(hPsEncode = GetRam_PsEncode())) {
+ if (NULL == (hPsEncode = GetRam_PsEncode())) {
error = PSENC_MEMORY_ERROR;
goto bail;
}
- FDKmemclear(hPsEncode,sizeof(PS_ENCODE));
+ FDKmemclear(hPsEncode, sizeof(PS_ENCODE));
*phPsEncode = hPsEncode; /* return allocated handle */
}
bail:
return error;
}
-FDK_PSENC_ERROR FDKsbrEnc_InitPSEncode(
- HANDLE_PS_ENCODE hPsEncode,
- const PS_BANDS psEncMode,
- const FIXP_DBL iidQuantErrorThreshold
- )
-{
+FDK_PSENC_ERROR FDKsbrEnc_InitPSEncode(HANDLE_PS_ENCODE hPsEncode,
+ const PS_BANDS psEncMode,
+ const FIXP_DBL iidQuantErrorThreshold) {
FDK_PSENC_ERROR error = PSENC_OK;
- if (NULL==hPsEncode) {
+ if (NULL == hPsEncode) {
error = PSENC_INVALID_HANDLE;
- }
- else {
+ } else {
if (PSENC_OK != (InitPSData(&hPsEncode->psData))) {
goto bail;
}
- switch(psEncMode){
+ switch (psEncMode) {
case PS_BANDS_COARSE:
case PS_BANDS_MID:
- hPsEncode->nQmfIidGroups = QMF_GROUPS_LO_RES;
+ hPsEncode->nQmfIidGroups = QMF_GROUPS_LO_RES;
hPsEncode->nSubQmfIidGroups = SUBQMF_GROUPS_LO_RES;
- FDKmemcpy(hPsEncode->iidGroupBorders, iidGroupBordersLoRes, (hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups + 1)*sizeof(INT));
- FDKmemcpy(hPsEncode->subband2parameterIndex, subband2parameter20, (hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups) *sizeof(INT));
- FDKmemcpy(hPsEncode->iidGroupWidthLd, iidGroupWidthLdLoRes, (hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups) *sizeof(UCHAR));
+ FDKmemcpy(hPsEncode->iidGroupBorders, iidGroupBordersLoRes,
+ (hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups + 1) *
+ sizeof(INT));
+ FDKmemcpy(hPsEncode->subband2parameterIndex, subband2parameter20,
+ (hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups) *
+ sizeof(INT));
+ FDKmemcpy(hPsEncode->iidGroupWidthLd, iidGroupWidthLdLoRes,
+ (hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups) *
+ sizeof(UCHAR));
break;
default:
error = PSENC_INIT_ERROR;
@@ -810,14 +798,10 @@ bail:
return error;
}
-
-FDK_PSENC_ERROR FDKsbrEnc_DestroyPSEncode(
- HANDLE_PS_ENCODE *phPsEncode
- )
-{
+FDK_PSENC_ERROR FDKsbrEnc_DestroyPSEncode(HANDLE_PS_ENCODE *phPsEncode) {
FDK_PSENC_ERROR error = PSENC_OK;
- if (NULL !=phPsEncode) {
+ if (NULL != phPsEncode) {
FreeRam_PsEncode(phPsEncode);
}
@@ -834,49 +818,43 @@ typedef struct {
} PS_PWR_DATA;
-
FDK_PSENC_ERROR FDKsbrEnc_PSEncode(
- HANDLE_PS_ENCODE hPsEncode,
- HANDLE_PS_OUT hPsOut,
- UCHAR *dynBandScale,
- UINT maxEnvelopes,
- FIXP_DBL *hybridData[HYBRID_FRAMESIZE][MAX_PS_CHANNELS][2],
- const INT frameSize,
- const INT sendHeader
- )
-{
+ HANDLE_PS_ENCODE hPsEncode, HANDLE_PS_OUT hPsOut, UCHAR *dynBandScale,
+ UINT maxEnvelopes,
+ FIXP_DBL *hybridData[HYBRID_FRAMESIZE][MAX_PS_CHANNELS][2],
+ const INT frameSize, const INT sendHeader) {
FDK_PSENC_ERROR error = PSENC_OK;
HANDLE_PS_DATA hPsData = &hPsEncode->psData;
- FIXP_DBL iid [PS_MAX_ENVELOPES][PS_MAX_BANDS];
- FIXP_DBL icc [PS_MAX_ENVELOPES][PS_MAX_BANDS];
- int envBorder[PS_MAX_ENVELOPES+1];
+ FIXP_DBL iid[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+ FIXP_DBL icc[PS_MAX_ENVELOPES][PS_MAX_BANDS];
+ int envBorder[PS_MAX_ENVELOPES + 1];
int group, bin, col, subband, band;
int i = 0;
int env = 0;
- int psBands = (int) hPsEncode->psEncMode;
- int nIidGroups = hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups;
- int nEnvelopes = fixMin(maxEnvelopes, (UINT)PS_MAX_ENVELOPES);
+ int psBands = (int)hPsEncode->psEncMode;
+ int nIidGroups = hPsEncode->nQmfIidGroups + hPsEncode->nSubQmfIidGroups;
+ int nEnvelopes = fixMin(maxEnvelopes, (UINT)PS_MAX_ENVELOPES);
- C_ALLOC_SCRATCH_START(pwrData, PS_PWR_DATA, 1);
+ C_ALLOC_SCRATCH_START(pwrData, PS_PWR_DATA, 1)
- for(env=0; env<nEnvelopes+1;env++) {
- envBorder[env] = fMultI(GetInvInt(nEnvelopes),frameSize*env);
+ for (env = 0; env < nEnvelopes + 1; env++) {
+ envBorder[env] = fMultI(GetInvInt(nEnvelopes), frameSize * env);
}
- for(env=0; env<nEnvelopes;env++) {
-
+ for (env = 0; env < nEnvelopes; env++) {
/* clear energy array */
- for (band=0; band<psBands; band++) {
- pwrData->pwrL[env][band] = pwrData->pwrR[env][band] = pwrData->pwrCr[env][band] = pwrData->pwrCi[env][band] = FIXP_DBL(1);
+ for (band = 0; band < psBands; band++) {
+ pwrData->pwrL[env][band] = pwrData->pwrR[env][band] =
+ pwrData->pwrCr[env][band] = pwrData->pwrCi[env][band] = FIXP_DBL(1);
}
/**** calculate energies and correlation ****/
/* start with hybrid data */
- for (group=0; group < nIidGroups; group++) {
+ for (group = 0; group < nIidGroups; group++) {
/* Translate group to bin */
bin = hPsEncode->subband2parameterIndex[group];
@@ -894,22 +872,26 @@ FDK_PSENC_ERROR FDKsbrEnc_PSEncode(
FIXP_DBL pwrCi_env_bin = pwrData->pwrCi[env][bin];
int scale = (int)dynBandScale[bin];
- for (col=envBorder[env]; col<envBorder[env+1]; col++) {
- for (subband = hPsEncode->iidGroupBorders[group]; subband < hPsEncode->iidGroupBorders[group+1]; subband++) {
- FIXP_QMF l_real = (hybridData[col][0][0][subband]) << scale;
- FIXP_QMF l_imag = (hybridData[col][0][1][subband]) << scale;
- FIXP_QMF r_real = (hybridData[col][1][0][subband]) << scale;
- FIXP_QMF r_imag = (hybridData[col][1][1][subband]) << scale;
-
- pwrL_env_bin += (fPow2Div2(l_real) + fPow2Div2(l_imag)) >> bScale;
- pwrR_env_bin += (fPow2Div2(r_real) + fPow2Div2(r_imag)) >> bScale;
- pwrCr_env_bin += (fMultDiv2(l_real, r_real) + fMultDiv2(l_imag, r_imag)) >> bScale;
- pwrCi_env_bin += (fMultDiv2(r_real, l_imag) - fMultDiv2(l_real, r_imag)) >> bScale;
+ for (col = envBorder[env]; col < envBorder[env + 1]; col++) {
+ for (subband = hPsEncode->iidGroupBorders[group];
+ subband < hPsEncode->iidGroupBorders[group + 1]; subband++) {
+ FIXP_DBL l_real = (hybridData[col][0][0][subband]) << scale;
+ FIXP_DBL l_imag = (hybridData[col][0][1][subband]) << scale;
+ FIXP_DBL r_real = (hybridData[col][1][0][subband]) << scale;
+ FIXP_DBL r_imag = (hybridData[col][1][1][subband]) << scale;
+
+ pwrL_env_bin += (fPow2Div2(l_real) + fPow2Div2(l_imag)) >> bScale;
+ pwrR_env_bin += (fPow2Div2(r_real) + fPow2Div2(r_imag)) >> bScale;
+ pwrCr_env_bin +=
+ (fMultDiv2(l_real, r_real) + fMultDiv2(l_imag, r_imag)) >> bScale;
+ pwrCi_env_bin +=
+ (fMultDiv2(r_real, l_imag) - fMultDiv2(l_real, r_imag)) >> bScale;
}
}
- /* assure, nrg's of left and right channel are not negative; necessary on 16 bit multiply units */
- pwrData->pwrL[env][bin] = fixMax((FIXP_DBL)0,pwrL_env_bin);
- pwrData->pwrR[env][bin] = fixMax((FIXP_DBL)0,pwrR_env_bin);
+ /* assure, nrg's of left and right channel are not negative; necessary on
+ * 16 bit multiply units */
+ pwrData->pwrL[env][bin] = fixMax((FIXP_DBL)0, pwrL_env_bin);
+ pwrData->pwrR[env][bin] = fixMax((FIXP_DBL)0, pwrR_env_bin);
pwrData->pwrCr[env][bin] = pwrCr_env_bin;
pwrData->pwrCi[env][bin] = pwrCi_env_bin;
@@ -924,126 +906,122 @@ FDK_PSENC_ERROR FDKsbrEnc_PSEncode(
/* calculate iid and icc */
calculateIID(pwrData->ldPwrL, pwrData->ldPwrR, iid, nEnvelopes, psBands);
- calculateICC(pwrData->ldPwrL, pwrData->ldPwrR, pwrData->pwrCr, pwrData->pwrCi, icc, nEnvelopes, psBands);
+ calculateICC(pwrData->pwrL, pwrData->pwrR, pwrData->pwrCr, pwrData->pwrCi,
+ icc, nEnvelopes, psBands);
/*** Envelope Reduction ***/
- while (envelopeReducible(iid,icc,psBands,nEnvelopes)) {
- int e=0;
+ while (envelopeReducible(iid, icc, psBands, nEnvelopes)) {
+ int e = 0;
/* sum energies of two neighboring envelopes */
nEnvelopes >>= 1;
- for (e=0; e<nEnvelopes; e++) {
- FDKsbrEnc_addFIXP_DBL(pwrData->pwrL[2*e], pwrData->pwrL[2*e+1], pwrData->pwrL[e], psBands);
- FDKsbrEnc_addFIXP_DBL(pwrData->pwrR[2*e], pwrData->pwrR[2*e+1], pwrData->pwrR[e], psBands);
- FDKsbrEnc_addFIXP_DBL(pwrData->pwrCr[2*e],pwrData->pwrCr[2*e+1],pwrData->pwrCr[e],psBands);
- FDKsbrEnc_addFIXP_DBL(pwrData->pwrCi[2*e],pwrData->pwrCi[2*e+1],pwrData->pwrCi[e],psBands);
+ for (e = 0; e < nEnvelopes; e++) {
+ FDKsbrEnc_addFIXP_DBL(pwrData->pwrL[2 * e], pwrData->pwrL[2 * e + 1],
+ pwrData->pwrL[e], psBands);
+ FDKsbrEnc_addFIXP_DBL(pwrData->pwrR[2 * e], pwrData->pwrR[2 * e + 1],
+ pwrData->pwrR[e], psBands);
+ FDKsbrEnc_addFIXP_DBL(pwrData->pwrCr[2 * e], pwrData->pwrCr[2 * e + 1],
+ pwrData->pwrCr[e], psBands);
+ FDKsbrEnc_addFIXP_DBL(pwrData->pwrCi[2 * e], pwrData->pwrCi[2 * e + 1],
+ pwrData->pwrCi[e], psBands);
/* calc logarithmic energy */
LdDataVector(pwrData->pwrL[e], pwrData->ldPwrL[e], psBands);
LdDataVector(pwrData->pwrR[e], pwrData->ldPwrR[e], psBands);
/* reduce number of envelopes and adjust borders */
- envBorder[e] = envBorder[2*e];
+ envBorder[e] = envBorder[2 * e];
}
- envBorder[nEnvelopes] = envBorder[2*nEnvelopes];
+ envBorder[nEnvelopes] = envBorder[2 * nEnvelopes];
/* re-calculate iid and icc */
calculateIID(pwrData->ldPwrL, pwrData->ldPwrR, iid, nEnvelopes, psBands);
- calculateICC(pwrData->ldPwrL, pwrData->ldPwrR, pwrData->pwrCr, pwrData->pwrCi, icc, nEnvelopes, psBands);
+ calculateICC(pwrData->pwrL, pwrData->pwrR, pwrData->pwrCr, pwrData->pwrCi,
+ icc, nEnvelopes, psBands);
}
-
/* */
- if(sendHeader) {
- hPsData->headerCnt = MAX_PS_NOHEADER_CNT;
+ if (sendHeader) {
+ hPsData->headerCnt = MAX_PS_NOHEADER_CNT;
hPsData->iidTimeCnt = MAX_TIME_DIFF_FRAMES;
hPsData->iccTimeCnt = MAX_TIME_DIFF_FRAMES;
- hPsData->noEnvCnt = MAX_NOENV_CNT;
+ hPsData->noEnvCnt = MAX_NOENV_CNT;
}
/*** Parameter processing, quantisation etc ***/
- processIidData(hPsData, iid, psBands, nEnvelopes, hPsEncode->iidQuantErrorThreshold);
+ processIidData(hPsData, iid, psBands, nEnvelopes,
+ hPsEncode->iidQuantErrorThreshold);
processIccData(hPsData, icc, psBands, nEnvelopes);
-
/*** Initialize output struct ***/
/* PS Header on/off ? */
- if( (hPsData->headerCnt<MAX_PS_NOHEADER_CNT)
- && ( (hPsData->iidQuantMode == hPsData->iidQuantModeLast) && (hPsData->iccQuantMode == hPsData->iccQuantModeLast) )
- && ( (hPsData->iidEnable == hPsData->iidEnableLast) && (hPsData->iccEnable == hPsData->iccEnableLast) ) ) {
+ if ((hPsData->headerCnt < MAX_PS_NOHEADER_CNT) &&
+ ((hPsData->iidQuantMode == hPsData->iidQuantModeLast) &&
+ (hPsData->iccQuantMode == hPsData->iccQuantModeLast)) &&
+ ((hPsData->iidEnable == hPsData->iidEnableLast) &&
+ (hPsData->iccEnable == hPsData->iccEnableLast))) {
hPsOut->enablePSHeader = 0;
- }
- else {
+ } else {
hPsOut->enablePSHeader = 1;
hPsData->headerCnt = 0;
}
/* nEnvelopes = 0 ? */
- if ( (hPsData->noEnvCnt < MAX_NOENV_CNT)
- && (similarIid(hPsData, psBands, nEnvelopes))
- && (similarIcc(hPsData, psBands, nEnvelopes)) ) {
+ if ((hPsData->noEnvCnt < MAX_NOENV_CNT) &&
+ (similarIid(hPsData, psBands, nEnvelopes)) &&
+ (similarIcc(hPsData, psBands, nEnvelopes))) {
hPsOut->nEnvelopes = nEnvelopes = 0;
hPsData->noEnvCnt++;
} else {
hPsData->noEnvCnt = 0;
}
+ if (nEnvelopes > 0) {
+ hPsOut->enableIID = hPsData->iidEnable;
+ hPsOut->iidMode = getIIDMode(psBands, hPsData->iidQuantMode);
- if (nEnvelopes>0) {
-
- hPsOut->enableIID = hPsData->iidEnable;
- hPsOut->iidMode = getIIDMode(psBands, hPsData->iidQuantMode);
+ hPsOut->enableICC = hPsData->iccEnable;
+ hPsOut->iccMode = getICCMode(psBands, hPsData->iccQuantMode);
- hPsOut->enableICC = hPsData->iccEnable;
- hPsOut->iccMode = getICCMode(psBands, hPsData->iccQuantMode);
+ hPsOut->enableIpdOpd = 0;
+ hPsOut->frameClass = 0;
+ hPsOut->nEnvelopes = nEnvelopes;
- hPsOut->enableIpdOpd = 0;
- hPsOut->frameClass = 0;
- hPsOut->nEnvelopes = nEnvelopes;
-
- for(env=0; env<nEnvelopes; env++) {
- hPsOut->frameBorder[env] = envBorder[env+1];
- }
-
- for(env=0; env<hPsOut->nEnvelopes; env++) {
+ for (env = 0; env < nEnvelopes; env++) {
+ hPsOut->frameBorder[env] = envBorder[env + 1];
hPsOut->deltaIID[env] = (PS_DELTA)hPsData->iidDiffMode[env];
-
- for(band=0; band<psBands; band++) {
- hPsOut->iid[env][band] = hPsData->iidIdx[env][band];
- }
- }
-
- for(env=0; env<hPsOut->nEnvelopes; env++) {
hPsOut->deltaICC[env] = (PS_DELTA)hPsData->iccDiffMode[env];
- for(band=0; band<psBands; band++) {
+ for (band = 0; band < psBands; band++) {
+ hPsOut->iid[env][band] = hPsData->iidIdx[env][band];
hPsOut->icc[env][band] = hPsData->iccIdx[env][band];
}
}
/* IPD OPD not supported right now */
- FDKmemclear(hPsOut->ipd, PS_MAX_ENVELOPES*PS_MAX_BANDS*sizeof(PS_DELTA));
- for(env=0; env<PS_MAX_ENVELOPES; env++) {
+ FDKmemclear(hPsOut->ipd,
+ PS_MAX_ENVELOPES * PS_MAX_BANDS * sizeof(PS_DELTA));
+ for (env = 0; env < PS_MAX_ENVELOPES; env++) {
hPsOut->deltaIPD[env] = PS_DELTA_FREQ;
hPsOut->deltaOPD[env] = PS_DELTA_FREQ;
}
- FDKmemclear(hPsOut->ipdLast, PS_MAX_BANDS*sizeof(INT));
- FDKmemclear(hPsOut->opdLast, PS_MAX_BANDS*sizeof(INT));
+ FDKmemclear(hPsOut->ipdLast, PS_MAX_BANDS * sizeof(INT));
+ FDKmemclear(hPsOut->opdLast, PS_MAX_BANDS * sizeof(INT));
- for(band=0; band<PS_MAX_BANDS; band++) {
+ for (band = 0; band < PS_MAX_BANDS; band++) {
hPsOut->iidLast[band] = hPsData->iidIdxLast[band];
hPsOut->iccLast[band] = hPsData->iccIdxLast[band];
}
/* save iids and iccs for differential time coding in the next frame */
- hPsData->nEnvelopesLast = nEnvelopes;
- hPsData->iidEnableLast = hPsData->iidEnable;
- hPsData->iccEnableLast = hPsData->iccEnable;
+ hPsData->nEnvelopesLast = nEnvelopes;
+ hPsData->iidEnableLast = hPsData->iidEnable;
+ hPsData->iccEnableLast = hPsData->iccEnable;
hPsData->iidQuantModeLast = hPsData->iidQuantMode;
hPsData->iccQuantModeLast = hPsData->iccQuantMode;
- for (i=0; i<psBands; i++) {
- hPsData->iidIdxLast[i] = hPsData->iidIdx[nEnvelopes-1][i];
- hPsData->iccIdxLast[i] = hPsData->iccIdx[nEnvelopes-1][i];
+ for (i = 0; i < psBands; i++) {
+ hPsData->iidIdxLast[i] = hPsData->iidIdx[nEnvelopes - 1][i];
+ hPsData->iccIdxLast[i] = hPsData->iccIdx[nEnvelopes - 1][i];
}
} /* Envelope > 0 */
@@ -1051,4 +1029,3 @@ FDK_PSENC_ERROR FDKsbrEnc_PSEncode(
return error;
}
-