64 #define EAC3_SR_CODE_REDUCED 3 69 uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
70 float rms_energy[SPX_MAX_BANDS];
74 bin = s->spx_dst_start_freq;
75 num_copy_sections = 0;
76 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
78 int bandsize = s->spx_band_sizes[bnd];
79 if (bin + bandsize > s->spx_src_start_freq) {
80 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
81 bin = s->spx_dst_start_freq;
84 for (i = 0; i < bandsize; i += copysize) {
85 if (bin == s->spx_src_start_freq) {
86 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
87 bin = s->spx_dst_start_freq;
89 copysize =
FFMIN(bandsize - i, s->spx_src_start_freq - bin);
93 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
95 for (ch = 1; ch <= s->fbw_channels; ch++) {
96 if (!s->channel_uses_spx[ch])
100 bin = s->spx_src_start_freq;
101 for (i = 0; i < num_copy_sections; i++) {
102 memcpy(&s->transform_coeffs[ch][bin],
103 &s->transform_coeffs[ch][s->spx_dst_start_freq],
104 copy_sizes[i]*
sizeof(
float));
105 bin += copy_sizes[
i];
109 bin = s->spx_src_start_freq;
110 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
111 int bandsize = s->spx_band_sizes[bnd];
113 for (i = 0; i < bandsize; i++) {
114 float coeff = s->transform_coeffs[ch][bin++];
115 accum += coeff *
coeff;
117 rms_energy[bnd] = sqrtf(accum / bandsize);
122 if (s->spx_atten_code[ch] >= 0) {
124 bin = s->spx_src_start_freq - 2;
125 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
127 float *coeffs = &s->transform_coeffs[ch][bin];
128 coeffs[0] *= atten_tab[0];
129 coeffs[1] *= atten_tab[1];
130 coeffs[2] *= atten_tab[2];
131 coeffs[3] *= atten_tab[1];
132 coeffs[4] *= atten_tab[0];
134 bin += s->spx_band_sizes[bnd];
141 bin = s->spx_src_start_freq;
142 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
143 float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
144 float sscale = s->spx_signal_blend[ch][bnd];
145 for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
147 s->transform_coeffs[ch][bin] *= sscale;
148 s->transform_coeffs[ch][bin++] +=
noise;
156 #define COEFF_0 10273905LL 159 #define COEFF_1 11863283LL 162 #define COEFF_2 3070444LL 171 int even0, even1, even2, odd0, odd1, odd2;
173 odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
175 even2 = ( pre_mant[2] *
COEFF_0) >> 23;
176 tmp = ( pre_mant[4] *
COEFF_1) >> 23;
177 odd0 = ((pre_mant[1] + pre_mant[5]) *
COEFF_2) >> 23;
179 even0 = pre_mant[0] + (tmp >> 1);
180 even1 = pre_mant[0] - tmp;
187 odd0 = tmp + pre_mant[1] + pre_mant[3];
188 odd2 = tmp + pre_mant[5] - pre_mant[3];
190 pre_mant[0] = even0 + odd0;
191 pre_mant[1] = even1 + odd1;
192 pre_mant[2] = even2 + odd2;
193 pre_mant[3] = even2 - odd2;
194 pre_mant[4] = even1 - odd1;
195 pre_mant[5] = even0 - odd0;
201 int end_bap, gaq_mode;
206 end_bap = (gaq_mode < 2) ? 12 : 17;
213 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
214 if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
215 gaq_gain[gs++] =
get_bits1(gbc) << (gaq_mode-1);
220 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
221 if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
224 if (group_code > 26) {
238 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
239 int hebap = s->bap[ch][bin];
243 for (blk = 0; blk < 6; blk++) {
244 s->pre_mantissa[ch][bin][
blk] = (
av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
246 }
else if (hebap < 8) {
249 for (blk = 0; blk < 6; blk++) {
256 log_gain = gaq_gain[gs++];
260 gbits = bits - log_gain;
262 for (blk = 0; blk < 6; blk++) {
264 if (log_gain && mant == -(1 << (gbits-1))) {
267 int mbits = bits - (2 - log_gain);
269 mant <<= (23 - (mbits - 1));
272 b = 1 << (23 - log_gain);
284 s->pre_mantissa[ch][bin][
blk] = mant;
287 idct6(s->pre_mantissa[ch][bin]);
294 int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
295 int parse_transient_proc_info;
313 if (s->substreamid) {
330 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
349 if (s->channel_mode & 1) {
352 s->center_mix_level =
get_bits(gbc, 3);
354 if (s->channel_mode & 4) {
357 s->surround_mix_level =
get_bits(gbc, 3);
369 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
383 int mix_data_size = (
get_bits(gbc, 5) + 2) << 3;
390 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
402 for (blk = 0; blk < s->num_blocks; blk++) {
403 if (s->num_blocks == 1 ||
get_bits1(gbc)) {
413 s->bitstream_mode =
get_bits(gbc, 3);
421 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
441 (s->num_blocks == 6 ||
get_bits1(gbc))) {
448 for (i = 0; i < addbsil + 1; i++) {
455 if (s->num_blocks == 6) {
461 ac3_exponent_strategy = 1;
465 s->snr_offset_strategy =
get_bits(gbc, 2);
466 parse_transient_proc_info =
get_bits1(gbc);
469 if (!s->block_switch_syntax)
470 memset(s->block_switch, 0,
sizeof(s->block_switch));
473 if (!s->dither_flag_syntax) {
474 for (ch = 1; ch <= s->fbw_channels; ch++)
475 s->dither_flag[ch] = 1;
477 s->dither_flag[
CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
479 s->bit_allocation_syntax =
get_bits1(gbc);
480 if (!s->bit_allocation_syntax) {
496 if (s->channel_mode > 1) {
497 for (blk = 0; blk < s->num_blocks; blk++) {
499 if (s->cpl_strategy_exists[blk]) {
502 s->cpl_in_use[
blk] = s->cpl_in_use[blk-1];
504 num_cpl_blocks += s->cpl_in_use[
blk];
507 memset(s->cpl_in_use, 0,
sizeof(s->cpl_in_use));
511 if (ac3_exponent_strategy) {
513 for (blk = 0; blk < s->num_blocks; blk++) {
514 for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
520 for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
522 for (blk = 0; blk < 6; blk++) {
529 for (blk = 0; blk < s->num_blocks; blk++) {
535 (s->num_blocks == 6 ||
get_bits1(gbc))) {
540 if (parse_aht_info) {
545 s->channel_uses_aht[
CPL_CH]=0;
546 for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
548 for (blk = 1; blk < 6; blk++) {
549 if ((s->exp_strategy[blk][ch] !=
EXP_REUSE) ||
550 (!ch && s->cpl_strategy_exists[blk])) {
555 s->channel_uses_aht[ch] = use_aht &&
get_bits1(gbc);
558 memset(s->channel_uses_aht, 0,
sizeof(s->channel_uses_aht));
562 if (!s->snr_offset_strategy) {
563 int csnroffst = (
get_bits(gbc, 6) - 15) << 4;
564 int snroffst = (csnroffst +
get_bits(gbc, 4)) << 2;
565 for (ch = 0; ch <= s->channels; ch++)
566 s->snr_offset[ch] = snroffst;
570 if (parse_transient_proc_info) {
571 for (ch = 1; ch <= s->fbw_channels; ch++) {
580 for (ch = 1; ch <= s->fbw_channels; ch++) {
581 if (parse_spx_atten_data &&
get_bits1(gbc)) {
582 s->spx_atten_code[ch] =
get_bits(gbc, 5);
584 s->spx_atten_code[ch] = -1;
589 if (s->num_blocks > 1 &&
get_bits1(gbc)) {
594 int block_start_bits = (s->num_blocks-1) * (4 +
av_log2(s->frame_size-2));
600 for (ch = 1; ch <= s->fbw_channels; ch++) {
601 s->first_spx_coords[ch] = 1;
602 s->first_cpl_coords[ch] = 1;
604 s->first_cpl_leak = 1;
EAC3GaqMode
gain adaptive quantization mode
const uint8_t ff_ac3_slow_decay_tab[4]
const float ff_eac3_spx_atten_tab[32][3]
Table E.25: Spectral Extension Attenuation Table ff_eac3_spx_atten_tab[code][bin]=pow(2.0,(bin+1)*(code+1)/-15.0);.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3]
Table used to ungroup 3 values stored in 5 bits.
static void skip_bits_long(GetBitContext *s, int n)
#define AV_LOG_WARNING
Something somehow does not look correct.
const uint16_t ff_ac3_slow_gain_tab[4]
static int get_sbits(GetBitContext *s, int n)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define COEFF_0
lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23))
const uint8_t ff_ac3_fast_decay_tab[4]
#define COEFF_2
lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23))
void av_log(void *avcl, int level, const char *fmt,...)
#define EAC3_SR_CODE_REDUCED
static void idct6(int pre_mant[6])
Calculate 6-point IDCT of the pre-mantissas.
void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
const int16_t ff_eac3_gaq_remap_1[12]
Table E3.6, Gk=1 No gain (Gk=1) inverse quantization, remapping scale factors ff_eac3_gaq_remap[hebap...
const int16_t ff_eac3_gaq_remap_2_4_a[9][2]
Table E3.6, Gk=2 & Gk=4, A Large mantissa inverse quantization, remapping scale factors ff_eac3_gaq_r...
int ff_eac3_parse_header(AC3DecodeContext *s)
#define COEFF_1
lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23))
const uint8_t ff_eac3_bits_vs_hebap[20]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int noise(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
#define CPL_CH
coupling channel index
const int16_t ff_eac3_gaq_remap_2_4_b[9][2]
Table E3.6, Gk=2 & Gk=4, B Large mantissa inverse quantization, negative mantissa remapping offsets f...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
synthesis window for stochastic i
static const double coeff[2][5]
const int16_t ff_ac3_floor_tab[8]
common internal api header.
const uint8_t ff_eac3_frm_expstr[32][6]
Table E2.14 Frame Exponent Strategy Combinations.
void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
const int16_t(*const [8] ff_eac3_mantissa_vq)[6]
const uint16_t ff_ac3_db_per_bit_tab[4]
Common code between the AC-3 encoder and decoder.