Proper use of logN and logM for the offsets
diff --git a/libcelt/rate.c b/libcelt/rate.c
index b6845ee..2c0af22 100644
--- 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 */