55 #define DCA_PRIM_CHANNELS_MAX (7)
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
328 #define DCA_NSYNCAUX 0x9A1105A0
455 uint32_t xxch_spk_masks[4];
456 int xxch_chset_nch[4];
462 int8_t xxch_order_tab[32];
469 int mix_config_num_ch[4];
484 0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,
485 5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,
486 5572, 5604, 5668, 5796, 5860, 5892, 6412, 6668, 6796, 7308, 7564,
487 7820, 8076, 8620, 9132, 9388, 9910, 10166, 10680, 11196, 11726, 12240,
488 12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 18264,
489 18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622,
494 static int vlcs_initialized = 0;
496 static VLC_TYPE dca_table[23622][2];
498 if (vlcs_initialized)
501 dca_bitalloc_index.
offset = 1;
502 dca_bitalloc_index.
wrap = 2;
503 for (i = 0; i < 5; i++) {
510 dca_scalefactor.
offset = -64;
511 dca_scalefactor.
wrap = 2;
512 for (i = 0; i < 5; i++) {
521 for (i = 0; i < 4; i++) {
529 for (i = 0; i < 10; i++)
530 for (j = 0; j < 7; j++) {
534 dca_smpl_bitalloc[i + 1].
wrap = 1 + (j > 4);
544 vlcs_initialized = 1;
559 i <= s->xxch_chset && !(mask & xxch_ch); mask = s->
xxch_spk_masks[++i])
560 base += av_popcount(mask);
562 return base + av_popcount(mask & (xxch_ch - 1));
569 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
570 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
571 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
572 int hdr_pos = 0, hdr_size = 0;
574 int this_chans, acc_mask;
575 int embedded_downmix;
605 if (coeff<1 || coeff>61) {
622 if (mask[j] & (1 << i)) {
625 "DCA-XXCH: dmix to LFE1 not supported.\n");
631 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",
830 value = av_clip(value, 0, (1 << log2range) - 1);
831 }
else if (level < 8) {
832 if (level + 1 > log2range) {
879 "Invalid bit allocation index\n");
887 av_dlog(s->
avctx,
"bitalloc index [%i][%i] too big (%i)\n",
899 k < s->vq_start_subband[j] && s->
bitalloc[j][k] > 0) {
910 const uint32_t *scale_table;
911 int scale_sum, log_size;
963 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
970 "Joint stereo coding not supported\n");
996 if (!base_channel && s->
lfe) {
999 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1003 for (j = lfe_samples; j < lfe_end_sample; j++) {
1019 for (j = lfe_samples; j < lfe_end_sample; j++)
1038 "prediction coefs: %f, %f, %f, %f\n",
1070 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++)
1078 if (!base_channel && s->
lfe) {
1079 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1083 for (j = lfe_samples; j < lfe_end_sample; j++)
1093 float samples_in[32][8],
float *samples_out,
1096 const float *prCoeff;
1100 scale *= sqrt(1 / 8.0);
1112 samples_out, s->
raXin, scale);
1116 int num_deci_sample,
float *samples_in,
1128 const float *prCoeff;
1132 if (decimation_select == 1) {
1140 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
1143 samples_out += 2 * 32 * (1 + idx);
1148 #define MIX_REAR1(samples, s1, rs, coef) \
1149 samples[0][i] += samples[s1][i] * coef[rs][0]; \
1150 samples[1][i] += samples[s1][i] * coef[rs][1];
1152 #define MIX_REAR2(samples, s1, s2, rs, coef) \
1153 samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
1154 samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
1156 #define MIX_FRONT3(samples, coef) \
1157 t = samples[c][i]; \
1158 u = samples[l][i]; \
1159 v = samples[r][i]; \
1160 samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
1161 samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
1163 #define DOWNMIX_TO_STEREO(op1, op2) \
1164 for (i = 0; i < 256; i++) { \
1171 const int8_t *channel_mapping)
1173 int c, l,
r, sl, sr,
s;
1188 c = channel_mapping[0];
1189 l = channel_mapping[1];
1190 r = channel_mapping[2];
1194 s = channel_mapping[2];
1198 c = channel_mapping[0];
1199 l = channel_mapping[1];
1200 r = channel_mapping[2];
1201 s = channel_mapping[3];
1206 sl = channel_mapping[2];
1207 sr = channel_mapping[3];
1211 c = channel_mapping[0];
1212 l = channel_mapping[1];
1213 r = channel_mapping[2];
1214 sl = channel_mapping[3];
1215 sr = channel_mapping[4];
1223 for (i = 0; i < 256; i++) {
1224 samples[0][i] += samples[lf_buf][i] * coef[lf_idx][0];
1225 samples[1][i] += samples[lf_buf][i] * coef[lf_idx][1];
1231 #ifndef decode_blockcodes
1237 int offset = (levels - 1) >> 1;
1239 for (i = 0; i < 4; i++) {
1240 int div =
FASTDIV(code, levels);
1241 values[i] = code - offset - div * levels;
1263 const float *quant_step_table;
1291 float quant_step_size = quant_step_table[abits];
1305 memset(
block + 8 * l, 0, 8 *
sizeof(
block[0]));
1309 rscale[l] = quant_step_size * s->
scale_factor[k][l][sfi] *
1312 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].
table) {
1315 int block_code1, block_code2,
size, levels, err;
1323 levels,
block + 8 * l);
1326 "ERROR: block code look-up failed\n");
1331 for (m = 0; m < 8; m++)
1336 for (m = 0; m < 8; m++)
1338 &dca_smpl_bitalloc[abits], sel);
1364 for (m = 1; m < 8; m++) {
1366 subband_samples[k][l][m - 1];
1367 for (n = 2; n <= 4; n++)
1370 subband_samples[k][l][m -
n];
1374 subband_samples[k][l][
m] += sum * (1.0f / 8192);
1385 "Stream with high frequencies VQ coding\n");
1451 int in,
out, aux_data_count, aux_data_end, reserved;
1459 if (!base_channel) {
1479 "Auxiliary Decode Time Stamp Flag");
1512 "Invalid mode %d for embedded downmix coefficients\n",
1519 if ((tmp & 0xFF) > 241) {
1521 "Invalid downmix coefficient code %"PRIu16
"\n",
1536 "Overread auxiliary data by %d bits\n", -reserved);
1538 }
else if (reserved) {
1540 "Core auxiliary data reserved content");
1609 return av_popcount(mask) +
1628 for (i = 0; i < channels; i++) {
1629 int mix_map_mask =
get_bits(gb, out_ch);
1630 int num_coeffs = av_popcount(mix_map_mask);
1643 int embedded_stereo = 0;
1644 int embedded_6ch = 0;
1645 int drc_code_present;
1678 int spkr_remap_sets;
1679 int spkr_mask_size = 16;
1688 spkr_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
1694 for (i = 0; i < spkr_remap_sets; i++) {
1699 for (i = 0; i < spkr_remap_sets; i++) {
1700 int num_dec_ch_remaps =
get_bits(&s->
gb, 5) + 1;
1704 for (j = 0; j < num_spkrs[i]; j++) {
1706 int num_dec_ch = av_popcount(remap_dec_ch_mask);
1717 if (drc_code_present)
1723 if (drc_code_present && embedded_stereo)
1747 if (embedded_stereo)
1753 case 0: extensions_mask =
get_bits(&s->
gb, 12);
break;
1756 case 3: extensions_mask = 0;
break;
1780 "DTS extensions detection mismatch (%d, %d)\n",
1794 int hdr_size, num_chsets, xbr_tmode, hdr_pos;
1795 int i, j, k, l, chset, chan_base;
1805 for(i = 0; i < num_chsets; i++)
1810 for(i = 0; i < num_chsets; i++) {
1813 for(j = 0; j < n_xbr_ch[i]; j++)
1814 active_bands[i][j] =
get_bits(&s->
gb, k) + 1;
1819 if(hdr_pos + hdr_size * 8 > i)
1824 for(chset = 0, chan_base = 0;
1825 chset < num_chsets && chan_base + n_xbr_ch[chset] <= s->
prim_channels;
1826 chan_base += n_xbr_ch[chset++]) {
1828 int subsubframe = 0;
1834 if(subsubframe == 0) {
1836 for(i = 0; i < n_xbr_ch[chset]; i++) {
1840 for(i = 0; i < n_xbr_ch[chset]; i++) {
1841 get_array(&s->
gb, abits_high[i], active_bands[chset][i], anctemp[i]);
1844 for(i = 0; i < n_xbr_ch[chset]; i++) {
1846 if(anctemp[i] < 1) {
1853 for(i = 0; i < n_xbr_ch[chset]; i++) {
1854 const uint32_t *scale_table;
1865 for(j = 0; j < active_bands[chset][i]; j++) {
1866 if(abits_high[i][j] > 0) {
1867 scale_table_high[i][j][0] =
1871 scale_table_high[i][j][1] =
1880 for(i = 0; i < n_xbr_ch[chset]; i++) {
1881 for(j = 0; j < active_bands[chset][i]; j++) {
1882 const int xbr_abits = abits_high[i][j];
1885 const float rscale = quant_step_size * scale_table_high[i][j][sfi];
1895 int block_code1, block_code2,
size, levels, err;
1906 "ERROR: DTS-XBR: block code look-up failed\n");
1912 for(l = 0; l < 8; l++)
1913 subband_samples[l] += (
float)block[l] * rscale;
1934 if(start_posn + chset_fsize[chset] * 8 != i) {
1935 j = start_posn + chset_fsize[chset] * 8 - i;
1938 " skipping further than expected (%d bits)\n", j);
1949 int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos;
1950 int i, chset, base_channel, chstart, fsize[8];
1959 for (i = 0; i < num_chsets; i++)
1969 if (hdr_pos + hdr_size * 8 > i)
1972 for (chset = 0; chset < num_chsets; chset++) {
1985 "Error decoding DTS-XXCH extension\n");
1992 if (chstart + fsize[chset] * 8 > i)
2010 int active_ss_mask[8];
2025 hdrsize =
get_bits(&s->
gb, 8 + 4 * blownup) + 1;
2040 if (num_audiop > 1) {
2042 "Multiple DTS-HD audio presentations");
2048 if (num_assets > 1) {
2054 for (i = 0; i < num_audiop; i++)
2055 active_ss_mask[i] =
get_bits(&s->
gb, ss_index + 1);
2057 for (i = 0; i < num_audiop; i++)
2058 for (j = 0; j <= ss_index; j++)
2059 if (active_ss_mask[i] & (1 << j))
2064 int mix_out_mask_size;
2067 mix_out_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
2071 int mix_out_mask =
get_bits(&s->
gb, mix_out_mask_size);
2079 for (i = 0; i < num_assets; i++)
2082 for (i = 0; i < num_assets; i++) {
2091 if (start_posn + hdrsize * 8 > j)
2094 for (i = 0; i < num_assets; i++) {
2099 if (mkr == 0x655e315e) {
2101 }
else if (mkr == 0x47004a03) {
2106 "DTS-ExSS: unknown marker = 0x%08x\n", mkr);
2111 if (start_posn + asset_size[i] * 8 > j)
2118 int sign = (code >> 8) - 1;
2120 return ((
dca_dmixtable[code] ^ sign) - sign) * (1.0 / (1 << 15));
2128 int *got_frame_ptr,
AVPacket *avpkt)
2132 int buf_size = avpkt->
size;
2136 int num_core_channels = 0;
2138 float **samples_flt;
2143 int channels, full_channels;
2191 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
2201 "Invalid channel mode %d\n", am);
2204 if (num_core_channels + !!s->
lfe >
2210 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
2216 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 " supported!\n", ext_amode);
2340 if (s->
amode < 16) {
2353 #if FF_API_REQUEST_CHANNELS
2372 channels = num_core_channels + !!s->
lfe;
2381 if (channels > !!s->
lfe &&
2390 if (num_core_channels + !!s->
lfe > 2 &&
2397 static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
2403 "Non standard configuration %d !\n", s->
amode);
2414 channels = num_core_channels + !!s->
lfe;
2430 if (channel_mask & (1 << i)) {
2437 if (av_popcount(channel_mask) != av_popcount(channel_layout)) {
2439 "DTS-XXCH: Inconsistent avcodec/dts channel layouts\n");
2447 for (chset = -1, j = 0; chset < s->
xxch_chset; ++chset) {
2453 posn = av_popcount(channel_layout & (lavc - 1));
2462 for (i = 0; i < channels; i++)
2498 full_channels - channels,
2508 for (ch = 0; ch < channels; ch++)
2510 for (; ch < full_channels; ch++)
2528 ch = num_core_channels;
2529 for (chset = 0; chset < s->
xxch_chset; chset++) {
2534 for (j = ch; j < endch; j++) {
2535 if (mask & (1 << j)) {
2537 for (k = 0; k < endch; k++) {
2550 if ((mask & (1 << ch)) && s->
xxch_dmix_sf[chset] != 1.0f) {
2553 for (j = 0; j < ch; j++) {
2555 for (k = 0; k < 256; k++)
2556 src_chan[k] *= scale;
2562 for (k = 0; k < 256; k++)
2563 src_chan[k] *= scale;
2575 for (i = 0; i < 2 * s->
lfe * 4; i++)
2616 #if FF_API_REQUEST_CHANNELS