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];
482 0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,
483 5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,
484 5572, 5604, 5668, 5796, 5860, 5892, 6412, 6668, 6796, 7308, 7564,
485 7820, 8076, 8620, 9132, 9388, 9910, 10166, 10680, 11196, 11726, 12240,
486 12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 18264,
487 18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622,
492 static int vlcs_initialized = 0;
494 static VLC_TYPE dca_table[23622][2];
496 if (vlcs_initialized)
499 dca_bitalloc_index.
offset = 1;
500 dca_bitalloc_index.
wrap = 2;
501 for (i = 0; i < 5; i++) {
508 dca_scalefactor.
offset = -64;
509 dca_scalefactor.
wrap = 2;
510 for (i = 0; i < 5; i++) {
519 for (i = 0; i < 4; i++) {
527 for (i = 0; i < 10; i++)
528 for (j = 0; j < 7; j++) {
532 dca_smpl_bitalloc[i + 1].
wrap = 1 + (j > 4);
542 vlcs_initialized = 1;
557 i <= s->xxch_chset && !(mask & xxch_ch); mask = s->
xxch_spk_masks[++i])
558 base += av_popcount(mask);
560 return base + av_popcount(mask & (xxch_ch - 1));
567 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
568 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
569 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
570 int hdr_pos = 0, hdr_size = 0;
571 float sign, mag, scale_factor;
572 int this_chans, acc_mask;
573 int embedded_downmix;
614 if (mask[j] & (1 << i)) {
617 "DCA-XXCH: dmix to LFE1 not supported.\n");
622 sign = (coeff & 64) ? 1.0 : -1.0;
654 for (j = 1; j < 11; j++)
659 for (j = 0; j < 11; j++)
663 for (j = 1; j < 11; j++)
676 if (hdr_pos + 8 * hdr_size > i)
700 for (j = 0; j < 11; j++)
704 for (j = 0; j < 11; j++)
800 "source pcm resolution: %i (%i bits/sample)\n",
820 value = av_clip(value, 0, (1 << log2range) - 1);
821 }
else if (level < 8) {
822 if (level + 1 > log2range) {
869 "Invalid bit allocation index\n");
877 av_dlog(s->
avctx,
"bitalloc index [%i][%i] too big (%i)\n",
889 k < s->vq_start_subband[j] && s->
bitalloc[j][k] > 0) {
900 const uint32_t *scale_table;
901 int scale_sum, log_size;
953 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
960 "Joint stereo coding not supported\n");
986 if (!base_channel && s->
lfe) {
989 int lfe_samples = 2 * s->
lfe * (4 + block_index);
993 for (j = lfe_samples; j < lfe_end_sample; j++) {
1009 for (j = lfe_samples; j < lfe_end_sample; j++)
1028 "prediction coefs: %f, %f, %f, %f\n",
1060 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++)
1068 if (!base_channel && s->
lfe) {
1069 int lfe_samples = 2 * s->
lfe * (4 + block_index);
1073 for (j = lfe_samples; j < lfe_end_sample; j++)
1083 float samples_in[32][8],
float *samples_out,
1086 const float *prCoeff;
1090 scale *= sqrt(1 / 8.0);
1102 samples_out, s->
raXin, scale);
1106 int num_deci_sample,
float *samples_in,
1118 const float *prCoeff;
1122 if (decimation_select == 1) {
1130 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
1133 samples_out += 2 * 32 * (1 + idx);
1138 #define MIX_REAR1(samples, s1, rs, coef) \
1139 samples[0][i] += samples[s1][i] * coef[rs][0]; \
1140 samples[1][i] += samples[s1][i] * coef[rs][1];
1142 #define MIX_REAR2(samples, s1, s2, rs, coef) \
1143 samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
1144 samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
1146 #define MIX_FRONT3(samples, coef) \
1147 t = samples[c][i]; \
1148 u = samples[l][i]; \
1149 v = samples[r][i]; \
1150 samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
1151 samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
1153 #define DOWNMIX_TO_STEREO(op1, op2) \
1154 for (i = 0; i < 256; i++) { \
1161 const int8_t *channel_mapping)
1163 int c, l,
r, sl, sr,
s;
1178 c = channel_mapping[0];
1179 l = channel_mapping[1];
1180 r = channel_mapping[2];
1184 s = channel_mapping[2];
1188 c = channel_mapping[0];
1189 l = channel_mapping[1];
1190 r = channel_mapping[2];
1191 s = channel_mapping[3];
1196 sl = channel_mapping[2];
1197 sr = channel_mapping[3];
1201 c = channel_mapping[0];
1202 l = channel_mapping[1];
1203 r = channel_mapping[2];
1204 sl = channel_mapping[3];
1205 sr = channel_mapping[4];
1213 for (i = 0; i < 256; i++) {
1214 samples[0][i] += samples[lf_buf][i] * coef[lf_idx][0];
1215 samples[1][i] += samples[lf_buf][i] * coef[lf_idx][1];
1221 #ifndef decode_blockcodes
1227 int offset = (levels - 1) >> 1;
1229 for (i = 0; i < 4; i++) {
1230 int div =
FASTDIV(code, levels);
1231 values[i] = code - offset - div * levels;
1253 const float *quant_step_table;
1281 float quant_step_size = quant_step_table[abits];
1295 memset(
block + 8 * l, 0, 8 *
sizeof(
block[0]));
1299 rscale[l] = quant_step_size * s->
scale_factor[k][l][sfi] *
1302 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].
table) {
1305 int block_code1, block_code2,
size, levels, err;
1313 levels,
block + 8 * l);
1316 "ERROR: block code look-up failed\n");
1321 for (m = 0; m < 8; m++)
1326 for (m = 0; m < 8; m++)
1328 &dca_smpl_bitalloc[abits], sel);
1354 for (m = 1; m < 8; m++) {
1356 subband_samples[k][l][m - 1];
1357 for (n = 2; n <= 4; n++)
1360 subband_samples[k][l][m -
n];
1364 subband_samples[k][l][
m] += sum * (1.0f / 8192);
1375 "Stream with high frequencies VQ coding\n");
1441 int in,
out, aux_data_count, aux_data_end, reserved;
1449 if (!base_channel) {
1469 "Auxiliary Decode Time Stamp Flag");
1502 "Invalid mode %d for embedded downmix coefficients\n",
1509 if ((tmp & 0xFF) > 241) {
1511 "Invalid downmix coefficient code %"PRIu16
"\n",
1526 "Overread auxiliary data by %d bits\n", -reserved);
1528 }
else if (reserved) {
1530 "Core auxiliary data reserved content");
1599 return av_popcount(mask) +
1618 for (i = 0; i < channels; i++) {
1619 int mix_map_mask =
get_bits(gb, out_ch);
1620 int num_coeffs = av_popcount(mix_map_mask);
1633 int embedded_stereo = 0;
1634 int embedded_6ch = 0;
1635 int drc_code_present;
1668 int spkr_remap_sets;
1669 int spkr_mask_size = 16;
1678 spkr_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
1684 for (i = 0; i < spkr_remap_sets; i++) {
1689 for (i = 0; i < spkr_remap_sets; i++) {
1690 int num_dec_ch_remaps =
get_bits(&s->
gb, 5) + 1;
1694 for (j = 0; j < num_spkrs[i]; j++) {
1696 int num_dec_ch = av_popcount(remap_dec_ch_mask);
1707 if (drc_code_present)
1713 if (drc_code_present && embedded_stereo)
1737 if (embedded_stereo)
1743 case 0: extensions_mask =
get_bits(&s->
gb, 12);
break;
1746 case 3: extensions_mask = 0;
break;
1770 "DTS extensions detection mismatch (%d, %d)\n",
1784 int hdr_size, num_chsets, xbr_tmode, hdr_pos;
1785 int i, j, k, l, chset, chan_base;
1795 for(i = 0; i < num_chsets; i++)
1800 for(i = 0; i < num_chsets; i++) {
1803 for(j = 0; j < n_xbr_ch[i]; j++)
1804 active_bands[i][j] =
get_bits(&s->
gb, k) + 1;
1809 if(hdr_pos + hdr_size * 8 > i)
1814 for(chset = 0, chan_base = 0;
1815 chset < num_chsets && chan_base + n_xbr_ch[chset] <= s->
prim_channels;
1816 chan_base += n_xbr_ch[chset++]) {
1818 int subsubframe = 0;
1824 if(subsubframe == 0) {
1826 for(i = 0; i < n_xbr_ch[chset]; i++) {
1830 for(i = 0; i < n_xbr_ch[chset]; i++) {
1831 get_array(&s->
gb, abits_high[i], active_bands[chset][i], anctemp[i]);
1834 for(i = 0; i < n_xbr_ch[chset]; i++) {
1836 if(anctemp[i] < 1) {
1843 for(i = 0; i < n_xbr_ch[chset]; i++) {
1844 const uint32_t *scale_table;
1855 for(j = 0; j < active_bands[chset][i]; j++) {
1856 if(abits_high[i][j] > 0) {
1857 scale_table_high[i][j][0] =
1861 scale_table_high[i][j][1] =
1870 for(i = 0; i < n_xbr_ch[chset]; i++) {
1871 for(j = 0; j < active_bands[chset][i]; j++) {
1872 const int xbr_abits = abits_high[i][j];
1875 const float rscale = quant_step_size * scale_table_high[i][j][sfi];
1885 int block_code1, block_code2,
size, levels, err;
1896 "ERROR: DTS-XBR: block code look-up failed\n");
1902 for(l = 0; l < 8; l++)
1903 subband_samples[l] += (
float)block[l] * rscale;
1924 if(start_posn + chset_fsize[chset] * 8 != i) {
1925 j = start_posn + chset_fsize[chset] * 8 - i;
1928 " skipping further than expected (%d bits)\n", j);
1939 int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos;
1940 int i, chset, base_channel, chstart, fsize[8];
1949 for (i = 0; i < num_chsets; i++)
1959 if (hdr_pos + hdr_size * 8 > i)
1962 for (chset = 0; chset < num_chsets; chset++) {
1975 "Error decoding DTS-XXCH extension\n");
1982 if (chstart + fsize[chset] * 8 > i)
2000 int active_ss_mask[8];
2015 hdrsize =
get_bits(&s->
gb, 8 + 4 * blownup) + 1;
2030 if (num_audiop > 1) {
2032 "Multiple DTS-HD audio presentations");
2038 if (num_assets > 1) {
2044 for (i = 0; i < num_audiop; i++)
2045 active_ss_mask[i] =
get_bits(&s->
gb, ss_index + 1);
2047 for (i = 0; i < num_audiop; i++)
2048 for (j = 0; j <= ss_index; j++)
2049 if (active_ss_mask[i] & (1 << j))
2054 int mix_out_mask_size;
2057 mix_out_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
2061 int mix_out_mask =
get_bits(&s->
gb, mix_out_mask_size);
2067 for (i = 0; i < num_assets; i++)
2070 for (i = 0; i < num_assets; i++) {
2078 if (num_assets > 0) {
2080 if (start_posn + hdrsize * 8 > j)
2083 for (i = 0; i < num_assets; i++) {
2088 if (mkr == 0x655e315e) {
2090 }
else if (mkr == 0x47004a03) {
2095 "DTS-ExSS: unknown marker = 0x%08x\n", mkr);
2100 if (start_posn + asset_size[i] * 8 > j)
2111 int *got_frame_ptr,
AVPacket *avpkt)
2115 int buf_size = avpkt->
size;
2119 int num_core_channels = 0;
2121 float **samples_flt;
2126 int channels, full_channels;
2191 "Invalid channel mode %d\n", am);
2238 int ext_amode, xch_fsize;
2255 if ((ext_amode =
get_bits(&s->
gb, 4)) != 1) {
2257 " supported!\n", ext_amode);
2330 if (s->
amode < 16) {
2332 #if FF_API_REQUEST_CHANNELS
2351 channels = num_core_channels + !!s->
lfe;
2360 if (channels > !!s->
lfe &&
2376 static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
2382 "Non standard configuration %d !\n", s->
amode);
2393 channels = num_core_channels + !!s->
lfe;
2409 if (channel_mask & (1 << i)) {
2416 if (av_popcount(channel_mask) != av_popcount(channel_layout)) {
2418 "DTS-XXCH: Inconsistant avcodec/dts channel layouts\n");
2426 for (chset = -1, j = 0; chset < s->
xxch_chset; ++chset) {
2432 posn = av_popcount(channel_layout & (lavc - 1));
2440 for (i = 0; i < channels; i++)
2476 full_channels - channels,
2486 for (ch = 0; ch < channels; ch++)
2488 for (; ch < full_channels; ch++)
2506 ch = num_core_channels;
2507 for (chset = 0; chset < s->
xxch_chset; chset++) {
2512 for (j = ch; j < endch; j++) {
2513 if (mask & (1 << j)) {
2515 for (k = 0; k < endch; k++) {
2528 if ((mask & (1 << ch)) && s->
xxch_dmix_sf[chset] != 1.0f) {
2531 for (j = 0; j < ch; j++) {
2533 for (k = 0; k < 256; k++)
2534 src_chan[k] *= scale;
2540 for (k = 0; k < 256; k++)
2541 src_chan[k] *= scale;
2553 for (i = 0; i < 2 * s->
lfe * 4; i++)
2594 #if FF_API_REQUEST_CHANNELS