---
 libavcodec/ac3dsp.c |   16 +++-------------
 libavcodec/ac3enc.c |   17 +++++++++++++++++
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c
index 8ce5f8d..858e1b8 100644
--- a/libavcodec/ac3dsp.c
+++ b/libavcodec/ac3dsp.c
@@ -164,21 +164,11 @@ static void ac3_extract_exponents_c(uint8_t *exp, int32_t *coef, int nb_coefs)
     int i;
 
     for (i = 0; i < nb_coefs; i++) {
-        int e;
         int v = abs(coef[i]);
         if (v == 0)
-            e = 24;
-        else {
-            e = 23 - av_log2(v);
-            if (e >= 24) {
-                e = 24;
-                coef[i] = 0;
-            } else if (e < 0) {
-                e = 0;
-                coef[i] = av_clip(coef[i], -16777215, 16777215);
-            }
-        }
-        exp[i] = e;
+            exp[i] = 24;
+        else
+            exp[i] = 23 - av_log2(v);
     }
 }
 
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 53f6251..bcdc183 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -525,6 +525,19 @@ static void compute_coupling_strategy(AC3EncodeContext *s)
 
 
 /**
+ * Clip an array of integers to a specified range.
+ * TODO: move to dsputil
+ */
+static void vector_clip_int32(int32_t *dst, int32_t *src, int32_t min,
+                              int32_t max, unsigned int len)
+{
+    int i;
+    for (i = 0; i < len; i++)
+        dst[i] = av_clip(src[i], min, max);
+}
+
+
+/**
  * Calculate a single coupling coordinate.
  */
 static inline float calc_cpl_coord(float energy_ch, float energy_cpl)
@@ -707,6 +720,8 @@ static void apply_channel_coupling(AC3EncodeContext *s)
         s->ac3dsp.float_to_fixed24(fixed_cpl_coords[blk][1],
                                    cpl_coords[blk][1],
                                    s->fbw_channels * 16);
+        vector_clip_int32(fixed_cpl_coords[blk][1], fixed_cpl_coords[blk][1],
+                          -16777215, 16777215, s->fbw_channels * 16);
         s->ac3dsp.extract_exponents(block->cpl_coord_exp[1],
                                     fixed_cpl_coords[blk][1],
                                     s->fbw_channels * 16);
@@ -904,6 +919,8 @@ static void extract_exponents(AC3EncodeContext *s)
     int chan_size = AC3_MAX_COEFS * AC3_MAX_BLOCKS * (s->channels - ch + 1);
     AC3Block *block = &s->blocks[0];
 
+    vector_clip_int32(block->fixed_coef[ch], block->fixed_coef[ch],
+                      -16777215, 16777215, chan_size);
     s->ac3dsp.extract_exponents(block->exp[ch], block->fixed_coef[ch], chan_size);
 }
 
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to