[FFmpeg-soc] [PATCH] aacenc: clean up quant sloppiness
Alex Converse
alex.converse at gmail.com
Thu Jun 11 19:02:26 CEST 2009
On Thu, Jun 11, 2009 at 12:00 PM, Kostya <kostya.shishkov at gmail.com> wrote:
>
> On Thu, Jun 11, 2009 at 11:24:46AM -0400, Alex Converse wrote:
> > Hi all,
> >
> > The quantizer code in the aac encoder is kind of sloppy. This cleans it up.
> >
> > Regards,
> >
> > Alex Converse
>
> > commit 35d52275e36c88a429da06e4f6c6ffdab22e3863
> > Author: Alex Converse <alex.converse at gmail.com>
> > Date: Wed Apr 22 00:24:19 2009 -0400
> >
> > Clean up quant sloppiness.
> > More cleanup
> > More quant cleanup
> >
> > diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
> > index d3a2755..b1ed259 100644
> > --- a/libavcodec/aaccoder.c
> > +++ b/libavcodec/aaccoder.c
[...]
>
> {
> > -static const float aac_cb_range[12] = { 0, 3, 3, 3, 3, 9, 9, 8, 8, 13, 13, 17};
> > -static const float aac_cb_maxval[12] = {0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12, 16};
> > +static const uint8_t aac_cb_range [12] = {0, 3, 3, 3, 3, 9, 9, 8, 8, 13, 13, 17};
> > +static const uint8_t aac_cb_maxval[12] = {0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12, 16};
> }
> Commit this change separately
>
split
> > /**
> > * Calculate rate distortion cost for quantizing with given codebook
> > @@ -107,8 +113,8 @@ static float quantize_band_cost(const float *in, int size, int scale_idx, int cb
> > int quants[4][2];
> > mincost = 0.0f;
> > for(j = 0; j < dim; j++){
> > - quants[j][0] = quant2(in[i+j], Q);
> > - quants[j][1] = quant (in[i+j], Q);
> > + quants[j][0] = quant2(fabsf(in[i+j]), Q);
> > + quants[j][1] = quant (fabsf(in[i+j]), Q);
> > for(k = 0; k < 2; k++){
> > quants[j][k] = FFMIN(quants[j][k], maxval);
> > if(!IS_CODEBOOK_UNSIGNED(cb) && in[i+j] < 0.0f)
> > @@ -151,7 +157,7 @@ static float quantize_band_cost(const float *in, int size, int scale_idx, int cb
> > di = t - 165140.0f;
> > curbits += 21;
> > }else{
> > - int c = quant(t, Q);
> > + int c = quant_clip(t, Q);
> > di = t - c*cbrt(c)*IQ;
> > curbits += av_log2(c)*2 - 4 + 1;
> > }
> > @@ -210,8 +216,8 @@ static void quantize_and_encode_band(PutBitContext *pb, const float *in, int siz
> > int quants[4][2];
> > mincost = 0.0f;
> > for(j = 0; j < dim; j++){
> > - quants[j][0] = av_clip(quant2(in[i+j], Q), -maxval, maxval);
> > - quants[j][1] = av_clip(quant (in[i+j], Q), -maxval, maxval);
> > + quants[j][0] = quant2(fabsf(in[i+j]), Q);
> > + quants[j][1] = quant (fabsf(in[i+j]), Q);
> >
> > for(k = 0; k < 2; k++){
> > quants[j][k] = FFMIN(quants[j][k], maxval);
> > if(!IS_CODEBOOK_UNSIGNED(cb) && in[i+j] < 0.0f)
> > @@ -254,7 +260,7 @@ static void quantize_and_encode_band(PutBitContext *pb, const float *in, int siz
> > di = t - 165140.0f;
> > curbits += 21;
> > }else{
> > - int c = quant(t, Q);
> > + int c = quant_clip(t, Q);
> > di = t - c*cbrt(c)*IQ;
> > curbits += av_log2(c)*2 - 4 + 1;
> > }
> > @@ -286,7 +292,7 @@ static void quantize_and_encode_band(PutBitContext *pb, const float *in, int siz
> > if(cb == ESC_BT){
> > for(j = 0; j < 2; j++){
> > if(ff_aac_codebook_vectors[cb-1][minidx*2+j] == 64.0f){
> > - int coef = quant(in[i+j], Q);
> > + int coef = quant_clip(fabsf(in[i+j]), Q);
> > int len = av_log2(coef);
> >
> > put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
> > @@ -308,6 +314,7 @@ static float quantize_band_cost(const float *in, int size, int scale_idx, int cb
> > const float lambda, const float uplim, int *bits)
> > {
> > const float Q = ff_aac_pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
> > + const float IQ = 1.0/Q;
> > int i, j, k;
> > float cost = 0;
> > const int dim = cb < FIRST_PAIR_BT ? 4 : 2;
> > @@ -340,7 +347,7 @@ static float quantize_band_cost(const float *in, int size, int scale_idx, int cb
> > di = t - 165140.0f;
> > curbits += 21;
> > }else{
> > - int c = quant(t, 1.0/Q);
> > + int c = quant_clip(t, IQ);
> > di = t - c*cbrt(c)*Q;
> > curbits += av_log2(c)*2 - 4 + 1;
> > }
> > @@ -413,7 +420,7 @@ static void quantize_and_encode_band(PutBitContext *pb, const float *in, int siz
> > di = t - 165140.0f;
> > curbits += 21;
> > }else{
> > - int c = quant(t, IQ);
> > + int c = quant_clip(t, IQ);
> > di = t - c*cbrt(c)*Q;
> > curbits += av_log2(c)*2 - 4 + 1;
> > }
> > @@ -445,7 +452,7 @@ static void quantize_and_encode_band(PutBitContext *pb, const float *in, int siz
> > if(cb == ESC_BT){
> > for(j = 0; j < 2; j++){
> > if(ff_aac_codebook_vectors[cb-1][minidx*2+j] == 64.0f){
> > - int coef = quant(in[i+j], IQ);
> > + int coef = quant_clip(fabsf(in[i+j]), IQ);
> > int len = av_log2(coef);
> >
> > put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
>
> No objections against introducing IQ where appropriate. Also commit
> separately anytime.
>
split
> As for having unlimited and limited quantizing - that's code
> duplication. I think it's better to clip it after the call.
fixed
> _______________________________________________
> FFmpeg-soc mailing list
> FFmpeg-soc at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc
Split, fixed, and applied.
More information about the FFmpeg-soc
mailing list