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;
181 if (avctx->
channels > 0 && avctx->request_channels > 0 &&
182 avctx->request_channels < avctx->
channels &&
183 avctx->request_channels <= 2) {
184 avctx->
channels = avctx->request_channels;
333 norm0 = 1.0f / norm0;
334 norm1 = 1.0f / norm1;
354 int i, j, grp, group_size;
359 group_size = exp_strategy + (exp_strategy ==
EXP_D45);
360 for (grp = 0, i = 0; grp < ngrps; grp++) {
369 for (i = 0, j = 0; i < ngrps * 3; i++) {
370 prevexp += dexp[i] - 2;
373 switch (group_size) {
374 case 4: dexps[j++] = prevexp;
375 dexps[j++] = prevexp;
376 case 2: dexps[j++] = prevexp;
377 case 1: dexps[j++] = prevexp;
394 int band_start = bin;
399 for (bin = band_start; bin < band_end; bin++) {
404 for (bin = band_start; bin < band_end; bin++)
432 int end_freq = s->
end_freq[ch_index];
434 int8_t *exps = s->
dexps[ch_index];
440 for (freq = start_freq; freq < end_freq; freq++) {
441 int bap = baps[freq];
497 coeffs[freq] = mantissa >> exps[freq];
530 for (bin = s->
start_freq[ch]; bin < s->end_freq[ch]; bin++) {
547 for (ch = 1; ch <= s->
channels; ch++) {
603 for (ch = 1; ch <= channels; ch++) {
607 for (i = 0; i < 128; i++)
612 for (i = 0; i < 128; i++)
629 int channel_data_size =
sizeof(s->
delay[0]);
634 memcpy(s->
delay[1], s->
delay[0], channel_data_size);
637 memset(s->
delay[3], 0, channel_data_size);
639 memset(s->
delay[2], 0, channel_data_size);
642 memset(s->
delay[4], 0, channel_data_size);
644 memset(s->
delay[3], 0, channel_data_size);
646 memcpy(s->
delay[2], s->
delay[1], channel_data_size);
647 memset(s->
delay[1], 0, channel_data_size);
669 int ecpl,
int start_subband,
int end_subband,
670 const uint8_t *default_band_struct,
671 int *num_bands,
uint8_t *band_sizes)
673 int subbnd, bnd, n_subbands, n_bands=0;
678 n_subbands = end_subband - start_subband;
682 for (subbnd = 0; subbnd < n_subbands - 1; subbnd++) {
683 coded_band_struct[subbnd] =
get_bits1(gbc);
685 band_struct = coded_band_struct;
687 band_struct = &default_band_struct[start_subband+1];
696 if (num_bands || band_sizes ) {
697 n_bands = n_subbands;
698 bnd_sz[0] = ecpl ? 6 : 12;
699 for (bnd = 0, subbnd = 1; subbnd < n_subbands; subbnd++) {
700 int subbnd_size = (ecpl && subbnd < 4) ? 6 : 12;
701 if (band_struct[subbnd - 1]) {
703 bnd_sz[bnd] += subbnd_size;
705 bnd_sz[++bnd] = subbnd_size;
712 *num_bands = n_bands;
714 memcpy(band_sizes, bnd_sz, n_bands);
725 int different_transforms;
732 different_transforms = 0;
734 for (ch = 1; ch <= fbw_channels; ch++) {
737 different_transforms = 1;
743 for (ch = 1; ch <= fbw_channels; ch++) {
754 }
else if (blk == 0) {
763 int dst_start_freq, dst_end_freq, src_start_freq,
764 start_subband, end_subband;
770 for (ch = 1; ch <= fbw_channels; ch++)
777 start_subband =
get_bits(gbc, 3) + 2;
778 if (start_subband > 7)
779 start_subband += start_subband - 7;
782 end_subband += end_subband - 7;
783 dst_start_freq = dst_start_freq * 12 + 25;
784 src_start_freq = start_subband * 12 + 25;
785 dst_end_freq = end_subband * 12 + 25;
788 if (start_subband >= end_subband) {
790 "range (%d >= %d)\n", start_subband, end_subband);
793 if (dst_start_freq >= src_start_freq) {
795 "copy start bin (%d >= %d)\n", dst_start_freq, src_start_freq);
804 start_subband, end_subband,
809 for (ch = 1; ch <= fbw_channels; ch++) {
818 for (ch = 1; ch <= fbw_channels; ch++) {
822 int bin, master_spx_coord;
825 spx_blend =
get_bits(gbc, 5) * (1.0f/32);
826 master_spx_coord =
get_bits(gbc, 2) * 3;
831 int spx_coord_exp, spx_coord_mant;
832 float nratio, sblend, nblend, spx_coord;
836 nratio = ((float)((bin + (bandsize >> 1))) / s->
spx_dst_end_freq) - spx_blend;
837 nratio = av_clipf(nratio, 0.0f, 1.0f);
838 nblend = sqrtf(3.0f * nratio);
840 sblend = sqrtf(1.0f - nratio);
846 if (spx_coord_exp == 15) spx_coord_mant <<= 1;
847 else spx_coord_mant += 4;
848 spx_coord_mant <<= (25 - spx_coord_exp - master_spx_coord);
849 spx_coord = spx_coord_mant * (1.0f / (1 << 23));
869 int cpl_start_subband, cpl_end_subband;
888 for (ch = 1; ch <= fbw_channels; ch++)
897 cpl_start_subband =
get_bits(gbc, 4);
900 if (cpl_start_subband >= cpl_end_subband) {
902 cpl_start_subband, cpl_end_subband);
914 for (ch = 1; ch <= fbw_channels; ch++) {
921 }
else if (!s->
eac3) {
924 "be present in block 0\n");
934 int cpl_coords_exist = 0;
936 for (ch = 1; ch <= fbw_channels; ch++) {
939 int master_cpl_coord, cpl_coord_exp, cpl_coord_mant;
941 cpl_coords_exist = 1;
942 master_cpl_coord = 3 *
get_bits(gbc, 2);
946 if (cpl_coord_exp == 15)
947 s->
cpl_coords[ch][bnd] = cpl_coord_mant << 22;
949 s->
cpl_coords[ch][bnd] = (cpl_coord_mant + 16) << 21;
950 s->
cpl_coords[ch][bnd] >>= (cpl_coord_exp + master_cpl_coord);
954 "be present in block 0\n");
983 "new rematrixing strategy not present in block 0\n");
989 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
993 bit_alloc_stages[ch] = 3;
997 for (ch = 1; ch <= fbw_channels; ch++) {
1007 int bandwidth_code =
get_bits(gbc, 6);
1008 if (bandwidth_code > 60) {
1012 s->
end_freq[ch] = bandwidth_code * 3 + 73;
1016 if (blk > 0 && s->
end_freq[ch] != prev)
1026 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1048 for (ch = !cpl_in_use; ch <= s->
channels; ch++)
1049 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1052 "be present in block 0\n");
1058 if (!s->
eac3 || !blk) {
1062 csnr = (
get_bits(gbc, 6) - 15) << 4;
1063 for (i = ch = !cpl_in_use; ch <= s->
channels; ch++) {
1066 snr = (csnr +
get_bits(gbc, 4)) << 2;
1069 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 1);
1079 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1082 }
else if (!s->
eac3 && !blk) {
1090 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1095 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1097 }
else if (s->
eac3 && !blk) {
1098 for (ch = !cpl_in_use; ch <= s->
channels; ch++)
1120 }
else if (!s->
eac3 && !blk) {
1122 "be present in block 0\n");
1131 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
1137 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1140 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
1143 for (seg = 0; seg < s->
dba_nsegs[ch]; seg++) {
1149 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1152 }
else if (blk == 0) {
1153 for (ch = 0; ch <= s->
channels; ch++) {
1159 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1160 if (bit_alloc_stages[ch] > 2) {
1166 if (bit_alloc_stages[ch] > 1) {
1179 if (bit_alloc_stages[ch] > 0) {
1187 bap_tab, s->
bap[ch]);
1209 for (ch = 1; ch <= s->
channels; ch++) {
1210 float gain = 1.0 / 4194304.0f;
1231 if (different_transforms) {
1241 if (downmix_output) {
1246 if (downmix_output) {
1267 int *got_frame_ptr,
AVPacket *avpkt)
1270 int buf_size = avpkt->
size;
1272 int blk, ch, err, ret;
1278 if (buf_size >= 2 &&
AV_RB16(buf) == 0x770B) {
1310 "skipping frame\n");
1351 if (avctx->request_channels > 0 && avctx->request_channels <= 2 &&
1352 avctx->request_channels < s->
channels) {
1385 for (ch = 0; ch < s->
channels; ch++) {
1386 if (ch < s->out_channels)
1390 output[ch] = s->
output[ch];
1399 memcpy(s->
outptr[channel_map[ch]], output[ch], 1024);
1401 output[ch] = s->
outptr[channel_map[ch]];
1408 memcpy(s->
output[ch], output[ch], 1024);
1428 #define OFFSET(x) offsetof(AC3DecodeContext, x)
1429 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
1431 {
"drc_scale",
"percentage of dynamic range compression to apply",
OFFSET(drc_scale),
AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 1.0,
PAR },
1457 #if CONFIG_EAC3_DECODER
1458 static const AVClass eac3_decoder_class = {
1473 .capabilities = CODEC_CAP_DR1,
1477 .priv_class = &eac3_decoder_class,