diff mbox series

[FFmpeg-devel,071/114] avcodec/atrac3plus: Make tables used to initialize VLCs smaller

Message ID 20201110104851.321029-72-andreas.rheinhardt@gmail.com
State Superseded
Headers show
Series VLC, esp. init_vlc patches | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 10, 2020, 10:48 a.m. UTC
The ATRAC3+ decoder currently uses ff_init_vlc_sparse() to initialize
several VLCs; sometimes a symbols table is used, sometimes not; some of
the codes tables are uint16_t, some are uint8_t. Because of these two
latter facts it makes sense to switch to ff_init_vlc_from_lengths()
because it allows to remove the codes at the cost of adding symbols
tables of type uint8_t in the cases where there were none before.

Notice that sometimes the same codes and lengths tables were reused with
two different symbols tables; this could have been preserved (meaning
one could use a lengths table twice), but hasn't, because this allows
to use only one pointer to both the symbols and lengths instead of two
pointers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/atrac3plus.c      |  72 ++++-------
 libavcodec/atrac3plus_data.h | 226 ++++++++++++++++-------------------
 2 files changed, 124 insertions(+), 174 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/atrac3plus.c b/libavcodec/atrac3plus.c
index 8ae5d6b8f9..955c9901a1 100644
--- a/libavcodec/atrac3plus.c
+++ b/libavcodec/atrac3plus.c
@@ -79,47 +79,24 @@  av_cold void ff_atrac3p_init_vlcs(void)
 
     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_bits[4] = {
-        atrac3p_wl_huff_bits1, atrac3p_wl_huff_bits2,
-        atrac3p_wl_huff_bits3, atrac3p_wl_huff_bits4
-    };
-    static const uint8_t * const wl_codes[4] = {
-        atrac3p_wl_huff_code1, atrac3p_wl_huff_code2,
-        atrac3p_wl_huff_code3, atrac3p_wl_huff_code4
-    };
-    static const uint8_t * const wl_xlats[4] = {
-        atrac3p_wl_huff_xlat1, atrac3p_wl_huff_xlat2, NULL, NULL
+    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_bits[4]  = {
-        atrac3p_ct_huff_bits1, atrac3p_ct_huff_bits2,
-        atrac3p_ct_huff_bits2, atrac3p_ct_huff_bits3
-    };
-    static const uint8_t * const ct_codes[4] = {
-        atrac3p_ct_huff_code1, atrac3p_ct_huff_code2,
-        atrac3p_ct_huff_code2, atrac3p_ct_huff_code3
-    };
-    static const uint8_t * const ct_xlats[4] = {
-        NULL, NULL, atrac3p_ct_huff_xlat1, NULL
+    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, 16, 16, 16, 16 };
-    static const uint8_t  * const sf_bits[8]  = {
-        atrac3p_sf_huff_bits1, atrac3p_sf_huff_bits1, atrac3p_sf_huff_bits2,
-        atrac3p_sf_huff_bits3, atrac3p_sf_huff_bits4, atrac3p_sf_huff_bits4,
-        atrac3p_sf_huff_bits5, atrac3p_sf_huff_bits6
-    };
-    static const uint16_t * const sf_codes[8] = {
-        atrac3p_sf_huff_code1, atrac3p_sf_huff_code1, atrac3p_sf_huff_code2,
-        atrac3p_sf_huff_code3, atrac3p_sf_huff_code4, atrac3p_sf_huff_code4,
-        atrac3p_sf_huff_code5, atrac3p_sf_huff_code6
-    };
-    static const uint8_t  * const sf_xlats[8] = {
-        atrac3p_sf_huff_xlat1, atrac3p_sf_huff_xlat2, NULL, NULL,
-        atrac3p_sf_huff_xlat4, atrac3p_sf_huff_xlat5, NULL, NULL
+    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
     };
 
     static const uint8_t * const gain_cbs[11] = {
@@ -156,17 +133,15 @@  av_cold void ff_atrac3p_init_vlcs(void)
         ct_vlc_tabs[i].table = &tables_data[ct_vlc_offs];
         ct_vlc_tabs[i].table_allocated = 1 << ct_nb_bits[i];
 
-        ff_init_vlc_sparse(&wl_vlc_tabs[i], wl_nb_bits[i], wl_nb_codes[i],
-                           wl_bits[i],  1, 1,
-                           wl_codes[i], 1, 1,
-                           wl_xlats[i], 1, 1,
-                           INIT_VLC_USE_NEW_STATIC);
+        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);
 
-        ff_init_vlc_sparse(&ct_vlc_tabs[i], ct_nb_bits[i], ct_nb_codes[i],
-                           ct_bits[i],  1, 1,
-                           ct_codes[i], 1, 1,
-                           ct_xlats[i], 1, 1,
-                           INIT_VLC_USE_NEW_STATIC);
+        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);
 
         wl_vlc_offs += wl_vlc_tabs[i].table_allocated;
         ct_vlc_offs += ct_vlc_tabs[i].table_allocated;
