ref: aead79b133ba976a0f6101748c0cc39c6e12040e
parent: c40d6f97a2456e7706740c670229e4800eef825e
author: Jean-Marc Valin <[email protected]>
date: Tue May 11 03:34:24 EDT 2010
Proper use of logN and logM for the offsets
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -639,7 +639,7 @@
if (b<0)
b = 0;
- qb = (b-2*(N-1)*(QTHETA_OFFSET-log2_frac(N,BITRES)))/(32*(N-1));
+ qb = (b-2*(N-1)*(QTHETA_OFFSET-m->logN[i]-(LM<<BITRES)))/(32*(N-1));
if (qb > (b>>BITRES)-1)
qb = (b>>BITRES)-1;
if (qb<0)
@@ -835,7 +835,7 @@
if (b<0)
b = 0;
- qb = (b-2*(N-1)*(QTHETA_OFFSET-log2_frac(N,BITRES)))/(32*(N-1));
+ qb = (b-2*(N-1)*(QTHETA_OFFSET-m->logN[i]-(LM<<BITRES)))/(32*(N-1));
if (qb > (b>>BITRES)-1)
qb = (b>>BITRES)-1;
if (qb>14)
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -379,7 +379,7 @@
goto failure;
for (i=0;i<mode->nbEBands;i++)
- logN[i] = log2_frac(mode->nbShortMdcts*(mode->eBands[i+1]-mode->eBands[i]), BITRES);
+ logN[i] = log2_frac(mode->eBands[i+1]-mode->eBands[i], BITRES);
mode->logN = logN;
#endif /* !STATIC_MODES */
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -107,8 +107,11 @@
int psum;
int lo, hi;
int j;
+ int logM;
const int C = CHANNELS(_C);
SAVE_STACK;
+
+ logM = log2_frac(M, BITRES);
lo = 0;
hi = 1<<BITRES;
while (hi-lo != 1)
@@ -148,7 +151,7 @@
N=M*(m->eBands[j+1]-m->eBands[j]);
/* Compensate for the extra DoF in stereo */
d=(C*N+ ((C==2 && N>2) ? 1 : 0))<<BITRES;
- offset = FINE_OFFSET - m->logN[j];
+ offset = FINE_OFFSET - m->logN[j] - logM;
/* Offset for the number of fine bits compared to their "fair share" of total/N */
offset = bits[j]-offset*N*C;
/* Compensate for the prediction gain in stereo */