ref: ce6d0904a1548143758f58d56340f5d4ddd2f96c
parent: 424eb7427960a84f27f7d8dc412aca17306b714c
author: Timothy B. Terriberry <[email protected]>
date: Tue Feb 1 12:41:12 EST 2011
Increase caps/allocation accuracy. This stores the caps array in 32nd bits/sample instead of 1/2 bits scaled by LM and the channel count, which is slightly less less accurate for the last two bands, and much more accurate for all the other bands. A constant offset is subtracted to allow it to represent values larger than 255 in 8 bits (the range of unoffset values is 77...304). In addition, this replaces the last modeline in the allocation table with the caps array, allowing the initial interpolation to allocate 8 bits/sample or more, which was otherwise impossible.
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -756,6 +756,17 @@
}
}
+static void init_caps(const CELTMode *m,int *cap,int LM,int C)
+{
+ int i;
+ for (i=0;i<m->nbEBands;i++)
+ {
+ int N;
+ N=(m->eBands[i+1]-m->eBands[i])<<LM;
+ cap[i] = (m->cache.caps[m->nbEBands*(2*LM+C-1)+i]+64)*C*N>>2;
+ }
+}
+
static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X,
const celt_word16 *bandLogE, int nbEBands, int LM, int C, int N0)
{
@@ -1229,10 +1240,8 @@
ALLOC(cap, st->mode->nbEBands, int);
ALLOC(offsets, st->mode->nbEBands, int);
+ init_caps(st->mode,cap,LM,C);
for (i=0;i<st->mode->nbEBands;i++)
- cap[i] = st->mode->cache.caps[st->mode->nbEBands*(2*LM+C-1)+i]
- << C+LM+BITRES-2;
- for (i=0;i<st->mode->nbEBands;i++)
offsets[i] = 0;
/* Dynamic allocation code */
/* Make sure that dynamic allocation can't make us bust the budget */
@@ -2294,9 +2303,7 @@
ALLOC(offsets, st->mode->nbEBands, int);
ALLOC(fine_priority, st->mode->nbEBands, int);
- for (i=0;i<st->mode->nbEBands;i++)
- cap[i] = st->mode->cache.caps[st->mode->nbEBands*(2*LM+C-1)+i]
- << C+LM+BITRES-2;
+ init_caps(st->mode,cap,LM,C);
dynalloc_logp = 6;
total_bits<<=BITRES;
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -66,7 +66,7 @@
#else
/* Alternate tuning (partially derived from Vorbis) */
-#define BITALLOC_SIZE 12
+#define BITALLOC_SIZE 11
/* Bit allocation table in units of 1/32 bit/sample (0.1875 dB SNR) */
static const unsigned char band_allocation[] = {
/*0 200 400 600 800 1k 1.2 1.4 1.6 2k 2.4 2.8 3.2 4k 4.8 5.6 6.8 8k 9.6 12k 15.6 */
@@ -81,7 +81,6 @@
162,155,148,142,133,127,121,115,108,102, 96, 90, 84, 77, 71, 65, 59, 53, 46, 30, 1,
172,165,158,152,143,137,131,125,118,112,106,100, 94, 87, 81, 75, 69, 63, 56, 45, 20,
200,200,200,200,200,200,200,200,198,193,188,183,178,173,168,163,158,153,148,129,104,
-255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,251,239,204,129,104,
};
#endif
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -150,8 +150,6 @@
{
for (C=1;C<=2;C++)
{
- int shift;
- shift = C+i+BITRES-2;
for (j=0;j<m->nbEBands;j++)
{
int N0;
@@ -239,8 +237,10 @@
celt_assert(qb >= 0);
max_bits += C*qb<<BITRES;
}
- celt_assert(max_bits>>shift < 256);
- *cap++ = (unsigned char)(max_bits>>shift);
+ max_bits = (4*max_bits/(C*(m->eBands[j+1]-m->eBands[j]<<i)))-64;
+ celt_assert(max_bits >= 0);
+ celt_assert(max_bits < 256);
+ *cap++ = (unsigned char)max_bits;
}
}
}
@@ -580,7 +580,7 @@
trim_offset[j] -= C<<BITRES;
}
lo = 1;
- hi = m->nbAllocVectors - 2;
+ hi = m->nbAllocVectors - 1;
do
{
int done = 0;
@@ -616,7 +616,8 @@
{
int N = m->eBands[j+1]-m->eBands[j];
bits1[j] = C*N*m->allocVectors[lo*len+j]<<LM>>2;
- bits2[j] = C*N*m->allocVectors[hi*len+j]<<LM>>2;
+ bits2[j] = hi>=m->nbAllocVectors ?
+ cap[j] : C*N*m->allocVectors[hi*len+j]<<LM>>2;
if (bits1[j] > 0)
bits1[j] = IMAX(0, bits1[j] + trim_offset[j]);
if (bits2[j] > 0)
--- a/libcelt/static_modes_fixed.c
+++ b/libcelt/static_modes_fixed.c
@@ -22,7 +22,7 @@
static const unsigned char cache_bits50[392] = {
40, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 40, 15, 23, 28, 31, 34, 36, 38, 39, 41, 42, 43, 44, 45, 46, 47, 47, 49, 50, 51, 52, 53, 54, 55, 55, 57, 58, 59, 60, 61, 62, 63, 63, 65, 66, 67, 68, 69, 70, 71, 71, 40, 20, 33, 41, 48, 53, 57, 61, 64, 66, 69, 71, 73, 75, 76, 78, 80, 82, 85, 87, 89, 91, 92, 94, 96, 98, 101, 103, 105, 107, 108, 110, 112, 114, 117, 119, 121, 123, 124, 126, 128, 40, 23, 39, 51, 60, 67, 73, 79, 83, 87, 91, 94, 97, 100, 102, 105, 107, 111, 115, 118, 121, 124, 126, 129, 131, 135, 139, 142, 145, 148, 150, 153, 155, 159, 163, 166, 169, 172, 174, 177, 179, 35, 28, 49, 65, 78, 89, 99, 107, 114, 120, 126, 132, 136, 141, 145, 149, 153, 159, 165, 171, 176, 180, 185, 189, 192, 199, 205, 211, 216, 220, 225, 229, 232, 239, 245, 251, 21, 33, 58, 79, 97, 112, 125, 137, 148, 157, 166, 174, 182, 189, 195, 201, 207, 217, 227, 235, 243, 251, 17, 35, 63, 86, 106, 123, 139, 152, 165, 177, 187, 197, 206, 214, 222, 230, 237, 250, 25, 31, 55, 75, 91, 105, 117, 128, 138, 146, 154, 161, 168, 174, 180, 185, 190, 200, 208, 215, 222, 229, 235, 240, 245, 255, 16, 36, 65, 89, 110, 128, 144, 159, 173, 185, 196, 207, 217, 226, 234, 242, 250, 11, 41, 74, 103, 128, 151, 172, 191, 209, 225, 241, 255, 9, 43, 79, 110, 138, 163, 186, 207, 227, 246, 12, 39, 71, 99, 123, 144, 164, 182, 198, 214, 228, 241, 253, 9, 44, 81, 113, 142, 168, 192, 214, 235, 255, 7, 49, 90, 127, 160, 191, 220, 247, 6, 51, 95, 134, 170, 203, 234, 7, 47, 87, 123, 155, 184, 212, 237, 6, 52, 97, 137, 174, 208, 240, 5, 57, 106, 151, 192, 231, 5, 59, 111, 158, 202, 243, 5, 55, 103, 147, 187, 224, 5, 60, 113, 161, 206, 248, 4, 65, 122, 175, 224, 4, 67, 127, 182, 234, };
static const unsigned char cache_caps50[168] = {
-18, 18, 18, 18, 18, 18, 18, 18, 28, 28, 28, 28, 62, 62, 62, 90, 90, 116, 148, 141, 139, 18, 18, 18, 18, 18, 18, 18, 18, 38, 38, 38, 38, 67, 67, 67, 98, 98, 123, 156, 146, 144, 14, 14, 14, 14, 14, 14, 14, 14, 31, 31, 31, 31, 64, 64, 64, 92, 92, 118, 151, 144, 141, 19, 19, 19, 19, 19, 19, 19, 19, 33, 33, 33, 33, 67, 67, 67, 96, 96, 122, 155, 147, 143, 15, 15, 15, 15, 15, 15, 15, 15, 32, 32, 32, 32, 64, 64, 64, 92, 92, 118, 152, 145, 142, 16, 16, 16, 16, 16, 16, 16, 16, 33, 33, 33, 33, 66, 66, 66, 94, 94, 120, 153, 147, 143, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 64, 64, 64, 93, 93, 118, 152, 145, 142, 16, 16, 16, 16, 16, 16, 16, 16, 33, 33, 33, 33, 65, 65, 65, 94, 94, 119, 153, 146, 143, };
+224, 224, 224, 224, 224, 224, 224, 224, 160, 160, 160, 160, 185, 185, 185, 178, 178, 168, 134, 61, 37, 224, 224, 224, 224, 224, 224, 224, 224, 240, 240, 240, 240, 207, 207, 207, 198, 198, 183, 144, 66, 40, 160, 160, 160, 160, 160, 160, 160, 160, 185, 185, 185, 185, 193, 193, 193, 183, 183, 172, 138, 64, 38, 240, 240, 240, 240, 240, 240, 240, 240, 207, 207, 207, 207, 204, 204, 204, 193, 193, 180, 143, 66, 40, 185, 185, 185, 185, 185, 185, 185, 185, 193, 193, 193, 193, 193, 193, 193, 183, 183, 172, 138, 65, 39, 207, 207, 207, 207, 207, 207, 207, 207, 204, 204, 204, 204, 201, 201, 201, 188, 188, 176, 141, 66, 40, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 194, 194, 194, 184, 184, 173, 139, 65, 39, 204, 204, 204, 204, 204, 204, 204, 204, 201, 201, 201, 201, 198, 198, 198, 187, 187, 175, 140, 66, 40, };
#endif
#ifndef FFT_TWIDDLES48000_960
@@ -112,7 +112,7 @@
/* factors */
fft_bitrev120, /* bitrev */
fft_twiddles48000_960, /* bitrev */
-endif
+endif
8000_960_3
#define FFT_STATE48000_960_3
static const kiss_fft_state fft_state48000_960_3 = {
--- a/libcelt/static_modes_float.c
+++ b/libcelt/static_modes_float.c
@@ -22,7 +22,7 @@
static const unsigned char cache_bits50[392] = {
40, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 40, 15, 23, 28, 31, 34, 36, 38, 39, 41, 42, 43, 44, 45, 46, 47, 47, 49, 50, 51, 52, 53, 54, 55, 55, 57, 58, 59, 60, 61, 62, 63, 63, 65, 66, 67, 68, 69, 70, 71, 71, 40, 20, 33, 41, 48, 53, 57, 61, 64, 66, 69, 71, 73, 75, 76, 78, 80, 82, 85, 87, 89, 91, 92, 94, 96, 98, 101, 103, 105, 107, 108, 110, 112, 114, 117, 119, 121, 123, 124, 126, 128, 40, 23, 39, 51, 60, 67, 73, 79, 83, 87, 91, 94, 97, 100, 102, 105, 107, 111, 115, 118, 121, 124, 126, 129, 131, 135, 139, 142, 145, 148, 150, 153, 155, 159, 163, 166, 169, 172, 174, 177, 179, 35, 28, 49, 65, 78, 89, 99, 107, 114, 120, 126, 132, 136, 141, 145, 149, 153, 159, 165, 171, 176, 180, 185, 189, 192, 199, 205, 211, 216, 220, 225, 229, 232, 239, 245, 251, 21, 33, 58, 79, 97, 112, 125, 137, 148, 157, 166, 174, 182, 189, 195, 201, 207, 217, 227, 235, 243, 251, 17, 35, 63, 86, 106, 123, 139, 152, 165, 177, 187, 197, 206, 214, 222, 230, 237, 250, 25, 31, 55, 75, 91, 105, 117, 128, 138, 146, 154, 161, 168, 174, 180, 185, 190, 200, 208, 215, 222, 229, 235, 240, 245, 255, 16, 36, 65, 89, 110, 128, 144, 159, 173, 185, 196, 207, 217, 226, 234, 242, 250, 11, 41, 74, 103, 128, 151, 172, 191, 209, 225, 241, 255, 9, 43, 79, 110, 138, 163, 186, 207, 227, 246, 12, 39, 71, 99, 123, 144, 164, 182, 198, 214, 228, 241, 253, 9, 44, 81, 113, 142, 168, 192, 214, 235, 255, 7, 49, 90, 127, 160, 191, 220, 247, 6, 51, 95, 134, 170, 203, 234, 7, 47, 87, 123, 155, 184, 212, 237, 6, 52, 97, 137, 174, 208, 240, 5, 57, 106, 151, 192, 231, 5, 59, 111, 158, 202, 243, 5, 55, 103, 147, 187, 224, 5, 60, 113, 161, 206, 248, 4, 65, 122, 175, 224, 4, 67, 127, 182, 234, };
static const unsigned char cache_caps50[168] = {
-18, 18, 18, 18, 18, 18, 18, 18, 28, 28, 28, 28, 62, 62, 62, 90, 90, 116, 148, 141, 139, 18, 18, 18, 18, 18, 18, 18, 18, 38, 38, 38, 38, 67, 67, 67, 98, 98, 123, 156, 146, 144, 14, 14, 14, 14, 14, 14, 14, 14, 31, 31, 31, 31, 64, 64, 64, 92, 92, 118, 151, 144, 141, 19, 19, 19, 19, 19, 19, 19, 19, 33, 33, 33, 33, 67, 67, 67, 96, 96, 122, 155, 147, 143, 15, 15, 15, 15, 15, 15, 15, 15, 32, 32, 32, 32, 64, 64, 64, 92, 92, 118, 152, 145, 142, 16, 16, 16, 16, 16, 16, 16, 16, 33, 33, 33, 33, 66, 66, 66, 94, 94, 120, 153, 147, 143, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 64, 64, 64, 93, 93, 118, 152, 145, 142, 16, 16, 16, 16, 16, 16, 16, 16, 33, 33, 33, 33, 65, 65, 65, 94, 94, 119, 153, 146, 143, };
+224, 224, 224, 224, 224, 224, 224, 224, 160, 160, 160, 160, 185, 185, 185, 178, 178, 168, 134, 61, 37, 224, 224, 224, 224, 224, 224, 224, 224, 240, 240, 240, 240, 207, 207, 207, 198, 198, 183, 144, 66, 40, 160, 160, 160, 160, 160, 160, 160, 160, 185, 185, 185, 185, 193, 193, 193, 183, 183, 172, 138, 64, 38, 240, 240, 240, 240, 240, 240, 240, 240, 207, 207, 207, 207, 204, 204, 204, 193, 193, 180, 143, 66, 40, 185, 185, 185, 185, 185, 185, 185, 185, 193, 193, 193, 193, 193, 193, 193, 183, 183, 172, 138, 65, 39, 207, 207, 207, 207, 207, 207, 207, 207, 204, 204, 204, 204, 201, 201, 201, 188, 188, 176, 141, 66, 40, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 194, 194, 194, 184, 184, 173, 139, 65, 39, 204, 204, 204, 204, 204, 204, 204, 204, 201, 201, 201, 201, 198, 198, 198, 187, 187, 175, 140, 66, 40, };
#endif
#ifndef FFT_TWIDDLES48000_960
@@ -116,7 +116,7 @@
207, 42, 102, 162, 222, 57, 117, 177, 237, 3, 63, 123, 183, 18, 78, 138, 198, 33, 93, 153, 213, 48, 108, 168, 228, 8, 68, 128, 188, 23, 83, 143, 203, 38, 98, 158, 218, 53, 113, 173, 233, 13, 73, 133, 193, 28, 88, 148, 208, 43, 103, 163, 223, 58, 118, 178, 238, 4, 64, 124, 184, 19, 79, 139, 199, 34, 94, 154, 214, 49, 109, 169, 229, 9, 69, 129, 189, 24, 84, 144, 204, 39, 99, 159, 219, 54, 114, 174, 234, 14, 74, 134, 194, 29, 89, 149, 209, 44, 104, 164, 224, 59, 119, 179, 239, };
#endif
-108, 168, 228, 8, 68, 128, 188, 23, 83, 143, 203, 38, 98, 158, 218, 53, 113, 173, 233, 13, 73, 133, 193, 28, 88, 148, 208, 43, 103, 163, 223, 58, 118, 178, 238, 4, 64, 124, 184, 19, 79, 139, 199, 34, 94, 154, 214, 49, 109, 169, 229, 9, 69, 129, 189, 24, 84, 144, 204, 39, 99, 159, 219, 54, 114, 174, 234, 14, 74, 134, 194, 29, 89, 149, 209, 44, 104, 164, 224, 59, 119, 179, 239, };
+108, 168, 228, 8, 68, 128, 188, 23, 83, 143, 203, 38, 98, 158, 218, 53, 113, 173, 233, 13, 73, 133, 193, 28, 88, 148, 208, 43, 103, 163, 223, 58, 118, 178, 238, 4, 64, 124, 184, 19, 79, 139, 199, 34, 94, 154, 214, 49, 109, 169, 229, 9, 69, 129, 189, 24, 84, 144, 204, 39, 99, 159, 219, 54, 114, 174, 234, 14, 74, 134, 194, 29, 89, 149, 209, 44, 104, 164, 224, 59, 119, 179, 239, };
, 188, 23, 83, 143, 203, 38, 98, 158, 218, 53, 113, 173, 233, 13, 73, 133, 193, 28, 88, 148, 208, 43, 103, 163, 223, 58, 118, 178, 238, 4, 64, 124, 184, 19, 79, 139, 199, 34, 94, 154, 214, 49, 109, 169, 229, 9, 69, 129, 189, 24, 84, 144, 204, 39, 99, 159, 219, 54, 114, 174, 234, 14, 74, 134, 194, 29, 89, 149, 209, 44, 104, 164, 224, 59, 119, 179, 239, };
#endif