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;
180 if (avctx->
channels > 0 && avctx->request_channels > 0 &&
181 avctx->request_channels < avctx->
channels &&
182 avctx->request_channels <= 2) {
183 avctx->
channels = avctx->request_channels;
290 }
else if (CONFIG_EAC3_DECODER) {
332 norm0 = 1.0f / norm0;
333 norm1 = 1.0f / norm1;
353 int i, j, grp, group_size;
358 group_size = exp_strategy + (exp_strategy ==
EXP_D45);
359 for (grp = 0, i = 0; grp < ngrps; grp++) {
368 for (i = 0, j = 0; i < ngrps * 3; i++) {
369 prevexp += dexp[i] - 2;
372 switch (group_size) {
373 case 4: dexps[j++] = prevexp;
374 dexps[j++] = prevexp;
375 case 2: dexps[j++] = prevexp;
376 case 1: dexps[j++] = prevexp;
393 int band_start = bin;
398 for (bin = band_start; bin < band_end; bin++) {
403 for (bin = band_start; bin < band_end; bin++)
431 int end_freq = s->
end_freq[ch_index];
433 int8_t *exps = s->
dexps[ch_index];
439 for (freq = start_freq; freq < end_freq; freq++) {
440 int bap = baps[freq];
496 coeffs[freq] = mantissa >> exps[freq];
527 if (!blk && CONFIG_EAC3_DECODER)
529 for (bin = s->
start_freq[ch]; bin < s->end_freq[ch]; bin++) {
546 for (ch = 1; ch <= s->
channels; ch++) {
602 for (ch = 1; ch <= channels; ch++) {
606 for (i = 0; i < 128; i++)
611 for (i = 0; i < 128; i++)
628 int channel_data_size =
sizeof(s->
delay[0]);
633 memcpy(s->
delay[1], s->
delay[0], channel_data_size);
636 memset(s->
delay[3], 0, channel_data_size);
638 memset(s->
delay[2], 0, channel_data_size);
641 memset(s->
delay[4], 0, channel_data_size);
643 memset(s->
delay[3], 0, channel_data_size);
645 memcpy(s->
delay[2], s->
delay[1], channel_data_size);
646 memset(s->
delay[1], 0, channel_data_size);
668 int ecpl,
int start_subband,
int end_subband,
669 const uint8_t *default_band_struct,
670 int *num_bands,
uint8_t *band_sizes)
672 int subbnd, bnd, n_subbands, n_bands=0;
677 n_subbands = end_subband - start_subband;
681 for (subbnd = 0; subbnd < n_subbands - 1; subbnd++) {
682 coded_band_struct[subbnd] =
get_bits1(gbc);
684 band_struct = coded_band_struct;
686 band_struct = &default_band_struct[start_subband+1];
695 if (num_bands || band_sizes ) {
696 n_bands = n_subbands;
697 bnd_sz[0] = ecpl ? 6 : 12;
698 for (bnd = 0, subbnd = 1; subbnd < n_subbands; subbnd++) {
699 int subbnd_size = (ecpl && subbnd < 4) ? 6 : 12;
700 if (band_struct[subbnd - 1]) {
702 bnd_sz[bnd] += subbnd_size;
704 bnd_sz[++bnd] = subbnd_size;
711 *num_bands = n_bands;
713 memcpy(band_sizes, bnd_sz, n_bands);
724 int different_transforms;
731 different_transforms = 0;
733 for (ch = 1; ch <= fbw_channels; ch++) {
736 different_transforms = 1;
742 for (ch = 1; ch <= fbw_channels; ch++) {
753 }
else if (blk == 0) {
762 int dst_start_freq, dst_end_freq, src_start_freq,
763 start_subband, end_subband;
769 for (ch = 1; ch <= fbw_channels; ch++)
776 start_subband =
get_bits(gbc, 3) + 2;
777 if (start_subband > 7)
778 start_subband += start_subband - 7;
781 end_subband += end_subband - 7;
782 dst_start_freq = dst_start_freq * 12 + 25;
783 src_start_freq = start_subband * 12 + 25;
784 dst_end_freq = end_subband * 12 + 25;
787 if (start_subband >= end_subband) {
789 "range (%d >= %d)\n", start_subband, end_subband);
792 if (dst_start_freq >= src_start_freq) {
794 "copy start bin (%d >= %d)\n", dst_start_freq, src_start_freq);
803 start_subband, end_subband,
808 for (ch = 1; ch <= fbw_channels; ch++) {
817 for (ch = 1; ch <= fbw_channels; ch++) {
821 int bin, master_spx_coord;
824 spx_blend =
get_bits(gbc, 5) * (1.0f/32);
825 master_spx_coord =
get_bits(gbc, 2) * 3;
830 int spx_coord_exp, spx_coord_mant;
831 float nratio, sblend, nblend, spx_coord;
835 nratio = ((float)((bin + (bandsize >> 1))) / s->
spx_dst_end_freq) - spx_blend;
836 nratio = av_clipf(nratio, 0.0f, 1.0f);
837 nblend = sqrtf(3.0f * nratio);
839 sblend = sqrtf(1.0f - nratio);
845 if (spx_coord_exp == 15) spx_coord_mant <<= 1;
846 else spx_coord_mant += 4;
847 spx_coord_mant <<= (25 - spx_coord_exp - master_spx_coord);
848 spx_coord = spx_coord_mant * (1.0f / (1 << 23));
868 int cpl_start_subband, cpl_end_subband;
887 for (ch = 1; ch <= fbw_channels; ch++)
896 cpl_start_subband =
get_bits(gbc, 4);
899 if (cpl_start_subband >= cpl_end_subband) {
901 cpl_start_subband, cpl_end_subband);
913 for (ch = 1; ch <= fbw_channels; ch++) {
920 }
else if (!s->
eac3) {
923 "be present in block 0\n");
933 int cpl_coords_exist = 0;
935 for (ch = 1; ch <= fbw_channels; ch++) {
938 int master_cpl_coord, cpl_coord_exp, cpl_coord_mant;
940 cpl_coords_exist = 1;
941 master_cpl_coord = 3 *
get_bits(gbc, 2);
945 if (cpl_coord_exp == 15)
946 s->
cpl_coords[ch][bnd] = cpl_coord_mant << 22;
948 s->
cpl_coords[ch][bnd] = (cpl_coord_mant + 16) << 21;
949 s->
cpl_coords[ch][bnd] >>= (cpl_coord_exp + master_cpl_coord);
953 "be present in block 0\n");
982 "new rematrixing strategy not present in block 0\n");
988 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
992 bit_alloc_stages[ch] = 3;
996 for (ch = 1; ch <= fbw_channels; ch++) {
1006 int bandwidth_code =
get_bits(gbc, 6);
1007 if (bandwidth_code > 60) {
1011 s->
end_freq[ch] = bandwidth_code * 3 + 73;
1015 if (blk > 0 && s->
end_freq[ch] != prev)
1025 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1047 for (ch = !cpl_in_use; ch <= s->
channels; ch++)
1048 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1051 "be present in block 0\n");
1057 if (!s->
eac3 || !blk) {
1061 csnr = (
get_bits(gbc, 6) - 15) << 4;
1062 for (i = ch = !cpl_in_use; ch <= s->
channels; ch++) {
1065 snr = (csnr +
get_bits(gbc, 4)) << 2;
1068 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 1);
1078 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1081 }
else if (!s->
eac3 && !blk) {
1089 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1094 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1096 }
else if (s->
eac3 && !blk) {
1097 for (ch = !cpl_in_use; ch <= s->
channels; ch++)
1119 }
else if (!s->
eac3 && !blk) {
1121 "be present in block 0\n");
1130 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
1136 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1139 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
1142 for (seg = 0; seg < s->
dba_nsegs[ch]; seg++) {
1148 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1151 }
else if (blk == 0) {
1152 for (ch = 0; ch <= s->
channels; ch++) {
1158 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1159 if (bit_alloc_stages[ch] > 2) {
1165 if (bit_alloc_stages[ch] > 1) {
1178 if (bit_alloc_stages[ch] > 0) {
1186 bap_tab, s->
bap[ch]);
1208 for (ch = 1; ch <= s->
channels; ch++) {
1209 float gain = 1.0 / 4194304.0f;
1230 if (different_transforms) {
1240 if (downmix_output) {
1245 if (downmix_output) {
1266 int *got_frame_ptr,
AVPacket *avpkt)
1269 int buf_size = avpkt->
size;
1271 int blk, ch, err, ret;
1277 if (buf_size >= 2 &&
AV_RB16(buf) == 0x770B) {
1309 "skipping frame\n");
1347 if (avctx->request_channels > 0 && avctx->request_channels <= 2 &&
1348 avctx->request_channels < s->
channels) {
1386 output[ch] = s->
output[ch];
1389 for (ch = 0; ch < s->
channels; ch++) {
1390 if (ch < s->out_channels)
1402 output[ch] = s->
outptr[channel_map[ch]];
1404 if (!ch || channel_map[ch])
1413 memcpy(s->
output[ch], output[ch], 1024);
1433 #define OFFSET(x) offsetof(AC3DecodeContext, x)
1434 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
1436 {
"drc_scale",
"percentage of dynamic range compression to apply",
OFFSET(drc_scale),
AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 1.0,
PAR },
1438 {
"dmix_mode",
"Preferred Stereo Downmix Mode",
OFFSET(preferred_stereo_downmix),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 2, 0,
"dmix_mode"},
1439 {
"ltrt_cmixlev",
"Lt/Rt Center Mix Level",
OFFSET(ltrt_center_mix_level),
AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
1440 {
"ltrt_surmixlev",
"Lt/Rt Surround Mix Level",
OFFSET(ltrt_surround_mix_level),
AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
1441 {
"loro_cmixlev",
"Lo/Ro Center Mix Level",
OFFSET(loro_center_mix_level),
AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
1442 {
"loro_surmixlev",
"Lo/Ro Surround Mix Level",
OFFSET(loro_surround_mix_level),
AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
1469 #if CONFIG_EAC3_DECODER
1470 static const AVClass eac3_decoder_class = {
1489 .priv_class = &eac3_decoder_class,