summaryrefslogtreecommitdiff
path: root/libavcodec/aaccoder.c
diff options
context:
space:
mode:
authorAlex Converse <alex.converse@gmail.com>2010-05-25 18:35:01 +0000
committerAlex Converse <alex.converse@gmail.com>2010-05-25 18:35:01 +0000
commit0ecfa7b7c7fe26cfd34795068c9880ed84df16a0 (patch)
tree17e6bc759485e21588d3b06bb85fadf87258a59c /libavcodec/aaccoder.c
parentaf2ee6fc4921a81133c0915985e05781505c2ff8 (diff)
aacenc: Split find_max_val() from find_min_book() to eliminate duplicate searches.
Originally committed as revision 23322 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/aaccoder.c')
-rw-r--r--libavcodec/aaccoder.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 1cdadb17de..53c4b66397 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -217,16 +217,21 @@ static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb,
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 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,
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 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx,
{
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;