This is slightly more complicated but it makes the per-channel calculation more 
generic in terms of the data structure of exponents and exponent strategies. 
This will allow different algorithms to be more easily plugged in to the 
encoder.
---
 libavcodec/ac3enc.c |   47 +++++++++++++++++++++++++++++++----------------
 1 files changed, 31 insertions(+), 16 deletions(-)

diff --git libavcodec/ac3enc.c libavcodec/ac3enc.c
index 0db0846..5760794 100644
--- libavcodec/ac3enc.c
+++ libavcodec/ac3enc.c
@@ -361,25 +361,25 @@ static int calc_exp_diff(uint8_t *exp1, uint8_t *exp2, int n)
     return sum;
 }
 
-static void compute_exp_strategy(uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
-                                 uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
-                                 int ch, int is_lfe)
+static void compute_exp_strategy_ch(uint8_t exp_strategy[AC3_MAX_BLOCKS],
+                                    uint8_t *exp[AC3_MAX_BLOCKS],
+                                    int is_lfe)
 {
     int blk, blk1;
     int exp_diff;
 
     /* estimate if the exponent variation & decide if they should be
        reused in the next frame */
-    exp_strategy[0][ch] = EXP_NEW;
+    exp_strategy[0] = EXP_NEW;
     for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) {
-        exp_diff = calc_exp_diff(exp[blk][ch], exp[blk-1][ch], AC3_MAX_COEFS);
+        exp_diff = calc_exp_diff(exp[blk], exp[blk-1], AC3_MAX_COEFS);
 #ifdef DEBUG_EXPONENTS
         dprintf(NULL, "exp_diff=%d\n", exp_diff);
 #endif
         if (exp_diff > EXP_DIFF_THRESHOLD)
-            exp_strategy[blk][ch] = EXP_NEW;
+            exp_strategy[blk] = EXP_NEW;
         else
-            exp_strategy[blk][ch] = EXP_REUSE;
+            exp_strategy[blk] = EXP_REUSE;
     }
     if (is_lfe)
         return;
@@ -389,24 +389,43 @@ static void compute_exp_strategy(uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CH
     blk = 0;
     while (blk < AC3_MAX_BLOCKS) {
         blk1 = blk + 1;
-        while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1][ch] == EXP_REUSE)
+        while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE)
             blk1++;
         switch(blk1 - blk) {
         case 1:
-            exp_strategy[blk][ch] = EXP_D45;
+            exp_strategy[blk] = EXP_D45;
             break;
         case 2:
         case 3:
-            exp_strategy[blk][ch] = EXP_D25;
+            exp_strategy[blk] = EXP_D25;
             break;
         default:
-            exp_strategy[blk][ch] = EXP_D15;
+            exp_strategy[blk] = EXP_D15;
             break;
         }
         blk = blk1;
     }
 }
 
+static void compute_exp_strategy(AC3EncodeContext *s,
+                                 uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
+                                 uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS])
+{
+    uint8_t *exp1[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS];
+    uint8_t exp_str1[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS];
+    int ch, blk;
+
+    for (ch = 0; ch < s->fbw_channels; ch++) {
+        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+            exp1[ch][blk] = exp[blk][ch];
+            exp_str1[ch][blk] = exp_strategy[blk][ch];
+        }
+        compute_exp_strategy_ch(exp_str1[ch], exp1[ch], ch == s->lfe_ch);
+        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
+            exp_strategy[blk][ch] = exp_str1[ch][blk];
+    }
+}
+
 /* set exp[i] to min(exp[i], exp1[i]) */
 static void exponent_min(uint8_t exp[AC3_MAX_COEFS], uint8_t exp1[AC3_MAX_COEFS], int n)
 {
@@ -521,13 +540,9 @@ static void process_exponents(AC3EncodeContext *s,
                               uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
                               int8_t exp_shift[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS])
 {
-    int ch;
-
     calculate_exponents(s, mdct_coef, exp, exp_shift);
 
-    for (ch = 0; ch < s->channels; ch++) {
-        compute_exp_strategy(exp_strategy, exp, ch, ch == s->lfe_ch);
-    }
+    compute_exp_strategy(s, exp_strategy, exp);
 
     encode_exponents(s, exp, exp_strategy);
 }
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to