Originally committed as revision 23322 to svn://svn.ffmpeg.org/ffmpeg/trunk
Showing the changes to libavcodec/aaccoder.c (1 of 1 file). Show all
Unified · Split
| @@ -217,16 +217,21 @@ static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb, · 216 unmodified lines | |||
| 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; |
| @@ -567,9 +572,10 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, · 334 unmodified lines | |||
| 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], |
| @@ -700,7 +706,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx, · 124 unmodified lines | |||
| 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; |