diff --git a/libcelt/bands.c b/libcelt/bands.c index 08ad6a0e6e4e5b7d6228973d4fba33ab7b001a6c..438ec6ea502cdb5c42676f9bf356b3035af0708d 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -598,11 +598,11 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_ int qalloc; celt_word16 mid, side; int offset, N2; - offset = m->logN[i]+(LM<<BITRES)-QTHETA_OFFSET; + offset = ((m->logN[i]+(LM<<BITRES))>>1)-QTHETA_OFFSET; /* Decide on the resolution to give to the split parameter theta */ N2 = 2*N-1; - if (stereo && N>2) + if (stereo && N==2) N2--; qb = (b+N2*offset)/(N2<<BITRES); if (qb > (b>>(BITRES+1))-1) @@ -627,7 +627,7 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_ mid = renormalise_vector(X, Q15ONE, N, 1); side = renormalise_vector(Y, Q15ONE, N, 1); - /* theta is the atan() of the ration between the (normalized) + /* theta is the atan() of the ratio between the (normalized) side and mid. With just that parameter, we can re-scale both mid and side because we know that 1) they have unit norm and 2) they are orthogonal. */ diff --git a/libcelt/rate.c b/libcelt/rate.c index 8110e426d85b9866b3b2fa57a5a9cb3d961542e1..c7d3a2a323f4e1a443d49d0b416071951eac42b6 100644 --- a/libcelt/rate.c +++ b/libcelt/rate.c @@ -173,8 +173,8 @@ static inline void interp_bits2pulses(const CELTMode *m, int start, int end, int if (N==1) ebits[j] = (bits[j]/C >> BITRES)-1; - if (ebits[j] < 1) - ebits[j] = 1; + if (ebits[j] < C) + ebits[j] = C; /* Make sure not to bust */ if (C*ebits[j] > (bits[j]>>BITRES)) ebits[j] = bits[j]/C >> BITRES; diff --git a/libcelt/rate.h b/libcelt/rate.h index ee5e25b6008b6c4bcb7d39ed729791fa0f106734..27f8dc45edaad538a98035ac8760692baf7030b0 100644 --- a/libcelt/rate.h +++ b/libcelt/rate.h @@ -41,7 +41,7 @@ #define BITRES 3 #define FINE_OFFSET 14 -#define QTHETA_OFFSET 18 +#define QTHETA_OFFSET (-2) #define BITOVERFLOW 30000