FFmpeg
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  * Transient Pre-noise Processing
35  * This is side information which a decoder should use to reduce artifacts
36  * caused by transients. There are samples which are known to have this
37  * information, but this decoder currently ignores it.
38  */
39 
40 
41 #include "avcodec.h"
42 #include "aac_ac3_parser.h"
43 #include "ac3.h"
44 #include "ac3dec.h"
45 #include "ac3dec_data.h"
46 #include "eac3_data.h"
47 
48 /** gain adaptive quantization mode */
49 typedef enum {
54 } EAC3GaqMode;
55 
56 #define EAC3_SR_CODE_REDUCED 3
57 
58 static void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
59 {
60  int bin, bnd, ch, i;
61  uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
62  float rms_energy[SPX_MAX_BANDS];
63 
64  /* Set copy index mapping table. Set wrap flags to apply a notch filter at
65  wrap points later on. */
66  bin = s->spx_dst_start_freq;
67  num_copy_sections = 0;
68  for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
69  int copysize;
70  int bandsize = s->spx_band_sizes[bnd];
71  if (bin + bandsize > s->spx_src_start_freq) {
72  copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
73  bin = s->spx_dst_start_freq;
74  wrapflag[bnd] = 1;
75  }
76  for (i = 0; i < bandsize; i += copysize) {
77  if (bin == s->spx_src_start_freq) {
78  copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
79  bin = s->spx_dst_start_freq;
80  }
81  copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
82  bin += copysize;
83  }
84  }
85  copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
86 
87  for (ch = 1; ch <= s->fbw_channels; ch++) {
88  if (!s->channel_uses_spx[ch])
89  continue;
90 
91  /* Copy coeffs from normal bands to extension bands */
92  bin = s->spx_src_start_freq;
93  for (i = 0; i < num_copy_sections; i++) {
94  memcpy(&s->transform_coeffs[ch][bin],
95  &s->transform_coeffs[ch][s->spx_dst_start_freq],
96  copy_sizes[i]*sizeof(INTFLOAT));
97  bin += copy_sizes[i];
98  }
99 
100  /* Calculate RMS energy for each SPX band. */
101  bin = s->spx_src_start_freq;
102  for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
103  int bandsize = s->spx_band_sizes[bnd];
104  float accum = 0.0f;
105  for (i = 0; i < bandsize; i++) {
106  float coeff = s->transform_coeffs[ch][bin++];
107  accum += coeff * coeff;
108  }
109  rms_energy[bnd] = sqrtf(accum / bandsize);
110  }
111 
112  /* Apply a notch filter at transitions between normal and extension
113  bands and at all wrap points. */
114  if (s->spx_atten_code[ch] >= 0) {
115  const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
116  bin = s->spx_src_start_freq - 2;
117  for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
118  if (wrapflag[bnd]) {
119  INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
120  coeffs[0] *= atten_tab[0];
121  coeffs[1] *= atten_tab[1];
122  coeffs[2] *= atten_tab[2];
123  coeffs[3] *= atten_tab[1];
124  coeffs[4] *= atten_tab[0];
125  }
126  bin += s->spx_band_sizes[bnd];
127  }
128  }
129 
130  /* Apply noise-blended coefficient scaling based on previously
131  calculated RMS energy, blending factors, and SPX coordinates for
132  each band. */
133  bin = s->spx_src_start_freq;
134  for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
135  float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
136  float sscale = s->spx_signal_blend[ch][bnd];
137 #if USE_FIXED
138  // spx_noise_blend and spx_signal_blend are both FP.23
139  nscale *= 1.0 / (1<<23);
140  sscale *= 1.0 / (1<<23);
141  if (nscale < -1.0)
142  nscale = -1.0;
143 #endif
144  for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
145  UINTFLOAT noise = (INTFLOAT)(nscale * (int32_t)av_lfg_get(&s->dith_state));
146  s->transform_coeffs[ch][bin] *= sscale;
147  s->transform_coeffs[ch][bin++] += noise;
148  }
149  }
150  }
151 }
152 
153 
154 /** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */
155 #define COEFF_0 10273905LL
156 
157 /** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */
158 #define COEFF_1 11863283LL
159 
160 /** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */
161 #define COEFF_2 3070444LL
162 
163 /**
164  * Calculate 6-point IDCT of the pre-mantissas.
165  * All calculations are 24-bit fixed-point.
166  */
167 static void idct6(int pre_mant[6])
168 {
169  int tmp;
170  int even0, even1, even2, odd0, odd1, odd2;
171 
172  odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
173 
174  even2 = ( pre_mant[2] * COEFF_0) >> 23;
175  tmp = ( pre_mant[4] * COEFF_1) >> 23;
176  odd0 = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
177 
178  even0 = pre_mant[0] + (tmp >> 1);
179  even1 = pre_mant[0] - tmp;
180 
181  tmp = even0;
182  even0 = tmp + even2;
183  even2 = tmp - even2;
184 
185  tmp = odd0;
186  odd0 = tmp + pre_mant[1] + pre_mant[3];
187  odd2 = tmp + pre_mant[5] - pre_mant[3];
188 
189  pre_mant[0] = even0 + odd0;
190  pre_mant[1] = even1 + odd1;
191  pre_mant[2] = even2 + odd2;
192  pre_mant[3] = even2 - odd2;
193  pre_mant[4] = even1 - odd1;
194  pre_mant[5] = even0 - odd0;
195 }
196 
197 static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
198 {
199  int bin, blk, gs;
200  int end_bap, gaq_mode;
201  GetBitContext *gbc = &s->gbc;
202  int gaq_gain[AC3_MAX_COEFS];
203 
204  gaq_mode = get_bits(gbc, 2);
205  end_bap = (gaq_mode < 2) ? 12 : 17;
206 
207  /* if GAQ gain is used, decode gain codes for bins with hebap between
208  8 and end_bap */
209  gs = 0;
210  if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
211  /* read 1-bit GAQ gain codes */
212  for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
213  if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
214  gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
215  }
216  } else if (gaq_mode == EAC3_GAQ_124) {
217  /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
218  int gc = 2;
219  for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
220  if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
221  if (gc++ == 2) {
222  int group_code = get_bits(gbc, 5);
223  if (group_code > 26) {
224  av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
225  group_code = 26;
226  }
227  gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
228  gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
229  gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
230  gc = 0;
231  }
232  }
233  }
234  }
235 
236  gs=0;
237  for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
238  int hebap = s->bap[ch][bin];
239  int bits = ff_eac3_bits_vs_hebap[hebap];
240  if (!hebap) {
241  /* zero-mantissa dithering */
242  for (blk = 0; blk < 6; blk++) {
243  s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
244  }
245  } else if (hebap < 8) {
246  /* Vector Quantization */
247  int v = get_bits(gbc, bits);
248  for (blk = 0; blk < 6; blk++) {
249  s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
250  }
251  } else {
252  /* Gain Adaptive Quantization */
253  int gbits, log_gain;
254  if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
255  log_gain = gaq_gain[gs++];
256  } else {
257  log_gain = 0;
258  }
259  gbits = bits - log_gain;
260 
261  for (blk = 0; blk < 6; blk++) {
262  int mant = get_sbits(gbc, gbits);
263  if (log_gain && mant == -(1 << (gbits-1))) {
264  /* large mantissa */
265  int b;
266  int mbits = bits - (2 - log_gain);
267  mant = get_sbits(gbc, mbits);
268  mant = ((unsigned)mant) << (23 - (mbits - 1));
269  /* remap mantissa value to correct for asymmetric quantization */
270  if (mant >= 0)
271  b = 1 << (23 - log_gain);
272  else
273  b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
274  mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
275  } else {
276  /* small mantissa, no GAQ, or Gk=1 */
277  mant *= (1 << 24 - bits);
278  if (!log_gain) {
279  /* remap mantissa value for no GAQ or Gk=1 */
280  mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
281  }
282  }
283  s->pre_mantissa[ch][bin][blk] = mant;
284  }
285  }
286  idct6(s->pre_mantissa[ch][bin]);
287  }
288 }
289 
290 static int ff_eac3_parse_header(AC3DecodeContext *s)
291 {
292  int i, blk, ch;
293  int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
294  int parse_transient_proc_info;
295  int num_cpl_blocks;
296  GetBitContext *gbc = &s->gbc;
297 
298  /* An E-AC-3 stream can have multiple independent streams which the
299  application can select from. each independent stream can also contain
300  dependent streams which are used to add or replace channels. */
301  if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) {
302  av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
304  }
305 
306  /* The substream id indicates which substream this frame belongs to. each
307  independent stream has its own substream id, and the dependent streams
308  associated to an independent stream have matching substream id's. */
309  if (s->substreamid) {
310  /* only decode substream with id=0. skip any additional substreams. */
311  if (!s->eac3_subsbtreamid_found) {
312  s->eac3_subsbtreamid_found = 1;
313  avpriv_request_sample(s->avctx, "Additional substreams");
314  }
316  }
317 
318  if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) {
319  /* The E-AC-3 specification does not tell how to handle reduced sample
320  rates in bit allocation. The best assumption would be that it is
321  handled like AC-3 DolbyNet, but we cannot be sure until we have a
322  sample which utilizes this feature. */
323  avpriv_request_sample(s->avctx, "Reduced sampling rate");
324  return AVERROR_PATCHWELCOME;
325  }
326  skip_bits(gbc, 5); // skip bitstream id
327 
328  /* volume control params */
329  for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
330  s->dialog_normalization[i] = -get_bits(gbc, 5);
331  if (s->dialog_normalization[i] == 0) {
332  s->dialog_normalization[i] = -31;
333  }
334  if (s->target_level != 0) {
335  s->level_gain[i] = powf(2.0f,
336  (float)(s->target_level - s->dialog_normalization[i])/6.0f);
337  }
338  s->compression_exists[i] = get_bits1(gbc);
339  if (s->compression_exists[i]) {
340  s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(get_bits(gbc, 8));
341  }
342  }
343 
344  /* dependent stream channel map */
345  if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
346  if (get_bits1(gbc)) {
347  int64_t channel_layout = 0;
348  int channel_map = get_bits(gbc, 16);
349  av_log(s->avctx, AV_LOG_DEBUG, "channel_map: %0X\n", channel_map);
350 
351  for (i = 0; i < 16; i++)
352  if (channel_map & (1 << (EAC3_MAX_CHANNELS - i - 1)))
353  channel_layout |= ff_eac3_custom_channel_map_locations[i][1];
354 
355  if (av_popcount64(channel_layout) > EAC3_MAX_CHANNELS) {
356  return AVERROR_INVALIDDATA;
357  }
358  s->channel_map = channel_map;
359  }
360  }
361 
362  /* mixing metadata */
363  if (get_bits1(gbc)) {
364  /* center and surround mix levels */
365  if (s->channel_mode > AC3_CHMODE_STEREO) {
366  s->preferred_downmix = get_bits(gbc, 2);
367  if (s->channel_mode & 1) {
368  /* if three front channels exist */
369  s->center_mix_level_ltrt = get_bits(gbc, 3);
370  s->center_mix_level = get_bits(gbc, 3);
371  }
372  if (s->channel_mode & 4) {
373  /* if a surround channel exists */
374  s->surround_mix_level_ltrt = av_clip(get_bits(gbc, 3), 3, 7);
375  s->surround_mix_level = av_clip(get_bits(gbc, 3), 3, 7);
376  }
377  }
378 
379  /* lfe mix level */
380  if (s->lfe_on && (s->lfe_mix_level_exists = get_bits1(gbc))) {
381  s->lfe_mix_level = get_bits(gbc, 5);
382  }
383 
384  /* info for mixing with other streams and substreams */
385  if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) {
386  for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
387  // TODO: apply program scale factor
388  if (get_bits1(gbc)) {
389  skip_bits(gbc, 6); // skip program scale factor
390  }
391  }
392  if (get_bits1(gbc)) {
393  skip_bits(gbc, 6); // skip external program scale factor
394  }
395  /* skip mixing parameter data */
396  switch(get_bits(gbc, 2)) {
397  case 1: skip_bits(gbc, 5); break;
398  case 2: skip_bits(gbc, 12); break;
399  case 3: {
400  int mix_data_size = (get_bits(gbc, 5) + 2) << 3;
401  skip_bits_long(gbc, mix_data_size);
402  break;
403  }
404  }
405  /* skip pan information for mono or dual mono source */
406  if (s->channel_mode < AC3_CHMODE_STEREO) {
407  for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
408  if (get_bits1(gbc)) {
409  /* note: this is not in the ATSC A/52B specification
410  reference: ETSI TS 102 366 V1.1.1
411  section: E.1.3.1.25 */
412  skip_bits(gbc, 8); // skip pan mean direction index
413  skip_bits(gbc, 6); // skip reserved paninfo bits
414  }
415  }
416  }
417  /* skip mixing configuration information */
418  if (get_bits1(gbc)) {
419  for (blk = 0; blk < s->num_blocks; blk++) {
420  if (s->num_blocks == 1 || get_bits1(gbc)) {
421  skip_bits(gbc, 5);
422  }
423  }
424  }
425  }
426  }
427 
428  /* informational metadata */
429  if (get_bits1(gbc)) {
430  s->bitstream_mode = get_bits(gbc, 3);
431  skip_bits(gbc, 2); // skip copyright bit and original bitstream bit
432  if (s->channel_mode == AC3_CHMODE_STEREO) {
433  s->dolby_surround_mode = get_bits(gbc, 2);
434  s->dolby_headphone_mode = get_bits(gbc, 2);
435  }
436  if (s->channel_mode >= AC3_CHMODE_2F2R) {
437  s->dolby_surround_ex_mode = get_bits(gbc, 2);
438  }
439  for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
440  if (get_bits1(gbc)) {
441  skip_bits(gbc, 8); // skip mix level, room type, and A/D converter type
442  }
443  }
444  if (s->bit_alloc_params.sr_code != EAC3_SR_CODE_REDUCED) {
445  skip_bits1(gbc); // skip source sample rate code
446  }
447  }
448 
449  /* converter synchronization flag
450  If frames are less than six blocks, this bit should be turned on
451  once every 6 blocks to indicate the start of a frame set.
452  reference: RFC 4598, Section 2.1.3 Frame Sets */
453  if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && s->num_blocks != 6) {
454  skip_bits1(gbc); // skip converter synchronization flag
455  }
456 
457  /* original frame size code if this stream was converted from AC-3 */
458  if (s->frame_type == EAC3_FRAME_TYPE_AC3_CONVERT &&
459  (s->num_blocks == 6 || get_bits1(gbc))) {
460  skip_bits(gbc, 6); // skip frame size code
461  }
462 
463  /* additional bitstream info */
464  if (get_bits1(gbc)) {
465  int addbsil = get_bits(gbc, 6);
466  for (i = 0; i < addbsil + 1; i++) {
467  if (i == 0) {
468  /* In this 8 bit chunk, the LSB is equal to flag_ec3_extension_type_a
469  which can be used to detect Atmos presence */
470  skip_bits(gbc, 7);
471  if (get_bits1(gbc)) {
472  s->eac3_extension_type_a = 1;
473  }
474  } else {
475  skip_bits(gbc, 8); // skip additional bit stream info
476  }
477  }
478  }
479 
480  /* audio frame syntax flags, strategy data, and per-frame data */
481 
482  if (s->num_blocks == 6) {
483  ac3_exponent_strategy = get_bits1(gbc);
484  parse_aht_info = get_bits1(gbc);
485  } else {
486  /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
487  do not use AHT */
488  ac3_exponent_strategy = 1;
489  parse_aht_info = 0;
490  }
491 
492  s->snr_offset_strategy = get_bits(gbc, 2);
493  parse_transient_proc_info = get_bits1(gbc);
494 
495  s->block_switch_syntax = get_bits1(gbc);
496  if (!s->block_switch_syntax)
497  memset(s->block_switch, 0, sizeof(s->block_switch));
498 
499  s->dither_flag_syntax = get_bits1(gbc);
500  if (!s->dither_flag_syntax) {
501  for (ch = 1; ch <= s->fbw_channels; ch++)
502  s->dither_flag[ch] = 1;
503  }
504  s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
505 
506  s->bit_allocation_syntax = get_bits1(gbc);
507  if (!s->bit_allocation_syntax) {
508  /* set default bit allocation parameters */
509  s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
510  s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
511  s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab [1];
512  s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
513  s->bit_alloc_params.floor = ff_ac3_floor_tab [7];
514  }
515 
516  s->fast_gain_syntax = get_bits1(gbc);
517  s->dba_syntax = get_bits1(gbc);
518  s->skip_syntax = get_bits1(gbc);
519  parse_spx_atten_data = get_bits1(gbc);
520 
521  /* coupling strategy occurrence and coupling use per block */
522  num_cpl_blocks = 0;
523  if (s->channel_mode > 1) {
524  for (blk = 0; blk < s->num_blocks; blk++) {
525  s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
526  if (s->cpl_strategy_exists[blk]) {
527  s->cpl_in_use[blk] = get_bits1(gbc);
528  } else {
529  s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
530  }
531  num_cpl_blocks += s->cpl_in_use[blk];
532  }
533  } else {
534  memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
535  }
536 
537  /* exponent strategy data */
538  if (ac3_exponent_strategy) {
539  /* AC-3-style exponent strategy syntax */
540  for (blk = 0; blk < s->num_blocks; blk++) {
541  for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
542  s->exp_strategy[blk][ch] = get_bits(gbc, 2);
543  }
544  }
545  } else {
546  /* LUT-based exponent strategy syntax */
547  for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
548  int frmchexpstr = get_bits(gbc, 5);
549  for (blk = 0; blk < 6; blk++) {
550  s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
551  }
552  }
553  }
554  /* LFE exponent strategy */
555  if (s->lfe_on) {
556  for (blk = 0; blk < s->num_blocks; blk++) {
557  s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
558  }
559  }
560  /* original exponent strategies if this stream was converted from AC-3 */
561  if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
562  (s->num_blocks == 6 || get_bits1(gbc))) {
563  skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
564  }
565 
566  /* determine which channels use AHT */
567  if (parse_aht_info) {
568  /* For AHT to be used, all non-zero blocks must reuse exponents from
569  the first block. Furthermore, for AHT to be used in the coupling
570  channel, all blocks must use coupling and use the same coupling
571  strategy. */
572  s->channel_uses_aht[CPL_CH]=0;
573  for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
574  int use_aht = 1;
575  for (blk = 1; blk < 6; blk++) {
576  if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
577  (!ch && s->cpl_strategy_exists[blk])) {
578  use_aht = 0;
579  break;
580  }
581  }
582  s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
583  }
584  } else {
585  memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
586  }
587 
588  /* per-frame SNR offset */
589  if (!s->snr_offset_strategy) {
590  int csnroffst = (get_bits(gbc, 6) - 15) << 4;
591  int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
592  for (ch = 0; ch <= s->channels; ch++)
593  s->snr_offset[ch] = snroffst;
594  }
595 
596  /* transient pre-noise processing data */
597  if (parse_transient_proc_info) {
598  for (ch = 1; ch <= s->fbw_channels; ch++) {
599  if (get_bits1(gbc)) { // channel in transient processing
600  skip_bits(gbc, 10); // skip transient processing location
601  skip_bits(gbc, 8); // skip transient processing length
602  }
603  }
604  }
605 
606  /* spectral extension attenuation data */
607  for (ch = 1; ch <= s->fbw_channels; ch++) {
608  if (parse_spx_atten_data && get_bits1(gbc)) {
609  s->spx_atten_code[ch] = get_bits(gbc, 5);
610  } else {
611  s->spx_atten_code[ch] = -1;
612  }
613  }
614 
615  /* block start information */
616  if (s->num_blocks > 1 && get_bits1(gbc)) {
617  /* reference: Section E2.3.2.27
618  nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame)))
619  The spec does not say what this data is or what it's used for.
620  It is likely the offset of each block within the frame. */
621  int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
622  skip_bits_long(gbc, block_start_bits);
623  avpriv_request_sample(s->avctx, "Block start info");
624  }
625 
626  /* syntax state initialization */
627  for (ch = 1; ch <= s->fbw_channels; ch++) {
628  s->first_spx_coords[ch] = 1;
629  s->first_cpl_coords[ch] = 1;
630  }
631  s->first_cpl_leak = 1;
632 
633  return 0;
634 }
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:278
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
INTFLOAT
#define INTFLOAT
Definition: dct32_template.c:44
ff_ac3_fast_decay_tab
const uint8_t ff_ac3_fast_decay_tab[4]
Definition: ac3tab.c:130
av_clip
#define av_clip
Definition: common.h:98
ff_eac3_parse_header
static int ff_eac3_parse_header(AC3DecodeContext *s)
Definition: eac3dec.c:290
ff_eac3_frm_expstr
const uint8_t ff_eac3_frm_expstr[32][6]
Table E2.14 Frame Exponent Strategy Combinations.
Definition: eac3_data.c:1064
av_popcount64
#define av_popcount64
Definition: common.h:155
aac_ac3_parser.h
EAC3_GAQ_14
@ EAC3_GAQ_14
Definition: eac3dec.c:52
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
b
#define b
Definition: input.c:41
EAC3_FRAME_TYPE_RESERVED
@ EAC3_FRAME_TYPE_RESERVED
Definition: ac3defs.h:101
COEFF_0
#define COEFF_0
lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23))
Definition: eac3dec.c:155
ff_eac3_decode_transform_coeffs_aht_ch
static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
Definition: eac3dec.c:197
ff_eac3_gaq_remap_2_4_a
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:51
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
ac3dec.h
GetBitContext
Definition: get_bits.h:108
noise
static int noise(AVBSFContext *ctx, AVPacket *pkt)
Definition: noise.c:126
EAC3_FRAME_TYPE_DEPENDENT
@ EAC3_FRAME_TYPE_DEPENDENT
Definition: ac3defs.h:99
COEFF_2
#define COEFF_2
lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23))
Definition: eac3dec.c:161
EXP_REUSE
#define EXP_REUSE
Definition: ac3defs.h:38
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
s
#define s(width, name)
Definition: cbs_vp9.c:198
EAC3_GAQ_12
@ EAC3_GAQ_12
Definition: eac3dec.c:51
av_lfg_get
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:53
AC3_MAX_COEFS
#define AC3_MAX_COEFS
Definition: ac3defs.h:29
eac3_data.h
ff_ac3_floor_tab
const int16_t ff_ac3_floor_tab[8]
Definition: ac3tab.c:142
bits
uint8_t bits
Definition: vp3data.h:128
EAC3_FRAME_TYPE_INDEPENDENT
@ EAC3_FRAME_TYPE_INDEPENDENT
Definition: ac3defs.h:98
get_sbits
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:320
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
channel_map
static const uint8_t channel_map[8][8]
Definition: atrac3plusdec.c:51
blk
#define blk(i)
Definition: sha.c:186
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
EAC3_SR_CODE_REDUCED
#define EAC3_SR_CODE_REDUCED
Definition: eac3dec.c:56
idct6
static void idct6(int pre_mant[6])
Calculate 6-point IDCT of the pre-mantissas.
Definition: eac3dec.c:167
ff_eac3_gaq_remap_2_4_b
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:68
ff_eac3_custom_channel_map_locations
const uint64_t ff_eac3_custom_channel_map_locations[16][2]
Definition: ac3tab.c:150
ff_eac3_bits_vs_hebap
const uint8_t ff_eac3_bits_vs_hebap[20]
Definition: eac3_data.c:32
EAC3_FRAME_TYPE_AC3_CONVERT
@ EAC3_FRAME_TYPE_AC3_CONVERT
Definition: ac3defs.h:100
f
f
Definition: af_crystalizer.c:121
AC3_CHMODE_STEREO
@ AC3_CHMODE_STEREO
Definition: ac3defs.h:57
powf
#define powf(x, y)
Definition: libm.h:50
ff_ac3_db_per_bit_tab
const uint16_t ff_ac3_db_per_bit_tab[4]
Definition: ac3tab.c:138
ac3dec_data.h
ff_ac3_ungroup_3_in_5_bits_tab
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:34
COEFF_1
#define COEFF_1
lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23))
Definition: eac3dec.c:158
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:413
ff_eac3_mantissa_vq
const int16_t(*const [8] ff_eac3_mantissa_vq)[6]
Definition: eac3_data.c:1050
CPL_CH
#define CPL_CH
coupling channel index
Definition: ac3defs.h:27
EAC3_GAQ_NO
@ EAC3_GAQ_NO
Definition: eac3dec.c:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
ff_ac3_slow_decay_tab
const uint8_t ff_ac3_slow_decay_tab[4]
Definition: ac3tab.c:126
ff_eac3_apply_spectral_extension
static void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
Definition: eac3dec.c:58
AC3_HEAVY_RANGE
#define AC3_HEAVY_RANGE(x)
Definition: ac3.h:71
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
EAC3_GAQ_124
@ EAC3_GAQ_124
Definition: eac3dec.c:53
UINTFLOAT
float UINTFLOAT
Definition: aac_defines.h:89
AAC_AC3_PARSE_ERROR_FRAME_TYPE
@ AAC_AC3_PARSE_ERROR_FRAME_TYPE
Definition: aac_ac3_parser.h:36
avcodec.h
ff_eac3_gaq_remap_1
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:42
AC3_CHMODE_2F2R
@ AC3_CHMODE_2F2R
Definition: ac3defs.h:61
EAC3_MAX_CHANNELS
#define EAC3_MAX_CHANNELS
maximum number of channels in EAC3
Definition: ac3defs.h:25
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
ff_ac3_slow_gain_tab
const uint16_t ff_ac3_slow_gain_tab[4]
Definition: ac3tab.c:134
ac3.h
int32_t
int32_t
Definition: audioconvert.c:56
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:79
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
INTFLOAT
float INTFLOAT
Definition: aac_defines.h:88
EAC3GaqMode
EAC3GaqMode
gain adaptive quantization mode
Definition: eac3dec.c:49
ff_eac3_spx_atten_tab
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....
Definition: eac3_data.c:1103