comparison aaccoder.c @ 11760:2167bf95c596 libavcodec

aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
author alexc
date Tue, 25 May 2010 18:24:16 +0000
parents 0c1f5ab77b36
children 418455c7e31f
comparison
equal deleted inserted replaced
11759:ad10fb453ad9 11760:2167bf95c596
212 const float *in, int size, int scale_idx, 212 const float *in, int size, int scale_idx,
213 int cb, const float lambda) 213 int cb, const float lambda)
214 { 214 {
215 quantize_and_encode_band_cost(s, pb, in, NULL, size, scale_idx, cb, lambda, 215 quantize_and_encode_band_cost(s, pb, in, NULL, size, scale_idx, cb, lambda,
216 INFINITY, NULL); 216 INFINITY, NULL);
217 }
218
219 static int find_min_book(int sf, int group_len, int swb_size, const float *scaled) {
220 float maxval = 0.0f;
221 float Q = ff_aac_pow2sf_tab[200 - sf + SCALE_ONE_POS - SCALE_DIV_512];
222 float Q34 = sqrtf(Q * sqrtf(Q));
223 int qmaxval, cb, w2, i;
224 for (w2 = 0; w2 < group_len; w2++) {
225 for (i = 0; i < swb_size; i++) {
226 maxval = FFMAX(maxval, scaled[w2*128+i]);
227 }
228 }
229 qmaxval = maxval * Q34 + 0.4054f;
230 if (qmaxval == 0) cb = 0;
231 else if (qmaxval == 1) cb = 1;
232 else if (qmaxval == 2) cb = 3;
233 else if (qmaxval <= 4) cb = 5;
234 else if (qmaxval <= 7) cb = 7;
235 else if (qmaxval <= 12) cb = 9;
236 else cb = 11;
237 return cb;
217 } 238 }
218 239
219 /** 240 /**
220 * structure used in optimal codebook search 241 * structure used in optimal codebook search
221 */ 242 */
671 } 692 }
672 minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]); 693 minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]);
673 { 694 {
674 float dist = 0.0f; 695 float dist = 0.0f;
675 int bb = 0; 696 int bb = 0;
676 float maxval = 0.0f; 697 cb = find_min_book(sce->sf_idx[w*16+g], sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled);
677 float Q = ff_aac_pow2sf_tab[200 - sce->sf_idx[w*16+g] + SCALE_ONE_POS - SCALE_DIV_512];
678 float Q34 = sqrtf(Q * sqrtf(Q));
679 int qmaxval;
680 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
681 for (i = 0; i < sce->ics.swb_sizes[g]; i++) {
682 maxval = FFMAX(maxval, scaled[w2*128+i]);
683 }
684 }
685 qmaxval = maxval * Q34 + 0.4054;
686 if (qmaxval == 0) cb = 0;
687 else if (qmaxval == 1) cb = 1;
688 else if (qmaxval == 2) cb = 3;
689 else if (qmaxval <= 4) cb = 5;
690 else if (qmaxval <= 7) cb = 7;
691 else if (qmaxval <= 12) cb = 9;
692 else cb = 11;
693 sce->band_type[w*16+g] = cb; 698 sce->band_type[w*16+g] = cb;
694 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { 699 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
695 int b; 700 int b;
696 dist += quantize_band_cost(s, coefs + w2*128, 701 dist += quantize_band_cost(s, coefs + w2*128,
697 scaled + w2*128, 702 scaled + w2*128,