]> git.sesse.net Git - ffmpeg/blob - libavcodec/eac3dec.c
vp9: split superframes in the filtering stage before actual decoding
[ffmpeg] / libavcodec / eac3dec.c
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 Libav.
7  *
8  * Libav 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  * Libav 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 Libav; 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 {
58     EAC3_GAQ_NO =0,
59     EAC3_GAQ_12,
60     EAC3_GAQ_14,
61     EAC3_GAQ_124
62 } EAC3GaqMode;
63
64 #define EAC3_SR_CODE_REDUCED  3
65
66 void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
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],
103                    &s->transform_coeffs[ch][s->spx_dst_start_freq],
104                    copy_sizes[i]*sizeof(float));
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                     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];
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             for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
146                 float noise  = nscale * (int32_t)av_lfg_get(&s->dith_state);
147                 s->transform_coeffs[ch][bin]   *= sscale;
148                 s->transform_coeffs[ch][bin++] += noise;
149             }
150         }
151     }
152 }
153
154
155 /** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */
156 #define COEFF_0 10273905LL
157
158 /** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */
159 #define COEFF_1 11863283LL
160
161 /** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */
162 #define COEFF_2  3070444LL
163
164 /**
165  * Calculate 6-point IDCT of the pre-mantissas.
166  * All calculations are 24-bit fixed-point.
167  */
168 static void idct6(int pre_mant[6])
169 {
170     int tmp;
171     int even0, even1, even2, odd0, odd1, odd2;
172
173     odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
174
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;
178
179     even0 = pre_mant[0] + (tmp >> 1);
180     even1 = pre_mant[0] - tmp;
181
182     tmp = even0;
183     even0 = tmp + even2;
184     even2 = tmp - even2;
185
186     tmp = odd0;
187     odd0 = tmp + pre_mant[1] + pre_mant[3];
188     odd2 = tmp + pre_mant[5] - pre_mant[3];
189
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;
196 }
197
198 void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
199 {
200     int bin, blk, gs;
201     int end_bap, gaq_mode;
202     GetBitContext *gbc = &s->gbc;
203     int gaq_gain[AC3_MAX_COEFS];
204
205     gaq_mode = get_bits(gbc, 2);
206     end_bap = (gaq_mode < 2) ? 12 : 17;
207
208     /* if GAQ gain is used, decode gain codes for bins with hebap between
209        8 and end_bap */
210     gs = 0;
211     if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
212         /* read 1-bit GAQ gain codes */
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);
216         }
217     } else if (gaq_mode == EAC3_GAQ_124) {
218         /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
219         int gc = 2;
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) {
222                 if (gc++ == 2) {
223                     int group_code = get_bits(gbc, 5);
224                     if (group_code > 26) {
225                         av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
226                         group_code = 26;
227                     }
228                     gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
229                     gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
230                     gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
231                     gc = 0;
232                 }
233             }
234         }
235     }
236
237     gs=0;
238     for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
239         int hebap = s->bap[ch][bin];
240         int bits = ff_eac3_bits_vs_hebap[hebap];
241         if (!hebap) {
242             /* zero-mantissa dithering */
243             for (blk = 0; blk < 6; blk++) {
244                 s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
245             }
246         } else if (hebap < 8) {
247             /* Vector Quantization */
248             int v = get_bits(gbc, bits);
249             for (blk = 0; blk < 6; blk++) {
250                 s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] << 8;
251             }
252         } else {
253             /* Gain Adaptive Quantization */
254             int gbits, log_gain;
255             if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
256                 log_gain = gaq_gain[gs++];
257             } else {
258                 log_gain = 0;
259             }
260             gbits = bits - log_gain;
261
262             for (blk = 0; blk < 6; blk++) {
263                 int mant = get_sbits(gbc, gbits);
264                 if (log_gain && mant == -(1 << (gbits-1))) {
265                     /* large mantissa */
266                     int b;
267                     int mbits = bits - (2 - log_gain);
268                     mant = get_sbits(gbc, mbits);
269                     mant <<= (23 - (mbits - 1));
270                     /* remap mantissa value to correct for asymmetric quantization */
271                     if (mant >= 0)
272                         b = 1 << (23 - log_gain);
273                     else
274                         b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] << 8;
275                     mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
276                 } else {
277                     /* small mantissa, no GAQ, or Gk=1 */
278                     mant <<= 24 - bits;
279                     if (!log_gain) {
280                         /* remap mantissa value for no GAQ or Gk=1 */
281                         mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
282                     }
283                 }
284                 s->pre_mantissa[ch][bin][blk] = mant;
285             }
286         }
287         idct6(s->pre_mantissa[ch][bin]);
288     }
289 }
290
291 int ff_eac3_parse_header(AC3DecodeContext *s)
292 {
293     int i, blk, ch;
294     int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
295     int parse_transient_proc_info;
296     int num_cpl_blocks;
297     GetBitContext *gbc = &s->gbc;
298
299     /* An E-AC-3 stream can have multiple independent streams which the
300        application can select from. each independent stream can also contain
301        dependent streams which are used to add or replace channels. */
302     if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
303         if (!s->eac3_frame_dependent_found) {
304             s->eac3_frame_dependent_found = 1;
305             avpriv_request_sample(s->avctx, "Dependent substream decoding");
306         }
307         return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
308     } else if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) {
309         av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
310         return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
311     }
312
313     /* The substream id indicates which substream this frame belongs to. each
314        independent stream has its own substream id, and the dependent streams
315        associated to an independent stream have matching substream id's. */
316     if (s->substreamid) {
317         /* only decode substream with id=0. skip any additional substreams. */
318         if (!s->eac3_subsbtreamid_found) {
319             s->eac3_subsbtreamid_found = 1;
320             avpriv_request_sample(s->avctx, "Additional substreams");
321         }
322         return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
323     }
324
325     if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) {
326         /* The E-AC-3 specification does not tell how to handle reduced sample
327            rates in bit allocation.  The best assumption would be that it is
328            handled like AC-3 DolbyNet, but we cannot be sure until we have a
329            sample which utilizes this feature. */
330         avpriv_request_sample(s->avctx, "Reduced sampling rate");
331         return AVERROR_PATCHWELCOME;
332     }
333     skip_bits(gbc, 5); // skip bitstream id
334
335     /* volume control params */
336     for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
337         skip_bits(gbc, 5); // skip dialog normalization
338         if (get_bits1(gbc)) {
339             skip_bits(gbc, 8); // skip compression gain word
340         }
341     }
342
343     /* dependent stream channel map */
344     if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
345         if (get_bits1(gbc)) {
346             skip_bits(gbc, 16); // skip custom channel map
347         }
348     }
349
350     /* mixing metadata */
351     if (get_bits1(gbc)) {
352         /* center and surround mix levels */
353         if (s->channel_mode > AC3_CHMODE_STEREO) {
354             s->preferred_downmix = get_bits(gbc, 2);
355             if (s->channel_mode & 1) {
356                 /* if three front channels exist */
357                 s->center_mix_level_ltrt = get_bits(gbc, 3);
358                 s->center_mix_level      = get_bits(gbc, 3);
359             }
360             if (s->channel_mode & 4) {
361                 /* if a surround channel exists */
362                 s->surround_mix_level_ltrt = av_clip(get_bits(gbc, 3), 3, 7);
363                 s->surround_mix_level      = av_clip(get_bits(gbc, 3), 3, 7);
364             }
365         }
366
367         /* lfe mix level */
368         if (s->lfe_on && (s->lfe_mix_level_exists = get_bits1(gbc))) {
369             s->lfe_mix_level = get_bits(gbc, 5);
370         }
371
372         /* info for mixing with other streams and substreams */
373         if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) {
374             for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
375                 // TODO: apply program scale factor
376                 if (get_bits1(gbc)) {
377                     skip_bits(gbc, 6);  // skip program scale factor
378                 }
379             }
380             if (get_bits1(gbc)) {
381                 skip_bits(gbc, 6);  // skip external program scale factor
382             }
383             /* skip mixing parameter data */
384             switch(get_bits(gbc, 2)) {
385                 case 1: skip_bits(gbc, 5);  break;
386                 case 2: skip_bits(gbc, 12); break;
387                 case 3: {
388                     int mix_data_size = (get_bits(gbc, 5) + 2) << 3;
389                     skip_bits_long(gbc, mix_data_size);
390                     break;
391                 }
392             }
393             /* skip pan information for mono or dual mono source */
394             if (s->channel_mode < AC3_CHMODE_STEREO) {
395                 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
396                     if (get_bits1(gbc)) {
397                         /* note: this is not in the ATSC A/52B specification
398                            reference: ETSI TS 102 366 V1.1.1
399                                       section: E.1.3.1.25 */
400                         skip_bits(gbc, 8);  // skip pan mean direction index
401                         skip_bits(gbc, 6);  // skip reserved paninfo bits
402                     }
403                 }
404             }
405             /* skip mixing configuration information */
406             if (get_bits1(gbc)) {
407                 for (blk = 0; blk < s->num_blocks; blk++) {
408                     if (s->num_blocks == 1 || get_bits1(gbc)) {
409                         skip_bits(gbc, 5);
410                     }
411                 }
412             }
413         }
414     }
415
416     /* informational metadata */
417     if (get_bits1(gbc)) {
418         s->bitstream_mode = get_bits(gbc, 3);
419         skip_bits(gbc, 2); // skip copyright bit and original bitstream bit
420         if (s->channel_mode == AC3_CHMODE_STEREO) {
421             s->dolby_surround_mode  = get_bits(gbc, 2);
422             s->dolby_headphone_mode = get_bits(gbc, 2);
423         }
424         if (s->channel_mode >= AC3_CHMODE_2F2R) {
425             s->dolby_surround_ex_mode = get_bits(gbc, 2);
426         }
427         for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
428             if (get_bits1(gbc)) {
429                 skip_bits(gbc, 8); // skip mix level, room type, and A/D converter type
430             }
431         }
432         if (s->bit_alloc_params.sr_code != EAC3_SR_CODE_REDUCED) {
433             skip_bits1(gbc); // skip source sample rate code
434         }
435     }
436
437     /* converter synchronization flag
438        If frames are less than six blocks, this bit should be turned on
439        once every 6 blocks to indicate the start of a frame set.
440        reference: RFC 4598, Section 2.1.3  Frame Sets */
441     if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && s->num_blocks != 6) {
442         skip_bits1(gbc); // skip converter synchronization flag
443     }
444
445     /* original frame size code if this stream was converted from AC-3 */
446     if (s->frame_type == EAC3_FRAME_TYPE_AC3_CONVERT &&
447             (s->num_blocks == 6 || get_bits1(gbc))) {
448         skip_bits(gbc, 6); // skip frame size code
449     }
450
451     /* additional bitstream info */
452     if (get_bits1(gbc)) {
453         int addbsil = get_bits(gbc, 6);
454         for (i = 0; i < addbsil + 1; i++) {
455             skip_bits(gbc, 8); // skip additional bit stream info
456         }
457     }
458
459     /* audio frame syntax flags, strategy data, and per-frame data */
460
461     if (s->num_blocks == 6) {
462         ac3_exponent_strategy = get_bits1(gbc);
463         parse_aht_info        = get_bits1(gbc);
464     } else {
465         /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
466            do not use AHT */
467         ac3_exponent_strategy = 1;
468         parse_aht_info = 0;
469     }
470
471     s->snr_offset_strategy    = get_bits(gbc, 2);
472     parse_transient_proc_info = get_bits1(gbc);
473
474     s->block_switch_syntax = get_bits1(gbc);
475     if (!s->block_switch_syntax)
476         memset(s->block_switch, 0, sizeof(s->block_switch));
477
478     s->dither_flag_syntax = get_bits1(gbc);
479     if (!s->dither_flag_syntax) {
480         for (ch = 1; ch <= s->fbw_channels; ch++)
481             s->dither_flag[ch] = 1;
482     }
483     s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
484
485     s->bit_allocation_syntax = get_bits1(gbc);
486     if (!s->bit_allocation_syntax) {
487         /* set default bit allocation parameters */
488         s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
489         s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
490         s->bit_alloc_params.slow_gain  = ff_ac3_slow_gain_tab [1];
491         s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
492         s->bit_alloc_params.floor      = ff_ac3_floor_tab     [7];
493     }
494
495     s->fast_gain_syntax  = get_bits1(gbc);
496     s->dba_syntax        = get_bits1(gbc);
497     s->skip_syntax       = get_bits1(gbc);
498     parse_spx_atten_data = get_bits1(gbc);
499
500     /* coupling strategy occurrence and coupling use per block */
501     num_cpl_blocks = 0;
502     if (s->channel_mode > 1) {
503         for (blk = 0; blk < s->num_blocks; blk++) {
504             s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
505             if (s->cpl_strategy_exists[blk]) {
506                 s->cpl_in_use[blk] = get_bits1(gbc);
507             } else {
508                 s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
509             }
510             num_cpl_blocks += s->cpl_in_use[blk];
511         }
512     } else {
513         memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
514     }
515
516     /* exponent strategy data */
517     if (ac3_exponent_strategy) {
518         /* AC-3-style exponent strategy syntax */
519         for (blk = 0; blk < s->num_blocks; blk++) {
520             for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
521                 s->exp_strategy[blk][ch] = get_bits(gbc, 2);
522             }
523         }
524     } else {
525         /* LUT-based exponent strategy syntax */
526         for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
527             int frmchexpstr = get_bits(gbc, 5);
528             for (blk = 0; blk < 6; blk++) {
529                 s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
530             }
531         }
532     }
533     /* LFE exponent strategy */
534     if (s->lfe_on) {
535         for (blk = 0; blk < s->num_blocks; blk++) {
536             s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
537         }
538     }
539     /* original exponent strategies if this stream was converted from AC-3 */
540     if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
541             (s->num_blocks == 6 || get_bits1(gbc))) {
542         skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
543     }
544
545     /* determine which channels use AHT */
546     if (parse_aht_info) {
547         /* For AHT to be used, all non-zero blocks must reuse exponents from
548            the first block.  Furthermore, for AHT to be used in the coupling
549            channel, all blocks must use coupling and use the same coupling
550            strategy. */
551         s->channel_uses_aht[CPL_CH]=0;
552         for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
553             int use_aht = 1;
554             for (blk = 1; blk < 6; blk++) {
555                 if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
556                         (!ch && s->cpl_strategy_exists[blk])) {
557                     use_aht = 0;
558                     break;
559                 }
560             }
561             s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
562         }
563     } else {
564         memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
565     }
566
567     /* per-frame SNR offset */
568     if (!s->snr_offset_strategy) {
569         int csnroffst = (get_bits(gbc, 6) - 15) << 4;
570         int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
571         for (ch = 0; ch <= s->channels; ch++)
572             s->snr_offset[ch] = snroffst;
573     }
574
575     /* transient pre-noise processing data */
576     if (parse_transient_proc_info) {
577         for (ch = 1; ch <= s->fbw_channels; ch++) {
578             if (get_bits1(gbc)) { // channel in transient processing
579                 skip_bits(gbc, 10); // skip transient processing location
580                 skip_bits(gbc, 8);  // skip transient processing length
581             }
582         }
583     }
584
585     /* spectral extension attenuation data */
586     for (ch = 1; ch <= s->fbw_channels; ch++) {
587         if (parse_spx_atten_data && get_bits1(gbc)) {
588             s->spx_atten_code[ch] = get_bits(gbc, 5);
589         } else {
590             s->spx_atten_code[ch] = -1;
591         }
592     }
593
594     /* block start information */
595     if (s->num_blocks > 1 && get_bits1(gbc)) {
596         /* reference: Section E2.3.2.27
597            nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame)))
598            The spec does not say what this data is or what it's used for.
599            It is likely the offset of each block within the frame. */
600         int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
601         skip_bits_long(gbc, block_start_bits);
602         avpriv_request_sample(s->avctx, "Block start info");
603     }
604
605     /* syntax state initialization */
606     for (ch = 1; ch <= s->fbw_channels; ch++) {
607         s->first_spx_coords[ch] = 1;
608         s->first_cpl_coords[ch] = 1;
609     }
610     s->first_cpl_leak = 1;
611
612     return 0;
613 }