---
 libavcodec/ac3enc.c |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git libavcodec/ac3enc.c libavcodec/ac3enc.c
index db1bfe9..ccf0c28 100644
--- libavcodec/ac3enc.c
+++ libavcodec/ac3enc.c
@@ -351,6 +351,21 @@ static void lshift_tab(int16_t *tab, int n, int lshift)
     }
 }
 
+/**
+ * Normalize the input samples to use the maximum available precision.
+ * This assumes signed 16-bit input samples. Exponents are reduced by 9 to
+ * match the 24-bit internal precision for MDCT coefficients.
+ *
+ * @return exponent shift
+ */
+static int normalize_samples(AC3EncodeContext *s)
+{
+    int v = 14 - log2_tab(s->windowed_samples, AC3_BLOCK_SIZE*2);
+    v = FFMAX(0, v);
+    lshift_tab(s->windowed_samples, AC3_BLOCK_SIZE*2, v);
+    return v - 9;
+}
+
 static void apply_window(int16_t *output, const int16_t *input,
                          const int16_t *window, int n)
 {
@@ -370,7 +385,7 @@ static void apply_window(int16_t *output, const int16_t *input,
 
 static void apply_mdct(AC3EncodeContext *s)
 {
-    int blk, ch, v;
+    int blk, ch;
 
     for (ch = 0; ch < s->channels; ch++) {
         /* fixed mdct to the six sub blocks & exponent computation */
@@ -382,10 +397,7 @@ static void apply_mdct(AC3EncodeContext *s)
                          AC3_BLOCK_SIZE*2);
 
             /* Normalize the samples to use the maximum available precision */
-            v = 14 - log2_tab(s->windowed_samples, AC3_BLOCK_SIZE*2);
-            v = FFMAX(0, v);
-            s->blocks[blk].exp_shift[ch] = v - 9;
-            lshift_tab(s->windowed_samples, AC3_BLOCK_SIZE*2, v);
+            s->blocks[blk].exp_shift[ch] = normalize_samples(s);
 
             /* do the MDCT */
             calc_mdct(&s->mdct, s->blocks[blk].mdct_coef[ch], s->windowed_samples);
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to