Original patch by Justin, updated and resubmitted by Christophe Gisquet, christophe D gisquet A gmail Originally committed as revision 22734 to svn://svn.ffmpeg.org/ffmpeg/trunk
Unified · Split
| @@ -68,6 +68,7 @@ version <next>: · 67 unmodified lines | |||
| 68 | - HTTP Digest authentication | 68 | - HTTP Digest authentication |
| 69 | - RTMP/RTMPT/RTMPS/RTMPE/RTMPTE protocol support via librtmp | 69 | - RTMP/RTMPT/RTMPS/RTMPE/RTMPTE protocol support via librtmp |
| 70 | - Psygnosis YOP demuxer and video decoder | 70 | - Psygnosis YOP demuxer and video decoder |
| 71 | - spectral extension support in the E-AC-3 decoder | ||
| 71 | 72 | ||
| 72 | 73 | ||
| 73 | 74 | ||
| @@ -815,14 +815,105 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) · 814 unmodified lines | |||
| 815 | 815 | ||
| 816 | /* spectral extension strategy */ | 816 | /* spectral extension strategy */ |
| 817 | if (s->eac3 && (!blk || get_bits1(gbc))) { | 817 | if (s->eac3 && (!blk || get_bits1(gbc))) { |
| 818 | if (get_bits1(gbc)) { | 818 | s->spx_in_use = get_bits1(gbc); |
| 819 | av_log_missing_feature(s->avctx, "Spectral extension", 1); | 819 | if (s->spx_in_use) { |
| 820 | return -1; | 820 | int dst_start_freq, dst_end_freq, src_start_freq, |
| 821 | start_subband, end_subband; | ||
| 822 | |||
| 823 | /* determine which channels use spx */ | ||
| 824 | if (s->channel_mode == AC3_CHMODE_MONO) { | ||
| 825 | s->channel_uses_spx[1] = 1; | ||
| 826 | } else { | ||
| 827 | for (ch = 1; ch <= fbw_channels; ch++) | ||
| 828 | s->channel_uses_spx[ch] = get_bits1(gbc); | ||
| 829 | } | ||
| 830 | |||
| 831 | /* get the frequency bins of the spx copy region and the spx start | ||
| 832 | and end subbands */ | ||
| 833 | dst_start_freq = get_bits(gbc, 2); | ||
| 834 | start_subband = get_bits(gbc, 3) + 2; | ||
| 835 | if (start_subband > 7) | ||
| 836 | start_subband += start_subband - 7; | ||
| 837 | end_subband = get_bits(gbc, 3) + 5; | ||
| 838 | if (end_subband > 7) | ||
| 839 | end_subband += end_subband - 7; | ||
| 840 | dst_start_freq = dst_start_freq * 12 + 25; | ||
| 841 | src_start_freq = start_subband * 12 + 25; | ||
| 842 | dst_end_freq = end_subband * 12 + 25; | ||
| 843 | |||
| 844 | /* check validity of spx ranges */ | ||
| 845 | if (start_subband >= end_subband) { | ||
| 846 | av_log(s->avctx, AV_LOG_ERROR, "invalid spectral extension " | ||
| 847 | "range (%d >= %d)\n", start_subband, end_subband); | ||
| 848 | return -1; | ||
| 849 | } | ||
| 850 | if (dst_start_freq >= src_start_freq) { | ||
| 851 | av_log(s->avctx, AV_LOG_ERROR, "invalid spectral extension " | ||
| 852 | "copy start bin (%d >= %d)\n", dst_start_freq, src_start_freq); | ||
| 853 | return -1; | ||
| 854 | } | ||
| 855 | |||
| 856 | s->spx_dst_start_freq = dst_start_freq; | ||
| 857 | s->spx_src_start_freq = src_start_freq; | ||
| 858 | s->spx_dst_end_freq = dst_end_freq; | ||
| 859 | |||
| 860 | decode_band_structure(gbc, blk, s->eac3, 0, | ||
| 861 | start_subband, end_subband, | ||
| 862 | ff_eac3_default_spx_band_struct, | ||
| 863 | &s->num_spx_bands, | ||
| 864 | s->spx_band_sizes); | ||
| 865 | } else { | ||
| 866 | for (ch = 1; ch <= fbw_channels; ch++) { | ||
| 867 | s->channel_uses_spx[ch] = 0; | ||
| 868 | s->first_spx_coords[ch] = 1; | ||
| 869 | } | ||
| 821 | } | 870 | } |
| 822 | /* TODO: parse spectral extension strategy info */ | ||
| 823 | } | 871 | } |
| 824 | 872 | ||
| 825 | /* TODO: spectral extension coordinates */ | 873 | /* spectral extension coordinates */ |
| 874 | if (s->spx_in_use) { | ||
| 875 | for (ch = 1; ch <= fbw_channels; ch++) { | ||
| 876 | if (s->channel_uses_spx[ch]) { | ||
| 877 | if (s->first_spx_coords[ch] || get_bits1(gbc)) { | ||
| 878 | float spx_blend; | ||
| 879 | int bin, master_spx_coord; | ||
| 880 | |||
| 881 | s->first_spx_coords[ch] = 0; | ||
| 882 | spx_blend = get_bits(gbc, 5) * (1.0f/32); | ||
| 883 | master_spx_coord = get_bits(gbc, 2) * 3; | ||
| 884 | |||
| 885 | bin = s->spx_src_start_freq; | ||
| 886 | for (bnd = 0; bnd < s->num_spx_bands; bnd++) { | ||
| 887 | int bandsize; | ||
| 888 | int spx_coord_exp, spx_coord_mant; | ||
| 889 | float nratio, sblend, nblend, spx_coord; | ||
| 890 | |||
| 891 | /* calculate blending factors */ | ||
| 892 | bandsize = s->spx_band_sizes[bnd]; | ||
| 893 | nratio = ((float)((bin + (bandsize >> 1))) / s->spx_dst_end_freq) - spx_blend; | ||
| 894 | nratio = av_clipf(nratio, 0.0f, 1.0f); | ||
| 895 | nblend = sqrtf(3.0f * nratio); // noise is scaled by sqrt(3) to give unity variance | ||
| 896 | sblend = sqrtf(1.0f - nratio); | ||
| 897 | bin += bandsize; | ||
| 898 | |||
| 899 | /* decode spx coordinates */ | ||
| 900 | spx_coord_exp = get_bits(gbc, 4); | ||
| 901 | spx_coord_mant = get_bits(gbc, 2); | ||
| 902 | if (spx_coord_exp == 15) spx_coord_mant <<= 1; | ||
| 903 | else spx_coord_mant += 4; | ||
| 904 | spx_coord_mant <<= (25 - spx_coord_exp - master_spx_coord); | ||
| 905 | spx_coord = spx_coord_mant * (1.0f/(1<<23)); | ||
| 906 | |||
| 907 | /* multiply noise and signal blending factors by spx coordinate */ | ||
| 908 | s->spx_noise_blend [ch][bnd] = nblend * spx_coord; | ||
| 909 | s->spx_signal_blend[ch][bnd] = sblend * spx_coord; | ||
| 910 | } | ||
| 911 | } | ||
| 912 | } else { | ||
| 913 | s->first_spx_coords[ch] = 1; | ||
| 914 | } | ||
| 915 | } | ||
| 916 | } | ||
| 826 | 917 | ||
| 827 | /* coupling strategy */ | 918 | /* coupling strategy */ |
| 828 | if (s->eac3 ? s->cpl_strategy_exists[blk] : get_bits1(gbc)) { | 919 | if (s->eac3 ? s->cpl_strategy_exists[blk] : get_bits1(gbc)) { |
| @@ -859,9 +950,9 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) · 30 unmodified lines | |||
| 859 | s->phase_flags_in_use = get_bits1(gbc); | 950 | s->phase_flags_in_use = get_bits1(gbc); |
| 860 | 951 | ||
| 861 | /* coupling frequency range */ | 952 | /* coupling frequency range */ |
| 862 | /* TODO: modify coupling end freq if spectral extension is used */ | ||
| 863 | cpl_start_subband = get_bits(gbc, 4); | 953 | cpl_start_subband = get_bits(gbc, 4); |
| 864 | cpl_end_subband = get_bits(gbc, 4) + 3; | 954 | cpl_end_subband = s->spx_in_use ? (s->spx_src_start_freq - 37) / 12 : |
| 955 | get_bits(gbc, 4) + 3; | ||
| 865 | if (cpl_start_subband >= cpl_end_subband) { | 956 | if (cpl_start_subband >= cpl_end_subband) { |
| 866 | av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n", | 957 | av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n", |
| 867 | cpl_start_subband, cpl_end_subband); | 958 | cpl_start_subband, cpl_end_subband); |
| @@ -934,8 +1025,11 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) · 66 unmodified lines | |||
| 934 | if (channel_mode == AC3_CHMODE_STEREO) { | 1025 | if (channel_mode == AC3_CHMODE_STEREO) { |
| 935 | if ((s->eac3 && !blk) || get_bits1(gbc)) { | 1026 | if ((s->eac3 && !blk) || get_bits1(gbc)) { |
| 936 | s->num_rematrixing_bands = 4; | 1027 | s->num_rematrixing_bands = 4; |
| 937 | if(cpl_in_use && s->start_freq[CPL_CH] <= 61) | 1028 | if (cpl_in_use && s->start_freq[CPL_CH] <= 61) { |
| 938 | s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37); | 1029 | s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37); |
| 1030 | } else if (s->spx_in_use && s->spx_src_start_freq <= 61) { | ||
| 1031 | s->num_rematrixing_bands--; | ||
| 1032 | } | ||
| 939 | for(bnd=0; bnd<s->num_rematrixing_bands; bnd++) | 1033 | for(bnd=0; bnd<s->num_rematrixing_bands; bnd++) |
| 940 | s->rematrixing_flags[bnd] = get_bits1(gbc); | 1034 | s->rematrixing_flags[bnd] = get_bits1(gbc); |
| 941 | } else if (!blk) { | 1035 | } else if (!blk) { |
| @@ -960,6 +1054,8 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) · 18 unmodified lines | |||
| 960 | int prev = s->end_freq[ch]; | 1054 | int prev = s->end_freq[ch]; |
| 961 | if (s->channel_in_cpl[ch]) | 1055 | if (s->channel_in_cpl[ch]) |
| 962 | s->end_freq[ch] = s->start_freq[CPL_CH]; | 1056 | s->end_freq[ch] = s->start_freq[CPL_CH]; |
| 1057 | else if (s->channel_uses_spx[ch]) | ||
| 1058 | s->end_freq[ch] = s->spx_src_start_freq; | ||
| 963 | else { | 1059 | else { |
| 964 | int bandwidth_code = get_bits(gbc, 6); | 1060 | int bandwidth_code = get_bits(gbc, 6); |
| 965 | if (bandwidth_code > 60) { | 1061 | if (bandwidth_code > 60) { |
| @@ -1156,8 +1252,6 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) · 190 unmodified lines | |||
| 1156 | 1252 | ||
| 1157 | /* TODO: generate enhanced coupling coordinates and uncouple */ | 1253 | /* TODO: generate enhanced coupling coordinates and uncouple */ |
| 1158 | 1254 | ||
| 1159 | /* TODO: apply spectral extension */ | ||
| 1160 | |||
| 1161 | /* recover coefficients if rematrixing is in use */ | 1255 | /* recover coefficients if rematrixing is in use */ |
| 1162 | if(s->channel_mode == AC3_CHMODE_STEREO) | 1256 | if(s->channel_mode == AC3_CHMODE_STEREO) |
| 1163 | do_rematrixing(s); | 1257 | do_rematrixing(s); |
| @@ -1173,6 +1267,11 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) · 9 unmodified lines | |||
| 1173 | s->dsp.int32_to_float_fmul_scalar(s->transform_coeffs[ch], s->fixed_coeffs[ch], gain, 256); | 1267 | s->dsp.int32_to_float_fmul_scalar(s->transform_coeffs[ch], s->fixed_coeffs[ch], gain, 256); |
| 1174 | } | 1268 | } |
| 1175 | 1269 | ||
| 1270 | /* apply spectral extension to high frequency bins */ | ||
| 1271 | if (s->spx_in_use) { | ||
| 1272 | ff_eac3_apply_spectral_extension(s); | ||
| 1273 | } | ||
| 1274 | |||
| 1176 | /* downmix and MDCT. order depends on whether block switching is used for | 1275 | /* downmix and MDCT. order depends on whether block switching is used for |
| 1177 | any channel in this block. this is because coefficients for the long | 1276 | any channel in this block. this is because coefficients for the long |
| 1178 | and short transforms cannot be mixed. */ | 1277 | and short transforms cannot be mixed. */ |
| @@ -22,6 +22,29 @@ · 21 unmodified lines | |||
| 22 | /** | 22 | /** |
| 23 | * @file libavcodec/ac3.h | 23 | * @file libavcodec/ac3.h |
| 24 | * Common code between the AC-3 and E-AC-3 decoders. | 24 | * Common code between the AC-3 and E-AC-3 decoders. |
| 25 | * | ||
| 26 | * Summary of MDCT Coefficient Grouping: | ||
| 27 | * The individual MDCT coefficient indices are often referred to in the | ||
| 28 | * (E-)AC-3 specification as frequency bins. These bins are grouped together | ||
| 29 | * into subbands of 12 coefficients each. The subbands are grouped together | ||
| 30 | * into bands as defined in the bitstream by the band structures, which | ||
| 31 | * determine the number of bands and the size of each band. The full spectrum | ||
| 32 | * of 256 frequency bins is divided into 1 DC bin + 21 subbands = 253 bins. | ||
| 33 | * This system of grouping coefficients is used for channel bandwidth, stereo | ||
| 34 | * rematrixing, channel coupling, enhanced coupling, and spectral extension. | ||
| 35 | * | ||
| 36 | * +-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-+ | ||
| 37 | * |1| |12| | [12|12|12|12] | | | | | | | | | | | | |3| | ||
| 38 | * +-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-+ | ||
| 39 | * ~~~ ~~~~ ~~~~~~~~~~~~~ ~~~ | ||
| 40 | * | | | | | ||
| 41 | * | | | 3 unused frequency bins--+ | ||
| 42 | * | | | | ||
| 43 | * | | +--1 band containing 4 subbands | ||
| 44 | * | | | ||
| 45 | * | +--1 subband of 12 frequency bins | ||
| 46 | * | | ||
| 47 | * +--DC frequency bin | ||
| 25 | */ | 48 | */ |
| 26 | 49 | ||
| 27 | #ifndef AVCODEC_AC3DEC_H | 50 | #ifndef AVCODEC_AC3DEC_H |
| @@ -43,6 +66,7 @@ · 15 unmodified lines | |||
| 43 | #define AC3_MAX_COEFS 256 | 66 | #define AC3_MAX_COEFS 256 |
| 44 | #define AC3_BLOCK_SIZE 256 | 67 | #define AC3_BLOCK_SIZE 256 |
| 45 | #define MAX_BLOCKS 6 | 68 | #define MAX_BLOCKS 6 |
| 69 | #define SPX_MAX_BANDS 17 | ||
| 46 | 70 | ||
| 47 | typedef struct { | 71 | typedef struct { |
| 48 | AVCodecContext *avctx; ///< parent context | 72 | AVCodecContext *avctx; ///< parent context |
| @@ -89,6 +113,22 @@ typedef struct { · 40 unmodified lines | |||
| 89 | int cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates (cplco) | 113 | int cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates (cplco) |
| 90 | ///@} | 114 | ///@} |
| 91 | 115 | ||
| 116 | ///@defgroup spx spectral extension | ||
| 117 | ///@{ | ||
| 118 | int spx_in_use; ///< spectral extension in use (spxinu) | ||
| 119 | uint8_t channel_uses_spx[AC3_MAX_CHANNELS]; ///< channel uses spectral extension (chinspx) | ||
| 120 | int8_t spx_atten_code[AC3_MAX_CHANNELS]; ///< spx attenuation code (spxattencod) | ||
| 121 | int spx_src_start_freq; ///< spx start frequency bin | ||
| 122 | int spx_dst_end_freq; ///< spx end frequency bin | ||
| 123 | int spx_dst_start_freq; ///< spx starting frequency bin for copying (copystartmant) | ||
| 124 | ///< the copy region ends at the start of the spx region. | ||
| 125 | int num_spx_bands; ///< number of spx bands (nspxbnds) | ||
| 126 | uint8_t spx_band_sizes[SPX_MAX_BANDS]; ///< number of bins in each spx band | ||
| 127 | uint8_t first_spx_coords[AC3_MAX_CHANNELS]; ///< first spx coordinates states (firstspxcos) | ||
| 128 | float spx_noise_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]; ///< spx noise blending factor (nblendfact) | ||
| 129 | float spx_signal_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS];///< spx signal blending factor (sblendfact) | ||
| 130 | ///@} | ||
| 131 | |||
| 92 | ///@defgroup aht adaptive hybrid transform | 132 | ///@defgroup aht adaptive hybrid transform |
| 93 | int channel_uses_aht[AC3_MAX_CHANNELS]; ///< channel AHT in use (chahtinu) | 133 | int channel_uses_aht[AC3_MAX_CHANNELS]; ///< channel AHT in use (chahtinu) |
| 94 | int pre_mantissa[AC3_MAX_CHANNELS][AC3_MAX_COEFS][MAX_BLOCKS]; ///< pre-IDCT mantissas | 134 | int pre_mantissa[AC3_MAX_CHANNELS][AC3_MAX_COEFS][MAX_BLOCKS]; ///< pre-IDCT mantissas |
| @@ -182,4 +222,11 @@ void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch); · 87 unmodified lines | |||
| 182 | void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], | 222 | void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], |
| 183 | int out_ch, int in_ch, int len); | 223 | int out_ch, int in_ch, int len); |
| 184 | 224 | ||
| 225 | /** | ||
| 226 | * Apply spectral extension to each channel by copying lower frequency | ||
| 227 | * coefficients to higher frequency bins and applying side information to | ||
| 228 | * approximate the original high frequency signal. | ||
| 229 | */ | ||
| 230 | void ff_eac3_apply_spectral_extension(AC3DecodeContext *s); | ||
| 231 | |||
| 185 | #endif /* AVCODEC_AC3DEC_H */ | 232 | #endif /* AVCODEC_AC3DEC_H */ |
| @@ -64,3 +64,9 @@ const uint8_t ff_eac3_hebap_tab[64] = { · 63 unmodified lines | |||
| 64 | */ | 64 | */ |
| 65 | const uint8_t ff_eac3_default_cpl_band_struct[18] = | 65 | const uint8_t ff_eac3_default_cpl_band_struct[18] = |
| 66 | { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1 }; | 66 | { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1 }; |
| 67 | |||
| 68 | /** | ||
| 69 | * Table E2.15 Default Spectral Extension Banding Structure | ||
| 70 | */ | ||
| 71 | const uint8_t ff_eac3_default_spx_band_struct[17] = | ||
| 72 | { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }; | ||
| @@ -29,5 +29,6 @@ extern const uint8_t ff_ac3_rematrix_band_tab[5]; · 28 unmodified lines | |||
| 29 | 29 | ||
| 30 | extern const uint8_t ff_eac3_hebap_tab[64]; | 30 | extern const uint8_t ff_eac3_hebap_tab[64]; |
| 31 | extern const uint8_t ff_eac3_default_cpl_band_struct[18]; | 31 | extern const uint8_t ff_eac3_default_cpl_band_struct[18]; |
| 32 | extern const uint8_t ff_eac3_default_spx_band_struct[17]; | ||
| 32 | 33 | ||
| 33 | #endif /* AVCODEC_AC3DEC_DATA_H */ | 34 | #endif /* AVCODEC_AC3DEC_DATA_H */ |
| @@ -30,7 +30,7 @@ · 29 unmodified lines | |||
| 30 | #include "libavutil/avutil.h" | 30 | #include "libavutil/avutil.h" |
| 31 | 31 | ||
| 32 | #define LIBAVCODEC_VERSION_MAJOR 52 | 32 | #define LIBAVCODEC_VERSION_MAJOR 52 |
| 33 | #define LIBAVCODEC_VERSION_MINOR 62 | 33 | #define LIBAVCODEC_VERSION_MINOR 63 |
| 34 | #define LIBAVCODEC_VERSION_MICRO 0 | 34 | #define LIBAVCODEC_VERSION_MICRO 0 |
| 35 | 35 | ||
| 36 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ | 36 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| @@ -23,10 +23,6 @@ · 22 unmodified lines | |||
| 23 | /* | 23 | /* |
| 24 | * There are several features of E-AC-3 that this decoder does not yet support. | 24 | * There are several features of E-AC-3 that this decoder does not yet support. |
| 25 | * | 25 | * |
| 26 | * Spectral Extension | ||
| 27 | * There is a patch to get this working for the two samples we have that | ||
| 28 | * use it, but it needs some minor changes in order to be accepted. | ||
| 29 | * | ||
| 30 | * Enhanced Coupling | 26 | * Enhanced Coupling |
| 31 | * No known samples exist. If any ever surface, this feature should not be | 27 | * No known samples exist. If any ever surface, this feature should not be |
| 32 | * too difficult to implement. | 28 | * too difficult to implement. |
| @@ -67,6 +63,95 @@ typedef enum { · 34 unmodified lines | |||
| 67 | 63 | ||
| 68 | #define EAC3_SR_CODE_REDUCED 3 | 64 | #define EAC3_SR_CODE_REDUCED 3 |
| 69 | 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/(1<<31)); | ||
| 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 | |||
| 70 | /** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */ | 155 | /** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */ |
| 71 | #define COEFF_0 10273905LL | 156 | #define COEFF_0 10273905LL |
| 72 | 157 | ||
| @@ -492,12 +577,11 @@ int ff_eac3_parse_header(AC3DecodeContext *s) · 419 unmodified lines | |||
| 492 | } | 577 | } |
| 493 | 578 | ||
| 494 | /* spectral extension attenuation data */ | 579 | /* spectral extension attenuation data */ |
| 495 | if (parse_spx_atten_data) { | 580 | for (ch = 1; ch <= s->fbw_channels; ch++) { |
| 496 | av_log_missing_feature(s->avctx, "Spectral extension attenuation", 1); | 581 | if (parse_spx_atten_data && get_bits1(gbc)) { |
| 497 | for (ch = 1; ch <= s->fbw_channels; ch++) { | 582 | s->spx_atten_code[ch] = get_bits(gbc, 5); |
| 498 | if (get_bits1(gbc)) { // channel has spx attenuation | 583 | } else { |
| 499 | skip_bits(gbc, 5); // skip spx attenuation code | 584 | s->spx_atten_code[ch] = -1; |
| 500 | } | ||
| 501 | } | 585 | } |
| 502 | } | 586 | } |
| 503 | 587 | ||
| @@ -514,6 +598,7 @@ int ff_eac3_parse_header(AC3DecodeContext *s) · 10 unmodified lines | |||
| 514 | 598 | ||
| 515 | /* syntax state initialization */ | 599 | /* syntax state initialization */ |
| 516 | for (ch = 1; ch <= s->fbw_channels; ch++) { | 600 | for (ch = 1; ch <= s->fbw_channels; ch++) { |
| 601 | s->first_spx_coords[ch] = 1; | ||
| 517 | s->first_cpl_coords[ch] = 1; | 602 | s->first_cpl_coords[ch] = 1; |
| 518 | } | 603 | } |
| 519 | s->first_cpl_leak = 1; | 604 | s->first_cpl_leak = 1; |
| @@ -1093,3 +1093,42 @@ const uint8_t ff_eac3_frm_expstr[32][6] = { · 1092 unmodified lines | |||
| 1093 | { EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE}, | 1093 | { EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE}, |
| 1094 | { EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D45}, | 1094 | { EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D45}, |
| 1095 | }; | 1095 | }; |
| 1096 | |||
| 1097 | /** | ||
| 1098 | * Table E.25: Spectral Extension Attenuation Table | ||
| 1099 | * ff_eac3_spx_atten_tab[code][bin]=pow(2.0,(bin+1)*(code+1)/-15.0); | ||
| 1100 | */ | ||
| 1101 | const float ff_eac3_spx_atten_tab[32][3] = { | ||
| 1102 | { 0.954841603910416503f, 0.911722488558216804f, 0.870550563296124125f }, | ||
| 1103 | { 0.911722488558216804f, 0.831237896142787758f, 0.757858283255198995f }, | ||
| 1104 | { 0.870550563296124125f, 0.757858283255198995f, 0.659753955386447100f }, | ||
| 1105 | { 0.831237896142787758f, 0.690956439983888004f, 0.574349177498517438f }, | ||
| 1106 | { 0.793700525984099792f, 0.629960524947436595f, 0.500000000000000000f }, | ||
| 1107 | { 0.757858283255198995f, 0.574349177498517438f, 0.435275281648062062f }, | ||
| 1108 | { 0.723634618720189082f, 0.523647061410313364f, 0.378929141627599553f }, | ||
| 1109 | { 0.690956439983888004f, 0.477420801955208307f, 0.329876977693223550f }, | ||
| 1110 | { 0.659753955386447100f, 0.435275281648062062f, 0.287174588749258719f }, | ||
| 1111 | { 0.629960524947436595f, 0.396850262992049896f, 0.250000000000000000f }, | ||
| 1112 | { 0.601512518041058319f, 0.361817309360094541f, 0.217637640824031003f }, | ||
| 1113 | { 0.574349177498517438f, 0.329876977693223550f, 0.189464570813799776f }, | ||
| 1114 | { 0.548412489847312945f, 0.300756259020529160f, 0.164938488846611775f }, | ||
| 1115 | { 0.523647061410313364f, 0.274206244923656473f, 0.143587294374629387f }, | ||
| 1116 | { 0.500000000000000000f, 0.250000000000000000f, 0.125000000000000000f }, | ||
| 1117 | { 0.477420801955208307f, 0.227930622139554201f, 0.108818820412015502f }, | ||
| 1118 | { 0.455861244279108402f, 0.207809474035696939f, 0.094732285406899888f }, | ||
| 1119 | { 0.435275281648062062f, 0.189464570813799776f, 0.082469244423305887f }, | ||
| 1120 | { 0.415618948071393879f, 0.172739109995972029f, 0.071793647187314694f }, | ||
| 1121 | { 0.396850262992049896f, 0.157490131236859149f, 0.062500000000000000f }, | ||
| 1122 | { 0.378929141627599553f, 0.143587294374629387f, 0.054409410206007751f }, | ||
| 1123 | { 0.361817309360094541f, 0.130911765352578369f, 0.047366142703449930f }, | ||
| 1124 | { 0.345478219991944002f, 0.119355200488802049f, 0.041234622211652958f }, | ||
| 1125 | { 0.329876977693223550f, 0.108818820412015502f, 0.035896823593657347f }, | ||
| 1126 | { 0.314980262473718298f, 0.099212565748012460f, 0.031250000000000000f }, | ||
| 1127 | { 0.300756259020529160f, 0.090454327340023621f, 0.027204705103003875f }, | ||
| 1128 | { 0.287174588749258719f, 0.082469244423305887f, 0.023683071351724965f }, | ||
| 1129 | { 0.274206244923656473f, 0.075189064755132290f, 0.020617311105826479f }, | ||
| 1130 | { 0.261823530705156682f, 0.068551561230914118f, 0.017948411796828673f }, | ||
| 1131 | { 0.250000000000000000f, 0.062500000000000000f, 0.015625000000000000f }, | ||
| 1132 | { 0.238710400977604098f, 0.056982655534888536f, 0.013602352551501938f }, | ||
| 1133 | { 0.227930622139554201f, 0.051952368508924235f, 0.011841535675862483f } | ||
| 1134 | }; | ||
| @@ -31,5 +31,6 @@ extern const int16_t ff_eac3_gaq_remap_2_4_b[9][2]; · 30 unmodified lines | |||
| 31 | 31 | ||
| 32 | extern const int16_t (* const ff_eac3_mantissa_vq[8])[6]; | 32 | extern const int16_t (* const ff_eac3_mantissa_vq[8])[6]; |
| 33 | extern const uint8_t ff_eac3_frm_expstr[32][6]; | 33 | extern const uint8_t ff_eac3_frm_expstr[32][6]; |
| 34 | extern const float ff_eac3_spx_atten_tab[32][3]; | ||
| 34 | 35 | ||
| 35 | #endif /* AVCODEC_EAC3DEC_DATA_H */ | 36 | #endif /* AVCODEC_EAC3DEC_DATA_H */ |