ref: c7ace558fe3faa30701011fce37aba522963ffa9
parent: 310fb3cb4d89c386d0d6b103d00243d34b0bdecb
author: Timothy B. Terriberry <[email protected]>
date: Sat Dec 13 20:42:37 EST 2008
Fix log2_frac() to return an upper bound, not a lower bound.
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -389,7 +389,7 @@
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 @@
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;
--- a/libcelt/cwrs.c
+++ b/libcelt/cwrs.c
@@ -54,6 +54,8 @@
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 @@
/*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;
}