From 37546cc3f60fd52880663d26f3e1cc0915f19538 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Tue, 27 Jul 2010 22:39:15 +0200 Subject: [PATCH] Bit allocation Also convert the stereo split code to use log(N)/2 as the bit allocation offset --- libcelt/bands.c | 6 +++--- libcelt/rate.c | 4 ++-- libcelt/rate.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index 08ad6a0e6..438ec6ea5 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<logN[i]+(LM<>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< (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 8110e426d..c7d3a2a32 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 ee5e25b60..27f8dc45e 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 -- GitLab