FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
eac3dec.c
Go to the documentation of this file.
1 /*
2  * E-AC-3 decoder
3  * Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
4  * Copyright (c) 2008 Justin Ruggles
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /*
24  * There are several features of E-AC-3 that this decoder does not yet support.
25  *
26  * Enhanced Coupling
27  * No known samples exist. If any ever surface, this feature should not be
28  * too difficult to implement.
29  *
30  * Reduced Sample Rates
31  * No known samples exist. The spec also does not give clear information
32  * on how this is to be implemented.
33  *
34  * Dependent Streams
35  * Only the independent stream is currently decoded. Any dependent
36  * streams are skipped. We have only come across two examples of this, and
37  * they are both just test streams, one for HD-DVD and the other for
38  * Blu-ray.
39  *
40  * Transient Pre-noise Processing
41  * This is side information which a decoder should use to reduce artifacts
42  * caused by transients. There are samples which are known to have this
43  * information, but this decoder currently ignores it.
44  */
45 
46 
47 #include "avcodec.h"
48 #include "internal.h"
49 #include "aac_ac3_parser.h"
50 #include "ac3.h"
51 #include "ac3_parser.h"
52 #include "ac3dec.h"
53 #include "ac3dec_data.h"
54 #include "eac3_data.h"
55 
56 /** gain adaptive quantization mode */
57 typedef enum {
62 } EAC3GaqMode;
63 
64 #define EAC3_SR_CODE_REDUCED 3
65 
67 {
68  int bin, bnd, ch, i;
69  uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
70  float rms_energy[SPX_MAX_BANDS];
71 
72  /* Set copy index mapping table. Set wrap flags to apply a notch filter at
73  wrap points later on. */
74  bin = s->spx_dst_start_freq;
75  num_copy_sections = 0;
76  for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
77  int copysize;
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;
82  wrapflag[bnd] = 1;
83  }
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;
88  }
89  copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
90  bin += copysize;
91  }
92  }
93  copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
94 
95  for (ch = 1; ch <= s->fbw_channels; ch++) {
96  if (!s->channel_uses_spx[ch])
97  continue;
98 
99  /* Copy coeffs from normal bands to extension bands */
100  bin = s->spx_src_start_freq;
101  for (i = 0; i < num_copy_sections; i++) {
102  memcpy(&s->transform_coeffs[ch][bin],
104  copy_sizes[i]*sizeof(INTFLOAT));
105  bin += copy_sizes[i];
106  }
107 
108  /* Calculate RMS energy for each SPX band. */
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];
112  float accum = 0.0f;
113  for (i = 0; i < bandsize; i++) {
114  float coeff = s->transform_coeffs[ch][bin++];
115  accum += coeff * coeff;
116  }
117  rms_energy[bnd] = sqrtf(accum / bandsize);
118  }
119 
120  /* Apply a notch filter at transitions between normal and extension
121  bands and at all wrap points. */
122  if (s->spx_atten_code[ch] >= 0) {
123  const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
124  bin = s->spx_src_start_freq - 2;
125  for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
126  if (wrapflag[bnd]) {
127  INTFLOAT *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];
133  }
134  bin += s->spx_band_sizes[bnd];
135  }
136  }
137 
138  /* Apply noise-blended coefficient scaling based on previously
139  calculated RMS energy, blending factors, and SPX coordinates for
140  each band. */
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 #if USE_FIXED
146  // spx_noise_blend and spx_signal_blend are both FP.23
147  nscale *= 1.0 / (1<<23);
148  sscale *= 1.0 / (1<<23);
149 #endif
150  for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
151  float noise = nscale * (int32_t)av_lfg_get(&s->dith_state);
152  s->transform_coeffs[ch][bin] *= sscale;
153  s->transform_coeffs[ch][bin++] += noise;
154  }
155  }
156  }
157 }
158 
159 
160 /** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */
161 #define COEFF_0 10273905LL
162 
163 /** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */
164 #define COEFF_1 11863283LL
165 
166 /** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */
167 #define COEFF_2 3070444LL
168 
169 /**
170  * Calculate 6-point IDCT of the pre-mantissas.
171  * All calculations are 24-bit fixed-point.
172  */
173 static void idct6(int pre_mant[6])
174 {
175  int tmp;
176  int even0, even1, even2, odd0, odd1, odd2;
177 
178  odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
179 
180  even2 = ( pre_mant[2] * COEFF_0) >> 23;
181  tmp = ( pre_mant[4] * COEFF_1) >> 23;
182  odd0 = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
183 
184  even0 = pre_mant[0] + (tmp >> 1);
185  even1 = pre_mant[0] - tmp;
186 
187  tmp = even0;
188  even0 = tmp + even2;
189  even2 = tmp - even2;
190 
191  tmp = odd0;
192  odd0 = tmp + pre_mant[1] + pre_mant[3];
193  odd2 = tmp + pre_mant[5] - pre_mant[3];
194 
195  pre_mant[0] = even0 + odd0;
196  pre_mant[1] = even1 + odd1;
197  pre_mant[2] = even2 + odd2;
198  pre_mant[3] = even2 - odd2;
199  pre_mant[4] = even1 - odd1;
200  pre_mant[5] = even0 - odd0;
201 }
202 
204 {
205  int bin, blk, gs;
206  int end_bap, gaq_mode;
207  GetBitContext *gbc = &s->gbc;
208  int gaq_gain[AC3_MAX_COEFS];
209 
210  gaq_mode = get_bits(gbc, 2);
211  end_bap = (gaq_mode < 2) ? 12 : 17;
212 
213  /* if GAQ gain is used, decode gain codes for bins with hebap between
214  8 and end_bap */
215  gs = 0;
216  if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
217  /* read 1-bit GAQ gain codes */
218  for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
219  if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
220  gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
221  }
222  } else if (gaq_mode == EAC3_GAQ_124) {
223  /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
224  int gc = 2;
225  for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
226  if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
227  if (gc++ == 2) {
228  int group_code = get_bits(gbc, 5);
229  if (group_code > 26) {
230  av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
231  group_code = 26;
232  }
233  gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
234  gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
235  gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
236  gc = 0;
237  }
238  }
239  }
240  }
241 
242  gs=0;
243  for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
244  int hebap = s->bap[ch][bin];
245  int bits = ff_eac3_bits_vs_hebap[hebap];
246  if (!hebap) {
247  /* zero-mantissa dithering */
248  for (blk = 0; blk < 6; blk++) {
249  s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
250  }
251  } else if (hebap < 8) {
252  /* Vector Quantization */
253  int v = get_bits(gbc, bits);
254  for (blk = 0; blk < 6; blk++) {
255  s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] << 8;
256  }
257  } else {
258  /* Gain Adaptive Quantization */
259  int gbits, log_gain;
260  if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
261  log_gain = gaq_gain[gs++];
262  } else {
263  log_gain = 0;
264  }
265  gbits = bits - log_gain;
266 
267  for (blk = 0; blk < 6; blk++) {
268  int mant = get_sbits(gbc, gbits);
269  if (log_gain && mant == -(1 << (gbits-1))) {
270  /* large mantissa */
271  int b;
272  int mbits = bits - (2 - log_gain);
273  mant = get_sbits(gbc, mbits);
274  mant <<= (23 - (mbits - 1));
275  /* remap mantissa value to correct for asymmetric quantization */
276  if (mant >= 0)
277  b = 1 << (23 - log_gain);
278  else
279  b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] << 8;
280  mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
281  } else {
282  /* small mantissa, no GAQ, or Gk=1 */
283  mant <<= 24 - bits;
284  if (!log_gain) {
285  /* remap mantissa value for no GAQ or Gk=1 */
286  mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
287  }
288  }
289  s->pre_mantissa[ch][bin][blk] = mant;
290  }
291  }
292  idct6(s->pre_mantissa[ch][bin]);
293  }
294 }
295 
297 {
298  int i, blk, ch;
299  int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
300  int parse_transient_proc_info;
301  int num_cpl_blocks;
302  GetBitContext *gbc = &s->gbc;
303 
304  /* An E-AC-3 stream can have multiple independent streams which the
305  application can select from. each independent stream can also contain
306  dependent streams which are used to add or replace channels. */
308  if (!s->eac3_frame_dependent_found) {
310  avpriv_request_sample(s->avctx, "Dependent substream decoding");
311  }
313  } else if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) {
314  av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
316  }
317 
318  /* The substream id indicates which substream this frame belongs to. each
319  independent stream has its own substream id, and the dependent streams
320  associated to an independent stream have matching substream id's. */
321  if (s->substreamid) {
322  /* only decode substream with id=0. skip any additional substreams. */
323  if (!s->eac3_subsbtreamid_found) {
325  avpriv_request_sample(s->avctx, "Additional substreams");
326  }
328  }
329 
331  /* The E-AC-3 specification does not tell how to handle reduced sample
332  rates in bit allocation. The best assumption would be that it is
333  handled like AC-3 DolbyNet, but we cannot be sure until we have a
334  sample which utilizes this feature. */
335  avpriv_request_sample(s->avctx, "Reduced sampling rate");
336  return AVERROR_PATCHWELCOME;
337  }
338  skip_bits(gbc, 5); // skip bitstream id
339 
340  /* volume control params */
341  for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
342  skip_bits(gbc, 5); // skip dialog normalization
343  if (get_bits1(gbc)) {
344  skip_bits(gbc, 8); // skip compression gain word
345  }
346  }
347 
348  /* dependent stream channel map */
350  if (get_bits1(gbc)) {
351  skip_bits(gbc, 16); // skip custom channel map
352  }
353  }
354 
355  /* mixing metadata */
356  if (get_bits1(gbc)) {
357  /* center and surround mix levels */
358  if (s->channel_mode > AC3_CHMODE_STEREO) {
359  s->preferred_downmix = get_bits(gbc, 2);
360  if (s->channel_mode & 1) {
361  /* if three front channels exist */
362  s->center_mix_level_ltrt = get_bits(gbc, 3);
363  s->center_mix_level = get_bits(gbc, 3);
364  }
365  if (s->channel_mode & 4) {
366  /* if a surround channel exists */
367  s->surround_mix_level_ltrt = av_clip(get_bits(gbc, 3), 3, 7);
368  s->surround_mix_level = av_clip(get_bits(gbc, 3), 3, 7);
369  }
370  }
371 
372  /* lfe mix level */
373  if (s->lfe_on && (s->lfe_mix_level_exists = get_bits1(gbc))) {
374  s->lfe_mix_level = get_bits(gbc, 5);
375  }
376 
377  /* info for mixing with other streams and substreams */
379  for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
380  // TODO: apply program scale factor
381  if (get_bits1(gbc)) {
382  skip_bits(gbc, 6); // skip program scale factor
383  }
384  }
385  if (get_bits1(gbc)) {
386  skip_bits(gbc, 6); // skip external program scale factor
387  }
388  /* skip mixing parameter data */
389  switch(get_bits(gbc, 2)) {
390  case 1: skip_bits(gbc, 5); break;
391  case 2: skip_bits(gbc, 12); break;
392  case 3: {
393  int mix_data_size = (get_bits(gbc, 5) + 2) << 3;
394  skip_bits_long(gbc, mix_data_size);
395  break;
396  }
397  }
398  /* skip pan information for mono or dual mono source */
399  if (s->channel_mode < AC3_CHMODE_STEREO) {
400  for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
401  if (get_bits1(gbc)) {
402  /* note: this is not in the ATSC A/52B specification
403  reference: ETSI TS 102 366 V1.1.1
404  section: E.1.3.1.25 */
405  skip_bits(gbc, 8); // skip pan mean direction index
406  skip_bits(gbc, 6); // skip reserved paninfo bits
407  }
408  }
409  }
410  /* skip mixing configuration information */
411  if (get_bits1(gbc)) {
412  for (blk = 0; blk < s->num_blocks; blk++) {
413  if (s->num_blocks == 1 || get_bits1(gbc)) {
414  skip_bits(gbc, 5);
415  }
416  }
417  }
418  }
419  }
420 
421  /* informational metadata */
422  if (get_bits1(gbc)) {
423  s->bitstream_mode = get_bits(gbc, 3);
424  skip_bits(gbc, 2); // skip copyright bit and original bitstream bit
425  if (s->channel_mode == AC3_CHMODE_STEREO) {
426  s->dolby_surround_mode = get_bits(gbc, 2);
427  s->dolby_headphone_mode = get_bits(gbc, 2);
428  }
429  if (s->channel_mode >= AC3_CHMODE_2F2R) {
430  s->dolby_surround_ex_mode = get_bits(gbc, 2);
431  }
432  for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
433  if (get_bits1(gbc)) {
434  skip_bits(gbc, 8); // skip mix level, room type, and A/D converter type
435  }
436  }
438  skip_bits1(gbc); // skip source sample rate code
439  }
440  }
441 
442  /* converter synchronization flag
443  If frames are less than six blocks, this bit should be turned on
444  once every 6 blocks to indicate the start of a frame set.
445  reference: RFC 4598, Section 2.1.3 Frame Sets */
446  if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && s->num_blocks != 6) {
447  skip_bits1(gbc); // skip converter synchronization flag
448  }
449 
450  /* original frame size code if this stream was converted from AC-3 */
452  (s->num_blocks == 6 || get_bits1(gbc))) {
453  skip_bits(gbc, 6); // skip frame size code
454  }
455 
456  /* additional bitstream info */
457  if (get_bits1(gbc)) {
458  int addbsil = get_bits(gbc, 6);
459  for (i = 0; i < addbsil + 1; i++) {
460  skip_bits(gbc, 8); // skip additional bit stream info
461  }
462  }
463 
464  /* audio frame syntax flags, strategy data, and per-frame data */
465 
466  if (s->num_blocks == 6) {
467  ac3_exponent_strategy = get_bits1(gbc);
468  parse_aht_info = get_bits1(gbc);
469  } else {
470  /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
471  do not use AHT */
472  ac3_exponent_strategy = 1;
473  parse_aht_info = 0;
474  }
475 
476  s->snr_offset_strategy = get_bits(gbc, 2);
477  parse_transient_proc_info = get_bits1(gbc);
478 
479  s->block_switch_syntax = get_bits1(gbc);
480  if (!s->block_switch_syntax)
481  memset(s->block_switch, 0, sizeof(s->block_switch));
482 
483  s->dither_flag_syntax = get_bits1(gbc);
484  if (!s->dither_flag_syntax) {
485  for (ch = 1; ch <= s->fbw_channels; ch++)
486  s->dither_flag[ch] = 1;
487  }
488  s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
489 
491  if (!s->bit_allocation_syntax) {
492  /* set default bit allocation parameters */
498  }
499 
500  s->fast_gain_syntax = get_bits1(gbc);
501  s->dba_syntax = get_bits1(gbc);
502  s->skip_syntax = get_bits1(gbc);
503  parse_spx_atten_data = get_bits1(gbc);
504 
505  /* coupling strategy occurrence and coupling use per block */
506  num_cpl_blocks = 0;
507  if (s->channel_mode > 1) {
508  for (blk = 0; blk < s->num_blocks; blk++) {
509  s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
510  if (s->cpl_strategy_exists[blk]) {
511  s->cpl_in_use[blk] = get_bits1(gbc);
512  } else {
513  s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
514  }
515  num_cpl_blocks += s->cpl_in_use[blk];
516  }
517  } else {
518  memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
519  }
520 
521  /* exponent strategy data */
522  if (ac3_exponent_strategy) {
523  /* AC-3-style exponent strategy syntax */
524  for (blk = 0; blk < s->num_blocks; blk++) {
525  for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
526  s->exp_strategy[blk][ch] = get_bits(gbc, 2);
527  }
528  }
529  } else {
530  /* LUT-based exponent strategy syntax */
531  for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
532  int frmchexpstr = get_bits(gbc, 5);
533  for (blk = 0; blk < 6; blk++) {
534  s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
535  }
536  }
537  }
538  /* LFE exponent strategy */
539  if (s->lfe_on) {
540  for (blk = 0; blk < s->num_blocks; blk++) {
541  s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
542  }
543  }
544  /* original exponent strategies if this stream was converted from AC-3 */
546  (s->num_blocks == 6 || get_bits1(gbc))) {
547  skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
548  }
549 
550  /* determine which channels use AHT */
551  if (parse_aht_info) {
552  /* For AHT to be used, all non-zero blocks must reuse exponents from
553  the first block. Furthermore, for AHT to be used in the coupling
554  channel, all blocks must use coupling and use the same coupling
555  strategy. */
556  s->channel_uses_aht[CPL_CH]=0;
557  for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
558  int use_aht = 1;
559  for (blk = 1; blk < 6; blk++) {
560  if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
561  (!ch && s->cpl_strategy_exists[blk])) {
562  use_aht = 0;
563  break;
564  }
565  }
566  s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
567  }
568  } else {
569  memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
570  }
571 
572  /* per-frame SNR offset */
573  if (!s->snr_offset_strategy) {
574  int csnroffst = (get_bits(gbc, 6) - 15) << 4;
575  int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
576  for (ch = 0; ch <= s->channels; ch++)
577  s->snr_offset[ch] = snroffst;
578  }
579 
580  /* transient pre-noise processing data */
581  if (parse_transient_proc_info) {
582  for (ch = 1; ch <= s->fbw_channels; ch++) {
583  if (get_bits1(gbc)) { // channel in transient processing
584  skip_bits(gbc, 10); // skip transient processing location
585  skip_bits(gbc, 8); // skip transient processing length
586  }
587  }
588  }
589 
590  /* spectral extension attenuation data */
591  for (ch = 1; ch <= s->fbw_channels; ch++) {
592  if (parse_spx_atten_data && get_bits1(gbc)) {
593  s->spx_atten_code[ch] = get_bits(gbc, 5);
594  } else {
595  s->spx_atten_code[ch] = -1;
596  }
597  }
598 
599  /* block start information */
600  if (s->num_blocks > 1 && get_bits1(gbc)) {
601  /* reference: Section E2.3.2.27
602  nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame)))
603  The spec does not say what this data is or what it's used for.
604  It is likely the offset of each block within the frame. */
605  int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
606  skip_bits_long(gbc, block_start_bits);
607  avpriv_request_sample(s->avctx, "Block start info");
608  }
609 
610  /* syntax state initialization */
611  for (ch = 1; ch <= s->fbw_channels; ch++) {
612  s->first_spx_coords[ch] = 1;
613  s->first_cpl_coords[ch] = 1;
614  }
615  s->first_cpl_leak = 1;
616 
617  return 0;
618 }
EAC3GaqMode
gain adaptive quantization mode
Definition: eac3dec.c:57
const char * s
Definition: avisynth_c.h:631
static int noise(AVBSFContext *ctx, AVPacket *out)
Definition: noise_bsf.c:37
const uint8_t ff_ac3_slow_decay_tab[4]
Definition: ac3tab.c:280
int dither_flag[AC3_MAX_CHANNELS]
dither flags (dithflg)
Definition: ac3dec.h:208
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);.
Definition: eac3_data.c:1101
int preferred_downmix
Preferred 2-channel downmix mode (dmixmod)
Definition: ac3dec.h:91
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:247
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3]
Table used to ungroup 3 values stored in 5 bits.
Definition: ac3dec_data.c:35
static int ff_eac3_parse_header(AC3DecodeContext *s)
Definition: eac3dec.c:296
static void skip_bits_long(GetBitContext *s, int n)
Definition: get_bits.h:204
#define AC3_MAX_COEFS
Definition: ac3.h:34
const char * b
Definition: vf_curves.c:109
int channels
number of total channels
Definition: ac3dec.h:160
int av_log2(unsigned v)
Definition: intmath.c:26
#define EXP_REUSE
Definition: ac3.h:47
int exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS]
exponent strategies (expstr)
Definition: ac3dec.h:188
int lfe_on
lfe channel in use
Definition: ac3dec.h:86
const uint16_t ff_ac3_slow_gain_tab[4]
Definition: ac3tab.c:288
int block_switch[AC3_MAX_CHANNELS]
block switch flags (blksw)
Definition: ac3dec.h:213
#define blk(i)
Definition: sha.c:185
int dba_syntax
delta bit allocation syntax enabled (dbaflde)
Definition: ac3dec.h:120
int spx_src_start_freq
spx start frequency bin
Definition: ac3dec.h:142
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:232
int lfe_mix_level_exists
indicates if lfemixlevcod is specified (lfemixlevcode)
Definition: ac3dec.h:96
float INTFLOAT
Definition: aac_defines.h:85
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))
Definition: eac3dec.c:161
uint8_t bits
Definition: crc.c:296
uint8_t
int first_cpl_coords[AC3_MAX_CHANNELS]
first coupling coordinates states (firstcplcos)
Definition: ac3dec.h:133
INTFLOAT spx_noise_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]
spx noise blending factor (nblendfact)
Definition: ac3dec.h:149
int bit_allocation_syntax
bit allocation model syntax enabled (bamode)
Definition: ac3dec.h:118
#define av_log(a,...)
Common code between the AC-3 and E-AC-3 decoders.
static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
Definition: eac3dec.c:203
int substreamid
substream identification
Definition: ac3dec.h:78
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
const uint8_t ff_ac3_fast_decay_tab[4]
Definition: ac3tab.c:284
int lfe_ch
index of LFE channel
Definition: ac3dec.h:161
uint8_t first_spx_coords[AC3_MAX_CHANNELS]
first spx coordinates states (firstspxcos)
Definition: ac3dec.h:148
AC3BitAllocParameters bit_alloc_params
bit allocation parameters
Definition: ac3dec.h:192
int dolby_surround_mode
dolby surround mode (dsurmod)
Definition: ac3dec.h:101
GetBitContext gbc
bitstream reader
Definition: ac3dec.h:73
int eac3_subsbtreamid_found
bitstream has E-AC-3 additional substream(s)
Definition: ac3dec.h:100
int dolby_headphone_mode
dolby headphone mode (dheadphonmod)
Definition: ac3dec.h:103
#define COEFF_2
lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23))
Definition: eac3dec.c:167
INTFLOAT transform_coeffs[AC3_MAX_CHANNELS][AC3_MAX_COEFS]
transform coefficients
Definition: ac3dec.h:235
#define EAC3_SR_CODE_REDUCED
Definition: eac3dec.c:64
int block_switch_syntax
block switch syntax enabled (blkswe)
Definition: ac3dec.h:116
int fast_gain_syntax
fast gain codes enabled (frmfgaincode)
Definition: ac3dec.h:119
uint8_t channel_uses_spx[AC3_MAX_CHANNELS]
channel uses spectral extension (chinspx)
Definition: ac3dec.h:140
static void idct6(int pre_mant[6])
Calculate 6-point IDCT of the pre-mantissas.
Definition: eac3dec.c:173
int surround_mix_level_ltrt
Surround mix level index for Lt/Rt (ltrtsurmixlev)
Definition: ac3dec.h:95
#define FFMIN(a, b)
Definition: common.h:96
int dither_flag_syntax
dither flag syntax enabled (dithflage)
Definition: ac3dec.h:117
int32_t
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...
Definition: eac3_data.c:40
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...
Definition: eac3_data.c:49
#define COEFF_1
lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23))
Definition: eac3dec.c:164
AVCodecContext * avctx
parent context
Definition: ac3dec.h:72
const uint8_t ff_eac3_bits_vs_hebap[20]
Definition: eac3_data.c:30
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
int fbw_channels
number of full-bandwidth channels
Definition: ac3dec.h:159
int8_t spx_atten_code[AC3_MAX_CHANNELS]
spx attenuation code (spxattencod)
Definition: ac3dec.h:141
uint8_t bap[AC3_MAX_CHANNELS][AC3_MAX_COEFS]
bit allocation pointers
Definition: ac3dec.h:196
#define CPL_CH
coupling channel index
Definition: ac3.h:32
Libavcodec external API header.
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...
Definition: eac3_data.c:66
static void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
Definition: eac3dec.c:66
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:38
int num_spx_bands
number of spx bands (nspxbnds)
Definition: ac3dec.h:146
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:299
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:324
INTFLOAT spx_signal_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]
spx signal blending factor (sblendfact)
Definition: ac3dec.h:150
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:292
int bitstream_mode
bitstream mode (bsmod)
Definition: ac3dec.h:84
int center_mix_level_ltrt
Center mix level index for Lt/Rt (ltrtcmixlev)
Definition: ac3dec.h:93
int frame_type
frame type (strmtyp)
Definition: ac3dec.h:77
int channel_uses_aht[AC3_MAX_CHANNELS]
channel AHT in use (chahtinu)
Definition: ac3dec.h:154
const int16_t ff_ac3_floor_tab[8]
Definition: ac3tab.c:296
int cpl_in_use[AC3_MAX_BLOCKS]
coupling in use (cplinu)
Definition: ac3dec.h:125
int first_cpl_leak
first coupling leak state (firstcplleak)
Definition: ac3dec.h:193
int surround_mix_level
Surround mix level index.
Definition: ac3dec.h:94
int snr_offset[AC3_MAX_CHANNELS]
signal-to-noise ratio offsets (snroffst)
Definition: ac3dec.h:194
common internal api header.
const uint8_t ff_eac3_frm_expstr[32][6]
Table E2.14 Frame Exponent Strategy Combinations.
Definition: eac3_data.c:1062
int num_blocks
number of audio blocks
Definition: ac3dec.h:82
#define SPX_MAX_BANDS
Definition: ac3dec.h:65
int pre_mantissa[AC3_MAX_CHANNELS][AC3_MAX_COEFS][AC3_MAX_BLOCKS]
pre-IDCT mantissas
Definition: ac3dec.h:155
uint8_t spx_band_sizes[SPX_MAX_BANDS]
number of bins in each spx band
Definition: ac3dec.h:147
int lfe_mix_level
LFE mix level index (lfemixlevcod)
Definition: ac3dec.h:97
int snr_offset_strategy
SNR offset strategy (snroffststr)
Definition: ac3dec.h:115
static const int16_t coeffs[]
int start_freq[AC3_MAX_CHANNELS]
start frequency bin (strtmant)
Definition: ac3dec.h:176
int center_mix_level
Center mix level index.
Definition: ac3dec.h:92
static uint8_t tmp[8]
Definition: des.c:38
static const double coeff[2][5]
Definition: vf_owdenoise.c:71
int frame_size
current frame size, in bytes
Definition: ac3dec.h:79
const int16_t(*const [8] ff_eac3_mantissa_vq)[6]
Definition: eac3_data.c:1048
int dolby_surround_ex_mode
dolby surround ex mode (dsurexmod)
Definition: ac3dec.h:102
AVLFG dith_state
for dither generation
Definition: ac3dec.h:209
int cpl_strategy_exists[AC3_MAX_BLOCKS]
coupling strategy exists (cplstre)
Definition: ac3dec.h:126
const uint16_t ff_ac3_db_per_bit_tab[4]
Definition: ac3tab.c:292
int eac3_frame_dependent_found
bitstream has E-AC-3 dependent frame(s)
Definition: ac3dec.h:99
Common code between the AC-3 encoder and decoder.
int channel_mode
channel mode (acmod)
Definition: ac3dec.h:85
int spx_dst_start_freq
spx starting frequency bin for copying (copystartmant) the copy region ends at the start of the spx r...
Definition: ac3dec.h:144
int skip_syntax
skip field syntax enabled (skipflde)
Definition: ac3dec.h:121