ref: eb7ce0316590cb752056b556724b0f96f7ea5f2a
parent: 46f3700e55953c3c279ea5d94784ed063fab0466
author: Jean-Marc Valin <[email protected]>
date: Sat Aug 2 16:14:17 EDT 2008
fixed a bunch of bugs in the unified allocation code.
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -150,11 +150,11 @@
for (j=0;j<len;j++)
{
ebits[j] = (((1<<BITRES)-mid)*ebits1[j] + mid*ebits2[j] + (1<<(BITRES-1)))>>BITRES;
- esum += C*ebits[j];
+ esum += ebits[j];
}
for (j=0;j<len;j++)
- bits[j] = ((1<<BITRES)-mid)*bits1[j] + mid*bits2[j] - C*(ebits[j]<<BITRES);
- if (vec_bits2pulses(m, cache, bits, pulses, len) > (total-esum)<<BITRES)
+ bits[j] = ((1<<BITRES)-mid)*bits1[j] + mid*bits2[j];
+ if (vec_bits2pulses(m, cache, bits, pulses, len) > (total-C*esum)<<BITRES)
hi = mid;
else
lo = mid;
@@ -164,12 +164,12 @@
for (j=0;j<len;j++)
{
ebits[j] = (((1<<BITRES)-lo)*ebits1[j] + lo*ebits2[j] + (1<<(BITRES-1)))>>BITRES;
- esum += C*ebits[j];
+ esum += ebits[j];
}
for (j=0;j<len;j++)
- bits[j] = ((1<<BITRES)-lo)*bits1[j] + lo*bits2[j] - C*(ebits[j]<<BITRES);
+ bits[j] = ((1<<BITRES)-lo)*bits1[j] + lo*bits2[j];
out = vec_bits2pulses(m, cache, bits, pulses, len);
- /*printf ("left to allocate: %d\n", total-esum-(out>>BITRES));*/
+ /*printf ("left to allocate: %d\n", total-C*esum-(out>>BITRES));*/
/* Do some refinement to use up all bits. In the first pass, we can only add pulses to
bands that are under their allocated budget. In the second pass, anything goes */
for (j=0;j<len;j++)
@@ -176,7 +176,7 @@
{
if (cache[j][pulses[j]] < bits[j] && pulses[j]<MAX_PULSES-1)
{
- if (out+cache[j][pulses[j]+1]-cache[j][pulses[j]] <= (total-esum)<<BITRES)
+ if (out+cache[j][pulses[j]+1]-cache[j][pulses[j]] <= (total-C*esum)<<BITRES)
{
out = out+cache[j][pulses[j]+1]-cache[j][pulses[j]];
pulses[j] += 1;
@@ -190,7 +190,7 @@
{
if (pulses[j]<MAX_PULSES-1)
{
- if (out+cache[j][pulses[j]+1]-cache[j][pulses[j]] <= (total-esum)<<BITRES)
+ if (out+cache[j][pulses[j]+1]-cache[j][pulses[j]] <= (total-C*esum)<<BITRES)
{
out = out+cache[j][pulses[j]+1]-cache[j][pulses[j]];
pulses[j] += 1;
@@ -245,7 +245,7 @@
int mid = (lo+hi) >> 1;
for (j=0;j<len;j++)
{
- bits1[j] = (m->allocVectors[mid*len+j] - C*m->energy_alloc[mid*(len+1)+j] + offsets[j])<<BITRES;
+ bits1[j] = (m->allocVectors[mid*len+j] + offsets[j])<<BITRES;
if (bits1[j] < 0)
bits1[j] = 0;
/*printf ("%d ", bits[j]);*/
@@ -264,8 +264,8 @@
{
ebits1[j] = m->energy_alloc[lo*(len+1)+j];
ebits2[j] = m->energy_alloc[hi*(len+1)+j];
- bits1[j] = m->allocVectors[lo*len+j] + offsets[j] - 0*ebits1[j];
- bits2[j] = m->allocVectors[hi*len+j] + offsets[j] - 0*ebits2[j];
+ bits1[j] = m->allocVectors[lo*len+j] + offsets[j];
+ bits2[j] = m->allocVectors[hi*len+j] + offsets[j];
if (bits1[j] < 0)
bits1[j] = 0;
if (bits2[j] < 0)