60 5, 6, 7, 8, 9, 10, 11, 12, 14, 16
84 { { 2, 7 }, { 7, 2 }, },
86 { { 2, 7 }, { 7, 2 }, },
87 { { 2, 7 }, { 5, 5 }, { 7, 2 }, },
88 { { 2, 7 }, { 7, 2 }, { 6, 6 }, },
89 { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 8, 8 }, },
90 { { 2, 7 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
91 { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
102 return ((code - (levels >> 1)) << 24) / levels;
114 for (i = 0; i < 128; i++) {
122 for (i = 0; i < 32; i++) {
128 for (i = 0; i < 128; i++) {
140 for (i = 0; i < 7; i++) {
144 for (i = 0; i < 15; i++) {
151 for (i = 0; i < 256; i++) {
152 int v = (i >> 5) - ((i >> 7) << 3) - 5;
166 if (avctx->drc_scale)
190 if (avctx->
channels > 0 && avctx->request_channels > 0 &&
191 avctx->request_channels < avctx->
channels &&
192 avctx->request_channels <= 2) {
193 avctx->
channels = avctx->request_channels;
337 norm0 = 1.0f / norm0;
338 norm1 = 1.0f / norm1;
356 uint8_t absexp, int8_t *dexps)
358 int i, j, grp, group_size;
363 group_size = exp_strategy + (exp_strategy ==
EXP_D45);
364 for (grp = 0, i = 0; grp < ngrps; grp++) {
373 for (i = 0, j = 0; i < ngrps * 3; i++) {
374 prevexp += dexp[i] - 2;
377 switch (group_size) {
378 case 4: dexps[j++] = prevexp;
379 dexps[j++] = prevexp;
380 case 2: dexps[j++] = prevexp;
381 case 1: dexps[j++] = prevexp;
398 int band_start = bin;
403 for (bin = band_start; bin < band_end; bin++) {
408 for (bin = band_start; bin < band_end; bin++)
436 int end_freq = s->
end_freq[ch_index];
437 uint8_t *baps = s->
bap[ch_index];
438 int8_t *exps = s->
dexps[ch_index];
444 for (freq = start_freq; freq < end_freq; freq++) {
445 int bap = baps[freq];
501 coeffs[freq] = mantissa >> exps[freq];
534 for (bin = s->
start_freq[ch]; bin < s->end_freq[ch]; bin++) {
551 for (ch = 1; ch <= s->
channels; ch++) {
607 for (ch = 1; ch <= channels; ch++) {
611 for (i = 0; i < 128; i++)
616 for (i = 0; i < 128; i++)
632 int out_ch,
int in_ch,
int len)
637 for (i = 0; i <
len; i++) {
639 for (j = 0; j < in_ch; j++) {
640 v0 +=
samples[j][i] * matrix[j][0];
641 v1 +=
samples[j][i] * matrix[j][1];
646 }
else if (out_ch == 1) {
647 for (i = 0; i <
len; i++) {
649 for (j = 0; j < in_ch; j++)
650 v0 +=
samples[j][i] * matrix[j][0];
661 int channel_data_size =
sizeof(s->
delay[0]);
666 memcpy(s->
delay[1], s->
delay[0], channel_data_size);
669 memset(s->
delay[3], 0, channel_data_size);
671 memset(s->
delay[2], 0, channel_data_size);
674 memset(s->
delay[4], 0, channel_data_size);
676 memset(s->
delay[3], 0, channel_data_size);
678 memcpy(s->
delay[2], s->
delay[1], channel_data_size);
679 memset(s->
delay[1], 0, channel_data_size);
701 int ecpl,
int start_subband,
int end_subband,
702 const uint8_t *default_band_struct,
703 int *num_bands, uint8_t *band_sizes)
705 int subbnd, bnd, n_subbands, n_bands=0;
707 uint8_t coded_band_struct[22];
708 const uint8_t *band_struct;
710 n_subbands = end_subband - start_subband;
714 for (subbnd = 0; subbnd < n_subbands - 1; subbnd++) {
715 coded_band_struct[subbnd] =
get_bits1(gbc);
717 band_struct = coded_band_struct;
719 band_struct = &default_band_struct[start_subband+1];
728 if (num_bands || band_sizes ) {
729 n_bands = n_subbands;
730 bnd_sz[0] = ecpl ? 6 : 12;
731 for (bnd = 0, subbnd = 1; subbnd < n_subbands; subbnd++) {
732 int subbnd_size = (ecpl && subbnd < 4) ? 6 : 12;
733 if (band_struct[subbnd - 1]) {
735 bnd_sz[bnd] += subbnd_size;
737 bnd_sz[++bnd] = subbnd_size;
744 *num_bands = n_bands;
746 memcpy(band_sizes, bnd_sz, n_bands);
757 int different_transforms;
766 different_transforms = 0;
768 for (ch = 1; ch <= fbw_channels; ch++) {
771 different_transforms = 1;
777 for (ch = 1; ch <= fbw_channels; ch++) {
788 }
else if (blk == 0) {
797 int dst_start_freq, dst_end_freq, src_start_freq,
798 start_subband, end_subband;
804 for (ch = 1; ch <= fbw_channels; ch++)
811 start_subband =
get_bits(gbc, 3) + 2;
812 if (start_subband > 7)
813 start_subband += start_subband - 7;
816 end_subband += end_subband - 7;
817 dst_start_freq = dst_start_freq * 12 + 25;
818 src_start_freq = start_subband * 12 + 25;
819 dst_end_freq = end_subband * 12 + 25;
822 if (start_subband >= end_subband) {
824 "range (%d >= %d)\n", start_subband, end_subband);
827 if (dst_start_freq >= src_start_freq) {
829 "copy start bin (%d >= %d)\n", dst_start_freq, src_start_freq);
838 start_subband, end_subband,
843 for (ch = 1; ch <= fbw_channels; ch++) {
852 for (ch = 1; ch <= fbw_channels; ch++) {
856 int bin, master_spx_coord;
859 spx_blend =
get_bits(gbc, 5) * (1.0f/32);
860 master_spx_coord =
get_bits(gbc, 2) * 3;
865 int spx_coord_exp, spx_coord_mant;
866 float nratio, sblend, nblend, spx_coord;
870 nratio = ((float)((bin + (bandsize >> 1))) / s->
spx_dst_end_freq) - spx_blend;
871 nratio = av_clipf(nratio, 0.0
f, 1.0
f);
872 nblend = sqrtf(3.0
f * nratio);
874 sblend = sqrtf(1.0
f - nratio);
880 if (spx_coord_exp == 15) spx_coord_mant <<= 1;
881 else spx_coord_mant += 4;
882 spx_coord_mant <<= (25 - spx_coord_exp - master_spx_coord);
883 spx_coord = spx_coord_mant * (1.0f / (1 << 23));
903 int cpl_start_subband, cpl_end_subband;
922 for (ch = 1; ch <= fbw_channels; ch++)
931 cpl_start_subband =
get_bits(gbc, 4);
934 if (cpl_start_subband >= cpl_end_subband) {
936 cpl_start_subband, cpl_end_subband);
948 for (ch = 1; ch <= fbw_channels; ch++) {
955 }
else if (!s->
eac3) {
958 "be present in block 0\n");
968 int cpl_coords_exist = 0;
970 for (ch = 1; ch <= fbw_channels; ch++) {
973 int master_cpl_coord, cpl_coord_exp, cpl_coord_mant;
975 cpl_coords_exist = 1;
976 master_cpl_coord = 3 *
get_bits(gbc, 2);
980 if (cpl_coord_exp == 15)
981 s->
cpl_coords[ch][bnd] = cpl_coord_mant << 22;
983 s->
cpl_coords[ch][bnd] = (cpl_coord_mant + 16) << 21;
984 s->
cpl_coords[ch][bnd] >>= (cpl_coord_exp + master_cpl_coord);
988 "be present in block 0\n");
1017 "new rematrixing strategy not present in block 0\n");
1023 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1027 bit_alloc_stages[ch] = 3;
1031 for (ch = 1; ch <= fbw_channels; ch++) {
1041 int bandwidth_code =
get_bits(gbc, 6);
1042 if (bandwidth_code > 60) {
1046 s->
end_freq[ch] = bandwidth_code * 3 + 73;
1050 if (blk > 0 && s->
end_freq[ch] != prev)
1060 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1082 for (ch = !cpl_in_use; ch <= s->
channels; ch++)
1083 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1086 "be present in block 0\n");
1092 if (!s->
eac3 || !blk) {
1096 csnr = (
get_bits(gbc, 6) - 15) << 4;
1097 for (i = ch = !cpl_in_use; ch <= s->
channels; ch++) {
1100 snr = (csnr +
get_bits(gbc, 4)) << 2;
1103 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 1);
1113 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1116 }
else if (!s->
eac3 && !blk) {
1124 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1129 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1131 }
else if (s->
eac3 && !blk) {
1132 for (ch = !cpl_in_use; ch <= s->
channels; ch++)
1154 }
else if (!s->
eac3 && !blk) {
1156 "be present in block 0\n");
1165 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
1171 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1174 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
1177 for (seg = 0; seg < s->
dba_nsegs[ch]; seg++) {
1183 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1186 }
else if (blk == 0) {
1187 for (ch = 0; ch <= s->
channels; ch++) {
1193 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1194 if (bit_alloc_stages[ch] > 2) {
1200 if (bit_alloc_stages[ch] > 1) {
1213 if (bit_alloc_stages[ch] > 0) {
1221 bap_tab, s->
bap[ch]);
1243 for (ch = 1; ch <= s->
channels; ch++) {
1244 float gain = s->
mul_bias / 4194304.0f;
1265 if (different_transforms) {
1275 if (downmix_output) {
1280 if (downmix_output) {
1301 int *got_frame_ptr,
AVPacket *avpkt)
1303 const uint8_t *buf = avpkt->
data;
1304 int buf_size = avpkt->
size;
1306 float *out_samples_flt;
1307 int16_t *out_samples_s16;
1308 int blk, ch, err, ret;
1309 const uint8_t *channel_map;
1314 if (buf_size >= 2 &&
AV_RB16(buf) == 0x770B) {
1346 "skipping frame\n");
1387 if (avctx->request_channels > 0 && avctx->request_channels <= 2 &&
1388 avctx->request_channels < s->
channels) {
1418 out_samples_flt = (
float *)s->
frame.
data[0];
1419 out_samples_s16 = (int16_t *)s->
frame.
data[0];
1424 output[ch] = s->
output[channel_map[ch]];
1459 #define OFFSET(x) offsetof(AC3DecodeContext, x)
1460 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
1462 {
"drc_scale",
"percentage of dynamic range compression to apply",
OFFSET(drc_scale),
AV_OPT_TYPE_FLOAT, {1.0}, 0.0, 1.0,
PAR },
1489 #if CONFIG_EAC3_DECODER
1490 static const AVClass eac3_decoder_class = {
1510 .priv_class = &eac3_decoder_class,