2018-02-26 20:17:00 +01:00
|
|
|
/* -----------------------------------------------------------------------------
|
2012-07-11 10:15:24 -07:00
|
|
|
Software License for The Fraunhofer FDK AAC Codec Library for Android
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
|
|
|
|
Forschung e.V. All rights reserved.
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
1. INTRODUCTION
|
2018-02-26 20:17:00 +01:00
|
|
|
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.
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
2. COPYRIGHT LICENSE
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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:
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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.
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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
|
2012-07-11 10:15:24 -07:00
|
|
|
modifications thereto to recipients of copies in binary form.
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
The name of Fraunhofer may not be used to endorse or promote products derived
|
|
|
|
from this library without prior written permission.
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
You may not charge copyright license fees for anyone to use, copy or distribute
|
|
|
|
the FDK AAC Codec software or your modifications thereto.
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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."
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
3. NO PATENT LICENSE
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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.
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
You may use this FDK AAC Codec software or modifications thereto only for
|
|
|
|
purposes that are authorized by appropriate patent licenses.
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
4. DISCLAIMER
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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.
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
5. CONTACT INFORMATION
|
|
|
|
|
|
|
|
Fraunhofer Institute for Integrated Circuits IIS
|
|
|
|
Attention: Audio and Multimedia Departments - FDK AAC LL
|
|
|
|
Am Wolfsmantel 33
|
|
|
|
91058 Erlangen, Germany
|
|
|
|
|
|
|
|
www.iis.fraunhofer.de/amm
|
|
|
|
amm-info@iis.fraunhofer.de
|
2018-02-26 20:17:00 +01:00
|
|
|
----------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**************************** AAC encoder library ******************************
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
Author(s): M. Werner
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
Description: Scale factor estimation
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
*******************************************************************************/
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
#include "sf_estim.h"
|
|
|
|
#include "aacEnc_rom.h"
|
|
|
|
#include "quantize.h"
|
|
|
|
#include "bit_cnt.h"
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
#ifdef __arm__
|
|
|
|
#endif
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
#define UPCOUNT_LIMIT 1
|
2012-07-11 10:15:24 -07:00
|
|
|
#define AS_PE_FAC_SHIFT 7
|
2018-02-26 20:17:00 +01:00
|
|
|
#define DIST_FAC_SHIFT 3
|
2012-07-11 10:15:24 -07:00
|
|
|
#define AS_PE_FAC_FLOAT (float)(1 << AS_PE_FAC_SHIFT)
|
|
|
|
static const INT MAX_SCF_DELTA = 60;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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 */
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function; FDKaacEnc_FDKaacEnc_CalcFormFactorChannel
|
|
|
|
|
|
|
|
Description: Calculates the formfactor
|
|
|
|
|
|
|
|
sf: scale factor of the mdct spectrum
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbFormFactorLdData is scaled with the factor 1/(((2^sf)^0.5) *
|
|
|
|
(2^FORM_FAC_SHIFT))
|
2012-07-11 10:15:24 -07:00
|
|
|
*/
|
2018-02-26 20:17:00 +01:00
|
|
|
static void FDKaacEnc_FDKaacEnc_CalcFormFactorChannel(
|
|
|
|
FIXP_DBL *RESTRICT sfbFormFactorLdData,
|
|
|
|
PSY_OUT_CHANNEL *RESTRICT psyOutChan) {
|
2012-07-11 10:15:24 -07:00
|
|
|
INT j, sfb, sfbGrp;
|
|
|
|
FIXP_DBL formFactor;
|
|
|
|
|
|
|
|
int tmp0 = psyOutChan->sfbCnt;
|
|
|
|
int tmp1 = psyOutChan->maxSfbPerGroup;
|
|
|
|
int step = psyOutChan->sfbPerGroup;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfbGrp = 0; sfbGrp < tmp0; sfbGrp += step) {
|
2012-07-11 10:15:24 -07:00
|
|
|
for (sfb = 0; sfb < tmp1; sfb++) {
|
|
|
|
formFactor = FL2FXCONST_DBL(0.0f);
|
|
|
|
/* calc sum of sqrt(spec) */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (j = psyOutChan->sfbOffsets[sfbGrp + sfb];
|
|
|
|
j < psyOutChan->sfbOffsets[sfbGrp + sfb + 1]; j++) {
|
|
|
|
formFactor +=
|
|
|
|
sqrtFixp(fixp_abs(psyOutChan->mdctSpectrum[j])) >> FORM_FAC_SHIFT;
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbFormFactorLdData[sfbGrp + sfb] = CalcLdData(formFactor);
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
/* set sfbFormFactor for sfbs with zero spec to zero. Just for debugging. */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (; sfb < psyOutChan->sfbPerGroup; sfb++) {
|
|
|
|
sfbFormFactorLdData[sfbGrp + sfb] = FL2FXCONST_DBL(-1.0f);
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: FDKaacEnc_CalcFormFactor
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
Description: Calls FDKaacEnc_FDKaacEnc_CalcFormFactorChannel() for each
|
|
|
|
channel
|
2012-07-11 10:15:24 -07:00
|
|
|
*/
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
void FDKaacEnc_CalcFormFactor(QC_OUT_CHANNEL *qcOutChannel[(2)],
|
|
|
|
PSY_OUT_CHANNEL *psyOutChannel[(2)],
|
|
|
|
const INT nChannels) {
|
2012-07-11 10:15:24 -07:00
|
|
|
INT j;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (j = 0; j < nChannels; j++) {
|
|
|
|
FDKaacEnc_FDKaacEnc_CalcFormFactorChannel(
|
|
|
|
qcOutChannel[j]->sfbFormFactorLdData, psyOutChannel[j]);
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: FDKaacEnc_calcSfbRelevantLines
|
|
|
|
|
|
|
|
Description: Calculates sfbNRelevantLines
|
|
|
|
|
|
|
|
sfbNRelevantLines is scaled with the factor 1/((2^FORM_FAC_SHIFT) * 2.0)
|
|
|
|
*/
|
2018-02-26 20:17:00 +01:00
|
|
|
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) {
|
2012-07-11 10:15:24 -07:00
|
|
|
INT sfbOffs, sfb;
|
|
|
|
FIXP_DBL sfbWidthLdData;
|
2018-02-26 20:17:00 +01:00
|
|
|
FIXP_DBL asPeFacLdData =
|
|
|
|
FL2FXCONST_DBL(0.109375); /* AS_PE_FAC_SHIFT*ld64(2) */
|
2012-07-11 10:15:24 -07:00
|
|
|
FIXP_DBL accu;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
/* sfbNRelevantLines[i] = 2^( (sfbFormFactorLdData[i] - 0.25 *
|
|
|
|
* (sfbEnergyLdData[i] - ld64(sfbWidth[i]/(2^7)) - AS_PE_FAC_SHIFT*ld64(2)) *
|
|
|
|
* 64); */
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
FDKmemclear(sfbNRelevantLines, sfbCnt * sizeof(FIXP_DBL));
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfbOffs = 0; sfbOffs < sfbCnt; sfbOffs += sfbPerGroup) {
|
|
|
|
for (sfb = 0; sfb < maxSfbPerGroup; sfb++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
/* calc sum of sqrt(spec) */
|
2018-02-26 20:17:00 +01:00
|
|
|
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));
|
2012-07-11 10:15:24 -07:00
|
|
|
sfbWidthLdData = CalcLdData(sfbWidthLdData);
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
accu = sfbEnergyLdData[sfbOffs + sfb] - sfbWidthLdData - asPeFacLdData;
|
|
|
|
accu = sfbFormFactorLdData[sfbOffs + sfb] - (accu >> 2);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbNRelevantLines[sfbOffs + sfb] = CalcInvLdData(accu) >> 1;
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: FDKaacEnc_countSingleScfBits
|
|
|
|
|
|
|
|
Description:
|
|
|
|
|
|
|
|
scfBitsFract is scaled by 1/(2^(2*AS_PE_FAC_SHIFT))
|
|
|
|
*/
|
2018-02-26 20:17:00 +01:00
|
|
|
static FIXP_DBL FDKaacEnc_countSingleScfBits(INT scf, INT scfLeft,
|
|
|
|
INT scfRight) {
|
2012-07-11 10:15:24 -07:00
|
|
|
FIXP_DBL scfBitsFract;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
scfBitsFract = (FIXP_DBL)(FDKaacEnc_bitCountScalefactorDelta(scfLeft - scf) +
|
|
|
|
FDKaacEnc_bitCountScalefactorDelta(scf - scfRight));
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
scfBitsFract = scfBitsFract << (DFRACT_BITS - 1 - (2 * AS_PE_FAC_SHIFT));
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
return scfBitsFract; /* output scaled by 1/(2^(2*AS_PE_FAC)) */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: FDKaacEnc_calcSingleSpecPe
|
|
|
|
|
|
|
|
specPe is scaled by 1/(2^(2*AS_PE_FAC_SHIFT))
|
|
|
|
*/
|
2018-02-26 20:17:00 +01:00
|
|
|
static FIXP_DBL FDKaacEnc_calcSingleSpecPe(INT scf, FIXP_DBL sfbConstPePart,
|
|
|
|
FIXP_DBL nLines) {
|
2012-07-11 10:15:24 -07:00
|
|
|
FIXP_DBL specPe = FL2FXCONST_DBL(0.0f);
|
|
|
|
FIXP_DBL ldRatio;
|
|
|
|
FIXP_DBL scfFract;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
scfFract = (FIXP_DBL)(scf << (DFRACT_BITS - 1 - AS_PE_FAC_SHIFT));
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
ldRatio = sfbConstPePart - fMult(FL2FXCONST_DBL(0.375f), scfFract);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
if (ldRatio >= PE_C1) {
|
2018-02-26 20:17:00 +01:00
|
|
|
specPe = fMult(FL2FXCONST_DBL(0.7f), fMult(nLines, ldRatio));
|
|
|
|
} else {
|
|
|
|
specPe = fMult(FL2FXCONST_DBL(0.7f),
|
|
|
|
fMult(nLines, (PE_C2 + fMult(PE_C3, ldRatio))));
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return specPe; /* output scaled by 1/(2^(2*AS_PE_FAC)) */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: FDKaacEnc_countScfBitsDiff
|
|
|
|
|
|
|
|
scfBitsDiff is scaled by 1/(2^(2*AS_PE_FAC_SHIFT))
|
|
|
|
*/
|
2018-02-26 20:17:00 +01:00
|
|
|
static FIXP_DBL FDKaacEnc_countScfBitsDiff(INT *scfOld, INT *scfNew, INT sfbCnt,
|
|
|
|
INT startSfb, INT stopSfb) {
|
2012-07-11 10:15:24 -07:00
|
|
|
FIXP_DBL scfBitsFract;
|
|
|
|
INT scfBitsDiff = 0;
|
|
|
|
INT sfb = 0, sfbLast;
|
|
|
|
INT sfbPrev, sfbNext;
|
|
|
|
|
|
|
|
/* search for first relevant sfb */
|
|
|
|
sfbLast = startSfb;
|
2018-02-26 20:17:00 +01:00
|
|
|
while ((sfbLast < stopSfb) && (scfOld[sfbLast] == FDK_INT_MIN)) sfbLast++;
|
2012-07-11 10:15:24 -07:00
|
|
|
/* search for previous relevant sfb and count diff */
|
|
|
|
sfbPrev = startSfb - 1;
|
2018-02-26 20:17:00 +01:00
|
|
|
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]);
|
2012-07-11 10:15:24 -07:00
|
|
|
/* now loop through all sfbs and count diffs of relevant sfbs */
|
2018-02-26 20:17:00 +01:00
|
|
|
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]);
|
2012-07-11 10:15:24 -07:00
|
|
|
sfbLast = sfb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* search for next relevant sfb and count diff */
|
|
|
|
sfbNext = stopSfb;
|
2018-02-26 20:17:00 +01:00
|
|
|
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]);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
scfBitsFract =
|
|
|
|
(FIXP_DBL)(scfBitsDiff << (DFRACT_BITS - 1 - (2 * AS_PE_FAC_SHIFT)));
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
return scfBitsFract;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: FDKaacEnc_calcSpecPeDiff
|
|
|
|
|
|
|
|
specPeDiff is scaled by 1/(2^(2*AS_PE_FAC_SHIFT))
|
|
|
|
*/
|
2018-02-26 20:17:00 +01:00
|
|
|
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) {
|
2012-07-11 10:15:24 -07:00
|
|
|
FIXP_DBL specPeDiff = FL2FXCONST_DBL(0.0f);
|
|
|
|
FIXP_DBL scfFract = FL2FXCONST_DBL(0.0f);
|
|
|
|
INT sfb;
|
|
|
|
|
|
|
|
/* loop through all sfbs and count pe difference */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
|
|
|
if (scfOld[sfb] != FDK_INT_MIN) {
|
2012-07-11 10:15:24 -07:00
|
|
|
FIXP_DBL ldRatioOld, ldRatioNew, pOld, pNew;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
/* 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 */
|
2012-07-11 10:15:24 -07:00
|
|
|
/* 0.09375f = log(64.0)/log(2.0)/64.0 = scale of sfbFormFactorLdData */
|
|
|
|
if (sfbConstPePart[sfb] == (FIXP_DBL)FDK_INT_MIN)
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbConstPePart[sfb] =
|
|
|
|
((psyOutChan->sfbEnergyLdData[sfb] - sfbFormFactorLdData[sfb] -
|
|
|
|
FL2FXCONST_DBL(0.09375f)) >>
|
|
|
|
1) +
|
|
|
|
FL2FXCONST_DBL(0.02152255861f);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
scfFract = (FIXP_DBL)(scfOld[sfb] << (DFRACT_BITS - 1 - AS_PE_FAC_SHIFT));
|
|
|
|
ldRatioOld =
|
|
|
|
sfbConstPePart[sfb] - fMult(FL2FXCONST_DBL(0.375f), scfFract);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
scfFract = (FIXP_DBL)(scfNew[sfb] << (DFRACT_BITS - 1 - AS_PE_FAC_SHIFT));
|
|
|
|
ldRatioNew =
|
|
|
|
sfbConstPePart[sfb] - fMult(FL2FXCONST_DBL(0.375f), scfFract);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
if (ldRatioOld >= PE_C1)
|
|
|
|
pOld = ldRatioOld;
|
|
|
|
else
|
2018-02-26 20:17:00 +01:00
|
|
|
pOld = PE_C2 + fMult(PE_C3, ldRatioOld);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
if (ldRatioNew >= PE_C1)
|
|
|
|
pNew = ldRatioNew;
|
|
|
|
else
|
2018-02-26 20:17:00 +01:00
|
|
|
pNew = PE_C2 + fMult(PE_C3, ldRatioNew);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
specPeDiff += fMult(FL2FXCONST_DBL(0.7f),
|
|
|
|
fMult(sfbNRelevantLines[sfb], (pNew - pOld)));
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return specPeDiff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: FDKaacEnc_improveScf
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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.
|
2012-07-11 10:15:24 -07:00
|
|
|
*/
|
2018-02-26 20:17:00 +01:00
|
|
|
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];
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
2018-02-26 20:17:00 +01:00
|
|
|
}
|
|
|
|
/* 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];
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
2018-02-26 20:17:00 +01:00
|
|
|
*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];
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
2018-02-26 20:17:00 +01:00
|
|
|
}
|
|
|
|
*distLdData = sfbDistBestLdData;
|
|
|
|
}
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
/* return best scalefactor */
|
|
|
|
return scfBest;
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: FDKaacEnc_assimilateSingleScf
|
|
|
|
|
|
|
|
*/
|
2018-02-26 20:17:00 +01:00
|
|
|
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) {
|
2012-07-11 10:15:24 -07:00
|
|
|
INT sfbLast, sfbAct, sfbNext;
|
|
|
|
INT scfAct, *scfLast, *scfNext, scfMin, scfMax;
|
|
|
|
INT sfbWidth, sfbOffs;
|
|
|
|
FIXP_DBL enLdData;
|
|
|
|
FIXP_DBL sfbPeOld, sfbPeNew;
|
|
|
|
FIXP_DBL sfbDistNew;
|
|
|
|
INT i, k;
|
|
|
|
INT success = 0;
|
|
|
|
FIXP_DBL deltaPe = FL2FXCONST_DBL(0.0f);
|
|
|
|
FIXP_DBL deltaPeNew, deltaPeTmp;
|
|
|
|
INT prevScfLast[MAX_GROUPED_SFB], prevScfNext[MAX_GROUPED_SFB];
|
|
|
|
FIXP_DBL deltaPeLast[MAX_GROUPED_SFB];
|
|
|
|
INT updateMinScfCalculated;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
for (i = 0; i < psyOutChan->sfbCnt; i++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
prevScfLast[i] = FDK_INT_MAX;
|
|
|
|
prevScfNext[i] = FDK_INT_MAX;
|
|
|
|
deltaPeLast[i] = (FIXP_DBL)FDK_INT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
sfbLast = -1;
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbAct = -1;
|
2012-07-11 10:15:24 -07:00
|
|
|
sfbNext = -1;
|
|
|
|
scfLast = 0;
|
|
|
|
scfNext = 0;
|
2018-02-26 20:17:00 +01:00
|
|
|
scfMin = FDK_INT_MAX;
|
|
|
|
scfMax = FDK_INT_MAX;
|
2012-07-11 10:15:24 -07:00
|
|
|
do {
|
|
|
|
/* search for new relevant sfb */
|
|
|
|
sfbNext++;
|
|
|
|
while ((sfbNext < psyOutChan->sfbCnt) && (scf[sfbNext] == FDK_INT_MIN))
|
|
|
|
sfbNext++;
|
2018-02-26 20:17:00 +01:00
|
|
|
if ((sfbLast >= 0) && (sfbAct >= 0) && (sfbNext < psyOutChan->sfbCnt)) {
|
2012-07-11 10:15:24 -07:00
|
|
|
/* relevant scfs to the left and to the right */
|
2018-02-26 20:17:00 +01:00
|
|
|
scfAct = scf[sfbAct];
|
2012-07-11 10:15:24 -07:00
|
|
|
scfLast = scf + sfbLast;
|
|
|
|
scfNext = scf + sfbNext;
|
2018-02-26 20:17:00 +01:00
|
|
|
scfMin = fixMin(*scfLast, *scfNext);
|
|
|
|
scfMax = fixMax(*scfLast, *scfNext);
|
|
|
|
} else if ((sfbLast == -1) && (sfbAct >= 0) &&
|
|
|
|
(sfbNext < psyOutChan->sfbCnt)) {
|
2012-07-11 10:15:24 -07:00
|
|
|
/* first relevant scf */
|
2018-02-26 20:17:00 +01:00
|
|
|
scfAct = scf[sfbAct];
|
2012-07-11 10:15:24 -07:00
|
|
|
scfLast = &scfAct;
|
|
|
|
scfNext = scf + sfbNext;
|
2018-02-26 20:17:00 +01:00
|
|
|
scfMin = *scfNext;
|
|
|
|
scfMax = *scfNext;
|
|
|
|
} else if ((sfbLast >= 0) && (sfbAct >= 0) &&
|
|
|
|
(sfbNext == psyOutChan->sfbCnt)) {
|
2012-07-11 10:15:24 -07:00
|
|
|
/* last relevant scf */
|
2018-02-26 20:17:00 +01:00
|
|
|
scfAct = scf[sfbAct];
|
2012-07-11 10:15:24 -07:00
|
|
|
scfLast = scf + sfbLast;
|
|
|
|
scfNext = &scfAct;
|
2018-02-26 20:17:00 +01:00
|
|
|
scfMin = *scfLast;
|
|
|
|
scfMax = *scfLast;
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
2018-02-26 20:17:00 +01:00
|
|
|
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] ||
|
2012-07-11 10:15:24 -07:00
|
|
|
deltaPe < deltaPeLast[sfbAct])) {
|
|
|
|
/* bigger than neighbouring scf found, try to use smaller scf */
|
|
|
|
success = 0;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbWidth =
|
|
|
|
psyOutChan->sfbOffsets[sfbAct + 1] - psyOutChan->sfbOffsets[sfbAct];
|
2012-07-11 10:15:24 -07:00
|
|
|
sfbOffs = psyOutChan->sfbOffsets[sfbAct];
|
|
|
|
|
|
|
|
/* estimate required bits for actual scf */
|
|
|
|
enLdData = qcOutChannel->sfbEnergyLdData[sfbAct];
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
/* 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 */
|
2012-07-11 10:15:24 -07:00
|
|
|
/* 0.09375f = log(64.0)/log(2.0)/64.0 = scale of sfbFormFactorLdData */
|
|
|
|
if (sfbConstPePart[sfbAct] == (FIXP_DBL)FDK_INT_MIN) {
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbConstPePart[sfbAct] = ((enLdData - sfbFormFactorLdData[sfbAct] -
|
|
|
|
FL2FXCONST_DBL(0.09375f)) >>
|
|
|
|
1) +
|
|
|
|
FL2FXCONST_DBL(0.02152255861f);
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbPeOld = FDKaacEnc_calcSingleSpecPe(scfAct, sfbConstPePart[sfbAct],
|
|
|
|
sfbNRelevantLines[sfbAct]) +
|
|
|
|
FDKaacEnc_countSingleScfBits(scfAct, *scfLast, *scfNext);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
deltaPeNew = deltaPe;
|
|
|
|
updateMinScfCalculated = 1;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* estimate required bits for smaller scf */
|
|
|
|
scfAct--;
|
|
|
|
/* check only if the same check was not done before */
|
2018-02-26 20:17:00 +01:00
|
|
|
if (scfAct < minScfCalculated[sfbAct] &&
|
|
|
|
scfAct >= scfMax - MAX_SCF_DELTA) {
|
2012-07-11 10:15:24 -07:00
|
|
|
/* estimate required bits for new scf */
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbPeNew = FDKaacEnc_calcSingleSpecPe(scfAct, sfbConstPePart[sfbAct],
|
|
|
|
sfbNRelevantLines[sfbAct]) +
|
|
|
|
FDKaacEnc_countSingleScfBits(scfAct, *scfLast, *scfNext);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
/* use new scf if no increase in pe and
|
|
|
|
quantization error is smaller */
|
|
|
|
deltaPeTmp = deltaPe + sfbPeNew - sfbPeOld;
|
|
|
|
/* 0.0006103515625f = 10.0f/(2^(2*AS_PE_FAC_SHIFT)) */
|
|
|
|
if (deltaPeTmp < FL2FXCONST_DBL(0.0006103515625f)) {
|
|
|
|
/* distortion of new scf */
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbDistNew = FDKaacEnc_calcSfbDist(
|
|
|
|
qcOutChannel->mdctSpectrum + sfbOffs, quantSpecTmp + sfbOffs,
|
|
|
|
sfbWidth, scfAct, dZoneQuantEnable);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
if (sfbDistNew < sfbDist[sfbAct]) {
|
|
|
|
/* success, replace scf by new one */
|
|
|
|
scf[sfbAct] = scfAct;
|
|
|
|
sfbDist[sfbAct] = sfbDistNew;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
for (k = 0; k < sfbWidth; k++)
|
|
|
|
quantSpec[sfbOffs + k] = quantSpecTmp[sfbOffs + k];
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
deltaPeNew = deltaPeTmp;
|
|
|
|
success = 1;
|
|
|
|
}
|
|
|
|
/* mark as already checked */
|
2018-02-26 20:17:00 +01:00
|
|
|
if (updateMinScfCalculated) minScfCalculated[sfbAct] = scfAct;
|
|
|
|
} else {
|
2012-07-11 10:15:24 -07:00
|
|
|
/* from this scf value on not all new values have been checked */
|
|
|
|
updateMinScfCalculated = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (scfAct > scfMin);
|
|
|
|
|
|
|
|
deltaPe = deltaPeNew;
|
|
|
|
|
|
|
|
/* save parameters to avoid multiple computations of the same sfb */
|
|
|
|
prevScfLast[sfbAct] = *scfLast;
|
|
|
|
prevScfNext[sfbAct] = *scfNext;
|
|
|
|
deltaPeLast[sfbAct] = deltaPe;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success && restartOnSuccess) {
|
|
|
|
/* start again at first sfb */
|
|
|
|
sfbLast = -1;
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbAct = -1;
|
2012-07-11 10:15:24 -07:00
|
|
|
sfbNext = -1;
|
|
|
|
scfLast = 0;
|
|
|
|
scfNext = 0;
|
2018-02-26 20:17:00 +01:00
|
|
|
scfMin = FDK_INT_MAX;
|
|
|
|
scfMax = FDK_INT_MAX;
|
2012-07-11 10:15:24 -07:00
|
|
|
success = 0;
|
2018-02-26 20:17:00 +01:00
|
|
|
} else {
|
2012-07-11 10:15:24 -07:00
|
|
|
/* shift sfbs for next band */
|
|
|
|
sfbLast = sfbAct;
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbAct = sfbNext;
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
} while (sfbNext < psyOutChan->sfbCnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: FDKaacEnc_assimilateMultipleScf
|
|
|
|
|
|
|
|
*/
|
2018-02-26 20:17:00 +01:00
|
|
|
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) {
|
2012-07-11 10:15:24 -07:00
|
|
|
INT sfb, startSfb, stopSfb;
|
|
|
|
INT scfTmp[MAX_GROUPED_SFB], scfMin, scfMax, scfAct;
|
|
|
|
INT possibleRegionFound;
|
|
|
|
INT sfbWidth, sfbOffs, i, k;
|
|
|
|
FIXP_DBL sfbDistNew[MAX_GROUPED_SFB], distOldSum, distNewSum;
|
|
|
|
INT deltaScfBits;
|
|
|
|
FIXP_DBL deltaSpecPe;
|
|
|
|
FIXP_DBL deltaPe = FL2FXCONST_DBL(0.0f);
|
|
|
|
FIXP_DBL deltaPeNew;
|
|
|
|
INT sfbCnt = psyOutChan->sfbCnt;
|
|
|
|
|
|
|
|
/* calc min and max scalfactors */
|
|
|
|
scfMin = FDK_INT_MAX;
|
|
|
|
scfMax = FDK_INT_MIN;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = 0; sfb < sfbCnt; sfb++) {
|
|
|
|
if (scf[sfb] != FDK_INT_MIN) {
|
2012-07-11 10:15:24 -07:00
|
|
|
scfMin = fixMin(scfMin, scf[sfb]);
|
|
|
|
scfMax = fixMax(scfMax, scf[sfb]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
if (scfMax != FDK_INT_MIN && scfMax <= scfMin + MAX_SCF_DELTA) {
|
2012-07-11 10:15:24 -07:00
|
|
|
scfAct = scfMax;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* try smaller scf */
|
|
|
|
scfAct--;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (i = 0; i < MAX_GROUPED_SFB; i++) scfTmp[i] = scf[i];
|
2012-07-11 10:15:24 -07:00
|
|
|
stopSfb = 0;
|
|
|
|
do {
|
|
|
|
/* search for region where all scfs are bigger than scfAct */
|
|
|
|
sfb = stopSfb;
|
2018-02-26 20:17:00 +01:00
|
|
|
while (sfb < sfbCnt && (scf[sfb] == FDK_INT_MIN || scf[sfb] <= scfAct))
|
2012-07-11 10:15:24 -07:00
|
|
|
sfb++;
|
|
|
|
startSfb = sfb;
|
|
|
|
sfb++;
|
2018-02-26 20:17:00 +01:00
|
|
|
while (sfb < sfbCnt && (scf[sfb] == FDK_INT_MIN || scf[sfb] > scfAct))
|
2012-07-11 10:15:24 -07:00
|
|
|
sfb++;
|
|
|
|
stopSfb = sfb;
|
|
|
|
|
|
|
|
/* check if in all sfb of a valid region scfAct >= minScf[sfb] */
|
|
|
|
possibleRegionFound = 0;
|
|
|
|
if (startSfb < sfbCnt) {
|
|
|
|
possibleRegionFound = 1;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
if (scf[sfb] != FDK_INT_MIN)
|
|
|
|
if (scfAct < minScf[sfb]) {
|
|
|
|
possibleRegionFound = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (possibleRegionFound) { /* region found */
|
|
|
|
|
|
|
|
/* replace scfs in region by scfAct */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
|
|
|
if (scfTmp[sfb] != FDK_INT_MIN) scfTmp[sfb] = scfAct;
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* estimate change in bit demand for new scfs */
|
2018-02-26 20:17:00 +01:00
|
|
|
deltaScfBits = FDKaacEnc_countScfBitsDiff(scf, scfTmp, sfbCnt,
|
|
|
|
startSfb, stopSfb);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
deltaSpecPe = FDKaacEnc_calcSpecPeDiff(
|
|
|
|
psyOutChan, qcOutChannel, scf, scfTmp, sfbConstPePart,
|
|
|
|
sfbFormFactorLdData, sfbNRelevantLines, startSfb, stopSfb);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
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);
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
if (scfTmp[sfb] != FDK_INT_MIN) {
|
|
|
|
distOldSum += CalcInvLdData(sfbDist[sfb]) >> DIST_FAC_SHIFT;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbWidth = psyOutChan->sfbOffsets[sfb + 1] -
|
|
|
|
psyOutChan->sfbOffsets[sfb];
|
2012-07-11 10:15:24 -07:00
|
|
|
sfbOffs = psyOutChan->sfbOffsets[sfb];
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(
|
|
|
|
qcOutChannel->mdctSpectrum + sfbOffs,
|
|
|
|
quantSpecTmp + sfbOffs, sfbWidth, scfAct, dZoneQuantEnable);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
if (sfbDistNew[sfb] > qcOutChannel->sfbThresholdLdData[sfb]) {
|
2012-07-11 10:15:24 -07:00
|
|
|
/* no improvement, skip further dist. calculations */
|
|
|
|
distNewSum = distOldSum << 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
distNewSum += CalcInvLdData(sfbDistNew[sfb]) >> DIST_FAC_SHIFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* distortion smaller ? -> use new scalefactors */
|
|
|
|
if (distNewSum < distOldSum) {
|
|
|
|
deltaPe = deltaPeNew;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
if (scf[sfb] != FDK_INT_MIN) {
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbWidth = psyOutChan->sfbOffsets[sfb + 1] -
|
2012-07-11 10:15:24 -07:00
|
|
|
psyOutChan->sfbOffsets[sfb];
|
|
|
|
sfbOffs = psyOutChan->sfbOffsets[sfb];
|
|
|
|
scf[sfb] = scfAct;
|
|
|
|
sfbDist[sfb] = sfbDistNew[sfb];
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
for (k = 0; k < sfbWidth; k++)
|
|
|
|
quantSpec[sfbOffs + k] = quantSpecTmp[sfbOffs + k];
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (stopSfb <= sfbCnt);
|
|
|
|
|
|
|
|
} while (scfAct > scfMin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: FDKaacEnc_FDKaacEnc_assimilateMultipleScf2
|
|
|
|
|
|
|
|
*/
|
2018-02-26 20:17:00 +01:00
|
|
|
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) {
|
2012-07-11 10:15:24 -07:00
|
|
|
INT sfb, startSfb, stopSfb;
|
|
|
|
INT scfTmp[MAX_GROUPED_SFB], scfAct, scfNew;
|
|
|
|
INT scfPrev, scfNext, scfPrevNextMin, scfPrevNextMax, scfLo, scfHi;
|
|
|
|
INT scfMin, scfMax;
|
|
|
|
INT *sfbOffs = psyOutChan->sfbOffsets;
|
|
|
|
FIXP_DBL sfbDistNew[MAX_GROUPED_SFB], sfbDistMax[MAX_GROUPED_SFB];
|
|
|
|
FIXP_DBL distOldSum, distNewSum;
|
|
|
|
INT deltaScfBits;
|
|
|
|
FIXP_DBL deltaSpecPe;
|
|
|
|
FIXP_DBL deltaPe = FL2FXCONST_DBL(0.0f);
|
|
|
|
FIXP_DBL deltaPeNew = FL2FXCONST_DBL(0.0f);
|
|
|
|
INT sfbCnt = psyOutChan->sfbCnt;
|
|
|
|
INT bSuccess, bCheckScf;
|
2018-02-26 20:17:00 +01:00
|
|
|
INT i, k;
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
/* calc min and max scalfactors */
|
|
|
|
scfMin = FDK_INT_MAX;
|
|
|
|
scfMax = FDK_INT_MIN;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = 0; sfb < sfbCnt; sfb++) {
|
|
|
|
if (scf[sfb] != FDK_INT_MIN) {
|
2012-07-11 10:15:24 -07:00
|
|
|
scfMin = fixMin(scfMin, scf[sfb]);
|
|
|
|
scfMax = fixMax(scfMax, scf[sfb]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stopSfb = 0;
|
|
|
|
scfAct = FDK_INT_MIN;
|
|
|
|
do {
|
|
|
|
/* search for region with same scf values scfAct */
|
|
|
|
scfPrev = scfAct;
|
|
|
|
|
|
|
|
sfb = stopSfb;
|
2018-02-26 20:17:00 +01:00
|
|
|
while (sfb < sfbCnt && (scf[sfb] == FDK_INT_MIN)) sfb++;
|
2012-07-11 10:15:24 -07:00
|
|
|
startSfb = sfb;
|
|
|
|
scfAct = scf[startSfb];
|
|
|
|
sfb++;
|
2018-02-26 20:17:00 +01:00
|
|
|
while (sfb < sfbCnt &&
|
|
|
|
((scf[sfb] == FDK_INT_MIN) || (scf[sfb] == scf[startSfb])))
|
2012-07-11 10:15:24 -07:00
|
|
|
sfb++;
|
|
|
|
stopSfb = sfb;
|
|
|
|
|
|
|
|
if (stopSfb < sfbCnt)
|
|
|
|
scfNext = scf[stopSfb];
|
|
|
|
else
|
|
|
|
scfNext = scfAct;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
if (scfPrev == FDK_INT_MIN) scfPrev = scfAct;
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
scfPrevNextMax = fixMax(scfPrev, scfNext);
|
|
|
|
scfPrevNextMin = fixMin(scfPrev, scfNext);
|
|
|
|
|
|
|
|
/* try to reduce bits by checking scf values in the range
|
|
|
|
scf[startSfb]...scfHi */
|
|
|
|
scfHi = fixMax(scfPrevNextMax, scfAct);
|
|
|
|
/* try to find a better solution by reducing the scf difference to
|
|
|
|
the nearest possible lower scf */
|
|
|
|
if (scfPrevNextMax >= scfAct)
|
|
|
|
scfLo = fixMin(scfAct, scfPrevNextMin);
|
|
|
|
else
|
|
|
|
scfLo = scfPrevNextMax;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
if (startSfb < sfbCnt &&
|
|
|
|
scfHi - scfLo <= MAX_SCF_DELTA) { /* region found */
|
2012-07-11 10:15:24 -07:00
|
|
|
/* 1. try to save bits by coarser quantization */
|
|
|
|
if (scfHi > scf[startSfb]) {
|
|
|
|
/* calculate the allowed distortion */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
if (scf[sfb] != FDK_INT_MIN) {
|
2018-02-26 20:17:00 +01:00
|
|
|
/* 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));
|
|
|
|
*/
|
2012-07-11 10:15:24 -07:00
|
|
|
/* -0.15571537944 = ld64(1.e-3f)*/
|
2018-02-26 20:17:00 +01:00
|
|
|
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]);
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop over all possible scf values for this region */
|
|
|
|
bCheckScf = 1;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (scfNew = scf[startSfb] + 1; scfNew <= scfHi; scfNew++) {
|
|
|
|
for (k = 0; k < MAX_GROUPED_SFB; k++) scfTmp[k] = scf[k];
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
/* replace scfs in region by scfNew */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
|
|
|
if (scfTmp[sfb] != FDK_INT_MIN) scfTmp[sfb] = scfNew;
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* estimate change in bit demand for new scfs */
|
2018-02-26 20:17:00 +01:00
|
|
|
deltaScfBits = FDKaacEnc_countScfBitsDiff(scf, scfTmp, sfbCnt,
|
|
|
|
startSfb, stopSfb);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
deltaSpecPe = FDKaacEnc_calcSpecPeDiff(
|
|
|
|
psyOutChan, qcOutChannel, scf, scfTmp, sfbConstPePart,
|
|
|
|
sfbFormFactorLdData, sfbNRelevantLines, startSfb, stopSfb);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
deltaPeNew = deltaPe + (FIXP_DBL)deltaScfBits + deltaSpecPe;
|
|
|
|
|
|
|
|
/* new bit demand small enough ? */
|
|
|
|
if (deltaPeNew < FL2FXCONST_DBL(0.0f)) {
|
|
|
|
bSuccess = 1;
|
|
|
|
|
|
|
|
/* quantize and calc sum of new distortion */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
if (scfTmp[sfb] != FDK_INT_MIN) {
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(
|
|
|
|
qcOutChannel->mdctSpectrum + sfbOffs[sfb],
|
|
|
|
quantSpecTmp + sfbOffs[sfb],
|
|
|
|
sfbOffs[sfb + 1] - sfbOffs[sfb], scfNew, dZoneQuantEnable);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
if (sfbDistNew[sfb] > sfbDistMax[sfb]) {
|
|
|
|
/* no improvement, skip further dist. calculations */
|
|
|
|
bSuccess = 0;
|
|
|
|
if (sfbDistNew[sfb] == qcOutChannel->sfbEnergyLdData[sfb]) {
|
|
|
|
/* if whole sfb is already quantized to 0, further
|
|
|
|
checks with even coarser quant. are useless*/
|
|
|
|
bCheckScf = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-26 20:17:00 +01:00
|
|
|
if (bCheckScf == 0) /* further calculations useless ? */
|
|
|
|
break;
|
2012-07-11 10:15:24 -07:00
|
|
|
/* distortion small enough ? -> use new scalefactors */
|
|
|
|
if (bSuccess) {
|
|
|
|
deltaPe = deltaPeNew;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
if (scf[sfb] != FDK_INT_MIN) {
|
|
|
|
scf[sfb] = scfNew;
|
|
|
|
sfbDist[sfb] = sfbDistNew[sfb];
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
for (k = 0; k < sfbOffs[sfb + 1] - sfbOffs[sfb]; k++)
|
|
|
|
quantSpec[sfbOffs[sfb] + k] =
|
|
|
|
quantSpecTmp[sfbOffs[sfb] + k];
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 2. only if coarser quantization was not successful, try to find
|
|
|
|
a better solution by finer quantization and reducing bits for
|
|
|
|
scalefactor coding */
|
2018-02-26 20:17:00 +01:00
|
|
|
if (scfAct == scf[startSfb] && scfLo < scfAct &&
|
|
|
|
scfMax - scfMin <= MAX_SCF_DELTA) {
|
2012-07-11 10:15:24 -07:00
|
|
|
int bminScfViolation = 0;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
for (k = 0; k < MAX_GROUPED_SFB; k++) scfTmp[k] = scf[k];
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
scfNew = scfLo;
|
|
|
|
|
|
|
|
/* replace scfs in region by scfNew and
|
|
|
|
check if in all sfb scfNew >= minScf[sfb] */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
if (scfTmp[sfb] != FDK_INT_MIN) {
|
|
|
|
scfTmp[sfb] = scfNew;
|
2018-02-26 20:17:00 +01:00
|
|
|
if (scfNew < minScf[sfb]) bminScfViolation = 1;
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bminScfViolation) {
|
|
|
|
/* estimate change in bit demand for new scfs */
|
2018-02-26 20:17:00 +01:00
|
|
|
deltaScfBits = FDKaacEnc_countScfBitsDiff(scf, scfTmp, sfbCnt,
|
|
|
|
startSfb, stopSfb);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
deltaSpecPe = FDKaacEnc_calcSpecPeDiff(
|
|
|
|
psyOutChan, qcOutChannel, scf, scfTmp, sfbConstPePart,
|
|
|
|
sfbFormFactorLdData, sfbNRelevantLines, startSfb, stopSfb);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
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);
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
if (scfTmp[sfb] != FDK_INT_MIN) {
|
|
|
|
distOldSum += CalcInvLdData(sfbDist[sfb]) >> DIST_FAC_SHIFT;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(
|
|
|
|
qcOutChannel->mdctSpectrum + sfbOffs[sfb],
|
|
|
|
quantSpecTmp + sfbOffs[sfb], sfbOffs[sfb + 1] - sfbOffs[sfb],
|
|
|
|
scfNew, dZoneQuantEnable);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
if (sfbDistNew[sfb] > qcOutChannel->sfbThresholdLdData[sfb]) {
|
|
|
|
/* no improvement, skip further dist. calculations */
|
|
|
|
distNewSum = distOldSum << 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
distNewSum += CalcInvLdData(sfbDistNew[sfb]) >> DIST_FAC_SHIFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* distortion smaller ? -> use new scalefactors */
|
2018-02-26 20:17:00 +01:00
|
|
|
if (distNewSum < fMult(FL2FXCONST_DBL(0.8f), distOldSum)) {
|
2012-07-11 10:15:24 -07:00
|
|
|
deltaPe = deltaPeNew;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
if (scf[sfb] != FDK_INT_MIN) {
|
|
|
|
scf[sfb] = scfNew;
|
|
|
|
sfbDist[sfb] = sfbDistNew[sfb];
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
for (k = 0; k < sfbOffs[sfb + 1] - sfbOffs[sfb]; k++)
|
|
|
|
quantSpec[sfbOffs[sfb] + k] = quantSpecTmp[sfbOffs[sfb] + k];
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 3. try to find a better solution (save bits) by only reducing the
|
|
|
|
scalefactor without new quantization */
|
2018-02-26 20:17:00 +01:00
|
|
|
if (scfMax - scfMin <=
|
|
|
|
MAX_SCF_DELTA - 3) { /* 3 bec. scf is reduced 3 times,
|
|
|
|
see for loop below */
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
for (k = 0; k < sfbCnt; k++) scfTmp[k] = scf[k];
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
scfNew = scfTmp[startSfb] - 1;
|
2012-07-11 10:15:24 -07:00
|
|
|
/* replace scfs in region by scfNew */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
|
|
|
if (scfTmp[sfb] != FDK_INT_MIN) scfTmp[sfb] = scfNew;
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
/* estimate change in bit demand for new scfs */
|
2018-02-26 20:17:00 +01:00
|
|
|
deltaScfBits = FDKaacEnc_countScfBitsDiff(scf, scfTmp, sfbCnt,
|
|
|
|
startSfb, stopSfb);
|
2012-07-11 10:15:24 -07:00
|
|
|
deltaPeNew = deltaPe + (FIXP_DBL)deltaScfBits;
|
|
|
|
/* new bit demand small enough ? */
|
|
|
|
if (deltaPeNew <= FL2FXCONST_DBL(0.0f)) {
|
|
|
|
bSuccess = 1;
|
|
|
|
distOldSum = distNewSum = FL2FXCONST_DBL(0.0f);
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
if (scfTmp[sfb] != FDK_INT_MIN) {
|
|
|
|
FIXP_DBL sfbEnQ;
|
|
|
|
/* calc the energy and distortion of the quantized spectrum for
|
|
|
|
a smaller scf */
|
2018-02-26 20:17:00 +01:00
|
|
|
FDKaacEnc_calcSfbQuantEnergyAndDist(
|
|
|
|
qcOutChannel->mdctSpectrum + sfbOffs[sfb],
|
|
|
|
quantSpec + sfbOffs[sfb], sfbOffs[sfb + 1] - sfbOffs[sfb],
|
|
|
|
scfNew, &sfbEnQ, &sfbDistNew[sfb]);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
distOldSum += CalcInvLdData(sfbDist[sfb]) >> DIST_FAC_SHIFT;
|
|
|
|
distNewSum += CalcInvLdData(sfbDistNew[sfb]) >> DIST_FAC_SHIFT;
|
|
|
|
|
|
|
|
/* 0.00259488556167 = ld64(1.122f) */
|
|
|
|
/* -0.00778722686652 = ld64(0.7079f) */
|
2018-02-26 20:17:00 +01:00
|
|
|
if ((sfbDistNew[sfb] >
|
|
|
|
(sfbDist[sfb] + FL2FXCONST_DBL(0.00259488556167f))) ||
|
|
|
|
(sfbEnQ < (qcOutChannel->sfbEnergyLdData[sfb] -
|
|
|
|
FL2FXCONST_DBL(0.00778722686652f)))) {
|
2012-07-11 10:15:24 -07:00
|
|
|
bSuccess = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* distortion smaller ? -> use new scalefactors */
|
|
|
|
if (distNewSum < distOldSum && bSuccess) {
|
|
|
|
deltaPe = deltaPeNew;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfb = startSfb; sfb < stopSfb; sfb++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
if (scf[sfb] != FDK_INT_MIN) {
|
|
|
|
scf[sfb] = scfNew;
|
|
|
|
sfbDist[sfb] = sfbDistNew[sfb];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (stopSfb <= sfbCnt);
|
|
|
|
}
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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) {
|
2012-07-11 10:15:24 -07:00
|
|
|
INT i, j, sfb, sfbOffs;
|
|
|
|
INT scfInt;
|
|
|
|
INT maxSf;
|
|
|
|
INT minSf;
|
|
|
|
FIXP_DBL threshLdData;
|
|
|
|
FIXP_DBL energyLdData;
|
|
|
|
FIXP_DBL energyPartLdData;
|
|
|
|
FIXP_DBL thresholdPartLdData;
|
|
|
|
FIXP_DBL scfFract;
|
|
|
|
FIXP_DBL maxSpec;
|
|
|
|
INT minScfCalculated[MAX_GROUPED_SFB];
|
|
|
|
FIXP_DBL sfbDistLdData[MAX_GROUPED_SFB];
|
2018-02-26 20:17:00 +01:00
|
|
|
C_ALLOC_SCRATCH_START(quantSpecTmp, SHORT, (1024))
|
2012-07-11 10:15:24 -07:00
|
|
|
INT minSfMaxQuant[MAX_GROUPED_SFB];
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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 */
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
if (invQuant > 0) {
|
|
|
|
FDKmemclear(quantSpec, (1024) * sizeof(SHORT));
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* scfs without energy or with thresh>energy are marked with FDK_INT_MIN */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (i = 0; i < psyOutChannel->sfbCnt; i++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
scf[i] = FDK_INT_MIN;
|
|
|
|
}
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
for (i = 0; i < MAX_GROUPED_SFB; i++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
minSfMaxQuant[i] = FDK_INT_MIN;
|
|
|
|
}
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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];
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
sfbDistLdData[sfbOffs + sfb] = energyLdData;
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
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 */
|
2018-02-26 20:17:00 +01:00
|
|
|
energyPartLdData =
|
|
|
|
sfbFormFactorLdData[sfbOffs + sfb] + FL2FXCONST_DBL(0.09375f);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
/* influence of allowed distortion */
|
|
|
|
/* thresholdPart = (float)log10(6.75*thresh+FLT_MIN); */
|
|
|
|
thresholdPartLdData = threshConstLdData + threshLdData;
|
|
|
|
|
|
|
|
/* scf calc */
|
|
|
|
/* scfFloat = 8.8585f * (thresholdPart - energyPart); */
|
|
|
|
scfFract = thresholdPartLdData - energyPartLdData;
|
|
|
|
/* conversion from log2 to log10 */
|
2018-02-26 20:17:00 +01:00
|
|
|
scfFract = fMult(convConst, scfFract);
|
2012-07-11 10:15:24 -07:00
|
|
|
/* (8.8585f * scfFract)/8 = 8/8 * scfFract + 0.8585 * scfFract/8 */
|
2018-02-26 20:17:00 +01:00
|
|
|
scfFract = scfFract + fMult(FL2FXCONST_DBL(0.8585f), scfFract >> 3);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
/* integer scalefactor */
|
|
|
|
/* scfInt = (int)floor(scfFloat); */
|
2018-02-26 20:17:00 +01:00
|
|
|
scfInt =
|
|
|
|
(INT)(scfFract >>
|
|
|
|
((DFRACT_BITS - 1) - 3 -
|
|
|
|
LD_DATA_SHIFT)); /* 3 bits => scfFract/8.0; 6 bits => ld64 */
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
/* maximum of spectrum */
|
|
|
|
maxSpec = FL2FXCONST_DBL(0.0f);
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
/* 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]))));
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
/* 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)); */
|
2018-02-26 20:17:00 +01:00
|
|
|
/* 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 */
|
2012-07-11 10:15:24 -07:00
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
// minSfMaxQuant[sfbOffs+sfb] = ((INT) ((c1Const + CalcLdData(maxSpec))
|
|
|
|
// >> ((DFRACT_BITS-1)-8))) + 1;
|
2012-07-11 10:15:24 -07:00
|
|
|
tmp = CalcLdData(maxSpec);
|
2018-02-26 20:17:00 +01:00
|
|
|
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;
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
scfInt = fixMax(scfInt, minSfMaxQuant[sfbOffs + sfb]);
|
2012-07-11 10:15:24 -07:00
|
|
|
|
|
|
|
/* find better scalefactor with analysis by synthesis */
|
2018-02-26 20:17:00 +01:00
|
|
|
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);
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
2018-02-26 20:17:00 +01:00
|
|
|
scf[sfbOffs + sfb] = scfInt;
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
if (invQuant > 0) {
|
2012-07-11 10:15:24 -07:00
|
|
|
/* try to decrease scf differences */
|
|
|
|
FIXP_DBL sfbConstPePart[MAX_GROUPED_SFB];
|
|
|
|
FIXP_DBL sfbNRelevantLines[MAX_GROUPED_SFB];
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
for (i = 0; i < psyOutChannel->sfbCnt; i++)
|
2012-07-11 10:15:24 -07:00
|
|
|
sfbConstPePart[i] = (FIXP_DBL)FDK_INT_MIN;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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);
|
2016-04-08 10:52:42 -07:00
|
|
|
}
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get min scalefac */
|
|
|
|
minSf = FDK_INT_MAX;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfbOffs = 0; sfbOffs < psyOutChannel->sfbCnt;
|
|
|
|
sfbOffs += psyOutChannel->sfbPerGroup) {
|
2012-07-11 10:15:24 -07:00
|
|
|
for (sfb = 0; sfb < psyOutChannel->maxSfbPerGroup; sfb++) {
|
2018-02-26 20:17:00 +01:00
|
|
|
if (scf[sfbOffs + sfb] != FDK_INT_MIN)
|
|
|
|
minSf = fixMin(minSf, scf[sfbOffs + sfb]);
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* limit scf delta */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfbOffs = 0; sfbOffs < psyOutChannel->sfbCnt;
|
|
|
|
sfbOffs += psyOutChannel->sfbPerGroup) {
|
2012-07-11 10:15:24 -07:00
|
|
|
for (sfb = 0; sfb < psyOutChannel->maxSfbPerGroup; sfb++) {
|
2018-02-26 20:17:00 +01:00
|
|
|
if ((scf[sfbOffs + sfb] != FDK_INT_MIN) &&
|
|
|
|
(minSf + MAX_SCF_DELTA) < scf[sfbOffs + sfb]) {
|
|
|
|
scf[sfbOffs + sfb] = minSf + MAX_SCF_DELTA;
|
2012-07-11 10:15:24 -07:00
|
|
|
if (invQuant > 0) { /* changed bands need to be quantized again */
|
2018-02-26 20:17:00 +01:00
|
|
|
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);
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get max scalefac for global gain */
|
|
|
|
maxSf = FDK_INT_MIN;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfbOffs = 0; sfbOffs < psyOutChannel->sfbCnt;
|
|
|
|
sfbOffs += psyOutChannel->sfbPerGroup) {
|
2012-07-11 10:15:24 -07:00
|
|
|
for (sfb = 0; sfb < psyOutChannel->maxSfbPerGroup; sfb++) {
|
2018-02-26 20:17:00 +01:00
|
|
|
maxSf = fixMax(maxSf, scf[sfbOffs + sfb]);
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calc loop scalefactors, if spec is not all zero (i.e. maxSf == -99) */
|
2018-02-26 20:17:00 +01:00
|
|
|
if (maxSf > FDK_INT_MIN) {
|
2012-07-11 10:15:24 -07:00
|
|
|
*globalGain = maxSf;
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfbOffs = 0; sfbOffs < psyOutChannel->sfbCnt;
|
|
|
|
sfbOffs += psyOutChannel->sfbPerGroup) {
|
2012-07-11 10:15:24 -07:00
|
|
|
for (sfb = 0; sfb < psyOutChannel->maxSfbPerGroup; sfb++) {
|
2018-02-26 20:17:00 +01:00
|
|
|
if (scf[sfbOffs + sfb] == FDK_INT_MIN) {
|
|
|
|
scf[sfbOffs + sfb] = 0;
|
2012-07-11 10:15:24 -07:00
|
|
|
/* set band explicitely to zero */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (j = psyOutChannel->sfbOffsets[sfbOffs + sfb];
|
|
|
|
j < psyOutChannel->sfbOffsets[sfbOffs + sfb + 1]; j++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
qcOutChannel->mdctSpectrum[j] = FL2FXCONST_DBL(0.0f);
|
|
|
|
}
|
2018-02-26 20:17:00 +01:00
|
|
|
} else {
|
|
|
|
scf[sfbOffs + sfb] = maxSf - scf[sfbOffs + sfb];
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-26 20:17:00 +01:00
|
|
|
} else {
|
2012-07-11 10:15:24 -07:00
|
|
|
*globalGain = 0;
|
|
|
|
/* set spectrum explicitely to zero */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (sfbOffs = 0; sfbOffs < psyOutChannel->sfbCnt;
|
|
|
|
sfbOffs += psyOutChannel->sfbPerGroup) {
|
2012-07-11 10:15:24 -07:00
|
|
|
for (sfb = 0; sfb < psyOutChannel->maxSfbPerGroup; sfb++) {
|
2018-02-26 20:17:00 +01:00
|
|
|
scf[sfbOffs + sfb] = 0;
|
2012-07-11 10:15:24 -07:00
|
|
|
/* set band explicitely to zero */
|
2018-02-26 20:17:00 +01:00
|
|
|
for (j = psyOutChannel->sfbOffsets[sfbOffs + sfb];
|
|
|
|
j < psyOutChannel->sfbOffsets[sfbOffs + sfb + 1]; j++) {
|
2012-07-11 10:15:24 -07:00
|
|
|
qcOutChannel->mdctSpectrum[j] = FL2FXCONST_DBL(0.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free quantSpecTmp from scratch */
|
2018-02-26 20:17:00 +01:00
|
|
|
C_ALLOC_SCRATCH_END(quantSpecTmp, SHORT, (1024))
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
void FDKaacEnc_EstimateScaleFactors(PSY_OUT_CHANNEL *psyOutChannel[],
|
|
|
|
QC_OUT_CHANNEL *qcOutChannel[],
|
|
|
|
const INT invQuant,
|
|
|
|
const INT dZoneQuantEnable,
|
|
|
|
const INT nChannels) {
|
2012-07-11 10:15:24 -07:00
|
|
|
int ch;
|
|
|
|
|
2018-02-26 20:17:00 +01:00
|
|
|
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);
|
2012-07-11 10:15:24 -07:00
|
|
|
}
|
|
|
|
}
|