diff options
Diffstat (limited to 'fdk-aac/libSBRdec/src/env_calc.cpp')
-rw-r--r-- | fdk-aac/libSBRdec/src/env_calc.cpp | 76 |
1 files changed, 35 insertions, 41 deletions
diff --git a/fdk-aac/libSBRdec/src/env_calc.cpp b/fdk-aac/libSBRdec/src/env_calc.cpp index cb1474f..1242833 100644 --- a/fdk-aac/libSBRdec/src/env_calc.cpp +++ b/fdk-aac/libSBRdec/src/env_calc.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 @@ -493,7 +493,7 @@ static void mapSineFlags( } } -#define INTER_TES_SF_CHANGE 3 +#define INTER_TES_SF_CHANGE 4 typedef struct { FIXP_DBL subsample_power_low[(((1024) / (32) * (4) / 2) + (3 * (4)))]; @@ -2325,7 +2325,15 @@ static void calcSubbandGain( } /* gain = nrgRef / B */ - FDK_divide_MantExp(nrgRef, nrgRef_e, b, b_e, ptrNrgGain, ptrNrgGain_e); + INT result_exp = 0; + *ptrNrgGain = fDivNorm(nrgRef, b, &result_exp); + *ptrNrgGain_e = (SCHAR)result_exp + (nrgRef_e - b_e); + + /* There could be a one bit diffs. This is important to compensate, + because later in the code values are compared by exponent only. */ + int headroom = CountLeadingBits(*ptrNrgGain); + *ptrNrgGain <<= headroom; + *ptrNrgGain_e -= headroom; } } @@ -2431,8 +2439,7 @@ static void adjustTimeSlot_EldGrid( sbNoise = *pNoiseLevel++; if (((INT)sineLevel_curr | noNoiseFlag) == 0) { signalReal += - (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[phaseIndex][0], sbNoise) - << 4); + fMult(FDK_sbrDecoder_sbr_randomPhase[phaseIndex][0], sbNoise); } signalReal += sineLevel_curr * p_harmonicPhase[0]; signalReal = @@ -2466,8 +2473,7 @@ static void adjustTimeSlot_EldGrid( sbNoise = *pNoiseLevel++; if (((INT)sineLevel_curr | noNoiseFlag) == 0) { signalReal += - (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[phaseIndex][0], sbNoise) - << 4); + fMult(FDK_sbrDecoder_sbr_randomPhase[phaseIndex][0], sbNoise); } signalReal += sineLevel_curr * p_harmonicPhase[0]; *ptrReal++ = signalReal; @@ -2527,8 +2533,7 @@ static void adjustTimeSlotLC( else if (!noNoiseFlag) /* Add noisefloor to the amplified signal */ signalReal += - (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], pNoiseLevel[0]) - << 4); + fMult(FDK_sbrDecoder_sbr_randomPhase[index][0], pNoiseLevel[0]); { if (!(harmIndex & 0x1)) { @@ -2575,9 +2580,8 @@ static void adjustTimeSlotLC( !noNoiseFlag) { /* Add noisefloor to the amplified signal */ index &= (SBR_NF_NO_RANDOM_VAL - 1); - signalReal += (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], - pNoiseLevel[0]) - << 4); + signalReal += + fMult(FDK_sbrDecoder_sbr_randomPhase[index][0], pNoiseLevel[0]); } /* The next multiplication constitutes the actual envelope adjustment of @@ -2602,9 +2606,8 @@ static void adjustTimeSlotLC( else if (!noNoiseFlag) { /* Add noisefloor to the amplified signal */ index &= (SBR_NF_NO_RANDOM_VAL - 1); - signalReal += (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], - pNoiseLevel[0]) - << 4); + signalReal += + fMult(FDK_sbrDecoder_sbr_randomPhase[index][0], pNoiseLevel[0]); } pNoiseLevel++; @@ -2633,10 +2636,8 @@ static void adjustTimeSlotLC( else if (!noNoiseFlag) { /* Add noisefloor to the amplified signal */ index &= (SBR_NF_NO_RANDOM_VAL - 1); - signalReal = - signalReal + - (fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], pNoiseLevel[0]) - << 4); + signalReal = signalReal + fMult(FDK_sbrDecoder_sbr_randomPhase[index][0], + pNoiseLevel[0]); } if (!(harmIndex & 0x1)) { @@ -2741,11 +2742,9 @@ static void adjustTimeSlotHQ_GainAndNoise( /* Add noisefloor to the amplified signal */ index &= (SBR_NF_NO_RANDOM_VAL - 1); noiseReal = - fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], smoothedNoise) - << 4; + fMult(FDK_sbrDecoder_sbr_randomPhase[index][0], smoothedNoise); noiseImag = - fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][1], smoothedNoise) - << 4; + fMult(FDK_sbrDecoder_sbr_randomPhase[index][1], smoothedNoise); *ptrReal++ = (signalReal + noiseReal); *ptrImag++ = (signalImag + noiseImag); } @@ -2763,13 +2762,12 @@ static void adjustTimeSlotHQ_GainAndNoise( smoothedNoise = noiseLevel[k]; index &= (SBR_NF_NO_RANDOM_VAL - 1); noiseReal = - fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], smoothedNoise); + fMult(FDK_sbrDecoder_sbr_randomPhase[index][0], smoothedNoise); noiseImag = - fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][1], smoothedNoise); + fMult(FDK_sbrDecoder_sbr_randomPhase[index][1], smoothedNoise); - /* FDK_sbrDecoder_sbr_randomPhase is downscaled by 2^3 */ - signalReal += noiseReal << 4; - signalImag += noiseImag << 4; + signalReal += noiseReal; + signalImag += noiseImag; } *ptrReal++ = signalReal; *ptrImag++ = signalImag; @@ -2944,13 +2942,10 @@ static void adjustTimeSlotHQ( } else { /* Add noisefloor to the amplified signal */ index &= (SBR_NF_NO_RANDOM_VAL - 1); - /* FDK_sbrDecoder_sbr_randomPhase is downscaled by 2^3 */ noiseReal = - fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], smoothedNoise) - << 4; + fMult(FDK_sbrDecoder_sbr_randomPhase[index][0], smoothedNoise); noiseImag = - fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][1], smoothedNoise) - << 4; + fMult(FDK_sbrDecoder_sbr_randomPhase[index][1], smoothedNoise); *ptrReal++ = (signalReal + noiseReal); *ptrImag++ = (signalImag + noiseImag); } @@ -2992,14 +2987,13 @@ static void adjustTimeSlotHQ( /* Add noisefloor to the amplified signal */ smoothedNoise = noiseLevel[k]; index &= (SBR_NF_NO_RANDOM_VAL - 1); - noiseReal = fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][0], - smoothedNoise); - noiseImag = fMultDiv2(FDK_sbrDecoder_sbr_randomPhase[index][1], - smoothedNoise); - - /* FDK_sbrDecoder_sbr_randomPhase is downscaled by 2^3 */ - signalReal += noiseReal << 4; - signalImag += noiseImag << 4; + noiseReal = + fMult(FDK_sbrDecoder_sbr_randomPhase[index][0], smoothedNoise); + noiseImag = + fMult(FDK_sbrDecoder_sbr_randomPhase[index][1], smoothedNoise); + + signalReal += noiseReal; + signalImag += noiseImag; } } *ptrReal++ = signalReal; |