From 4c6ee567ee8bde030a620b577570bc0cd9620a7d Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Tue, 27 May 2008 22:17:13 +1000 Subject: [PATCH] Preventing encoder-decoder mismatch when energy values are too large to be represented by the laplace encoder (would have a probability of zero due to finite precision) --- libcelt/laplace.c | 15 ++++++++++----- libcelt/laplace.h | 4 ++-- libcelt/quant_bands.c | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libcelt/laplace.c b/libcelt/laplace.c index b48bfe73..abfe5761 100644 --- a/libcelt/laplace.c +++ b/libcelt/laplace.c @@ -40,19 +40,20 @@ int ec_laplace_get_start_freq(int decay) return (((ec_uint32)32767)*(16384-decay))/(16384+decay); } -void ec_laplace_encode_start(ec_enc *enc, int value, int decay, int fs) +void ec_laplace_encode_start(ec_enc *enc, int *value, int decay, int fs) { int i; int fl, ft; int s = 0; - if (value < 0) + int val = *value; + if (val < 0) { s = 1; - value = -value; + val = -val; } ft = 32767; fl = -fs; - for (i=0;i budget+16) qi = -1; else - ec_laplace_encode_start(enc, qi, prob[2*i], prob[2*i+1]); + ec_laplace_encode_start(enc, &qi, prob[2*i], prob[2*i+1]); q = qi*base_resolution; error[i] = f - SHL16(qi,8);