aboutsummaryrefslogtreecommitdiffstats
path: root/libSBRenc/src
diff options
context:
space:
mode:
authorMartin Storsjo <martin@martin.st>2023-11-10 11:39:50 +0200
committerMartin Storsjo <martin@martin.st>2023-11-10 11:43:44 +0200
commit8264e376ea6f2fdaa3813ff1a8463e368d95083c (patch)
treecf09b6c7788de0e2f859f23919056fbe4a813efa /libSBRenc/src
parent4de681c193d45b14f87efc30e3e3f02d389387b5 (diff)
downloadfdk-aac-8264e376ea6f2fdaa3813ff1a8463e368d95083c.tar.gz
fdk-aac-8264e376ea6f2fdaa3813ff1a8463e368d95083c.tar.bz2
fdk-aac-8264e376ea6f2fdaa3813ff1a8463e368d95083c.zip
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.
Diffstat (limited to 'libSBRenc/src')
-rw-r--r--libSBRenc/src/env_est.cpp4
1 files changed, 2 insertions, 2 deletions
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 +=