mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avcodec/atrac3plus: Run-length encode length tables to make them smaller
This is very beneficial for the scale factor tables where 4*64+4*15 bytes of length information can be replaced by eight codebooks of 12 bytes each; furthermore the number of codes as well as the maximum length of a code can be easily derived from said codebooks, making tables containing said information superfluous. This and combining the symbols into one big array also made an array of pointers to the tables redundant. For the wordlen and code table tables the benefits are not that big (given these tables don't contain that many elements), but all in all using codebooks is also advantageouos for them. Therefore it has been done. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
parent
a7dbeb77c3
commit
58fc810d42
@ -78,55 +78,18 @@ av_cold void ff_atrac3p_init_vlcs(void)
|
||||
int i, tab_offset = 0;
|
||||
const uint8_t *xlats;
|
||||
|
||||
static const uint8_t wl_nb_bits[4] = { 2, 3, 5, 5 };
|
||||
static const uint8_t wl_nb_codes[4] = { 3, 5, 8, 8 };
|
||||
static const uint8_t (*const wl_huffs[4])[2] = {
|
||||
atrac3p_wl_huff1, atrac3p_wl_huff2,
|
||||
atrac3p_wl_huff3, atrac3p_wl_huff4
|
||||
};
|
||||
|
||||
static const uint8_t ct_nb_bits[4] = { 3, 4, 4, 4 };
|
||||
static const uint8_t ct_nb_codes[4] = { 4, 8, 8, 8 };
|
||||
static const uint8_t (*const ct_huffs[4])[2] = {
|
||||
atrac3p_ct_huff1, atrac3p_ct_huff2,
|
||||
atrac3p_ct_huff3, atrac3p_ct_huff4
|
||||
};
|
||||
|
||||
static const uint8_t sf_nb_bits[8] = { 9, 9, 9, 9, 6, 6, 7, 7 };
|
||||
static const uint8_t sf_nb_codes[8] = { 64, 64, 64, 64, 15, 15, 15, 15 };
|
||||
static const uint8_t (*const sf_huffs[8])[2] = {
|
||||
atrac3p_sf_huff1, atrac3p_sf_huff2, atrac3p_sf_huff3,
|
||||
atrac3p_sf_huff4, atrac3p_sf_huff5, atrac3p_sf_huff6,
|
||||
atrac3p_sf_huff7, atrac3p_sf_huff8
|
||||
};
|
||||
|
||||
xlats = atrac3p_wl_ct_xlats;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
wl_vlc_tabs[i].table = &tables_data[tab_offset];
|
||||
wl_vlc_tabs[i].table_allocated = 1 << wl_nb_bits[i];
|
||||
tab_offset += 1 << wl_nb_bits[i];
|
||||
ff_init_vlc_from_lengths(&wl_vlc_tabs[i], wl_nb_bits[i], wl_nb_codes[i],
|
||||
&wl_huffs[i][0][1], 2,
|
||||
&wl_huffs[i][0][0], 2, 1,
|
||||
0, INIT_VLC_USE_NEW_STATIC, NULL);
|
||||
|
||||
ct_vlc_tabs[i].table = &tables_data[tab_offset];
|
||||
ct_vlc_tabs[i].table_allocated = 1 << ct_nb_bits[i];
|
||||
tab_offset += 1 << ct_nb_bits[i];
|
||||
ff_init_vlc_from_lengths(&ct_vlc_tabs[i], ct_nb_bits[i], ct_nb_codes[i],
|
||||
&ct_huffs[i][0][1], 2,
|
||||
&ct_huffs[i][0][0], 2, 1,
|
||||
0, INIT_VLC_USE_NEW_STATIC, NULL);
|
||||
build_canonical_huff(atrac3p_wl_cbs[i], &xlats,
|
||||
&tab_offset, &wl_vlc_tabs[i]);
|
||||
build_canonical_huff(atrac3p_ct_cbs[i], &xlats,
|
||||
&tab_offset, &ct_vlc_tabs[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
sf_vlc_tabs[i].table = &tables_data[tab_offset];
|
||||
sf_vlc_tabs[i].table_allocated = 1 << sf_nb_bits[i];
|
||||
tab_offset += 1 << sf_nb_bits[i];
|
||||
ff_init_vlc_from_lengths(&sf_vlc_tabs[i], sf_nb_bits[i], sf_nb_codes[i],
|
||||
&sf_huffs[i][0][1], 2,
|
||||
&sf_huffs[i][0][0], 2, 1,
|
||||
0, INIT_VLC_USE_NEW_STATIC, NULL);
|
||||
}
|
||||
xlats = atrac3p_sf_xlats;
|
||||
for (int i = 0; i < 8; i++)
|
||||
build_canonical_huff(atrac3p_sf_cbs[i], &xlats,
|
||||
&tab_offset, &sf_vlc_tabs[i]);
|
||||
|
||||
/* build huffman tables for spectrum decoding */
|
||||
xlats = atrac3p_spectra_xlats;
|
||||
|
@ -27,106 +27,83 @@
|
||||
#include <stdint.h>
|
||||
|
||||
/** VLC tables for wordlen */
|
||||
static const uint8_t atrac3p_wl_huff1[3][2] = {
|
||||
{ 0, 1 }, { 1, 2 }, { 7, 2 },
|
||||
};
|
||||
|
||||
static const uint8_t atrac3p_wl_huff2[5][2] = {
|
||||
{ 0, 1 }, { 1, 3 }, { 2, 3 }, { 6, 3 }, { 7, 3 },
|
||||
};
|
||||
|
||||
static const uint8_t atrac3p_wl_huff3[8][2] = {
|
||||
{ 0, 1 }, { 1, 3 }, { 7, 3 }, { 2, 4 }, { 5, 4 }, { 6, 4 }, { 3, 5 },
|
||||
{ 4, 5 },
|
||||
};
|
||||
|
||||
static const uint8_t atrac3p_wl_huff4[8][2] = {
|
||||
{ 0, 1 }, { 1, 3 }, { 7, 3 }, { 2, 4 }, { 3, 4 }, { 6, 4 }, { 4, 5 },
|
||||
{ 5, 5 },
|
||||
};
|
||||
|
||||
/** VLC tables for scale factor indexes */
|
||||
static const uint8_t atrac3p_sf_huff1[64][2] = {
|
||||
{ 0, 2 }, { 1, 3 }, { 61, 3 }, { 62, 3 }, { 63, 3 }, { 2, 4 },
|
||||
{ 60, 4 }, { 3, 8 }, { 4, 8 }, { 5, 8 }, { 6, 8 }, { 57, 8 },
|
||||
{ 58, 8 }, { 59, 8 }, { 7, 9 }, { 8, 9 }, { 9, 9 }, { 10, 9 },
|
||||
{ 11, 9 }, { 12, 9 }, { 13, 9 }, { 14, 9 }, { 15, 9 }, { 16, 9 },
|
||||
{ 17, 9 }, { 18, 9 }, { 19, 9 }, { 20, 9 }, { 21, 9 }, { 22, 9 },
|
||||
{ 23, 9 }, { 24, 9 }, { 25, 9 }, { 26, 9 }, { 27, 9 }, { 28, 9 },
|
||||
{ 29, 9 }, { 30, 9 }, { 31, 9 }, { 32, 9 }, { 33, 9 }, { 34, 9 },
|
||||
{ 35, 9 }, { 36, 9 }, { 37, 9 }, { 38, 9 }, { 39, 9 }, { 40, 9 },
|
||||
{ 41, 9 }, { 42, 9 }, { 43, 9 }, { 44, 9 }, { 45, 9 }, { 46, 9 },
|
||||
{ 47, 9 }, { 48, 9 }, { 49, 9 }, { 50, 9 }, { 51, 9 }, { 52, 9 },
|
||||
{ 53, 9 }, { 54, 9 }, { 55, 9 }, { 56, 9 },
|
||||
};
|
||||
|
||||
static const uint8_t atrac3p_sf_huff2[64][2] = {
|
||||
{ 0, 2 }, { 1, 3 }, { 2, 3 }, { 62, 3 }, { 63, 3 }, { 3, 4 },
|
||||
{ 61, 4 }, { 4, 8 }, { 5, 8 }, { 6, 8 }, { 57, 8 }, { 58, 8 },
|
||||
{ 59, 8 }, { 60, 8 }, { 7, 9 }, { 8, 9 }, { 9, 9 }, { 10, 9 },
|
||||
{ 11, 9 }, { 12, 9 }, { 13, 9 }, { 14, 9 }, { 15, 9 }, { 16, 9 },
|
||||
{ 17, 9 }, { 18, 9 }, { 19, 9 }, { 20, 9 }, { 21, 9 }, { 22, 9 },
|
||||
{ 23, 9 }, { 24, 9 }, { 25, 9 }, { 26, 9 }, { 27, 9 }, { 28, 9 },
|
||||
{ 29, 9 }, { 30, 9 }, { 31, 9 }, { 32, 9 }, { 33, 9 }, { 34, 9 },
|
||||
{ 35, 9 }, { 36, 9 }, { 37, 9 }, { 38, 9 }, { 39, 9 }, { 40, 9 },
|
||||
{ 41, 9 }, { 42, 9 }, { 43, 9 }, { 44, 9 }, { 45, 9 }, { 46, 9 },
|
||||
{ 47, 9 }, { 48, 9 }, { 49, 9 }, { 50, 9 }, { 51, 9 }, { 52, 9 },
|
||||
{ 53, 9 }, { 54, 9 }, { 55, 9 }, { 56, 9 },
|
||||
};
|
||||
|
||||
static const uint8_t atrac3p_sf_huff3[64][2] = {
|
||||
{ 0, 1 }, { 1, 3 }, { 63, 3 }, { 2, 5 }, { 3, 5 }, { 61, 5 },
|
||||
{ 62, 5 }, { 4, 7 }, { 60, 7 }, { 59, 8 }, { 5, 9 }, { 6, 9 },
|
||||
{ 7, 9 }, { 8, 9 }, { 9, 9 }, { 10, 9 }, { 11, 9 }, { 12, 9 },
|
||||
{ 13, 9 }, { 14, 9 }, { 15, 9 }, { 16, 9 }, { 17, 9 }, { 18, 9 },
|
||||
{ 19, 9 }, { 20, 9 }, { 21, 9 }, { 22, 9 }, { 23, 9 }, { 24, 9 },
|
||||
{ 25, 9 }, { 26, 9 }, { 27, 9 }, { 28, 9 }, { 29, 9 }, { 30, 9 },
|
||||
{ 31, 9 }, { 32, 9 }, { 33, 9 }, { 34, 9 }, { 35, 9 }, { 36, 9 },
|
||||
{ 37, 9 }, { 38, 9 }, { 39, 9 }, { 40, 9 }, { 41, 9 }, { 42, 9 },
|
||||
{ 43, 9 }, { 44, 9 }, { 45, 9 }, { 46, 9 }, { 47, 9 }, { 48, 9 },
|
||||
{ 49, 9 }, { 50, 9 }, { 51, 9 }, { 52, 9 }, { 53, 9 }, { 54, 9 },
|
||||
{ 55, 9 }, { 56, 9 }, { 57, 9 }, { 58, 9 },
|
||||
};
|
||||
|
||||
static const uint8_t atrac3p_sf_huff4[64][2] = {
|
||||
{ 0, 2 }, { 1, 3 }, { 2, 3 }, { 62, 3 }, { 63, 3 }, { 3, 5 },
|
||||
{ 4, 5 }, { 60, 5 }, { 61, 5 }, { 5, 7 }, { 58, 7 }, { 59, 7 },
|
||||
{ 6, 9 }, { 7, 9 }, { 8, 9 }, { 9, 9 }, { 10, 9 }, { 11, 9 },
|
||||
{ 12, 9 }, { 13, 9 }, { 14, 9 }, { 15, 9 }, { 16, 9 }, { 17, 9 },
|
||||
{ 18, 9 }, { 19, 9 }, { 20, 9 }, { 21, 9 }, { 22, 9 }, { 23, 9 },
|
||||
{ 24, 9 }, { 25, 9 }, { 26, 9 }, { 27, 9 }, { 28, 9 }, { 29, 9 },
|
||||
{ 30, 9 }, { 31, 9 }, { 32, 9 }, { 33, 9 }, { 34, 9 }, { 35, 9 },
|
||||
{ 36, 9 }, { 37, 9 }, { 38, 9 }, { 39, 9 }, { 40, 9 }, { 41, 9 },
|
||||
{ 42, 9 }, { 43, 9 }, { 44, 9 }, { 45, 9 }, { 46, 9 }, { 47, 9 },
|
||||
{ 48, 9 }, { 49, 9 }, { 50, 9 }, { 51, 9 }, { 52, 9 }, { 53, 9 },
|
||||
{ 54, 9 }, { 55, 9 }, { 56, 9 }, { 57, 9 },
|
||||
};
|
||||
|
||||
static const uint8_t atrac3p_sf_huff5[15][2] = {
|
||||
{ 0, 2 }, { 1, 3 }, { 13, 3 }, { 14, 3 }, { 15, 3 }, { 2, 4 },
|
||||
{ 12, 4 }, { 3, 6 }, { 4, 6 }, { 5, 6 }, { 6, 6 }, { 7, 6 },
|
||||
{ 9, 6 }, { 10, 6 }, { 11, 6 },
|
||||
};
|
||||
|
||||
static const uint8_t atrac3p_sf_huff6[15][2] = {
|
||||
{ 0, 2 }, { 1, 3 }, { 2, 3 }, { 14, 3 }, { 15, 3 }, { 3, 4 },
|
||||
{ 13, 4 }, { 4, 6 }, { 5, 6 }, { 6, 6 }, { 7, 6 }, { 9, 6 },
|
||||
{ 10, 6 }, { 11, 6 }, { 12, 6 },
|
||||
};
|
||||
|
||||
static const uint8_t atrac3p_sf_huff7[15][2] = {
|
||||
{ 0, 1 }, { 1, 3 }, { 15, 3 }, { 2, 4 }, { 14, 4 }, { 3, 5 },
|
||||
{ 13, 5 }, { 4, 7 }, { 5, 7 }, { 6, 7 }, { 7, 7 }, { 9, 7 },
|
||||
{ 10, 7 }, { 11, 7 }, { 12, 7 },
|
||||
};
|
||||
|
||||
static const uint8_t atrac3p_sf_huff8[15][2] = {
|
||||
{ 0, 2 }, { 1, 3 }, { 2, 3 }, { 14, 3 }, { 15, 3 }, { 3, 4 },
|
||||
{ 13, 4 }, { 4, 5 }, { 12, 5 }, { 5, 6 }, { 11, 6 }, { 6, 7 },
|
||||
{ 7, 7 }, { 9, 7 }, { 10, 7 },
|
||||
static const uint8_t atrac3p_wl_cbs[][12] = {
|
||||
{ 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 1, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 1, 0, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 1, 0, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
/** VLC tables for code table indexes */
|
||||
static const uint8_t atrac3p_ct_cbs[][12] = {
|
||||
{ 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 0, 1, 5, 2, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 0, 1, 5, 2, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 1, 0, 1, 6, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
/* Symbols for wordlen interleaved with symbols for code table */
|
||||
static const uint8_t atrac3p_wl_ct_xlats[] = {
|
||||
/* wordlen table 1 - 3 entries */
|
||||
0, 1, 7,
|
||||
/* code table 1 - 4 entries */
|
||||
0, 1, 2, 3,
|
||||
/* wordlen table 2 - 5 entries */
|
||||
0, 1, 2, 6, 7,
|
||||
/* code table 2 - 8 entries */
|
||||
0, 1, 2, 3, 4, 5, 6, 7,
|
||||
/* wordlen table 3 - 8 entries */
|
||||
0, 1, 7, 2, 5, 6, 3, 4,
|
||||
/* code table 3 - 8 entries */
|
||||
0, 1, 2, 3, 6, 7, 4, 5,
|
||||
/* wordlen table 4 - 8 entries */
|
||||
0, 1, 7, 2, 3, 6, 4, 5,
|
||||
/* code table 4 - 8 entries */
|
||||
0, 1, 2, 3, 4, 5, 6, 7,
|
||||
};
|
||||
|
||||
/** VLC tables for scale factor indexes */
|
||||
static const uint8_t atrac3p_sf_cbs[][12] = {
|
||||
{ 0, 1, 4, 2, 0, 0, 0, 7, 50, 0, 0, 0 },
|
||||
{ 0, 1, 4, 2, 0, 0, 0, 7, 50, 0, 0, 0 },
|
||||
{ 1, 0, 2, 0, 4, 0, 2, 1, 54, 0, 0, 0 },
|
||||
{ 0, 1, 4, 0, 4, 0, 3, 0, 52, 0, 0, 0 },
|
||||
{ 0, 1, 4, 2, 0, 8, 0, 0, 0, 0, 0, 0 },
|
||||
{ 0, 1, 4, 2, 0, 8, 0, 0, 0, 0, 0, 0 },
|
||||
{ 1, 0, 2, 2, 2, 0, 8, 0, 0, 0, 0, 0 },
|
||||
{ 0, 1, 4, 2, 2, 2, 4, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
static const uint8_t atrac3p_sf_xlats[] = {
|
||||
/* Scale factor index 1 - 64 entries */
|
||||
0, 1, 61, 62, 63, 2, 60, 3, 4, 5, 6, 57, 58, 59, 7, 8,
|
||||
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
||||
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
|
||||
/* Scale factor index 2 - 64 entries */
|
||||
0, 1, 2, 62, 63, 3, 61, 4, 5, 6, 57, 58, 59, 60, 7, 8,
|
||||
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
||||
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
|
||||
/* Scale factor index 3 - 64 entries */
|
||||
0, 1, 63, 2, 3, 61, 62, 4, 60, 59, 5, 6, 7, 8, 9, 10,
|
||||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
|
||||
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
|
||||
43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
|
||||
/* Scale factor index 4 - 64 entries */
|
||||
0, 1, 2, 62, 63, 3, 4, 60, 61, 5, 58, 59, 6, 7, 8, 9,
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
|
||||
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
|
||||
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
|
||||
/* Scale factor index 5 - 15 entries */
|
||||
0, 1, 13, 14, 15, 2, 12, 3, 4, 5, 6, 7, 9, 10, 11,
|
||||
/* Scale factor index 6 - 15 entries */
|
||||
0, 1, 2, 14, 15, 3, 13, 4, 5, 6, 7, 9, 10, 11, 12,
|
||||
/* Scale factor index 7 - 15 entries */
|
||||
0, 1, 15, 2, 14, 3, 13, 4, 5, 6, 7, 9, 10, 11, 12,
|
||||
/* Scale factor index 8 - 15 entries */
|
||||
0, 1, 2, 14, 15, 3, 13, 4, 12, 5, 11, 6, 7, 9, 10,
|
||||
};
|
||||
|
||||
static const uint8_t atrac3p_ct_huff1[4][2] = {
|
||||
{ 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 3 },
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user