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;
229 if (xxch && nchans >= 3) {
256 if (coeff<1 || coeff>61) {
273 if (mask[j] & (1 << i)) {
276 "DCA-XXCH: dmix to LFE1 not supported.\n");
282 if ((coeff&63)<1 || (coeff&63)>61) {
314 for (j = 1; j < 11; j++)
319 for (j = 0; j < 11; j++)
323 for (j = 1; j < 11; j++)
336 if (hdr_pos + 8 * hdr_size > i)
415 value = av_clip(value, 0, (1 << log2range) - 1);
416 }
else if (level < 8) {
417 if (level + 1 > log2range) {
468 "Invalid bit allocation index\n");
476 av_dlog(s->
avctx,
"bitalloc index [%i][%i] too big (%i)\n",
488 k < s->vq_start_subband[j] && s->
bitalloc[j][k] > 0) {
499 const uint32_t *scale_table;
500 int scale_sum, log_size;
552 for (k = s->
subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
559 "Joint stereo coding not supported\n");
585 if (!base_channel && s->
lfe) {
588 int lfe_samples = 2 * s->
lfe * (4 + block_index);
592 for (j = lfe_samples; j < lfe_end_sample; j++) {
608 for (j = lfe_samples; j < lfe_end_sample; j++)
616 float samples_in[32][8],
float *samples_out,
619 const float *prCoeff;
623 scale *= sqrt(1 / 8.0);
635 samples_out, s->
raXin, scale);
639 int num_deci_sample,
float *samples_in,
651 const float *prCoeff;
655 if (decimation_select == 1) {
663 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
666 samples_out += 2 * 32 * (1 + idx);
671 #define MIX_REAR1(samples, s1, rs, coef) \
672 samples[0][i] += samples[s1][i] * coef[rs][0]; \
673 samples[1][i] += samples[s1][i] * coef[rs][1];
675 #define MIX_REAR2(samples, s1, s2, rs, coef) \
676 samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
677 samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
679 #define MIX_FRONT3(samples, coef) \
683 samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
684 samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
686 #define DOWNMIX_TO_STEREO(op1, op2) \
687 for (i = 0; i < 256; i++) { \
692 static void dca_downmix(
float **samples,
int srcfmt,
int lfe_present,
694 const int8_t *channel_mapping)
696 int c, l,
r, sl, sr,
s;
711 c = channel_mapping[0];
712 l = channel_mapping[1];
713 r = channel_mapping[2];
717 s = channel_mapping[2];
721 c = channel_mapping[0];
722 l = channel_mapping[1];
723 r = channel_mapping[2];
724 s = channel_mapping[3];
729 sl = channel_mapping[2];
730 sr = channel_mapping[3];
734 c = channel_mapping[0];
735 l = channel_mapping[1];
736 r = channel_mapping[2];
737 sl = channel_mapping[3];
738 sr = channel_mapping[4];
746 for (i = 0; i < 256; i++) {
747 samples[0][i] += samples[lf_buf][i] * coef[lf_idx][0];
748 samples[1][i] += samples[lf_buf][i] * coef[lf_idx][1];
753 #ifndef decode_blockcodes
759 int offset = (levels - 1) >> 1;
761 for (i = 0; i < 4; i++) {
762 int div =
FASTDIV(code, levels);
763 values[i] = code - offset - div * levels;
785 const float *quant_step_table;
813 float quant_step_size = quant_step_table[abits];
827 memset(
block + 8 * l, 0, 8 *
sizeof(
block[0]));
831 rscale[l] = quant_step_size * s->
scale_factor[k][l][sfi] *
834 if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].
table) {
837 int block_code1, block_code2,
size, levels, err;
845 levels,
block + 8 * l);
848 "ERROR: block code look-up failed\n");
853 for (m = 0; m < 8; m++)
858 for (m = 0; m < 8; m++)
860 &dca_smpl_bitalloc[abits], sel);
885 for (m = 1; m < 8; m++) {
887 subband_samples[k][l][m - 1];
888 for (n = 2; n <= 4; n++)
891 subband_samples[k][l][m -
n];
895 subband_samples[k][l][
m] += sum * (1.0f / 8192);
906 "Stream with high frequencies VQ coding\n");
965 int in,
out, aux_data_count, aux_data_end, reserved;
993 "Auxiliary Decode Time Stamp Flag");
1026 "Invalid mode %d for embedded downmix coefficients\n",
1033 if ((tmp & 0xFF) > 241) {
1035 "Invalid downmix coefficient code %"PRIu16
"\n",
1050 "Overread auxiliary data by %d bits\n", -reserved);
1052 }
else if (reserved) {
1054 "Core auxiliary data reserved content");
1116 int hdr_size, num_chsets, xbr_tmode, hdr_pos;
1117 int i, j, k, l, chset, chan_base;
1127 for(i = 0; i < num_chsets; i++)
1132 for(i = 0; i < num_chsets; i++) {
1135 for(j = 0; j < n_xbr_ch[i]; j++) {
1136 active_bands[i][j] =
get_bits(&s->
gb, k) + 1;
1146 if(hdr_pos + hdr_size * 8 > i)
1151 for(chset = 0, chan_base = 0;
1152 chset < num_chsets && chan_base + n_xbr_ch[chset] <= s->
prim_channels;
1153 chan_base += n_xbr_ch[chset++]) {
1155 int subsubframe = 0;
1161 if(subsubframe == 0) {
1163 for(i = 0; i < n_xbr_ch[chset]; i++) {
1167 for(i = 0; i < n_xbr_ch[chset]; i++) {
1168 get_array(&s->
gb, abits_high[i], active_bands[chset][i], anctemp[i]);
1171 for(i = 0; i < n_xbr_ch[chset]; i++) {
1173 if(anctemp[i] < 1) {
1180 for(i = 0; i < n_xbr_ch[chset]; i++) {
1181 const uint32_t *scale_table;
1183 int scale_table_size;
1195 for(j = 0; j < active_bands[chset][i]; j++) {
1196 if(abits_high[i][j] > 0) {
1198 if (index >= scale_table_size) {
1202 scale_table_high[i][j][0] = scale_table[
index];
1206 if (index >= scale_table_size) {
1210 scale_table_high[i][j][1] = scale_table[
index];
1218 for(i = 0; i < n_xbr_ch[chset]; i++) {
1219 for(j = 0; j < active_bands[chset][i]; j++) {
1220 const int xbr_abits = abits_high[i][j];
1223 const float rscale = quant_step_size * scale_table_high[i][j][sfi];
1233 int block_code1, block_code2,
size, levels, err;
1244 "ERROR: DTS-XBR: block code look-up failed\n");
1250 for(l = 0; l < 8; l++)
1251 subband_samples[l] += (
float)block[l] * rscale;
1272 if(start_posn + chset_fsize[chset] * 8 != i) {
1273 j = start_posn + chset_fsize[chset] * 8 - i;
1276 " skipping further than expected (%d bits)\n", j);
1288 int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos;
1289 int i, chset, base_channel, chstart, fsize[8];
1298 for (i = 0; i < num_chsets; i++)
1308 if (hdr_pos + hdr_size * 8 > i)
1311 for (chset = 0; chset < num_chsets; chset++) {
1324 "Error decoding DTS-XXCH extension\n");
1331 if (chstart + fsize[chset] * 8 > i)
1341 int sign = (code >> 8) - 1;
1351 int *got_frame_ptr,
AVPacket *avpkt)
1355 int buf_size = avpkt->
size;
1359 int num_core_channels = 0;
1361 float **samples_flt;
1366 int channels, full_channels;
1414 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
1424 "Invalid channel mode %d\n", am);
1427 if (num_core_channels + !!s->
lfe >
1433 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
1439 for (i = 0; i < num_core_channels + !!s->
lfe; i++) {
1470 int ext_amode, xch_fsize;
1487 if ((ext_amode =
get_bits(&s->
gb, 4)) != 1) {
1489 "XCh extension amode %d not supported!\n",
1563 if (s->
amode < 16) {
1576 #if FF_API_REQUEST_CHANNELS
1599 channels = num_core_channels + !!s->
lfe;
1608 if (channels > !!s->
lfe &&
1617 if (num_core_channels + !!s->
lfe > 2 &&
1624 static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
1630 "Non standard configuration %d !\n", s->
amode);
1641 channels = num_core_channels + !!s->
lfe;
1657 if (channel_mask & (1 << i)) {
1664 if (av_popcount(channel_mask) != av_popcount(channel_layout)) {
1666 "DTS-XXCH: Inconsistent avcodec/dts channel layouts\n");
1674 for (chset = -1, j = 0; chset < s->
xxch_chset; ++chset) {
1680 posn = av_popcount(channel_layout & (lavc - 1));
1689 for (i = 0; i < channels; i++)
1725 full_channels - channels,
1735 for (ch = 0; ch < channels; ch++)
1737 for (; ch < full_channels; ch++)
1755 ch = num_core_channels;
1756 for (chset = 0; chset < s->
xxch_chset; chset++) {
1761 for (j = ch; j < endch; j++) {
1762 if (mask & (1 << j)) {
1764 for (k = 0; k < endch; k++) {
1777 if ((mask & (1 << ch)) && s->
xxch_dmix_sf[chset] != 1.0f) {
1780 for (j = 0; j < ch; j++) {
1782 for (k = 0; k < 256; k++)
1783 src_chan[k] *= scale;
1789 for (k = 0; k < 256; k++)
1790 src_chan[k] *= scale;
1802 for (i = 0; i < 2 * s->
lfe * 4; i++)
1844 #if FF_API_REQUEST_CHANNELS