summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@amazon.com>2022-12-02 15:33:48 -0500
committerJean-Marc Valin <jmvalin@amazon.com>2022-12-02 15:33:48 -0500
commitd5cacaec07a22f11d21f1988a67cb4efbd771d29 (patch)
treec3ab036dea58106ca16812505403e9813d042147
parentf08528e5a6d595ce5c04e24bc493ada60c2b4baa (diff)
downloadopus-d5cacaec07a22f11d21f1988a67cb4efbd771d29.tar.gz
DRED: Fix infinite loop on "impossible" symbols
-rw-r--r--silk/dred_coding.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/silk/dred_coding.c b/silk/dred_coding.c
index d2e71c74..9b0381d2 100644
--- a/silk/dred_coding.c
+++ b/silk/dred_coding.c
@@ -77,6 +77,8 @@ void dred_encode_latents(ec_enc *enc, const float *x, const opus_uint16 *scale,
xq = x[i]*scale[i]*(1.f/256.f);
xq = xq - delta*tanh(xq/(delta+eps));
q = (int)floor(.5f+xq);
+ /* Make the impossible actually impossible. */
+ if (r[i] == 0 || p0[i] >= 32768) q = 0;
ec_laplace_encode_p0(enc, q, p0[i], r[i]);
}
}
@@ -190,4 +192,4 @@ int main()
printf("\n");
}
}
-#endif \ No newline at end of file
+#endif