56 #define DCA_PRIM_CHANNELS_MAX (7)
57 #define DCA_SUBBANDS (32)
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)
124 #define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96)
173 1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 3
177 { 0, -1, -1, -1, -1, -1, -1, -1, -1},
178 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
179 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
180 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
181 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
182 { 2, 0, 1, -1, -1, -1, -1, -1, -1},
183 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
184 { 2, 0, 1, 4, -1, -1, -1, -1, -1},
185 { 0, 1, 3, 4, -1, -1, -1, -1, -1},
186 { 2, 0, 1, 4, 5, -1, -1, -1, -1},
187 { 3, 4, 0, 1, 5, 6, -1, -1, -1},
188 { 2, 0, 1, 4, 5, 6, -1, -1, -1},
189 { 0, 6, 4, 5, 2, 3, -1, -1, -1},
190 { 4, 2, 5, 0, 1, 6, 7, -1, -1},
191 { 5, 6, 0, 1, 7, 3, 8, 4, -1},
192 { 4, 2, 5, 0, 1, 6, 8, 7, -1},
196 { 0, 2, -1, -1, -1, -1, -1, -1, -1},
197 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
198 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
199 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
200 { 0, 1, 3, -1, -1, -1, -1, -1, -1},
201 { 2, 0, 1, 4, -1, -1, -1, -1, -1},
202 { 0, 1, 3, 4, -1, -1, -1, -1, -1},
203 { 2, 0, 1, 4, 5, -1, -1, -1, -1},
204 { 0, 1, 4, 5, 3, -1, -1, -1, -1},
205 { 2, 0, 1, 5, 6, 4, -1, -1, -1},
206 { 3, 4, 0, 1, 6, 7, 5, -1, -1},
207 { 2, 0, 1, 4, 5, 6, 7, -1, -1},
208 { 0, 6, 4, 5, 2, 3, 7, -1, -1},
209 { 4, 2, 5, 0, 1, 7, 8, 6, -1},
210 { 5, 6, 0, 1, 8, 3, 9, 4, 7},
211 { 4, 2, 5, 0, 1, 6, 9, 8, 7},
215 { 0, -1, -1, -1, -1, -1, -1, -1, -1},
216 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
217 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
218 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
219 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
220 { 2, 0, 1, -1, -1, -1, -1, -1, -1},
221 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
222 { 2, 0, 1, 3, -1, -1, -1, -1, -1},
223 { 0, 1, 2, 3, -1, -1, -1, -1, -1},
224 { 2, 0, 1, 3, 4, -1, -1, -1, -1},
225 { 2, 3, 0, 1, 4, 5, -1, -1, -1},
226 { 2, 0, 1, 3, 4, 5, -1, -1, -1},
227 { 0, 5, 3, 4, 1, 2, -1, -1, -1},
228 { 3, 2, 4, 0, 1, 5, 6, -1, -1},
229 { 4, 5, 0, 1, 6, 2, 7, 3, -1},
230 { 3, 2, 4, 0, 1, 5, 7, 6, -1},
234 { 0, 1, -1, -1, -1, -1, -1, -1, -1},
235 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
236 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
237 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
238 { 0, 1, 2, -1, -1, -1, -1, -1, -1},
239 { 2, 0, 1, 3, -1, -1, -1, -1, -1},
240 { 0, 1, 2, 3, -1, -1, -1, -1, -1},
241 { 2, 0, 1, 3, 4, -1, -1, -1, -1},
242 { 0, 1, 3, 4, 2, -1, -1, -1, -1},
243 { 2, 0, 1, 4, 5, 3, -1, -1, -1},
244 { 2, 3, 0, 1, 5, 6, 4, -1, -1},
245 { 2, 0, 1, 3, 4, 5, 6, -1, -1},
246 { 0, 5, 3, 4, 1, 2, 6, -1, -1},
247 { 3, 2, 4, 0, 1, 6, 7, 5, -1},
248 { 4, 5, 0, 1, 7, 2, 8, 3, 6},
249 { 3, 2, 4, 0, 1, 5, 8, 7, 6},
252 #define DCA_DOLBY 101
254 #define DCA_CHANNEL_BITS 6
255 #define DCA_CHANNEL_MASK 0x3F
259 #define HEADER_SIZE 14
261 #define DCA_MAX_FRAME_SIZE 16384
262 #define DCA_MAX_EXSS_HEADER_SIZE 4096
264 #define DCA_BUFFER_PADDING_SIZE 1024
384 int mix_config_num_ch[4];
397 0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,
398 5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,
399 5572, 5604, 5668, 5796, 5860, 5892, 6412, 6668, 6796, 7308, 7564,
400 7820, 8076, 8620, 9132, 9388, 9910, 10166, 10680, 11196, 11726, 12240,
401 12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 18264,
402 18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622,
407 static int vlcs_initialized = 0;
409 static VLC_TYPE dca_table[23622][2];
411 if (vlcs_initialized)
414 dca_bitalloc_index.
offset = 1;
415 dca_bitalloc_index.
wrap = 2;
416 for (i = 0; i < 5; i++) {
423 dca_scalefactor.
offset = -64;
424 dca_scalefactor.
wrap = 2;
425 for (i = 0; i < 5; i++) {
434 for (i = 0; i < 4; i++) {
442 for (i = 0; i < 10; i++)
443 for (j = 0; j < 7; j++) {
447 dca_smpl_bitalloc[i + 1].
wrap = 1 + (j > 4);
449 dca_smpl_bitalloc[i + 1].
vlc[j].
table_allocated = dca_vlc_offs[c + 1] - dca_vlc_offs[c];
457 vlcs_initialized = 1;
469 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
470 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
471 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
498 for (j = 1; j < 11; j++)
503 for (j = 0; j < 11; j++)
507 for (j = 1; j < 11; j++)
537 for (j = 0; j < 11; j++)
541 for (j = 0; j < 11; j++)
632 "source pcm resolution: %i (%i bits/sample)\n",
652 value = av_clip(value, 0, (1 << log2range) - 1);
653 }
else if (level < 8) {
654 if (level + 1 > log2range) {
701 "Invalid bit allocation index\n");
709 av_dlog(s->
avctx,
"bitalloc index [%i][%i] too big (%i)\n",
721 k < s->vq_start_subband[j] && s->
bitalloc[j][k] > 0) {
732 const uint32_t *scale_table;
733 int scale_sum, log_size;
785 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
792 "Joint stereo coding not supported\n");
809 "Invalid channel mode %d\n", am);
839 if (!base_channel && s->
lfe) {
841 int lfe_samples = 2 * s->
lfe * (4 + block_index);
845 for (j = lfe_samples; j < lfe_end_sample; j++) {
857 for (j = lfe_samples; j < lfe_end_sample; j++)
876 "prediction coefs: %f, %f, %f, %f\n",
908 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++)
926 if (!base_channel && s->
lfe) {
927 int lfe_samples = 2 * s->
lfe * (4 + block_index);
931 for (j = lfe_samples; j < lfe_end_sample; j++)
941 float samples_in[32][8],
float *samples_out,
944 const float *prCoeff;
950 scale *= sqrt(1 / 8.0);
958 for (i = sb_act; i < 32; i++)
962 for (subindex = 0; subindex < 8; subindex++) {
964 for (i = 0; i < sb_act; i++) {
965 unsigned sign = (i - 1) & 2;
966 uint32_t v =
AV_RN32A(&samples_in[i][subindex]) ^ sign << 30;
974 samples_out, s->
raXin, scale);
980 int num_deci_sample,
float *samples_in,
981 float *samples_out,
float scale)
992 const float *prCoeff;
996 if (decimation_select == 1) {
1004 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
1005 s->
dcadsp.
lfe_fir(samples_out, samples_in, prCoeff, decifactor, scale);
1007 samples_out += 2 * decifactor;
1012 #define MIX_REAR1(samples, s1, rs, coef) \
1013 samples[0][i] += samples[s1][i] * coef[rs][0]; \
1014 samples[1][i] += samples[s1][i] * coef[rs][1];
1016 #define MIX_REAR2(samples, s1, s2, rs, coef) \
1017 samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
1018 samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
1020 #define MIX_FRONT3(samples, coef) \
1021 t = samples[c][i]; \
1022 u = samples[l][i]; \
1023 v = samples[r][i]; \
1024 samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
1025 samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
1027 #define DOWNMIX_TO_STEREO(op1, op2) \
1028 for (i = 0; i < 256; i++) { \
1035 const int8_t *channel_mapping)
1037 int c, l,
r, sl, sr, s;
1058 c = channel_mapping[0];
1059 l = channel_mapping[1];
1060 r = channel_mapping[2];
1064 s = channel_mapping[2];
1068 c = channel_mapping[0];
1069 l = channel_mapping[1];
1070 r = channel_mapping[2];
1071 s = channel_mapping[3];
1076 sl = channel_mapping[2];
1077 sr = channel_mapping[3];
1081 c = channel_mapping[0];
1082 l = channel_mapping[1];
1083 r = channel_mapping[2];
1084 sl = channel_mapping[3];
1085 sr = channel_mapping[4];
1093 #ifndef decode_blockcodes
1099 int offset = (levels - 1) >> 1;
1101 for (i = 0; i < 4; i++) {
1102 int div =
FASTDIV(code, levels);
1103 values[i] = code - offset - div * levels;
1120 #ifndef int8x8_fmul_int32
1123 float fscale = scale / 16.0;
1125 for (i = 0; i < 8; i++)
1126 dst[i] = src[i] * fscale;
1135 const float *quant_step_table;
1161 float quant_step_size = quant_step_table[abits];
1174 memset(subband_samples[k][l], 0, 8 *
sizeof(subband_samples[0][0][0]));
1178 float rscale = quant_step_size * s->
scale_factor[k][l][sfi] *
1181 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table) {
1184 int block_code1, block_code2,
size, levels, err;
1195 "ERROR: block code look-up failed\n");
1200 for (m = 0; m < 8; m++)
1205 for (m = 0; m < 8; m++)
1207 &dca_smpl_bitalloc[abits], sel);
1219 for (m = 0; m < 8; m++) {
1220 for (n = 1; n <= 4; n++)
1222 subband_samples[k][l][m] +=
1224 subband_samples[k][l][m - n] / 8192);
1226 subband_samples[k][l][m] +=
1243 "Stream with high frequencies VQ coding\n");
1268 &subband_samples[k][l][4],
1269 4 *
sizeof(subband_samples[0][0][0]));
1286 M_SQRT1_2 / 32768.0 );
1299 1.0 / (256.0 * 32768.0));
1309 int aux_data_count = 0, i;
1316 if (!base_channel) {
1323 for (i = 0; i < aux_data_count; i++)
1390 return av_popcount(mask) +
1409 for (i = 0; i < channels; i++) {
1410 int mix_map_mask =
get_bits(gb, out_ch);
1411 int num_coeffs = av_popcount(mix_map_mask);
1424 int embedded_stereo = 0;
1425 int embedded_6ch = 0;
1426 int drc_code_present;
1427 int extensions_mask;
1459 int spkr_remap_sets;
1460 int spkr_mask_size = 16;
1469 spkr_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
1475 for (i = 0; i < spkr_remap_sets; i++) {
1480 for (i = 0; i < spkr_remap_sets; i++) {
1481 int num_dec_ch_remaps =
get_bits(&s->
gb, 5) + 1;
1485 for (j = 0; j < num_spkrs[i]; j++) {
1487 int num_dec_ch = av_popcount(remap_dec_ch_mask);
1498 if (drc_code_present)
1504 if (drc_code_present && embedded_stereo)
1528 if (embedded_stereo)
1534 case 0: extensions_mask =
get_bits(&s->
gb, 12);
break;
1537 case 3: extensions_mask = 0;
break;
1561 "DTS extensions detection mismatch (%d, %d)\n",
1576 int active_ss_mask[8];
1601 if (num_audiop > 1) {
1608 if (num_assets > 1) {
1614 for (i = 0; i < num_audiop; i++)
1615 active_ss_mask[i] =
get_bits(&s->
gb, ss_index + 1);
1617 for (i = 0; i < num_audiop; i++)
1618 for (j = 0; j <= ss_index; j++)
1619 if (active_ss_mask[i] & (1 << j))
1624 int mix_out_mask_size;
1627 mix_out_mask_size = (
get_bits(&s->
gb, 2) + 1) << 2;
1631 int mix_out_mask =
get_bits(&s->
gb, mix_out_mask_size);
1637 for (i = 0; i < num_assets; i++)
1640 for (i = 0; i < num_assets; i++) {
1654 int *got_frame_ptr,
AVPacket *avpkt)
1657 int buf_size = avpkt->
size;
1660 int num_core_channels = 0;
1662 float **samples_flt;
1664 int channels, full_channels;
1721 int ext_amode, xch_fsize;
1738 if ((ext_amode =
get_bits(&s->
gb, 4)) != 1) {
1740 " supported!\n", ext_amode);
1800 if (s->
amode < 16) {
1803 if (s->
xch_present && (!avctx->request_channels ||
1804 avctx->request_channels > num_core_channels + !!s->
lfe)) {
1813 channels = num_core_channels + !!s->
lfe;
1822 if (channels > !!s->
lfe &&
1860 full_channels - channels,
1870 for (ch = 0; ch < channels; ch++)
1872 for (; ch < full_channels; ch++)
1890 for (i = 0; i < 2 * s->
lfe * 4; i++)
1924 avctx->request_channels == 2) {
1925 avctx->
channels = avctx->request_channels;