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.
This commit is contained in:
Martin Storsjo 2023-11-10 11:39:50 +02:00
parent 4de681c193
commit 8264e376ea
3 changed files with 6 additions and 6 deletions

View File

@ -637,8 +637,8 @@ static FIXP_DBL getEnvSfbEnergy(
for (; l < stop_pos; l++) { for (; l < stop_pos; l++) {
nrg2 += YBuffer[l >> YBufferSzShift][k] >> sc1; nrg2 += YBuffer[l >> YBufferSzShift][k] >> sc1;
} }
accu1 += (nrg1 >> dynScale1); accu1 = fAddSaturate(accu1, (nrg1 >> dynScale1));
accu2 += (nrg2 >> dynScale2); accu2 = fAddSaturate(accu2, (nrg2 >> dynScale2));
} }
/* This shift factor is always positive. See comment above. */ /* This shift factor is always positive. See comment above. */
nrgSum += nrgSum +=

View File

@ -1,2 +1,2 @@
encode hash: 516e51016cbba6068f1aa285a8fdd55b00ada6b0 encode hash: 7f00e85a1eda67964e1b4044a5659a62e3952af2
decode hash: 3b3b3a17cc5ba50ade75b3ef1a37f96017935fe5 decode hash: af682b197a94e32fce09643857fa77b364574571

View File

@ -1,2 +1,2 @@
encode hash: 1179940ca3a5c62de45b6823efbdbe42fce11de2 encode hash: 8411e71bf6b32576d287764cfa577ea0e9b73280
decode hash: 85f2a154b46cc6cfa2792ff95c67b4200ce4463b decode hash: 30ad42bc97b53c03139cca5437b7d9a861de0e92