comparison aaccoder.c @ 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 847502a2f850
comparison
equal deleted inserted replaced
11763:3fee94a43e64 11764:e9c024d542f4
215 { 215 {
216 quantize_and_encode_band_cost(s, pb, in, NULL, size, scale_idx, cb, lambda, 216 quantize_and_encode_band_cost(s, pb, in, NULL, size, scale_idx, cb, lambda,
217 INFINITY, NULL); 217 INFINITY, NULL);
218 } 218 }
219 219
220 static int find_min_book(int sf, int group_len, int swb_size, const float *scaled) { 220 static float find_max_val(int group_len, int swb_size, const float *scaled) {
221 float maxval = 0.0f; 221 float maxval = 0.0f;
222 float Q = ff_aac_pow2sf_tab[200 - sf + SCALE_ONE_POS - SCALE_DIV_512]; 222 int w2, i;
223 float Q34 = sqrtf(Q * sqrtf(Q));
224 int qmaxval, cb, w2, i;
225 for (w2 = 0; w2 < group_len; w2++) { 223 for (w2 = 0; w2 < group_len; w2++) {
226 for (i = 0; i < swb_size; i++) { 224 for (i = 0; i < swb_size; i++) {
227 maxval = FFMAX(maxval, scaled[w2*128+i]); 225 maxval = FFMAX(maxval, scaled[w2*128+i]);
228 } 226 }
229 } 227 }
228 return maxval;
229 }
230
231 static int find_min_book(float maxval, int sf) {
232 float Q = ff_aac_pow2sf_tab[200 - sf + SCALE_ONE_POS - SCALE_DIV_512];
233 float Q34 = sqrtf(Q * sqrtf(Q));
234 int qmaxval, cb;
230 qmaxval = maxval * Q34 + 0.4054f; 235 qmaxval = maxval * Q34 + 0.4054f;
231 if (qmaxval == 0) cb = 0; 236 if (qmaxval == 0) cb = 0;
232 else if (qmaxval == 1) cb = 1; 237 else if (qmaxval == 1) cb = 1;
233 else if (qmaxval == 2) cb = 3; 238 else if (qmaxval == 2) cb = 3;
234 else if (qmaxval <= 4) cb = 5; 239 else if (qmaxval <= 4) cb = 5;
565 minscale = av_clip_uint8(log2(qmin)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512); 570 minscale = av_clip_uint8(log2(qmin)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512);
566 //maximum scalefactor index is when maximum coefficient after quantizing is still not zero 571 //maximum scalefactor index is when maximum coefficient after quantizing is still not zero
567 maxscale = av_clip_uint8(log2(qmax)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512); 572 maxscale = av_clip_uint8(log2(qmax)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512);
568 minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1); 573 minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1);
569 maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES); 574 maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES);
575 float maxval = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start);
570 for (q = minscale; q < maxscale; q++) { 576 for (q = minscale; q < maxscale; q++) {
571 float dist = 0; 577 float dist = 0;
572 int cb = find_min_book(sce->sf_idx[w*16+g], sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start); 578 int cb = find_min_book(maxval, sce->sf_idx[w*16+g]);
573 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { 579 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
574 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g]; 580 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];
575 dist += quantize_band_cost(s, coefs + w2*128, s->scoefs + start + w2*128, sce->ics.swb_sizes[g], 581 dist += quantize_band_cost(s, coefs + w2*128, s->scoefs + start + w2*128, sce->ics.swb_sizes[g],
576 q + q0, cb, lambda / band->threshold, INFINITY, NULL); 582 q + q0, cb, lambda / band->threshold, INFINITY, NULL);
577 } 583 }
698 } 704 }
699 minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]); 705 minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]);
700 { 706 {
701 float dist = 0.0f; 707 float dist = 0.0f;
702 int bb = 0; 708 int bb = 0;
703 cb = find_min_book(sce->sf_idx[w*16+g], sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled); 709 cb = find_min_book(find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled), sce->sf_idx[w*16+g]);
704 sce->band_type[w*16+g] = cb; 710 sce->band_type[w*16+g] = cb;
705 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { 711 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
706 int b; 712 int b;
707 dist += quantize_band_cost(s, coefs + w2*128, 713 dist += quantize_band_cost(s, coefs + w2*128,
708 scaled + w2*128, 714 scaled + w2*128,