42 #define GET_DELTA(gb, delta_bits) \
43 ((delta_bits) ? get_bits((gb), (delta_bits)) : 0)
54 int *tab_offset,
VLC *out_vlc)
64 for (b = min_len; b <= max_len; b++) {
65 for (i = *cb++; i > 0; i--) {
68 codes[
index] = code++;
80 *tab_offset += 1 << max_len;
85 int i, wl_vlc_offs, ct_vlc_offs, sf_vlc_offs, tab_offset;
87 static int wl_nb_bits[4] = { 2, 3, 5, 5 };
88 static int wl_nb_codes[4] = { 3, 5, 8, 8 };
89 static const uint8_t *wl_bits[4] = {
93 static const uint8_t *wl_codes[4] = {
97 static const uint8_t *wl_xlats[4] = {
101 static int ct_nb_bits[4] = { 3, 4, 4, 4 };
102 static int ct_nb_codes[4] = { 4, 8, 8, 8 };
103 static const uint8_t *ct_bits[4] = {
107 static const uint8_t *ct_codes[4] = {
111 static const uint8_t *ct_xlats[4] = {
115 static int sf_nb_bits[8] = { 9, 9, 9, 9, 6, 6, 7, 7 };
116 static int sf_nb_codes[8] = { 64, 64, 64, 64, 16, 16, 16, 16 };
117 static const uint8_t *sf_bits[8] = {
122 static const uint16_t *sf_codes[8] = {
127 static const uint8_t *sf_xlats[8] = {
132 static const uint8_t *gain_cbs[11] = {
140 static const uint8_t *gain_xlats[11] = {
148 static const uint8_t *tone_cbs[7] = {
154 static const uint8_t *tone_xlats[7] = {
160 for (i = 0, wl_vlc_offs = 0, ct_vlc_offs = 2508; i < 4; i++) {
182 for (i = 0, sf_vlc_offs = 76; i < 8; i++) {
197 for (i = 0; i < 112; i++) {
201 &tab_offset, &spec_vlc_tabs[i]);
203 spec_vlc_tabs[i].
table = 0;
207 for (i = 0; i < 11; i++)
211 for (i = 0; i < 7; i++)
234 "Invalid number of transmitted units!\n");
259 const int8_t *weights_tab =
266 "WL index out of range: pos=%d, val=%d!\n",
295 "SF index out of range: pos=%d, val=%d!\n",
313 int *dst,
int num_values)
318 dst[0] = dst[1] = dst[2] = start_val;
319 for (i = 3; i < num_values; i++)
324 #define UNPACK_SF_VQ_SHAPE(gb, dst, num_vals) \
325 start_val = get_bits((gb), 6); \
326 unpack_vq_shape(start_val, &atrac3p_sf_shapes[get_bits((gb), 6)][0], \
341 int i, weight_idx = 0,
delta, diff, pos, delta_bits, min_val, flag,
360 vlc_tab = &wl_vlc_tabs[
get_bits(gb, 2)];
376 "WL mode 1: invalid position!\n");
383 for (i = 0; i < pos; i++)
396 vlc_tab = &wl_vlc_tabs[
get_bits(gb, 2)];
407 vlc_tab = &wl_vlc_tabs[
get_bits(gb, 1)];
424 vlc_tab->
bits, 1)) & 7;
427 vlc_tab->
bits, 1)) & 7;
433 vlc_tab->
bits, 1)) & 7;
443 vlc_tab = &wl_vlc_tabs[
get_bits(gb, 2)];
484 int i, weight_idx = 0,
delta, diff, num_long_vals,
485 delta_bits, min_val, vlc_sel, start_val;
497 vlc_tab = &sf_vlc_tabs[
get_bits(gb, 2)];
505 if (weight_idx == 3) {
512 for (i = 0; i < num_long_vals; i++)
526 "SF mode 1: invalid parameters!\n");
531 for (i = 0; i < num_long_vals; i++)
543 vlc_tab = &sf_vlc_tabs[
get_bits(gb, 2)];
554 vlc_tab = &sf_vlc_tabs[
get_bits(gb, 2) + 4];
573 vlc_tab = &sf_vlc_tabs[vlc_sel];
575 if (weight_idx == 3) {
576 vlc_tab = &sf_vlc_tabs[vlc_sel + 4];
580 diff = (
get_bits(gb, 4) + 56) & 0x3F;
601 if (weight_idx && weight_idx < 3)
621 for (ch_num = 0; ch_num < num_channels; ch_num++) {
657 for (ch_num = 0; ch_num < num_channels; ch_num++) {
685 "Invalid number of code table indexes: %d!\n", num_coded_vals);
688 return num_coded_vals;
693 #define DEC_CT_IDX_COMMON(OP) \
694 num_vals = get_num_ct_values(gb, ctx, avctx); \
698 for (i = 0; i < num_vals; i++) { \
699 if (chan->qu_wordlen[i]) { \
700 chan->qu_tab_idx[i] = OP; \
701 } else if (ch_num && ref_chan->qu_wordlen[i]) \
703 chan->qu_tab_idx[i] = get_bits1(gb); \
706 #define CODING_DIRECT get_bits(gb, num_bits)
708 #define CODING_VLC get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1)
710 #define CODING_VLC_DELTA \
712 : (pred + get_vlc2(gb, delta_vlc->table, \
713 delta_vlc->bits, 1)) & mask; \
714 pred = chan->qu_tab_idx[i]
716 #define CODING_VLC_DIFF \
717 (ref_chan->qu_tab_idx[i] + \
718 get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1)) & mask
732 int i, num_vals, num_bits,
pred;
734 VLC *vlc_tab, *delta_vlc;
752 vlc_tab = &ct_vlc_tabs[1];
753 delta_vlc = &ct_vlc_tabs[2];
792 for (ch_num = 0; ch_num < num_channels; ch_num++) {
816 VLC *vlc_tab, int16_t *
out,
const int num_specs)
825 for (pos = 0; pos < num_specs;) {
827 for (j = 0; j < group_size; j++) {
830 for (i = 0; i < num_coeffs; i++) {
842 pos += group_size * num_coeffs;
857 int i, ch_num,
qu, wordlen, codetab, tab_index, num_specs;
861 for (ch_num = 0; ch_num < num_channels; ch_num++) {
879 tab_index = (chan->
table_type * 8 + codetab) * 7 + wordlen - 1;
887 &chan->
spectrum[ff_atrac3p_qu_to_spec_pos[qu]],
891 memcpy(&chan->
spectrum[ff_atrac3p_qu_to_spec_pos[qu]],
894 sizeof(chan->
spectrum[ff_atrac3p_qu_to_spec_pos[qu]]));
905 for (i = 0; i < num_specs; i++)
928 memset(out, 0, num_flags);
933 for (i = 0; i < num_flags; i++)
936 memset(out, 1, num_flags);
954 for (ch_num = 0; ch_num < num_channels; ch_num++)
969 int ch_num,
int coded_subbands)
971 int i,
delta, delta_bits, min_val;
977 for (i = 0; i < coded_subbands; i++)
981 for (i = 0; i < coded_subbands; i++)
984 gain_vlc_tabs[0].
bits, 1);
988 for (i = 0; i < coded_subbands; i++) {
989 delta =
get_vlc2(gb, gain_vlc_tabs[1].table,
990 gain_vlc_tabs[1].bits, 1);
996 get_vlc2(gb, gain_vlc_tabs[0].table,
997 gain_vlc_tabs[0].bits, 1);
999 for (i = 1; i < coded_subbands; i++) {
1000 delta =
get_vlc2(gb, gain_vlc_tabs[1].table,
1001 gain_vlc_tabs[1].bits, 1);
1009 for (i = 0; i < coded_subbands; i++)
1016 for (i = 0; i < coded_subbands; i++) {
1056 gain_vlc_tabs[2].
bits, 1);
1059 delta =
get_vlc2(gb, gain_vlc_tabs[3].table,
1060 gain_vlc_tabs[3].bits, 1);
1075 int ch_num,
int coded_subbands)
1077 int sb, i,
delta, delta_bits, min_val,
pred;
1083 for (sb = 0; sb < coded_subbands; sb++)
1089 for (sb = 0; sb < coded_subbands; sb++)
1092 gain_vlc_tabs[5].
bits, 1);
1098 for (sb = 0; sb < coded_subbands; sb++)
1104 for (sb = 0; sb < coded_subbands; sb++)
1116 for (sb = 1; sb < coded_subbands; sb++)
1119 gain_vlc_tabs[4].
bits, 1);
1128 for (sb = 0; sb < coded_subbands; sb++)
1135 for (sb = 0; sb < coded_subbands; sb++)
1161 if (!pos || dst->
loc_code[pos - 1] < 15)
1163 else if (dst->
loc_code[pos - 1] >= 30)
1194 : &gain_vlc_tabs[9];
1212 int ch_num,
int coded_subbands,
1215 int sb, i,
delta, delta_bits, min_val,
pred, more_than_ref;
1223 for (sb = 0; sb < coded_subbands; sb++)
1229 for (sb = 0; sb < coded_subbands; sb++) {
1237 gain_vlc_tabs[10].
bits, 1);
1245 if (more_than_ref) {
1247 get_vlc2(gb, gain_vlc_tabs[9].table,
1248 gain_vlc_tabs[9].bits, 1);
1257 tab = more_than_ref ? &gain_vlc_tabs[7]
1258 : &gain_vlc_tabs[10];
1268 for (sb = 0; sb < coded_subbands; sb++)
1273 for (sb = 0; sb < coded_subbands; sb++) {
1289 for (sb = 1; sb < coded_subbands; sb++) {
1297 gain_vlc_tabs[6].
bits, 1);
1307 2 + more_than_ref + 6];
1319 for (sb = 0; sb < coded_subbands; sb++)
1331 for (sb = 0; sb < coded_subbands; sb++)
1340 for (sb = 0; sb < coded_subbands; sb++) {
1346 "Invalid gain location: ch=%d, sb=%d, pos=%d, val=%d\n",
1368 int ch_num, coded_subbands, sb,
ret;
1370 for (ch_num = 0; ch_num < num_channels; ch_num++) {
1375 coded_subbands =
get_bits(gb, 4) + 1;
1386 if (coded_subbands > 0) {
1409 int ch_num,
int band_has_tones[])
1417 if (!band_has_tones[sb])
1428 if (!band_has_tones[sb])
1450 int ch_num,
int band_has_tones[],
1461 if (band_has_tones[sb])
1466 if (band_has_tones[sb])
1469 tone_vlc_tabs[1].
bits, 1);
1473 if (band_has_tones[sb]) {
1474 delta =
get_vlc2(gb, tone_vlc_tabs[2].table,
1475 tone_vlc_tabs[2].bits, 1);
1482 if (band_has_tones[sb])
1489 if (band_has_tones[sb]) {
1492 "Too many tones: %d (max. 48), frame: %d!\n",
1514 int ch_num,
int band_has_tones[])
1516 int sb, i, direction, nbits,
pred,
delta;
1523 if (!band_has_tones[sb] || !dst[sb].num_wavs)
1528 if (dst[sb].num_wavs)
1530 for (i = dst[sb].num_wavs - 2; i >= 0 ; i--) {
1531 nbits =
av_log2(iwav[i+1].freq_index) + 1;
1535 for (i = 0; i < dst[sb].
num_wavs; i++) {
1536 if (!i || iwav[i - 1].freq_index < 512)
1539 nbits =
av_log2(1023 - iwav[i - 1].freq_index) + 1;
1541 1024 - (1 << nbits);
1548 if (!band_has_tones[sb] || !dst[sb].num_wavs)
1552 for (i = 0; i < dst[sb].
num_wavs; i++) {
1554 tone_vlc_tabs[6].
bits, 1);
1556 pred = (i < ref[sb].
num_wavs) ? iwav[i].freq_index :
1557 (ref[sb].num_wavs ? iwav[ref[sb].num_wavs - 1].freq_index : 0);
1574 int ch_num,
int band_has_tones[])
1584 if (!band_has_tones[sb] || !dst[sb].num_wavs)
1588 for (j = 0; j < dst[sb].
num_wavs; j++) {
1589 for (i = 0, fi = 0, maxdiff = 1024; i < ref[sb].
num_wavs; i++) {
1590 diff =
FFABS(wsrc[j].freq_index - wref[i].freq_index);
1591 if (diff < maxdiff) {
1599 else if (j < ref[sb].num_wavs)
1600 refwaves[dst[sb].start_index + j] = j + ref[sb].
start_index;
1602 refwaves[dst[sb].start_index + j] = -1;
1612 if (!band_has_tones[sb] || !dst[sb].num_wavs)
1615 for (i = 0; i < dst[sb].
num_wavs; i++)
1623 if (!band_has_tones[sb] || !dst[sb].num_wavs)
1626 for (i = 0; i < dst[sb].
num_wavs; i++)
1629 tone_vlc_tabs[3].
bits, 1) + 20;
1632 get_vlc2(gb, tone_vlc_tabs[4].table,
1633 tone_vlc_tabs[4].bits, 1) + 24;
1638 if (!band_has_tones[sb] || !dst[sb].num_wavs)
1640 for (i = 0; i < dst[sb].
num_wavs; i++) {
1642 tone_vlc_tabs[5].
bits, 1);
1652 if (!band_has_tones[sb])
1654 for (i = 0; i < dst[sb].
num_wavs; i++)
1674 int ch_num,
int band_has_tones[])
1681 if (!band_has_tones[sb])
1684 for (i = 0; i < dst[sb].
num_wavs; i++)
1685 wparam[i].phase_index =
get_bits(gb, 5);
1702 int band_has_tones[16];
1704 for (ch_num = 0; ch_num < num_channels; ch_num++)
1722 tone_vlc_tabs[0].
bits, 1) + 1;
1724 if (num_channels == 2) {
1736 for (ch_num = 0; ch_num < num_channels; ch_num++) {
1750 if (num_channels == 2) {
1773 "Invalid number of quantization units: %d!\n",
1797 if (num_channels == 2) {