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

kostya subversion at mplayerhq.hu
Fri Aug 15 08:50:56 CEST 2008


Author: kostya
Date: Fri Aug 15 08:50:56 2008
New Revision: 3304

Log:
Use window grouping scheme in the same manner as decoder does

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

Modified: aacenc/aacenc.c
==============================================================================
--- aacenc/aacenc.c	(original)
+++ aacenc/aacenc.c	Fri Aug 15 08:50:56 2008
@@ -301,7 +301,7 @@ static void apply_window_and_mdct(AVCode
 static void put_ics_info(AVCodecContext *avctx, IndividualChannelStream *info)
 {
     AACEncContext *s = avctx->priv_data;
-    int i;
+    int wg;
 
     put_bits(&s->pb, 1, 0);                // ics_reserved bit
     put_bits(&s->pb, 2, info->window_sequence[0]);
@@ -311,8 +311,12 @@ static void put_ics_info(AVCodecContext 
         put_bits(&s->pb, 1, 0);            // no prediction
     }else{
         put_bits(&s->pb, 4, info->max_sfb);
-        for(i = 1; i < info->num_windows; i++)
-            put_bits(&s->pb, 1, info->group_len[i]);
+        for(wg = 0; wg < info->num_window_groups; wg++){
+            if(wg)
+                put_bits(&s->pb, 1, 0);
+            if(info->group_len[wg] > 1)
+                put_sbits(&s->pb, info->group_len[wg] - 1, 0xFF);
+        }
     }
 }
 
@@ -322,15 +326,17 @@ static void put_ics_info(AVCodecContext 
  */
 static void encode_ms_info(PutBitContext *pb, ChannelElement *cpe)
 {
-    int i, w;
+    int i, w, wg;
 
     put_bits(pb, 2, cpe->ms.present);
-    if(cpe->ms.present == 1)
-        for(w = 0; w < cpe->ch[0].ics.num_windows; w++){
-            if(cpe->ch[0].ics.group_len[w]) continue;
+    if(cpe->ms.present == 1){
+        w = 0;
+        for(wg = 0; wg < cpe->ch[0].ics.num_window_groups; wg++){
             for(i = 0; i < cpe->ch[0].ics.max_sfb; i++)
                 put_bits(pb, 1, cpe->ms.mask[w][i]);
+            w += cpe->ch[0].ics.group_len[wg];
         }
+    }
 }
 
 /**
@@ -344,7 +350,7 @@ static void encode_ms_info(PutBitContext
  * @param start   scalefactor band position in spectral coefficients
  * @param size    scalefactor band size
  */
-static int determine_section_info(AACEncContext *s, ChannelElement *cpe, int channel, int win, int band, int start, int size)
+static int determine_section_info(AACEncContext *s, ChannelElement *cpe, int channel, int win, int group_len, int band, int start, int size)
 {
     int i, j, w;
     int maxval, sign;
@@ -354,14 +360,13 @@ static int determine_section_info(AACEnc
     sign = 0;
     w = win;
     start2 = start;
-    do{
+    for(w = win; w < win + group_len; w++){
         for(i = start2; i < start2 + size; i++){
             maxval = FFMAX(maxval, FFABS(cpe->ch[channel].icoefs[i]));
             if(cpe->ch[channel].icoefs[i] < 0) sign = 1;
         }
-        w++;
         start2 += 128;
-    }while(w < cpe->ch[channel].ics.num_windows && cpe->ch[channel].ics.group_len[w]);
+    }
 
     if(maxval > 12) return 11;
     if(!maxval) return 0;
@@ -376,10 +381,9 @@ static int determine_section_info(AACEnc
         dim = (aac_cb_info[cb].flags & CB_PAIRS) ? 2 : 4;
         if(!band || cpe->ch[channel].band_type[win][band - 1] != cb)
             score += 9; //that's for new codebook entry
-        w = win;
         start2 = start;
         if(aac_cb_info[cb].flags & CB_UNSIGNED){
-            do{
+            for(w = win; w < win + group_len; w++){
                 for(i = start2; i < start2 + size; i += dim){
                     idx = 0;
                     for(j = 0; j < dim; j++)
@@ -389,20 +393,18 @@ static int determine_section_info(AACEnc
                         if(cpe->ch[channel].icoefs[i+j])
                             score++;
                 }
-                w++;
                 start2 += 128;
-            }while(w < cpe->ch[channel].ics.num_windows && cpe->ch[channel].ics.group_len[w]);
+            }
         }else{
-            do{
+            for(w = win; w < win + group_len; w++){
                 for(i = start2; i < start2 + size; i += dim){
                     idx = 0;
                     for(j = 0; j < dim; j++)
                         idx = idx * (aac_cb_info[cb].maxval*2 + 1) + cpe->ch[channel].icoefs[i+j] + aac_cb_info[cb].maxval;
                     score += ff_aac_spectral_bits[aac_cb_info[cb].cb_num][idx];
                 }
-                w++;
                 start2 += 128;
-            }while(w < cpe->ch[channel].ics.num_windows && cpe->ch[channel].ics.group_len[w]);
+            }
         }
         if(score < best){
             best = score;
@@ -477,13 +479,13 @@ static void encode_band_coeffs(AACEncCon
  */
 static void encode_band_info(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, int channel)
 {
-    int i, w;
+    int i, w, wg;
     int bits = cpe->ch[channel].ics.num_windows == 1 ? 5 : 3;
     int esc = (1 << bits) - 1;
     int count;
 
-    for(w = 0; w < cpe->ch[channel].ics.num_windows; w++){
-        if(cpe->ch[channel].ics.group_len[w]) continue;
+    w = 0;
+    for(wg = 0; wg < cpe->ch[channel].ics.num_window_groups; wg++){
         count = 0;
         for(i = 0; i < cpe->ch[channel].ics.max_sfb; i++){
             if(!i || cpe->ch[channel].band_type[w][i] != cpe->ch[channel].band_type[w][i-1]){
@@ -506,6 +508,7 @@ static void encode_band_info(AVCodecCont
             }
             put_bits(&s->pb, bits, count);
         }
+        w += cpe->ch[channel].ics.group_len[wg];
     }
 }
 
@@ -515,10 +518,10 @@ static void encode_band_info(AVCodecCont
 static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, int channel, int global_gain)
 {
     int off = global_gain, diff;
-    int i, w;
+    int i, w, wg;
 
-    for(w = 0; w < cpe->ch[channel].ics.num_windows; w++){
-        if(cpe->ch[channel].ics.group_len[w]) continue;
+    w = 0;
+    for(wg = 0; wg < cpe->ch[channel].ics.num_window_groups; wg++){
         for(i = 0; i < cpe->ch[channel].ics.max_sfb; i++){
             if(!cpe->ch[channel].zeroes[w][i]){
                 diff = cpe->ch[channel].sf_idx[w][i] - off + SCALE_DIFF_ZERO;
@@ -527,6 +530,7 @@ static void encode_scale_factors(AVCodec
                 put_bits(&s->pb, ff_aac_scalefactor_bits[diff], ff_aac_scalefactor_code[diff]);
             }
         }
+        w += cpe->ch[channel].ics.group_len[wg];
     }
 }
 
@@ -593,23 +597,22 @@ static void encode_tns_data(AVCodecConte
  */
 static void encode_spectral_coeffs(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, int channel)
 {
-    int start, i, w, w2;
+    int start, i, w, w2, wg;
 
-    for(w = 0; w < cpe->ch[channel].ics.num_windows; w++){
-        if(cpe->ch[channel].ics.group_len[w]) continue;
+    w = 0;
+    for(wg = 0; wg < cpe->ch[channel].ics.num_window_groups; wg++){
         start = 0;
         for(i = 0; i < cpe->ch[channel].ics.max_sfb; i++){
             if(cpe->ch[channel].zeroes[w][i]){
                 start += cpe->ch[channel].ics.swb_sizes[i];
                 continue;
             }
-            w2 = w;
-            do{
+            for(w2 = w; w2 < w + cpe->ch[channel].ics.group_len[wg]; w2++){
                 encode_band_coeffs(s, cpe, channel, start + w2*128, cpe->ch[channel].ics.swb_sizes[i], cpe->ch[channel].band_type[w][i]);
-                w2++;
-            }while(w2 < cpe->ch[channel].ics.num_windows && cpe->ch[channel].ics.group_len[w2]);
+            }
             start += cpe->ch[channel].ics.swb_sizes[i];
         }
+        w += cpe->ch[channel].ics.group_len[wg];
     }
 }
 
@@ -619,26 +622,27 @@ static void encode_spectral_coeffs(AVCod
 static int encode_individual_channel(AVCodecContext *avctx, ChannelElement *cpe, int channel)
 {
     AACEncContext *s = avctx->priv_data;
-    int i, g, w;
+    int i, g, w, wg;
     int global_gain;
 
-    for(w = 0; w < cpe->ch[channel].ics.num_windows; w++){
+    w = 0;
+    for(wg = 0; wg < cpe->ch[channel].ics.num_window_groups; wg++){
         i = w << 7;
-        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]){
-                cpe->ch[channel].band_type[w][g] = determine_section_info(s, cpe, channel, w, g, i, cpe->ch[channel].ics.swb_sizes[g]);
+                cpe->ch[channel].band_type[w][g] = determine_section_info(s, cpe, channel, w, cpe->ch[channel].ics.group_len[wg], g, i, cpe->ch[channel].ics.swb_sizes[g]);
                 cpe->ch[channel].zeroes[w][g] = !cpe->ch[channel].band_type[w][g];
             }else
                 cpe->ch[channel].band_type[w][g] = 0;
             i += cpe->ch[channel].ics.swb_sizes[g];
         }
+        w += cpe->ch[channel].ics.group_len[wg];
     }
 
     //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;
+    w = 0;
+    for(wg = 0; wg < cpe->ch[channel].ics.num_window_groups; wg++){
         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];
@@ -646,6 +650,7 @@ static int encode_individual_channel(AVC
             }
         }
         if(global_gain) break;
+        w += cpe->ch[channel].ics.group_len[wg];
     }
 
     put_bits(&s->pb, 8, global_gain);

Modified: aacenc/aacpsy.c
==============================================================================
--- aacenc/aacpsy.c	(original)
+++ aacenc/aacpsy.c	Fri Aug 15 08:50:56 2008
@@ -81,7 +81,7 @@ static inline float calc_distortion(floa
  */
 static void psy_create_output(AACPsyContext *apc, ChannelElement *cpe, int chans, int search_pulses)
 {
-    int i, w, w2, g, ch;
+    int i, w, w2, wg, g, ch;
     int start, sum, maxsfb, cmaxsfb;
     int pulses, poff[4], pamp[4];
 
@@ -139,20 +139,19 @@ static void psy_create_output(AACPsyCont
         cpe->ch[ch].ics.max_sfb = maxsfb;
 
         //adjust zero bands for window groups
-        for(w = 0; w < cpe->ch[ch].ics.num_windows; w++){
-            if(cpe->ch[ch].ics.group_len[w]) continue;
+        w = 0;
+        for(wg = 0; wg < cpe->ch[ch].ics.num_window_groups; wg++){
             for(g = 0; g < cpe->ch[ch].ics.max_sfb; g++){
                 i = 1;
-                w2 = w;
-                do{
-                    if(!cpe->ch[ch].zeroes[w2][g]){
+                for(w2 = 0; w2 < cpe->ch[ch].ics.group_len[wg]; w2++){
+                    if(!cpe->ch[ch].zeroes[w + w2][g]){
                         i = 0;
                         break;
                     }
-                    w2++;
-                }while(w2 < cpe->ch[ch].ics.num_windows && cpe->ch[ch].ics.group_len[w2]);
+                }
                 cpe->ch[ch].zeroes[w][g] = i;
             }
+            w += cpe->ch[ch].ics.group_len[wg];
         }
     }
 
@@ -179,7 +178,8 @@ static void psy_null_window(AACPsyContex
         cpe->ch[ch].ics.num_windows = 1;
         cpe->ch[ch].ics.swb_sizes = apc->bands1024;
         cpe->ch[ch].ics.num_swb = apc->num_bands1024;
-        cpe->ch[ch].ics.group_len[0] = 0;
+        cpe->ch[ch].ics.num_window_groups = 1;
+        cpe->ch[ch].ics.group_len[0] = 1;
     }
     cpe->common_window = cpe->ch[0].ics.use_kb_window[0] == cpe->ch[1].ics.use_kb_window[0];
 }
@@ -246,14 +246,16 @@ static void psy_null8_window(AACPsyConte
             cpe->ch[ch].ics.num_windows = 1;
             cpe->ch[ch].ics.swb_sizes = apc->bands1024;
             cpe->ch[ch].ics.num_swb = apc->num_bands1024;
-            cpe->ch[ch].ics.group_len[0] = 0;
+            cpe->ch[ch].ics.num_window_groups = 1;
+            cpe->ch[ch].ics.group_len[0] = 1;
         }else{
             cpe->ch[ch].ics.use_kb_window[0] = 1;
             cpe->ch[ch].ics.num_windows = 8;
             cpe->ch[ch].ics.swb_sizes = apc->bands128;
             cpe->ch[ch].ics.num_swb = apc->num_bands128;
-            for(i = 0; i < cpe->ch[ch].ics.num_windows; i++)
-                cpe->ch[ch].ics.group_len[i] = i & 1;
+            cpe->ch[ch].ics.num_window_groups = 4;
+            for(i = 0; i < 4; i++)
+                cpe->ch[ch].ics.group_len[i] = 2;
         }
     }
     cpe->common_window = cpe->ch[0].ics.use_kb_window[0] == cpe->ch[1].ics.use_kb_window[0];
@@ -529,13 +531,23 @@ static void psy_3gpp_window(AACPsyContex
             cpe->ch[ch].ics.num_windows = 1;
             cpe->ch[ch].ics.swb_sizes = apc->bands1024;
             cpe->ch[ch].ics.num_swb = apc->num_bands1024;
+            cpe->ch[ch].ics.num_window_groups = 1;
+            cpe->ch[ch].ics.group_len[0] = 1;
         }else{
             cpe->ch[ch].ics.num_windows = 8;
             cpe->ch[ch].ics.swb_sizes = apc->bands128;
             cpe->ch[ch].ics.num_swb = apc->num_bands128;
+            cpe->ch[ch].ics.num_window_groups = 0;
+            cpe->ch[ch].ics.group_len[0] = 1;
+            for(i = 0; i < 8; i++){
+                if((grouping[ch] >> i) & 1){
+                    cpe->ch[ch].ics.group_len[cpe->ch[ch].ics.num_window_groups - 1]++;
+                }else{
+                    cpe->ch[ch].ics.num_window_groups++;
+                    cpe->ch[ch].ics.group_len[cpe->ch[ch].ics.num_window_groups - 1] = 1;
+                }
+            }
         }
-        for(i = 0; i < 8; i++)
-            cpe->ch[ch].ics.group_len[i] = (grouping[ch] >> i) & 1;
     }
     cpe->common_window = chans > 1 && cpe->ch[0].ics.window_sequence[0] == cpe->ch[1].ics.window_sequence[0] && cpe->ch[0].ics.use_kb_window[0] == cpe->ch[1].ics.use_kb_window[0];
     if(cpe->common_window && cpe->ch[0].ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE && grouping[0] != grouping[1])
@@ -588,7 +600,7 @@ static void calc_pe(Psy3gppBand *band, i
 static void psy_3gpp_process(AACPsyContext *apc, int tag, int type, ChannelElement *cpe)
 {
     int start;
-    int ch, w, w2, g, g2, i;
+    int ch, w, wg, g, g2, i;
     int prev_scale;
     Psy3gppContext *pctx = (Psy3gppContext*) apc->model_priv_data;
     float pe_target;
@@ -808,22 +820,19 @@ static void psy_3gpp_process(AACPsyConte
             }
 
         //adjust scalefactors for window groups
-        for(w = 0; w < cpe->ch[ch].ics.num_windows - 1; w++){
+        w = 0;
+        for(wg = 0; wg < cpe->ch[ch].ics.num_window_groups; wg++){
             int min_scale = 256;
 
-            if(cpe->ch[ch].ics.group_len[w]) continue;
-            w2 = w;
-            do{
-                w2++;
-            }while(w2 < cpe->ch[ch].ics.num_windows && cpe->ch[ch].ics.group_len[w2]);
             for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
-                for(i = w; i < w2; i++){
+                for(i = w; i < w + cpe->ch[ch].ics.group_len[wg]; i++){
                     if(cpe->ch[ch].zeroes[i][g]) continue;
                     min_scale = FFMIN(min_scale, cpe->ch[ch].sf_idx[i][g]);
                 }
-                for(i = w; i < w2; i++)
+                for(i = w; i < w + cpe->ch[ch].ics.group_len[wg]; i++)
                     cpe->ch[ch].sf_idx[i][g] = min_scale;
             }
+            w += cpe->ch[ch].ics.group_len[wg];
         }
     }
 



More information about the FFmpeg-soc mailing list