ref: fffae794eaabb1eb691d52d606bfdae58d71608d
parent: 6d3829f266f0c9aa86e10b5998cbfbb450d2797e
author: Jean-Marc Valin <[email protected]>
date: Mon Aug 30 17:34:11 EDT 2010
New fine energy allocation tuning. Based on 1/2*log2(N)-19/8, but with the 2-bit and 3-bit thresholds shifted by 2*log2(N)/8 bit and log2(N)/8 bit, respectively.
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -181,25 +181,19 @@
{
int N0, N, den;
int offset;
- int fine_offset;
N0 = m->eBands[j+1]-m->eBands[j];
N=M*N0;
/* Compensate for the extra DoF in stereo */
den=(C*N+ ((C==2 && N>2) ? 1 : 0));
- if (N0==1)
- fine_offset = 19;
- else if (N0<=4)
- fine_offset = 14;
- else
- fine_offset = 12;
-
/* Offset for the number of fine bits compared to their "fair share" of total/N */
- offset = N*C*((m->logN[j] + logM - 2*fine_offset)>>1);
+ offset = N*C*(((m->logN[j] + logM)>>1)-FINE_OFFSET);
- /* Compensate for the prediction gain in stereo */
- if (C==2)
- offset -= 1<<BITRES;
+ /* Changing the offset for allocating the second and third fine energy bit */
+ if (bits[j] + offset < den*2<<BITRES)
+ offset += (m->logN[j] + logM)*N*C>>BITRES-1;
+ else if (bits[j] + offset < den*3<<BITRES)
+ offset += (m->logN[j] + logM)*N*C>>BITRES;
ebits[j] = (bits[j] + offset + (den<<(BITRES-1))) / (den<<BITRES);
--- a/libcelt/rate.h
+++ b/libcelt/rate.h
@@ -40,6 +40,7 @@
#define LOG_MAX_PULSES 7
#define BITRES 3
+#define FINE_OFFSET 19
#define QTHETA_OFFSET 6
#define QTHETA_OFFSET_STEREO 4