| OLD | NEW |
| 1 /* | 1 /* |
| 2 * AAC encoder | 2 * AAC encoder |
| 3 * Copyright (C) 2008 Konstantin Shishkov | 3 * Copyright (C) 2008 Konstantin Shishkov |
| 4 * | 4 * |
| 5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
| 6 * | 6 * |
| 7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 for (i = 0; i < cpe->ch[0].ics.max_sfb; i++) | 295 for (i = 0; i < cpe->ch[0].ics.max_sfb; i++) |
| 296 put_bits(pb, 1, cpe->ms_mask[w*16 + i]); | 296 put_bits(pb, 1, cpe->ms_mask[w*16 + i]); |
| 297 } | 297 } |
| 298 | 298 |
| 299 /** | 299 /** |
| 300 * Produce integer coefficients from scalefactors provided by the model. | 300 * Produce integer coefficients from scalefactors provided by the model. |
| 301 */ | 301 */ |
| 302 static void adjust_frame_information(AACEncContext *apc, ChannelElement *cpe, in
t chans) | 302 static void adjust_frame_information(AACEncContext *apc, ChannelElement *cpe, in
t chans) |
| 303 { | 303 { |
| 304 int i, w, w2, g, ch; | 304 int i, w, w2, g, ch; |
| 305 int start, sum, maxsfb, cmaxsfb; | 305 int start, maxsfb, cmaxsfb; |
| 306 | 306 |
| 307 for (ch = 0; ch < chans; ch++) { | 307 for (ch = 0; ch < chans; ch++) { |
| 308 IndividualChannelStream *ics = &cpe->ch[ch].ics; | 308 IndividualChannelStream *ics = &cpe->ch[ch].ics; |
| 309 start = 0; | 309 start = 0; |
| 310 maxsfb = 0; | 310 maxsfb = 0; |
| 311 cpe->ch[ch].pulse.num_pulse = 0; | 311 cpe->ch[ch].pulse.num_pulse = 0; |
| 312 for (w = 0; w < ics->num_windows*16; w += 16) { | 312 for (w = 0; w < ics->num_windows*16; w += 16) { |
| 313 for (g = 0; g < ics->num_swb; g++) { | 313 for (g = 0; g < ics->num_swb; g++) { |
| 314 sum = 0; | |
| 315 //apply M/S | 314 //apply M/S |
| 316 if (!ch && cpe->ms_mask[w + g]) { | 315 if (cpe->common_window && !ch && cpe->ms_mask[w + g]) { |
| 317 for (i = 0; i < ics->swb_sizes[g]; i++) { | 316 for (i = 0; i < ics->swb_sizes[g]; i++) { |
| 318 cpe->ch[0].coeffs[start+i] = (cpe->ch[0].coeffs[start+i]
+ cpe->ch[1].coeffs[start+i]) / 2.0; | 317 cpe->ch[0].coeffs[start+i] = (cpe->ch[0].coeffs[start+i]
+ cpe->ch[1].coeffs[start+i]) / 2.0; |
| 319 cpe->ch[1].coeffs[start+i] = cpe->ch[0].coeffs[start+i]
- cpe->ch[1].coeffs[start+i]; | 318 cpe->ch[1].coeffs[start+i] = cpe->ch[0].coeffs[start+i]
- cpe->ch[1].coeffs[start+i]; |
| 320 } | 319 } |
| 321 } | 320 } |
| 322 start += ics->swb_sizes[g]; | 321 start += ics->swb_sizes[g]; |
| 323 } | 322 } |
| 324 for (cmaxsfb = ics->num_swb; cmaxsfb > 0 && cpe->ch[ch].zeroes[w+cma
xsfb-1]; cmaxsfb--) | 323 for (cmaxsfb = ics->num_swb; cmaxsfb > 0 && cpe->ch[ch].zeroes[w+cma
xsfb-1]; cmaxsfb--) |
| 325 ; | 324 ; |
| 326 maxsfb = FFMAX(maxsfb, cmaxsfb); | 325 maxsfb = FFMAX(maxsfb, cmaxsfb); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 ics->window_sequence[1] = ics->window_sequence[0]; | 536 ics->window_sequence[1] = ics->window_sequence[0]; |
| 538 ics->window_sequence[0] = wi[j].window_type[0]; | 537 ics->window_sequence[0] = wi[j].window_type[0]; |
| 539 ics->use_kb_window[1] = ics->use_kb_window[0]; | 538 ics->use_kb_window[1] = ics->use_kb_window[0]; |
| 540 ics->use_kb_window[0] = wi[j].window_shape; | 539 ics->use_kb_window[0] = wi[j].window_shape; |
| 541 ics->num_windows = wi[j].num_windows; | 540 ics->num_windows = wi[j].num_windows; |
| 542 ics->swb_sizes = s->psy.bands [ics->num_windows == 8]; | 541 ics->swb_sizes = s->psy.bands [ics->num_windows == 8]; |
| 543 ics->num_swb = tag == TYPE_LFE ? 12 : s->psy.num_bands[ic
s->num_windows == 8]; | 542 ics->num_swb = tag == TYPE_LFE ? 12 : s->psy.num_bands[ic
s->num_windows == 8]; |
| 544 for (k = 0; k < ics->num_windows; k++) | 543 for (k = 0; k < ics->num_windows; k++) |
| 545 ics->group_len[k] = wi[j].grouping[k]; | 544 ics->group_len[k] = wi[j].grouping[k]; |
| 546 | 545 |
| 547 s->cur_channel = cur_channel; | |
| 548 apply_window_and_mdct(avctx, s, &cpe->ch[j], samples2); | 546 apply_window_and_mdct(avctx, s, &cpe->ch[j], samples2); |
| 549 } | 547 } |
| 550 start_ch += chans; | 548 start_ch += chans; |
| 551 } | 549 } |
| 552 do { | 550 do { |
| 553 int frame_bits; | 551 int frame_bits; |
| 554 init_put_bits(&s->pb, frame, buf_size*8); | 552 init_put_bits(&s->pb, frame, buf_size*8); |
| 555 if ((avctx->frame_number & 0xFF)==1 && !(avctx->flags & CODEC_FLAG_BITEX
ACT)) | 553 if ((avctx->frame_number & 0xFF)==1 && !(avctx->flags & CODEC_FLAG_BITEX
ACT)) |
| 556 put_bitstream_info(avctx, s, LIBAVCODEC_IDENT); | 554 put_bitstream_info(avctx, s, LIBAVCODEC_IDENT); |
| 557 start_ch = 0; | 555 start_ch = 0; |
| 558 memset(chan_el_counter, 0, sizeof(chan_el_counter)); | 556 memset(chan_el_counter, 0, sizeof(chan_el_counter)); |
| 559 for (i = 0; i < chan_map[0]; i++) { | 557 for (i = 0; i < chan_map[0]; i++) { |
| 560 FFPsyWindowInfo* wi = windows + start_ch; | 558 FFPsyWindowInfo* wi = windows + start_ch; |
| 561 tag = chan_map[i+1]; | 559 tag = chan_map[i+1]; |
| 562 chans = tag == TYPE_CPE ? 2 : 1; | 560 chans = tag == TYPE_CPE ? 2 : 1; |
| 563 cpe = &s->cpe[i]; | 561 cpe = &s->cpe[i]; |
| 562 put_bits(&s->pb, 3, tag); |
| 563 put_bits(&s->pb, 4, chan_el_counter[tag]++); |
| 564 for (j = 0; j < chans; j++) { | 564 for (j = 0; j < chans; j++) { |
| 565 s->cur_channel = start_ch + j; | 565 s->cur_channel = start_ch + j; |
| 566 ff_psy_set_band_info(&s->psy, s->cur_channel, cpe->ch[j].coeffs,
&wi[j]); | 566 ff_psy_set_band_info(&s->psy, s->cur_channel, cpe->ch[j].coeffs,
&wi[j]); |
| 567 s->coder->search_for_quantizers(avctx, s, &cpe->ch[j], s->lambda
); | 567 s->coder->search_for_quantizers(avctx, s, &cpe->ch[j], s->lambda
); |
| 568 } | 568 } |
| 569 cpe->common_window = 0; | 569 cpe->common_window = 0; |
| 570 if (chans > 1 | 570 if (chans > 1 |
| 571 && wi[0].window_type[0] == wi[1].window_type[0] | 571 && wi[0].window_type[0] == wi[1].window_type[0] |
| 572 && wi[0].window_shape == wi[1].window_shape) { | 572 && wi[0].window_shape == wi[1].window_shape) { |
| 573 | 573 |
| 574 cpe->common_window = 1; | 574 cpe->common_window = 1; |
| 575 for (j = 0; j < wi[0].num_windows; j++) { | 575 for (j = 0; j < wi[0].num_windows; j++) { |
| 576 if (wi[0].grouping[j] != wi[1].grouping[j]) { | 576 if (wi[0].grouping[j] != wi[1].grouping[j]) { |
| 577 cpe->common_window = 0; | 577 cpe->common_window = 0; |
| 578 break; | 578 break; |
| 579 } | 579 } |
| 580 } | 580 } |
| 581 } | 581 } |
| 582 s->cur_channel = start_ch; | 582 s->cur_channel = start_ch; |
| 583 if (cpe->common_window && s->coder->search_for_ms) | 583 if (cpe->common_window && s->coder->search_for_ms) |
| 584 s->coder->search_for_ms(s, cpe, s->lambda); | 584 s->coder->search_for_ms(s, cpe, s->lambda); |
| 585 adjust_frame_information(s, cpe, chans); | 585 adjust_frame_information(s, cpe, chans); |
| 586 put_bits(&s->pb, 3, tag); | |
| 587 put_bits(&s->pb, 4, chan_el_counter[tag]++); | |
| 588 if (chans == 2) { | 586 if (chans == 2) { |
| 589 put_bits(&s->pb, 1, cpe->common_window); | 587 put_bits(&s->pb, 1, cpe->common_window); |
| 590 if (cpe->common_window) { | 588 if (cpe->common_window) { |
| 591 put_ics_info(s, &cpe->ch[0].ics); | 589 put_ics_info(s, &cpe->ch[0].ics); |
| 592 encode_ms_info(&s->pb, cpe); | 590 encode_ms_info(&s->pb, cpe); |
| 593 } | 591 } |
| 594 } | 592 } |
| 595 for (j = 0; j < chans; j++) { | 593 for (j = 0; j < chans; j++) { |
| 596 s->cur_channel = start_ch + j; | 594 s->cur_channel = start_ch + j; |
| 597 encode_individual_channel(avctx, s, &cpe->ch[j], cpe->common_win
dow); | 595 encode_individual_channel(avctx, s, &cpe->ch[j], cpe->common_win
dow); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 AVMEDIA_TYPE_AUDIO, | 641 AVMEDIA_TYPE_AUDIO, |
| 644 CODEC_ID_AAC, | 642 CODEC_ID_AAC, |
| 645 sizeof(AACEncContext), | 643 sizeof(AACEncContext), |
| 646 aac_encode_init, | 644 aac_encode_init, |
| 647 aac_encode_frame, | 645 aac_encode_frame, |
| 648 aac_encode_end, | 646 aac_encode_end, |
| 649 .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_EXP
ERIMENTAL, | 647 .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_EXP
ERIMENTAL, |
| 650 .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, | 648 .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, |
| 651 .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), | 649 .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), |
| 652 }; | 650 }; |
| OLD | NEW |