diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2021-04-30 22:53:38 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-04-30 22:53:38 +0000 |
commit | 23308594fbf53792c2d4efb5b9f4d6f8a9b1f33a (patch) | |
tree | 24e23566011750fd437ebc8de9b0c58a8ee553d0 | |
parent | 99cd9ab658d11dd242e630758907832f70b4482b (diff) | |
parent | a37553e3278ec9ff9785d0b1bc5affca77a510d7 (diff) | |
download | fdk-aac-23308594fbf53792c2d4efb5b9f4d6f8a9b1f33a.tar.gz fdk-aac-23308594fbf53792c2d4efb5b9f4d6f8a9b1f33a.tar.bz2 fdk-aac-23308594fbf53792c2d4efb5b9f4d6f8a9b1f33a.zip |
Merge "Use dynamic scaling depending on autocorr length to avoid signed integer overflow." into sc-dev am: a37553e327
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/aac/+/14355879
Change-Id: I3c35d6347cafc9ace7bbcefd9d15213f257c5cae
-rw-r--r-- | libFDK/src/autocorr2nd.cpp | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/libFDK/src/autocorr2nd.cpp b/libFDK/src/autocorr2nd.cpp index 718a555..8c5673c 100644 --- a/libFDK/src/autocorr2nd.cpp +++ b/libFDK/src/autocorr2nd.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 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -102,11 +102,6 @@ amm-info@iis.fraunhofer.de #include "autocorr2nd.h" -/* If the accumulator does not provide enough overflow bits, - products have to be shifted down in the autocorrelation below. */ -#define SHIFT_FACTOR (5) -#define SHIFT >> (SHIFT_FACTOR) - /*! * * \brief Calculate second order autocorrelation using 2 accumulators @@ -126,45 +121,49 @@ INT autoCorr2nd_real( const FIXP_DBL *realBuf = reBuffer; + const int len_scale = fMax(DFRACT_BITS - fNormz((FIXP_DBL)(len / 2)), 1); /* r11r,r22r r01r,r12r r02r */ pReBuf = realBuf - 2; - accu5 = ((fMultDiv2(pReBuf[0], pReBuf[2]) + fMultDiv2(pReBuf[1], pReBuf[3])) - SHIFT); + accu5 = + ((fMultDiv2(pReBuf[0], pReBuf[2]) + fMultDiv2(pReBuf[1], pReBuf[3])) >> + len_scale); pReBuf++; /* len must be even */ - accu1 = fPow2Div2(pReBuf[0]) SHIFT; - accu3 = fMultDiv2(pReBuf[0], pReBuf[1]) SHIFT; + accu1 = fPow2Div2(pReBuf[0]) >> len_scale; + accu3 = fMultDiv2(pReBuf[0], pReBuf[1]) >> len_scale; pReBuf++; for (j = (len - 2) >> 1; j != 0; j--, pReBuf += 2) { - accu1 += ((fPow2Div2(pReBuf[0]) + fPow2Div2(pReBuf[1])) SHIFT); + accu1 += ((fPow2Div2(pReBuf[0]) + fPow2Div2(pReBuf[1])) >> len_scale); - accu3 += ((fMultDiv2(pReBuf[0], pReBuf[1]) + - fMultDiv2(pReBuf[1], pReBuf[2])) SHIFT); + accu3 += + ((fMultDiv2(pReBuf[0], pReBuf[1]) + fMultDiv2(pReBuf[1], pReBuf[2])) >> + len_scale); - accu5 += ((fMultDiv2(pReBuf[0], pReBuf[2]) + - fMultDiv2(pReBuf[1], pReBuf[3])) SHIFT); + accu5 += + ((fMultDiv2(pReBuf[0], pReBuf[2]) + fMultDiv2(pReBuf[1], pReBuf[3])) >> + len_scale); } - accu2 = (fPow2Div2(realBuf[-2]) SHIFT); + accu2 = (fPow2Div2(realBuf[-2]) >> len_scale); accu2 += accu1; - accu1 += (fPow2Div2(realBuf[len - 2]) SHIFT); + accu1 += (fPow2Div2(realBuf[len - 2]) >> len_scale); - accu4 = (fMultDiv2(realBuf[-1], realBuf[-2]) SHIFT); + accu4 = (fMultDiv2(realBuf[-1], realBuf[-2]) >> len_scale); accu4 += accu3; - accu3 += (fMultDiv2(realBuf[len - 1], realBuf[len - 2]) SHIFT); + accu3 += (fMultDiv2(realBuf[len - 1], realBuf[len - 2]) >> len_scale); mScale = CntLeadingZeros( (accu1 | accu2 | fAbs(accu3) | fAbs(accu4) | fAbs(accu5))) - 1; - autoCorrScaling = mScale - 1 - SHIFT_FACTOR; /* -1 because of fMultDiv2*/ + autoCorrScaling = mScale - 1 - len_scale; /* -1 because of fMultDiv2*/ /* Scale to common scale factor */ ac->r11r = accu1 << mScale; @@ -190,7 +189,7 @@ INT autoCorr2nd_cplx( const FIXP_DBL *imBuffer, /*!< Pointer to imag part of input samples */ const int len /*!< Number of input samples (should be smaller than 128) */ ) { - int j, autoCorrScaling, mScale, len_scale; + int j, autoCorrScaling, mScale; FIXP_DBL accu0, accu1, accu2, accu3, accu4, accu5, accu6, accu7, accu8; @@ -199,7 +198,7 @@ INT autoCorr2nd_cplx( const FIXP_DBL *realBuf = reBuffer; const FIXP_DBL *imagBuf = imBuffer; - (len > 64) ? (len_scale = 6) : (len_scale = 5); + const int len_scale = fMax(DFRACT_BITS - fNormz((FIXP_DBL)len), 1); /* r00r, r11r,r22r |