From d5cacaec07a22f11d21f1988a67cb4efbd771d29 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Fri, 2 Dec 2022 15:33:48 -0500 Subject: DRED: Fix infinite loop on "impossible" symbols --- silk/dred_coding.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1