comparison aac.c @ 7540:5298e05f931d libavcodec

Synchronise code with AAC decoder in SoC
author superdump
date Mon, 11 Aug 2008 11:22:48 +0000
parents 4fca7939ad48
children a05954c505ab
comparison
equal deleted inserted replaced
7539:4fca7939ad48 7540:5298e05f931d
434 } 434 }
435 435
436 /** 436 /**
437 * Decode scalefactors; reference: table 4.47. 437 * Decode scalefactors; reference: table 4.47.
438 * 438 *
439 * @param mix_gain channel gain (Not used by AAC bitstream.)
440 * @param global_gain first scalefactor value as scalefactors are differentially coded 439 * @param global_gain first scalefactor value as scalefactors are differentially coded
441 * @param band_type array of the used band type 440 * @param band_type array of the used band type
442 * @param band_type_run_end array of the last scalefactor band of a band type run 441 * @param band_type_run_end array of the last scalefactor band of a band type run
443 * @param sf array of scalefactors or intensity stereo positions 442 * @param sf array of scalefactors or intensity stereo positions
444 * 443 *
445 * @return Returns error status. 0 - OK, !0 - error 444 * @return Returns error status. 0 - OK, !0 - error
446 */ 445 */
447 static int decode_scalefactors(AACContext * ac, float sf[120], GetBitContext * gb, 446 static int decode_scalefactors(AACContext * ac, float sf[120], GetBitContext * gb,
448 float mix_gain, unsigned int global_gain, IndividualChannelStream * ics, 447 unsigned int global_gain, IndividualChannelStream * ics,
449 enum BandType band_type[120], int band_type_run_end[120]) { 448 enum BandType band_type[120], int band_type_run_end[120]) {
450 const int sf_offset = ac->sf_offset + (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ? 12 : 0); 449 const int sf_offset = ac->sf_offset + (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ? 12 : 0);
451 int g, i, idx = 0; 450 int g, i, idx = 0;
452 int offset[3] = { global_gain, global_gain - 90, 100 }; 451 int offset[3] = { global_gain, global_gain - 90, 100 };
453 int noise_flag = 1; 452 int noise_flag = 1;
467 av_log(ac->avccontext, AV_LOG_ERROR, 466 av_log(ac->avccontext, AV_LOG_ERROR,
468 "%s (%d) out of range.\n", sf_str[2], offset[2]); 467 "%s (%d) out of range.\n", sf_str[2], offset[2]);
469 return -1; 468 return -1;
470 } 469 }
471 sf[idx] = ff_aac_pow2sf_tab[-offset[2] + 300]; 470 sf[idx] = ff_aac_pow2sf_tab[-offset[2] + 300];
472 sf[idx] *= mix_gain;
473 } 471 }
474 }else if(band_type[idx] == NOISE_BT) { 472 }else if(band_type[idx] == NOISE_BT) {
475 for(; i < run_end; i++, idx++) { 473 for(; i < run_end; i++, idx++) {
476 if(noise_flag-- > 0) 474 if(noise_flag-- > 0)
477 offset[1] += get_bits(gb, 9) - 256; 475 offset[1] += get_bits(gb, 9) - 256;
481 av_log(ac->avccontext, AV_LOG_ERROR, 479 av_log(ac->avccontext, AV_LOG_ERROR,
482 "%s (%d) out of range.\n", sf_str[1], offset[1]); 480 "%s (%d) out of range.\n", sf_str[1], offset[1]);
483 return -1; 481 return -1;
484 } 482 }
485 sf[idx] = -ff_aac_pow2sf_tab[ offset[1] + sf_offset]; 483 sf[idx] = -ff_aac_pow2sf_tab[ offset[1] + sf_offset];
486 sf[idx] *= mix_gain;
487 } 484 }
488 }else { 485 }else {
489 for(; i < run_end; i++, idx++) { 486 for(; i < run_end; i++, idx++) {
490 offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; 487 offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
491 if(offset[0] > 255U) { 488 if(offset[0] > 255U) {
492 av_log(ac->avccontext, AV_LOG_ERROR, 489 av_log(ac->avccontext, AV_LOG_ERROR,
493 "%s (%d) out of range.\n", sf_str[0], offset[0]); 490 "%s (%d) out of range.\n", sf_str[0], offset[0]);
494 return -1; 491 return -1;
495 } 492 }
496 sf[idx] = -ff_aac_pow2sf_tab[ offset[0] + sf_offset]; 493 sf[idx] = -ff_aac_pow2sf_tab[ offset[0] + sf_offset];
497 sf[idx] *= mix_gain;
498 } 494 }
499 } 495 }
500 } 496 }
501 } 497 }
502 return 0; 498 return 0;
647 * 643 *
648 * @return Returns number of bytes consumed from the TYPE_FIL element. 644 * @return Returns number of bytes consumed from the TYPE_FIL element.
649 */ 645 */
650 static int decode_sbr_extension(AACContext * ac, GetBitContext * gb, int crc, int cnt) { 646 static int decode_sbr_extension(AACContext * ac, GetBitContext * gb, int crc, int cnt) {
651 // TODO : sbr_extension implementation 647 // TODO : sbr_extension implementation
652 av_log(ac->avccontext, AV_LOG_DEBUG, "aac: SBR not yet supported.\n"); 648 av_log_missing_feature(ac->avccontext, "SBR", 0);
653 skip_bits_long(gb, 8*cnt - 4); // -4 due to reading extension type 649 skip_bits_long(gb, 8*cnt - 4); // -4 due to reading extension type
654 return cnt; 650 return cnt;
655 } 651 }
656 652
657 /** 653 /**
767 return; 763 return;
768 } 764 }
769 for (g = 0; g < ics->num_window_groups; g++) { 765 for (g = 0; g < ics->num_window_groups; g++) {
770 for (i = 0; i < ics->max_sfb; i++, idx++) { 766 for (i = 0; i < ics->max_sfb; i++, idx++) {
771 if (cc->ch[0].band_type[idx] != ZERO_BT) { 767 if (cc->ch[0].band_type[idx] != ZERO_BT) {
772 float gain = cc->coup.gain[index][idx] * sce->mixing_gain;
773 for (group = 0; group < ics->group_len[g]; group++) { 768 for (group = 0; group < ics->group_len[g]; group++) {
774 for (k = offsets[i]; k < offsets[i+1]; k++) { 769 for (k = offsets[i]; k < offsets[i+1]; k++) {
775 // XXX dsputil-ize 770 // XXX dsputil-ize
776 dest[group*128+k] += gain * src[group*128+k]; 771 dest[group*128+k] += cc->coup.gain[index][idx] * src[group*128+k];
777 } 772 }
778 } 773 }
779 } 774 }
780 } 775 }
781 dest += ics->group_len[g]*128; 776 dest += ics->group_len[g]*128;
788 * 783 *
789 * @param index index into coupling gain array 784 * @param index index into coupling gain array
790 */ 785 */
791 static void apply_independent_coupling(AACContext * ac, SingleChannelElement * sce, ChannelElement * cc, int index) { 786 static void apply_independent_coupling(AACContext * ac, SingleChannelElement * sce, ChannelElement * cc, int index) {
792 int i; 787 int i;
793 float gain = cc->coup.gain[index][0] * sce->mixing_gain;
794 for (i = 0; i < 1024; i++) 788 for (i = 0; i < 1024; i++)
795 sce->ret[i] += gain * (cc->ch[0].ret[i] - ac->add_bias); 789 sce->ret[i] += cc->coup.gain[index][0] * (cc->ch[0].ret[i] - ac->add_bias);
796 } 790 }
797 791
798 if (!ac->is_saved) { 792 if (!ac->is_saved) {
799 ac->is_saved = 1; 793 ac->is_saved = 1;
800 *data_size = 0; 794 *data_size = 0;
815 return buf_size; 809 return buf_size;
816 } 810 }
817 811
818 static av_cold int aac_decode_close(AVCodecContext * avccontext) { 812 static av_cold int aac_decode_close(AVCodecContext * avccontext) {
819 AACContext * ac = avccontext->priv_data; 813 AACContext * ac = avccontext->priv_data;
820 int i, j; 814 int i, type;
821 815
822 for (i = 0; i < MAX_ELEM_ID; i++) { 816 for (i = 0; i < MAX_ELEM_ID; i++) {
823 for(j = 0; j < 4; j++) 817 for(type = 0; type < 4; type++)
824 av_freep(&ac->che[j][i]); 818 av_freep(&ac->che[type][i]);
825 } 819 }
826 820
827 ff_mdct_end(&ac->mdct); 821 ff_mdct_end(&ac->mdct);
828 ff_mdct_end(&ac->mdct_small); 822 ff_mdct_end(&ac->mdct_small);
829 return 0 ; 823 return 0 ;