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;
288 }
else if (CONFIG_EAC3_DECODER) {
330 norm0 = 1.0f / norm0;
331 norm1 = 1.0f / norm1;
351 int i, j, grp, group_size;
356 group_size = exp_strategy + (exp_strategy ==
EXP_D45);
357 for (grp = 0, i = 0; grp < ngrps; grp++) {
366 for (i = 0, j = 0; i < ngrps * 3; i++) {
367 prevexp += dexp[i] - 2;
370 switch (group_size) {
371 case 4: dexps[j++] = prevexp;
372 dexps[j++] = prevexp;
373 case 2: dexps[j++] = prevexp;
374 case 1: dexps[j++] = prevexp;
391 int band_start = bin;
396 for (bin = band_start; bin < band_end; bin++) {
401 for (bin = band_start; bin < band_end; bin++)
429 int end_freq = s->
end_freq[ch_index];
431 int8_t *exps = s->
dexps[ch_index];
437 for (freq = start_freq; freq < end_freq; freq++) {
438 int bap = baps[freq];
495 coeffs[freq] = mantissa >> exps[freq];
526 if (!blk && CONFIG_EAC3_DECODER)
528 for (bin = s->
start_freq[ch]; bin < s->end_freq[ch]; bin++) {
545 for (ch = 1; ch <= s->
channels; ch++) {
601 for (ch = 1; ch <= channels; ch++) {
605 for (i = 0; i < 128; i++)
610 for (i = 0; i < 128; i++)
627 int channel_data_size =
sizeof(s->
delay[0]);
632 memcpy(s->
delay[1], s->
delay[0], channel_data_size);
635 memset(s->
delay[3], 0, channel_data_size);
637 memset(s->
delay[2], 0, channel_data_size);
640 memset(s->
delay[4], 0, channel_data_size);
642 memset(s->
delay[3], 0, channel_data_size);
644 memcpy(s->
delay[2], s->
delay[1], channel_data_size);
645 memset(s->
delay[1], 0, channel_data_size);
667 int ecpl,
int start_subband,
int end_subband,
668 const uint8_t *default_band_struct,
669 int *num_bands,
uint8_t *band_sizes)
671 int subbnd, bnd, n_subbands, n_bands=0;
676 n_subbands = end_subband - start_subband;
680 for (subbnd = 0; subbnd < n_subbands - 1; subbnd++) {
681 coded_band_struct[subbnd] =
get_bits1(gbc);
683 band_struct = coded_band_struct;
685 band_struct = &default_band_struct[start_subband+1];
694 if (num_bands || band_sizes ) {
695 n_bands = n_subbands;
696 bnd_sz[0] = ecpl ? 6 : 12;
697 for (bnd = 0, subbnd = 1; subbnd < n_subbands; subbnd++) {
698 int subbnd_size = (ecpl && subbnd < 4) ? 6 : 12;
699 if (band_struct[subbnd - 1]) {
701 bnd_sz[bnd] += subbnd_size;
703 bnd_sz[++bnd] = subbnd_size;
710 *num_bands = n_bands;
712 memcpy(band_sizes, bnd_sz, n_bands);
723 int different_transforms;
730 different_transforms = 0;
732 for (ch = 1; ch <= fbw_channels; ch++) {
735 different_transforms = 1;
741 for (ch = 1; ch <= fbw_channels; ch++) {
752 }
else if (blk == 0) {
761 int dst_start_freq, dst_end_freq, src_start_freq,
762 start_subband, end_subband;
768 for (ch = 1; ch <= fbw_channels; ch++)
775 start_subband =
get_bits(gbc, 3) + 2;
776 if (start_subband > 7)
777 start_subband += start_subband - 7;
780 end_subband += end_subband - 7;
781 dst_start_freq = dst_start_freq * 12 + 25;
782 src_start_freq = start_subband * 12 + 25;
783 dst_end_freq = end_subband * 12 + 25;
786 if (start_subband >= end_subband) {
788 "range (%d >= %d)\n", start_subband, end_subband);
791 if (dst_start_freq >= src_start_freq) {
793 "copy start bin (%d >= %d)\n", dst_start_freq, src_start_freq);
802 start_subband, end_subband,
807 for (ch = 1; ch <= fbw_channels; ch++) {
816 for (ch = 1; ch <= fbw_channels; ch++) {
820 int bin, master_spx_coord;
823 spx_blend =
get_bits(gbc, 5) * (1.0f/32);
824 master_spx_coord =
get_bits(gbc, 2) * 3;
829 int spx_coord_exp, spx_coord_mant;
830 float nratio, sblend, nblend, spx_coord;
834 nratio = ((float)((bin + (bandsize >> 1))) / s->
spx_dst_end_freq) - spx_blend;
835 nratio = av_clipf(nratio, 0.0f, 1.0f);
836 nblend = sqrtf(3.0f * nratio);
838 sblend = sqrtf(1.0f - nratio);
844 if (spx_coord_exp == 15) spx_coord_mant <<= 1;
845 else spx_coord_mant += 4;
846 spx_coord_mant <<= (25 - spx_coord_exp - master_spx_coord);
847 spx_coord = spx_coord_mant * (1.0f / (1 << 23));
867 int cpl_start_subband, cpl_end_subband;
886 for (ch = 1; ch <= fbw_channels; ch++)
895 cpl_start_subband =
get_bits(gbc, 4);
898 if (cpl_start_subband >= cpl_end_subband) {
900 cpl_start_subband, cpl_end_subband);
912 for (ch = 1; ch <= fbw_channels; ch++) {
919 }
else if (!s->
eac3) {
922 "be present in block 0\n");
932 int cpl_coords_exist = 0;
934 for (ch = 1; ch <= fbw_channels; ch++) {
937 int master_cpl_coord, cpl_coord_exp, cpl_coord_mant;
939 cpl_coords_exist = 1;
940 master_cpl_coord = 3 *
get_bits(gbc, 2);
944 if (cpl_coord_exp == 15)
945 s->
cpl_coords[ch][bnd] = cpl_coord_mant << 22;
947 s->
cpl_coords[ch][bnd] = (cpl_coord_mant + 16) << 21;
948 s->
cpl_coords[ch][bnd] >>= (cpl_coord_exp + master_cpl_coord);
952 "be present in block 0\n");
981 "new rematrixing strategy not present in block 0\n");
987 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
991 bit_alloc_stages[ch] = 3;
995 for (ch = 1; ch <= fbw_channels; ch++) {
1005 int bandwidth_code =
get_bits(gbc, 6);
1006 if (bandwidth_code > 60) {
1010 s->
end_freq[ch] = bandwidth_code * 3 + 73;
1014 if (blk > 0 && s->
end_freq[ch] != prev)
1024 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1046 for (ch = !cpl_in_use; ch <= s->
channels; ch++)
1047 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1050 "be present in block 0\n");
1056 if (!s->
eac3 || !blk) {
1060 csnr = (
get_bits(gbc, 6) - 15) << 4;
1061 for (i = ch = !cpl_in_use; ch <= s->
channels; ch++) {
1064 snr = (csnr +
get_bits(gbc, 4)) << 2;
1067 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 1);
1077 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1080 }
else if (!s->
eac3 && !blk) {
1088 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1093 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1095 }
else if (s->
eac3 && !blk) {
1096 for (ch = !cpl_in_use; ch <= s->
channels; ch++)
1118 }
else if (!s->
eac3 && !blk) {
1120 "be present in block 0\n");
1129 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
1135 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1138 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
1141 for (seg = 0; seg < s->
dba_nsegs[ch]; seg++) {
1147 bit_alloc_stages[ch] =
FFMAX(bit_alloc_stages[ch], 2);
1150 }
else if (blk == 0) {
1151 for (ch = 0; ch <= s->
channels; ch++) {
1157 for (ch = !cpl_in_use; ch <= s->
channels; ch++) {
1158 if (bit_alloc_stages[ch] > 2) {
1164 if (bit_alloc_stages[ch] > 1) {
1177 if (bit_alloc_stages[ch] > 0) {
1185 bap_tab, s->
bap[ch]);
1207 for (ch = 1; ch <= s->
channels; ch++) {
1208 float gain = 1.0 / 4194304.0f;
1229 if (different_transforms) {
1239 if (downmix_output) {
1244 if (downmix_output) {
1265 int *got_frame_ptr,
AVPacket *avpkt)
1269 int buf_size = avpkt->
size;
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) {
1384 output[ch] = s->
output[ch];
1387 for (ch = 0; ch < s->
channels; ch++) {
1388 if (ch < s->out_channels)
1389 s->
outptr[channel_map[ch]] = (
float *)frame->
data[ch];
1400 output[ch] = s->
outptr[channel_map[ch]];
1402 if (!ch || channel_map[ch])
1411 memcpy(s->
output[ch], output[ch], 1024);
1430 #define OFFSET(x) offsetof(AC3DecodeContext, x)
1431 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
1433 {
"drc_scale",
"percentage of dynamic range compression to apply",
OFFSET(drc_scale),
AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 1.0,
PAR },
1435 {
"dmix_mode",
"Preferred Stereo Downmix Mode",
OFFSET(preferred_stereo_downmix),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 2, 0,
"dmix_mode"},
1436 {
"ltrt_cmixlev",
"Lt/Rt Center Mix Level",
OFFSET(ltrt_center_mix_level),
AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
1437 {
"ltrt_surmixlev",
"Lt/Rt Surround Mix Level",
OFFSET(ltrt_surround_mix_level),
AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
1438 {
"loro_cmixlev",
"Lo/Ro Center Mix Level",
OFFSET(loro_center_mix_level),
AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
1439 {
"loro_surmixlev",
"Lo/Ro Surround Mix Level",
OFFSET(loro_surround_mix_level),
AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
1466 #if CONFIG_EAC3_DECODER
1467 static const AVClass eac3_decoder_class = {
1486 .priv_class = &eac3_decoder_class,