56 #define DCA_PRIM_CHANNELS_MAX (7)
57 #define DCA_SUBBANDS (64)
58 #define DCA_ABITS_MAX (32)
59 #define DCA_SUBSUBFRAMES_MAX (4)
60 #define DCA_SUBFRAMES_MAX (16)
61 #define DCA_BLOCKS_MAX (16)
62 #define DCA_LFE_MAX (3)
63 #define DCA_CHSETS_MAX (4)
64 #define DCA_CHSET_CHANS_MAX (8)
188 #define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96)
237 1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 3
241 { 0, -1, -1, -1, -1, -1, -1, -1, -1},
242 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
243 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
244 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
245 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
246 { 2, 0, 1, -1, -1, -1, -1, -1, -1},
247 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
248 { 2, 0, 1, 4, -1, -1, -1, -1, -1},
249 { 0, 1, 3, 4, -1, -1, -1, -1, -1},
250 { 2, 0, 1, 4, 5, -1, -1, -1, -1},
251 { 3, 4, 0, 1, 5, 6, -1, -1, -1},
252 { 2, 0, 1, 4, 5, 6, -1, -1, -1},
253 { 0, 6, 4, 5, 2, 3, -1, -1, -1},
254 { 4, 2, 5, 0, 1, 6, 7, -1, -1},
255 { 5, 6, 0, 1, 7, 3, 8, 4, -1},
256 { 4, 2, 5, 0, 1, 6, 8, 7, -1},
260 { 0, 2, -1, -1, -1, -1, -1, -1, -1},
261 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
262 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
263 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
264 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
265 { 2, 0, 1, 4, -1, -1, -1, -1, -1},
266 { 0, 1, 3, 4, -1, -1, -1, -1, -1},
267 { 2, 0, 1, 4, 5, -1, -1, -1, -1},
268 { 0, 1, 4, 5, 3, -1, -1, -1, -1},
269 { 2, 0, 1, 5, 6, 4, -1, -1, -1},
270 { 3, 4, 0, 1, 6, 7, 5, -1, -1},
271 { 2, 0, 1, 4, 5, 6, 7, -1, -1},
272 { 0, 6, 4, 5, 2, 3, 7, -1, -1},
273 { 4, 2, 5, 0, 1, 7, 8, 6, -1},
274 { 5, 6, 0, 1, 8, 3, 9, 4, 7},
275 { 4, 2, 5, 0, 1, 6, 9, 8, 7},
279 { 0, -1, -1, -1, -1, -1, -1, -1, -1},
280 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
281 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
282 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
283 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
284 { 2, 0, 1, -1, -1, -1, -1, -1, -1},
285 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
286 { 2, 0, 1, 3, -1, -1, -1, -1, -1},
287 { 0, 1, 2, 3, -1, -1, -1, -1, -1},
288 { 2, 0, 1, 3, 4, -1, -1, -1, -1},
289 { 2, 3, 0, 1, 4, 5, -1, -1, -1},
290 { 2, 0, 1, 3, 4, 5, -1, -1, -1},
291 { 0, 5, 3, 4, 1, 2, -1, -1, -1},
292 { 3, 2, 4, 0, 1, 5, 6, -1, -1},
293 { 4, 5, 0, 1, 6, 2, 7, 3, -1},
294 { 3, 2, 4, 0, 1, 5, 7, 6, -1},
298 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
299 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
300 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
301 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
302 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
303 { 2, 0, 1, 3, -1, -1, -1, -1, -1},
304 { 0, 1, 2, 3, -1, -1, -1, -1, -1},
305 { 2, 0, 1, 3, 4, -1, -1, -1, -1},
306 { 0, 1, 3, 4, 2, -1, -1, -1, -1},
307 { 2, 0, 1, 4, 5, 3, -1, -1, -1},
308 { 2, 3, 0, 1, 5, 6, 4, -1, -1},
309 { 2, 0, 1, 3, 4, 5, 6, -1, -1},
310 { 0, 5, 3, 4, 1, 2, 6, -1, -1},
311 { 3, 2, 4, 0, 1, 6, 7, 5, -1},
312 { 4, 5, 0, 1, 7, 2, 8, 3, 6},
313 { 3, 2, 4, 0, 1, 5, 8, 7, 6},
316 #define DCA_DOLBY 101
318 #define DCA_CHANNEL_BITS 6
319 #define DCA_CHANNEL_MASK 0x3F
323 #define HEADER_SIZE 14
325 #define DCA_MAX_FRAME_SIZE 16384
326 #define DCA_MAX_EXSS_HEADER_SIZE 4096
328 #define DCA_BUFFER_PADDING_SIZE 1024
448 uint32_t xxch_spk_masks[4];
449 int xxch_chset_nch[4];
455 int8_t xxch_order_tab[32];
462 int mix_config_num_ch[4];
475 0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,
476 5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,
477 5572, 5604, 5668, 5796, 5860, 5892, 6412, 6668, 6796, 7308, 7564,
478 7820, 8076, 8620, 9132, 9388, 9910, 10166, 10680, 11196, 11726, 12240,
479 12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 18264,
480 18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622,
485 static int vlcs_initialized = 0;
487 static VLC_TYPE dca_table[23622][2];
489 if (vlcs_initialized)
492 dca_bitalloc_index.
offset = 1;
493 dca_bitalloc_index.
wrap = 2;
494 for (i = 0; i < 5; i++) {
501 dca_scalefactor.
offset = -64;
502 dca_scalefactor.
wrap = 2;
503 for (i = 0; i < 5; i++) {
512 for (i = 0; i < 4; i++) {
520 for (i = 0; i < 10; i++)
521 for (j = 0; j < 7; j++) {
525 dca_smpl_bitalloc[i + 1].
wrap = 1 + (j > 4);
535 vlcs_initialized = 1;
550 i <= s->xxch_chset && !(mask & xxch_ch); mask = s->
xxch_spk_masks[++i])
551 base += av_popcount(mask);
553 return base + av_popcount(mask & (xxch_ch - 1));
560 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
561 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
562 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
563 int hdr_pos = 0, hdr_size = 0;
564 float sign, mag, scale_factor;
565 int this_chans, acc_mask;
566 int embedded_downmix;
607 if (mask[j] & (1 << i)) {
610 "DCA-XXCH: dmix to LFE1 not supported.\n");
615 sign = (coeff & 64) ? 1.0 : -1.0;
647 for (j = 1; j < 11; j++)
652 for (j = 0; j < 11; j++)
656 for (j = 1; j < 11; j++)
669 if (hdr_pos + 8 * hdr_size > i)
693 for (j = 0; j < 11; j++)
697 for (j = 0; j < 11; j++)
794 "source pcm resolution: %i (%i bits/sample)\n",
814 value = av_clip(value, 0, (1 << log2range) - 1);
815 }
else if (level < 8) {
816 if (level + 1 > log2range) {
863 "Invalid bit allocation index\n");
871 av_dlog(s->
avctx,
"bitalloc index [%i][%i] too big (%i)\n",
883 k < s->vq_start_subband[j] && s->
bitalloc[j][k] > 0) {
894 const uint32_t *scale_table;
895 int scale_sum, log_size;
947 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
954 "Joint stereo coding not supported\n");
971 "Invalid channel mode %d\n", am);
1001 if (!base_channel && s->
lfe) {
1004 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1008 for (j = lfe_samples; j < lfe_end_sample; j++) {
1024 for (j = lfe_samples; j < lfe_end_sample; j++)
1043 "prediction coefs: %f, %f, %f, %f\n",
1075 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++)
1093 if (!base_channel && s->
lfe) {
1094 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1098 for (j = lfe_samples; j < lfe_end_sample; j++)
1108 float samples_in[32][8],
float *samples_out,
1111 const float *prCoeff;
1117 scale *= sqrt(1 / 8.0);
1125 for (i = sb_act; i < 32; i++)
1129 for (subindex = 0; subindex < 8; subindex++) {
1131 for (i = 0; i < sb_act; i++) {
1132 unsigned sign = (i - 1) & 2;
1133 uint32_t v =
AV_RN32A(&samples_in[i][subindex]) ^ sign << 30;
1141 samples_out, s->
raXin, scale);
1147 int num_deci_sample,
float *samples_in,
1148 float *samples_out,
float scale)
1159 const float *prCoeff;
1163 if (decimation_select == 1) {
1171 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
1172 s->
dcadsp.
lfe_fir(samples_out, samples_in, prCoeff, decifactor, scale);
1174 samples_out += 2 * decifactor;
1179 #define MIX_REAR1(samples, s1, rs, coef) \
1180 samples[0][i] += samples[s1][i] * coef[rs][0]; \
1181 samples[1][i] += samples[s1][i] * coef[rs][1];
1183 #define MIX_REAR2(samples, s1, s2, rs, coef) \
1184 samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
1185 samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
1187 #define MIX_FRONT3(samples, coef) \
1188 t = samples[c][i]; \
1189 u = samples[l][i]; \
1190 v = samples[r][i]; \
1191 samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
1192 samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
1194 #define DOWNMIX_TO_STEREO(op1, op2) \
1195 for (i = 0; i < 256; i++) { \
1202 const int8_t *channel_mapping)
1204 int c, l,
r, sl, sr, s;
1225 c = channel_mapping[0];
1226 l = channel_mapping[1];
1227 r = channel_mapping[2];
1231 s = channel_mapping[2];
1235 c = channel_mapping[0];
1236 l = channel_mapping[1];
1237 r = channel_mapping[2];
1238 s = channel_mapping[3];
1243 sl = channel_mapping[2];
1244 sr = channel_mapping[3];
1248 c = channel_mapping[0];
1249 l = channel_mapping[1];
1250 r = channel_mapping[2];
1251 sl = channel_mapping[3];
1252 sr = channel_mapping[4];
1260 #ifndef decode_blockcodes
1266 int offset = (levels - 1) >> 1;
1268 for (i = 0; i < 4; i++) {
1269 int div =
FASTDIV(code, levels);
1270 values[i] = code - offset - div * levels;
1287 #ifndef int8x8_fmul_int32
1290 float fscale = scale / 16.0;
1292 for (i = 0; i < 8; i++)
1293 dst[i] = src[i] * fscale;
1302 const float *quant_step_table;
1328 float quant_step_size = quant_step_table[abits];
1341 memset(subband_samples[k][l], 0, 8 *
sizeof(subband_samples[0][0][0]));
1345 float rscale = quant_step_size * s->
scale_factor[k][l][sfi] *
1348 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].
table) {
1351 int block_code1, block_code2,
size, levels, err;
1362 "ERROR: block code look-up failed\n");
1367 for (m = 0; m < 8; m++)
1372 for (m = 0; m < 8; m++)
1374 &dca_smpl_bitalloc[abits], sel);
1386 for (m = 0; m < 8; m++) {
1387 for (n = 1; n <= 4; n++)
1389 subband_samples[k][l][
m] +=
1391 subband_samples[k][l][m - n] / 8192);
1393 subband_samples[k][l][
m] +=
1410 "Stream with high frequencies VQ coding\n");
1435 &subband_samples[k][l][4],
1436 4 *
sizeof(subband_samples[0][0][0]));
1466 1.0 / (256.0 * 32768.0));
1476 int aux_data_count = 0, i;
1483 if (!base_channel) {
1490 for (i = 0; i < aux_data_count; i++)
1557 return av_popcount(mask) +
1576 for (i = 0; i < channels; i++) {
1577 int mix_map_mask =
get_bits(gb, out_ch);
1578 int num_coeffs = av_popcount(mix_map_mask);
1591 int embedded_stereo = 0;
1592 int embedded_6ch = 0;
1593 int drc_code_present;
1626 int spkr_remap_sets;
1627 int spkr_mask_size = 16;
1636 spkr_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
1642 for (i = 0; i < spkr_remap_sets; i++) {
1647 for (i = 0; i < spkr_remap_sets; i++) {
1648 int num_dec_ch_remaps =
get_bits(&s->
gb, 5) + 1;
1652 for (j = 0; j < num_spkrs[i]; j++) {
1654 int num_dec_ch = av_popcount(remap_dec_ch_mask);
1665 if (drc_code_present)
1671 if (drc_code_present && embedded_stereo)
1695 if (embedded_stereo)
1701 case 0: extensions_mask =
get_bits(&s->
gb, 12);
break;
1704 case 3: extensions_mask = 0;
break;
1728 "DTS extensions detection mismatch (%d, %d)\n",
1742 int hdr_size, num_chsets, xbr_tmode, hdr_pos;
1743 int i, j, k, l, chset, chan_base;
1753 for(i = 0; i < num_chsets; i++)
1758 for(i = 0; i < num_chsets; i++) {
1761 for(j = 0; j < n_xbr_ch[i]; j++)
1762 active_bands[i][j] =
get_bits(&s->
gb, k) + 1;
1767 if(hdr_pos + hdr_size * 8 > i)
1772 for(chset = 0, chan_base = 0;
1773 chset < num_chsets && chan_base + n_xbr_ch[chset] <= s->
prim_channels;
1774 chan_base += n_xbr_ch[chset++]) {
1776 int subsubframe = 0;
1782 if(subsubframe == 0) {
1784 for(i = 0; i < n_xbr_ch[chset]; i++) {
1788 for(i = 0; i < n_xbr_ch[chset]; i++) {
1789 get_array(&s->
gb, abits_high[i], active_bands[chset][i], anctemp[i]);
1792 for(i = 0; i < n_xbr_ch[chset]; i++) {
1794 if(anctemp[i] < 1) {
1801 for(i = 0; i < n_xbr_ch[chset]; i++) {
1802 const uint32_t *scale_table;
1813 for(j = 0; j < active_bands[chset][i]; j++) {
1814 if(abits_high[i][j] > 0) {
1815 scale_table_high[i][j][0] =
1819 scale_table_high[i][j][1] =
1828 for(i = 0; i < n_xbr_ch[chset]; i++) {
1829 for(j = 0; j < active_bands[chset][i]; j++) {
1830 const int xbr_abits = abits_high[i][j];
1833 const float rscale = quant_step_size * scale_table_high[i][j][sfi];
1843 int block_code1, block_code2,
size, levels, err;
1854 "ERROR: DTS-XBR: block code look-up failed\n");
1860 for(l = 0; l < 8; l++)
1861 subband_samples[l] += (
float)block[l] * rscale;
1882 if(start_posn + chset_fsize[chset] * 8 != i) {
1883 j = start_posn + chset_fsize[chset] * 8 - i;
1886 " skipping further than expected (%d bits)\n", j);
1897 int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos;
1898 int i, chset, base_channel, chstart, fsize[8];
1907 for (i = 0; i < num_chsets; i++)
1917 if (hdr_pos + hdr_size * 8 > i)
1920 for (chset = 0; chset < num_chsets; chset++) {
1933 "Error decoding DTS-XXCH extension\n");
1940 if (chstart + fsize[chset] * 8 > i)
1958 int active_ss_mask[8];
1973 hdrsize =
get_bits(&s->
gb, 8 + 4 * blownup) + 1;
1988 if (num_audiop > 1) {
1995 if (num_assets > 1) {
2001 for (i = 0; i < num_audiop; i++)
2002 active_ss_mask[i] =
get_bits(&s->
gb, ss_index + 1);
2004 for (i = 0; i < num_audiop; i++)
2005 for (j = 0; j <= ss_index; j++)
2006 if (active_ss_mask[i] & (1 << j))
2011 int mix_out_mask_size;
2014 mix_out_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
2018 int mix_out_mask =
get_bits(&s->
gb, mix_out_mask_size);
2024 for (i = 0; i < num_assets; i++)
2027 for (i = 0; i < num_assets; i++) {
2035 if (num_assets > 0) {
2037 if (start_posn + hdrsize * 8 > j)
2040 for (i = 0; i < num_assets; i++) {
2045 if (mkr == 0x655e315e) {
2047 }
else if (mkr == 0x47004a03) {
2052 "DTS-ExSS: unknown marker = 0x%08x\n", mkr);
2057 if (start_posn + asset_size[i] * 8 > j)
2068 int *got_frame_ptr,
AVPacket *avpkt)
2071 int buf_size = avpkt->
size;
2075 int num_core_channels = 0;
2077 float **samples_flt;
2082 int channels, full_channels;
2145 int ext_amode, xch_fsize;
2162 if ((ext_amode =
get_bits(&s->
gb, 4)) != 1) {
2164 " supported!\n", ext_amode);
2234 && avctx->request_channels
2237 if (s->
amode < 16) {
2240 if (s->
xch_present && (!avctx->request_channels ||
2241 avctx->request_channels
2242 > num_core_channels + !!s->
lfe)) {
2253 channels = num_core_channels + !!s->
lfe;
2262 if (channels > !!s->
lfe &&
2277 static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
2283 "Non standard configuration %d !\n", s->
amode);
2292 if (avctx->request_channels > 0
2294 channels = num_core_channels + !!s->
lfe;
2296 <= avctx->request_channels; i++) {
2310 if (channel_mask & (1 << i)) {
2317 if (av_popcount(channel_mask) != av_popcount(channel_layout)) {
2319 "DTS-XXCH: Inconsistant avcodec/dts channel layouts\n");
2327 for (chset = -1, j = 0; chset < s->
xxch_chset; ++chset) {
2333 posn = av_popcount(channel_layout & (lavc - 1));
2341 for (i = 0; i < channels; i++)
2379 full_channels - channels,
2389 for (ch = 0; ch < channels; ch++)
2391 for (; ch < full_channels; ch++)
2409 ch = num_core_channels;
2410 for (chset = 0; chset < s->
xxch_chset; chset++) {
2415 for (j = ch; j < endch; j++) {
2416 if (mask & (1 << j)) {
2418 for (k = 0; k < endch; k++) {
2431 if ((mask & (1 << ch)) && s->
xxch_dmix_sf[chset] != 1.0f) {
2434 for (j = 0; j < ch; j++) {
2436 for (k = 0; k < 256; k++)
2437 src_chan[k] *= scale;
2443 for (k = 0; k < 256; k++)
2444 src_chan[k] *= scale;
2456 for (i = 0; i < 2 * s->
lfe * 4; i++)
2490 avctx->request_channels == 2) {
2491 avctx->
channels = avctx->request_channels;