Mercurial > libavcodec.hg
comparison ac3dec.c @ 7626:8618fb5d9bce libavcodec
commit the OKed parts of the E-AC-3 decoder
author | jbr |
---|---|
date | Wed, 20 Aug 2008 00:32:17 +0000 |
parents | da9353cd6d71 |
children | 93c5703328d6 |
comparison
equal
deleted
inserted
replaced
7625:da9353cd6d71 | 7626:8618fb5d9bce |
---|---|
1 /* | 1 /* |
2 * AC-3 Audio Decoder | 2 * AC-3 Audio Decoder |
3 * This code is developed as part of Google Summer of Code 2006 Program. | 3 * This code was developed as part of Google Summer of Code 2006. |
4 * E-AC-3 support was added as part of Google Summer of Code 2007. | |
4 * | 5 * |
5 * Copyright (c) 2006 Kartikey Mahendra BHATT (bhattkm at gmail dot com). | 6 * Copyright (c) 2006 Kartikey Mahendra BHATT (bhattkm at gmail dot com). |
7 * Copyright (c) 2007-2008 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com> | |
6 * Copyright (c) 2007 Justin Ruggles <justin.ruggles@gmail.com> | 8 * Copyright (c) 2007 Justin Ruggles <justin.ruggles@gmail.com> |
7 * | 9 * |
8 * Portions of this code are derived from liba52 | 10 * Portions of this code are derived from liba52 |
9 * http://liba52.sourceforge.net | 11 * http://liba52.sourceforge.net |
10 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> | 12 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> |
300 s->end_freq[s->lfe_ch] = 7; | 302 s->end_freq[s->lfe_ch] = 7; |
301 s->num_exp_groups[s->lfe_ch] = 2; | 303 s->num_exp_groups[s->lfe_ch] = 2; |
302 s->channel_in_cpl[s->lfe_ch] = 0; | 304 s->channel_in_cpl[s->lfe_ch] = 0; |
303 } | 305 } |
304 | 306 |
305 if(hdr.bitstream_id > 10) | 307 if (hdr.bitstream_id <= 10) { |
308 s->eac3 = 0; | |
309 s->snr_offset_strategy = 2; | |
310 s->block_switch_syntax = 1; | |
311 s->dither_flag_syntax = 1; | |
312 s->bit_allocation_syntax = 1; | |
313 s->fast_gain_syntax = 0; | |
314 s->first_cpl_leak = 0; | |
315 s->dba_syntax = 1; | |
316 s->skip_syntax = 1; | |
317 memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht)); | |
318 return ac3_parse_header(s); | |
319 } else { | |
320 /*s->eac3 = 1; | |
321 return ff_eac3_parse_header(s);*/ | |
306 return AC3_PARSE_ERROR_BSID; | 322 return AC3_PARSE_ERROR_BSID; |
307 | 323 } |
308 return ac3_parse_header(s); | |
309 } | 324 } |
310 | 325 |
311 /** | 326 /** |
312 * Set stereo downmixing coefficients based on frame header info. | 327 * Set stereo downmixing coefficients based on frame header info. |
313 * reference: Section 7.8.2 Downmixing Into Two Channels | 328 * reference: Section 7.8.2 Downmixing Into Two Channels |
530 } | 545 } |
531 } | 546 } |
532 } | 547 } |
533 } | 548 } |
534 } | 549 } |
550 | |
551 #if 0 | |
552 static void get_transform_coeffs_ch(AC3DecodeContext *s, int blk, int ch, | |
553 mant_groups *m) | |
554 { | |
555 if (!s->channel_uses_aht[ch]) { | |
556 ac3_get_transform_coeffs_ch(s, ch, m); | |
557 } else { | |
558 /* if AHT is used, mantissas for all blocks are encoded in the first | |
559 block of the frame. */ | |
560 int bin; | |
561 if (!blk) | |
562 ff_eac3_get_transform_coeffs_aht_ch(s, ch); | |
563 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { | |
564 s->fixed_coeffs[ch][bin] = s->pre_mantissa[ch][bin][blk] >> s->dexps[ch][bin]; | |
565 } | |
566 } | |
567 } | |
568 #endif | |
535 | 569 |
536 /** | 570 /** |
537 * Get the transform coefficients. | 571 * Get the transform coefficients. |
538 */ | 572 */ |
539 static void get_transform_coeffs(AC3DecodeContext *s) | 573 static void get_transform_coeffs(AC3DecodeContext *s) |
696 | 730 |
697 memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS); | 731 memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS); |
698 | 732 |
699 /* block switch flags */ | 733 /* block switch flags */ |
700 different_transforms = 0; | 734 different_transforms = 0; |
735 if (s->block_switch_syntax) { | |
701 for (ch = 1; ch <= fbw_channels; ch++) { | 736 for (ch = 1; ch <= fbw_channels; ch++) { |
702 s->block_switch[ch] = get_bits1(gbc); | 737 s->block_switch[ch] = get_bits1(gbc); |
703 if(ch > 1 && s->block_switch[ch] != s->block_switch[1]) | 738 if(ch > 1 && s->block_switch[ch] != s->block_switch[1]) |
704 different_transforms = 1; | 739 different_transforms = 1; |
705 } | 740 } |
741 } | |
706 | 742 |
707 /* dithering flags */ | 743 /* dithering flags */ |
744 if (s->dither_flag_syntax) { | |
708 s->dither_all = 1; | 745 s->dither_all = 1; |
709 for (ch = 1; ch <= fbw_channels; ch++) { | 746 for (ch = 1; ch <= fbw_channels; ch++) { |
710 s->dither_flag[ch] = get_bits1(gbc); | 747 s->dither_flag[ch] = get_bits1(gbc); |
711 if(!s->dither_flag[ch]) | 748 if(!s->dither_flag[ch]) |
712 s->dither_all = 0; | 749 s->dither_all = 0; |
750 } | |
713 } | 751 } |
714 | 752 |
715 /* dynamic range */ | 753 /* dynamic range */ |
716 i = !(s->channel_mode); | 754 i = !(s->channel_mode); |
717 do { | 755 do { |
868 skip_bits(gbc, 2); /* skip gainrng */ | 906 skip_bits(gbc, 2); /* skip gainrng */ |
869 } | 907 } |
870 } | 908 } |
871 | 909 |
872 /* bit allocation information */ | 910 /* bit allocation information */ |
911 if (s->bit_allocation_syntax) { | |
873 if (get_bits1(gbc)) { | 912 if (get_bits1(gbc)) { |
874 s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; | 913 s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; |
875 s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; | 914 s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; |
876 s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gbc, 2)]; | 915 s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gbc, 2)]; |
877 s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)]; | 916 s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)]; |
880 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); | 919 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
881 } else if (!blk) { | 920 } else if (!blk) { |
882 av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must be present in block 0\n"); | 921 av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must be present in block 0\n"); |
883 return -1; | 922 return -1; |
884 } | 923 } |
924 } | |
885 | 925 |
886 /* signal-to-noise ratio offsets and fast gains (signal-to-mask ratios) */ | 926 /* signal-to-noise ratio offsets and fast gains (signal-to-mask ratios) */ |
887 if (get_bits1(gbc)) { | 927 if (get_bits1(gbc)) { |
888 int csnr; | 928 int csnr; |
889 csnr = (get_bits(gbc, 6) - 15) << 4; | 929 csnr = (get_bits(gbc, 6) - 15) << 4; |
908 return -1; | 948 return -1; |
909 } | 949 } |
910 } | 950 } |
911 | 951 |
912 /* delta bit allocation information */ | 952 /* delta bit allocation information */ |
913 if (get_bits1(gbc)) { | 953 if (s->dba_syntax && get_bits1(gbc)) { |
914 /* delta bit allocation exists (strategy) */ | 954 /* delta bit allocation exists (strategy) */ |
915 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) { | 955 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) { |
916 s->dba_mode[ch] = get_bits(gbc, 2); | 956 s->dba_mode[ch] = get_bits(gbc, 2); |
917 if (s->dba_mode[ch] == DBA_RESERVED) { | 957 if (s->dba_mode[ch] == DBA_RESERVED) { |
918 av_log(s->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); | 958 av_log(s->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); |
957 s->dba_offsets[ch], s->dba_lengths[ch], | 997 s->dba_offsets[ch], s->dba_lengths[ch], |
958 s->dba_values[ch], s->mask[ch]); | 998 s->dba_values[ch], s->mask[ch]); |
959 } | 999 } |
960 if(bit_alloc_stages[ch] > 0) { | 1000 if(bit_alloc_stages[ch] > 0) { |
961 /* Compute bit allocation */ | 1001 /* Compute bit allocation */ |
1002 const uint8_t *bap_tab = s->channel_uses_aht[ch] ? | |
1003 ff_eac3_hebap_tab : ff_ac3_bap_tab; | |
962 ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch], | 1004 ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch], |
963 s->start_freq[ch], s->end_freq[ch], | 1005 s->start_freq[ch], s->end_freq[ch], |
964 s->snr_offset[ch], | 1006 s->snr_offset[ch], |
965 s->bit_alloc_params.floor, | 1007 s->bit_alloc_params.floor, |
966 ff_ac3_bap_tab, s->bap[ch]); | 1008 bap_tab, s->bap[ch]); |
967 } | 1009 } |
968 } | 1010 } |
969 | 1011 |
970 /* unused dummy data */ | 1012 /* unused dummy data */ |
971 if (get_bits1(gbc)) { | 1013 if (s->skip_syntax && get_bits1(gbc)) { |
972 int skipl = get_bits(gbc, 9); | 1014 int skipl = get_bits(gbc, 9); |
973 while(skipl--) | 1015 while(skipl--) |
974 skip_bits(gbc, 8); | 1016 skip_bits(gbc, 8); |
975 } | 1017 } |
976 | 1018 |
977 /* unpack the transform coefficients | 1019 /* unpack the transform coefficients |
978 this also uncouples channels if coupling is in use. */ | 1020 this also uncouples channels if coupling is in use. */ |
979 get_transform_coeffs(s); | 1021 get_transform_coeffs(s); |
1022 | |
1023 /* TODO: generate enhanced coupling coordinates and uncouple */ | |
1024 | |
1025 /* TODO: apply spectral extension */ | |
980 | 1026 |
981 /* recover coefficients if rematrixing is in use */ | 1027 /* recover coefficients if rematrixing is in use */ |
982 if(s->channel_mode == AC3_CHMODE_STEREO) | 1028 if(s->channel_mode == AC3_CHMODE_STEREO) |
983 do_rematrixing(s); | 1029 do_rematrixing(s); |
984 | 1030 |
1159 .id = CODEC_ID_AC3, | 1205 .id = CODEC_ID_AC3, |
1160 .priv_data_size = sizeof (AC3DecodeContext), | 1206 .priv_data_size = sizeof (AC3DecodeContext), |
1161 .init = ac3_decode_init, | 1207 .init = ac3_decode_init, |
1162 .close = ac3_decode_end, | 1208 .close = ac3_decode_end, |
1163 .decode = ac3_decode_frame, | 1209 .decode = ac3_decode_frame, |
1164 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52 / AC-3"), | 1210 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52 (AC-3, E-AC-3)"), |
1165 }; | 1211 }; |