diff options
author | Martin Storsjo <martin@martin.st> | 2023-11-10 11:39:50 +0200 |
---|---|---|
committer | Martin Storsjo <martin@martin.st> | 2023-11-10 11:43:44 +0200 |
commit | 8264e376ea6f2fdaa3813ff1a8463e368d95083c (patch) | |
tree | cf09b6c7788de0e2f859f23919056fbe4a813efa | |
parent | 4de681c193d45b14f87efc30e3e3f02d389387b5 (diff) | |
download | fdk-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.
-rw-r--r-- | libSBRenc/src/env_est.cpp | 4 | ||||
-rw-r--r-- | test/ref-mono.txt | 4 | ||||
-rw-r--r-- | test/ref-stereo.txt | 4 |
3 files changed, 6 insertions, 6 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 += diff --git a/test/ref-mono.txt b/test/ref-mono.txt index 22a84f2..39fa6df 100644 --- a/test/ref-mono.txt +++ b/test/ref-mono.txt @@ -1,2 +1,2 @@ -encode hash: 516e51016cbba6068f1aa285a8fdd55b00ada6b0 -decode hash: 3b3b3a17cc5ba50ade75b3ef1a37f96017935fe5 +encode hash: 7f00e85a1eda67964e1b4044a5659a62e3952af2 +decode hash: af682b197a94e32fce09643857fa77b364574571 diff --git a/test/ref-stereo.txt b/test/ref-stereo.txt index 3de5276..a765c93 100644 --- a/test/ref-stereo.txt +++ b/test/ref-stereo.txt @@ -1,2 +1,2 @@ -encode hash: 1179940ca3a5c62de45b6823efbdbe42fce11de2 -decode hash: 85f2a154b46cc6cfa2792ff95c67b4200ce4463b +encode hash: 8411e71bf6b32576d287764cfa577ea0e9b73280 +decode hash: 30ad42bc97b53c03139cca5437b7d9a861de0e92 |