Fix totally broken bit allocation for non-mainstream modes (e.g. powers of two).
Also, making per-band dynamic allocation less aggressive.
This commit is contained in:
parent
bad42a7d05
commit
1bfa18cb92
2 changed files with 16 additions and 37 deletions
|
@ -896,7 +896,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
|
||||||
offsets[i] = 0;
|
offsets[i] = 0;
|
||||||
/* Dynamic allocation code */
|
/* Dynamic allocation code */
|
||||||
/* Make sure that dynamic allocation can't make us bust the budget */
|
/* Make sure that dynamic allocation can't make us bust the budget */
|
||||||
if (nbCompressedBytes > 30 && LM>=1)
|
if (nbCompressedBytes > 50 && LM>=1)
|
||||||
{
|
{
|
||||||
int t1, t2;
|
int t1, t2;
|
||||||
if (LM <= 1)
|
if (LM <= 1)
|
||||||
|
|
|
@ -215,50 +215,29 @@ static void compute_allocation_table(CELTMode *mode, int res)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* If not the standard mode, interpolate */
|
/* If not the standard mode, interpolate */
|
||||||
|
|
||||||
/* 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++)
|
||||||
{
|
{
|
||||||
celt_int32 current = 0;
|
for (j=0;j<mode->nbEBands;j++)
|
||||||
int eband = 0;
|
|
||||||
/* We may be looping over too many bands, but eband will stop being
|
|
||||||
incremented once we reach the last band */
|
|
||||||
for (j=0;j<maxBands;j++)
|
|
||||||
{
|
{
|
||||||
int edge, low, high;
|
int k;
|
||||||
celt_int32 alloc;
|
for (k=0;k<maxBands;k++)
|
||||||
alloc = band_allocation[i*maxBands + j]*(mode->eBands[eband+1]-mode->eBands[eband])<<4;
|
|
||||||
low = eband5ms[j]*200;
|
|
||||||
high = eband5ms[j+1]*200;
|
|
||||||
edge = mode->eBands[eband+1]*res;
|
|
||||||
while (edge <= high && eband < mode->nbEBands)
|
|
||||||
{
|
{
|
||||||
celt_int32 num;
|
if (400*(celt_int32)eband5ms[k] > mode->eBands[j]*(celt_int32)mode->Fs/mode->shortMdctSize)
|
||||||
int den, bits;
|
break;
|
||||||
int N = (mode->eBands[eband+1]-mode->eBands[eband]);
|
}
|
||||||
num = alloc * (edge-low);
|
if (k>mode->nbEBands-1)
|
||||||
den = high-low;
|
allocVectors[i*mode->nbEBands+j] = band_allocation[i*maxBands + maxBands-1];
|
||||||
/* Divide with rounding */
|
else {
|
||||||
bits = (2*num+den)/(2*den);
|
celt_int32 a0, a1;
|
||||||
allocVectors[i*mode->nbEBands+eband] = (2*(current+bits)+(N<<4))/(2*N<<4);
|
a1 = mode->eBands[j]*(celt_int32)mode->Fs/mode->shortMdctSize - 400*(celt_int32)eband5ms[k-1];
|
||||||
/* Remove the part of the band we just allocated */
|
a0 = 400*(celt_int32)eband5ms[k] - mode->eBands[j]*(celt_int32)mode->Fs/mode->shortMdctSize;
|
||||||
low = edge;
|
allocVectors[i*mode->nbEBands+j] = (a0*band_allocation[i*maxBands+k-1]
|
||||||
alloc -= bits;
|
+ a1*band_allocation[i*maxBands+k])/(a0+a1);
|
||||||
|
|
||||||
/* Move to next eband */
|
|
||||||
current = 0;
|
|
||||||
eband++;
|
|
||||||
if (eband < mode->nbEBands)
|
|
||||||
edge = mode->eBands[eband+1]*res;
|
|
||||||
}
|
}
|
||||||
current += alloc;
|
|
||||||
}
|
|
||||||
if (eband < mode->nbEBands)
|
|
||||||
{
|
|
||||||
int N = (mode->eBands[eband+1]-mode->eBands[eband]);
|
|
||||||
allocVectors[i*mode->nbEBands+eband] = (2*current+(N<<4))/(2*N<<4);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*printf ("\n");
|
/*printf ("\n");
|
||||||
for (i=0;i<BITALLOC_SIZE;i++)
|
for (i=0;i<BITALLOC_SIZE;i++)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue