56 #define DCA_PRIM_CHANNELS_MAX (7)
57 #define DCA_ABITS_MAX (32)
58 #define DCA_SUBSUBFRAMES_MAX (4)
59 #define DCA_SUBFRAMES_MAX (16)
60 #define DCA_BLOCKS_MAX (16)
61 #define DCA_LFE_MAX (3)
62 #define DCA_CHSETS_MAX (4)
63 #define DCA_CHSET_CHANS_MAX (8)
187 #define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96)
236 1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 3
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 { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
245 { 2, 0, 1, -1, -1, -1, -1, -1, -1 },
246 { 0, 1, 3, -1, -1, -1, -1, -1, -1 },
247 { 2, 0, 1, 4, -1, -1, -1, -1, -1 },
248 { 0, 1, 3, 4, -1, -1, -1, -1, -1 },
249 { 2, 0, 1, 4, 5, -1, -1, -1, -1 },
250 { 3, 4, 0, 1, 5, 6, -1, -1, -1 },
251 { 2, 0, 1, 4, 5, 6, -1, -1, -1 },
252 { 0, 6, 4, 5, 2, 3, -1, -1, -1 },
253 { 4, 2, 5, 0, 1, 6, 7, -1, -1 },
254 { 5, 6, 0, 1, 7, 3, 8, 4, -1 },
255 { 4, 2, 5, 0, 1, 6, 8, 7, -1 },
259 { 0, 2, -1, -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 { 0, 1, 3, -1, -1, -1, -1, -1, -1 },
264 { 2, 0, 1, 4, -1, -1, -1, -1, -1 },
265 { 0, 1, 3, 4, -1, -1, -1, -1, -1 },
266 { 2, 0, 1, 4, 5, -1, -1, -1, -1 },
267 { 0, 1, 4, 5, 3, -1, -1, -1, -1 },
268 { 2, 0, 1, 5, 6, 4, -1, -1, -1 },
269 { 3, 4, 0, 1, 6, 7, 5, -1, -1 },
270 { 2, 0, 1, 4, 5, 6, 7, -1, -1 },
271 { 0, 6, 4, 5, 2, 3, 7, -1, -1 },
272 { 4, 2, 5, 0, 1, 7, 8, 6, -1 },
273 { 5, 6, 0, 1, 8, 3, 9, 4, 7 },
274 { 4, 2, 5, 0, 1, 6, 9, 8, 7 },
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 { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
283 { 2, 0, 1, -1, -1, -1, -1, -1, -1 },
284 { 0, 1, 2, -1, -1, -1, -1, -1, -1 },
285 { 2, 0, 1, 3, -1, -1, -1, -1, -1 },
286 { 0, 1, 2, 3, -1, -1, -1, -1, -1 },
287 { 2, 0, 1, 3, 4, -1, -1, -1, -1 },
288 { 2, 3, 0, 1, 4, 5, -1, -1, -1 },
289 { 2, 0, 1, 3, 4, 5, -1, -1, -1 },
290 { 0, 5, 3, 4, 1, 2, -1, -1, -1 },
291 { 3, 2, 4, 0, 1, 5, 6, -1, -1 },
292 { 4, 5, 0, 1, 6, 2, 7, 3, -1 },
293 { 3, 2, 4, 0, 1, 5, 7, 6, -1 },
297 { 0, 1, -1, -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 { 0, 1, 2, -1, -1, -1, -1, -1, -1 },
302 { 2, 0, 1, 3, -1, -1, -1, -1, -1 },
303 { 0, 1, 2, 3, -1, -1, -1, -1, -1 },
304 { 2, 0, 1, 3, 4, -1, -1, -1, -1 },
305 { 0, 1, 3, 4, 2, -1, -1, -1, -1 },
306 { 2, 0, 1, 4, 5, 3, -1, -1, -1 },
307 { 2, 3, 0, 1, 5, 6, 4, -1, -1 },
308 { 2, 0, 1, 3, 4, 5, 6, -1, -1 },
309 { 0, 5, 3, 4, 1, 2, 6, -1, -1 },
310 { 3, 2, 4, 0, 1, 6, 7, 5, -1 },
311 { 4, 5, 0, 1, 7, 2, 8, 3, 6 },
312 { 3, 2, 4, 0, 1, 5, 8, 7, 6 },
315 #define DCA_DOLBY 101
317 #define DCA_CHANNEL_BITS 6
318 #define DCA_CHANNEL_MASK 0x3F
322 #define HEADER_SIZE 14
324 #define DCA_MAX_FRAME_SIZE 16384
325 #define DCA_MAX_EXSS_HEADER_SIZE 4096
327 #define DCA_BUFFER_PADDING_SIZE 1024
329 #define DCA_NSYNCAUX 0x9A1105A0
456 uint32_t xxch_spk_masks[4];
457 int xxch_chset_nch[4];
463 int8_t xxch_order_tab[32];
470 int mix_config_num_ch[4];
485 0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,
486 5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,
487 5572, 5604, 5668, 5796, 5860, 5892, 6412, 6668, 6796, 7308, 7564,
488 7820, 8076, 8620, 9132, 9388, 9910, 10166, 10680, 11196, 11726, 12240,
489 12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 18264,
490 18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622,
495 static int vlcs_initialized = 0;
497 static VLC_TYPE dca_table[23622][2];
499 if (vlcs_initialized)
502 dca_bitalloc_index.
offset = 1;
503 dca_bitalloc_index.
wrap = 2;
504 for (i = 0; i < 5; i++) {
511 dca_scalefactor.
offset = -64;
512 dca_scalefactor.
wrap = 2;
513 for (i = 0; i < 5; i++) {
522 for (i = 0; i < 4; i++) {
530 for (i = 0; i < 10; i++)
531 for (j = 0; j < 7; j++) {
535 dca_smpl_bitalloc[i + 1].
wrap = 1 + (j > 4);
545 vlcs_initialized = 1;
560 i <= s->xxch_chset && !(mask & xxch_ch); mask = s->
xxch_spk_masks[++i])
561 base += av_popcount(mask);
563 return base + av_popcount(mask & (xxch_ch - 1));
570 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
571 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
572 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
573 int hdr_pos = 0, hdr_size = 0;
575 int this_chans, acc_mask;
576 int embedded_downmix;
606 if (coeff<1 || coeff>61) {
623 if (mask[j] & (1 << i)) {
626 "DCA-XXCH: dmix to LFE1 not supported.\n");
632 if ((coeff&63)<1 || (coeff&63)>61) {
664 for (j = 1; j < 11; j++)
669 for (j = 0; j < 11; j++)
673 for (j = 1; j < 11; j++)
686 if (hdr_pos + 8 * hdr_size > i)
710 for (j = 0; j < 11; j++)
714 for (j = 0; j < 11; j++)
810 "source pcm resolution: %i (%i bits/sample)\n",
829 value = av_clip(value, 0, (1 << log2range) - 1);
830 }
else if (level < 8) {
831 if (level + 1 > log2range) {
878 "Invalid bit allocation index\n");
886 av_dlog(s->
avctx,
"bitalloc index [%i][%i] too big (%i)\n",
898 k < s->vq_start_subband[j] && s->
bitalloc[j][k] > 0) {
909 const uint32_t *scale_table;
910 int scale_sum, log_size;
962 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
969 "Joint stereo coding not supported\n");
995 if (!base_channel && s->
lfe) {
998 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1002 for (j = lfe_samples; j < lfe_end_sample; j++) {
1018 for (j = lfe_samples; j < lfe_end_sample; j++)
1037 "prediction coefs: %f, %f, %f, %f\n",
1069 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++)
1077 if (!base_channel && s->
lfe) {
1078 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1082 for (j = lfe_samples; j < lfe_end_sample; j++)
1092 float samples_in[32][8],
float *samples_out,
1095 const float *prCoeff;
1099 scale *= sqrt(1 / 8.0);
1111 samples_out, s->
raXin, scale);
1115 int num_deci_sample,
float *samples_in,
1127 const float *prCoeff;
1131 if (decimation_select == 1) {
1139 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
1142 samples_out += 2 * 32 * (1 + idx);
1147 #define MIX_REAR1(samples, s1, rs, coef) \
1148 samples[0][i] += samples[s1][i] * coef[rs][0]; \
1149 samples[1][i] += samples[s1][i] * coef[rs][1];
1151 #define MIX_REAR2(samples, s1, s2, rs, coef) \
1152 samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
1153 samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
1155 #define MIX_FRONT3(samples, coef) \
1156 t = samples[c][i]; \
1157 u = samples[l][i]; \
1158 v = samples[r][i]; \
1159 samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
1160 samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
1162 #define DOWNMIX_TO_STEREO(op1, op2) \
1163 for (i = 0; i < 256; i++) { \
1170 const int8_t *channel_mapping)
1172 int c, l,
r, sl, sr,
s;
1187 c = channel_mapping[0];
1188 l = channel_mapping[1];
1189 r = channel_mapping[2];
1193 s = channel_mapping[2];
1197 c = channel_mapping[0];
1198 l = channel_mapping[1];
1199 r = channel_mapping[2];
1200 s = channel_mapping[3];
1205 sl = channel_mapping[2];
1206 sr = channel_mapping[3];
1210 c = channel_mapping[0];
1211 l = channel_mapping[1];
1212 r = channel_mapping[2];
1213 sl = channel_mapping[3];
1214 sr = channel_mapping[4];
1222 for (i = 0; i < 256; i++) {
1223 samples[0][i] += samples[lf_buf][i] * coef[lf_idx][0];
1224 samples[1][i] += samples[lf_buf][i] * coef[lf_idx][1];
1229 #ifndef decode_blockcodes
1235 int offset = (levels - 1) >> 1;
1237 for (i = 0; i < 4; i++) {
1238 int div =
FASTDIV(code, levels);
1239 values[i] = code - offset - div * levels;
1261 const float *quant_step_table;
1289 float quant_step_size = quant_step_table[abits];
1303 memset(
block + 8 * l, 0, 8 *
sizeof(
block[0]));
1307 rscale[l] = quant_step_size * s->
scale_factor[k][l][sfi] *
1310 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].
table) {
1313 int block_code1, block_code2,
size, levels, err;
1321 levels,
block + 8 * l);
1324 "ERROR: block code look-up failed\n");
1329 for (m = 0; m < 8; m++)
1334 for (m = 0; m < 8; m++)
1336 &dca_smpl_bitalloc[abits], sel);
1361 for (m = 1; m < 8; m++) {
1363 subband_samples[k][l][m - 1];
1364 for (n = 2; n <= 4; n++)
1367 subband_samples[k][l][m -
n];
1371 subband_samples[k][l][
m] += sum * (1.0f / 8192);
1382 "Stream with high frequencies VQ coding\n");
1445 int in,
out, aux_data_count, aux_data_end, reserved;
1453 if (!base_channel) {
1473 "Auxiliary Decode Time Stamp Flag");
1506 "Invalid mode %d for embedded downmix coefficients\n",
1513 if ((tmp & 0xFF) > 241) {
1515 "Invalid downmix coefficient code %"PRIu16
"\n",
1530 "Overread auxiliary data by %d bits\n", -reserved);
1532 }
else if (reserved) {
1534 "Core auxiliary data reserved content");
1603 return av_popcount(mask) +
1622 for (i = 0; i < channels; i++) {
1623 int mix_map_mask =
get_bits(gb, out_ch);
1624 int num_coeffs = av_popcount(mix_map_mask);
1637 int embedded_stereo = 0;
1638 int embedded_6ch = 0;
1639 int drc_code_present;
1640 int extensions_mask = 0;
1672 int spkr_remap_sets;
1673 int spkr_mask_size = 16;
1682 spkr_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
1688 for (i = 0; i < spkr_remap_sets; i++) {
1693 for (i = 0; i < spkr_remap_sets; i++) {
1694 int num_dec_ch_remaps =
get_bits(&s->
gb, 5) + 1;
1698 for (j = 0; j < num_spkrs[i]; j++) {
1700 int num_dec_ch = av_popcount(remap_dec_ch_mask);
1710 if (drc_code_present)
1716 if (drc_code_present && embedded_stereo)
1740 if (embedded_stereo)
1756 extensions_mask = 0;
1781 "DTS extensions detection mismatch (%d, %d)\n",
1795 int hdr_size, num_chsets, xbr_tmode, hdr_pos;
1796 int i, j, k, l, chset, chan_base;
1806 for(i = 0; i < num_chsets; i++)
1811 for(i = 0; i < num_chsets; i++) {
1814 for(j = 0; j < n_xbr_ch[i]; j++)
1815 active_bands[i][j] =
get_bits(&s->
gb, k) + 1;
1820 if(hdr_pos + hdr_size * 8 > i)
1825 for(chset = 0, chan_base = 0;
1826 chset < num_chsets && chan_base + n_xbr_ch[chset] <= s->
prim_channels;
1827 chan_base += n_xbr_ch[chset++]) {
1829 int subsubframe = 0;
1835 if(subsubframe == 0) {
1837 for(i = 0; i < n_xbr_ch[chset]; i++) {
1841 for(i = 0; i < n_xbr_ch[chset]; i++) {
1842 get_array(&s->
gb, abits_high[i], active_bands[chset][i], anctemp[i]);
1845 for(i = 0; i < n_xbr_ch[chset]; i++) {
1847 if(anctemp[i] < 1) {
1854 for(i = 0; i < n_xbr_ch[chset]; i++) {
1855 const uint32_t *scale_table;
1866 for(j = 0; j < active_bands[chset][i]; j++) {
1867 if(abits_high[i][j] > 0) {
1868 scale_table_high[i][j][0] =
1872 scale_table_high[i][j][1] =
1881 for(i = 0; i < n_xbr_ch[chset]; i++) {
1882 for(j = 0; j < active_bands[chset][i]; j++) {
1883 const int xbr_abits = abits_high[i][j];
1886 const float rscale = quant_step_size * scale_table_high[i][j][sfi];
1896 int block_code1, block_code2,
size, levels, err;
1907 "ERROR: DTS-XBR: block code look-up failed\n");
1913 for(l = 0; l < 8; l++)
1914 subband_samples[l] += (
float)block[l] * rscale;
1935 if(start_posn + chset_fsize[chset] * 8 != i) {
1936 j = start_posn + chset_fsize[chset] * 8 - i;
1939 " skipping further than expected (%d bits)\n", j);
1950 int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos;
1951 int i, chset, base_channel, chstart, fsize[8];
1960 for (i = 0; i < num_chsets; i++)
1970 if (hdr_pos + hdr_size * 8 > i)
1973 for (chset = 0; chset < num_chsets; chset++) {
1986 "Error decoding DTS-XXCH extension\n");
1993 if (chstart + fsize[chset] * 8 > i)
2011 int active_ss_mask[8];
2026 hdrsize =
get_bits(&s->
gb, 8 + 4 * blownup) + 1;
2041 if (num_audiop > 1) {
2043 "Multiple DTS-HD audio presentations");
2049 if (num_assets > 1) {
2055 for (i = 0; i < num_audiop; i++)
2056 active_ss_mask[i] =
get_bits(&s->
gb, ss_index + 1);
2058 for (i = 0; i < num_audiop; i++)
2059 for (j = 0; j <= ss_index; j++)
2060 if (active_ss_mask[i] & (1 << j))
2065 int mix_out_mask_size;
2068 mix_out_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
2072 int mix_out_mask =
get_bits(&s->
gb, mix_out_mask_size);
2080 for (i = 0; i < num_assets; i++)
2083 for (i = 0; i < num_assets; i++) {
2092 if (start_posn + hdrsize * 8 > j)
2095 for (i = 0; i < num_assets; i++) {
2100 if (mkr == 0x655e315e) {
2102 }
else if (mkr == 0x47004a03) {
2107 "DTS-ExSS: unknown marker = 0x%08x\n", mkr);
2112 if (start_posn + asset_size[i] * 8 > j)
2119 int sign = (code >> 8) - 1;
2121 return ((
dca_dmixtable[code] ^ sign) - sign) * (1.0 / (1 << 15));
2129 int *got_frame_ptr,
AVPacket *avpkt)
2133 int buf_size = avpkt->
size;
2137 int num_core_channels = 0;
2139 float **samples_flt;
2144 int channels, full_channels;
2192 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
2202 "Invalid channel mode %d\n", am);
2205 if (num_core_channels + !!s->
lfe >
2211 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
2217 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
2248 int ext_amode, xch_fsize;
2265 if ((ext_amode =
get_bits(&s->
gb, 4)) != 1) {
2267 "XCh extension amode %d not supported!\n",
2341 if (s->
amode < 16) {
2354 #if FF_API_REQUEST_CHANNELS
2373 channels = num_core_channels + !!s->
lfe;
2382 if (channels > !!s->
lfe &&
2391 if (num_core_channels + !!s->
lfe > 2 &&
2398 static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
2404 "Non standard configuration %d !\n", s->
amode);
2415 channels = num_core_channels + !!s->
lfe;
2431 if (channel_mask & (1 << i)) {
2438 if (av_popcount(channel_mask) != av_popcount(channel_layout)) {
2440 "DTS-XXCH: Inconsistent avcodec/dts channel layouts\n");
2448 for (chset = -1, j = 0; chset < s->
xxch_chset; ++chset) {
2454 posn = av_popcount(channel_layout & (lavc - 1));
2463 for (i = 0; i < channels; i++)
2499 full_channels - channels,
2509 for (ch = 0; ch < channels; ch++)
2511 for (; ch < full_channels; ch++)
2529 ch = num_core_channels;
2530 for (chset = 0; chset < s->
xxch_chset; chset++) {
2535 for (j = ch; j < endch; j++) {
2536 if (mask & (1 << j)) {
2538 for (k = 0; k < endch; k++) {
2551 if ((mask & (1 << ch)) && s->
xxch_dmix_sf[chset] != 1.0f) {
2554 for (j = 0; j < ch; j++) {
2556 for (k = 0; k < 256; k++)
2557 src_chan[k] *= scale;
2563 for (k = 0; k < 256; k++)
2564 src_chan[k] *= scale;
2576 for (i = 0; i < 2 * s->
lfe * 4; i++)
2618 #if FF_API_REQUEST_CHANNELS