Libav
|
00001 /* 00002 * E-AC-3 decoder 00003 * Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com> 00004 * Copyright (c) 2008 Justin Ruggles 00005 * 00006 * This file is part of FFmpeg. 00007 * 00008 * FFmpeg is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * FFmpeg is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with FFmpeg; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 /* 00024 * There are several features of E-AC-3 that this decoder does not yet support. 00025 * 00026 * Enhanced Coupling 00027 * No known samples exist. If any ever surface, this feature should not be 00028 * too difficult to implement. 00029 * 00030 * Reduced Sample Rates 00031 * No known samples exist. The spec also does not give clear information 00032 * on how this is to be implemented. 00033 * 00034 * Dependent Streams 00035 * Only the independent stream is currently decoded. Any dependent 00036 * streams are skipped. We have only come across two examples of this, and 00037 * they are both just test streams, one for HD-DVD and the other for 00038 * Blu-ray. 00039 * 00040 * Transient Pre-noise Processing 00041 * This is side information which a decoder should use to reduce artifacts 00042 * caused by transients. There are samples which are known to have this 00043 * information, but this decoder currently ignores it. 00044 */ 00045 00046 00047 #include "avcodec.h" 00048 #include "internal.h" 00049 #include "aac_ac3_parser.h" 00050 #include "ac3.h" 00051 #include "ac3_parser.h" 00052 #include "ac3dec.h" 00053 #include "ac3dec_data.h" 00054 #include "eac3dec_data.h" 00055 00057 typedef enum { 00058 EAC3_GAQ_NO =0, 00059 EAC3_GAQ_12, 00060 EAC3_GAQ_14, 00061 EAC3_GAQ_124 00062 } EAC3GaqMode; 00063 00064 #define EAC3_SR_CODE_REDUCED 3 00065 00066 void ff_eac3_apply_spectral_extension(AC3DecodeContext *s) 00067 { 00068 int bin, bnd, ch, i; 00069 uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS]; 00070 float rms_energy[SPX_MAX_BANDS]; 00071 00072 /* Set copy index mapping table. Set wrap flags to apply a notch filter at 00073 wrap points later on. */ 00074 bin = s->spx_dst_start_freq; 00075 num_copy_sections = 0; 00076 for (bnd = 0; bnd < s->num_spx_bands; bnd++) { 00077 int copysize; 00078 int bandsize = s->spx_band_sizes[bnd]; 00079 if (bin + bandsize > s->spx_src_start_freq) { 00080 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq; 00081 bin = s->spx_dst_start_freq; 00082 wrapflag[bnd] = 1; 00083 } 00084 for (i = 0; i < bandsize; i += copysize) { 00085 if (bin == s->spx_src_start_freq) { 00086 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq; 00087 bin = s->spx_dst_start_freq; 00088 } 00089 copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin); 00090 bin += copysize; 00091 } 00092 } 00093 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq; 00094 00095 for (ch = 1; ch <= s->fbw_channels; ch++) { 00096 if (!s->channel_uses_spx[ch]) 00097 continue; 00098 00099 /* Copy coeffs from normal bands to extension bands */ 00100 bin = s->spx_src_start_freq; 00101 for (i = 0; i < num_copy_sections; i++) { 00102 memcpy(&s->transform_coeffs[ch][bin], 00103 &s->transform_coeffs[ch][s->spx_dst_start_freq], 00104 copy_sizes[i]*sizeof(float)); 00105 bin += copy_sizes[i]; 00106 } 00107 00108 /* Calculate RMS energy for each SPX band. */ 00109 bin = s->spx_src_start_freq; 00110 for (bnd = 0; bnd < s->num_spx_bands; bnd++) { 00111 int bandsize = s->spx_band_sizes[bnd]; 00112 float accum = 0.0f; 00113 for (i = 0; i < bandsize; i++) { 00114 float coeff = s->transform_coeffs[ch][bin++]; 00115 accum += coeff * coeff; 00116 } 00117 rms_energy[bnd] = sqrtf(accum / bandsize); 00118 } 00119 00120 /* Apply a notch filter at transitions between normal and extension 00121 bands and at all wrap points. */ 00122 if (s->spx_atten_code[ch] >= 0) { 00123 const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]]; 00124 bin = s->spx_src_start_freq - 2; 00125 for (bnd = 0; bnd < s->num_spx_bands; bnd++) { 00126 if (wrapflag[bnd]) { 00127 float *coeffs = &s->transform_coeffs[ch][bin]; 00128 coeffs[0] *= atten_tab[0]; 00129 coeffs[1] *= atten_tab[1]; 00130 coeffs[2] *= atten_tab[2]; 00131 coeffs[3] *= atten_tab[1]; 00132 coeffs[4] *= atten_tab[0]; 00133 } 00134 bin += s->spx_band_sizes[bnd]; 00135 } 00136 } 00137 00138 /* Apply noise-blended coefficient scaling based on previously 00139 calculated RMS energy, blending factors, and SPX coordinates for 00140 each band. */ 00141 bin = s->spx_src_start_freq; 00142 for (bnd = 0; bnd < s->num_spx_bands; bnd++) { 00143 float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f/(1<<31)); 00144 float sscale = s->spx_signal_blend[ch][bnd]; 00145 for (i = 0; i < s->spx_band_sizes[bnd]; i++) { 00146 float noise = nscale * (int32_t)av_lfg_get(&s->dith_state); 00147 s->transform_coeffs[ch][bin] *= sscale; 00148 s->transform_coeffs[ch][bin++] += noise; 00149 } 00150 } 00151 } 00152 } 00153 00154 00156 #define COEFF_0 10273905LL 00157 00159 #define COEFF_1 11863283LL 00160 00162 #define COEFF_2 3070444LL 00163 00168 static void idct6(int pre_mant[6]) 00169 { 00170 int tmp; 00171 int even0, even1, even2, odd0, odd1, odd2; 00172 00173 odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5]; 00174 00175 even2 = ( pre_mant[2] * COEFF_0) >> 23; 00176 tmp = ( pre_mant[4] * COEFF_1) >> 23; 00177 odd0 = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23; 00178 00179 even0 = pre_mant[0] + (tmp >> 1); 00180 even1 = pre_mant[0] - tmp; 00181 00182 tmp = even0; 00183 even0 = tmp + even2; 00184 even2 = tmp - even2; 00185 00186 tmp = odd0; 00187 odd0 = tmp + pre_mant[1] + pre_mant[3]; 00188 odd2 = tmp + pre_mant[5] - pre_mant[3]; 00189 00190 pre_mant[0] = even0 + odd0; 00191 pre_mant[1] = even1 + odd1; 00192 pre_mant[2] = even2 + odd2; 00193 pre_mant[3] = even2 - odd2; 00194 pre_mant[4] = even1 - odd1; 00195 pre_mant[5] = even0 - odd0; 00196 } 00197 00198 void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch) 00199 { 00200 int bin, blk, gs; 00201 int end_bap, gaq_mode; 00202 GetBitContext *gbc = &s->gbc; 00203 int gaq_gain[AC3_MAX_COEFS]; 00204 00205 gaq_mode = get_bits(gbc, 2); 00206 end_bap = (gaq_mode < 2) ? 12 : 17; 00207 00208 /* if GAQ gain is used, decode gain codes for bins with hebap between 00209 8 and end_bap */ 00210 gs = 0; 00211 if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) { 00212 /* read 1-bit GAQ gain codes */ 00213 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { 00214 if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap) 00215 gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1); 00216 } 00217 } else if (gaq_mode == EAC3_GAQ_124) { 00218 /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */ 00219 int gc = 2; 00220 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { 00221 if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) { 00222 if (gc++ == 2) { 00223 int group_code = get_bits(gbc, 5); 00224 if (group_code > 26) { 00225 av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n"); 00226 group_code = 26; 00227 } 00228 gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0]; 00229 gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1]; 00230 gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2]; 00231 gc = 0; 00232 } 00233 } 00234 } 00235 } 00236 00237 gs=0; 00238 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { 00239 int hebap = s->bap[ch][bin]; 00240 int bits = ff_eac3_bits_vs_hebap[hebap]; 00241 if (!hebap) { 00242 /* zero-mantissa dithering */ 00243 for (blk = 0; blk < 6; blk++) { 00244 s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; 00245 } 00246 } else if (hebap < 8) { 00247 /* Vector Quantization */ 00248 int v = get_bits(gbc, bits); 00249 for (blk = 0; blk < 6; blk++) { 00250 s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] << 8; 00251 } 00252 } else { 00253 /* Gain Adaptive Quantization */ 00254 int gbits, log_gain; 00255 if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) { 00256 log_gain = gaq_gain[gs++]; 00257 } else { 00258 log_gain = 0; 00259 } 00260 gbits = bits - log_gain; 00261 00262 for (blk = 0; blk < 6; blk++) { 00263 int mant = get_sbits(gbc, gbits); 00264 if (log_gain && mant == -(1 << (gbits-1))) { 00265 /* large mantissa */ 00266 int b; 00267 int mbits = bits - (2 - log_gain); 00268 mant = get_sbits(gbc, mbits); 00269 mant <<= (23 - (mbits - 1)); 00270 /* remap mantissa value to correct for asymmetric quantization */ 00271 if (mant >= 0) 00272 b = 1 << (23 - log_gain); 00273 else 00274 b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] << 8; 00275 mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b; 00276 } else { 00277 /* small mantissa, no GAQ, or Gk=1 */ 00278 mant <<= 24 - bits; 00279 if (!log_gain) { 00280 /* remap mantissa value for no GAQ or Gk=1 */ 00281 mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15; 00282 } 00283 } 00284 s->pre_mantissa[ch][bin][blk] = mant; 00285 } 00286 } 00287 idct6(s->pre_mantissa[ch][bin]); 00288 } 00289 } 00290 00291 int ff_eac3_parse_header(AC3DecodeContext *s) 00292 { 00293 int i, blk, ch; 00294 int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data; 00295 int parse_transient_proc_info; 00296 int num_cpl_blocks; 00297 GetBitContext *gbc = &s->gbc; 00298 00299 /* An E-AC-3 stream can have multiple independent streams which the 00300 application can select from. each independent stream can also contain 00301 dependent streams which are used to add or replace channels. */ 00302 if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) { 00303 av_log_missing_feature(s->avctx, "Dependent substream decoding", 1); 00304 return AAC_AC3_PARSE_ERROR_FRAME_TYPE; 00305 } else if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) { 00306 av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n"); 00307 return AAC_AC3_PARSE_ERROR_FRAME_TYPE; 00308 } 00309 00310 /* The substream id indicates which substream this frame belongs to. each 00311 independent stream has its own substream id, and the dependent streams 00312 associated to an independent stream have matching substream id's. */ 00313 if (s->substreamid) { 00314 /* only decode substream with id=0. skip any additional substreams. */ 00315 av_log_missing_feature(s->avctx, "Additional substreams", 1); 00316 return AAC_AC3_PARSE_ERROR_FRAME_TYPE; 00317 } 00318 00319 if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) { 00320 /* The E-AC-3 specification does not tell how to handle reduced sample 00321 rates in bit allocation. The best assumption would be that it is 00322 handled like AC-3 DolbyNet, but we cannot be sure until we have a 00323 sample which utilizes this feature. */ 00324 av_log_missing_feature(s->avctx, "Reduced sampling rates", 1); 00325 return -1; 00326 } 00327 skip_bits(gbc, 5); // skip bitstream id 00328 00329 /* volume control params */ 00330 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) { 00331 skip_bits(gbc, 5); // skip dialog normalization 00332 if (get_bits1(gbc)) { 00333 skip_bits(gbc, 8); // skip compression gain word 00334 } 00335 } 00336 00337 /* dependent stream channel map */ 00338 if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) { 00339 if (get_bits1(gbc)) { 00340 skip_bits(gbc, 16); // skip custom channel map 00341 } 00342 } 00343 00344 /* mixing metadata */ 00345 if (get_bits1(gbc)) { 00346 /* center and surround mix levels */ 00347 if (s->channel_mode > AC3_CHMODE_STEREO) { 00348 skip_bits(gbc, 2); // skip preferred stereo downmix mode 00349 if (s->channel_mode & 1) { 00350 /* if three front channels exist */ 00351 skip_bits(gbc, 3); //skip Lt/Rt center mix level 00352 s->center_mix_level = get_bits(gbc, 3); 00353 } 00354 if (s->channel_mode & 4) { 00355 /* if a surround channel exists */ 00356 skip_bits(gbc, 3); //skip Lt/Rt surround mix level 00357 s->surround_mix_level = get_bits(gbc, 3); 00358 } 00359 } 00360 00361 /* lfe mix level */ 00362 if (s->lfe_on && get_bits1(gbc)) { 00363 // TODO: use LFE mix level 00364 skip_bits(gbc, 5); // skip LFE mix level code 00365 } 00366 00367 /* info for mixing with other streams and substreams */ 00368 if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) { 00369 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) { 00370 // TODO: apply program scale factor 00371 if (get_bits1(gbc)) { 00372 skip_bits(gbc, 6); // skip program scale factor 00373 } 00374 } 00375 if (get_bits1(gbc)) { 00376 skip_bits(gbc, 6); // skip external program scale factor 00377 } 00378 /* skip mixing parameter data */ 00379 switch(get_bits(gbc, 2)) { 00380 case 1: skip_bits(gbc, 5); break; 00381 case 2: skip_bits(gbc, 12); break; 00382 case 3: { 00383 int mix_data_size = (get_bits(gbc, 5) + 2) << 3; 00384 skip_bits_long(gbc, mix_data_size); 00385 break; 00386 } 00387 } 00388 /* skip pan information for mono or dual mono source */ 00389 if (s->channel_mode < AC3_CHMODE_STEREO) { 00390 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) { 00391 if (get_bits1(gbc)) { 00392 /* note: this is not in the ATSC A/52B specification 00393 reference: ETSI TS 102 366 V1.1.1 00394 section: E.1.3.1.25 */ 00395 skip_bits(gbc, 8); // skip pan mean direction index 00396 skip_bits(gbc, 6); // skip reserved paninfo bits 00397 } 00398 } 00399 } 00400 /* skip mixing configuration information */ 00401 if (get_bits1(gbc)) { 00402 for (blk = 0; blk < s->num_blocks; blk++) { 00403 if (s->num_blocks == 1 || get_bits1(gbc)) { 00404 skip_bits(gbc, 5); 00405 } 00406 } 00407 } 00408 } 00409 } 00410 00411 /* informational metadata */ 00412 if (get_bits1(gbc)) { 00413 skip_bits(gbc, 3); // skip bit stream mode 00414 skip_bits(gbc, 2); // skip copyright bit and original bitstream bit 00415 if (s->channel_mode == AC3_CHMODE_STEREO) { 00416 skip_bits(gbc, 4); // skip Dolby surround and headphone mode 00417 } 00418 if (s->channel_mode >= AC3_CHMODE_2F2R) { 00419 skip_bits(gbc, 2); // skip Dolby surround EX mode 00420 } 00421 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) { 00422 if (get_bits1(gbc)) { 00423 skip_bits(gbc, 8); // skip mix level, room type, and A/D converter type 00424 } 00425 } 00426 if (s->bit_alloc_params.sr_code != EAC3_SR_CODE_REDUCED) { 00427 skip_bits1(gbc); // skip source sample rate code 00428 } 00429 } 00430 00431 /* converter synchronization flag 00432 If frames are less than six blocks, this bit should be turned on 00433 once every 6 blocks to indicate the start of a frame set. 00434 reference: RFC 4598, Section 2.1.3 Frame Sets */ 00435 if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && s->num_blocks != 6) { 00436 skip_bits1(gbc); // skip converter synchronization flag 00437 } 00438 00439 /* original frame size code if this stream was converted from AC-3 */ 00440 if (s->frame_type == EAC3_FRAME_TYPE_AC3_CONVERT && 00441 (s->num_blocks == 6 || get_bits1(gbc))) { 00442 skip_bits(gbc, 6); // skip frame size code 00443 } 00444 00445 /* additional bitstream info */ 00446 if (get_bits1(gbc)) { 00447 int addbsil = get_bits(gbc, 6); 00448 for (i = 0; i < addbsil + 1; i++) { 00449 skip_bits(gbc, 8); // skip additional bit stream info 00450 } 00451 } 00452 00453 /* audio frame syntax flags, strategy data, and per-frame data */ 00454 00455 if (s->num_blocks == 6) { 00456 ac3_exponent_strategy = get_bits1(gbc); 00457 parse_aht_info = get_bits1(gbc); 00458 } else { 00459 /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and 00460 do not use AHT */ 00461 ac3_exponent_strategy = 1; 00462 parse_aht_info = 0; 00463 } 00464 00465 s->snr_offset_strategy = get_bits(gbc, 2); 00466 parse_transient_proc_info = get_bits1(gbc); 00467 00468 s->block_switch_syntax = get_bits1(gbc); 00469 if (!s->block_switch_syntax) 00470 memset(s->block_switch, 0, sizeof(s->block_switch)); 00471 00472 s->dither_flag_syntax = get_bits1(gbc); 00473 if (!s->dither_flag_syntax) { 00474 for (ch = 1; ch <= s->fbw_channels; ch++) 00475 s->dither_flag[ch] = 1; 00476 } 00477 s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0; 00478 00479 s->bit_allocation_syntax = get_bits1(gbc); 00480 if (!s->bit_allocation_syntax) { 00481 /* set default bit allocation parameters */ 00482 s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2]; 00483 s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1]; 00484 s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab [1]; 00485 s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2]; 00486 s->bit_alloc_params.floor = ff_ac3_floor_tab [7]; 00487 } 00488 00489 s->fast_gain_syntax = get_bits1(gbc); 00490 s->dba_syntax = get_bits1(gbc); 00491 s->skip_syntax = get_bits1(gbc); 00492 parse_spx_atten_data = get_bits1(gbc); 00493 00494 /* coupling strategy occurance and coupling use per block */ 00495 num_cpl_blocks = 0; 00496 if (s->channel_mode > 1) { 00497 for (blk = 0; blk < s->num_blocks; blk++) { 00498 s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc)); 00499 if (s->cpl_strategy_exists[blk]) { 00500 s->cpl_in_use[blk] = get_bits1(gbc); 00501 } else { 00502 s->cpl_in_use[blk] = s->cpl_in_use[blk-1]; 00503 } 00504 num_cpl_blocks += s->cpl_in_use[blk]; 00505 } 00506 } else { 00507 memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use)); 00508 } 00509 00510 /* exponent strategy data */ 00511 if (ac3_exponent_strategy) { 00512 /* AC-3-style exponent strategy syntax */ 00513 for (blk = 0; blk < s->num_blocks; blk++) { 00514 for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) { 00515 s->exp_strategy[blk][ch] = get_bits(gbc, 2); 00516 } 00517 } 00518 } else { 00519 /* LUT-based exponent strategy syntax */ 00520 for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) { 00521 int frmchexpstr = get_bits(gbc, 5); 00522 for (blk = 0; blk < 6; blk++) { 00523 s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk]; 00524 } 00525 } 00526 } 00527 /* LFE exponent strategy */ 00528 if (s->lfe_on) { 00529 for (blk = 0; blk < s->num_blocks; blk++) { 00530 s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc); 00531 } 00532 } 00533 /* original exponent strategies if this stream was converted from AC-3 */ 00534 if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && 00535 (s->num_blocks == 6 || get_bits1(gbc))) { 00536 skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy 00537 } 00538 00539 /* determine which channels use AHT */ 00540 if (parse_aht_info) { 00541 /* For AHT to be used, all non-zero blocks must reuse exponents from 00542 the first block. Furthermore, for AHT to be used in the coupling 00543 channel, all blocks must use coupling and use the same coupling 00544 strategy. */ 00545 s->channel_uses_aht[CPL_CH]=0; 00546 for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) { 00547 int use_aht = 1; 00548 for (blk = 1; blk < 6; blk++) { 00549 if ((s->exp_strategy[blk][ch] != EXP_REUSE) || 00550 (!ch && s->cpl_strategy_exists[blk])) { 00551 use_aht = 0; 00552 break; 00553 } 00554 } 00555 s->channel_uses_aht[ch] = use_aht && get_bits1(gbc); 00556 } 00557 } else { 00558 memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht)); 00559 } 00560 00561 /* per-frame SNR offset */ 00562 if (!s->snr_offset_strategy) { 00563 int csnroffst = (get_bits(gbc, 6) - 15) << 4; 00564 int snroffst = (csnroffst + get_bits(gbc, 4)) << 2; 00565 for (ch = 0; ch <= s->channels; ch++) 00566 s->snr_offset[ch] = snroffst; 00567 } 00568 00569 /* transient pre-noise processing data */ 00570 if (parse_transient_proc_info) { 00571 for (ch = 1; ch <= s->fbw_channels; ch++) { 00572 if (get_bits1(gbc)) { // channel in transient processing 00573 skip_bits(gbc, 10); // skip transient processing location 00574 skip_bits(gbc, 8); // skip transient processing length 00575 } 00576 } 00577 } 00578 00579 /* spectral extension attenuation data */ 00580 for (ch = 1; ch <= s->fbw_channels; ch++) { 00581 if (parse_spx_atten_data && get_bits1(gbc)) { 00582 s->spx_atten_code[ch] = get_bits(gbc, 5); 00583 } else { 00584 s->spx_atten_code[ch] = -1; 00585 } 00586 } 00587 00588 /* block start information */ 00589 if (s->num_blocks > 1 && get_bits1(gbc)) { 00590 /* reference: Section E2.3.2.27 00591 nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame))) 00592 The spec does not say what this data is or what it's used for. 00593 It is likely the offset of each block within the frame. */ 00594 int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2)); 00595 skip_bits_long(gbc, block_start_bits); 00596 av_log_missing_feature(s->avctx, "Block start info", 1); 00597 } 00598 00599 /* syntax state initialization */ 00600 for (ch = 1; ch <= s->fbw_channels; ch++) { 00601 s->first_spx_coords[ch] = 1; 00602 s->first_cpl_coords[ch] = 1; 00603 } 00604 s->first_cpl_leak = 1; 00605 00606 return 0; 00607 }