From 8264e376ea6f2fdaa3813ff1a8463e368d95083c Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Fri, 10 Nov 2023 11:39:50 +0200 Subject: Saturate additions in getEnvSfbEnergy in SBR encoding This avoids wraparounds, which can trigger failed asserts with some inputs. This fixes https://github.com/mstorsjo/fdk-aac/issues/158. The implementation of saturated addition loses the contents of the lowest bit though, thus this change affects the output - but the change is said to be acceptable. --- libSBRenc/src/env_est.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libSBRenc/src/env_est.cpp') diff --git a/libSBRenc/src/env_est.cpp b/libSBRenc/src/env_est.cpp index cc8780a..e7eea37 100644 --- a/libSBRenc/src/env_est.cpp +++ b/libSBRenc/src/env_est.cpp @@ -637,8 +637,8 @@ static FIXP_DBL getEnvSfbEnergy( for (; l < stop_pos; l++) { nrg2 += YBuffer[l >> YBufferSzShift][k] >> sc1; } - accu1 += (nrg1 >> dynScale1); - accu2 += (nrg2 >> dynScale2); + accu1 = fAddSaturate(accu1, (nrg1 >> dynScale1)); + accu2 = fAddSaturate(accu2, (nrg2 >> dynScale2)); } /* This shift factor is always positive. See comment above. */ nrgSum += -- cgit v1.2.3