diff options
author | Alex Converse <alex.converse@gmail.com> | 2010-07-24 02:37:42 +0400 |
---|---|---|
committer | Alex Converse <alex.converse@gmail.com> | 2010-07-24 02:37:42 +0400 |
commit | 04d72abf17c9ce8f99f092ac83b9b027c8655b2f (patch) | |
tree | 72d6052f14750130e355717d5e8e248f02744c3b /libavcodec | |
parent | 3611e7a3090f06ef3b9f5060334070e122e1b406 (diff) |
aacenc: Factorize some scalefactor utilities.
Originally committed as revision 24472 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/aaccoder.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c index 4a79f125a1..f6b7c2a3ac 100644 --- a/libavcodec/aaccoder.c +++ b/libavcodec/aaccoder.c @@ -515,6 +515,16 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, } } +/** Return the minimum scalefactor where the quantized coef does not clip. */ +static av_always_inline uint8_t coef2minsf(float coef) { + return av_clip_uint8(log2(coef)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512); +} + +/** Return the maximum scalefactor where the quantized coef is not zero. */ +static av_always_inline uint8_t coef2maxsf(float coef) { + return av_clip_uint8(log2(coef)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512); +} + typedef struct TrellisPath { float cost; int prev; @@ -554,9 +564,9 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, } //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped - q0 = av_clip_uint8(log2(q0f)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512); + q0 = coef2minsf(q0f); //maximum scalefactor index is when maximum coefficient after quantizing is still not zero - q1 = av_clip_uint8(log2(q1f)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512); + q1 = coef2maxsf(q1f); //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1); if (q1 - q0 > 60) { int q0low = q0; @@ -618,9 +628,9 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, float minrd = INFINITY; float maxval; //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped - minscale = av_clip_uint8(log2(qmin)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512); + minscale = coef2minsf(qmin); //maximum scalefactor index is when maximum coefficient after quantizing is still not zero - maxscale = av_clip_uint8(log2(qmax)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512); + maxscale = coef2maxsf(qmax); minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1); maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES); maxval = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start); |