changeset 11764:e9c024d542f4 libavcodec

aacenc: Split find_max_val() from find_min_book() to eliminate duplicate searches.
author alexc
date Tue, 25 May 2010 18:35:01 +0000
parents 3fee94a43e64
children c96e649c4e0a
files aaccoder.c
diffstat 1 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/aaccoder.c	Tue May 25 18:32:59 2010 +0000
+++ b/aaccoder.c	Tue May 25 18:35:01 2010 +0000
@@ -217,16 +217,21 @@
                                   INFINITY, NULL);
 }
 
-static int find_min_book(int sf, int group_len, int swb_size, const float *scaled) {
+static float find_max_val(int group_len, int swb_size, const float *scaled) {
     float maxval = 0.0f;
-    float Q = ff_aac_pow2sf_tab[200 - sf + SCALE_ONE_POS - SCALE_DIV_512];
-    float Q34 = sqrtf(Q * sqrtf(Q));
-    int qmaxval, cb, w2, i;
+    int w2, i;
     for (w2 = 0; w2 < group_len; w2++) {
         for (i = 0; i < swb_size; i++) {
             maxval = FFMAX(maxval, scaled[w2*128+i]);
         }
     }
+    return maxval;
+}
+
+static int find_min_book(float maxval, int sf) {
+    float Q = ff_aac_pow2sf_tab[200 - sf + SCALE_ONE_POS - SCALE_DIV_512];
+    float Q34 = sqrtf(Q * sqrtf(Q));
+    int qmaxval, cb;
     qmaxval = maxval * Q34 + 0.4054f;
     if      (qmaxval ==  0) cb = 0;
     else if (qmaxval ==  1) cb = 1;
@@ -567,9 +572,10 @@
                 maxscale = av_clip_uint8(log2(qmax)*4 +  6 + SCALE_ONE_POS - SCALE_DIV_512);
                 minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1);
                 maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES);
+                float maxval = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start);
                 for (q = minscale; q < maxscale; q++) {
                     float dist = 0;
-                    int cb = find_min_book(sce->sf_idx[w*16+g], sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start);
+                    int cb = find_min_book(maxval, sce->sf_idx[w*16+g]);
                     for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
                         FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];
                         dist += quantize_band_cost(s, coefs + w2*128, s->scoefs + start + w2*128, sce->ics.swb_sizes[g],
@@ -700,7 +706,7 @@
                     {
                         float dist = 0.0f;
                         int bb = 0;
-                        cb = find_min_book(sce->sf_idx[w*16+g], sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled);
+                        cb = find_min_book(find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled), sce->sf_idx[w*16+g]);
                         sce->band_type[w*16+g] = cb;
                         for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
                             int b;