[FFmpeg-soc] [soc]: r3213 - in aacenc: aac.h aacenc.c aacpsy.c

kostya subversion at mplayerhq.hu
Wed Aug 13 12:04:56 CEST 2008


Author: kostya
Date: Wed Aug 13 12:04:56 2008
New Revision: 3213

Log:
Do not scale input by 512 during windowing and MDCT, let psy model handle that

Modified:
   aacenc/aac.h
   aacenc/aacenc.c
   aacenc/aacpsy.c

Modified: aacenc/aac.h
==============================================================================
--- aacenc/aac.h	(original)
+++ aacenc/aac.h	Wed Aug 13 12:04:56 2008
@@ -153,6 +153,7 @@ enum {
     MIXDOWN_BACK,
 };
 
+#define SCALE_DIV_512    36    ///< scalefactor difference that corresponds to scale difference in 512 times
 #define SCALE_ONE_POS   140    ///< scalefactor index that corresponds to scale=1.0
 #define SCALE_MAX_POS   255    ///< scalefactor index maximum value
 #define SCALE_MAX_DIFF   60    ///< maximum scalefactor difference allowed by standard

Modified: aacenc/aacenc.c
==============================================================================
--- aacenc/aacenc.c	(original)
+++ aacenc/aacenc.c	Wed Aug 13 12:04:56 2008
@@ -258,19 +258,19 @@ static void apply_window_and_mdct(AVCode
         if(cpe->ch[channel].ics.window_sequence[0] != LONG_START_SEQUENCE){
             j = channel;
             for (i = 0; i < 1024; i++, j += avctx->channels){
-                s->output[i+1024]         = audio[j] / 512.0 * lwindow[1024 - i - 1];
-                cpe->ch[channel].saved[i] = audio[j] / 512.0 * lwindow[i];
+                s->output[i+1024]         = audio[j] * lwindow[1024 - i - 1];
+                cpe->ch[channel].saved[i] = audio[j] * lwindow[i];
             }
         }else{
             j = channel;
             for(i = 0; i < 448; i++, j += avctx->channels)
-                s->output[i+1024]         = audio[j] / 512.0;
+                s->output[i+1024]         = audio[j];
             for(i = 448; i < 576; i++, j += avctx->channels)
-                s->output[i+1024]         = audio[j] / 512.0 * swindow[576 - i - 1];
+                s->output[i+1024]         = audio[j] * swindow[576 - i - 1];
             memset(s->output+1024+576, 0, sizeof(s->output[0]) * 448);
             j = channel;
             for(i = 0; i < 1024; i++, j += avctx->channels)
-                cpe->ch[channel].saved[i] = audio[j] / 512.0;
+                cpe->ch[channel].saved[i] = audio[j];
         }
         ff_mdct_calc(&s->mdct1024, cpe->ch[channel].coeffs, s->output, s->tmp);
     }else{
@@ -284,7 +284,7 @@ static void apply_window_and_mdct(AVCode
         }
         j = channel;
         for(i = 0; i < 1024; i++, j += avctx->channels)
-            cpe->ch[channel].saved[i] = audio[j] / 512.0;
+            cpe->ch[channel].saved[i] = audio[j];
     }
 }
 

Modified: aacenc/aacpsy.c
==============================================================================
--- aacenc/aacpsy.c	(original)
+++ aacenc/aacpsy.c	Wed Aug 13 12:04:56 2008
@@ -41,7 +41,7 @@ static inline int convert_coeffs(float *
     int i, sign, sum = 0;
     for(i = 0; i < size; i++){
         sign = in[i] > 0.0;
-        out[i] = (int)(pow(FFABS(in[i]) * pow2sf_tab[200 - scale_idx + SCALE_ONE_POS], 0.75) + 0.4054);
+        out[i] = (int)(pow(FFABS(in[i]) * pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512], 0.75) + 0.4054);
         if(out[i] > 8191) out[i] = 8191;
         sum += out[i];
         if(sign) out[i] = -out[i];
@@ -59,9 +59,9 @@ static inline float calc_distortion(floa
     float coef, unquant, sum = 0.0f;
     for(i = 0; i < size; i++){
         coef = FFABS(c[i]);
-        q = (int)(pow(FFABS(coef) * pow2sf_tab[200 - scale_idx + SCALE_ONE_POS], 0.75) + 0.4054);
+        q = (int)(pow(FFABS(coef) * pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512], 0.75) + 0.4054);
         q = av_clip(q, 0, 8191);
-        unquant = (q * cbrt(q)) * pow2sf_tab[200 + scale_idx - SCALE_ONE_POS];
+        unquant = (q * cbrt(q)) * pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
         sum += (coef - unquant) * (coef - unquant);
     }
     return sum;
@@ -598,6 +598,7 @@ static void psy_3gpp_process(AACPsyConte
                 g2 = w*16 + g;
                 for(i = 0; i < cpe->ch[ch].ics.swb_sizes[g]; i++)
                     pch->band[ch][g2].energy +=  cpe->ch[ch].coeffs[start+i] *  cpe->ch[ch].coeffs[start+i];
+                pch->band[ch][g2].energy /= 262144.0f;
                 pch->band[ch][g2].thr = pch->band[ch][g2].energy * 0.001258925f;
                 start += cpe->ch[ch].ics.swb_sizes[g];
                 if(pch->band[ch][g2].energy != 0.0){
@@ -605,7 +606,7 @@ static void psy_3gpp_process(AACPsyConte
 
                     for(i = 0; i < cpe->ch[ch].ics.swb_sizes[g]; i++)
                         ffac += sqrt(FFABS(cpe->ch[ch].coeffs[start+i]));
-                    pch->band[ch][g2].ffac = ffac;
+                    pch->band[ch][g2].ffac = ffac / sqrt(512.0);
                 }
             }
         }
@@ -660,6 +661,10 @@ static void psy_3gpp_process(AACPsyConte
                     ff_m += sqrt(FFABS(m));
                     ff_s += sqrt(FFABS(s));
                 }
+                en_m /= 262144.0;
+                en_s /= 262144.0;
+                ff_m /= sqrt(512.0);
+                ff_s /= sqrt(512.0);
                 l1 = FFMIN(pch->band[0][g2].thr, pch->band[1][g2].thr);
                 if(en_m == 0.0 || en_s == 0.0 || l1*l1 / (en_m * en_s) >= (pch->band[0][g2].thr * pch->band[1][g2].thr / (pch->band[0][g2].energy * pch->band[1][g2].energy))){
                     cpe->ms.mask[w][g] = 1;



More information about the FFmpeg-soc mailing list