From aead79b133ba976a0f6101748c0cc39c6e12040e Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Tue, 11 May 2010 07:34:24 -0400 Subject: [PATCH] Proper use of logN and logM for the offsets --- libcelt/bands.c | 4 ++-- libcelt/modes.c | 2 +- libcelt/rate.c | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index 6733380c..8de5bb72 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -639,7 +639,7 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_ 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< (b>>BITRES)-1) qb = (b>>BITRES)-1; if (qb<0) @@ -835,7 +835,7 @@ void unquant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const cel 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< (b>>BITRES)-1) qb = (b>>BITRES)-1; if (qb>14) diff --git a/libcelt/modes.c b/libcelt/modes.c index 69165a17..147dcc10 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -379,7 +379,7 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) goto failure; for (i=0;inbEBands;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 */ diff --git a/libcelt/rate.c b/libcelt/rate.c index b6845eef..2c0af229 100644 --- a/libcelt/rate.c +++ b/libcelt/rate.c @@ -107,8 +107,11 @@ static inline void interp_bits2pulses(const CELTMode *m, int start, int *bits1, 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<eBands[j+1]-m->eBands[j]); /* Compensate for the extra DoF in stereo */ d=(C*N+ ((C==2 && N>2) ? 1 : 0))<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 */