comparison aaccoder.c @ 12258:86d6c00756cc libavcodec

aacenc: Favor log2f() and sqrtf() over log2() and sqrt().
author alexc
date Sat, 24 Jul 2010 02:10:59 +0000
parents ad42f9293ec6
children 940736055764
comparison
equal deleted inserted replaced
12257:ad42f9293ec6 12258:86d6c00756cc
515 } 515 }
516 } 516 }
517 517
518 /** Return the minimum scalefactor where the quantized coef does not clip. */ 518 /** Return the minimum scalefactor where the quantized coef does not clip. */
519 static av_always_inline uint8_t coef2minsf(float coef) { 519 static av_always_inline uint8_t coef2minsf(float coef) {
520 return av_clip_uint8(log2(coef)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512); 520 return av_clip_uint8(log2f(coef)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512);
521 } 521 }
522 522
523 /** Return the maximum scalefactor where the quantized coef is not zero. */ 523 /** Return the maximum scalefactor where the quantized coef is not zero. */
524 static av_always_inline uint8_t coef2maxsf(float coef) { 524 static av_always_inline uint8_t coef2maxsf(float coef) {
525 return av_clip_uint8(log2(coef)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512); 525 return av_clip_uint8(log2f(coef)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512);
526 } 526 }
527 527
528 typedef struct TrellisPath { 528 typedef struct TrellisPath {
529 float cost; 529 float cost;
530 int prev; 530 int prev;
570 //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1); 570 //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1);
571 if (q1 - q0 > 60) { 571 if (q1 - q0 > 60) {
572 int q0low = q0; 572 int q0low = q0;
573 int q1high = q1; 573 int q1high = q1;
574 //minimum scalefactor index is when maximum nonzero coefficient after quantizing is not clipped 574 //minimum scalefactor index is when maximum nonzero coefficient after quantizing is not clipped
575 int qnrg = av_clip_uint8(log2(sqrt(qnrgf/qcnt))*4 - 31 + SCALE_ONE_POS - SCALE_DIV_512); 575 int qnrg = av_clip_uint8(log2f(sqrtf(qnrgf/qcnt))*4 - 31 + SCALE_ONE_POS - SCALE_DIV_512);
576 q1 = qnrg + 30; 576 q1 = qnrg + 30;
577 q0 = qnrg - 30; 577 q0 = qnrg - 30;
578 //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1); 578 //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1);
579 if (q0 < q0low) { 579 if (q0 < q0low) {
580 q1 += q0low - q0; 580 q1 += q0low - q0;
729 for (g = 0; g < sce->ics.num_swb; g++) { 729 for (g = 0; g < sce->ics.num_swb; g++) {
730 if (sce->zeroes[w*16+g]) { 730 if (sce->zeroes[w*16+g]) {
731 sce->sf_idx[w*16+g] = SCALE_ONE_POS; 731 sce->sf_idx[w*16+g] = SCALE_ONE_POS;
732 continue; 732 continue;
733 } 733 }
734 sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2(uplims[w*16+g]/minthr)*4,59); 734 sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2f(uplims[w*16+g]/minthr)*4,59);
735 } 735 }
736 } 736 }
737 737
738 if (!allz) 738 if (!allz)
739 return; 739 return;
923 sce->zeroes[w*16+g] = 1; 923 sce->zeroes[w*16+g] = 1;
924 start += size; 924 start += size;
925 continue; 925 continue;
926 } 926 }
927 sce->zeroes[w*16+g] = 0; 927 sce->zeroes[w*16+g] = 0;
928 scf = prev_scf = av_clip(SCALE_ONE_POS - SCALE_DIV_512 - log2(1/maxq[w*16+g])*16/3, 60, 218); 928 scf = prev_scf = av_clip(SCALE_ONE_POS - SCALE_DIV_512 - log2f(1/maxq[w*16+g])*16/3, 60, 218);
929 step = 16; 929 step = 16;
930 for (;;) { 930 for (;;) {
931 float dist = 0.0f; 931 float dist = 0.0f;
932 int quant_max; 932 int quant_max;
933 933
952 prev_scf = scf; 952 prev_scf = scf;
953 curdiff = fabsf(dist - uplim[w*16+g]); 953 curdiff = fabsf(dist - uplim[w*16+g]);
954 if (curdiff <= 1.0f) 954 if (curdiff <= 1.0f)
955 step = 0; 955 step = 0;
956 else 956 else
957 step = log2(curdiff); 957 step = log2f(curdiff);
958 if (dist > uplim[w*16+g]) 958 if (dist > uplim[w*16+g])
959 step = -step; 959 step = -step;
960 scf += step; 960 scf += step;
961 scf = av_clip_uint8(scf); 961 scf = av_clip_uint8(scf);
962 step = scf - prev_scf; 962 step = scf - prev_scf;
1005 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g]; 1005 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];
1006 if (band->energy <= band->threshold) { 1006 if (band->energy <= band->threshold) {
1007 sce->sf_idx[(w+w2)*16+g] = 218; 1007 sce->sf_idx[(w+w2)*16+g] = 218;
1008 sce->zeroes[(w+w2)*16+g] = 1; 1008 sce->zeroes[(w+w2)*16+g] = 1;
1009 } else { 1009 } else {
1010 sce->sf_idx[(w+w2)*16+g] = av_clip(SCALE_ONE_POS - SCALE_DIV_512 + log2(band->threshold), 80, 218); 1010 sce->sf_idx[(w+w2)*16+g] = av_clip(SCALE_ONE_POS - SCALE_DIV_512 + log2f(band->threshold), 80, 218);
1011 sce->zeroes[(w+w2)*16+g] = 0; 1011 sce->zeroes[(w+w2)*16+g] = 0;
1012 } 1012 }
1013 minq = FFMIN(minq, sce->sf_idx[(w+w2)*16+g]); 1013 minq = FFMIN(minq, sce->sf_idx[(w+w2)*16+g]);
1014 } 1014 }
1015 } 1015 }