From patchwork Fri Nov 20 07:20:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23844 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id D576B448F87 for ; Fri, 20 Nov 2020 09:41:04 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EC34F68BC6F; Fri, 20 Nov 2020 09:26:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6E0D06879A0 for ; Fri, 20 Nov 2020 09:25:42 +0200 (EET) Received: by mail-ej1-f65.google.com with SMTP id s25so11498588ejy.6 for ; Thu, 19 Nov 2020 23:25:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=RS8wcS/G5VWyrUOXTcTyiXhAxCMybP5N6fx0qvCe1DM=; b=CS6vnDsrE9g4c7ePizr4NUamHjX3kRz24LN+S+dycTihFVNtpKHf0vl84F1kO5/8Yf fGnERwon+Zx00F8fx03hdaZFBnItbPVcr/B3A/QEzv97ST2KuXV8yL6DBvFpgIMP29gU ZzqEXn+VhA9tLneUlpUDtSsGiYVV9KGqaqbqzWbEzcqB0J78UbJaL2orJ1ZOY4N6mGdU D0BMrRBW+XKacexwm8q+DJ1Aw7+GrflBXivCBjJ7lrwhuNTAaPH7BUkVq+HfXVtmlRDY yd/nClwOiN+r5nUV6J0TW0ivFfd0pScgbtkqI8ws61h2MH8sKNwwj0LGZkCuTZWuBhnk jmHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=RS8wcS/G5VWyrUOXTcTyiXhAxCMybP5N6fx0qvCe1DM=; b=Pl29KdLsfqtjLQQSJvpQv7MSW5ri42oec/O+ODLTjiaJ8owwjb6JhAh8Ng69EMrGW0 al0g5mBNsRdhu26qmAiZGHAvbaBU4gKFhDdtk/8Ek1dBQKs1v5/MWwOzC1TZ406m0wqp j3/BY6rm7+0IxKlv4Rkf6pTT58xrE9T8r+GmJ46R54LTHwXyd0N50++kfnPWDoLcbOX2 bib9A+xjfAehB/gXvwUS0aUSUb5MBSt1eCenD7NatOmhWYE82eqrQSmu3c+hG5yv91HY M4zma1DuPI52apRcrQD23pdztPkp4j+Y0vsheScSNg5qtGuDjH/Iya1Tt6Vccpujb2Qg ef9Q== X-Gm-Message-State: AOAM533TdadCaQftXSxnhxQtpAEMXFioEhVED/kbrHhR52Kva9mNgr9i 1+wAGCAMNQ0pawnSrYXyqHQiK/SgmoZmbg== X-Google-Smtp-Source: ABdhPJxs1MtH7jEph3e+D0HXWR5Wa1tbP2KvSSGlXFPtN+jxjqBeHBP/VGj8CE3vNRrTtCz35kOR9g== X-Received: by 2002:a17:906:8691:: with SMTP id g17mr250460ejx.317.1605857141253; Thu, 19 Nov 2020 23:25:41 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id lz27sm779419ejb.39.2020.11.19.23.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:25:40 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:20:04 +0100 Message-Id: <20201120072116.818090-92-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> References: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 091/162] avcodec/atrac3plus: Make tables used to initialize VLCs smaller X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- libavcodec/atrac3plus.c | 72 ++++------- libavcodec/atrac3plus_data.h | 226 ++++++++++++++++------------------- 2 files changed, 124 insertions(+), 174 deletions(-) diff --git a/libavcodec/atrac3plus.c b/libavcodec/atrac3plus.c index f527d3b9fc..c93d42ab39 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, NULL); - 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, NULL); 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, NULL); 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 /** 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,