[FFmpeg-soc] [soc]: r3278 - in aacenc: aacenc.c aacpsy.c

kostya subversion at mplayerhq.hu
Thu Aug 14 20:00:25 CEST 2008


Author: kostya
Date: Thu Aug 14 20:00:24 2008
New Revision: 3278

Log:
Find out global_gain as recommended instead of relying on psy model

Modified:
   aacenc/aacenc.c
   aacenc/aacpsy.c

Modified: aacenc/aacenc.c
==============================================================================
--- aacenc/aacenc.c	(original)
+++ aacenc/aacenc.c	Thu Aug 14 20:00:24 2008
@@ -512,9 +512,9 @@ static void encode_band_info(AVCodecCont
 /**
  * Encode scalefactors.
  */
-static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, int channel)
+static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, int channel, int global_gain)
 {
-    int off = cpe->ch[channel].mixing_gain, diff;
+    int off = global_gain, diff;
     int i, w;
 
     for(w = 0; w < cpe->ch[channel].ics.num_windows; w++){
@@ -620,6 +620,7 @@ static int encode_individual_channel(AVC
 {
     AACEncContext *s = avctx->priv_data;
     int i, g, w;
+    int global_gain;
 
     for(w = 0; w < cpe->ch[channel].ics.num_windows; w++){
         i = w << 7;
@@ -634,10 +635,23 @@ static int encode_individual_channel(AVC
         }
     }
 
-    put_bits(&s->pb, 8, cpe->ch[channel].mixing_gain); //global gain
+    //determine global gain as standard recommends - the first scalefactor value
+    global_gain = 0;
+    for(w = 0; w < cpe->ch[channel].ics.num_windows; w++){
+        if(cpe->ch[channel].ics.group_len[w]) continue;
+        for(g = 0; g < cpe->ch[channel].ics.max_sfb; g++){
+            if(!cpe->ch[channel].zeroes[w][g]){
+                global_gain = cpe->ch[channel].sf_idx[w][g];
+                break;
+            }
+        }
+        if(global_gain) break;
+    }
+
+    put_bits(&s->pb, 8, global_gain);
     if(!cpe->common_window) put_ics_info(avctx, &cpe->ch[channel].ics);
     encode_band_info(avctx, s, cpe, channel);
-    encode_scale_factors(avctx, s, cpe, channel);
+    encode_scale_factors(avctx, s, cpe, channel, global_gain);
     encode_pulses(avctx, s, cpe, channel);
     encode_tns_data(avctx, s, cpe, channel);
     put_bits(&s->pb, 1, 0); //ssr

Modified: aacenc/aacpsy.c
==============================================================================
--- aacenc/aacpsy.c	(original)
+++ aacenc/aacpsy.c	Thu Aug 14 20:00:24 2008
@@ -218,7 +218,6 @@ static void psy_null_process(AACPsyConte
         for(g = 0; g < apc->num_bands1024; g++)
             if(!cpe->ch[ch].zeroes[0][g])
                 minscale = FFMIN(minscale, cpe->ch[ch].sf_idx[0][g]);
-        cpe->ch[ch].mixing_gain = minscale;
         for(g = 0; g < apc->num_bands1024; g++)
             if(!cpe->ch[ch].zeroes[0][g])
                 cpe->ch[ch].sf_idx[0][g] = FFMIN(minscale + SCALE_MAX_DIFF, cpe->ch[ch].sf_idx[0][g]);
@@ -280,7 +279,6 @@ static void psy_null8_process(AACPsyCont
         }
     }
     for(ch = 0; ch < chans; ch++){
-        cpe->ch[ch].mixing_gain = SCALE_ONE_POS;
         for(w = 0; w < cpe->ch[ch].ics.num_windows; w++){
             for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
                 cpe->ch[ch].sf_idx[w][g] = SCALE_ONE_POS;
@@ -602,7 +600,6 @@ static void psy_3gpp_process(AACPsyConte
     memset(pch->band, 0, sizeof(pch->band));
     for(ch = 0; ch < chans; ch++){
         start = 0;
-        cpe->ch[ch].mixing_gain = 0;
         for(w = 0; w < cpe->ch[ch].ics.num_windows; w++){
             for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
                 g2 = w*16 + g;
@@ -752,7 +749,6 @@ static void psy_3gpp_process(AACPsyConte
         //determine scalefactors - 5.6.2 "Scalefactor determination"
         for(ch = 0; ch < chans; ch++){
             prev_scale = -1;
-            cpe->ch[ch].mixing_gain = 0;
             for(w = 0; w < cpe->ch[ch].ics.num_windows; w++){
                 for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
                     g2 = w*16 + g;
@@ -809,7 +805,6 @@ static void psy_3gpp_process(AACPsyConte
             for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
                 if(cpe->ch[ch].zeroes[w][g]) continue;
                 cpe->ch[ch].sf_idx[w][g] = av_clip(SCALE_ONE_POS + cpe->ch[ch].sf_idx[w][g], 0, SCALE_MAX_POS);
-                if(!cpe->ch[ch].mixing_gain) cpe->ch[ch].mixing_gain = cpe->ch[ch].sf_idx[w][g];
             }
 
         //adjust scalefactors for window groups



More information about the FFmpeg-soc mailing list