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
... | ... |
@@ -815,14 +815,105 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
815 | 815 |
|
816 | 816 |
/* spectral extension strategy */ |
817 | 817 |
if (s->eac3 && (!blk || get_bits1(gbc))) { |
818 |
- if (get_bits1(gbc)) { |
|
819 |
- av_log_missing_feature(s->avctx, "Spectral extension", 1); |
|
820 |
- return -1; |
|
818 |
+ s->spx_in_use = get_bits1(gbc); |
|
819 |
+ if (s->spx_in_use) { |
|
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 | 918 |
/* coupling strategy */ |
828 | 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) |
859 | 859 |
s->phase_flags_in_use = get_bits1(gbc); |
860 | 860 |
|
861 | 861 |
/* coupling frequency range */ |
862 |
- /* TODO: modify coupling end freq if spectral extension is used */ |
|
863 | 862 |
cpl_start_subband = get_bits(gbc, 4); |
864 |
- cpl_end_subband = get_bits(gbc, 4) + 3; |
|
863 |
+ cpl_end_subband = s->spx_in_use ? (s->spx_src_start_freq - 37) / 12 : |
|
864 |
+ get_bits(gbc, 4) + 3; |
|
865 | 865 |
if (cpl_start_subband >= cpl_end_subband) { |
866 | 866 |
av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n", |
867 | 867 |
cpl_start_subband, cpl_end_subband); |
... | ... |
@@ -934,8 +1025,11 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
934 | 934 |
if (channel_mode == AC3_CHMODE_STEREO) { |
935 | 935 |
if ((s->eac3 && !blk) || get_bits1(gbc)) { |
936 | 936 |
s->num_rematrixing_bands = 4; |
937 |
- if(cpl_in_use && s->start_freq[CPL_CH] <= 61) |
|
937 |
+ if (cpl_in_use && s->start_freq[CPL_CH] <= 61) { |
|
938 | 938 |
s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37); |
939 |
+ } else if (s->spx_in_use && s->spx_src_start_freq <= 61) { |
|
940 |
+ s->num_rematrixing_bands--; |
|
941 |
+ } |
|
939 | 942 |
for(bnd=0; bnd<s->num_rematrixing_bands; bnd++) |
940 | 943 |
s->rematrixing_flags[bnd] = get_bits1(gbc); |
941 | 944 |
} else if (!blk) { |
... | ... |
@@ -960,6 +1054,8 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
960 | 960 |
int prev = s->end_freq[ch]; |
961 | 961 |
if (s->channel_in_cpl[ch]) |
962 | 962 |
s->end_freq[ch] = s->start_freq[CPL_CH]; |
963 |
+ else if (s->channel_uses_spx[ch]) |
|
964 |
+ s->end_freq[ch] = s->spx_src_start_freq; |
|
963 | 965 |
else { |
964 | 966 |
int bandwidth_code = get_bits(gbc, 6); |
965 | 967 |
if (bandwidth_code > 60) { |
... | ... |
@@ -1156,8 +1252,6 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1156 | 1156 |
|
1157 | 1157 |
/* TODO: generate enhanced coupling coordinates and uncouple */ |
1158 | 1158 |
|
1159 |
- /* TODO: apply spectral extension */ |
|
1160 |
- |
|
1161 | 1159 |
/* recover coefficients if rematrixing is in use */ |
1162 | 1160 |
if(s->channel_mode == AC3_CHMODE_STEREO) |
1163 | 1161 |
do_rematrixing(s); |
... | ... |
@@ -1173,6 +1267,11 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1173 | 1173 |
s->dsp.int32_to_float_fmul_scalar(s->transform_coeffs[ch], s->fixed_coeffs[ch], gain, 256); |
1174 | 1174 |
} |
1175 | 1175 |
|
1176 |
+ /* apply spectral extension to high frequency bins */ |
|
1177 |
+ if (s->spx_in_use) { |
|
1178 |
+ ff_eac3_apply_spectral_extension(s); |
|
1179 |
+ } |
|
1180 |
+ |
|
1176 | 1181 |
/* downmix and MDCT. order depends on whether block switching is used for |
1177 | 1182 |
any channel in this block. this is because coefficients for the long |
1178 | 1183 |
and short transforms cannot be mixed. */ |
... | ... |
@@ -22,6 +22,29 @@ |
22 | 22 |
/** |
23 | 23 |
* @file libavcodec/ac3.h |
24 | 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 | 50 |
#ifndef AVCODEC_AC3DEC_H |
... | ... |
@@ -43,6 +66,7 @@ |
43 | 43 |
#define AC3_MAX_COEFS 256 |
44 | 44 |
#define AC3_BLOCK_SIZE 256 |
45 | 45 |
#define MAX_BLOCKS 6 |
46 |
+#define SPX_MAX_BANDS 17 |
|
46 | 47 |
|
47 | 48 |
typedef struct { |
48 | 49 |
AVCodecContext *avctx; ///< parent context |
... | ... |
@@ -89,6 +113,22 @@ typedef struct { |
89 | 89 |
int cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates (cplco) |
90 | 90 |
///@} |
91 | 91 |
|
92 |
+///@defgroup spx spectral extension |
|
93 |
+///@{ |
|
94 |
+ int spx_in_use; ///< spectral extension in use (spxinu) |
|
95 |
+ uint8_t channel_uses_spx[AC3_MAX_CHANNELS]; ///< channel uses spectral extension (chinspx) |
|
96 |
+ int8_t spx_atten_code[AC3_MAX_CHANNELS]; ///< spx attenuation code (spxattencod) |
|
97 |
+ int spx_src_start_freq; ///< spx start frequency bin |
|
98 |
+ int spx_dst_end_freq; ///< spx end frequency bin |
|
99 |
+ int spx_dst_start_freq; ///< spx starting frequency bin for copying (copystartmant) |
|
100 |
+ ///< the copy region ends at the start of the spx region. |
|
101 |
+ int num_spx_bands; ///< number of spx bands (nspxbnds) |
|
102 |
+ uint8_t spx_band_sizes[SPX_MAX_BANDS]; ///< number of bins in each spx band |
|
103 |
+ uint8_t first_spx_coords[AC3_MAX_CHANNELS]; ///< first spx coordinates states (firstspxcos) |
|
104 |
+ float spx_noise_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]; ///< spx noise blending factor (nblendfact) |
|
105 |
+ float spx_signal_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS];///< spx signal blending factor (sblendfact) |
|
106 |
+///@} |
|
107 |
+ |
|
92 | 108 |
///@defgroup aht adaptive hybrid transform |
93 | 109 |
int channel_uses_aht[AC3_MAX_CHANNELS]; ///< channel AHT in use (chahtinu) |
94 | 110 |
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); |
182 | 182 |
void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], |
183 | 183 |
int out_ch, int in_ch, int len); |
184 | 184 |
|
185 |
+/** |
|
186 |
+ * Apply spectral extension to each channel by copying lower frequency |
|
187 |
+ * coefficients to higher frequency bins and applying side information to |
|
188 |
+ * approximate the original high frequency signal. |
|
189 |
+ */ |
|
190 |
+void ff_eac3_apply_spectral_extension(AC3DecodeContext *s); |
|
191 |
+ |
|
185 | 192 |
#endif /* AVCODEC_AC3DEC_H */ |
... | ... |
@@ -64,3 +64,9 @@ const uint8_t ff_eac3_hebap_tab[64] = { |
64 | 64 |
*/ |
65 | 65 |
const uint8_t ff_eac3_default_cpl_band_struct[18] = |
66 | 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]; |
29 | 29 |
|
30 | 30 |
extern const uint8_t ff_eac3_hebap_tab[64]; |
31 | 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 | 34 |
#endif /* AVCODEC_AC3DEC_DATA_H */ |
... | ... |
@@ -30,7 +30,7 @@ |
30 | 30 |
#include "libavutil/avutil.h" |
31 | 31 |
|
32 | 32 |
#define LIBAVCODEC_VERSION_MAJOR 52 |
33 |
-#define LIBAVCODEC_VERSION_MINOR 62 |
|
33 |
+#define LIBAVCODEC_VERSION_MINOR 63 |
|
34 | 34 |
#define LIBAVCODEC_VERSION_MICRO 0 |
35 | 35 |
|
36 | 36 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
... | ... |
@@ -23,10 +23,6 @@ |
23 | 23 |
/* |
24 | 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 | 26 |
* Enhanced Coupling |
31 | 27 |
* No known samples exist. If any ever surface, this feature should not be |
32 | 28 |
* too difficult to implement. |
... | ... |
@@ -67,6 +63,95 @@ typedef enum { |
67 | 67 |
|
68 | 68 |
#define EAC3_SR_CODE_REDUCED 3 |
69 | 69 |
|
70 |
+void ff_eac3_apply_spectral_extension(AC3DecodeContext *s) |
|
71 |
+{ |
|
72 |
+ int bin, bnd, ch, i; |
|
73 |
+ uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS]; |
|
74 |
+ float rms_energy[SPX_MAX_BANDS]; |
|
75 |
+ |
|
76 |
+ /* Set copy index mapping table. Set wrap flags to apply a notch filter at |
|
77 |
+ wrap points later on. */ |
|
78 |
+ bin = s->spx_dst_start_freq; |
|
79 |
+ num_copy_sections = 0; |
|
80 |
+ for (bnd = 0; bnd < s->num_spx_bands; bnd++) { |
|
81 |
+ int copysize; |
|
82 |
+ int bandsize = s->spx_band_sizes[bnd]; |
|
83 |
+ if (bin + bandsize > s->spx_src_start_freq) { |
|
84 |
+ copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq; |
|
85 |
+ bin = s->spx_dst_start_freq; |
|
86 |
+ wrapflag[bnd] = 1; |
|
87 |
+ } |
|
88 |
+ for (i = 0; i < bandsize; i += copysize) { |
|
89 |
+ if (bin == s->spx_src_start_freq) { |
|
90 |
+ copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq; |
|
91 |
+ bin = s->spx_dst_start_freq; |
|
92 |
+ } |
|
93 |
+ copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin); |
|
94 |
+ bin += copysize; |
|
95 |
+ } |
|
96 |
+ } |
|
97 |
+ copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq; |
|
98 |
+ |
|
99 |
+ for (ch = 1; ch <= s->fbw_channels; ch++) { |
|
100 |
+ if (!s->channel_uses_spx[ch]) |
|
101 |
+ continue; |
|
102 |
+ |
|
103 |
+ /* Copy coeffs from normal bands to extension bands */ |
|
104 |
+ bin = s->spx_src_start_freq; |
|
105 |
+ for (i = 0; i < num_copy_sections; i++) { |
|
106 |
+ memcpy(&s->transform_coeffs[ch][bin], |
|
107 |
+ &s->transform_coeffs[ch][s->spx_dst_start_freq], |
|
108 |
+ copy_sizes[i]*sizeof(float)); |
|
109 |
+ bin += copy_sizes[i]; |
|
110 |
+ } |
|
111 |
+ |
|
112 |
+ /* Calculate RMS energy for each SPX band. */ |
|
113 |
+ bin = s->spx_src_start_freq; |
|
114 |
+ for (bnd = 0; bnd < s->num_spx_bands; bnd++) { |
|
115 |
+ int bandsize = s->spx_band_sizes[bnd]; |
|
116 |
+ float accum = 0.0f; |
|
117 |
+ for (i = 0; i < bandsize; i++) { |
|
118 |
+ float coeff = s->transform_coeffs[ch][bin++]; |
|
119 |
+ accum += coeff * coeff; |
|
120 |
+ } |
|
121 |
+ rms_energy[bnd] = sqrtf(accum / bandsize); |
|
122 |
+ } |
|
123 |
+ |
|
124 |
+ /* Apply a notch filter at transitions between normal and extension |
|
125 |
+ bands and at all wrap points. */ |
|
126 |
+ if (s->spx_atten_code[ch] >= 0) { |
|
127 |
+ const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]]; |
|
128 |
+ bin = s->spx_src_start_freq - 2; |
|
129 |
+ for (bnd = 0; bnd < s->num_spx_bands; bnd++) { |
|
130 |
+ if (wrapflag[bnd]) { |
|
131 |
+ float *coeffs = &s->transform_coeffs[ch][bin]; |
|
132 |
+ coeffs[0] *= atten_tab[0]; |
|
133 |
+ coeffs[1] *= atten_tab[1]; |
|
134 |
+ coeffs[2] *= atten_tab[2]; |
|
135 |
+ coeffs[3] *= atten_tab[1]; |
|
136 |
+ coeffs[4] *= atten_tab[0]; |
|
137 |
+ } |
|
138 |
+ bin += s->spx_band_sizes[bnd]; |
|
139 |
+ } |
|
140 |
+ } |
|
141 |
+ |
|
142 |
+ /* Apply noise-blended coefficient scaling based on previously |
|
143 |
+ calculated RMS energy, blending factors, and SPX coordinates for |
|
144 |
+ each band. */ |
|
145 |
+ bin = s->spx_src_start_freq; |
|
146 |
+ for (bnd = 0; bnd < s->num_spx_bands; bnd++) { |
|
147 |
+ float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f/(1<<31)); |
|
148 |
+ float sscale = s->spx_signal_blend[ch][bnd]; |
|
149 |
+ for (i = 0; i < s->spx_band_sizes[bnd]; i++) { |
|
150 |
+ float noise = nscale * (int32_t)av_lfg_get(&s->dith_state); |
|
151 |
+ s->transform_coeffs[ch][bin] *= sscale; |
|
152 |
+ s->transform_coeffs[ch][bin++] += noise; |
|
153 |
+ } |
|
154 |
+ } |
|
155 |
+ } |
|
156 |
+} |
|
157 |
+ |
|
158 |
+ |
|
70 | 159 |
/** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */ |
71 | 160 |
#define COEFF_0 10273905LL |
72 | 161 |
|
... | ... |
@@ -492,12 +577,11 @@ int ff_eac3_parse_header(AC3DecodeContext *s) |
492 | 492 |
} |
493 | 493 |
|
494 | 494 |
/* spectral extension attenuation data */ |
495 |
- if (parse_spx_atten_data) { |
|
496 |
- av_log_missing_feature(s->avctx, "Spectral extension attenuation", 1); |
|
497 |
- for (ch = 1; ch <= s->fbw_channels; ch++) { |
|
498 |
- if (get_bits1(gbc)) { // channel has spx attenuation |
|
499 |
- skip_bits(gbc, 5); // skip spx attenuation code |
|
500 |
- } |
|
495 |
+ for (ch = 1; ch <= s->fbw_channels; ch++) { |
|
496 |
+ if (parse_spx_atten_data && get_bits1(gbc)) { |
|
497 |
+ s->spx_atten_code[ch] = get_bits(gbc, 5); |
|
498 |
+ } else { |
|
499 |
+ s->spx_atten_code[ch] = -1; |
|
501 | 500 |
} |
502 | 501 |
} |
503 | 502 |
|
... | ... |
@@ -514,6 +598,7 @@ int ff_eac3_parse_header(AC3DecodeContext *s) |
514 | 514 |
|
515 | 515 |
/* syntax state initialization */ |
516 | 516 |
for (ch = 1; ch <= s->fbw_channels; ch++) { |
517 |
+ s->first_spx_coords[ch] = 1; |
|
517 | 518 |
s->first_cpl_coords[ch] = 1; |
518 | 519 |
} |
519 | 520 |
s->first_cpl_leak = 1; |
... | ... |
@@ -1093,3 +1093,42 @@ const uint8_t ff_eac3_frm_expstr[32][6] = { |
1093 | 1093 |
{ EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE}, |
1094 | 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]; |
31 | 31 |
|
32 | 32 |
extern const int16_t (* const ff_eac3_mantissa_vq[8])[6]; |
33 | 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 | 36 |
#endif /* AVCODEC_EAC3DEC_DATA_H */ |