From fda0e10f0108e9fbb004bc5ca7edc7da559c7e65 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Mon, 9 Feb 2009 23:17:44 -0500 Subject: [PATCH] Better allocation rounding as suggested by derf --- libcelt/modes.c | 4 ++-- libcelt/rate.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libcelt/modes.c b/libcelt/modes.c index c5b8738e..6f1937ae 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -248,11 +248,11 @@ static void compute_allocation_table(CELTMode *mode, int res) for (j=0;jnbEBands;j++) allocVectors[i*mode->nbEBands+j] = (allocVectors[i*mode->nbEBands+j]+128)/256; } - for (i=0;inbAllocVectors;i++) + /*for (i=0;inbAllocVectors;i++) { for (j=0;jnbEBands;j++) allocVectors[i*mode->nbEBands+j] += C; - } + }*/ mode->energy_alloc = allocEnergy; mode->allocVectors = allocVectors; } diff --git a/libcelt/rate.c b/libcelt/rate.c index 9c830493..38b193d1 100644 --- a/libcelt/rate.c +++ b/libcelt/rate.c @@ -113,13 +113,18 @@ static void interp_bits2pulses(const CELTMode *m, int *bits1, int *bits2, int to } for (j=0;j= C>>BITRES) + if (bits[j] >= C<eBands[j+1]-m->eBands[j]; + d=C*N<eBands[j+1]-m->eBands[j], 4); - ebits[j] = IMAX(min_bits , ((bits[j]+C*(m->eBands[j+1]-m->eBands[j])/2) / (C*(m->eBands[j+1]-m->eBands[j])) - offset)>>BITRES ); + ebits[j] = IMAX(min_bits, (bits[j]-offset*N*C+(d>>1))/d); + /* Make sure not to bust */ if (C*ebits[j] > (bits[j]>>BITRES)) ebits[j] = bits[j]/C >> BITRES;