Originally committed as revision 23322 to svn://svn.ffmpeg.org/ffmpeg/trunk
Unified · Split
| @@ -217,16 +217,21 @@ static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb, · 216 unmodified lines | ||
| 217 | 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 | 221 | float maxval = 0.0f; |
| 222 | − float Q = ff_aac_pow2sf_tab[200 - sf + SCALE_ONE_POS - SCALE_DIV_512]; | |
| 223 | − float Q34 = sqrtf(Q * sqrtf(Q)); | |
| 224 | − int qmaxval, cb, w2, i; | |
| 222 | + int w2, i; | |
| 225 | 223 | for (w2 = 0; w2 < group_len; w2++) { |
| 226 | 224 | for (i = 0; i < swb_size; i++) { |
| 227 | 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 | 235 | qmaxval = maxval * Q34 + 0.4054f; |
| 231 | 236 | if (qmaxval == 0) cb = 0; |
| 232 | 237 | else if (qmaxval == 1) cb = 1; |
| @@ -567,9 +572,10 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, · 334 unmodified lines | ||
| 567 | 572 | maxscale = av_clip_uint8(log2(qmax)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512); |
| 568 | 573 | minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1); |
| 569 | 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 | 576 | for (q = minscale; q < maxscale; q++) { |
| 571 | 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 | 579 | for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { |
| 574 | 580 | FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g]; |
| 575 | 581 | 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, · 124 unmodified lines | ||
| 700 | 706 | { |
| 701 | 707 | float dist = 0.0f; |
| 702 | 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 | 710 | sce->band_type[w*16+g] = cb; |
| 705 | 711 | for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { |
| 706 | 712 | int b; |