shithub: opus

Download patch

ref: a345decd971cb77263343168b8801c0812a42f88
parent: 6f1cbca519ad1daa59093135da13d9de575e65eb
author: Timothy B. Terriberry <[email protected]>
date: Tue Jul 27 03:49:24 EDT 2010

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.

--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -160,7 +160,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] - 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 @@
 
       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;
--- 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