Originally committed as revision 14674 to svn://svn.ffmpeg.org/ffmpeg/trunk
Robert Swain authored on 2008/08/09 19:46:27... | ... |
@@ -82,6 +82,7 @@ |
82 | 82 |
|
83 | 83 |
#include "aac.h" |
84 | 84 |
#include "aactab.h" |
85 |
+#include "aacdectab.h" |
|
85 | 86 |
#include "mpeg4audio.h" |
86 | 87 |
|
87 | 88 |
#include <assert.h> |
... | ... |
@@ -91,6 +92,7 @@ |
91 | 91 |
|
92 | 92 |
#ifndef CONFIG_HARDCODED_TABLES |
93 | 93 |
static float ff_aac_ivquant_tab[IVQUANT_SIZE]; |
94 |
+ static float ff_aac_pow2sf_tab[316]; |
|
94 | 95 |
#endif /* CONFIG_HARDCODED_TABLES */ |
95 | 96 |
|
96 | 97 |
static VLC vlc_scalefactors; |
... | ... |
@@ -104,27 +106,29 @@ static VLC vlc_spectral[11]; |
104 | 104 |
num_assoc_data = get_bits(gb, 3); |
105 | 105 |
num_cc = get_bits(gb, 4); |
106 | 106 |
|
107 |
- newpcs->mono_mixdown_tag = get_bits1(gb) ? get_bits(gb, 4) : -1; |
|
108 |
- newpcs->stereo_mixdown_tag = get_bits1(gb) ? get_bits(gb, 4) : -1; |
|
107 |
+ if (get_bits1(gb)) |
|
108 |
+ skip_bits(gb, 4); // mono_mixdown_tag |
|
109 |
+ if (get_bits1(gb)) |
|
110 |
+ skip_bits(gb, 4); // stereo_mixdown_tag |
|
109 | 111 |
|
110 |
- if (get_bits1(gb)) { |
|
111 |
- newpcs->mixdown_coeff_index = get_bits(gb, 2); |
|
112 |
- newpcs->pseudo_surround = get_bits1(gb); |
|
113 |
- } |
|
112 |
+ if (get_bits1(gb)) |
|
113 |
+ skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround |
|
114 | 114 |
|
115 |
- program_config_element_parse_tags(newpcs->che_type[ID_CPE], newpcs->che_type[ID_SCE], AAC_CHANNEL_FRONT, gb, num_front); |
|
116 |
- program_config_element_parse_tags(newpcs->che_type[ID_CPE], newpcs->che_type[ID_SCE], AAC_CHANNEL_SIDE, gb, num_side ); |
|
117 |
- program_config_element_parse_tags(newpcs->che_type[ID_CPE], newpcs->che_type[ID_SCE], AAC_CHANNEL_BACK, gb, num_back ); |
|
118 |
- program_config_element_parse_tags(NULL, newpcs->che_type[ID_LFE], AAC_CHANNEL_LFE, gb, num_lfe ); |
|
115 |
+ decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_FRONT, gb, num_front); |
|
116 |
+ decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_SIDE, gb, num_side ); |
|
117 |
+ decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_BACK, gb, num_back ); |
|
118 |
+ decode_channel_map(NULL, new_che_pos[TYPE_LFE], AAC_CHANNEL_LFE, gb, num_lfe ); |
|
119 | 119 |
|
120 | 120 |
skip_bits_long(gb, 4 * num_assoc_data); |
121 | 121 |
|
122 |
- program_config_element_parse_tags(newpcs->che_type[ID_CCE], newpcs->che_type[ID_CCE], AAC_CHANNEL_CC, gb, num_cc ); |
|
122 |
+ decode_channel_map(new_che_pos[TYPE_CCE], new_che_pos[TYPE_CCE], AAC_CHANNEL_CC, gb, num_cc ); |
|
123 | 123 |
|
124 | 124 |
align_get_bits(gb); |
125 | 125 |
|
126 | 126 |
/* comment field, first byte is length */ |
127 | 127 |
skip_bits_long(gb, 8 * get_bits(gb, 8)); |
128 |
+ return 0; |
|
129 |
+} |
|
128 | 130 |
|
129 | 131 |
static av_cold int aac_decode_init(AVCodecContext * avccontext) { |
130 | 132 |
AACContext * ac = avccontext->priv_data; |
... | ... |
@@ -132,6 +136,10 @@ static av_cold int aac_decode_init(AVCodecContext * avccontext) { |
132 | 132 |
|
133 | 133 |
ac->avccontext = avccontext; |
134 | 134 |
|
135 |
+ if (avccontext->extradata_size <= 0 || |
|
136 |
+ decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size)) |
|
137 |
+ return -1; |
|
138 |
+ |
|
135 | 139 |
avccontext->sample_rate = ac->m4ac.sample_rate; |
136 | 140 |
avccontext->frame_size = 1024; |
137 | 141 |
|
... | ... |
@@ -166,6 +174,8 @@ static av_cold int aac_decode_init(AVCodecContext * avccontext) { |
166 | 166 |
#ifndef CONFIG_HARDCODED_TABLES |
167 | 167 |
for (i = 1 - IVQUANT_SIZE/2; i < IVQUANT_SIZE/2; i++) |
168 | 168 |
ff_aac_ivquant_tab[i + IVQUANT_SIZE/2 - 1] = cbrt(fabs(i)) * i; |
169 |
+ for (i = 0; i < 316; i++) |
|
170 |
+ ff_aac_pow2sf_tab[i] = pow(2, (i - 200)/4.); |
|
169 | 171 |
#endif /* CONFIG_HARDCODED_TABLES */ |
170 | 172 |
|
171 | 173 |
INIT_VLC_STATIC(&vlc_scalefactors, 7, sizeof(ff_aac_scalefactor_code)/sizeof(ff_aac_scalefactor_code[0]), |
... | ... |
@@ -200,6 +210,112 @@ static inline float ivquant(int a) { |
200 | 200 |
return cbrtf(fabsf(a)) * a; |
201 | 201 |
} |
202 | 202 |
|
203 |
+ int band_type_run_end[120], GetBitContext * gb, IndividualChannelStream * ics) { |
|
204 |
+ int g, idx = 0; |
|
205 |
+ const int bits = (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) ? 3 : 5; |
|
206 |
+ for (g = 0; g < ics->num_window_groups; g++) { |
|
207 |
+ int k = 0; |
|
208 |
+ while (k < ics->max_sfb) { |
|
209 |
+ uint8_t sect_len = k; |
|
210 |
+ int sect_len_incr; |
|
211 |
+ int sect_band_type = get_bits(gb, 4); |
|
212 |
+ if (sect_band_type == 12) { |
|
213 |
+ av_log(ac->avccontext, AV_LOG_ERROR, "invalid band type\n"); |
|
214 |
+ return -1; |
|
215 |
+ } |
|
216 |
+ while ((sect_len_incr = get_bits(gb, bits)) == (1 << bits)-1) |
|
217 |
+ sect_len += sect_len_incr; |
|
218 |
+ sect_len += sect_len_incr; |
|
219 |
+ if (sect_len > ics->max_sfb) { |
|
220 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
221 |
+ "Number of bands (%d) exceeds limit (%d).\n", |
|
222 |
+ sect_len, ics->max_sfb); |
|
223 |
+ return -1; |
|
224 |
+ } |
|
225 |
+ |
|
226 |
+ * |
|
227 |
+ * @param mix_gain channel gain (Not used by AAC bitstream.) |
|
228 |
+ * @param global_gain first scalefactor value as scalefactors are differentially coded |
|
229 |
+ * @param band_type array of the used band type |
|
230 |
+ * @param band_type_run_end array of the last scalefactor band of a band type run |
|
231 |
+ * @param sf array of scalefactors or intensity stereo positions |
|
232 |
+ * |
|
233 |
+ * @return Returns error status. 0 - OK, !0 - error |
|
234 |
+ */ |
|
235 |
+static int decode_scalefactors(AACContext * ac, float sf[120], GetBitContext * gb, |
|
236 |
+ float mix_gain, unsigned int global_gain, IndividualChannelStream * ics, |
|
237 |
+ enum BandType band_type[120], int band_type_run_end[120]) { |
|
238 |
+ const int sf_offset = ac->sf_offset + (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ? 12 : 0); |
|
239 |
+ int g, i, idx = 0; |
|
240 |
+ int offset[3] = { global_gain, global_gain - 90, 100 }; |
|
241 |
+ int noise_flag = 1; |
|
242 |
+ static const char *sf_str[3] = { "Global gain", "Noise gain", "Intensity stereo position" }; |
|
243 |
+ ics->intensity_present = 0; |
|
244 |
+ for (g = 0; g < ics->num_window_groups; g++) { |
|
245 |
+ for (i = 0; i < ics->max_sfb;) { |
|
246 |
+ int run_end = band_type_run_end[idx]; |
|
247 |
+ if (band_type[idx] == ZERO_BT) { |
|
248 |
+ for(; i < run_end; i++, idx++) |
|
249 |
+ sf[idx] = 0.; |
|
250 |
+ }else if((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) { |
|
251 |
+ ics->intensity_present = 1; |
|
252 |
+ for(; i < run_end; i++, idx++) { |
|
253 |
+ offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; |
|
254 |
+ if(offset[2] > 255U) { |
|
255 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
256 |
+ "%s (%d) out of range.\n", sf_str[2], offset[2]); |
|
257 |
+ return -1; |
|
258 |
+ } |
|
259 |
+ sf[idx] = ff_aac_pow2sf_tab[-offset[2] + 300]; |
|
260 |
+ sf[idx] *= mix_gain; |
|
261 |
+ } |
|
262 |
+ }else if(band_type[idx] == NOISE_BT) { |
|
263 |
+ for(; i < run_end; i++, idx++) { |
|
264 |
+ if(noise_flag-- > 0) |
|
265 |
+ offset[1] += get_bits(gb, 9) - 256; |
|
266 |
+ else |
|
267 |
+ offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; |
|
268 |
+ if(offset[1] > 255U) { |
|
269 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
270 |
+ "%s (%d) out of range.\n", sf_str[1], offset[1]); |
|
271 |
+ return -1; |
|
272 |
+ } |
|
273 |
+ sf[idx] = -ff_aac_pow2sf_tab[ offset[1] + sf_offset]; |
|
274 |
+ sf[idx] *= mix_gain; |
|
275 |
+ } |
|
276 |
+ }else { |
|
277 |
+ for(; i < run_end; i++, idx++) { |
|
278 |
+ offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; |
|
279 |
+ if(offset[0] > 255U) { |
|
280 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
281 |
+ "%s (%d) out of range.\n", sf_str[0], offset[0]); |
|
282 |
+ return -1; |
|
283 |
+ } |
|
284 |
+ sf[idx] = -ff_aac_pow2sf_tab[ offset[0] + sf_offset]; |
|
285 |
+ sf[idx] *= mix_gain; |
|
286 |
+ } |
|
287 |
+ } |
|
288 |
+ } |
|
289 |
+ } |
|
290 |
+ return 0; |
|
291 |
+} |
|
292 |
+ |
|
293 |
+/** |
|
294 |
+ * Decode pulse data; reference: table 4.7. |
|
295 |
+ */ |
|
296 |
+static void decode_pulses(Pulse * pulse, GetBitContext * gb) { |
|
297 |
+ int i; |
|
298 |
+ pulse->num_pulse = get_bits(gb, 2) + 1; |
|
299 |
+ pulse->start = get_bits(gb, 6); |
|
300 |
+ for (i = 0; i < pulse->num_pulse; i++) { |
|
301 |
+ pulse->offset[i] = get_bits(gb, 5); |
|
302 |
+ pulse->amp [i] = get_bits(gb, 4); |
|
303 |
+ } |
|
304 |
+} |
|
305 |
+ |
|
306 |
+/** |
|
307 |
+ * Add pulses with particular amplitudes to the quantized spectral data; reference: 4.6.3.3. |
|
308 |
+ * |
|
203 | 309 |
* @param pulse pointer to pulse data struct |
204 | 310 |
* @param icoef array of quantized spectral data |
205 | 311 |
*/ |
... | ... |
@@ -213,18 +329,97 @@ static void add_pulses(int icoef[1024], const Pulse * pulse, const IndividualCha |
213 | 213 |
} |
214 | 214 |
} |
215 | 215 |
|
216 |
+/** |
|
217 |
+ * Parse Spectral Band Replication extension data; reference: table 4.55. |
|
218 |
+ * |
|
219 |
+ * @param crc flag indicating the presence of CRC checksum |
|
220 |
+ * @param cnt length of TYPE_FIL syntactic element in bytes |
|
221 |
+ * @return Returns number of bytes consumed from the TYPE_FIL element. |
|
222 |
+ */ |
|
223 |
+static int decode_sbr_extension(AACContext * ac, GetBitContext * gb, int crc, int cnt) { |
|
224 |
+ // TODO : sbr_extension implementation |
|
225 |
+ av_log(ac->avccontext, AV_LOG_DEBUG, "aac: SBR not yet supported.\n"); |
|
226 |
+ skip_bits_long(gb, 8*cnt - 4); // -4 due to reading extension type |
|
227 |
+ return cnt; |
|
228 |
+} |
|
229 |
+ |
|
230 |
+ int crc_flag = 0; |
|
231 |
+ int res = cnt; |
|
232 |
+ switch (get_bits(gb, 4)) { // extension type |
|
233 |
+ case EXT_SBR_DATA_CRC: |
|
234 |
+ crc_flag++; |
|
235 |
+ case EXT_SBR_DATA: |
|
236 |
+ res = decode_sbr_extension(ac, gb, crc_flag, cnt); |
|
237 |
+ break; |
|
238 |
+ case EXT_DYNAMIC_RANGE: |
|
239 |
+ res = decode_dynamic_range(&ac->che_drc, gb, cnt); |
|
240 |
+ break; |
|
241 |
+ case EXT_FILL: |
|
242 |
+ case EXT_FILL_DATA: |
|
243 |
+ case EXT_DATA_ELEMENT: |
|
244 |
+ default: |
|
245 |
+ skip_bits_long(gb, 8*cnt - 4); |
|
246 |
+ break; |
|
247 |
+ }; |
|
248 |
+ return res; |
|
249 |
+} |
|
250 |
+ |
|
251 |
+/** |
|
252 |
+ * Apply dependent channel coupling (applied before IMDCT). |
|
253 |
+ * |
|
254 |
+ * @param index index into coupling gain array |
|
255 |
+ */ |
|
256 |
+static void apply_dependent_coupling(AACContext * ac, SingleChannelElement * sce, ChannelElement * cc, int index) { |
|
257 |
+ IndividualChannelStream * ics = &cc->ch[0].ics; |
|
258 |
+ const uint16_t * offsets = ics->swb_offset; |
|
259 |
+ float * dest = sce->coeffs; |
|
260 |
+ const float * src = cc->ch[0].coeffs; |
|
261 |
+ int g, i, group, k, idx = 0; |
|
262 |
+ if(ac->m4ac.object_type == AOT_AAC_LTP) { |
|
263 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
264 |
+ "Dependent coupling is not supported together with LTP\n"); |
|
265 |
+ return; |
|
266 |
+ } |
|
267 |
+ for (g = 0; g < ics->num_window_groups; g++) { |
|
268 |
+ for (i = 0; i < ics->max_sfb; i++, idx++) { |
|
269 |
+ if (cc->ch[0].band_type[idx] != ZERO_BT) { |
|
270 |
+ float gain = cc->coup.gain[index][idx] * sce->mixing_gain; |
|
271 |
+ for (group = 0; group < ics->group_len[g]; group++) { |
|
272 |
+ for (k = offsets[i]; k < offsets[i+1]; k++) { |
|
273 |
+ // XXX dsputil-ize |
|
274 |
+ dest[group*128+k] += gain * src[group*128+k]; |
|
275 |
+ } |
|
276 |
+ } |
|
277 |
+ } |
|
278 |
+ } |
|
279 |
+ dest += ics->group_len[g]*128; |
|
280 |
+ src += ics->group_len[g]*128; |
|
281 |
+ } |
|
282 |
+} |
|
283 |
+ |
|
284 |
+/** |
|
285 |
+ * Apply independent channel coupling (applied after IMDCT). |
|
286 |
+ * |
|
287 |
+ * @param index index into coupling gain array |
|
288 |
+ */ |
|
289 |
+static void apply_independent_coupling(AACContext * ac, SingleChannelElement * sce, ChannelElement * cc, int index) { |
|
290 |
+ int i; |
|
291 |
+ float gain = cc->coup.gain[index][0] * sce->mixing_gain; |
|
292 |
+ for (i = 0; i < 1024; i++) |
|
293 |
+ sce->ret[i] += gain * (cc->ch[0].ret[i] - ac->add_bias); |
|
294 |
+} |
|
295 |
+ |
|
216 | 296 |
static av_cold int aac_decode_close(AVCodecContext * avccontext) { |
217 | 297 |
AACContext * ac = avccontext->priv_data; |
218 | 298 |
int i, j; |
219 | 299 |
|
220 |
- for (i = 0; i < MAX_TAGID; i++) { |
|
300 |
+ for (i = 0; i < MAX_ELEM_ID; i++) { |
|
221 | 301 |
for(j = 0; j < 4; j++) |
222 | 302 |
av_freep(&ac->che[j][i]); |
223 | 303 |
} |
224 | 304 |
|
225 | 305 |
ff_mdct_end(&ac->mdct); |
226 | 306 |
ff_mdct_end(&ac->mdct_small); |
227 |
- av_freep(&ac->interleaved_output); |
|
228 | 307 |
return 0 ; |
229 | 308 |
} |
230 | 309 |
|
... | ... |
@@ -238,4 +433,5 @@ AVCodec aac_decoder = { |
238 | 238 |
aac_decode_close, |
239 | 239 |
aac_decode_frame, |
240 | 240 |
.long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), |
241 |
+ .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, |
|
241 | 242 |
}; |
... | ... |
@@ -42,8 +42,49 @@ |
42 | 42 |
ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), sizeof(ff_aac_spectral_codes[num][0]), \ |
43 | 43 |
size); |
44 | 44 |
|
45 |
+#define MAX_CHANNELS 64 |
|
46 |
+ |
|
45 | 47 |
#define IVQUANT_SIZE 1024 |
46 | 48 |
|
49 |
+enum AudioObjectType { |
|
50 |
+ AOT_NULL, |
|
51 |
+ // Support? Name |
|
52 |
+ AOT_AAC_MAIN, ///< Y Main |
|
53 |
+ AOT_AAC_LC, ///< Y Low Complexity |
|
54 |
+ AOT_AAC_SSR, ///< N (code in SoC repo) Scalable Sample Rate |
|
55 |
+ AOT_AAC_LTP, ///< N (code in SoC repo) Long Term Prediction |
|
56 |
+ AOT_SBR, ///< N (in progress) Spectral Band Replication |
|
57 |
+ AOT_AAC_SCALABLE, ///< N Scalable |
|
58 |
+ AOT_TWINVQ, ///< N Twin Vector Quantizer |
|
59 |
+ AOT_CELP, ///< N Code Excited Linear Prediction |
|
60 |
+ AOT_HVXC, ///< N Harmonic Vector eXcitation Coding |
|
61 |
+ AOT_TTSI = 12, ///< N Text-To-Speech Interface |
|
62 |
+ AOT_MAINSYNTH, ///< N Main Synthesis |
|
63 |
+ AOT_WAVESYNTH, ///< N Wavetable Synthesis |
|
64 |
+ AOT_MIDI, ///< N General MIDI |
|
65 |
+ AOT_SAFX, ///< N Algorithmic Synthesis and Audio Effects |
|
66 |
+ AOT_ER_AAC_LC, ///< N Error Resilient Low Complexity |
|
67 |
+ AOT_ER_AAC_LTP = 19, ///< N Error Resilient Long Term Prediction |
|
68 |
+ AOT_ER_AAC_SCALABLE, ///< N Error Resilient Scalable |
|
69 |
+ AOT_ER_TWINVQ, ///< N Error Resilient Twin Vector Quantizer |
|
70 |
+ AOT_ER_BSAC, ///< N Error Resilient Bit-Sliced Arithmetic Coding |
|
71 |
+ AOT_ER_AAC_LD, ///< N Error Resilient Low Delay |
|
72 |
+ AOT_ER_CELP, ///< N Error Resilient Code Excited Linear Prediction |
|
73 |
+ AOT_ER_HVXC, ///< N Error Resilient Harmonic Vector eXcitation Coding |
|
74 |
+ AOT_ER_HILN, ///< N Error Resilient Harmonic and Individual Lines plus Noise |
|
75 |
+ AOT_ER_PARAM, ///< N Error Resilient Parametric |
|
76 |
+ AOT_SSC, ///< N SinuSoidal Coding |
|
77 |
+}; |
|
78 |
+ |
|
79 |
+enum ExtensionPayloadID { |
|
80 |
+ EXT_FILL, |
|
81 |
+ EXT_FILL_DATA, |
|
82 |
+ EXT_DATA_ELEMENT, |
|
83 |
+ EXT_DYNAMIC_RANGE = 0xb, |
|
84 |
+ EXT_SBR_DATA = 0xd, |
|
85 |
+ EXT_SBR_DATA_CRC = 0xe, |
|
86 |
+}; |
|
87 |
+ |
|
47 | 88 |
enum WindowSequence { |
48 | 89 |
ONLY_LONG_SEQUENCE, |
49 | 90 |
LONG_START_SEQUENCE, |
... | ... |
@@ -51,7 +92,18 @@ enum WindowSequence { |
51 | 51 |
LONG_STOP_SEQUENCE, |
52 | 52 |
}; |
53 | 53 |
|
54 |
-enum ChannelType { |
|
54 |
+enum BandType { |
|
55 |
+ ZERO_BT = 0, ///< Scalefactors and spectral data are all zero. |
|
56 |
+ FIRST_PAIR_BT = 5, ///< This and later band types encode two values (rather than four) with one code word. |
|
57 |
+ ESC_BT = 11, ///< Spectral data are coded with an escape sequence. |
|
58 |
+ NOISE_BT = 13, ///< Spectral data are scaled white noise not coded in the bitstream. |
|
59 |
+ INTENSITY_BT2 = 14, ///< Scalefactor data are intensity stereo positions. |
|
60 |
+ INTENSITY_BT = 15, ///< Scalefactor data are intensity stereo positions. |
|
61 |
+}; |
|
62 |
+ |
|
63 |
+#define IS_CODEBOOK_UNSIGNED(x) ((x - 1) & 10) |
|
64 |
+ |
|
65 |
+enum ChannelPosition { |
|
55 | 66 |
AAC_CHANNEL_FRONT = 1, |
56 | 67 |
AAC_CHANNEL_SIDE = 2, |
57 | 68 |
AAC_CHANNEL_BACK = 3, |
... | ... |
@@ -59,12 +111,33 @@ enum ChannelType { |
59 | 59 |
AAC_CHANNEL_CC = 5, |
60 | 60 |
}; |
61 | 61 |
|
62 |
+typedef struct { |
|
63 |
+ int num_pulse; |
|
64 |
+ int start; |
|
65 |
+ int offset[4]; |
|
66 |
+ int amp[4]; |
|
67 |
+} Pulse; |
|
68 |
+ |
|
69 |
+/** |
|
70 |
+ * coupling parameters |
|
71 |
+ */ |
|
72 |
+typedef struct { |
|
73 |
+ |
|
62 | 74 |
/** |
63 | 75 |
* main AAC context |
64 | 76 |
*/ |
65 | 77 |
typedef struct { |
66 | 78 |
AVCodecContext * avccontext; |
67 | 79 |
|
80 |
+ MPEG4AudioConfig m4ac; |
|
81 |
+ |
|
82 |
+ int is_saved; ///< Set if elements have stored overlap from previous frame. |
|
83 |
+ DynamicRangeControl che_drc; |
|
84 |
+ |
|
85 |
+ enum ChannelPosition che_pos[4][MAX_ELEM_ID]; /**< channel element channel mapping with the |
|
86 |
+ * first index as the first 4 raw data block types |
|
87 |
+ */ |
|
88 |
+ |
|
68 | 89 |
/** |
69 | 90 |
* @defgroup tables Computed / set up during initialization. |
70 | 91 |
* @{ |
... | ... |
@@ -75,9 +148,10 @@ typedef struct { |
75 | 75 |
/** @} */ |
76 | 76 |
|
77 | 77 |
/** |
78 |
- * @defgroup output Members used for output interleaving and down-mixing. |
|
78 |
+ * @defgroup output Members used for output interleaving. |
|
79 | 79 |
* @{ |
80 | 80 |
*/ |
81 |
+ float *output_data[MAX_CHANNELS]; ///< Points to each element's 'ret' buffer (PCM output). |
|
81 | 82 |
float add_bias; ///< offset for dsp.float_to_int16 |
82 | 83 |
float sf_scale; ///< Pre-scale for correct IMDCT and dsp.float_to_int16. |
83 | 84 |
int sf_offset; ///< offset into pow2sf_tab as appropriate for dsp.float_to_int16 |
84 | 85 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,159 @@ |
0 |
+/* |
|
1 |
+ * AAC decoder data |
|
2 |
+ * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) |
|
3 |
+ * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) |
|
4 |
+ * |
|
5 |
+ * This file is part of FFmpeg. |
|
6 |
+ * |
|
7 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
8 |
+ * modify it under the terms of the GNU Lesser General Public |
|
9 |
+ * License as published by the Free Software Foundation; either |
|
10 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
11 |
+ * |
|
12 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
13 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
+ * Lesser General Public License for more details. |
|
16 |
+ * |
|
17 |
+ * You should have received a copy of the GNU Lesser General Public |
|
18 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
19 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
20 |
+ */ |
|
21 |
+ |
|
22 |
+/** |
|
23 |
+ * @file aacdectab.h |
|
24 |
+ * AAC decoder data |
|
25 |
+ * @author Oded Shimon ( ods15 ods15 dyndns org ) |
|
26 |
+ * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) |
|
27 |
+ */ |
|
28 |
+ |
|
29 |
+#ifndef FFMPEG_AACDECTAB_H |
|
30 |
+#define FFMPEG_AACDECTAB_H |
|
31 |
+ |
|
32 |
+#include "aac.h" |
|
33 |
+ |
|
34 |
+#include <stdint.h> |
|
35 |
+ |
|
36 |
+/* @name swb_offsets |
|
37 |
+ * Sample offset into the window indicating the beginning of a scalefactor |
|
38 |
+ * window band |
|
39 |
+ * |
|
40 |
+ * scalefactor window band - term for scalefactor bands within a window, |
|
41 |
+ * given in Table 4.110 to Table 4.128. |
|
42 |
+ * |
|
43 |
+ * scalefactor band - a set of spectral coefficients which are scaled by one |
|
44 |
+ * scalefactor. In case of EIGHT_SHORT_SEQUENCE and grouping a scalefactor band |
|
45 |
+ * may contain several scalefactor window bands of corresponding frequency. For |
|
46 |
+ * all other window_sequences scalefactor bands and scalefactor window bands are |
|
47 |
+ * identical. |
|
48 |
+ * @{ |
|
49 |
+ */ |
|
50 |
+ |
|
51 |
+static const uint16_t swb_offset_1024_96[] = { |
|
52 |
+ 0, 4, 8, 12, 16, 20, 24, 28, |
|
53 |
+ 32, 36, 40, 44, 48, 52, 56, 64, |
|
54 |
+ 72, 80, 88, 96, 108, 120, 132, 144, |
|
55 |
+ 156, 172, 188, 212, 240, 276, 320, 384, |
|
56 |
+ 448, 512, 576, 640, 704, 768, 832, 896, |
|
57 |
+ 960, 1024 |
|
58 |
+}; |
|
59 |
+ |
|
60 |
+static const uint16_t swb_offset_128_96[] = { |
|
61 |
+ 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128 |
|
62 |
+}; |
|
63 |
+ |
|
64 |
+static const uint16_t swb_offset_1024_64[] = { |
|
65 |
+ 0, 4, 8, 12, 16, 20, 24, 28, |
|
66 |
+ 32, 36, 40, 44, 48, 52, 56, 64, |
|
67 |
+ 72, 80, 88, 100, 112, 124, 140, 156, |
|
68 |
+ 172, 192, 216, 240, 268, 304, 344, 384, |
|
69 |
+ 424, 464, 504, 544, 584, 624, 664, 704, |
|
70 |
+ 744, 784, 824, 864, 904, 944, 984, 1024 |
|
71 |
+}; |
|
72 |
+ |
|
73 |
+static const uint16_t swb_offset_1024_48[] = { |
|
74 |
+ 0, 4, 8, 12, 16, 20, 24, 28, |
|
75 |
+ 32, 36, 40, 48, 56, 64, 72, 80, |
|
76 |
+ 88, 96, 108, 120, 132, 144, 160, 176, |
|
77 |
+ 196, 216, 240, 264, 292, 320, 352, 384, |
|
78 |
+ 416, 448, 480, 512, 544, 576, 608, 640, |
|
79 |
+ 672, 704, 736, 768, 800, 832, 864, 896, |
|
80 |
+ 928, 1024 |
|
81 |
+}; |
|
82 |
+ |
|
83 |
+static const uint16_t swb_offset_128_48[] = { |
|
84 |
+ 0, 4, 8, 12, 16, 20, 28, 36, |
|
85 |
+ 44, 56, 68, 80, 96, 112, 128 |
|
86 |
+}; |
|
87 |
+ |
|
88 |
+static const uint16_t swb_offset_1024_32[] = { |
|
89 |
+ 0, 4, 8, 12, 16, 20, 24, 28, |
|
90 |
+ 32, 36, 40, 48, 56, 64, 72, 80, |
|
91 |
+ 88, 96, 108, 120, 132, 144, 160, 176, |
|
92 |
+ 196, 216, 240, 264, 292, 320, 352, 384, |
|
93 |
+ 416, 448, 480, 512, 544, 576, 608, 640, |
|
94 |
+ 672, 704, 736, 768, 800, 832, 864, 896, |
|
95 |
+ 928, 960, 992, 1024 |
|
96 |
+}; |
|
97 |
+ |
|
98 |
+static const uint16_t swb_offset_1024_24[] = { |
|
99 |
+ 0, 4, 8, 12, 16, 20, 24, 28, |
|
100 |
+ 32, 36, 40, 44, 52, 60, 68, 76, |
|
101 |
+ 84, 92, 100, 108, 116, 124, 136, 148, |
|
102 |
+ 160, 172, 188, 204, 220, 240, 260, 284, |
|
103 |
+ 308, 336, 364, 396, 432, 468, 508, 552, |
|
104 |
+ 600, 652, 704, 768, 832, 896, 960, 1024 |
|
105 |
+}; |
|
106 |
+ |
|
107 |
+static const uint16_t swb_offset_128_24[] = { |
|
108 |
+ 0, 4, 8, 12, 16, 20, 24, 28, |
|
109 |
+ 36, 44, 52, 64, 76, 92, 108, 128 |
|
110 |
+}; |
|
111 |
+ |
|
112 |
+static const uint16_t swb_offset_1024_16[] = { |
|
113 |
+ 0, 8, 16, 24, 32, 40, 48, 56, |
|
114 |
+ 64, 72, 80, 88, 100, 112, 124, 136, |
|
115 |
+ 148, 160, 172, 184, 196, 212, 228, 244, |
|
116 |
+ 260, 280, 300, 320, 344, 368, 396, 424, |
|
117 |
+ 456, 492, 532, 572, 616, 664, 716, 772, |
|
118 |
+ 832, 896, 960, 1024 |
|
119 |
+}; |
|
120 |
+ |
|
121 |
+static const uint16_t swb_offset_128_16[] = { |
|
122 |
+ 0, 4, 8, 12, 16, 20, 24, 28, |
|
123 |
+ 32, 40, 48, 60, 72, 88, 108, 128 |
|
124 |
+}; |
|
125 |
+ |
|
126 |
+static const uint16_t swb_offset_1024_8[] = { |
|
127 |
+ 0, 12, 24, 36, 48, 60, 72, 84, |
|
128 |
+ 96, 108, 120, 132, 144, 156, 172, 188, |
|
129 |
+ 204, 220, 236, 252, 268, 288, 308, 328, |
|
130 |
+ 348, 372, 396, 420, 448, 476, 508, 544, |
|
131 |
+ 580, 620, 664, 712, 764, 820, 880, 944, |
|
132 |
+ 1024 |
|
133 |
+}; |
|
134 |
+ |
|
135 |
+static const uint16_t swb_offset_128_8[] = { |
|
136 |
+ 0, 4, 8, 12, 16, 20, 24, 28, |
|
137 |
+ 36, 44, 52, 60, 72, 88, 108, 128 |
|
138 |
+}; |
|
139 |
+ |
|
140 |
+static const uint16_t *swb_offset_1024[] = { |
|
141 |
+ swb_offset_1024_96, swb_offset_1024_96, swb_offset_1024_64, |
|
142 |
+ swb_offset_1024_48, swb_offset_1024_48, swb_offset_1024_32, |
|
143 |
+ swb_offset_1024_24, swb_offset_1024_24, swb_offset_1024_16, |
|
144 |
+ swb_offset_1024_16, swb_offset_1024_16, swb_offset_1024_8 |
|
145 |
+}; |
|
146 |
+ |
|
147 |
+static const uint16_t *swb_offset_128[] = { |
|
148 |
+ /* The last entry on the following row is swb_offset_128_64 but is a |
|
149 |
+ duplicate of swb_offset_128_96. */ |
|
150 |
+ swb_offset_128_96, swb_offset_128_96, swb_offset_128_96, |
|
151 |
+ swb_offset_128_48, swb_offset_128_48, swb_offset_128_48, |
|
152 |
+ swb_offset_128_24, swb_offset_128_24, swb_offset_128_16, |
|
153 |
+ swb_offset_128_16, swb_offset_128_16, swb_offset_128_8 |
|
154 |
+}; |
|
155 |
+ |
|
156 |
+// @} |
|
157 |
+ |
|
158 |
+#endif /* FFMPEG_AACDECTAB_H */ |
... | ... |
@@ -27,6 +27,7 @@ |
27 | 27 |
* @author Maxim Gavrilov ( maxim.gavrilov gmail com ) |
28 | 28 |
*/ |
29 | 29 |
|
30 |
+#include "libavutil/mem.h" |
|
30 | 31 |
#include "aac.h" |
31 | 32 |
|
32 | 33 |
#include <stdint.h> |
... | ... |
@@ -795,4 +796,86 @@ const float ff_aac_ivquant_tab[IVQUANT_SIZE] = { |
795 | 795 |
4064.0312908, 4074.6805676, 4085.3368071, 4096.0000000, |
796 | 796 |
}; |
797 | 797 |
|
798 |
+const float ff_aac_pow2sf_tab[316] = { |
|
799 |
+ 8.88178420e-16, 1.05622810e-15, 1.25607397e-15, 1.49373210e-15, |
|
800 |
+ 1.77635684e-15, 2.11245619e-15, 2.51214793e-15, 2.98746420e-15, |
|
801 |
+ 3.55271368e-15, 4.22491238e-15, 5.02429587e-15, 5.97492839e-15, |
|
802 |
+ 7.10542736e-15, 8.44982477e-15, 1.00485917e-14, 1.19498568e-14, |
|
803 |
+ 1.42108547e-14, 1.68996495e-14, 2.00971835e-14, 2.38997136e-14, |
|
804 |
+ 2.84217094e-14, 3.37992991e-14, 4.01943669e-14, 4.77994272e-14, |
|
805 |
+ 5.68434189e-14, 6.75985982e-14, 8.03887339e-14, 9.55988543e-14, |
|
806 |
+ 1.13686838e-13, 1.35197196e-13, 1.60777468e-13, 1.91197709e-13, |
|
807 |
+ 2.27373675e-13, 2.70394393e-13, 3.21554936e-13, 3.82395417e-13, |
|
808 |
+ 4.54747351e-13, 5.40788785e-13, 6.43109871e-13, 7.64790834e-13, |
|
809 |
+ 9.09494702e-13, 1.08157757e-12, 1.28621974e-12, 1.52958167e-12, |
|
810 |
+ 1.81898940e-12, 2.16315514e-12, 2.57243948e-12, 3.05916334e-12, |
|
811 |
+ 3.63797881e-12, 4.32631028e-12, 5.14487897e-12, 6.11832668e-12, |
|
812 |
+ 7.27595761e-12, 8.65262056e-12, 1.02897579e-11, 1.22366534e-11, |
|
813 |
+ 1.45519152e-11, 1.73052411e-11, 2.05795159e-11, 2.44733067e-11, |
|
814 |
+ 2.91038305e-11, 3.46104823e-11, 4.11590317e-11, 4.89466134e-11, |
|
815 |
+ 5.82076609e-11, 6.92209645e-11, 8.23180635e-11, 9.78932268e-11, |
|
816 |
+ 1.16415322e-10, 1.38441929e-10, 1.64636127e-10, 1.95786454e-10, |
|
817 |
+ 2.32830644e-10, 2.76883858e-10, 3.29272254e-10, 3.91572907e-10, |
|
818 |
+ 4.65661287e-10, 5.53767716e-10, 6.58544508e-10, 7.83145814e-10, |
|
819 |
+ 9.31322575e-10, 1.10753543e-09, 1.31708902e-09, 1.56629163e-09, |
|
820 |
+ 1.86264515e-09, 2.21507086e-09, 2.63417803e-09, 3.13258326e-09, |
|
821 |
+ 3.72529030e-09, 4.43014173e-09, 5.26835606e-09, 6.26516652e-09, |
|
822 |
+ 7.45058060e-09, 8.86028346e-09, 1.05367121e-08, 1.25303330e-08, |
|
823 |
+ 1.49011612e-08, 1.77205669e-08, 2.10734243e-08, 2.50606661e-08, |
|
824 |
+ 2.98023224e-08, 3.54411338e-08, 4.21468485e-08, 5.01213321e-08, |
|
825 |
+ 5.96046448e-08, 7.08822677e-08, 8.42936970e-08, 1.00242664e-07, |
|
826 |
+ 1.19209290e-07, 1.41764535e-07, 1.68587394e-07, 2.00485328e-07, |
|
827 |
+ 2.38418579e-07, 2.83529071e-07, 3.37174788e-07, 4.00970657e-07, |
|
828 |
+ 4.76837158e-07, 5.67058141e-07, 6.74349576e-07, 8.01941314e-07, |
|
829 |
+ 9.53674316e-07, 1.13411628e-06, 1.34869915e-06, 1.60388263e-06, |
|
830 |
+ 1.90734863e-06, 2.26823256e-06, 2.69739830e-06, 3.20776526e-06, |
|
831 |
+ 3.81469727e-06, 4.53646513e-06, 5.39479661e-06, 6.41553051e-06, |
|
832 |
+ 7.62939453e-06, 9.07293026e-06, 1.07895932e-05, 1.28310610e-05, |
|
833 |
+ 1.52587891e-05, 1.81458605e-05, 2.15791864e-05, 2.56621220e-05, |
|
834 |
+ 3.05175781e-05, 3.62917210e-05, 4.31583729e-05, 5.13242441e-05, |
|
835 |
+ 6.10351562e-05, 7.25834421e-05, 8.63167458e-05, 1.02648488e-04, |
|
836 |
+ 1.22070312e-04, 1.45166884e-04, 1.72633492e-04, 2.05296976e-04, |
|
837 |
+ 2.44140625e-04, 2.90333768e-04, 3.45266983e-04, 4.10593953e-04, |
|
838 |
+ 4.88281250e-04, 5.80667537e-04, 6.90533966e-04, 8.21187906e-04, |
|
839 |
+ 9.76562500e-04, 1.16133507e-03, 1.38106793e-03, 1.64237581e-03, |
|
840 |
+ 1.95312500e-03, 2.32267015e-03, 2.76213586e-03, 3.28475162e-03, |
|
841 |
+ 3.90625000e-03, 4.64534029e-03, 5.52427173e-03, 6.56950324e-03, |
|
842 |
+ 7.81250000e-03, 9.29068059e-03, 1.10485435e-02, 1.31390065e-02, |
|
843 |
+ 1.56250000e-02, 1.85813612e-02, 2.20970869e-02, 2.62780130e-02, |
|
844 |
+ 3.12500000e-02, 3.71627223e-02, 4.41941738e-02, 5.25560260e-02, |
|
845 |
+ 6.25000000e-02, 7.43254447e-02, 8.83883476e-02, 1.05112052e-01, |
|
846 |
+ 1.25000000e-01, 1.48650889e-01, 1.76776695e-01, 2.10224104e-01, |
|
847 |
+ 2.50000000e-01, 2.97301779e-01, 3.53553391e-01, 4.20448208e-01, |
|
848 |
+ 5.00000000e-01, 5.94603558e-01, 7.07106781e-01, 8.40896415e-01, |
|
849 |
+ 1.00000000e+00, 1.18920712e+00, 1.41421356e+00, 1.68179283e+00, |
|
850 |
+ 2.00000000e+00, 2.37841423e+00, 2.82842712e+00, 3.36358566e+00, |
|
851 |
+ 4.00000000e+00, 4.75682846e+00, 5.65685425e+00, 6.72717132e+00, |
|
852 |
+ 8.00000000e+00, 9.51365692e+00, 1.13137085e+01, 1.34543426e+01, |
|
853 |
+ 1.60000000e+01, 1.90273138e+01, 2.26274170e+01, 2.69086853e+01, |
|
854 |
+ 3.20000000e+01, 3.80546277e+01, 4.52548340e+01, 5.38173706e+01, |
|
855 |
+ 6.40000000e+01, 7.61092554e+01, 9.05096680e+01, 1.07634741e+02, |
|
856 |
+ 1.28000000e+02, 1.52218511e+02, 1.81019336e+02, 2.15269482e+02, |
|
857 |
+ 2.56000000e+02, 3.04437021e+02, 3.62038672e+02, 4.30538965e+02, |
|
858 |
+ 5.12000000e+02, 6.08874043e+02, 7.24077344e+02, 8.61077929e+02, |
|
859 |
+ 1.02400000e+03, 1.21774809e+03, 1.44815469e+03, 1.72215586e+03, |
|
860 |
+ 2.04800000e+03, 2.43549617e+03, 2.89630938e+03, 3.44431172e+03, |
|
861 |
+ 4.09600000e+03, 4.87099234e+03, 5.79261875e+03, 6.88862343e+03, |
|
862 |
+ 8.19200000e+03, 9.74198469e+03, 1.15852375e+04, 1.37772469e+04, |
|
863 |
+ 1.63840000e+04, 1.94839694e+04, 2.31704750e+04, 2.75544937e+04, |
|
864 |
+ 3.27680000e+04, 3.89679387e+04, 4.63409500e+04, 5.51089875e+04, |
|
865 |
+ 6.55360000e+04, 7.79358775e+04, 9.26819000e+04, 1.10217975e+05, |
|
866 |
+ 1.31072000e+05, 1.55871755e+05, 1.85363800e+05, 2.20435950e+05, |
|
867 |
+ 2.62144000e+05, 3.11743510e+05, 3.70727600e+05, 4.40871900e+05, |
|
868 |
+ 5.24288000e+05, 6.23487020e+05, 7.41455200e+05, 8.81743800e+05, |
|
869 |
+ 1.04857600e+06, 1.24697404e+06, 1.48291040e+06, 1.76348760e+06, |
|
870 |
+ 2.09715200e+06, 2.49394808e+06, 2.96582080e+06, 3.52697520e+06, |
|
871 |
+ 4.19430400e+06, 4.98789616e+06, 5.93164160e+06, 7.05395040e+06, |
|
872 |
+ 8.38860800e+06, 9.97579232e+06, 1.18632832e+07, 1.41079008e+07, |
|
873 |
+ 1.67772160e+07, 1.99515846e+07, 2.37265664e+07, 2.82158016e+07, |
|
874 |
+ 3.35544320e+07, 3.99031693e+07, 4.74531328e+07, 5.64316032e+07, |
|
875 |
+ 6.71088640e+07, 7.98063385e+07, 9.49062656e+07, 1.12863206e+08, |
|
876 |
+ 1.34217728e+08, 1.59612677e+08, 1.89812531e+08, 2.25726413e+08, |
|
877 |
+ 2.68435456e+08, 3.19225354e+08, 3.79625062e+08, 4.51452825e+08, |
|
878 |
+}; |
|
879 |
+ |
|
798 | 880 |
#endif /* CONFIG_HARDCODED_TABLES */ |
... | ... |
@@ -30,6 +30,7 @@ |
30 | 30 |
#ifndef FFMPEG_AACTAB_H |
31 | 31 |
#define FFMPEG_AACTAB_H |
32 | 32 |
|
33 |
+#include "libavutil/mem.h" |
|
33 | 34 |
#include "aac.h" |
34 | 35 |
|
35 | 36 |
#include <stdint.h> |
... | ... |
@@ -45,6 +46,7 @@ extern const int8_t *ff_aac_codebook_vectors[]; |
45 | 45 |
|
46 | 46 |
#ifdef CONFIG_HARDCODED_TABLES |
47 | 47 |
extern const float ff_aac_ivquant_tab[IVQUANT_SIZE]; |
48 |
+extern const float ff_aac_pow2sf_tab[316]; |
|
48 | 49 |
#endif /* CONFIG_HARDCODED_TABLES */ |
49 | 50 |
|
50 | 51 |
#endif /* FFMPEG_AACTAB_H */ |