101 #define DCA_DOLBY 101
103 #define DCA_CHANNEL_BITS 6
104 #define DCA_CHANNEL_MASK 0x3F
108 #define HEADER_SIZE 14
110 #define DCA_NSYNCAUX 0x9A1105A0
137 static int vlcs_initialized = 0;
139 static VLC_TYPE dca_table[23622][2];
141 if (vlcs_initialized)
144 dca_bitalloc_index.
offset = 1;
145 dca_bitalloc_index.
wrap = 2;
146 for (i = 0; i < 5; i++) {
148 dca_bitalloc_index.
vlc[i].
table_allocated = ff_dca_vlc_offs[i + 1] - ff_dca_vlc_offs[i];
153 dca_scalefactor.
offset = -64;
154 dca_scalefactor.
wrap = 2;
155 for (i = 0; i < 5; i++) {
157 dca_scalefactor.
vlc[i].
table_allocated = ff_dca_vlc_offs[i + 6] - ff_dca_vlc_offs[i + 5];
164 for (i = 0; i < 4; i++) {
172 for (i = 0; i < 10; i++)
173 for (j = 0; j < 7; j++) {
177 dca_smpl_bitalloc[i + 1].
wrap = 1 + (j > 4);
179 dca_smpl_bitalloc[i + 1].
vlc[j].
table_allocated = ff_dca_vlc_offs[c + 1] - ff_dca_vlc_offs[
c];
187 vlcs_initialized = 1;
202 i <= s->xxch_chset && !(mask & xxch_ch); mask = s->
xxch_spk_masks[++i])
203 base += av_popcount(mask);
205 return base + av_popcount(mask & (xxch_ch - 1));
212 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
213 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
214 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
215 int hdr_pos = 0, hdr_size = 0;
217 int this_chans, acc_mask;
218 int embedded_downmix;
248 if (coeff<1 || coeff>61) {
265 if (mask[j] & (1 << i)) {
268 "DCA-XXCH: dmix to LFE1 not supported.\n");
274 if ((coeff&63)<1 || (coeff&63)>61) {
306 for (j = 1; j < 11; j++)
311 for (j = 0; j < 11; j++)
315 for (j = 1; j < 11; j++)
328 if (hdr_pos + 8 * hdr_size > i)
407 value = av_clip(value, 0, (1 << log2range) - 1);
408 }
else if (level < 8) {
409 if (level + 1 > log2range) {
456 "Invalid bit allocation index\n");
464 av_dlog(s->
avctx,
"bitalloc index [%i][%i] too big (%i)\n",
476 k < s->vq_start_subband[j] && s->
bitalloc[j][k] > 0) {
487 const uint32_t *scale_table;
488 int scale_sum, log_size;
540 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
547 "Joint stereo coding not supported\n");
573 if (!base_channel && s->
lfe) {
576 int lfe_samples = 2 * s->
lfe * (4 + block_index);
580 for (j = lfe_samples; j < lfe_end_sample; j++) {
596 for (j = lfe_samples; j < lfe_end_sample; j++)
604 float samples_in[32][8],
float *samples_out,
607 const float *prCoeff;
611 scale *= sqrt(1 / 8.0);
623 samples_out, s->
raXin, scale);
627 int num_deci_sample,
float *samples_in,
639 const float *prCoeff;
643 if (decimation_select == 1) {
651 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
654 samples_out += 2 * 32 * (1 + idx);
659 #define MIX_REAR1(samples, s1, rs, coef) \
660 samples[0][i] += samples[s1][i] * coef[rs][0]; \
661 samples[1][i] += samples[s1][i] * coef[rs][1];
663 #define MIX_REAR2(samples, s1, s2, rs, coef) \
664 samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
665 samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
667 #define MIX_FRONT3(samples, coef) \
671 samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
672 samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
674 #define DOWNMIX_TO_STEREO(op1, op2) \
675 for (i = 0; i < 256; i++) { \
680 static void dca_downmix(
float **samples,
int srcfmt,
int lfe_present,
682 const int8_t *channel_mapping)
684 int c, l,
r, sl, sr,
s;
699 c = channel_mapping[0];
700 l = channel_mapping[1];
701 r = channel_mapping[2];
705 s = channel_mapping[2];
709 c = channel_mapping[0];
710 l = channel_mapping[1];
711 r = channel_mapping[2];
712 s = channel_mapping[3];
717 sl = channel_mapping[2];
718 sr = channel_mapping[3];
722 c = channel_mapping[0];
723 l = channel_mapping[1];
724 r = channel_mapping[2];
725 sl = channel_mapping[3];
726 sr = channel_mapping[4];
734 for (i = 0; i < 256; i++) {
735 samples[0][i] += samples[lf_buf][i] * coef[lf_idx][0];
736 samples[1][i] += samples[lf_buf][i] * coef[lf_idx][1];
741 #ifndef decode_blockcodes
747 int offset = (levels - 1) >> 1;
749 for (i = 0; i < 4; i++) {
750 int div =
FASTDIV(code, levels);
751 values[i] = code - offset - div * levels;
773 const float *quant_step_table;
801 float quant_step_size = quant_step_table[abits];
815 memset(
block + 8 * l, 0, 8 *
sizeof(
block[0]));
819 rscale[l] = quant_step_size * s->
scale_factor[k][l][sfi] *
822 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].
table) {
825 int block_code1, block_code2,
size, levels, err;
833 levels,
block + 8 * l);
836 "ERROR: block code look-up failed\n");
841 for (m = 0; m < 8; m++)
846 for (m = 0; m < 8; m++)
848 &dca_smpl_bitalloc[abits], sel);
873 for (m = 1; m < 8; m++) {
875 subband_samples[k][l][m - 1];
876 for (n = 2; n <= 4; n++)
879 subband_samples[k][l][m -
n];
883 subband_samples[k][l][
m] += sum * (1.0f / 8192);
894 "Stream with high frequencies VQ coding\n");
953 int in,
out, aux_data_count, aux_data_end, reserved;
981 "Auxiliary Decode Time Stamp Flag");
1014 "Invalid mode %d for embedded downmix coefficients\n",
1021 if ((tmp & 0xFF) > 241) {
1023 "Invalid downmix coefficient code %"PRIu16
"\n",
1038 "Overread auxiliary data by %d bits\n", -reserved);
1040 }
else if (reserved) {
1042 "Core auxiliary data reserved content");
1104 int hdr_size, num_chsets, xbr_tmode, hdr_pos;
1105 int i, j, k, l, chset, chan_base;
1115 for(i = 0; i < num_chsets; i++)
1120 for(i = 0; i < num_chsets; i++) {
1123 for(j = 0; j < n_xbr_ch[i]; j++)
1124 active_bands[i][j] =
get_bits(&s->
gb, k) + 1;
1129 if(hdr_pos + hdr_size * 8 > i)
1134 for(chset = 0, chan_base = 0;
1135 chset < num_chsets && chan_base + n_xbr_ch[chset] <= s->
prim_channels;
1136 chan_base += n_xbr_ch[chset++]) {
1138 int subsubframe = 0;
1144 if(subsubframe == 0) {
1146 for(i = 0; i < n_xbr_ch[chset]; i++) {
1150 for(i = 0; i < n_xbr_ch[chset]; i++) {
1151 get_array(&s->
gb, abits_high[i], active_bands[chset][i], anctemp[i]);
1154 for(i = 0; i < n_xbr_ch[chset]; i++) {
1156 if(anctemp[i] < 1) {
1163 for(i = 0; i < n_xbr_ch[chset]; i++) {
1164 const uint32_t *scale_table;
1175 for(j = 0; j < active_bands[chset][i]; j++) {
1176 if(abits_high[i][j] > 0) {
1177 scale_table_high[i][j][0] =
1181 scale_table_high[i][j][1] =
1190 for(i = 0; i < n_xbr_ch[chset]; i++) {
1191 for(j = 0; j < active_bands[chset][i]; j++) {
1192 const int xbr_abits = abits_high[i][j];
1195 const float rscale = quant_step_size * scale_table_high[i][j][sfi];
1205 int block_code1, block_code2,
size, levels, err;
1216 "ERROR: DTS-XBR: block code look-up failed\n");
1222 for(l = 0; l < 8; l++)
1223 subband_samples[l] += (
float)block[l] * rscale;
1244 if(start_posn + chset_fsize[chset] * 8 != i) {
1245 j = start_posn + chset_fsize[chset] * 8 - i;
1248 " skipping further than expected (%d bits)\n", j);
1260 int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos;
1261 int i, chset, base_channel, chstart, fsize[8];
1270 for (i = 0; i < num_chsets; i++)
1280 if (hdr_pos + hdr_size * 8 > i)
1283 for (chset = 0; chset < num_chsets; chset++) {
1296 "Error decoding DTS-XXCH extension\n");
1303 if (chstart + fsize[chset] * 8 > i)
1313 int sign = (code >> 8) - 1;
1323 int *got_frame_ptr,
AVPacket *avpkt)
1327 int buf_size = avpkt->
size;
1331 int num_core_channels = 0;
1333 float **samples_flt;
1338 int channels, full_channels;
1386 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
1396 "Invalid channel mode %d\n", am);
1399 if (num_core_channels + !!s->
lfe >
1405 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
1411 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
1442 int ext_amode, xch_fsize;
1459 if ((ext_amode =
get_bits(&s->
gb, 4)) != 1) {
1461 "XCh extension amode %d not supported!\n",
1535 if (s->
amode < 16) {
1548 #if FF_API_REQUEST_CHANNELS
1571 channels = num_core_channels + !!s->
lfe;
1580 if (channels > !!s->
lfe &&
1589 if (num_core_channels + !!s->
lfe > 2 &&
1596 static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
1602 "Non standard configuration %d !\n", s->
amode);
1613 channels = num_core_channels + !!s->
lfe;
1629 if (channel_mask & (1 << i)) {
1636 if (av_popcount(channel_mask) != av_popcount(channel_layout)) {
1638 "DTS-XXCH: Inconsistent avcodec/dts channel layouts\n");
1646 for (chset = -1, j = 0; chset < s->
xxch_chset; ++chset) {
1652 posn = av_popcount(channel_layout & (lavc - 1));
1661 for (i = 0; i < channels; i++)
1697 full_channels - channels,
1707 for (ch = 0; ch < channels; ch++)
1709 for (; ch < full_channels; ch++)
1727 ch = num_core_channels;
1728 for (chset = 0; chset < s->
xxch_chset; chset++) {
1733 for (j = ch; j < endch; j++) {
1734 if (mask & (1 << j)) {
1736 for (k = 0; k < endch; k++) {
1749 if ((mask & (1 << ch)) && s->
xxch_dmix_sf[chset] != 1.0f) {
1752 for (j = 0; j < ch; j++) {
1754 for (k = 0; k < 256; k++)
1755 src_chan[k] *= scale;
1761 for (k = 0; k < 256; k++)
1762 src_chan[k] *= scale;
1774 for (i = 0; i < 2 * s->
lfe * 4; i++)
1816 #if FF_API_REQUEST_CHANNELS