+static av_cold void atrac9_init_vlc(VLC *vlc, int nb_bits, int nb_codes,
+ const uint8_t (**tab)[2],
+ unsigned *buf_offset, int offset)
+{
+ static VLC_TYPE vlc_buf[24812][2];
+
+ vlc->table = &vlc_buf[*buf_offset];
+ vlc->table_allocated = FF_ARRAY_ELEMS(vlc_buf) - *buf_offset;
+ ff_init_vlc_from_lengths(vlc, nb_bits, nb_codes,
+ &(*tab)[0][1], 2, &(*tab)[0][0], 2, 1,
+ offset, INIT_VLC_STATIC_OVERLONG, NULL);
+ *buf_offset += vlc->table_size;
+ *tab += nb_codes;
+}
+
+static av_cold void atrac9_init_static(void)
+{
+ const uint8_t (*tab)[2];
+ unsigned offset = 0;
+
+ /* Unsigned scalefactor VLCs */
+ tab = at9_sfb_a_tab;
+ for (int i = 1; i < 7; i++) {
+ const HuffmanCodebook *hf = &at9_huffman_sf_unsigned[i];
+
+ atrac9_init_vlc(&sf_vlc[0][i], ATRAC9_SF_VLC_BITS,
+ hf->size, &tab, &offset, 0);
+ }
+
+ /* Signed scalefactor VLCs */
+ tab = at9_sfb_b_tab;
+ for (int i = 2; i < 6; i++) {
+ const HuffmanCodebook *hf = &at9_huffman_sf_signed[i];
+
+ /* The symbols are signed integers in the range -16..15;
+ * the values in the source table are offset by 16 to make
+ * them fit into an uint8_t; the -16 reverses this shift. */
+ atrac9_init_vlc(&sf_vlc[1][i], ATRAC9_SF_VLC_BITS,
+ hf->size, &tab, &offset, -16);
+ }
+
+ /* Coefficient VLCs */
+ tab = at9_coeffs_tab;
+ for (int i = 0; i < 2; i++) {
+ for (int j = 2; j < 8; j++) {
+ for (int k = i; k < 4; k++) {
+ const HuffmanCodebook *hf = &at9_huffman_coeffs[i][j][k];
+ atrac9_init_vlc(&coeff_vlc[i][j][k], ATRAC9_COEFF_VLC_BITS,
+ hf->size, &tab, &offset, 0);
+ }
+ }
+ }
+}
+