Commit ccea9ce9 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Two-pass algorithm for filling the remaining bits. Still not perfect, but close

enough.
parent 17683ebe
......@@ -361,7 +361,7 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
}
}
if (ec_enc_tell(&st->enc, 0) < nbCompressedBytes*8 - 16)
if (ec_enc_tell(&st->enc, 0) < nbCompressedBytes*8 - 7)
celt_warning_int ("many unused bits: ", nbCompressedBytes*8-ec_enc_tell(&st->enc, 0));
//printf ("%d\n", ec_enc_tell(&st->enc, 0)-8*nbCompressedBytes);
/* Finishing the stream with a 0101... pattern so that the decoder can check is everything's right */
......
......@@ -221,13 +221,15 @@ int interp_bits2pulses(const struct alloc_data *alloc, int *bits1, int *bits2, i
for (j=0;j<len;j++)
bits[j] = ((1<<BITRES)-lo)*bits1[j] + lo*bits2[j];
out = vec_bits2pulses(alloc, bands, bits, pulses, len);
/* Do some refinement to use up all bits */
/* 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 */
int firstpass = 1;
while(1)
{
int incremented = 0;
for (j=0;j<len;j++)
{
if (alloc->bits[j][pulses[j]] < bits[j] && pulses[j]<MAX_PULSES-1)
if ((!firstpass || alloc->bits[j][pulses[j]] < bits[j]) && pulses[j]<MAX_PULSES-1)
{
if (out+alloc->bits[j][pulses[j]+1]-alloc->bits[j][pulses[j]] <= total<<BITRES)
{
......@@ -239,7 +241,12 @@ int interp_bits2pulses(const struct alloc_data *alloc, int *bits1, int *bits2, i
}
}
if (!incremented)
break;
{
if (firstpass)
firstpass = 0;
else
break;
}
}
return (out+BITROUND) >> BITRES;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment