Skip to content
Snippets Groups Projects
Commit c7ace558 authored by Timothy B. Terriberry's avatar Timothy B. Terriberry Committed by Jean-Marc Valin
Browse files

Fix log2_frac() to return an upper bound, not a lower bound.

parent 310fb3cb
No related branches found
No related tags found
No related merge requests found
......@@ -389,7 +389,7 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, ce
tell = ec_enc_tell(enc, 4);
if (i != 0)
balance -= tell;
remaining_bits = (total_bits<<BITRES)-tell-2;
remaining_bits = (total_bits<<BITRES)-tell-1;
curr_balance = (m->nbEBands-i);
if (curr_balance > 3)
curr_balance = 3;
......@@ -472,7 +472,7 @@ void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P,
tell = ec_dec_tell(dec, 4);
if (i != 0)
balance -= tell;
remaining_bits = (total_bits<<BITRES)-tell-2;
remaining_bits = (total_bits<<BITRES)-tell-1;
curr_balance = (m->nbEBands-i);
if (curr_balance > 3)
curr_balance = 3;
......
......@@ -54,6 +54,8 @@ int log2_frac(ec_uint32 val, int frac)
int i;
/* EC_ILOG() actually returns log2()+1, go figure */
int L = EC_ILOG(val)-1;
int pow2;
pow2=!(val&val-1);
/*printf ("in: %d %d ", val, L);*/
if (L>14)
val >>= L-14;
......@@ -67,9 +69,12 @@ int log2_frac(ec_uint32 val, int frac)
/*printf ("%d\n", val);*/
if (val > 16384)
L |= (1<<(frac-i-1));
else
else
val <<= 1;
}
/*The previous loop returns a conservatively low estimate.
If val wasn't a power of two, we should round up.*/
L += !pow2;
return L;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment