From e0835d4cbde8e3b61b0c965afcd41f8f4b7ac121 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 1 Jun 2021 14:42:00 +0200 Subject: Update fdk to v2.0.2 --- fdk-aac/libSACdec/src/sac_reshapeBBEnv.cpp | 215 ++++++++++++----------------- 1 file changed, 91 insertions(+), 124 deletions(-) (limited to 'fdk-aac/libSACdec/src/sac_reshapeBBEnv.cpp') diff --git a/fdk-aac/libSACdec/src/sac_reshapeBBEnv.cpp b/fdk-aac/libSACdec/src/sac_reshapeBBEnv.cpp index 87c0ac6..272d009 100644 --- a/fdk-aac/libSACdec/src/sac_reshapeBBEnv.cpp +++ b/fdk-aac/libSACdec/src/sac_reshapeBBEnv.cpp @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -162,75 +162,59 @@ static inline void getSlotNrgHQ(FIXP_DBL *RESTRICT pReal, FIXP_DBL nrg; /* qs = 12, 13, 14 */ - slotNrg[0] = ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); - slotNrg[1] = ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); - slotNrg[2] = ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); + slotNrg[0] = ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); + slotNrg[1] = ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); + slotNrg[2] = ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); /* qs = 15 */ - slotNrg[3] = ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); + slotNrg[3] = ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); /* qs = 16, 17 */ - nrg = ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); - slotNrg[4] = nrg + ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); + nrg = ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); + slotNrg[4] = + nrg + ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); /* qs = 18, 19, 20 */ - nrg = ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); - nrg += ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); - slotNrg[5] = nrg + ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); + nrg = ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); + nrg += ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); + slotNrg[5] = + nrg + ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); /* qs = 21, 22 */ - nrg = ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); - slotNrg[6] = nrg + ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); + nrg = ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); + slotNrg[6] = + nrg + ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); /* qs = 23, 24 */ if (hybBands > 23) { - slotNrg[6] += ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); - slotNrg[6] += ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); + slotNrg[6] += ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); + slotNrg[6] += ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); /* qs = 25, 26, 29, 28, 29 */ - nrg = ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); - nrg += ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); - nrg += ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); - nrg += ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); - slotNrg[7] = nrg + ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); + nrg = ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); + nrg += ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); + nrg += ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); + nrg += ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); + slotNrg[7] = + nrg + ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); /* qs = 30 ... min(41,hybBands-1) */ - nrg = ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); + nrg = ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); for (qs = 31; qs < hybBands; qs++) { - nrg += ((fPow2Div2((*pReal++) << maxValSF) + - fPow2Div2((*pImag++) << maxValSF)) >> - (SF_FACTOR_SLOT - 1)); + nrg += ((fPow2Div2((*pReal++) << maxValSF) >> (SF_FACTOR_SLOT - 1)) + + (fPow2Div2((*pImag++) << maxValSF) >> (SF_FACTOR_SLOT - 1))); } slotNrg[8] = nrg; } else { @@ -239,49 +223,22 @@ static inline void getSlotNrgHQ(FIXP_DBL *RESTRICT pReal, } } -static inline INT getMaxValDmx(FIXP_DBL *RESTRICT pReal, - FIXP_DBL *RESTRICT pImag, INT cplxBands, - INT hybBands) { - INT qs, clz; - FIXP_DBL maxVal = FL2FXCONST_DBL(0.0f); - - for (qs = 12; qs < cplxBands; qs++) { - maxVal |= fAbs(pReal[qs]); - maxVal |= fAbs(pImag[qs]); - } - for (; qs < hybBands; qs++) { - maxVal |= fAbs(pReal[qs]); - } - - clz = fixMax(0, CntLeadingZeros(maxVal) - 1); - - return (clz); -} - -static inline INT getMaxValDryWet(FIXP_DBL *RESTRICT pReal, - FIXP_DBL *RESTRICT pImag, - FIXP_DBL *RESTRICT pHybOutputRealDry, - FIXP_DBL *RESTRICT pHybOutputImagDry, - FIXP_DBL *RESTRICT pHybOutputRealWet, - FIXP_DBL *RESTRICT pHybOutputImagWet, - INT cplxBands, INT hybBands) { - INT qs, clz; - FIXP_DBL maxVal = FL2FXCONST_DBL(0.0f); +static inline void combineDryWet(FIXP_DBL *RESTRICT pReal, + FIXP_DBL *RESTRICT pImag, + FIXP_DBL *RESTRICT pHybOutputRealDry, + FIXP_DBL *RESTRICT pHybOutputImagDry, + FIXP_DBL *RESTRICT pHybOutputRealWet, + FIXP_DBL *RESTRICT pHybOutputImagWet, + INT cplxBands, INT hybBands) { + INT qs; for (qs = 12; qs < cplxBands; qs++) { - pReal[qs] = pHybOutputRealDry[qs] + pHybOutputRealWet[qs]; - maxVal |= fAbs(pReal[qs]); - pImag[qs] = pHybOutputImagDry[qs] + pHybOutputImagWet[qs]; - maxVal |= fAbs(pImag[qs]); + pReal[qs] = (pHybOutputRealDry[qs] >> 1) + (pHybOutputRealWet[qs] >> 1); + pImag[qs] = (pHybOutputImagDry[qs] >> 1) + (pHybOutputImagWet[qs] >> 1); } for (; qs < hybBands; qs++) { - pReal[qs] = pHybOutputRealDry[qs] + pHybOutputRealWet[qs]; - maxVal |= fAbs(pReal[qs]); + pReal[qs] = (pHybOutputRealDry[qs] >> 1) + (pHybOutputRealWet[qs] >> 1); } - - clz = fixMax(0, CntLeadingZeros(maxVal) - 1); - - return (clz); } static inline void slotAmp(FIXP_DBL *RESTRICT slotAmp_dry, @@ -296,17 +253,17 @@ static inline void slotAmp(FIXP_DBL *RESTRICT slotAmp_dry, dry = wet = FL2FXCONST_DBL(0.0f); for (qs = 0; qs < cplxBands; qs++) { - dry = fAddSaturate(dry, fPow2Div2(pHybOutputRealDry[qs]) + - fPow2Div2(pHybOutputImagDry[qs])); - wet = fAddSaturate(wet, fPow2Div2(pHybOutputRealWet[qs]) + - fPow2Div2(pHybOutputImagWet[qs])); + dry = fAddSaturate(dry, fPow2Div2(pHybOutputRealDry[qs] << (1)) + + fPow2Div2(pHybOutputImagDry[qs] << (1))); + wet = fAddSaturate(wet, fPow2Div2(pHybOutputRealWet[qs] << (1)) + + fPow2Div2(pHybOutputImagWet[qs] << (1))); } for (; qs < hybBands; qs++) { - dry = fAddSaturate(dry, fPow2Div2(pHybOutputRealDry[qs])); - wet = fAddSaturate(wet, fPow2Div2(pHybOutputRealWet[qs])); + dry = fAddSaturate(dry, fPow2Div2(pHybOutputRealDry[qs] << (1))); + wet = fAddSaturate(wet, fPow2Div2(pHybOutputRealWet[qs] << (1))); } - *slotAmp_dry = dry; - *slotAmp_wet = wet; + *slotAmp_dry = dry >> (2 * (1)); + *slotAmp_wet = wet >> (2 * (1)); } #if defined(__aarch64__) @@ -327,11 +284,14 @@ shapeBBEnv(FIXP_DBL *pHybOutputRealDry, FIXP_DBL *pHybOutputImagDry, } } else { for (qs = 0; qs < cplxBands; qs++) { - pHybOutputRealDry[qs] = fMultDiv2(pHybOutputRealDry[qs], dryFac) << scale; - pHybOutputImagDry[qs] = fMultDiv2(pHybOutputImagDry[qs], dryFac) << scale; + pHybOutputRealDry[qs] = SATURATE_LEFT_SHIFT( + fMultDiv2(pHybOutputRealDry[qs], dryFac), scale, DFRACT_BITS); + pHybOutputImagDry[qs] = SATURATE_LEFT_SHIFT( + fMultDiv2(pHybOutputImagDry[qs], dryFac), scale, DFRACT_BITS); } for (; qs < hybBands; qs++) { - pHybOutputRealDry[qs] = fMultDiv2(pHybOutputRealDry[qs], dryFac) << scale; + pHybOutputRealDry[qs] = SATURATE_LEFT_SHIFT( + fMultDiv2(pHybOutputRealDry[qs], dryFac), scale, DFRACT_BITS); } } } @@ -367,7 +327,7 @@ static void extractBBEnv(spatialDec *self, INT inp, INT start, INT channels, INT shapeActiv = 1; INT hybBands = fixMin(42, self->hybridBands); - INT staticScale = self->staticDecScale; + INT staticScale = self->staticDecScale + (1); INT cplxBands; cplxBands = fixMin(42, self->hybridBands); @@ -386,15 +346,18 @@ static void extractBBEnv(spatialDec *self, INT inp, INT start, INT channels, prevChOffs = ch; pReal = pScratchBuffer; pImag = pScratchBuffer + 42; - clz = getMaxValDryWet( - pReal, pImag, self->hybOutputRealDry__FDK[ch], - self->hybOutputImagDry__FDK[ch], self->hybOutputRealWet__FDK[ch], - self->hybOutputImagWet__FDK[ch], cplxBands, hybBands); + combineDryWet(pReal, pImag, self->hybOutputRealDry__FDK[ch], + self->hybOutputImagDry__FDK[ch], + self->hybOutputRealWet__FDK[ch], + self->hybOutputImagWet__FDK[ch], cplxBands, hybBands); + clz = fMin(getScalefactor(&pReal[12], fMax(0, hybBands - 12)), + getScalefactor(&pImag[12], fMax(0, cplxBands - 12))); } else { prevChOffs = ch + self->numOutputChannels; pReal = self->hybInputReal__FDK[ch]; pImag = self->hybInputImag__FDK[ch]; - clz = getMaxValDmx(pReal, pImag, cplxBands, hybBands); + clz = fMin(getScalefactor(&pReal[12], fMax(0, hybBands - 12)), + getScalefactor(&pImag[12], fMax(0, cplxBands - 12))); } partNrg = partNrgPrev = pBBEnvState->partNrgPrev__FDK[prevChOffs]; @@ -411,8 +374,10 @@ static void extractBBEnv(spatialDec *self, INT inp, INT start, INT channels, SF_FACTOR_SLOT */ } - slotNrgSF = 2 * (staticScale - clz) + SF_FACTOR_SLOT; - frameNrgSF = 2 * (staticScale - clz) + SF_FACTOR_SLOT; + slotNrgSF = 2 * (staticScale - clz + ((inp == INP_DRY_WET) ? 1 : 0)) + + SF_FACTOR_SLOT; + frameNrgSF = 2 * (staticScale - clz + ((inp == INP_DRY_WET) ? 1 : 0)) + + SF_FACTOR_SLOT; partNrgSF = fixMax(slotNrgSF - SF_ALPHA1 + 1, pPartNrgPrevSF[0] - pPartNrgPrev2SF[0] + 1); @@ -652,14 +617,16 @@ void SpatialDecReshapeBBEnv(spatialDec *self, const SPATIAL_BS_FRAME *frame, fixMax(3, fixMax(dryFacSF, slotAmpSF)); /* scale is at least with 3 bits to avoid overflows when calculating dryFac */ - dryFac = dryFac >> (scale - dryFacSF); - slotAmp_ratio = slotAmp_ratio >> (scale - slotAmpSF); + dryFac = dryFac >> fixMin(scale - dryFacSF, DFRACT_BITS - 1); + slotAmp_ratio = + slotAmp_ratio >> fixMin(scale - slotAmpSF, DFRACT_BITS - 1); /* limit dryFac */ dryFac = fixMax( FL2FXCONST_DBL(0.25f) >> (INT)fixMin(2 * scale, DFRACT_BITS - 1), - fMult(dryFac, slotAmp_ratio) - (slotAmp_ratio >> scale) + - (dryFac >> scale)); + fMult(dryFac, slotAmp_ratio) - + (slotAmp_ratio >> fixMin(scale, DFRACT_BITS - 1)) + + (dryFac >> fixMin(scale, DFRACT_BITS - 1))); dryFac = fixMin( FL2FXCONST_DBL(0.50f) >> (INT)fixMin(2 * scale - 3, DFRACT_BITS - 1), dryFac); /* reduce shift bits by 3, because upper @@ -673,8 +640,8 @@ void SpatialDecReshapeBBEnv(spatialDec *self, const SPATIAL_BS_FRAME *frame, /* shaping */ shapeBBEnv(&self->hybOutputRealDry__FDK[ch][6], - &self->hybOutputImagDry__FDK[ch][6], dryFac, scale, cplxBands, - hybBands); + &self->hybOutputImagDry__FDK[ch][6], dryFac, + fixMin(scale, DFRACT_BITS - 1), cplxBands, hybBands); } } } -- cgit v1.2.3