Skip to content

Commit

Permalink
Saturate additions in getEnvSfbEnergy in SBR encoding
Browse files Browse the repository at this point in the history
This avoids wraparounds, which can trigger failed asserts with
some inputs. This fixes
#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.
  • Loading branch information
mstorsjo committed Nov 10, 2023
1 parent 14922d3 commit 46965df
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions libSBRenc/src/env_est.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 +=
Expand Down
4 changes: 2 additions & 2 deletions test/ref-mono.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
encode hash: 516e51016cbba6068f1aa285a8fdd55b00ada6b0
decode hash: 3b3b3a17cc5ba50ade75b3ef1a37f96017935fe5
encode hash: 7f00e85a1eda67964e1b4044a5659a62e3952af2
decode hash: af682b197a94e32fce09643857fa77b364574571
4 changes: 2 additions & 2 deletions test/ref-stereo.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
encode hash: 1179940ca3a5c62de45b6823efbdbe42fce11de2
decode hash: 85f2a154b46cc6cfa2792ff95c67b4200ce4463b
encode hash: 8411e71bf6b32576d287764cfa577ea0e9b73280
decode hash: 30ad42bc97b53c03139cca5437b7d9a861de0e92

0 comments on commit 46965df

Please sign in to comment.