ref: fda0e10f0108e9fbb004bc5ca7edc7da559c7e65
parent: 520eeaee1a18a20b97207f9df3d685fc64c6d177
author: Jean-Marc Valin <[email protected]>
date: Mon Feb 9 18:17:44 EST 2009
Better allocation rounding as suggested by derf
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -248,11 +248,11 @@
for (j=0;j<mode->nbEBands;j++)
allocVectors[i*mode->nbEBands+j] = (allocVectors[i*mode->nbEBands+j]+128)/256;
}
- for (i=0;i<mode->nbAllocVectors;i++)
+ /*for (i=0;i<mode->nbAllocVectors;i++)
{
for (j=0;j<mode->nbEBands;j++)
allocVectors[i*mode->nbEBands+j] += C;
- }
+ }*/
mode->energy_alloc = allocEnergy;
mode->allocVectors = allocVectors;
}
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -113,13 +113,18 @@
}
for (j=0;j<len;j++)
{
+ int N, d;
int offset;
int min_bits=0;
- if (bits[j] >= C>>BITRES)
+ if (bits[j] >= C<<BITRES)
min_bits = 1;
+
+ N=m->eBands[j+1]-m->eBands[j];
+ d=C*N<<BITRES;
+ offset = 50 - log2_frac(N, 4);
/* Offset for the number of fine bits compared to their "fair share" of total/N */
- offset = 45 - log2_frac(m->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;