From a345decd971cb77263343168b8801c0812a42f88 Mon Sep 17 00:00:00 2001 From: "Timothy B. Terriberry" Date: Tue, 27 Jul 2010 07:49:24 -0700 Subject: [PATCH] Adjust fine bits allocation. The old code allocated too many fine bits to large bands. New allocations were derived from by numerical optimization using quantization MSE sampled from Laplacian distributed random data to within +/- 1 bit for N=2...160 and bits per band from 0 to 64. Those allocations could be modeled with only minor errors using a simple offset of 19/8+log2(N), with no bits spent on fine energy when there would not be enough bits remaining to code a single pulse. However, PEAQ testing suggested an offset of 14/8 was better, and that it was always worth spending at least one bit on fine energy. --- libcelt/rate.c | 4 +++- libcelt/rate.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libcelt/rate.c b/libcelt/rate.c index 42bdb7d5..8110e426 100644 --- a/libcelt/rate.c +++ b/libcelt/rate.c @@ -160,7 +160,7 @@ static inline void interp_bits2pulses(const CELTMode *m, int start, int end, int 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))<logN[j] - logM; + offset = FINE_OFFSET - ((m->logN[j] + logM)>>1); /* 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 */ @@ -173,6 +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; /* 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 833e1e2b..ee5e25b6 100644 --- a/libcelt/rate.h +++ b/libcelt/rate.h @@ -40,7 +40,7 @@ #define LOG_MAX_PULSES 7 #define BITRES 3 -#define FINE_OFFSET 25 +#define FINE_OFFSET 14 #define QTHETA_OFFSET 18 #define BITOVERFLOW 30000