@@ -176,11 +151,10 @@  av_cold void ff_atrac3p_init_vlcs(void)
         sf_vlc_tabs[i].table = &tables_data[sf_vlc_offs];
         sf_vlc_tabs[i].table_allocated = 1 << sf_nb_bits[i];
 
-        ff_init_vlc_sparse(&sf_vlc_tabs[i], sf_nb_bits[i], sf_nb_codes[i],
-                           sf_bits[i],  1, 1,
-                           sf_codes[i], 2, 2,
-                           sf_xlats[i], 1, 1,
-                           INIT_VLC_USE_NEW_STATIC);
+        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);
         sf_vlc_offs += sf_vlc_tabs[i].table_allocated;
     }
 
diff --git a/libavcodec/atrac3plus_data.h b/libavcodec/atrac3plus_data.h
index 2a107eef1f..418735abc5 100644
--- a/libavcodec/atrac3plus_data.h
+++ b/libavcodec/atrac3plus_data.h
@@ -27,149 +27,125 @@ 
 #include <stdint.h>
 
 /** VLC tables for wordlen */
-static const uint8_t atrac3p_wl_huff_code1[3] = { 0, 2, 3 };
-
-static const uint8_t atrac3p_wl_huff_bits1[3] = { 1, 2, 2 };
-
-static const uint8_t atrac3p_wl_huff_xlat1[3] = { 0, 1, 7 };
-
-static const uint8_t atrac3p_wl_huff_code2[5] = { 0, 4, 5, 6, 7 };
-
-static const uint8_t atrac3p_wl_huff_bits2[5] = { 1, 3, 3, 3, 3 };
-
-static const uint8_t atrac3p_wl_huff_xlat2[5] = { 0, 1, 2, 6, 7 };
-
-static const uint8_t atrac3p_wl_huff_code3[8] = {
-    0, 4, 0xC, 0x1E, 0x1F, 0xD, 0xE, 5
-};
-
-static const uint8_t atrac3p_wl_huff_bits3[8] = { 1, 3, 4, 5, 5, 4, 4, 3 };
-
-static const uint8_t atrac3p_wl_huff_code4[8] = {
-    0, 4, 0xC, 0xD, 0x1E, 0x1F, 0xE, 5
-};
-
-static const uint8_t atrac3p_wl_huff_bits4[8] = { 1, 3, 4, 4, 5, 5, 4, 3 };
-
-/** VLC tables for scale factor indexes */
-static const uint16_t atrac3p_sf_huff_code1[64] = {
-        0,     2,     3,     4,     5,   0xC,   0xD,  0xE0,
-     0xE1,  0xE2,  0xE3,  0xE4,  0xE5,  0xE6, 0x1CE, 0x1CF,
-    0x1D0, 0x1D1, 0x1D2, 0x1D3, 0x1D4, 0x1D5, 0x1D6, 0x1D7,
-    0x1D8, 0x1D9, 0x1DA, 0x1DB, 0x1DC, 0x1DD, 0x1DE, 0x1DF,
-    0x1E0, 0x1E1, 0x1E2, 0x1E3, 0x1E4, 0x1E5, 0x1E6, 0x1E7,
-    0x1E8, 0x1E9, 0x1EA, 0x1EB, 0x1EC, 0x1ED, 0x1EE, 0x1EF,
-    0x1F0, 0x1F1, 0x1F2, 0x1F3, 0x1F4, 0x1F5, 0x1F6, 0x1F7,
-    0x1F8, 0x1F9, 0x1FA, 0x1FB, 0x1FC, 0x1FD, 0x1FE, 0x1FF
-};
-
-static const uint8_t atrac3p_sf_huff_bits1[64] = {
-    2, 3, 3, 3, 3, 4, 4, 8, 8, 8, 8, 8, 8, 8, 9, 9,
-    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9
-};
-
-static const uint8_t atrac3p_sf_huff_xlat1[64] = {
-     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
-};
-
-static const uint8_t atrac3p_sf_huff_xlat2[64] = {
-    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
+static const uint8_t atrac3p_wl_huff1[3][2] = {
+    { 0, 1 }, { 1, 2 }, { 7, 2 },
 };
 
-static const uint16_t atrac3p_sf_huff_code2[64] = {
-        0,     4,  0x18,  0x19,  0x70, 0x1CA, 0x1CB, 0x1CC,
-    0x1CD, 0x1CE, 0x1CF, 0x1D0, 0x1D1, 0x1D2, 0x1D3, 0x1D4,
-    0x1D5, 0x1D6, 0x1D7, 0x1D8, 0x1D9, 0x1DA, 0x1DB, 0x1DC,
-    0x1DD, 0x1DE, 0x1DF, 0x1E0, 0x1E1, 0x1E2, 0x1E3, 0x1E4,
-    0x1E5, 0x1E6, 0x1E7, 0x1E8, 0x1E9, 0x1EA, 0x1EB, 0x1EC,
-    0x1ED, 0x1EE, 0x1EF, 0x1F0, 0x1F1, 0x1F2, 0x1F3, 0x1F4,
-    0x1F5, 0x1F6, 0x1F7, 0x1F8, 0x1F9, 0x1FA, 0x1FB, 0x1FC,
-    0x1FD, 0x1FE, 0x1FF,  0xE4,  0x71,  0x1A,  0x1B,     5
+static const uint8_t atrac3p_wl_huff2[5][2] = {
+    { 0, 1 }, { 1, 3 }, { 2, 3 }, { 6, 3 }, { 7, 3 },
 };
 
-static const uint8_t atrac3p_sf_huff_bits2[64] = {
-    1, 3, 5, 5, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 7, 5, 5, 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 uint16_t atrac3p_sf_huff_code3[64] = {
-        0,     2,     3,  0x18,  0x19,  0x70, 0x1CC, 0x1CD,
-    0x1CE, 0x1CF, 0x1D0, 0x1D1, 0x1D2, 0x1D3, 0x1D4, 0x1D5,
-    0x1D6, 0x1D7, 0x1D8, 0x1D9, 0x1DA, 0x1DB, 0x1DC, 0x1DD,
-    0x1DE, 0x1DF, 0x1E0, 0x1E1, 0x1E2, 0x1E3, 0x1E4, 0x1E5,
-    0x1E6, 0x1E7, 0x1E8, 0x1E9, 0x1EA, 0x1EB, 0x1EC, 0x1ED,
-    0x1EE, 0x1EF, 0x1F0, 0x1F1, 0x1F2, 0x1F3, 0x1F4, 0x1F5,
-    0x1F6, 0x1F7, 0x1F8, 0x1F9, 0x1FA, 0x1FB, 0x1FC, 0x1FD,
-    0x1FE, 0x1FF,  0x71,  0x72,  0x1A,  0x1B,     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 },
 };
 
-static const uint8_t atrac3p_sf_huff_bits3[64] = {
-    2, 3, 3, 5, 5, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
-    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 5, 5, 3, 3
-};
-
-static const uint16_t atrac3p_sf_huff_code4[16] = {
-    0, 2, 3, 4, 5, 0xC, 0xD, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0, 0x3D, 0x3E, 0x3F
-};
-
-static const uint8_t atrac3p_sf_huff_bits4[16] = {
-    2, 3, 3, 3, 3, 4, 4, 6, 6, 6, 6, 6, 0, 6, 6, 6
-};
-
-static const uint8_t atrac3p_sf_huff_xlat4[16] = {
-    0, 1, 13, 14, 15, 2, 12, 3, 4, 5, 6, 7, 8, 9, 10, 11
-};
-
-static const uint8_t atrac3p_sf_huff_xlat5[16] = {
-    0, 1, 2, 14, 15, 3, 13, 4, 5, 6, 7, 9, 8, 10, 11, 12
-};
-
-static const uint16_t atrac3p_sf_huff_code5[16] = {
-    0,    4,  0xC, 0x1C, 0x78, 0x79, 0x7A, 0x7B,
-    0, 0x7C, 0x7D, 0x7E, 0x7F, 0x1D, 0xD,     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_sf_huff_bits5[16] = {
-    1, 3, 4, 5, 7, 7, 7, 7, 0, 7, 7, 7, 7, 5, 4, 3
+/** VLC tables for code table indexes */
+static const uint8_t atrac3p_ct_huff1[4][2] = {
+    { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 3 },
 };
 
-static const uint16_t atrac3p_sf_huff_code6[16] = {
-    0, 2, 3, 0xC, 0x1C, 0x3C, 0x7C, 0x7D, 0, 0x7E, 0x7F, 0x3D, 0x1D, 0xD, 4, 5
+static const uint8_t atrac3p_ct_huff2[8][2] = {
+    { 0, 2 }, { 1, 3 }, { 2, 3 }, { 3, 3 }, { 4, 3 }, { 5, 3 }, { 6, 4 },
+    { 7, 4 },
 };
 
-static const uint8_t atrac3p_sf_huff_bits6[16] = {
-    2, 3, 3, 4, 5, 6, 7, 7, 0, 7, 7, 6, 5, 4, 3, 3
+static const uint8_t atrac3p_ct_huff3[8][2] = {
+    { 0, 2 }, { 1, 3 }, { 2, 3 }, { 3, 3 }, { 6, 3 }, { 7, 3 }, { 4, 4 },
+    { 5, 4 },
 };
 
-/** VLC tables for code table indexes */
-static const uint8_t atrac3p_ct_huff_code1[4] = { 0, 2, 6, 7 };
-
-static const uint8_t atrac3p_ct_huff_bits1[4] = { 1, 2, 3, 3 };
-
-static const uint8_t atrac3p_ct_huff_code2[8] = { 0, 2, 3, 4, 5, 6, 0xE, 0xF };
-
-static const uint8_t atrac3p_ct_huff_bits2[8] = { 2, 3, 3, 3, 3, 3, 4, 4 };
-
-static const uint8_t atrac3p_ct_huff_xlat1[8] = { 0, 1, 2, 3, 6, 7, 4, 5 };
-
-static const uint8_t atrac3p_ct_huff_code3[8] = {
-    0, 4, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF
+static const uint8_t atrac3p_ct_huff4[8][2] = {
+    { 0, 1 }, { 1, 3 }, { 2, 4 }, { 3, 4 }, { 4, 4 }, { 5, 4 }, { 6, 4 },
+    { 7, 4 },
 };
 
-static const uint8_t atrac3p_ct_huff_bits3[8] = { 1, 3, 4, 4, 4, 4, 4, 4 };
-
 /* weights for quantized word lengths */
 static const int8_t atrac3p_wl_weights[6][32] = {
     { 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0,