comparison aacenc.c @ 7605:681e7430fbeb libavcodec

Add okayed parts for AAC encoder
author kostya
date Mon, 18 Aug 2008 05:38:26 +0000
parents ab454e7f1c35
children 1c01b74dc78c
comparison
equal deleted inserted replaced
7604:6250ff63990b 7605:681e7430fbeb
160 typedef struct { 160 typedef struct {
161 PutBitContext pb; 161 PutBitContext pb;
162 MDCTContext mdct1024; ///< long (1024 samples) frame transform context 162 MDCTContext mdct1024; ///< long (1024 samples) frame transform context
163 MDCTContext mdct128; ///< short (128 samples) frame transform context 163 MDCTContext mdct128; ///< short (128 samples) frame transform context
164 DSPContext dsp; 164 DSPContext dsp;
165 DECLARE_ALIGNED_16(FFTSample, output[2048]); ///< temporary buffer for MDCT input coefficients
166 int16_t* samples; ///< saved preprocessed input
167
168 int samplerate_index; ///< MPEG-4 samplerate index
169
170 ChannelElement *cpe; ///< channel elements
165 AACPsyContext psy; ///< psychoacoustic model context 171 AACPsyContext psy; ///< psychoacoustic model context
166 int last_frame; 172 int last_frame;
167 } AACEncContext; 173 } AACEncContext;
168 174
169 /** 175 /**
219 ff_sine_window_init(ff_sine_1024, 1024); 225 ff_sine_window_init(ff_sine_1024, 1024);
220 ff_sine_window_init(ff_sine_128, 128); 226 ff_sine_window_init(ff_sine_128, 128);
221 227
222 s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0])); 228 s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0]));
223 s->cpe = av_mallocz(sizeof(ChannelElement) * aac_chan_configs[avctx->channels-1][0]); 229 s->cpe = av_mallocz(sizeof(ChannelElement) * aac_chan_configs[avctx->channels-1][0]);
224 if(ff_aac_psy_init(&s->psy, avctx, AAC_PSY_3GPP, aac_chan_configs[avctx->channels-1][0], 0, s->swb_sizes1024, s->swb_num1024, s->swb_sizes128, s->swb_num128) < 0){ 230 if(ff_aac_psy_init(&s->psy, avctx, AAC_PSY_3GPP,
231 aac_chan_configs[avctx->channels-1][0], 0,
232 s->swb_sizes1024, s->swb_num1024, s->swb_sizes128, s->swb_num128) < 0){
225 av_log(avctx, AV_LOG_ERROR, "Cannot initialize selected model.\n"); 233 av_log(avctx, AV_LOG_ERROR, "Cannot initialize selected model.\n");
226 return -1; 234 return -1;
227 } 235 }
228 avctx->extradata = av_malloc(2); 236 avctx->extradata = av_malloc(2);
229 avctx->extradata_size = 2; 237 avctx->extradata_size = 2;
254 } 262 }
255 263
256 /** 264 /**
257 * Encode pulse data. 265 * Encode pulse data.
258 */ 266 */
259 static void encode_pulses(AVCodecContext *avctx, AACEncContext *s, Pulse *pulse, int channel) 267 static void encode_pulses(AACEncContext *s, Pulse *pulse, int channel)
260 { 268 {
261 int i; 269 int i;
262 270
263 put_bits(&s->pb, 1, !!pulse->num_pulse); 271 put_bits(&s->pb, 1, !!pulse->num_pulse);
264 if(!pulse->num_pulse) return; 272 if(!pulse->num_pulse) return;
272 } 280 }
273 281
274 /** 282 /**
275 * Encode spectral coefficients processed by psychoacoustic model. 283 * Encode spectral coefficients processed by psychoacoustic model.
276 */ 284 */
277 static void encode_spectral_coeffs(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, int channel) 285 static void encode_spectral_coeffs(AACEncContext *s, ChannelElement *cpe, int channel)
278 { 286 {
279 int start, i, w, w2, wg; 287 int start, i, w, w2, wg;
280 288
281 w = 0; 289 w = 0;
282 for(wg = 0; wg < cpe->ch[channel].ics.num_window_groups; wg++){ 290 for(wg = 0; wg < cpe->ch[channel].ics.num_window_groups; wg++){
285 if(cpe->ch[channel].zeroes[w*16 + i]){ 293 if(cpe->ch[channel].zeroes[w*16 + i]){
286 start += cpe->ch[channel].ics.swb_sizes[i]; 294 start += cpe->ch[channel].ics.swb_sizes[i];
287 continue; 295 continue;
288 } 296 }
289 for(w2 = w; w2 < w + cpe->ch[channel].ics.group_len[wg]; w2++){ 297 for(w2 = w; w2 < w + cpe->ch[channel].ics.group_len[wg]; w2++){
290 encode_band_coeffs(s, cpe, channel, start + w2*128, cpe->ch[channel].ics.swb_sizes[i], cpe->ch[channel].band_type[w*16 + i]); 298 encode_band_coeffs(s, cpe, channel, start + w2*128,
299 cpe->ch[channel].ics.swb_sizes[i],
300 cpe->ch[channel].band_type[w*16 + i]);
291 } 301 }
292 start += cpe->ch[channel].ics.swb_sizes[i]; 302 start += cpe->ch[channel].ics.swb_sizes[i];
293 } 303 }
294 w += cpe->ch[channel].ics.group_len[wg]; 304 w += cpe->ch[channel].ics.group_len[wg];
295 } 305 }