ref: 91f07dc125247a422c186edbebc05f54380b2dbf
parent: 949a29bf0c7305bd79021815a06123b343972743
author: Jean-Marc Valin <[email protected]>
date: Sat Jul 25 16:42:24 EDT 2009
Changing some code to use BITRES directly instead of its value.
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -417,7 +417,7 @@
N = eBands[i+1]-eBands[i];
BPbits = m->bits;
- tell = ec_enc_tell(enc, 4);
+ tell = ec_enc_tell(enc, BITRES);
if (i != 0)
balance -= tell;
remaining_bits = (total_bits<<BITRES)-tell-1;
@@ -517,7 +517,7 @@
BPbits = m->bits;
N = eBands[i+1]-eBands[i];
- tell = ec_enc_tell(enc, 4);
+ tell = ec_enc_tell(enc, BITRES);
if (i != 0)
balance -= tell;
remaining_bits = (total_bits<<BITRES)-tell-1;
@@ -529,7 +529,7 @@
if (b<0)
b = 0;
- qb = (b-2*(N-1)*(40-log2_frac(N,4)))/(32*(N-1));
+ qb = (b-2*(N-1)*(QTHETA_OFFSET-log2_frac(N,BITRES)))/(32*(N-1));
if (qb > (b>>BITRES)-1)
qb = (b>>BITRES)-1;
if (qb<0)
@@ -546,7 +546,7 @@
#else
itheta = floor(.5+16384*0.63662*atan2(side,mid));
#endif
- qalloc = log2_frac((1<<qb)+1,4);
+ qalloc = log2_frac((1<<qb)+1,BITRES);
if (qb==0)
{
itheta=0;
@@ -570,7 +570,7 @@
} else {
imid = bitexact_cos(itheta);
iside = bitexact_cos(16384-itheta);
- delta = (N-1)*(log2_frac(iside,6)-log2_frac(imid,6))>>2;
+ delta = (N-1)*(log2_frac(iside,BITRES+2)-log2_frac(imid,BITRES+2))>>2;
}
mbits = (b-qalloc/2-delta)/2;
if (mbits > b-qalloc)
@@ -702,7 +702,7 @@
N = eBands[i+1]-eBands[i];
BPbits = m->bits;
- tell = ec_dec_tell(dec, 4);
+ tell = ec_dec_tell(dec, BITRES);
if (i != 0)
balance -= tell;
remaining_bits = (total_bits<<BITRES)-tell-1;
@@ -801,7 +801,7 @@
BPbits = m->bits;
N = eBands[i+1]-eBands[i];
- tell = ec_dec_tell(dec, 4);
+ tell = ec_dec_tell(dec, BITRES);
if (i != 0)
balance -= tell;
remaining_bits = (total_bits<<BITRES)-tell-1;
@@ -813,7 +813,7 @@
if (b<0)
b = 0;
- qb = (b-2*(N-1)*(40-log2_frac(N,4)))/(32*(N-1));
+ qb = (b-2*(N-1)*(QTHETA_OFFSET-log2_frac(N,BITRES)))/(32*(N-1));
if (qb > (b>>BITRES)-1)
qb = (b>>BITRES)-1;
if (qb>14)
@@ -820,7 +820,7 @@
qb = 14;
if (qb<0)
qb = 0;
- qalloc = log2_frac((1<<qb)+1,4);
+ qalloc = log2_frac((1<<qb)+1,BITRES);
if (qb==0)
{
itheta=0;
@@ -843,7 +843,7 @@
} else {
imid = bitexact_cos(itheta);
iside = bitexact_cos(16384-itheta);
- delta = (N-1)*(log2_frac(iside,6)-log2_frac(imid,6))>>2;
+ delta = (N-1)*(log2_frac(iside,BITRES+2)-log2_frac(imid,BITRES+2))>>2;
}
mbits = (b-qalloc/2-delta)/2;
if (mbits > b-qalloc)
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -828,7 +828,7 @@
/* The average energy is removed from the target and the actual
energy added*/
- target=target-588+ec_enc_tell(&enc, 4);
+ target=target-588+ec_enc_tell(&enc, BITRES);
/* In VBR mode the frame size must not be reduced so much that it would result in the coarse energy busting its budget */
target=IMAX(coarse_needed,(target+64)/128);
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -146,7 +146,7 @@
N=m->eBands[j+1]-m->eBands[j];
d=C*N<<BITRES;
- offset = 50 - log2_frac(N, 4);
+ offset = FINE_OFFSET - log2_frac(N, BITRES);
/* Offset for the number of fine bits compared to their "fair share" of total/N */
offset = bits[j]-offset*N*C;
if (offset < 0)
--- a/libcelt/rate.h
+++ b/libcelt/rate.h
@@ -39,7 +39,9 @@
#define LOG_MAX_PULSES 7
#define BITRES 4
-#define BITROUND 8
+#define FINE_OFFSET 50
+#define QTHETA_OFFSET 40
+
#define BITOVERFLOW 30000
#include "cwrs.h"