Mercurial > libavcodec.hg
comparison ac3dec.c @ 6089:12a77958941f libavcodec
cosmetics: rename GetBitContext gb to gbc
author | jbr |
---|---|
date | Sun, 30 Dec 2007 20:47:22 +0000 |
parents | 2b84971fb4f1 |
children | b7b19fbc4746 |
comparison
equal
deleted
inserted
replaced
6088:2b84971fb4f1 | 6089:12a77958941f |
---|---|
186 DECLARE_ALIGNED_16(float, tmp_imdct[256]); ///< temporary storage for imdct transform | 186 DECLARE_ALIGNED_16(float, tmp_imdct[256]); ///< temporary storage for imdct transform |
187 DECLARE_ALIGNED_16(float, tmp_output[512]); ///< temporary storage for output before windowing | 187 DECLARE_ALIGNED_16(float, tmp_output[512]); ///< temporary storage for output before windowing |
188 DECLARE_ALIGNED_16(float, window[256]); ///< window coefficients | 188 DECLARE_ALIGNED_16(float, window[256]); ///< window coefficients |
189 | 189 |
190 /* Miscellaneous. */ | 190 /* Miscellaneous. */ |
191 GetBitContext gb; ///< bitstream reader | 191 GetBitContext gbc; ///< bitstream reader |
192 AVRandomState dith_state; ///< for dither generation | 192 AVRandomState dith_state; ///< for dither generation |
193 AVCodecContext *avctx; ///< parent context | 193 AVCodecContext *avctx; ///< parent context |
194 } AC3DecodeContext; | 194 } AC3DecodeContext; |
195 | 195 |
196 /** | 196 /** |
320 * start of the synchronized ac3 bitstream. | 320 * start of the synchronized ac3 bitstream. |
321 */ | 321 */ |
322 static int ac3_parse_header(AC3DecodeContext *ctx) | 322 static int ac3_parse_header(AC3DecodeContext *ctx) |
323 { | 323 { |
324 AC3HeaderInfo hdr; | 324 AC3HeaderInfo hdr; |
325 GetBitContext *gb = &ctx->gb; | 325 GetBitContext *gbc = &ctx->gbc; |
326 float center_mix_level, surround_mix_level; | 326 float center_mix_level, surround_mix_level; |
327 int err, i; | 327 int err, i; |
328 | 328 |
329 err = ff_ac3_parse_header(gb->buffer, &hdr); | 329 err = ff_ac3_parse_header(gbc->buffer, &hdr); |
330 if(err) | 330 if(err) |
331 return err; | 331 return err; |
332 | 332 |
333 /* get decoding parameters from header info */ | 333 /* get decoding parameters from header info */ |
334 ctx->bit_alloc_params.sr_code = hdr.sr_code; | 334 ctx->bit_alloc_params.sr_code = hdr.sr_code; |
349 ctx->output_mode = ctx->channel_mode; | 349 ctx->output_mode = ctx->channel_mode; |
350 if(ctx->lfe_on) | 350 if(ctx->lfe_on) |
351 ctx->output_mode |= AC3_OUTPUT_LFEON; | 351 ctx->output_mode |= AC3_OUTPUT_LFEON; |
352 | 352 |
353 /* skip over portion of header which has already been read */ | 353 /* skip over portion of header which has already been read */ |
354 skip_bits(gb, 16); // skip the sync_word | 354 skip_bits(gbc, 16); // skip the sync_word |
355 skip_bits(gb, 16); // skip crc1 | 355 skip_bits(gbc, 16); // skip crc1 |
356 skip_bits(gb, 8); // skip fscod and frmsizecod | 356 skip_bits(gbc, 8); // skip fscod and frmsizecod |
357 skip_bits(gb, 11); // skip bsid, bsmod, and acmod | 357 skip_bits(gbc, 11); // skip bsid, bsmod, and acmod |
358 if(ctx->channel_mode == AC3_CHMODE_STEREO) { | 358 if(ctx->channel_mode == AC3_CHMODE_STEREO) { |
359 skip_bits(gb, 2); // skip dsurmod | 359 skip_bits(gbc, 2); // skip dsurmod |
360 } else { | 360 } else { |
361 if((ctx->channel_mode & 1) && ctx->channel_mode != AC3_CHMODE_MONO) | 361 if((ctx->channel_mode & 1) && ctx->channel_mode != AC3_CHMODE_MONO) |
362 skip_bits(gb, 2); // skip cmixlev | 362 skip_bits(gbc, 2); // skip cmixlev |
363 if(ctx->channel_mode & 4) | 363 if(ctx->channel_mode & 4) |
364 skip_bits(gb, 2); // skip surmixlev | 364 skip_bits(gbc, 2); // skip surmixlev |
365 } | 365 } |
366 skip_bits1(gb); // skip lfeon | 366 skip_bits1(gbc); // skip lfeon |
367 | 367 |
368 /* read the rest of the bsi. read twice for dual mono mode. */ | 368 /* read the rest of the bsi. read twice for dual mono mode. */ |
369 i = !(ctx->channel_mode); | 369 i = !(ctx->channel_mode); |
370 do { | 370 do { |
371 skip_bits(gb, 5); // skip dialog normalization | 371 skip_bits(gbc, 5); // skip dialog normalization |
372 if (get_bits1(gb)) | 372 if (get_bits1(gbc)) |
373 skip_bits(gb, 8); //skip compression | 373 skip_bits(gbc, 8); //skip compression |
374 if (get_bits1(gb)) | 374 if (get_bits1(gbc)) |
375 skip_bits(gb, 8); //skip language code | 375 skip_bits(gbc, 8); //skip language code |
376 if (get_bits1(gb)) | 376 if (get_bits1(gbc)) |
377 skip_bits(gb, 7); //skip audio production information | 377 skip_bits(gbc, 7); //skip audio production information |
378 } while (i--); | 378 } while (i--); |
379 | 379 |
380 skip_bits(gb, 2); //skip copyright bit and original bitstream bit | 380 skip_bits(gbc, 2); //skip copyright bit and original bitstream bit |
381 | 381 |
382 /* skip the timecodes (or extra bitstream information for Alternate Syntax) | 382 /* skip the timecodes (or extra bitstream information for Alternate Syntax) |
383 TODO: read & use the xbsi1 downmix levels */ | 383 TODO: read & use the xbsi1 downmix levels */ |
384 if (get_bits1(gb)) | 384 if (get_bits1(gbc)) |
385 skip_bits(gb, 14); //skip timecode1 / xbsi1 | 385 skip_bits(gbc, 14); //skip timecode1 / xbsi1 |
386 if (get_bits1(gb)) | 386 if (get_bits1(gbc)) |
387 skip_bits(gb, 14); //skip timecode2 / xbsi2 | 387 skip_bits(gbc, 14); //skip timecode2 / xbsi2 |
388 | 388 |
389 /* skip additional bitstream info */ | 389 /* skip additional bitstream info */ |
390 if (get_bits1(gb)) { | 390 if (get_bits1(gbc)) { |
391 i = get_bits(gb, 6); | 391 i = get_bits(gbc, 6); |
392 do { | 392 do { |
393 skip_bits(gb, 8); | 393 skip_bits(gbc, 8); |
394 } while(i--); | 394 } while(i--); |
395 } | 395 } |
396 | 396 |
397 /* set stereo downmixing coefficients | 397 /* set stereo downmixing coefficients |
398 reference: Section 7.8.2 Downmixing Into Two Channels */ | 398 reference: Section 7.8.2 Downmixing Into Two Channels */ |
417 | 417 |
418 /** | 418 /** |
419 * Decode the grouped exponents according to exponent strategy. | 419 * Decode the grouped exponents according to exponent strategy. |
420 * reference: Section 7.1.3 Exponent Decoding | 420 * reference: Section 7.1.3 Exponent Decoding |
421 */ | 421 */ |
422 static void decode_exponents(GetBitContext *gb, int exp_strategy, int ngrps, | 422 static void decode_exponents(GetBitContext *gbc, int exp_strategy, int ngrps, |
423 uint8_t absexp, int8_t *dexps) | 423 uint8_t absexp, int8_t *dexps) |
424 { | 424 { |
425 int i, j, grp, group_size; | 425 int i, j, grp, group_size; |
426 int dexp[256]; | 426 int dexp[256]; |
427 int expacc, prevexp; | 427 int expacc, prevexp; |
428 | 428 |
429 /* unpack groups */ | 429 /* unpack groups */ |
430 group_size = exp_strategy + (exp_strategy == EXP_D45); | 430 group_size = exp_strategy + (exp_strategy == EXP_D45); |
431 for(grp=0,i=0; grp<ngrps; grp++) { | 431 for(grp=0,i=0; grp<ngrps; grp++) { |
432 expacc = get_bits(gb, 7); | 432 expacc = get_bits(gbc, 7); |
433 dexp[i++] = exp_ungroup_tab[expacc][0]; | 433 dexp[i++] = exp_ungroup_tab[expacc][0]; |
434 dexp[i++] = exp_ungroup_tab[expacc][1]; | 434 dexp[i++] = exp_ungroup_tab[expacc][1]; |
435 dexp[i++] = exp_ungroup_tab[expacc][2]; | 435 dexp[i++] = exp_ungroup_tab[expacc][2]; |
436 } | 436 } |
437 | 437 |
486 * Get the transform coefficients for a particular channel | 486 * Get the transform coefficients for a particular channel |
487 * reference: Section 7.3 Quantization and Decoding of Mantissas | 487 * reference: Section 7.3 Quantization and Decoding of Mantissas |
488 */ | 488 */ |
489 static int get_transform_coeffs_ch(AC3DecodeContext *ctx, int ch_index, mant_groups *m) | 489 static int get_transform_coeffs_ch(AC3DecodeContext *ctx, int ch_index, mant_groups *m) |
490 { | 490 { |
491 GetBitContext *gb = &ctx->gb; | 491 GetBitContext *gbc = &ctx->gbc; |
492 int i, gcode, tbap, start, end; | 492 int i, gcode, tbap, start, end; |
493 uint8_t *exps; | 493 uint8_t *exps; |
494 uint8_t *bap; | 494 uint8_t *bap; |
495 float *coeffs; | 495 float *coeffs; |
496 | 496 |
507 coeffs[i] = ((av_random(&ctx->dith_state) & 0xFFFF) / 65535.0f) - 0.5f; | 507 coeffs[i] = ((av_random(&ctx->dith_state) & 0xFFFF) / 65535.0f) - 0.5f; |
508 break; | 508 break; |
509 | 509 |
510 case 1: | 510 case 1: |
511 if(m->b1ptr > 2) { | 511 if(m->b1ptr > 2) { |
512 gcode = get_bits(gb, 5); | 512 gcode = get_bits(gbc, 5); |
513 m->b1_mant[0] = b1_mantissas[gcode][0]; | 513 m->b1_mant[0] = b1_mantissas[gcode][0]; |
514 m->b1_mant[1] = b1_mantissas[gcode][1]; | 514 m->b1_mant[1] = b1_mantissas[gcode][1]; |
515 m->b1_mant[2] = b1_mantissas[gcode][2]; | 515 m->b1_mant[2] = b1_mantissas[gcode][2]; |
516 m->b1ptr = 0; | 516 m->b1ptr = 0; |
517 } | 517 } |
518 coeffs[i] = m->b1_mant[m->b1ptr++]; | 518 coeffs[i] = m->b1_mant[m->b1ptr++]; |
519 break; | 519 break; |
520 | 520 |
521 case 2: | 521 case 2: |
522 if(m->b2ptr > 2) { | 522 if(m->b2ptr > 2) { |
523 gcode = get_bits(gb, 7); | 523 gcode = get_bits(gbc, 7); |
524 m->b2_mant[0] = b2_mantissas[gcode][0]; | 524 m->b2_mant[0] = b2_mantissas[gcode][0]; |
525 m->b2_mant[1] = b2_mantissas[gcode][1]; | 525 m->b2_mant[1] = b2_mantissas[gcode][1]; |
526 m->b2_mant[2] = b2_mantissas[gcode][2]; | 526 m->b2_mant[2] = b2_mantissas[gcode][2]; |
527 m->b2ptr = 0; | 527 m->b2ptr = 0; |
528 } | 528 } |
529 coeffs[i] = m->b2_mant[m->b2ptr++]; | 529 coeffs[i] = m->b2_mant[m->b2ptr++]; |
530 break; | 530 break; |
531 | 531 |
532 case 3: | 532 case 3: |
533 coeffs[i] = b3_mantissas[get_bits(gb, 3)]; | 533 coeffs[i] = b3_mantissas[get_bits(gbc, 3)]; |
534 break; | 534 break; |
535 | 535 |
536 case 4: | 536 case 4: |
537 if(m->b4ptr > 1) { | 537 if(m->b4ptr > 1) { |
538 gcode = get_bits(gb, 7); | 538 gcode = get_bits(gbc, 7); |
539 m->b4_mant[0] = b4_mantissas[gcode][0]; | 539 m->b4_mant[0] = b4_mantissas[gcode][0]; |
540 m->b4_mant[1] = b4_mantissas[gcode][1]; | 540 m->b4_mant[1] = b4_mantissas[gcode][1]; |
541 m->b4ptr = 0; | 541 m->b4ptr = 0; |
542 } | 542 } |
543 coeffs[i] = m->b4_mant[m->b4ptr++]; | 543 coeffs[i] = m->b4_mant[m->b4ptr++]; |
544 break; | 544 break; |
545 | 545 |
546 case 5: | 546 case 5: |
547 coeffs[i] = b5_mantissas[get_bits(gb, 4)]; | 547 coeffs[i] = b5_mantissas[get_bits(gbc, 4)]; |
548 break; | 548 break; |
549 | 549 |
550 default: | 550 default: |
551 /* asymmetric dequantization */ | 551 /* asymmetric dequantization */ |
552 coeffs[i] = get_sbits(gb, quantization_tab[tbap]) * scale_factors[quantization_tab[tbap]-1]; | 552 coeffs[i] = get_sbits(gbc, quantization_tab[tbap]) * scale_factors[quantization_tab[tbap]-1]; |
553 break; | 553 break; |
554 } | 554 } |
555 coeffs[i] *= scale_factors[exps[i]]; | 555 coeffs[i] *= scale_factors[exps[i]]; |
556 } | 556 } |
557 | 557 |
767 static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) | 767 static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) |
768 { | 768 { |
769 int fbw_channels = ctx->fbw_channels; | 769 int fbw_channels = ctx->fbw_channels; |
770 int channel_mode = ctx->channel_mode; | 770 int channel_mode = ctx->channel_mode; |
771 int i, bnd, seg, ch; | 771 int i, bnd, seg, ch; |
772 GetBitContext *gb = &ctx->gb; | 772 GetBitContext *gbc = &ctx->gbc; |
773 uint8_t bit_alloc_stages[AC3_MAX_CHANNELS]; | 773 uint8_t bit_alloc_stages[AC3_MAX_CHANNELS]; |
774 | 774 |
775 memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS); | 775 memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS); |
776 | 776 |
777 /* block switch flags */ | 777 /* block switch flags */ |
778 for (ch = 1; ch <= fbw_channels; ch++) | 778 for (ch = 1; ch <= fbw_channels; ch++) |
779 ctx->block_switch[ch] = get_bits1(gb); | 779 ctx->block_switch[ch] = get_bits1(gbc); |
780 | 780 |
781 /* dithering flags */ | 781 /* dithering flags */ |
782 ctx->dither_all = 1; | 782 ctx->dither_all = 1; |
783 for (ch = 1; ch <= fbw_channels; ch++) { | 783 for (ch = 1; ch <= fbw_channels; ch++) { |
784 ctx->dither_flag[ch] = get_bits1(gb); | 784 ctx->dither_flag[ch] = get_bits1(gbc); |
785 if(!ctx->dither_flag[ch]) | 785 if(!ctx->dither_flag[ch]) |
786 ctx->dither_all = 0; | 786 ctx->dither_all = 0; |
787 } | 787 } |
788 | 788 |
789 /* dynamic range */ | 789 /* dynamic range */ |
790 i = !(ctx->channel_mode); | 790 i = !(ctx->channel_mode); |
791 do { | 791 do { |
792 if(get_bits1(gb)) { | 792 if(get_bits1(gbc)) { |
793 ctx->dynamic_range[i] = ((dynamic_range_tab[get_bits(gb, 8)]-1.0) * | 793 ctx->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)]-1.0) * |
794 ctx->avctx->drc_scale)+1.0; | 794 ctx->avctx->drc_scale)+1.0; |
795 } else if(blk == 0) { | 795 } else if(blk == 0) { |
796 ctx->dynamic_range[i] = 1.0f; | 796 ctx->dynamic_range[i] = 1.0f; |
797 } | 797 } |
798 } while(i--); | 798 } while(i--); |
799 | 799 |
800 /* coupling strategy */ | 800 /* coupling strategy */ |
801 if (get_bits1(gb)) { | 801 if (get_bits1(gbc)) { |
802 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); | 802 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
803 ctx->cpl_in_use = get_bits1(gb); | 803 ctx->cpl_in_use = get_bits1(gbc); |
804 if (ctx->cpl_in_use) { | 804 if (ctx->cpl_in_use) { |
805 /* coupling in use */ | 805 /* coupling in use */ |
806 int cpl_begin_freq, cpl_end_freq; | 806 int cpl_begin_freq, cpl_end_freq; |
807 | 807 |
808 /* determine which channels are coupled */ | 808 /* determine which channels are coupled */ |
809 for (ch = 1; ch <= fbw_channels; ch++) | 809 for (ch = 1; ch <= fbw_channels; ch++) |
810 ctx->channel_in_cpl[ch] = get_bits1(gb); | 810 ctx->channel_in_cpl[ch] = get_bits1(gbc); |
811 | 811 |
812 /* phase flags in use */ | 812 /* phase flags in use */ |
813 if (channel_mode == AC3_CHMODE_STEREO) | 813 if (channel_mode == AC3_CHMODE_STEREO) |
814 ctx->phase_flags_in_use = get_bits1(gb); | 814 ctx->phase_flags_in_use = get_bits1(gbc); |
815 | 815 |
816 /* coupling frequency range and band structure */ | 816 /* coupling frequency range and band structure */ |
817 cpl_begin_freq = get_bits(gb, 4); | 817 cpl_begin_freq = get_bits(gbc, 4); |
818 cpl_end_freq = get_bits(gb, 4); | 818 cpl_end_freq = get_bits(gbc, 4); |
819 if (3 + cpl_end_freq - cpl_begin_freq < 0) { | 819 if (3 + cpl_end_freq - cpl_begin_freq < 0) { |
820 av_log(ctx->avctx, AV_LOG_ERROR, "3+cplendf = %d < cplbegf = %d\n", 3+cpl_end_freq, cpl_begin_freq); | 820 av_log(ctx->avctx, AV_LOG_ERROR, "3+cplendf = %d < cplbegf = %d\n", 3+cpl_end_freq, cpl_begin_freq); |
821 return -1; | 821 return -1; |
822 } | 822 } |
823 ctx->num_cpl_bands = ctx->num_cpl_subbands = 3 + cpl_end_freq - cpl_begin_freq; | 823 ctx->num_cpl_bands = ctx->num_cpl_subbands = 3 + cpl_end_freq - cpl_begin_freq; |
824 ctx->start_freq[CPL_CH] = cpl_begin_freq * 12 + 37; | 824 ctx->start_freq[CPL_CH] = cpl_begin_freq * 12 + 37; |
825 ctx->end_freq[CPL_CH] = cpl_end_freq * 12 + 73; | 825 ctx->end_freq[CPL_CH] = cpl_end_freq * 12 + 73; |
826 for (bnd = 0; bnd < ctx->num_cpl_subbands - 1; bnd++) { | 826 for (bnd = 0; bnd < ctx->num_cpl_subbands - 1; bnd++) { |
827 if (get_bits1(gb)) { | 827 if (get_bits1(gbc)) { |
828 ctx->cpl_band_struct[bnd] = 1; | 828 ctx->cpl_band_struct[bnd] = 1; |
829 ctx->num_cpl_bands--; | 829 ctx->num_cpl_bands--; |
830 } | 830 } |
831 } | 831 } |
832 } else { | 832 } else { |
840 if (ctx->cpl_in_use) { | 840 if (ctx->cpl_in_use) { |
841 int cpl_coords_exist = 0; | 841 int cpl_coords_exist = 0; |
842 | 842 |
843 for (ch = 1; ch <= fbw_channels; ch++) { | 843 for (ch = 1; ch <= fbw_channels; ch++) { |
844 if (ctx->channel_in_cpl[ch]) { | 844 if (ctx->channel_in_cpl[ch]) { |
845 if (get_bits1(gb)) { | 845 if (get_bits1(gbc)) { |
846 int master_cpl_coord, cpl_coord_exp, cpl_coord_mant; | 846 int master_cpl_coord, cpl_coord_exp, cpl_coord_mant; |
847 cpl_coords_exist = 1; | 847 cpl_coords_exist = 1; |
848 master_cpl_coord = 3 * get_bits(gb, 2); | 848 master_cpl_coord = 3 * get_bits(gbc, 2); |
849 for (bnd = 0; bnd < ctx->num_cpl_bands; bnd++) { | 849 for (bnd = 0; bnd < ctx->num_cpl_bands; bnd++) { |
850 cpl_coord_exp = get_bits(gb, 4); | 850 cpl_coord_exp = get_bits(gbc, 4); |
851 cpl_coord_mant = get_bits(gb, 4); | 851 cpl_coord_mant = get_bits(gbc, 4); |
852 if (cpl_coord_exp == 15) | 852 if (cpl_coord_exp == 15) |
853 ctx->cpl_coords[ch][bnd] = cpl_coord_mant / 16.0f; | 853 ctx->cpl_coords[ch][bnd] = cpl_coord_mant / 16.0f; |
854 else | 854 else |
855 ctx->cpl_coords[ch][bnd] = (cpl_coord_mant + 16.0f) / 32.0f; | 855 ctx->cpl_coords[ch][bnd] = (cpl_coord_mant + 16.0f) / 32.0f; |
856 ctx->cpl_coords[ch][bnd] *= scale_factors[cpl_coord_exp + master_cpl_coord]; | 856 ctx->cpl_coords[ch][bnd] *= scale_factors[cpl_coord_exp + master_cpl_coord]; |
859 } | 859 } |
860 } | 860 } |
861 /* phase flags */ | 861 /* phase flags */ |
862 if (channel_mode == AC3_CHMODE_STEREO && ctx->phase_flags_in_use && cpl_coords_exist) { | 862 if (channel_mode == AC3_CHMODE_STEREO && ctx->phase_flags_in_use && cpl_coords_exist) { |
863 for (bnd = 0; bnd < ctx->num_cpl_bands; bnd++) { | 863 for (bnd = 0; bnd < ctx->num_cpl_bands; bnd++) { |
864 if (get_bits1(gb)) | 864 if (get_bits1(gbc)) |
865 ctx->cpl_coords[2][bnd] = -ctx->cpl_coords[2][bnd]; | 865 ctx->cpl_coords[2][bnd] = -ctx->cpl_coords[2][bnd]; |
866 } | 866 } |
867 } | 867 } |
868 } | 868 } |
869 | 869 |
870 /* stereo rematrixing strategy and band structure */ | 870 /* stereo rematrixing strategy and band structure */ |
871 if (channel_mode == AC3_CHMODE_STEREO) { | 871 if (channel_mode == AC3_CHMODE_STEREO) { |
872 ctx->rematrixing_strategy = get_bits1(gb); | 872 ctx->rematrixing_strategy = get_bits1(gbc); |
873 if (ctx->rematrixing_strategy) { | 873 if (ctx->rematrixing_strategy) { |
874 ctx->num_rematrixing_bands = 4; | 874 ctx->num_rematrixing_bands = 4; |
875 if(ctx->cpl_in_use && ctx->start_freq[CPL_CH] <= 61) | 875 if(ctx->cpl_in_use && ctx->start_freq[CPL_CH] <= 61) |
876 ctx->num_rematrixing_bands -= 1 + (ctx->start_freq[CPL_CH] == 37); | 876 ctx->num_rematrixing_bands -= 1 + (ctx->start_freq[CPL_CH] == 37); |
877 for(bnd=0; bnd<ctx->num_rematrixing_bands; bnd++) | 877 for(bnd=0; bnd<ctx->num_rematrixing_bands; bnd++) |
878 ctx->rematrixing_flags[bnd] = get_bits1(gb); | 878 ctx->rematrixing_flags[bnd] = get_bits1(gbc); |
879 } | 879 } |
880 } | 880 } |
881 | 881 |
882 /* exponent strategies for each channel */ | 882 /* exponent strategies for each channel */ |
883 ctx->exp_strategy[CPL_CH] = EXP_REUSE; | 883 ctx->exp_strategy[CPL_CH] = EXP_REUSE; |
884 ctx->exp_strategy[ctx->lfe_ch] = EXP_REUSE; | 884 ctx->exp_strategy[ctx->lfe_ch] = EXP_REUSE; |
885 for (ch = !ctx->cpl_in_use; ch <= ctx->channels; ch++) { | 885 for (ch = !ctx->cpl_in_use; ch <= ctx->channels; ch++) { |
886 if(ch == ctx->lfe_ch) | 886 if(ch == ctx->lfe_ch) |
887 ctx->exp_strategy[ch] = get_bits(gb, 1); | 887 ctx->exp_strategy[ch] = get_bits(gbc, 1); |
888 else | 888 else |
889 ctx->exp_strategy[ch] = get_bits(gb, 2); | 889 ctx->exp_strategy[ch] = get_bits(gbc, 2); |
890 if(ctx->exp_strategy[ch] != EXP_REUSE) | 890 if(ctx->exp_strategy[ch] != EXP_REUSE) |
891 bit_alloc_stages[ch] = 3; | 891 bit_alloc_stages[ch] = 3; |
892 } | 892 } |
893 | 893 |
894 /* channel bandwidth */ | 894 /* channel bandwidth */ |
897 if (ctx->exp_strategy[ch] != EXP_REUSE) { | 897 if (ctx->exp_strategy[ch] != EXP_REUSE) { |
898 int prev = ctx->end_freq[ch]; | 898 int prev = ctx->end_freq[ch]; |
899 if (ctx->channel_in_cpl[ch]) | 899 if (ctx->channel_in_cpl[ch]) |
900 ctx->end_freq[ch] = ctx->start_freq[CPL_CH]; | 900 ctx->end_freq[ch] = ctx->start_freq[CPL_CH]; |
901 else { | 901 else { |
902 int bandwidth_code = get_bits(gb, 6); | 902 int bandwidth_code = get_bits(gbc, 6); |
903 if (bandwidth_code > 60) { | 903 if (bandwidth_code > 60) { |
904 av_log(ctx->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60", bandwidth_code); | 904 av_log(ctx->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60", bandwidth_code); |
905 return -1; | 905 return -1; |
906 } | 906 } |
907 ctx->end_freq[ch] = bandwidth_code * 3 + 73; | 907 ctx->end_freq[ch] = bandwidth_code * 3 + 73; |
922 num_groups = (ctx->end_freq[ch] - ctx->start_freq[ch]) / group_size; | 922 num_groups = (ctx->end_freq[ch] - ctx->start_freq[ch]) / group_size; |
923 else if(ch == ctx->lfe_ch) | 923 else if(ch == ctx->lfe_ch) |
924 num_groups = 2; | 924 num_groups = 2; |
925 else | 925 else |
926 num_groups = (ctx->end_freq[ch] + group_size - 4) / group_size; | 926 num_groups = (ctx->end_freq[ch] + group_size - 4) / group_size; |
927 ctx->dexps[ch][0] = get_bits(gb, 4) << !ch; | 927 ctx->dexps[ch][0] = get_bits(gbc, 4) << !ch; |
928 decode_exponents(gb, ctx->exp_strategy[ch], num_groups, ctx->dexps[ch][0], | 928 decode_exponents(gbc, ctx->exp_strategy[ch], num_groups, ctx->dexps[ch][0], |
929 &ctx->dexps[ch][ctx->start_freq[ch]+!!ch]); | 929 &ctx->dexps[ch][ctx->start_freq[ch]+!!ch]); |
930 if(ch != CPL_CH && ch != ctx->lfe_ch) | 930 if(ch != CPL_CH && ch != ctx->lfe_ch) |
931 skip_bits(gb, 2); /* skip gainrng */ | 931 skip_bits(gbc, 2); /* skip gainrng */ |
932 } | 932 } |
933 } | 933 } |
934 | 934 |
935 /* bit allocation information */ | 935 /* bit allocation information */ |
936 if (get_bits1(gb)) { | 936 if (get_bits1(gbc)) { |
937 ctx->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[get_bits(gb, 2)] >> ctx->bit_alloc_params.sr_shift; | 937 ctx->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[get_bits(gbc, 2)] >> ctx->bit_alloc_params.sr_shift; |
938 ctx->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[get_bits(gb, 2)] >> ctx->bit_alloc_params.sr_shift; | 938 ctx->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[get_bits(gbc, 2)] >> ctx->bit_alloc_params.sr_shift; |
939 ctx->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gb, 2)]; | 939 ctx->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gbc, 2)]; |
940 ctx->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gb, 2)]; | 940 ctx->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)]; |
941 ctx->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gb, 3)]; | 941 ctx->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gbc, 3)]; |
942 for(ch=!ctx->cpl_in_use; ch<=ctx->channels; ch++) { | 942 for(ch=!ctx->cpl_in_use; ch<=ctx->channels; ch++) { |
943 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); | 943 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
944 } | 944 } |
945 } | 945 } |
946 | 946 |
947 /* signal-to-noise ratio offsets and fast gains (signal-to-mask ratios) */ | 947 /* signal-to-noise ratio offsets and fast gains (signal-to-mask ratios) */ |
948 if (get_bits1(gb)) { | 948 if (get_bits1(gbc)) { |
949 int csnr; | 949 int csnr; |
950 csnr = (get_bits(gb, 6) - 15) << 4; | 950 csnr = (get_bits(gbc, 6) - 15) << 4; |
951 for (ch = !ctx->cpl_in_use; ch <= ctx->channels; ch++) { /* snr offset and fast gain */ | 951 for (ch = !ctx->cpl_in_use; ch <= ctx->channels; ch++) { /* snr offset and fast gain */ |
952 ctx->snr_offset[ch] = (csnr + get_bits(gb, 4)) << 2; | 952 ctx->snr_offset[ch] = (csnr + get_bits(gbc, 4)) << 2; |
953 ctx->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gb, 3)]; | 953 ctx->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; |
954 } | 954 } |
955 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); | 955 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
956 } | 956 } |
957 | 957 |
958 /* coupling leak information */ | 958 /* coupling leak information */ |
959 if (ctx->cpl_in_use && get_bits1(gb)) { | 959 if (ctx->cpl_in_use && get_bits1(gbc)) { |
960 ctx->bit_alloc_params.cpl_fast_leak = get_bits(gb, 3); | 960 ctx->bit_alloc_params.cpl_fast_leak = get_bits(gbc, 3); |
961 ctx->bit_alloc_params.cpl_slow_leak = get_bits(gb, 3); | 961 ctx->bit_alloc_params.cpl_slow_leak = get_bits(gbc, 3); |
962 bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2); | 962 bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2); |
963 } | 963 } |
964 | 964 |
965 /* delta bit allocation information */ | 965 /* delta bit allocation information */ |
966 if (get_bits1(gb)) { | 966 if (get_bits1(gbc)) { |
967 /* delta bit allocation exists (strategy) */ | 967 /* delta bit allocation exists (strategy) */ |
968 for (ch = !ctx->cpl_in_use; ch <= fbw_channels; ch++) { | 968 for (ch = !ctx->cpl_in_use; ch <= fbw_channels; ch++) { |
969 ctx->dba_mode[ch] = get_bits(gb, 2); | 969 ctx->dba_mode[ch] = get_bits(gbc, 2); |
970 if (ctx->dba_mode[ch] == DBA_RESERVED) { | 970 if (ctx->dba_mode[ch] == DBA_RESERVED) { |
971 av_log(ctx->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); | 971 av_log(ctx->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); |
972 return -1; | 972 return -1; |
973 } | 973 } |
974 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); | 974 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
975 } | 975 } |
976 /* channel delta offset, len and bit allocation */ | 976 /* channel delta offset, len and bit allocation */ |
977 for (ch = !ctx->cpl_in_use; ch <= fbw_channels; ch++) { | 977 for (ch = !ctx->cpl_in_use; ch <= fbw_channels; ch++) { |
978 if (ctx->dba_mode[ch] == DBA_NEW) { | 978 if (ctx->dba_mode[ch] == DBA_NEW) { |
979 ctx->dba_nsegs[ch] = get_bits(gb, 3); | 979 ctx->dba_nsegs[ch] = get_bits(gbc, 3); |
980 for (seg = 0; seg <= ctx->dba_nsegs[ch]; seg++) { | 980 for (seg = 0; seg <= ctx->dba_nsegs[ch]; seg++) { |
981 ctx->dba_offsets[ch][seg] = get_bits(gb, 5); | 981 ctx->dba_offsets[ch][seg] = get_bits(gbc, 5); |
982 ctx->dba_lengths[ch][seg] = get_bits(gb, 4); | 982 ctx->dba_lengths[ch][seg] = get_bits(gbc, 4); |
983 ctx->dba_values[ch][seg] = get_bits(gb, 3); | 983 ctx->dba_values[ch][seg] = get_bits(gbc, 3); |
984 } | 984 } |
985 } | 985 } |
986 } | 986 } |
987 } else if(blk == 0) { | 987 } else if(blk == 0) { |
988 for(ch=0; ch<=ctx->channels; ch++) { | 988 for(ch=0; ch<=ctx->channels; ch++) { |
1017 ctx->bap[ch]); | 1017 ctx->bap[ch]); |
1018 } | 1018 } |
1019 } | 1019 } |
1020 | 1020 |
1021 /* unused dummy data */ | 1021 /* unused dummy data */ |
1022 if (get_bits1(gb)) { | 1022 if (get_bits1(gbc)) { |
1023 int skipl = get_bits(gb, 9); | 1023 int skipl = get_bits(gbc, 9); |
1024 while(skipl--) | 1024 while(skipl--) |
1025 skip_bits(gb, 8); | 1025 skip_bits(gbc, 8); |
1026 } | 1026 } |
1027 | 1027 |
1028 /* unpack the transform coefficients | 1028 /* unpack the transform coefficients |
1029 this also uncouples channels if coupling is in use. */ | 1029 this also uncouples channels if coupling is in use. */ |
1030 if (get_transform_coeffs(ctx)) { | 1030 if (get_transform_coeffs(ctx)) { |
1077 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data; | 1077 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data; |
1078 int16_t *out_samples = (int16_t *)data; | 1078 int16_t *out_samples = (int16_t *)data; |
1079 int i, blk, ch, err; | 1079 int i, blk, ch, err; |
1080 | 1080 |
1081 /* initialize the GetBitContext with the start of valid AC-3 Frame */ | 1081 /* initialize the GetBitContext with the start of valid AC-3 Frame */ |
1082 init_get_bits(&ctx->gb, buf, buf_size * 8); | 1082 init_get_bits(&ctx->gbc, buf, buf_size * 8); |
1083 | 1083 |
1084 /* parse the syncinfo */ | 1084 /* parse the syncinfo */ |
1085 err = ac3_parse_header(ctx); | 1085 err = ac3_parse_header(ctx); |
1086 if(err) { | 1086 if(err) { |
1087 switch(err) { | 1087 switch(err) { |