59 #define DCA_PRIM_CHANNELS_MAX (7)
60 #define DCA_SUBBANDS (32)
61 #define DCA_ABITS_MAX (32)
62 #define DCA_SUBSUBFRAMES_MAX (4)
63 #define DCA_SUBFRAMES_MAX (16)
64 #define DCA_BLOCKS_MAX (16)
65 #define DCA_LFE_MAX (3)
127 #define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96)
176 1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 3
180 { 0, -1, -1, -1, -1, -1, -1, -1, -1},
181 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
182 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
183 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
184 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
185 { 2, 0, 1, -1, -1, -1, -1, -1, -1},
186 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
187 { 2, 0, 1, 4, -1, -1, -1, -1, -1},
188 { 0, 1, 3, 4, -1, -1, -1, -1, -1},
189 { 2, 0, 1, 4, 5, -1, -1, -1, -1},
190 { 3, 4, 0, 1, 5, 6, -1, -1, -1},
191 { 2, 0, 1, 4, 5, 6, -1, -1, -1},
192 { 0, 6, 4, 5, 2, 3, -1, -1, -1},
193 { 4, 2, 5, 0, 1, 6, 7, -1, -1},
194 { 5, 6, 0, 1, 7, 3, 8, 4, -1},
195 { 4, 2, 5, 0, 1, 6, 8, 7, -1},
199 { 0, 2, -1, -1, -1, -1, -1, -1, -1},
200 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
201 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
202 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
203 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
204 { 2, 0, 1, 4, -1, -1, -1, -1, -1},
205 { 0, 1, 3, 4, -1, -1, -1, -1, -1},
206 { 2, 0, 1, 4, 5, -1, -1, -1, -1},
207 { 0, 1, 4, 5, 3, -1, -1, -1, -1},
208 { 2, 0, 1, 5, 6, 4, -1, -1, -1},
209 { 3, 4, 0, 1, 6, 7, 5, -1, -1},
210 { 2, 0, 1, 4, 5, 6, 7, -1, -1},
211 { 0, 6, 4, 5, 2, 3, 7, -1, -1},
212 { 4, 2, 5, 0, 1, 7, 8, 6, -1},
213 { 5, 6, 0, 1, 8, 3, 9, 4, 7},
214 { 4, 2, 5, 0, 1, 6, 9, 8, 7},
218 { 0, -1, -1, -1, -1, -1, -1, -1, -1},
219 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
220 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
221 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
222 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
223 { 2, 0, 1, -1, -1, -1, -1, -1, -1},
224 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
225 { 2, 0, 1, 3, -1, -1, -1, -1, -1},
226 { 0, 1, 2, 3, -1, -1, -1, -1, -1},
227 { 2, 0, 1, 3, 4, -1, -1, -1, -1},
228 { 2, 3, 0, 1, 4, 5, -1, -1, -1},
229 { 2, 0, 1, 3, 4, 5, -1, -1, -1},
230 { 0, 5, 3, 4, 1, 2, -1, -1, -1},
231 { 3, 2, 4, 0, 1, 5, 6, -1, -1},
232 { 4, 5, 0, 1, 6, 2, 7, 3, -1},
233 { 3, 2, 4, 0, 1, 5, 7, 6, -1},
237 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
238 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
239 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
240 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
241 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
242 { 2, 0, 1, 3, -1, -1, -1, -1, -1},
243 { 0, 1, 2, 3, -1, -1, -1, -1, -1},
244 { 2, 0, 1, 3, 4, -1, -1, -1, -1},
245 { 0, 1, 3, 4, 2, -1, -1, -1, -1},
246 { 2, 0, 1, 4, 5, 3, -1, -1, -1},
247 { 2, 3, 0, 1, 5, 6, 4, -1, -1},
248 { 2, 0, 1, 3, 4, 5, 6, -1, -1},
249 { 0, 5, 3, 4, 1, 2, 6, -1, -1},
250 { 3, 2, 4, 0, 1, 6, 7, 5, -1},
251 { 4, 5, 0, 1, 7, 2, 8, 3, 6},
252 { 3, 2, 4, 0, 1, 5, 8, 7, 6},
255 #define DCA_DOLBY 101
257 #define DCA_CHANNEL_BITS 6
258 #define DCA_CHANNEL_MASK 0x3F
262 #define HEADER_SIZE 14
264 #define DCA_MAX_FRAME_SIZE 16384
265 #define DCA_MAX_EXSS_HEADER_SIZE 4096
267 #define DCA_BUFFER_PADDING_SIZE 1024
269 #define DCA_NSYNCAUX 0x9A1105A0
396 int mix_config_num_ch[4];
409 0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,
410 5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,
411 5572, 5604, 5668, 5796, 5860, 5892, 6412, 6668, 6796, 7308, 7564,
412 7820, 8076, 8620, 9132, 9388, 9910, 10166, 10680, 11196, 11726, 12240,
413 12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 18264,
414 18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622,
419 static int vlcs_initialized = 0;
421 static VLC_TYPE dca_table[23622][2];
423 if (vlcs_initialized)
426 dca_bitalloc_index.
offset = 1;
427 dca_bitalloc_index.
wrap = 2;
428 for (i = 0; i < 5; i++) {
435 dca_scalefactor.
offset = -64;
436 dca_scalefactor.
wrap = 2;
437 for (i = 0; i < 5; i++) {
446 for (i = 0; i < 4; i++) {
454 for (i = 0; i < 10; i++)
455 for (j = 0; j < 7; j++) {
459 dca_smpl_bitalloc[i + 1].
wrap = 1 + (j > 4);
461 dca_smpl_bitalloc[i + 1].
vlc[j].
table_allocated = dca_vlc_offs[c + 1] - dca_vlc_offs[c];
469 vlcs_initialized = 1;
481 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
482 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
483 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
510 for (j = 1; j < 11; j++)
515 for (j = 0; j < 11; j++)
519 for (j = 1; j < 11; j++)
549 for (j = 0; j < 11; j++)
553 for (j = 0; j < 11; j++)
648 "source pcm resolution: %i (%i bits/sample)\n",
668 value = av_clip(value, 0, (1 << log2range) - 1);
669 }
else if (level < 8) {
670 if (level + 1 > log2range) {
717 "Invalid bit allocation index\n");
725 av_dlog(s->
avctx,
"bitalloc index [%i][%i] too big (%i)\n",
737 k < s->vq_start_subband[j] && s->
bitalloc[j][k] > 0) {
748 const uint32_t *scale_table;
749 int scale_sum, log_size;
801 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
808 "Joint stereo coding not supported\n");
834 if (!base_channel && s->
lfe) {
836 int lfe_samples = 2 * s->
lfe * (4 + block_index);
840 for (j = lfe_samples; j < lfe_end_sample; j++) {
852 for (j = lfe_samples; j < lfe_end_sample; j++)
871 "prediction coefs: %f, %f, %f, %f\n",
903 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++)
911 if (!base_channel && s->
lfe) {
912 int lfe_samples = 2 * s->
lfe * (4 + block_index);
916 for (j = lfe_samples; j < lfe_end_sample; j++)
926 float samples_in[32][8],
float *samples_out,
929 const float *prCoeff;
933 scale *= sqrt(1 / 8.0);
945 samples_out, s->
raXin, scale);
949 int num_deci_sample,
float *samples_in,
950 float *samples_out,
float scale)
961 const float *prCoeff;
965 if (decimation_select == 1) {
973 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
976 samples_out += 2 * 32 * (1 + idx);
981 #define MIX_REAR1(samples, s1, rs, coef) \
982 samples[0][i] += samples[s1][i] * coef[rs][0]; \
983 samples[1][i] += samples[s1][i] * coef[rs][1];
985 #define MIX_REAR2(samples, s1, s2, rs, coef) \
986 samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
987 samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
989 #define MIX_FRONT3(samples, coef) \
993 samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
994 samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
996 #define DOWNMIX_TO_STEREO(op1, op2) \
997 for (i = 0; i < 256; i++) { \
1004 const int8_t *channel_mapping)
1006 int c, l,
r, sl, sr, s;
1021 c = channel_mapping[0];
1022 l = channel_mapping[1];
1023 r = channel_mapping[2];
1027 s = channel_mapping[2];
1031 c = channel_mapping[0];
1032 l = channel_mapping[1];
1033 r = channel_mapping[2];
1034 s = channel_mapping[3];
1039 sl = channel_mapping[2];
1040 sr = channel_mapping[3];
1044 c = channel_mapping[0];
1045 l = channel_mapping[1];
1046 r = channel_mapping[2];
1047 sl = channel_mapping[3];
1048 sr = channel_mapping[4];
1056 for (i = 0; i < 256; i++) {
1057 samples[0][i] += samples[lf_buf][i] * coef[lf_idx][0];
1058 samples[1][i] += samples[lf_buf][i] * coef[lf_idx][1];
1064 #ifndef decode_blockcodes
1070 int offset = (levels - 1) >> 1;
1072 for (i = 0; i < 4; i++) {
1073 int div =
FASTDIV(code, levels);
1074 values[i] = code - offset - div * levels;
1091 #ifndef int8x8_fmul_int32
1093 const int8_t *src,
int scale)
1104 const float *quant_step_table;
1132 float quant_step_size = quant_step_table[abits];
1146 memset(
block + 8 * l, 0, 8 *
sizeof(
block[0]));
1150 rscale[l] = quant_step_size * s->
scale_factor[k][l][sfi] *
1153 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table) {
1156 int block_code1, block_code2,
size, levels, err;
1164 levels,
block + 8 * l);
1167 "ERROR: block code look-up failed\n");
1172 for (m = 0; m < 8; m++)
1177 for (m = 0; m < 8; m++)
1179 &dca_smpl_bitalloc[abits], sel);
1195 for (m = 0; m < 8; m++) {
1196 for (n = 1; n <= 4; n++)
1198 subband_samples[k][l][m] +=
1200 subband_samples[k][l][m - n] / 8192);
1202 subband_samples[k][l][m] +=
1219 "Stream with high frequencies VQ coding\n");
1261 M_SQRT1_2 / 32768.0 );
1269 1.0 / (256.0 * 32768.0));
1286 int in,
out, aux_data_count, aux_data_end, reserved;
1294 if (!base_channel) {
1314 "Auxiliary Decode Time Stamp Flag");
1347 "Invalid mode %d for embedded downmix coefficients\n",
1354 if ((tmp & 0xFF) > 241) {
1356 "Invalid downmix coefficient code %"PRIu16
"\n",
1371 "Overread auxiliary data by %d bits\n", -reserved);
1373 }
else if (reserved) {
1375 "Core auxiliary data reserved content");
1444 return av_popcount(mask) +
1463 for (i = 0; i < channels; i++) {
1464 int mix_map_mask =
get_bits(gb, out_ch);
1465 int num_coeffs = av_popcount(mix_map_mask);
1478 int embedded_stereo = 0;
1479 int embedded_6ch = 0;
1480 int drc_code_present;
1481 int extensions_mask;
1513 int spkr_remap_sets;
1514 int spkr_mask_size = 16;
1523 spkr_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
1529 for (i = 0; i < spkr_remap_sets; i++) {
1534 for (i = 0; i < spkr_remap_sets; i++) {
1535 int num_dec_ch_remaps =
get_bits(&s->
gb, 5) + 1;
1539 for (j = 0; j < num_spkrs[i]; j++) {
1541 int num_dec_ch = av_popcount(remap_dec_ch_mask);
1552 if (drc_code_present)
1558 if (drc_code_present && embedded_stereo)
1582 if (embedded_stereo)
1588 case 0: extensions_mask =
get_bits(&s->
gb, 12);
break;
1591 case 3: extensions_mask = 0;
break;
1615 "DTS extensions detection mismatch (%d, %d)\n",
1630 int active_ss_mask[8];
1655 if (num_audiop > 1) {
1657 "Multiple DTS-HD audio presentations");
1663 if (num_assets > 1) {
1669 for (i = 0; i < num_audiop; i++)
1670 active_ss_mask[i] =
get_bits(&s->
gb, ss_index + 1);
1672 for (i = 0; i < num_audiop; i++)
1673 for (j = 0; j <= ss_index; j++)
1674 if (active_ss_mask[i] & (1 << j))
1679 int mix_out_mask_size;
1682 mix_out_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
1686 int mix_out_mask =
get_bits(&s->
gb, mix_out_mask_size);
1692 for (i = 0; i < num_assets; i++)
1695 for (i = 0; i < num_assets; i++) {
1709 int *got_frame_ptr,
AVPacket *avpkt)
1713 int buf_size = avpkt->
size;
1716 int num_core_channels = 0;
1718 float **samples_flt;
1720 int channels, full_channels;
1777 int ext_amode, xch_fsize;
1794 if ((ext_amode =
get_bits(&s->
gb, 4)) != 1) {
1796 " supported!\n", ext_amode);
1856 if (s->
amode < 16) {
1869 #if FF_API_REQUEST_CHANNELS
1886 channels = num_core_channels + !!s->
lfe;
1895 if (channels > !!s->
lfe &&
1899 if (num_core_channels + !!s->
lfe > 2 &&
1913 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
1928 "Invalid channel mode %d\n", am);
1931 if (num_core_channels + !!s->
lfe >
1937 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
1943 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
1980 full_channels - channels,
1990 for (ch = 0; ch < channels; ch++)
1992 for (; ch < full_channels; ch++)
2010 for (i = 0; i < 2 * s->
lfe * 4; i++)
2051 #if FF_API_REQUEST_CHANNELS