Better allocation rounding as suggested by derf

This commit is contained in:
Jean-Marc Valin 2009-02-09 23:17:44 -05:00
parent 520eeaee1a
commit fda0e10f01
2 changed files with 10 additions and 5 deletions

View file

@ -113,13 +113,18 @@ static void interp_bits2pulses(const CELTMode *m, int *bits1, int *bits2, int to
}
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;