Mercurial > libavcodec.hg
comparison aaccoder.c @ 9939:6c5a58b34997 libavcodec
Turn on AAC rate control.
author | alexc |
---|---|
date | Wed, 08 Jul 2009 23:04:22 +0000 |
parents | 6c1ac45b3097 |
children | c5ca5e520fe1 |
comparison
equal
deleted
inserted
replaced
9938:6c1ac45b3097 | 9939:6c5a58b34997 |
---|---|
455 } | 455 } |
456 put_bits(&s->pb, run_bits, count); | 456 put_bits(&s->pb, run_bits, count); |
457 } | 457 } |
458 } | 458 } |
459 | 459 |
460 static void encode_window_bands_info_fixed(AACEncContext *s, | |
461 SingleChannelElement *sce, | |
462 int win, int group_len, | |
463 const float lambda) | |
464 { | |
465 encode_window_bands_info(s, sce, win, group_len, 1.0f); | |
466 } | |
467 | |
468 | |
469 typedef struct TrellisPath { | 460 typedef struct TrellisPath { |
470 float cost; | 461 float cost; |
471 int prev; | 462 int prev; |
472 int min_val; | 463 int min_val; |
473 int max_val; | 464 int max_val; |
698 dist += quantize_band_cost(s, coefs + w2*128, | 689 dist += quantize_band_cost(s, coefs + w2*128, |
699 scaled + w2*128, | 690 scaled + w2*128, |
700 sce->ics.swb_sizes[g], | 691 sce->ics.swb_sizes[g], |
701 sce->sf_idx[w*16+g], | 692 sce->sf_idx[w*16+g], |
702 ESC_BT, | 693 ESC_BT, |
703 1.0, | 694 lambda, |
704 INFINITY, | 695 INFINITY, |
705 &b); | 696 &b); |
706 bb += b; | 697 bb += b; |
707 } | 698 } |
708 if (dist < mindist) { | 699 if (dist < mindist) { |
709 mindist = dist; | 700 mindist = dist; |
710 minbits = bb; | 701 minbits = bb; |
711 } | 702 } |
712 } | 703 } |
713 dists[w*16+g] = mindist - minbits; | 704 dists[w*16+g] = (mindist - minbits) / lambda; |
714 bits = minbits; | 705 bits = minbits; |
715 if (prev != -1) { | 706 if (prev != -1) { |
716 bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO]; | 707 bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO]; |
717 } | 708 } |
718 tbits += bits; | 709 tbits += bits; |
868 dist += quantize_band_cost(s, coefs + w2*128, | 859 dist += quantize_band_cost(s, coefs + w2*128, |
869 scaled + w2*128, | 860 scaled + w2*128, |
870 sce->ics.swb_sizes[g], | 861 sce->ics.swb_sizes[g], |
871 scf, | 862 scf, |
872 ESC_BT, | 863 ESC_BT, |
873 1.0, | 864 lambda, |
874 INFINITY, | 865 INFINITY, |
875 &b); | 866 &b); |
876 dist -= b; | 867 dist -= b; |
877 } | 868 } |
878 dist *= 1.0f/512.0f; | 869 dist *= 1.0f / 512.0f / lambda; |
879 quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[200 - scf + SCALE_ONE_POS - SCALE_DIV_512]); | 870 quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[200 - scf + SCALE_ONE_POS - SCALE_DIV_512]); |
880 if (quant_max >= 8191) { // too much, return to the previous quantizer | 871 if (quant_max >= 8191) { // too much, return to the previous quantizer |
881 sce->sf_idx[w*16+g] = prev_scf; | 872 sce->sf_idx[w*16+g] = prev_scf; |
882 break; | 873 break; |
883 } | 874 } |
1017 } | 1008 } |
1018 | 1009 |
1019 AACCoefficientsEncoder ff_aac_coders[] = { | 1010 AACCoefficientsEncoder ff_aac_coders[] = { |
1020 { | 1011 { |
1021 search_for_quantizers_faac, | 1012 search_for_quantizers_faac, |
1022 encode_window_bands_info_fixed, | 1013 encode_window_bands_info, |
1023 quantize_and_encode_band, | 1014 quantize_and_encode_band, |
1024 // search_for_ms, | 1015 // search_for_ms, |
1025 }, | 1016 }, |
1026 { | 1017 { |
1027 search_for_quantizers_anmr, | 1018 search_for_quantizers_anmr, |