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
447 uint32_t xxch_spk_masks[4];
448 int xxch_chset_nch[4];
454 int8_t xxch_order_tab[32];
461 int mix_config_num_ch[4];
474 0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,
475 5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,
476 5572, 5604, 5668, 5796, 5860, 5892, 6412, 6668, 6796, 7308, 7564,
477 7820, 8076, 8620, 9132, 9388, 9910, 10166, 10680, 11196, 11726, 12240,
478 12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 18264,
479 18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622,
484 static int vlcs_initialized = 0;
486 static VLC_TYPE dca_table[23622][2];
488 if (vlcs_initialized)
491 dca_bitalloc_index.
offset = 1;
492 dca_bitalloc_index.
wrap = 2;
493 for (i = 0; i < 5; i++) {
500 dca_scalefactor.
offset = -64;
501 dca_scalefactor.
wrap = 2;
502 for (i = 0; i < 5; i++) {
511 for (i = 0; i < 4; i++) {
519 for (i = 0; i < 10; i++)
520 for (j = 0; j < 7; j++) {
524 dca_smpl_bitalloc[i + 1].
wrap = 1 + (j > 4);
534 vlcs_initialized = 1;
549 i <= s->xxch_chset && !(mask & xxch_ch); mask = s->
xxch_spk_masks[++i])
550 base += av_popcount(mask);
552 return base + av_popcount(mask & (xxch_ch - 1));
559 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
560 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
561 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
562 int hdr_pos = 0, hdr_size = 0;
563 float sign, mag, scale_factor;
564 int this_chans, acc_mask;
565 int embedded_downmix;
606 if (mask[j] & (1 << i)) {
609 "DCA-XXCH: dmix to LFE1 not supported.\n");
614 sign = (coeff & 64) ? 1.0 : -1.0;
646 for (j = 1; j < 11; j++)
651 for (j = 0; j < 11; j++)
655 for (j = 1; j < 11; j++)
668 if (hdr_pos + 8 * hdr_size > i)
692 for (j = 0; j < 11; j++)
696 for (j = 0; j < 11; j++)
793 "source pcm resolution: %i (%i bits/sample)\n",
813 value = av_clip(value, 0, (1 << log2range) - 1);
814 }
else if (level < 8) {
815 if (level + 1 > log2range) {
862 "Invalid bit allocation index\n");
870 av_dlog(s->
avctx,
"bitalloc index [%i][%i] too big (%i)\n",
882 k < s->vq_start_subband[j] && s->
bitalloc[j][k] > 0) {
893 const uint32_t *scale_table;
894 int scale_sum, log_size;
946 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
953 "Joint stereo coding not supported\n");
970 "Invalid channel mode %d\n", am);
1000 if (!base_channel && s->
lfe) {
1003 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1007 for (j = lfe_samples; j < lfe_end_sample; j++) {
1023 for (j = lfe_samples; j < lfe_end_sample; j++)
1042 "prediction coefs: %f, %f, %f, %f\n",
1074 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++)
1092 if (!base_channel && s->
lfe) {
1093 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1097 for (j = lfe_samples; j < lfe_end_sample; j++)
1107 float samples_in[32][8],
float *samples_out,
1110 const float *prCoeff;
1116 scale *= sqrt(1 / 8.0);
1124 for (i = sb_act; i < 32; i++)
1128 for (subindex = 0; subindex < 8; subindex++) {
1130 for (i = 0; i < sb_act; i++) {
1131 unsigned sign = (i - 1) & 2;
1132 uint32_t
v =
AV_RN32A(&samples_in[i][subindex]) ^ sign << 30;
1140 samples_out, s->
raXin, scale);
1146 int num_deci_sample,
float *samples_in,
1147 float *samples_out,
float scale)
1158 const float *prCoeff;
1162 if (decimation_select == 1) {
1170 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
1171 s->
dcadsp.
lfe_fir(samples_out, samples_in, prCoeff, decifactor, scale);
1173 samples_out += 2 * decifactor;
1178 #define MIX_REAR1(samples, s1, rs, coef) \
1179 samples[0][i] += samples[s1][i] * coef[rs][0]; \
1180 samples[1][i] += samples[s1][i] * coef[rs][1];
1182 #define MIX_REAR2(samples, s1, s2, rs, coef) \
1183 samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
1184 samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
1186 #define MIX_FRONT3(samples, coef) \
1187 t = samples[c][i]; \
1188 u = samples[l][i]; \
1189 v = samples[r][i]; \
1190 samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
1191 samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
1193 #define DOWNMIX_TO_STEREO(op1, op2) \
1194 for (i = 0; i < 256; i++) { \
1201 const int8_t *channel_mapping)
1203 int c, l,
r, sl, sr, s;
1224 c = channel_mapping[0];
1225 l = channel_mapping[1];
1226 r = channel_mapping[2];
1230 s = channel_mapping[2];
1234 c = channel_mapping[0];
1235 l = channel_mapping[1];
1236 r = channel_mapping[2];
1237 s = channel_mapping[3];
1242 sl = channel_mapping[2];
1243 sr = channel_mapping[3];
1247 c = channel_mapping[0];
1248 l = channel_mapping[1];
1249 r = channel_mapping[2];
1250 sl = channel_mapping[3];
1251 sr = channel_mapping[4];
1259 #ifndef decode_blockcodes
1265 int offset = (levels - 1) >> 1;
1267 for (i = 0; i < 4; i++) {
1268 int div =
FASTDIV(code, levels);
1269 values[i] = code - offset - div * levels;
1286 #ifndef int8x8_fmul_int32
1289 float fscale = scale / 16.0;
1291 for (i = 0; i < 8; i++)
1292 dst[i] = src[i] * fscale;
1301 const float *quant_step_table;
1327 float quant_step_size = quant_step_table[abits];
1340 memset(subband_samples[k][l], 0, 8 *
sizeof(subband_samples[0][0][0]));
1344 float rscale = quant_step_size * s->
scale_factor[k][l][sfi] *
1347 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].
table) {
1350 int block_code1, block_code2,
size, levels, err;
1361 "ERROR: block code look-up failed\n");
1366 for (m = 0; m < 8; m++)
1371 for (m = 0; m < 8; m++)
1373 &dca_smpl_bitalloc[abits], sel);
1385 for (m = 0; m < 8; m++) {
1386 for (n = 1; n <= 4; n++)
1388 subband_samples[k][l][
m] +=
1390 subband_samples[k][l][m - n] / 8192);
1392 subband_samples[k][l][
m] +=
1409 "Stream with high frequencies VQ coding\n");
1434 &subband_samples[k][l][4],
1435 4 *
sizeof(subband_samples[0][0][0]));
1465 1.0 / (256.0 * 32768.0));
1475 int aux_data_count = 0, i;
1482 if (!base_channel) {
1489 for (i = 0; i < aux_data_count; i++)
1556 return av_popcount(mask) +
1575 for (i = 0; i < channels; i++) {
1576 int mix_map_mask =
get_bits(gb, out_ch);
1577 int num_coeffs = av_popcount(mix_map_mask);
1590 int embedded_stereo = 0;
1591 int embedded_6ch = 0;
1592 int drc_code_present;
1625 int spkr_remap_sets;
1626 int spkr_mask_size = 16;
1635 spkr_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
1641 for (i = 0; i < spkr_remap_sets; i++) {
1646 for (i = 0; i < spkr_remap_sets; i++) {
1647 int num_dec_ch_remaps =
get_bits(&s->
gb, 5) + 1;
1651 for (j = 0; j < num_spkrs[i]; j++) {
1653 int num_dec_ch = av_popcount(remap_dec_ch_mask);
1664 if (drc_code_present)
1670 if (drc_code_present && embedded_stereo)
1694 if (embedded_stereo)
1700 case 0: extensions_mask =
get_bits(&s->
gb, 12);
break;
1703 case 3: extensions_mask = 0;
break;
1727 "DTS extensions detection mismatch (%d, %d)\n",
1741 int hdr_size, num_chsets, xbr_tmode, hdr_pos;
1742 int i, j, k, l, chset, chan_base;
1752 for(i = 0; i < num_chsets; i++)
1757 for(i = 0; i < num_chsets; i++) {
1760 for(j = 0; j < n_xbr_ch[i]; j++)
1761 active_bands[i][j] =
get_bits(&s->
gb, k) + 1;
1766 if(hdr_pos + hdr_size * 8 > i)
1771 for(chset = 0, chan_base = 0;
1772 chset < num_chsets && chan_base + n_xbr_ch[chset] <= s->
prim_channels;
1773 chan_base += n_xbr_ch[chset++]) {
1775 int subsubframe = 0;
1781 if(subsubframe == 0) {
1783 for(i = 0; i < n_xbr_ch[chset]; i++) {
1787 for(i = 0; i < n_xbr_ch[chset]; i++) {
1788 get_array(&s->
gb, abits_high[i], active_bands[chset][i], anctemp[i]);
1791 for(i = 0; i < n_xbr_ch[chset]; i++) {
1793 if(anctemp[i] < 1) {
1800 for(i = 0; i < n_xbr_ch[chset]; i++) {
1801 const uint32_t *scale_table;
1812 for(j = 0; j < active_bands[chset][i]; j++) {
1813 if(abits_high[i][j] > 0) {
1814 scale_table_high[i][j][0] =
1818 scale_table_high[i][j][1] =
1827 for(i = 0; i < n_xbr_ch[chset]; i++) {
1828 for(j = 0; j < active_bands[chset][i]; j++) {
1829 const int xbr_abits = abits_high[i][j];
1832 const float rscale = quant_step_size * scale_table_high[i][j][sfi];
1842 int block_code1, block_code2,
size, levels, err;
1853 "ERROR: DTS-XBR: block code look-up failed\n");
1859 for(l = 0; l < 8; l++)
1860 subband_samples[l] += (
float)block[l] * rscale;
1881 if(start_posn + chset_fsize[chset] * 8 != i) {
1882 j = start_posn + chset_fsize[chset] * 8 - i;
1885 " skipping further than expected (%d bits)\n", j);
1896 int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos;
1897 int i, chset, base_channel, chstart, fsize[8];
1906 for (i = 0; i < num_chsets; i++)
1916 if (hdr_pos + hdr_size * 8 > i)
1919 for (chset = 0; chset < num_chsets; chset++) {
1932 "Error decoding DTS-XXCH extension\n");
1939 if (chstart + fsize[chset] * 8 > i)
1957 int active_ss_mask[8];
1972 hdrsize =
get_bits(&s->
gb, 8 + 4 * blownup) + 1;
1987 if (num_audiop > 1) {
1994 if (num_assets > 1) {
2000 for (i = 0; i < num_audiop; i++)
2001 active_ss_mask[i] =
get_bits(&s->
gb, ss_index + 1);
2003 for (i = 0; i < num_audiop; i++)
2004 for (j = 0; j <= ss_index; j++)
2005 if (active_ss_mask[i] & (1 << j))
2010 int mix_out_mask_size;
2013 mix_out_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
2017 int mix_out_mask =
get_bits(&s->
gb, mix_out_mask_size);
2023 for (i = 0; i < num_assets; i++)
2026 for (i = 0; i < num_assets; i++) {
2034 if (num_assets > 0) {
2036 if (start_posn + hdrsize * 8 > j)
2039 for (i = 0; i < num_assets; i++) {
2044 if (mkr == 0x655e315e) {
2046 }
else if (mkr == 0x47004a03) {
2051 "DTS-ExSS: unknown marker = 0x%08x\n", mkr);
2056 if (start_posn + asset_size[i] * 8 > j)
2067 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++)
2489 avctx->request_channels == 2) {
2490 avctx->
channels = avctx->request_channels;