diff --git a/libcelt/bands.c b/libcelt/bands.c index ffa2f53b..2102dfda 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -637,6 +637,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c celt_int32 *remaining_bits, int LM, celt_norm *lowband_out, const celt_ener *bandE, int level, celt_uint32 *seed, celt_word16 gain, celt_norm *lowband_scratch, int fill) { + const unsigned char *cache; int q; int curr_bits; int stereo, split; @@ -739,8 +740,9 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c } } - /* If we need more than 32 bits, try splitting the band in two. */ - if (!stereo && LM != -1 && b > 32<2) + /* If we need 1 more bit than we can produce, split the band in two. */ + cache = m->cache.bits + m->cache.index[(LM+1)*m->nbEBands+i]; + if (!stereo && LM != -1 && b > cache[cache[0]]+9 && N>2) { if (LM>0 || (N&1)==0) { diff --git a/libcelt/rate.c b/libcelt/rate.c index 68845d27..22350130 100644 --- a/libcelt/rate.c +++ b/libcelt/rate.c @@ -172,19 +172,17 @@ void compute_pulse_cache(CELTMode *m, int LM) int qb; int k; LM0 = 0; - /* Even-sized bands bigger than N=4 can be split one more - time (N=4 also _can_ be split, but not without waste: the - result can only use 26 bits, but requires an allocation - of 32 to trigger the split). */ - if (N0 > 4 && !(N0&1)) + /* Even-sized bands bigger than N=2 can be split one more + time. */ + if (N0 > 2 && !(N0&1)) { N0>>=1; LM0--; } - /* N0=1 and N0=2 bands can't be split down to N=2. */ - else if (N0 <= 2) + /* N0=1 bands can't be split down to N<2. */ + else if (N0 <= 1) { - LM0=IMIN(i,3-N0); + LM0=IMIN(i,1); N0<<=LM0; } /* Compute the cost for the lowest-level PVQ of a fully split diff --git a/libcelt/static_modes_fixed.c b/libcelt/static_modes_fixed.c index ef189e1d..553b1e21 100644 --- a/libcelt/static_modes_fixed.c +++ b/libcelt/static_modes_fixed.c @@ -22,7 +22,7 @@ static const celt_int16 cache_index50[105] = { 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, 55, 55, 55, 90, 90, 116, 148, 141, 139, 18, 18, 18, 18, 18, 18, 18, 18, 38, 38, 38, 38, 62, 62, 62, 98, 98, 123, 156, 146, 144, 14, 14, 14, 14, 14, 14, 14, 14, 27, 27, 27, 27, 58, 58, 58, 92, 92, 118, 151, 144, 141, 19, 19, 19, 19, 19, 19, 19, 19, 31, 31, 31, 31, 61, 61, 61, 96, 96, 122, 155, 147, 143, 13, 13, 13, 13, 13, 13, 13, 13, 29, 29, 29, 29, 59, 59, 59, 92, 92, 118, 152, 145, 142, 15, 15, 15, 15, 15, 15, 15, 15, 30, 30, 30, 30, 61, 61, 61, 94, 94, 120, 153, 147, 143, 14, 14, 14, 14, 14, 14, 14, 14, 29, 29, 29, 29, 59, 59, 59, 93, 93, 118, 152, 145, 142, 15, 15, 15, 15, 15, 15, 15, 15, 30, 30, 30, 30, 60, 60, 60, 94, 94, 119, 153, 146, 143, }; +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, }; #endif #ifndef FFT_TWIDDLES48000_960 diff --git a/libcelt/static_modes_float.c b/libcelt/static_modes_float.c index 9747aa5e..b550a86d 100644 --- a/libcelt/static_modes_float.c +++ b/libcelt/static_modes_float.c @@ -22,7 +22,7 @@ static const celt_int16 cache_index50[105] = { 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, 55, 55, 55, 90, 90, 116, 148, 141, 139, 18, 18, 18, 18, 18, 18, 18, 18, 38, 38, 38, 38, 62, 62, 62, 98, 98, 123, 156, 146, 144, 14, 14, 14, 14, 14, 14, 14, 14, 27, 27, 27, 27, 58, 58, 58, 92, 92, 118, 151, 144, 141, 19, 19, 19, 19, 19, 19, 19, 19, 31, 31, 31, 31, 61, 61, 61, 96, 96, 122, 155, 147, 143, 13, 13, 13, 13, 13, 13, 13, 13, 29, 29, 29, 29, 59, 59, 59, 92, 92, 118, 152, 145, 142, 15, 15, 15, 15, 15, 15, 15, 15, 30, 30, 30, 30, 61, 61, 61, 94, 94, 120, 153, 147, 143, 14, 14, 14, 14, 14, 14, 14, 14, 29, 29, 29, 29, 59, 59, 59, 93, 93, 118, 152, 145, 142, 15, 15, 15, 15, 15, 15, 15, 15, 30, 30, 30, 30, 60, 60, 60, 94, 94, 119, 153, 146, 143, }; +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, }; #endif #ifndef FFT_TWIDDLES48000_960