Reduce rounding in the mode allocator and remove a scaling loop.

This breaks the bitstream.
This commit is contained in:
Gregory Maxwell 2009-05-04 14:55:40 -04:00 committed by Jean-Marc Valin
parent 74f4e9f385
commit ec836da27c

View file

@ -206,7 +206,7 @@ static void compute_pbands(CELTMode *mode, int res)
static void compute_allocation_table(CELTMode *mode, int res) static void compute_allocation_table(CELTMode *mode, int res)
{ {
int i, j, eband, nBark; int i, j, nBark;
celt_int16_t *allocVectors, *allocEnergy; celt_int16_t *allocVectors, *allocEnergy;
const int C = CHANNELS(mode); const int C = CHANNELS(mode);
@ -221,38 +221,31 @@ static void compute_allocation_table(CELTMode *mode, int res)
/* Compute per-codec-band allocation from per-critical-band matrix */ /* Compute per-codec-band allocation from per-critical-band matrix */
for (i=0;i<BITALLOC_SIZE;i++) for (i=0;i<BITALLOC_SIZE;i++)
{ {
eband = 0; celt_int32_t current = 0;
int eband = 0;
for (j=0;j<nBark;j++) for (j=0;j<nBark;j++)
{ {
int edge, low; int edge, low;
celt_int32_t alloc; celt_int32_t alloc;
edge = mode->eBands[eband+1]*res; edge = mode->eBands[eband+1]*res;
alloc = band_allocation[i*BARK_BANDS+j]; alloc = band_allocation[i*BARK_BANDS+j];
alloc = alloc*C*mode->mdctSize/4; alloc = alloc*C*mode->mdctSize;
if (edge < bark_freq[j+1]) if (edge < bark_freq[j+1])
{ {
int num, den; int num, den;
num = alloc * (edge-bark_freq[j]); num = alloc * (edge-bark_freq[j]);
den = bark_freq[j+1]-bark_freq[j]; den = bark_freq[j+1]-bark_freq[j];
low = (num+den/2)/den; low = (num+den/2)/den;
allocVectors[i*mode->nbEBands+eband] += low; allocVectors[i*mode->nbEBands+eband] = (current+low+128)/256;
current=0;
eband++; eband++;
allocVectors[i*mode->nbEBands+eband] += alloc-low; current += alloc-low;
} else { } else {
allocVectors[i*mode->nbEBands+eband] += alloc; current += alloc;
} }
} }
allocVectors[i*mode->nbEBands+eband] = (current+128)/256;
} }
for (i=0;i<mode->nbAllocVectors;i++)
{
for (j=0;j<mode->nbEBands;j++)
allocVectors[i*mode->nbEBands+j] = (allocVectors[i*mode->nbEBands+j]+32)/64;
}
/*for (i=0;i<mode->nbAllocVectors;i++)
{
for (j=0;j<mode->nbEBands;j++)
allocVectors[i*mode->nbEBands+j] += C;
}*/
mode->allocVectors = allocVectors; mode->allocVectors = allocVectors;
} }