21#define BITSTREAM_READER_LE
89 { 0, -1, -1, -1, -1 },
99 { 0, -1, -1, -1, -1 },
100 { 0, 1, -1, -1, -1 },
102 { 1, 2, -1, -1, -1 },
125 -0.995734176295034521871191178905, -0.961825643172819070408796290732,
126 -0.895163291355062322067016499754, -0.798017227280239503332805112796,
127 -0.673695643646557211712691912426, -0.526432162877355800244607799141,
128 -0.361241666187152948744714596184, -0.183749517816570331574408839621,
129 0.0, 0.207911690817759337101742284405,
130 0.406736643075800207753985990341, 0.587785252292473129168705954639,
131 0.743144825477394235014697048974, 0.866025403784438646763723170753,
132 0.951056516295153572116439333379, 0.994521895368273336922691944981
139 for (
i = 0;
i < 256;
i++)
146 int i, ps, si,
code, step_i;
152 value = (((ps & 0x7fffff) ^ -si) + si) * (1.0f / 0x7fffff);
155 if (step_i > step_max) {
162 for (
i = 0;
i < 64;
i++) {
165 delta = step * 0.03125f;
169 delta += step * 0.5f;
171 delta += step * 0.25f;
173 delta += step * 0.125f;
175 delta += step * 0.0625f;
188 step_i =
av_clip(step_i, 0, step_max);
191 s->lfe_data[
i] =
value *
s->lfe_scale;
200 int i, ps, si,
code, step_i;
206 value = (((ps & 0x7fff) ^ -si) + si) * (1.0f / 0x7fff);
209 if (step_i > step_max) {
216 for (
i = 0;
i < 64;
i++) {
219 delta = step * 0.125f;
223 delta += step * 0.5f;
225 delta += step * 0.25f;
238 step_i =
av_clip(step_i, 0, step_max);
241 s->lfe_data[
i] =
value *
s->lfe_scale;
262 if (chunk->
len >= 52)
264 if (chunk->
len >= 35)
272 int nb_bits,
int max_depth)
286 int sf, sf_idx, ch, main_ch, freq;
290 for (sf = 0; sf < 1 << group; sf +=
diff ? 8 : 1) {
291 sf_idx = ((
s->framenum << group) + sf) & 31;
292 s->tonal_bounds[group][sf_idx][0] =
s->ntones;
295 for (freq = 1;; freq++) {
312 if (freq >> (5 - group) >
s->nsubbands * 4 - 6) {
321 +
s->limited_range - 2;
322 amp[main_ch] = main_amp <
AMP_MAX ? main_amp : 0;
326 for (ch = 0; ch <
s->nchannels_total; ch++) {
343 t->
x_freq = freq >> (5 - group);
344 t->
f_delt = (freq & ((1 << (5 - group)) - 1)) << group;
350 for (ch = 0; ch <
s->nchannels; ch++) {
352 t->
phs[ch] = 128 - phs[ch] * 32 +
shift;
357 s->tonal_bounds[group][sf_idx][1] =
s->ntones;
381 for (sb = 0; sb < 6; sb++)
387 for (group = 0; group < 5; group++) {
428 int i, sf, prev, next, dist;
437 for (sf = 0; sf < 7; sf += dist) {
457 next = prev + ((next + 1) >> 1);
459 next = prev - ( next >> 1);
465 scf[sf + 1] = prev + ((next - prev) >> 1);
467 scf[sf + 1] = prev - ((prev - next) >> 1);
472 scf[sf + 1] = prev + ( (next - prev) >> 2);
473 scf[sf + 2] = prev + ( (next - prev) >> 1);
474 scf[sf + 3] = prev + (((next - prev) * 3) >> 2);
476 scf[sf + 1] = prev - ( (prev - next) >> 2);
477 scf[sf + 2] = prev - ( (prev - next) >> 1);
478 scf[sf + 3] = prev - (((prev - next) * 3) >> 2);
483 for (
i = 1;
i < dist;
i++)
484 scf[sf +
i] = prev + (next - prev) *
i / dist;
512 int ch, sb, sf, nsubbands, ret;
523 for (sb = 2; sb < nsubbands; sb++) {
538 for (sb = 0; sb <
s->nsubbands - 4; sb++) {
541 if (sb + 4 <
s->min_mono_subband)
544 s->grid_3_avg[ch2][sb] =
s->grid_3_avg[ch1][sb];
563 nsubbands = (
s->nsubbands -
s->min_mono_subband + 3) / 4;
564 for (sb = 0; sb < nsubbands; sb++)
565 for (ch = ch1; ch <= ch2; ch++)
566 for (sf = 1; sf <= 4; sf++)
570 s->part_stereo_pres |= 1 << ch1;
580 int sb, nsubbands, ret;
584 for (sb = 2; sb < nsubbands; sb++) {
593 for (sb = 0; sb <
s->nsubbands - 4; sb++) {
594 if (sb + 4 >=
s->min_mono_subband) {
608 for (ch = ch1; ch <= ch2; ch++) {
609 if ((ch != ch1 && sb + 4 >=
s->min_mono_subband) !=
flag)
612 if (
s->grid_3_pres[ch] & (1U << sb))
615 for (
i = 0;
i < 8;
i++) {
622 s->grid_3_pres[ch] |= 1U << sb;
628 s->lbr_rand = 1103515245U *
s->lbr_rand + 12345U;
629 return s->lbr_rand *
s->sb_scf[sb];
637 float *samples =
s->time_samples[ch][sb];
638 int i, j,
code, nblocks, coding_method;
645 switch (quant_level) {
648 for (
i = 0;
i < nblocks;
i++, samples += 8) {
650 for (j = 0; j < 8; j++)
666 for (
i = 0;
i < nblocks;
i++, samples += 5) {
668 for (j = 0; j < 5; j++)
677 for (
i = 0;
i < nblocks;
i++, samples += 3) {
679 for (j = 0; j < 3; j++)
692 for (
i = 0;
i < nblocks;
i++)
706 s->ch_pres[ch] |= 1U << sb;
710 int start_sb,
int end_sb,
int flag)
712 int sb, sb_g3, sb_reorder, quant_level;
714 for (sb = start_sb; sb < end_sb; sb++) {
718 }
else if (
flag && sb < s->max_mono_subband) {
719 sb_reorder =
s->sb_indices[sb];
723 sb_reorder =
get_bits(&
s->gb,
s->limited_range + 3);
726 s->sb_indices[sb] = sb_reorder;
728 if (sb_reorder >=
s->nsubbands)
733 for (sb_g3 = 0; sb_g3 <
s->g3_avg_only_start_sb - 4; sb_g3++)
735 }
else if (sb < 12 && sb_reorder >= 4) {
743 if (!
flag || sb_reorder >=
s->max_mono_subband)
744 s->sec_ch_sbms[ch1 / 2][sb_reorder] =
get_bits(&
s->gb, 8);
745 if (
flag && sb_reorder >=
s->min_mono_subband)
746 s->sec_ch_lrms[ch1 / 2][sb_reorder] =
get_bits(&
s->gb, 8);
749 quant_level =
s->quant_levels[ch1 / 2][sb];
754 if (sb < s->max_mono_subband && sb_reorder >=
s->min_mono_subband) {
756 parse_ch(
s, ch1, sb_reorder, quant_level, 0);
758 parse_ch(
s, ch2, sb_reorder, quant_level, 1);
760 parse_ch(
s, ch1, sb_reorder, quant_level, 0);
762 parse_ch(
s, ch2, sb_reorder, quant_level, 0);
776 for (
i = 0;
i < 8;
i++) {
778 for (j = 0; j < (
i + 1) / 2; j++) {
779 float tmp1 =
coeff[ j ];
780 float tmp2 =
coeff[
i - j - 1];
781 coeff[ j ] = tmp1 + rc * tmp2;
782 coeff[
i - j - 1] = tmp2 + rc * tmp1;
790 int f =
s->framenum & 1;
791 int i, sb, ch, codes[16];
794 for (sb = start_sb; sb < end_sb; sb++) {
795 int ncodes = 8 * (1 + (sb < 2));
796 for (ch = ch1; ch <= ch2; ch++) {
799 for (
i = 0;
i < ncodes;
i++)
801 for (
i = 0;
i < ncodes / 8;
i++)
812 int sb, ch, ol, st, max_sb,
profile, ret;
831 for (sb = 0; sb <
s->nsubbands; sb++) {
832 int f = sb *
s->limited_rate /
s->nsubbands;
833 int a = 18000 / (12 *
f / 1000 + 100 + 40 * st) + 20 * ol;
835 quant_levels[sb] = 1;
837 quant_levels[sb] = 2;
839 quant_levels[sb] = 3;
841 quant_levels[sb] = 4;
843 quant_levels[sb] = 5;
847 for (sb = 0; sb < 8; sb++)
849 for (; sb <
s->nsubbands; sb++)
850 s->quant_levels[ch1 / 2][sb] = quant_levels[sb];
863 for (sb = 0; sb < 2; sb++)
864 for (ch = ch1; ch <= ch2; ch++)
872 int start_sb,
int end_sb,
int flag)
874 int i, j, sb, ch, nsubbands;
877 if (end_sb > nsubbands)
880 for (sb = start_sb; sb < end_sb; sb++) {
881 for (ch = ch1; ch <= ch2; ch++) {
882 uint8_t *g2_scf =
s->grid_2_scf[ch][sb];
886 memcpy(g2_scf,
s->grid_2_scf[ch1][sb], 64);
891 for (
i = 0;
i < 8;
i++, g2_scf += 8) {
893 memset(g2_scf, 0, 64 -
i * 8);
898 for (j = 0; j < 8; j++) {
904 memset(g2_scf, 0, 8);
922 if ((ret =
parse_ts(
s, ch1, ch2, 2, 4, 0)) < 0)
926 if ((ret =
parse_ts(
s, ch1, ch2, 4, 6, 0)) < 0)
941 if ((ret =
parse_ts(
s, ch1, ch2, 6,
s->max_mono_subband, 0)) < 0)
949 if ((ret =
parse_ts(
s, ch1, ch2,
s->min_mono_subband,
s->nsubbands, 1)) < 0)
956 double scale = (-1.0 / (1 << 17)) * sqrt(1 << (2 -
s->limited_range));
957 float scale_t =
scale;
958 int i, br_per_ch =
s->bit_rate_scaled /
s->nchannels_total;
968 for (
i = 0;
i < 32 <<
s->freq_range;
i++)
971 if (br_per_ch < 14000)
973 else if (br_per_ch < 32000)
974 scale = (br_per_ch - 14000) * (1.0 / 120000) + 0.85;
978 scale *= 1.0 / INT_MAX;
980 for (
i = 0;
i <
s->nsubbands;
i++) {
984 s->sb_scf[
i] = (
i - 1) * 0.25 * 0.785 *
scale;
989 s->lfe_scale = (16 <<
s->freq_range) * 0.0000078265894;
998 int nsamples = nchsamples *
s->nchannels *
s->nsubbands;
1008 for (ch = 0; ch <
s->nchannels; ch++) {
1009 for (sb = 0; sb <
s->nsubbands; sb++) {
1010 s->time_samples[ch][sb] = ptr;
1020 int old_rate =
s->sample_rate;
1021 int old_band_limit =
s->band_limit;
1022 int old_nchannels =
s->nchannels;
1024 unsigned int sr_code;
1027 sr_code = bytestream2_get_byte(gb);
1033 if (
s->sample_rate > 48000) {
1039 s->ch_mask = bytestream2_get_le16(gb);
1040 if (!(
s->ch_mask & 0x7)) {
1044 if ((
s->ch_mask & 0xfff0) && !(
s->warned & 1)) {
1050 version = bytestream2_get_le16(gb);
1051 if ((
version & 0xff00) != 0x0800) {
1057 s->flags = bytestream2_get_byte(gb);
1063 if (!(
s->warned & 2)) {
1071 bit_rate_hi = bytestream2_get_byte(gb);
1074 s->bit_rate_orig = bytestream2_get_le16(gb) | ((bit_rate_hi & 0x0F) << 16);
1077 s->bit_rate_scaled = bytestream2_get_le16(gb) | ((bit_rate_hi & 0xF0) << 12);
1103 if (
s->bit_rate_orig >= 44000 * (
s->nchannels_total + 2))
1105 else if (
s->bit_rate_orig >= 25000 * (
s->nchannels_total + 2))
1111 s->limited_rate =
s->sample_rate >>
s->band_limit;
1112 s->limited_range =
s->freq_range -
s->band_limit;
1113 if (
s->limited_range < 0) {
1118 s->nsubbands = 8 <<
s->limited_range;
1121 if (
s->g3_avg_only_start_sb >
s->nsubbands)
1122 s->g3_avg_only_start_sb =
s->nsubbands;
1124 s->min_mono_subband =
s->nsubbands * 2000 / (
s->limited_rate / 2);
1125 if (
s->min_mono_subband >
s->nsubbands)
1126 s->min_mono_subband =
s->nsubbands;
1128 s->max_mono_subband =
s->nsubbands * 14000 / (
s->limited_rate / 2);
1129 if (
s->max_mono_subband >
s->nsubbands)
1130 s->max_mono_subband =
s->nsubbands;
1133 if ((old_rate !=
s->sample_rate || old_band_limit !=
s->band_limit) &&
init_sample_rate(
s) < 0)
1152 s->nchannels_total += 2;
1159 if (old_rate !=
s->sample_rate
1160 || old_band_limit !=
s->band_limit
1161 || old_nchannels !=
s->nchannels) {
1184 int i, ch, sb, sf, ret, group, chunk_id, chunk_len;
1195 switch (bytestream2_get_byte(&gb)) {
1197 if (!
s->sample_rate) {
1214 chunk_id = bytestream2_get_byte(&gb);
1215 chunk_len = (chunk_id & 0x80) ? bytestream2_get_be16(&gb) : bytestream2_get_byte(&gb);
1226 switch (chunk_id & 0x7f) {
1229 int checksum = bytestream2_get_be16(&gb);
1230 uint16_t res = chunk_id;
1231 res += (chunk_len >> 8) & 0xff;
1232 res += chunk_len & 0xff;
1233 for (
i = 0;
i < chunk_len - 2;
i++)
1235 if (checksum != res) {
1252 memset(
s->quant_levels, 0,
sizeof(
s->quant_levels));
1253 memset(
s->sb_indices, 0xff,
sizeof(
s->sb_indices));
1254 memset(
s->sec_ch_sbms, 0,
sizeof(
s->sec_ch_sbms));
1255 memset(
s->sec_ch_lrms, 0,
sizeof(
s->sec_ch_lrms));
1256 memset(
s->ch_pres, 0,
sizeof(
s->ch_pres));
1257 memset(
s->grid_1_scf, 0,
sizeof(
s->grid_1_scf));
1258 memset(
s->grid_2_scf, 0,
sizeof(
s->grid_2_scf));
1259 memset(
s->grid_3_avg, 0,
sizeof(
s->grid_3_avg));
1260 memset(
s->grid_3_scf, 0,
sizeof(
s->grid_3_scf));
1261 memset(
s->grid_3_pres, 0,
sizeof(
s->grid_3_pres));
1262 memset(
s->tonal_scf, 0,
sizeof(
s->tonal_scf));
1263 memset(
s->lfe_data, 0,
sizeof(
s->lfe_data));
1264 s->part_stereo_pres = 0;
1265 s->framenum = (
s->framenum + 1) & 31;
1267 for (ch = 0; ch <
s->nchannels; ch++) {
1268 for (sb = 0; sb <
s->nsubbands / 4; sb++) {
1269 s->part_stereo[ch][sb][0] =
s->part_stereo[ch][sb][4];
1270 s->part_stereo[ch][sb][4] = 16;
1274 memset(
s->lpc_coeff[
s->framenum & 1], 0,
sizeof(
s->lpc_coeff[0]));
1276 for (group = 0; group < 5; group++) {
1277 for (sf = 0; sf < 1 << group; sf++) {
1278 int sf_idx = ((
s->framenum << group) + sf) & 31;
1279 s->tonal_bounds[group][sf_idx][0] =
1280 s->tonal_bounds[group][sf_idx][1] =
s->ntones;
1286 chunk_id = bytestream2_get_byte(&gb);
1287 chunk_len = (chunk_id & 0x80) ? bytestream2_get_be16(&gb) : bytestream2_get_byte(&gb);
1299 chunk.lfe.len = chunk_len;
1300 chunk.lfe.data = gb.
buffer;
1306 chunk.tonal.id = chunk_id;
1307 chunk.tonal.len = chunk_len;
1308 chunk.tonal.data = gb.
buffer;
1317 chunk.tonal_grp[
i].id =
i;
1318 chunk.tonal_grp[
i].len = chunk_len;
1319 chunk.tonal_grp[
i].data = gb.
buffer;
1328 chunk.tonal_grp[
i].id =
i;
1329 chunk.tonal_grp[
i].len = chunk_len;
1330 chunk.tonal_grp[
i].data = gb.
buffer;
1337 chunk.grid1[
i].len = chunk_len;
1338 chunk.grid1[
i].data = gb.
buffer;
1345 chunk.hr_grid[
i].len = chunk_len;
1346 chunk.hr_grid[
i].data = gb.
buffer;
1353 chunk.ts1[
i].len = chunk_len;
1354 chunk.ts1[
i].data = gb.
buffer;
1361 chunk.ts2[
i].len = chunk_len;
1362 chunk.ts2[
i].data = gb.
buffer;
1374 for (
i = 0;
i < 5;
i++)
1377 for (
i = 0;
i < (
s->nchannels + 1) / 2;
i++) {
1379 int ch2 =
FFMIN(ch1 + 1,
s->nchannels - 1);
1388 if (!chunk.grid1[
i].len || !chunk.hr_grid[
i].len || !chunk.ts1[
i].len)
1411 for (ch = ch1; ch <= ch2; ch++) {
1412 for (sb = 0; sb <
s->nsubbands; sb++) {
1415 uint8_t *g1_scf_a =
s->grid_1_scf[ch][g1_sb ];
1416 uint8_t *g1_scf_b =
s->grid_1_scf[ch][g1_sb + 1];
1421 uint8_t *hr_scf =
s->high_res_scf[ch][sb];
1424 for (
i = 0;
i < 8;
i++) {
1425 int scf = w1 * g1_scf_a[
i] + w2 * g1_scf_b[
i];
1426 hr_scf[
i] = scf >> 7;
1429 int8_t *g3_scf =
s->grid_3_scf[ch][sb - 4];
1430 int g3_avg =
s->grid_3_avg[ch][sb - 4];
1432 for (
i = 0;
i < 8;
i++) {
1433 int scf = w1 * g1_scf_a[
i] + w2 * g1_scf_b[
i];
1434 hr_scf[
i] = (scf >> 7) - g3_avg - g3_scf[
i];
1446 int i, j, k, ch, sb;
1448 for (ch = ch1; ch <= ch2; ch++) {
1449 for (sb = 0; sb <
s->nsubbands; sb++) {
1450 float *samples =
s->time_samples[ch][sb];
1452 if (
s->ch_pres[ch] & (1U << sb))
1458 }
else if (sb < 10) {
1463 float accum[8] = { 0 };
1466 for (k = 2; k < 6; k++) {
1467 float *other = &
s->time_samples[ch][k][
i * 8];
1468 for (j = 0; j < 8; j++)
1469 accum[j] +=
fabs(other[j]);
1472 for (j = 0; j < 8; j++)
1473 samples[j] = (accum[j] * 0.25f + 0.5f) *
lbr_rand(
s, sb);
1484 for (
i = 0;
i < nsamples;
i++) {
1486 for (j = 0; j < 8; j++)
1487 res +=
coeff[j] * samples[
i - j - 1];
1494 int f =
s->framenum & 1;
1497 for (ch = ch1; ch <= ch2; ch++) {
1498 float *samples =
s->time_samples[ch][sb];
1500 if (!(
s->ch_pres[ch] & (1U << sb)))
1504 predict(samples,
s->lpc_coeff[
f^1][ch][sb][1], 16);
1505 predict(samples + 16,
s->lpc_coeff[
f ][ch][sb][0], 64);
1506 predict(samples + 80,
s->lpc_coeff[
f ][ch][sb][1], 48);
1508 predict(samples,
s->lpc_coeff[
f^1][ch][sb][0], 16);
1509 predict(samples + 16,
s->lpc_coeff[
f ][ch][sb][0], 112);
1518 for (sb = 0; sb <
s->nsubbands; sb++) {
1520 for (ch = ch1; ch <= ch2; ch++) {
1521 float *samples =
s->time_samples[ch][sb];
1522 uint8_t *hr_scf =
s->high_res_scf[ch][sb];
1525 unsigned int scf = hr_scf[
i];
1528 for (j = 0; j < 16; j++)
1534 unsigned int scf = hr_scf[
i / 8] - g2_scf[
i];
1545 float *samples_l =
s->time_samples[ch1][sb];
1546 float *samples_r =
s->time_samples[ch2][sb];
1547 int ch2_pres =
s->ch_pres[ch2] & (1U << sb);
1550 int sbms = (
s->sec_ch_sbms[ch1 / 2][sb] >>
i) & 1;
1551 int lrms = (
s->sec_ch_lrms[ch1 / 2][sb] >>
i) & 1;
1553 if (sb >=
s->min_mono_subband) {
1554 if (lrms && ch2_pres) {
1556 for (j = 0; j < 16; j++) {
1557 float tmp = samples_l[j];
1558 samples_l[j] = samples_r[j];
1559 samples_r[j] = -
tmp;
1562 for (j = 0; j < 16; j++) {
1563 float tmp = samples_l[j];
1564 samples_l[j] = samples_r[j];
1568 }
else if (!ch2_pres) {
1569 if (sbms && (
s->part_stereo_pres & (1 << ch1))) {
1570 for (j = 0; j < 16; j++)
1571 samples_r[j] = -samples_l[j];
1573 for (j = 0; j < 16; j++)
1574 samples_r[j] = samples_l[j];
1577 }
else if (sbms && ch2_pres) {
1578 for (j = 0; j < 16; j++) {
1579 float tmp = samples_l[j];
1580 samples_l[j] = (
tmp + samples_r[j]) * 0.5f;
1581 samples_r[j] = (
tmp - samples_r[j]) * 0.5f;
1603 for (ch = ch1; ch <= ch2; ch++) {
1604 for (sb =
s->min_mono_subband; sb < s->nsubbands; sb++) {
1605 uint8_t *pt_st =
s->part_stereo[ch][(sb -
s->min_mono_subband) / 4];
1606 float *samples =
s->time_samples[ch][sb];
1608 if (
s->ch_pres[ch2] & (1U << sb))
1611 for (sf = 1; sf <= 4; sf++, samples += 32) {
1615 for (
i = 0;
i < 32;
i++)
1616 samples[
i] *= (32 -
i) * prev +
i * next;
1626 int group,
int group_sf,
int synth_idx)
1628 int i, start, count;
1633 start =
s->tonal_bounds[group][group_sf][0];
1634 count = (
s->tonal_bounds[group][group_sf][1] - start) & (
DCA_LBR_TONES - 1);
1636 for (
i = 0;
i < count;
i++) {
1650 values[3] += cf[0] * -
s;
1651 values[2] += cf[1] *
c;
1652 values[1] += cf[2] *
s;
1653 values[0] += cf[3] * -
c;
1656 values[2] += cf[0] * -
s;
1657 values[1] += cf[1] *
c;
1658 values[0] += cf[2] *
s;
1661 values[1] += cf[0] * -
s;
1662 values[0] += cf[1] *
c;
1665 values[0] += cf[0] * -
s;
1669 values[x_freq - 5] += cf[ 0] * -
s;
1670 p4: values[x_freq - 4] += cf[ 1] *
c;
1671 p3: values[x_freq - 3] += cf[ 2] *
s;
1672 p2: values[x_freq - 2] += cf[ 3] * -
c;
1673 p1: values[x_freq - 1] += cf[ 4] * -
s;
1674 p0: values[x_freq ] += cf[ 5] *
c;
1675 values[x_freq + 1] += cf[ 6] *
s;
1676 values[x_freq + 2] += cf[ 7] * -
c;
1677 values[x_freq + 3] += cf[ 8] * -
s;
1678 values[x_freq + 4] += cf[ 9] *
c;
1679 values[x_freq + 5] += cf[10] *
s;
1694 for (group = 0; group < 5; group++) {
1695 int group_sf = (
s->framenum << group) + ((sf - 22) >> (5 - group));
1696 int synth_idx = ((((sf - 22) & 31) << group) & 31) + (1 << group) - 1;
1698 synth_tones(
s, ch, values, group, (group_sf - 1) & 31, 30 - synth_idx);
1699 synth_tones(
s, ch, values, group, (group_sf ) & 31, synth_idx);
1707 int sf, sb, nsubbands =
s->nsubbands, noutsubbands = 8 <<
s->freq_range;
1710 if (nsubbands < noutsubbands)
1711 memset(values[nsubbands], 0, (noutsubbands - nsubbands) *
sizeof(values[0]));
1715 s->dcadsp->lbr_bank(values,
s->time_samples[ch],
1720 s->imdct_fn(
s->imdct, result[0], values[0],
sizeof(
float));
1723 s->fdsp->vector_fmul_add(output, result[0],
s->window,
1724 s->history[ch], noutsubbands * 4);
1725 s->fdsp->vector_fmul_reverse(
s->history[ch], result[noutsubbands],
1726 s->window, noutsubbands * 4);
1727 output += noutsubbands * 4;
1731 for (sb = 0; sb < nsubbands; sb++) {
1740 int i, ret, nchannels, ch_conf = (
s->ch_mask & 0x7) - 1;
1741 const int8_t *reorder;
1761 frame->nb_samples = 1024 <<
s->freq_range;
1766 for (
i = 0;
i < (
s->nchannels + 1) / 2;
i++) {
1768 int ch2 =
FFMIN(ch1 + 1,
s->nchannels - 1);
1776 if (ch1 != ch2 && (
s->part_stereo_pres & (1 << ch1)))
1779 if (ch1 < nchannels)
1782 if (ch1 != ch2 && ch2 < nchannels)
1790 s->lfe_history, 16 <<
s->freq_range);
1803 if (!
s->sample_rate)
1807 memset(
s->part_stereo, 16,
sizeof(
s->part_stereo));
1808 memset(
s->lpc_coeff, 0,
sizeof(
s->lpc_coeff));
1809 memset(
s->history, 0,
sizeof(
s->history));
1810 memset(
s->tonal_bounds, 0,
sizeof(
s->tonal_bounds));
1811 memset(
s->lfe_history, 0,
sizeof(
s->lfe_history));
1815 for (ch = 0; ch <
s->nchannels; ch++) {
1816 for (sb = 0; sb <
s->nsubbands; sb++) {
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
static __device__ float fabs(float a)
const uint8_t ff_dca_freq_ranges[16]
const uint32_t ff_dca_sampling_freqs[16]
#define DCA_SPEAKER_LAYOUT_STEREO
static int ff_dca_count_chs_for_mask(unsigned int mask)
Return number of individual channels in DCASpeakerPair mask.
static void random_ts(DCALbrDecoder *s, int ch1, int ch2)
Fill unallocated subbands with randomness.
static int alloc_sample_buffer(DCALbrDecoder *s)
static int parse_grid_1_sec_ch(DCALbrDecoder *s, int ch2)
int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame)
static void filter_ts(DCALbrDecoder *s, int ch1, int ch2)
static void decode_grid(DCALbrDecoder *s, int ch1, int ch2)
Reconstruct high-frequency resolution grid from first and third grids.
static void predict(float *samples, const float *coeff, int nsamples)
static const int8_t channel_reorder_lfe[7][5]
static int parse_decoder_init(DCALbrDecoder *s, GetByteContext *gb)
static void transform_channel(DCALbrDecoder *s, int ch, float *output)
static int parse_lfe_chunk(DCALbrDecoder *s, LBRChunk *chunk)
static const uint16_t channel_layouts[7]
static void decode_part_stereo(DCALbrDecoder *s, int ch1, int ch2)
Modulate by interpolated partial stereo coefficients.
static int parse_tonal_chunk(DCALbrDecoder *s, LBRChunk *chunk)
static int parse_tonal(DCALbrDecoder *s, int group)
static const uint8_t lfe_index[7]
static int ensure_bits(GetBitContext *s, int n)
Check point to ensure that enough bits are left.
static int parse_high_res_grid(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
static int parse_ts1_chunk(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
static void synth_lpc(DCALbrDecoder *s, int ch1, int ch2, int sb)
av_cold int ff_dca_lbr_init(DCALbrDecoder *s)
@ LBR_FLAG_BAND_LIMIT_1_4
@ LBR_FLAG_BAND_LIMIT_1_2
@ LBR_FLAG_BAND_LIMIT_MASK
@ LBR_FLAG_BAND_LIMIT_2_3
@ LBR_FLAG_BAND_LIMIT_1_8
@ LBR_FLAG_BAND_LIMIT_1_3
@ LBR_FLAG_BAND_LIMIT_NONE
static int parse_tonal_group(DCALbrDecoder *s, LBRChunk *chunk)
static float cos_tab[256]
static float lbr_rand(DCALbrDecoder *s, int sb)
static const float lpc_tab[16]
static void synth_tones(DCALbrDecoder *s, int ch, float *values, int group, int group_sf, int synth_idx)
Synthesise tones in the given group for the given tonal subframe.
static int parse_ts2_chunk(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
static void parse_grid_3(DCALbrDecoder *s, int ch1, int ch2, int sb, int flag)
static int parse_st_code(GetBitContext *s, int min_v)
static int init_sample_rate(DCALbrDecoder *s)
int ff_dca_lbr_parse(DCALbrDecoder *s, const uint8_t *data, DCAExssAsset *asset)
static int parse_grid_1_chunk(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
av_cold void ff_dca_lbr_close(DCALbrDecoder *s)
static void parse_ch(DCALbrDecoder *s, int ch, int sb, int quant_level, int flag)
Parse time samples for one subband, filling truncated samples with randomness.
static int parse_lfe_16(DCALbrDecoder *s)
static int parse_lpc(DCALbrDecoder *s, int ch1, int ch2, int start_sb, int end_sb)
static const int8_t channel_reorder_nolfe[7][5]
av_cold void ff_dca_lbr_flush(DCALbrDecoder *s)
static void convert_lpc(float *coeff, const int *codes)
Convert from reflection coefficients to direct form coefficients.
@ LBR_CHUNK_TONAL_SCF_GRP_3
@ LBR_CHUNK_RES_TS_1_LAST
@ LBR_CHUNK_RES_GRID_LR_LAST
@ LBR_CHUNK_TONAL_SCF_GRP_2
@ LBR_CHUNK_RES_GRID_HR_LAST
@ LBR_CHUNK_TONAL_SCF_GRP_1
@ LBR_CHUNK_RES_TS_2_LAST
@ LBR_CHUNK_TONAL_SCF_GRP_5
@ LBR_CHUNK_FRAME_NO_CSUM
@ LBR_CHUNK_TONAL_SCF_GRP_4
static int parse_vlc(GetBitContext *s, const VLC *vlc, int nb_bits, int max_depth)
static int parse_ts(DCALbrDecoder *s, int ch1, int ch2, int start_sb, int end_sb, int flag)
static int parse_grid_2(DCALbrDecoder *s, int ch1, int ch2, int start_sb, int end_sb, int flag)
static int parse_scale_factors(DCALbrDecoder *s, uint8_t *scf)
static void base_func_synth(DCALbrDecoder *s, int ch, float *values, int sf)
Synthesise all tones in all groups for the given residual subframe.
static int parse_lfe_24(DCALbrDecoder *s)
av_cold void ff_dca_lbr_init_tables(void)
@ DCA_LBR_HEADER_SYNC_ONLY
@ DCA_LBR_HEADER_DECODER_INIT
#define DCA_LBR_CHANNELS_TOTAL
#define DCA_LBR_TIME_SAMPLES
#define DCA_LBR_TIME_HISTORY
const float ff_dca_lfe_step_size_24[144]
const float ff_dca_rsd_level_5[5]
const uint8_t ff_dca_scf_to_grid_2[32]
const int8_t ff_dca_lfe_delta_index_24[32]
const float ff_dca_rsd_level_8[8]
const float ff_dca_rsd_level_2b[2]
const uint8_t ff_dca_freq_to_sb[32]
const float ff_dca_bank_coeff[10]
const float ff_dca_rsd_level_16[16]
const float ff_dca_quant_amp[57]
const float ff_dca_corr_cf[32][11]
const float ff_dca_rsd_level_2a[2]
const float ff_dca_lfe_step_size_16[101]
const int8_t ff_dca_lfe_delta_index_16[8]
const uint8_t ff_dca_grid_1_to_scf[11]
const uint16_t ff_dca_fst_amp[44]
const uint8_t ff_dca_grid_2_to_scf[3]
const float ff_dca_st_coeff[34]
const uint8_t ff_dca_rsd_pack_3_in_7[128][3]
const float ff_dca_long_window[128]
const uint8_t ff_dca_grid_1_weights[12][32]
const float ff_dca_rsd_level_3[3]
const uint8_t ff_dca_sb_reorder[8][8]
const uint16_t ff_dca_avg_g3_freqs[3]
const float ff_dca_lfe_iir[5][4]
const uint8_t ff_dca_scf_to_grid_1[32]
const uint16_t ff_dca_rsd_pack_5_in_8[256]
const float ff_dca_synth_env[32]
const int8_t ff_dca_ph0_shift[8]
VLC ff_dca_vlc_fst_rsd_amp
VLC ff_dca_vlc_tnl_grp[5]
#define DCA_FST_RSD_VLC_BITS
#define DCA_AVG_G3_VLC_BITS
#define DCA_TNL_GRP_VLC_BITS
#define DCA_ST_GRID_VLC_BITS
#define DCA_TNL_SCF_VLC_BITS
#define DCA_GRID_VLC_BITS
#define DCA_RSD_APPRX_VLC_BITS
#define DCA_DAMP_VLC_BITS
#define DCA_RSD_AMP_VLC_BITS
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_side_data_update_matrix_encoding(AVFrame *frame, enum AVMatrixEncoding matrix_encoding)
Add or update AV_FRAME_DATA_MATRIXENCODING side data.
#define AV_PROFILE_DTS_EXPRESS
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define AV_EF_CAREFUL
consider things that violate the spec, are fast to calculate and have not been seen in the wild as er...
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
#define AV_CH_LAYOUT_5POINT0
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_SURROUND
#define AV_CH_LAYOUT_STEREO
@ AV_MATRIX_ENCODING_NONE
#define AV_CH_FRONT_CENTER
#define AV_CH_LOW_FREQUENCY
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
Allocate and clear a buffer, reusing the given one if large enough.
@ AV_SAMPLE_FMT_FLTP
float, planar
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static int shift(int a, int b)
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
Memory handling functions.
#define LOCAL_ALIGNED_32(t, v,...)
#define FF_ARRAY_ELEMS(a)
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int64_t bit_rate
the average bitrate
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int sample_rate
samples per second
This structure describes decoded (raw) audio or video data.
int request_channel_layout
Converted from avctx.request_channel_layout.
int lbr_offset
Offset to LBR component from start of substream.
int lbr_size
Size of LBR component in extension substream.
uint8_t amp[DCA_LBR_CHANNELS]
Per-channel amplitude.
uint8_t phs[DCA_LBR_CHANNELS]
Per-channel phase.
uint8_t f_delt
Difference between original and center frequency.
uint8_t ph_rot
Phase rotation.
uint8_t x_freq
Spectral line offset.
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
@ AV_TX_FULL_IMDCT
Performs a full inverse MDCT rather than leaving out samples that can be derived through symmetry.
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respectively.
static const double coeff[2][5]
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)