* Generate canonical VLC table from given descriptor.
*
* @param[in] cb ptr to codebook descriptor
- * @param[in] xlat ptr to translation table or NULL
+ * @param[in,out] xlat ptr to ptr to translation table
* @param[in,out] tab_offset starting offset to the generated vlc table
* @param[out] out_vlc ptr to vlc table to be generated
*/
-static av_cold void build_canonical_huff(const uint8_t *cb, const uint8_t *xlat,
+static av_cold void build_canonical_huff(const uint8_t *cb, const uint8_t **xlat,
int *tab_offset, VLC *out_vlc)
{
- int i, b;
+ int i, max_len;
uint8_t bits[256];
int index = 0;
- int min_len = *cb++; // get shortest codeword length
- int max_len = *cb++; // get longest codeword length
- for (b = min_len; b <= max_len; b++) {
+ for (int b = 1; b <= 12; b++) {
for (i = *cb++; i > 0; i--) {
av_assert0(index < 256);
bits[index] = b;
index++;
}
}
+ max_len = bits[index - 1];
out_vlc->table = &tables_data[*tab_offset];
out_vlc->table_allocated = 1 << max_len;
ff_init_vlc_from_lengths(out_vlc, max_len, index, bits, 1,
- xlat, 1, 1, 0, INIT_VLC_USE_NEW_STATIC, NULL);
+ *xlat, 1, 1, 0, INIT_VLC_USE_NEW_STATIC, NULL);
*tab_offset += 1 << max_len;
+ *xlat += index;
}
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
- };
-
- static const uint8_t * const gain_cbs[11] = {
- atrac3p_huff_gain_npoints1_cb, atrac3p_huff_gain_npoints1_cb,
- atrac3p_huff_gain_lev1_cb, atrac3p_huff_gain_lev2_cb,
- atrac3p_huff_gain_lev3_cb, atrac3p_huff_gain_lev4_cb,
- atrac3p_huff_gain_loc3_cb, atrac3p_huff_gain_loc1_cb,
- atrac3p_huff_gain_loc4_cb, atrac3p_huff_gain_loc2_cb,
- atrac3p_huff_gain_loc5_cb
- };
- static const uint8_t * const gain_xlats[11] = {
- NULL, atrac3p_huff_gain_npoints2_xlat, atrac3p_huff_gain_lev1_xlat,
- atrac3p_huff_gain_lev2_xlat, atrac3p_huff_gain_lev3_xlat,
- atrac3p_huff_gain_lev4_xlat, atrac3p_huff_gain_loc3_xlat,
- atrac3p_huff_gain_loc1_xlat, atrac3p_huff_gain_loc4_xlat,
- atrac3p_huff_gain_loc2_xlat, atrac3p_huff_gain_loc5_xlat
- };
-
- static const uint8_t * const tone_cbs[7] = {
- atrac3p_huff_tonebands_cb, atrac3p_huff_numwavs1_cb,
- atrac3p_huff_numwavs2_cb, atrac3p_huff_wav_ampsf1_cb,
- atrac3p_huff_wav_ampsf2_cb, atrac3p_huff_wav_ampsf3_cb,
- atrac3p_huff_freq_cb
- };
- static const uint8_t * const tone_xlats[7] = {
- NULL, NULL, atrac3p_huff_numwavs2_xlat, atrac3p_huff_wav_ampsf1_xlat,
- atrac3p_huff_wav_ampsf2_xlat, atrac3p_huff_wav_ampsf3_xlat,
- atrac3p_huff_freq_xlat
- };
-
+ 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;
for (i = 0; i < 112; i++) {
- if (atrac3p_spectra_tabs[i].redirect < 0)
- build_canonical_huff(atrac3p_spectra_tabs[i].cb,
- atrac3p_spectra_tabs[i].xlat,
- &tab_offset, &spec_vlc_tabs[i]);
+ if (atrac3p_spectra_cbs[i][0] >= 0)
+ build_canonical_huff(atrac3p_spectra_cbs[i],
+ &xlats, &tab_offset, &spec_vlc_tabs[i]);
else /* Reuse already initialized VLC table */
- spec_vlc_tabs[i] = spec_vlc_tabs[atrac3p_spectra_tabs[i].redirect];
+ spec_vlc_tabs[i] = spec_vlc_tabs[-atrac3p_spectra_cbs[i][0]];
}
/* build huffman tables for gain data decoding */
+ xlats = atrac3p_gain_xlats;
for (i = 0; i < 11; i++)
- build_canonical_huff(gain_cbs[i], gain_xlats[i], &tab_offset, &gain_vlc_tabs[i]);
+ build_canonical_huff(atrac3p_gain_cbs[i], &xlats,
+ &tab_offset, &gain_vlc_tabs[i]);
/* build huffman tables for tone decoding */
+ xlats = atrac3p_tone_xlats;
for (i = 0; i < 7; i++)
- build_canonical_huff(tone_cbs[i], tone_xlats[i], &tab_offset, &tone_vlc_tabs[i]);
+ build_canonical_huff(atrac3p_tone_cbs[i], &xlats,
+ &tab_offset, &tone_vlc_tabs[i]);
}
/**