54 #define DCA_PRIM_CHANNELS_MAX (7)
55 #define DCA_SUBBANDS (64)
56 #define DCA_ABITS_MAX (32)
57 #define DCA_SUBSUBFRAMES_MAX (4)
58 #define DCA_SUBFRAMES_MAX (16)
59 #define DCA_BLOCKS_MAX (16)
60 #define DCA_LFE_MAX (3)
61 #define DCA_CHSETS_MAX (4)
62 #define DCA_CHSET_CHANS_MAX (8)
186 #define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96)
235 1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 3
239 { 0, -1, -1, -1, -1, -1, -1, -1, -1},
240 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
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 { 2, 0, 1, -1, -1, -1, -1, -1, -1},
245 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
246 { 2, 0, 1, 4, -1, -1, -1, -1, -1},
247 { 0, 1, 3, 4, -1, -1, -1, -1, -1},
248 { 2, 0, 1, 4, 5, -1, -1, -1, -1},
249 { 3, 4, 0, 1, 5, 6, -1, -1, -1},
250 { 2, 0, 1, 4, 5, 6, -1, -1, -1},
251 { 0, 6, 4, 5, 2, 3, -1, -1, -1},
252 { 4, 2, 5, 0, 1, 6, 7, -1, -1},
253 { 5, 6, 0, 1, 7, 3, 8, 4, -1},
254 { 4, 2, 5, 0, 1, 6, 8, 7, -1},
258 { 0, 2, -1, -1, -1, -1, -1, -1, -1},
259 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
260 { 0, 1, 3, -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 { 2, 0, 1, 4, -1, -1, -1, -1, -1},
264 { 0, 1, 3, 4, -1, -1, -1, -1, -1},
265 { 2, 0, 1, 4, 5, -1, -1, -1, -1},
266 { 0, 1, 4, 5, 3, -1, -1, -1, -1},
267 { 2, 0, 1, 5, 6, 4, -1, -1, -1},
268 { 3, 4, 0, 1, 6, 7, 5, -1, -1},
269 { 2, 0, 1, 4, 5, 6, 7, -1, -1},
270 { 0, 6, 4, 5, 2, 3, 7, -1, -1},
271 { 4, 2, 5, 0, 1, 7, 8, 6, -1},
272 { 5, 6, 0, 1, 8, 3, 9, 4, 7},
273 { 4, 2, 5, 0, 1, 6, 9, 8, 7},
277 { 0, -1, -1, -1, -1, -1, -1, -1, -1},
278 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
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 { 2, 0, 1, -1, -1, -1, -1, -1, -1},
283 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
284 { 2, 0, 1, 3, -1, -1, -1, -1, -1},
285 { 0, 1, 2, 3, -1, -1, -1, -1, -1},
286 { 2, 0, 1, 3, 4, -1, -1, -1, -1},
287 { 2, 3, 0, 1, 4, 5, -1, -1, -1},
288 { 2, 0, 1, 3, 4, 5, -1, -1, -1},
289 { 0, 5, 3, 4, 1, 2, -1, -1, -1},
290 { 3, 2, 4, 0, 1, 5, 6, -1, -1},
291 { 4, 5, 0, 1, 6, 2, 7, 3, -1},
292 { 3, 2, 4, 0, 1, 5, 7, 6, -1},
296 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
297 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
298 { 0, 1, 2, -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 { 2, 0, 1, 3, -1, -1, -1, -1, -1},
302 { 0, 1, 2, 3, -1, -1, -1, -1, -1},
303 { 2, 0, 1, 3, 4, -1, -1, -1, -1},
304 { 0, 1, 3, 4, 2, -1, -1, -1, -1},
305 { 2, 0, 1, 4, 5, 3, -1, -1, -1},
306 { 2, 3, 0, 1, 5, 6, 4, -1, -1},
307 { 2, 0, 1, 3, 4, 5, 6, -1, -1},
308 { 0, 5, 3, 4, 1, 2, 6, -1, -1},
309 { 3, 2, 4, 0, 1, 6, 7, 5, -1},
310 { 4, 5, 0, 1, 7, 2, 8, 3, 6},
311 { 3, 2, 4, 0, 1, 5, 8, 7, 6},
314 #define DCA_DOLBY 101
316 #define DCA_CHANNEL_BITS 6
317 #define DCA_CHANNEL_MASK 0x3F
321 #define HEADER_SIZE 14
323 #define DCA_MAX_FRAME_SIZE 16384
324 #define DCA_MAX_EXSS_HEADER_SIZE 4096
326 #define DCA_BUFFER_PADDING_SIZE 1024
445 uint32_t xxch_spk_masks[4];
446 int xxch_chset_nch[4];
452 int8_t xxch_order_tab[32];
459 int mix_config_num_ch[4];
472 0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,
473 5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,
474 5572, 5604, 5668, 5796, 5860, 5892, 6412, 6668, 6796, 7308, 7564,
475 7820, 8076, 8620, 9132, 9388, 9910, 10166, 10680, 11196, 11726, 12240,
476 12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 18264,
477 18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622,
482 static int vlcs_initialized = 0;
484 static VLC_TYPE dca_table[23622][2];
486 if (vlcs_initialized)
489 dca_bitalloc_index.
offset = 1;
490 dca_bitalloc_index.
wrap = 2;
491 for (i = 0; i < 5; i++) {
498 dca_scalefactor.
offset = -64;
499 dca_scalefactor.
wrap = 2;
500 for (i = 0; i < 5; i++) {
509 for (i = 0; i < 4; i++) {
517 for (i = 0; i < 10; i++)
518 for (j = 0; j < 7; j++) {
522 dca_smpl_bitalloc[i + 1].
wrap = 1 + (j > 4);
532 vlcs_initialized = 1;
547 i <= s->xxch_chset && !(mask & xxch_ch); mask = s->
xxch_spk_masks[++i])
548 base += av_popcount(mask);
550 return base + av_popcount(mask & (xxch_ch - 1));
557 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
558 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
559 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
560 int hdr_pos = 0, hdr_size = 0;
561 float sign, mag, scale_factor;
562 int this_chans, acc_mask;
563 int embedded_downmix;
604 if (mask[j] & (1 << i)) {
607 "DCA-XXCH: dmix to LFE1 not supported.\n");
612 sign = (coeff & 64) ? 1.0 : -1.0;
644 for (j = 1; j < 11; j++)
649 for (j = 0; j < 11; j++)
653 for (j = 1; j < 11; j++)
666 if (hdr_pos + 8 * hdr_size > i)
690 for (j = 0; j < 11; j++)
694 for (j = 0; j < 11; j++)
791 "source pcm resolution: %i (%i bits/sample)\n",
811 value = av_clip(value, 0, (1 << log2range) - 1);
812 }
else if (level < 8) {
813 if (level + 1 > log2range) {
860 "Invalid bit allocation index\n");
868 av_dlog(s->
avctx,
"bitalloc index [%i][%i] too big (%i)\n",
880 k < s->vq_start_subband[j] && s->
bitalloc[j][k] > 0) {
891 const uint32_t *scale_table;
892 int scale_sum, log_size;
944 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
951 "Joint stereo coding not supported\n");
968 "Invalid channel mode %d\n", am);
998 if (!base_channel && s->
lfe) {
1001 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1005 for (j = lfe_samples; j < lfe_end_sample; j++) {
1021 for (j = lfe_samples; j < lfe_end_sample; j++)
1040 "prediction coefs: %f, %f, %f, %f\n",
1072 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++)
1090 if (!base_channel && s->
lfe) {
1091 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1095 for (j = lfe_samples; j < lfe_end_sample; j++)
1105 float samples_in[32][8],
float *samples_out,
1108 const float *prCoeff;
1114 scale *= sqrt(1 / 8.0);
1122 for (i = sb_act; i < 32; i++)
1126 for (subindex = 0; subindex < 8; subindex++) {
1128 for (i = 0; i < sb_act; i++) {
1129 unsigned sign = (i - 1) & 2;
1130 uint32_t
v =
AV_RN32A(&samples_in[i][subindex]) ^ sign << 30;
1138 samples_out, s->
raXin, scale);
1144 int num_deci_sample,
float *samples_in,
1145 float *samples_out,
float scale)
1156 const float *prCoeff;
1160 if (decimation_select == 1) {
1168 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
1169 s->
dcadsp.
lfe_fir(samples_out, samples_in, prCoeff, decifactor, scale);
1171 samples_out += 2 * decifactor;
1176 #define MIX_REAR1(samples, s1, rs, coef) \
1177 samples[0][i] += samples[s1][i] * coef[rs][0]; \
1178 samples[1][i] += samples[s1][i] * coef[rs][1];
1180 #define MIX_REAR2(samples, s1, s2, rs, coef) \
1181 samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
1182 samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
1184 #define MIX_FRONT3(samples, coef) \
1185 t = samples[c][i]; \
1186 u = samples[l][i]; \
1187 v = samples[r][i]; \
1188 samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
1189 samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
1191 #define DOWNMIX_TO_STEREO(op1, op2) \
1192 for (i = 0; i < 256; i++) { \
1199 const int8_t *channel_mapping)
1201 int c, l,
r, sl, sr,
s;
1222 c = channel_mapping[0];
1223 l = channel_mapping[1];
1224 r = channel_mapping[2];
1228 s = channel_mapping[2];
1232 c = channel_mapping[0];
1233 l = channel_mapping[1];
1234 r = channel_mapping[2];
1235 s = channel_mapping[3];
1240 sl = channel_mapping[2];
1241 sr = channel_mapping[3];
1245 c = channel_mapping[0];
1246 l = channel_mapping[1];
1247 r = channel_mapping[2];
1248 sl = channel_mapping[3];
1249 sr = channel_mapping[4];
1257 #ifndef decode_blockcodes
1263 int offset = (levels - 1) >> 1;
1265 for (i = 0; i < 4; i++) {
1266 int div =
FASTDIV(code, levels);
1267 values[i] = code - offset - div * levels;
1284 #ifndef int8x8_fmul_int32
1287 float fscale = scale / 16.0;
1289 for (i = 0; i < 8; i++)
1290 dst[i] = src[i] * fscale;
1299 const float *quant_step_table;
1325 float quant_step_size = quant_step_table[abits];
1338 memset(subband_samples[k][l], 0, 8 *
sizeof(subband_samples[0][0][0]));
1342 float rscale = quant_step_size * s->
scale_factor[k][l][sfi] *
1345 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].
table) {
1348 int block_code1, block_code2,
size, levels, err;
1359 "ERROR: block code look-up failed\n");
1364 for (m = 0; m < 8; m++)
1369 for (m = 0; m < 8; m++)
1371 &dca_smpl_bitalloc[abits], sel);
1383 for (m = 0; m < 8; m++) {
1384 for (n = 1; n <= 4; n++)
1386 subband_samples[k][l][
m] +=
1388 subband_samples[k][l][m -
n] / 8192);
1390 subband_samples[k][l][
m] +=
1407 "Stream with high frequencies VQ coding\n");
1432 &subband_samples[k][l][4],
1433 4 *
sizeof(subband_samples[0][0][0]));
1463 1.0 / (256.0 * 32768.0));
1473 int aux_data_count = 0, i;
1480 if (!base_channel) {
1487 for (i = 0; i < aux_data_count; i++)
1554 return av_popcount(mask) +
1573 for (i = 0; i < channels; i++) {
1574 int mix_map_mask =
get_bits(gb, out_ch);
1575 int num_coeffs = av_popcount(mix_map_mask);
1588 int embedded_stereo = 0;
1589 int embedded_6ch = 0;
1590 int drc_code_present;
1623 int spkr_remap_sets;
1624 int spkr_mask_size = 16;
1633 spkr_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
1639 for (i = 0; i < spkr_remap_sets; i++) {
1644 for (i = 0; i < spkr_remap_sets; i++) {
1645 int num_dec_ch_remaps =
get_bits(&s->
gb, 5) + 1;
1649 for (j = 0; j < num_spkrs[i]; j++) {
1651 int num_dec_ch = av_popcount(remap_dec_ch_mask);
1662 if (drc_code_present)
1668 if (drc_code_present && embedded_stereo)
1692 if (embedded_stereo)
1698 case 0: extensions_mask =
get_bits(&s->
gb, 12);
break;
1701 case 3: extensions_mask = 0;
break;
1725 "DTS extensions detection mismatch (%d, %d)\n",
1739 int hdr_size, num_chsets, xbr_tmode, hdr_pos;
1740 int i, j, k, l, chset, chan_base;
1750 for(i = 0; i < num_chsets; i++)
1755 for(i = 0; i < num_chsets; i++) {
1758 for(j = 0; j < n_xbr_ch[i]; j++)
1759 active_bands[i][j] =
get_bits(&s->
gb, k) + 1;
1764 if(hdr_pos + hdr_size * 8 > i)
1769 for(chset = 0, chan_base = 0;
1770 chset < num_chsets && chan_base + n_xbr_ch[chset] <= s->
prim_channels;
1771 chan_base += n_xbr_ch[chset++]) {
1773 int subsubframe = 0;
1779 if(subsubframe == 0) {
1781 for(i = 0; i < n_xbr_ch[chset]; i++) {
1785 for(i = 0; i < n_xbr_ch[chset]; i++) {
1786 get_array(&s->
gb, abits_high[i], active_bands[chset][i], anctemp[i]);
1789 for(i = 0; i < n_xbr_ch[chset]; i++) {
1791 if(anctemp[i] < 1) {
1798 for(i = 0; i < n_xbr_ch[chset]; i++) {
1799 const uint32_t *scale_table;
1810 for(j = 0; j < active_bands[chset][i]; j++) {
1811 if(abits_high[i][j] > 0) {
1812 scale_table_high[i][j][0] =
1816 scale_table_high[i][j][1] =
1825 for(i = 0; i < n_xbr_ch[chset]; i++) {
1826 for(j = 0; j < active_bands[chset][i]; j++) {
1827 const int xbr_abits = abits_high[i][j];
1830 const float rscale = quant_step_size * scale_table_high[i][j][sfi];
1840 int block_code1, block_code2,
size, levels, err;
1851 "ERROR: DTS-XBR: block code look-up failed\n");
1857 for(l = 0; l < 8; l++)
1858 subband_samples[l] += (
float)block[l] * rscale;
1879 if(start_posn + chset_fsize[chset] * 8 != i) {
1880 j = start_posn + chset_fsize[chset] * 8 - i;
1883 " skipping further than expected (%d bits)\n", j);
1894 int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos;
1895 int i, chset, base_channel, chstart, fsize[8];
1904 for (i = 0; i < num_chsets; i++)
1914 if (hdr_pos + hdr_size * 8 > i)
1917 for (chset = 0; chset < num_chsets; chset++) {
1930 "Error decoding DTS-XXCH extension\n");
1937 if (chstart + fsize[chset] * 8 > i)
1955 int active_ss_mask[8];
1970 hdrsize =
get_bits(&s->
gb, 8 + 4 * blownup) + 1;
1985 if (num_audiop > 1) {
1987 "Multiple DTS-HD audio presentations");
1993 if (num_assets > 1) {
1999 for (i = 0; i < num_audiop; i++)
2000 active_ss_mask[i] =
get_bits(&s->
gb, ss_index + 1);
2002 for (i = 0; i < num_audiop; i++)
2003 for (j = 0; j <= ss_index; j++)
2004 if (active_ss_mask[i] & (1 << j))
2009 int mix_out_mask_size;
2012 mix_out_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
2016 int mix_out_mask =
get_bits(&s->
gb, mix_out_mask_size);
2022 for (i = 0; i < num_assets; i++)
2025 for (i = 0; i < num_assets; i++) {
2033 if (num_assets > 0) {
2035 if (start_posn + hdrsize * 8 > j)
2038 for (i = 0; i < num_assets; i++) {
2043 if (mkr == 0x655e315e) {
2045 }
else if (mkr == 0x47004a03) {
2050 "DTS-ExSS: unknown marker = 0x%08x\n", mkr);
2055 if (start_posn + asset_size[i] * 8 > j)
2066 int *got_frame_ptr,
AVPacket *avpkt)
2070 int buf_size = avpkt->
size;
2074 int num_core_channels = 0;
2076 float **samples_flt;
2081 int channels, full_channels;
2144 int ext_amode, xch_fsize;
2161 if ((ext_amode =
get_bits(&s->
gb, 4)) != 1) {
2163 " supported!\n", ext_amode);
2233 && avctx->request_channels
2236 if (s->
amode < 16) {
2239 if (s->
xch_present && (!avctx->request_channels ||
2240 avctx->request_channels
2241 > num_core_channels + !!s->
lfe)) {
2252 channels = num_core_channels + !!s->
lfe;
2261 if (channels > !!s->
lfe &&
2276 static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
2282 "Non standard configuration %d !\n", s->
amode);
2291 if (avctx->request_channels > 0
2293 channels = num_core_channels + !!s->
lfe;
2295 <= avctx->request_channels; i++) {
2309 if (channel_mask & (1 << i)) {
2316 if (av_popcount(channel_mask) != av_popcount(channel_layout)) {
2318 "DTS-XXCH: Inconsistant avcodec/dts channel layouts\n");
2326 for (chset = -1, j = 0; chset < s->
xxch_chset; ++chset) {
2332 posn = av_popcount(channel_layout & (lavc - 1));
2340 for (i = 0; i < channels; i++)
2376 full_channels - channels,
2386 for (ch = 0; ch < channels; ch++)
2388 for (; ch < full_channels; ch++)
2406 ch = num_core_channels;
2407 for (chset = 0; chset < s->
xxch_chset; chset++) {
2412 for (j = ch; j < endch; j++) {
2413 if (mask & (1 << j)) {
2415 for (k = 0; k < endch; k++) {
2428 if ((mask & (1 << ch)) && s->
xxch_dmix_sf[chset] != 1.0f) {
2431 for (j = 0; j < ch; j++) {
2433 for (k = 0; k < 256; k++)
2434 src_chan[k] *= scale;
2440 for (k = 0; k < 256; k++)
2441 src_chan[k] *= scale;
2453 for (i = 0; i < 2 * s->
lfe * 4; i++)
2486 avctx->request_channels == 2) {
2487 avctx->
channels = avctx->request_channels;