This will allow for changing the exponent strategies later and
recalculating the final exponents.
---
 libavcodec/ac3enc.c |   90 +++++++++++++++++++++++++++++++++-----------------
 1 files changed, 59 insertions(+), 31 deletions(-)

diff --git libavcodec/ac3enc.c libavcodec/ac3enc.c
index 425b842..0f876e8 100644
--- libavcodec/ac3enc.c
+++ libavcodec/ac3enc.c
@@ -304,6 +304,38 @@ static void apply_mdct(AC3EncodeContext *s,
     }
 }
 
+/**
+ * Calculate MDCT coefficient exponents.
+ */
+static void calculate_exponents(AC3EncodeContext *s,
+                                int32_t mdct_coef[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
+                                uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
+                                int8_t exp_shift[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS])
+{
+    int ch, blk, i, v;
+
+    for (ch = 0; ch < s->channels; ch++) {
+        /* fixed mdct to the six sub blocks & exponent computation */
+        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+            /* compute "exponents". We take into account the normalization there */
+            for (i = 0; i < AC3_MAX_COEFS; i++) {
+                int e;
+                v = abs(mdct_coef[blk][ch][i]);
+                if (v == 0)
+                    e = 24;
+                else {
+                    e = 23 - av_log2(v) + exp_shift[blk][ch];
+                    if (e >= 24) {
+                        e = 24;
+                        mdct_coef[blk][ch][i] = 0;
+                    }
+                }
+                exp[blk][ch][i] = e;
+            }
+        }
+    }
+}
+
 /* XXX: use another norm ? */
 static int calc_exp_diff(uint8_t *exp1, uint8_t *exp2, int n)
 {
@@ -434,41 +466,19 @@ static int encode_exp_blk_ch(uint8_t *exp, int nb_exps, int exp_strategy)
     return 4 + (nb_groups / 3) * 7;
 }
 
-static void process_exponents(AC3EncodeContext *s,
-                              int32_t mdct_coef[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
-                              uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
-                              uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
-                              int8_t exp_shift[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
-                              int *frame_bits)
+/**
+ * Compute the exponents as the decoder will see them.
+ * The EXP_REUSE case must be handled carefully : we select the min of the exponents.
+ */
+static void encode_exponents(AC3EncodeContext *s,
+                             uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
+                             uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
+                             int *frame_bits)
 {
-    int ch, blk, i, v;
+    int ch, blk;
 
     *frame_bits = 0;
     for (ch = 0; ch < s->channels; ch++) {
-        /* fixed mdct to the six sub blocks & exponent computation */
-        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
-            /* compute "exponents". We take into account the normalization there */
-            for (i = 0; i < AC3_MAX_COEFS; i++) {
-                int e;
-                v = abs(mdct_coef[blk][ch][i]);
-                if (v == 0)
-                    e = 24;
-                else {
-                    e = 23 - av_log2(v) + exp_shift[blk][ch];
-                    if (e >= 24) {
-                        e = 24;
-                        mdct_coef[blk][ch][i] = 0;
-                    }
-                }
-                exp[blk][ch][i] = e;
-            }
-        }
-
-        compute_exp_strategy(exp_strategy, exp, ch, ch == s->lfe_ch);
-
-        /* compute the exponents as the decoder will see them. The
-           EXP_REUSE case must be handled carefully : we select the
-           min of the exponents */
         blk = 0;
         while (blk < AC3_MAX_BLOCKS) {
             int blk2;
@@ -489,6 +499,24 @@ static void process_exponents(AC3EncodeContext *s,
     }
 }
 
+static void process_exponents(AC3EncodeContext *s,
+                              int32_t mdct_coef[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
+                              uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
+                              uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
+                              int8_t exp_shift[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
+                              int *frame_bits)
+{
+    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);
+    }
+
+    encode_exponents(s, exp, exp_strategy, frame_bits);
+}
+
 /* return the size in bits taken by the mantissa */
 static int compute_mantissa_size(AC3EncodeContext *s, uint8_t *m, int nb_coefs)
 {
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to