---
 libavcodec/ac3enc.c       |  101 +++++++++++++++++++++++++++++++++++++++++---
 libavcodec/ac3enc_fixed.c |   12 -----
 libavcodec/ac3enc_fixed.h |    5 ++
 libavcodec/ac3enc_float.c |   92 -----------------------------------------
 libavcodec/ac3enc_float.h |    5 ++
 5 files changed, 104 insertions(+), 111 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 65774dd..d0dd240 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -363,8 +363,6 @@ static void apply_window(DSPContext *dsp, SampleType *output, const SampleType *
 
 static int normalize_samples(AC3EncodeContext *s);
 
-static void compute_rematrixing(AC3EncodeContext *s);
-
 
 /**
  * LUT for number of exponent groups.
@@ -470,6 +468,98 @@ static void apply_mdct(AC3EncodeContext *s)
 
 
 /**
+ * Determine rematrixing flags for each block and band.
+ */
+static void compute_rematrixing_strategy(AC3EncodeContext *s)
+{
+    int nb_coefs;
+    int blk, bnd, i;
+    AC3Block *block, *block0;
+
+    nb_coefs = FFMIN(s->nb_coefs[0], s->nb_coefs[1]);
+
+    s->blocks[0].new_rematrixing_strategy = 1;
+    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+        block = &s->blocks[blk];
+        for (bnd = 0; bnd < 4; bnd++) {
+            /* calculate calculate sum of squared coeffs for one band in one block */
+            int start = ff_ac3_rematrix_band_tab[bnd];
+            int end   = FFMIN(nb_coefs, ff_ac3_rematrix_band_tab[bnd+1]);
+            CoefSumType sum[4] = {0,};
+            for (i = start; i < end; i++) {
+                CoefType lt = block->mdct_coef[0][i];
+                CoefType rt = block->mdct_coef[1][i];
+                CoefType md = lt + rt;
+                CoefType sd = lt - rt;
+                sum[0] += MULCOEF(lt, lt);
+                sum[1] += MULCOEF(rt, rt);
+                sum[2] += MULCOEF(md, md);
+                sum[3] += MULCOEF(sd, sd);
+            }
+
+            /* compare sums to determine if rematrixing will be used for this band */
+            if (FFMIN(sum[2], sum[3]) < FFMIN(sum[0], sum[1]))
+                block->rematrixing_flags[bnd] = 1;
+            else
+                block->rematrixing_flags[bnd] = 0;
+
+            /* determine if new rematrixing flags will be sent */
+            if (blk &&
+                !block->new_rematrixing_strategy &&
+                block->rematrixing_flags[bnd] != block0->rematrixing_flags[bnd]) {
+                block->new_rematrixing_strategy = 1;
+            }
+        }
+        block0 = block;
+    }
+}
+
+
+/**
+ * Apply stereo rematrixing to coefficients based on rematrixing flags.
+ */
+static void apply_rematrixing(AC3EncodeContext *s)
+{
+    int nb_coefs;
+    int blk, bnd, i;
+    int start, end;
+    uint8_t *flags;
+
+    nb_coefs = FFMIN(s->nb_coefs[0], s->nb_coefs[1]);
+
+    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+        AC3Block *block = &s->blocks[blk];
+        if (block->new_rematrixing_strategy)
+            flags = block->rematrixing_flags;
+        for (bnd = 0; bnd < 4; bnd++) {
+            if (flags[bnd]) {
+                start = ff_ac3_rematrix_band_tab[bnd];
+                end   = FFMIN(nb_coefs, ff_ac3_rematrix_band_tab[bnd+1]);
+                for (i = start; i < end; i++) {
+                    CoefType lt = block->mdct_coef[0][i];
+                    CoefType rt = block->mdct_coef[1][i];
+                    block->mdct_coef[0][i] = RSHIFT1(lt + rt);
+                    block->mdct_coef[1][i] = RSHIFT1(lt - rt);
+                }
+            }
+        }
+    }
+}
+
+
+/**
+ * Determine rematrixing flags and apply rematrixing to coefficients.
+ */
+static void compute_rematrixing(AC3EncodeContext *s)
+{
+    if (!(s->rematrixing & AC3_REMATRIXING_IS_STATIC))
+        compute_rematrixing_strategy(s);
+    if (s->rematrixing != AC3_REMATRIXING_NONE)
+        apply_rematrixing(s);
+}
+
+
+/**
  * Initialize exponent tables.
  */
 static av_cold void exponent_init(AC3EncodeContext *s)
@@ -1982,12 +2072,9 @@ static av_cold void set_bandwidth(AC3EncodeContext *s)
  */
 static void rematrixing_init(AC3EncodeContext *s)
 {
-    if (CONFIG_AC3ENC_FLOAT)
         s->rematrixing = AC3_REMATRIXING_SUMS;
-    else
-        s->rematrixing = AC3_REMATRIXING_NONE;
-    /* NOTE: AC3_REMATRIXING_ALWAYS might be used in the future in conjunction
-             with channel coupling. */
+    /* NOTE: AC3_REMATRIXING_ALWAYS and AC3_REMATRIXING_NONE might be used in
+             the future in conjunction with channel coupling. */
 
     if (s->rematrixing & AC3_REMATRIXING_IS_STATIC) {
         int flag = (s->rematrixing == AC3_REMATRIXING_ALWAYS);
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index 97c0b00..5561c7e 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -319,18 +319,6 @@ static int normalize_samples(AC3EncodeContext *s)
 }
 
 
-/**
- * Determine rematrixing flags and apply rematrixing to coefficients.
- */
-static void compute_rematrixing(AC3EncodeContext *s)
-{
-    /* The fixed-point encoder cannot use rematrixing because it is not
-       accurate enough.  The result always has lower quality. */
-    assert(s->rematrixing == AC3_REMATRIXING_NONE);
-    return;
-}
-
-
 #ifdef TEST
 /*************************************************************************/
 /* TEST */
diff --git a/libavcodec/ac3enc_fixed.h b/libavcodec/ac3enc_fixed.h
index 2d51201..3d9082f 100644
--- a/libavcodec/ac3enc_fixed.h
+++ b/libavcodec/ac3enc_fixed.h
@@ -34,9 +34,14 @@
 
 typedef int16_t SampleType;
 typedef int32_t CoefType;
+typedef int64_t CoefSumType;
 
 #define SCALE_COEF(a) (a)
 
+#define MULCOEF(a,b) MUL64(a,b)
+
+#define RSHIFT1(a) ((a) >> 1)
+
 
 /**
  * Compex number.
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index 936b107..b026139 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -97,98 +97,6 @@ static int normalize_samples(AC3EncodeContext *s)
 }
 
 
-/**
- * Determine rematrixing flags for each block and band.
- */
-static void compute_rematrixing_strategy(AC3EncodeContext *s)
-{
-    int nb_coefs;
-    int blk, bnd, i;
-    AC3Block *block, *block0;
-
-    nb_coefs = FFMIN(s->nb_coefs[0], s->nb_coefs[1]);
-
-    s->blocks[0].new_rematrixing_strategy = 1;
-    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
-        block = &s->blocks[blk];
-        for (bnd = 0; bnd < 4; bnd++) {
-            /* calculate calculate sum of squared coeffs for one band in one block */
-            int start = ff_ac3_rematrix_band_tab[bnd];
-            int end   = FFMIN(nb_coefs, ff_ac3_rematrix_band_tab[bnd+1]);
-            float sum[4] = {0,};
-            for (i = start; i < end; i++) {
-                float lt = block->mdct_coef[0][i];
-                float rt = block->mdct_coef[1][i];
-                float md = lt + rt;
-                float sd = lt - rt;
-                sum[0] += lt * lt;
-                sum[1] += rt * rt;
-                sum[2] += md * md;
-                sum[3] += sd * sd;
-            }
-
-            /* compare sums to determine if rematrixing will be used for this band */
-            if (FFMIN(sum[2], sum[3]) < FFMIN(sum[0], sum[1]))
-                block->rematrixing_flags[bnd] = 1;
-            else
-                block->rematrixing_flags[bnd] = 0;
-
-            /* determine if new rematrixing flags will be sent */
-            if (blk &&
-                !block->new_rematrixing_strategy &&
-                block->rematrixing_flags[bnd] != block0->rematrixing_flags[bnd]) {
-                block->new_rematrixing_strategy = 1;
-            }
-        }
-        block0 = block;
-    }
-}
-
-
-/**
- * Apply stereo rematrixing to coefficients based on rematrixing flags.
- */
-static void apply_rematrixing(AC3EncodeContext *s)
-{
-    int nb_coefs;
-    int blk, bnd, i;
-    int start, end;
-    uint8_t *flags;
-
-    nb_coefs = FFMIN(s->nb_coefs[0], s->nb_coefs[1]);
-
-    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
-        AC3Block *block = &s->blocks[blk];
-        if (block->new_rematrixing_strategy)
-            flags = block->rematrixing_flags;
-        for (bnd = 0; bnd < 4; bnd++) {
-            if (flags[bnd]) {
-                start = ff_ac3_rematrix_band_tab[bnd];
-                end   = FFMIN(nb_coefs, ff_ac3_rematrix_band_tab[bnd+1]);
-                for (i = start; i < end; i++) {
-                    float lt = block->mdct_coef[0][i];
-                    float rt = block->mdct_coef[1][i];
-                    block->mdct_coef[0][i] = (lt + rt) * 0.5;
-                    block->mdct_coef[1][i] = (lt - rt) * 0.5;
-                }
-            }
-        }
-    }
-}
-
-
-/**
- * Determine rematrixing flags and apply rematrixing to coefficients.
- */
-static void compute_rematrixing(AC3EncodeContext *s)
-{
-    if (!(s->rematrixing & AC3_REMATRIXING_IS_STATIC))
-        compute_rematrixing_strategy(s);
-    if (s->rematrixing != AC3_REMATRIXING_NONE)
-        apply_rematrixing(s);
-}
-
-
 AVCodec ac3_encoder = {
     "ac3",
     AVMEDIA_TYPE_AUDIO,
diff --git a/libavcodec/ac3enc_float.h b/libavcodec/ac3enc_float.h
index 1cd3681..09441bf 100644
--- a/libavcodec/ac3enc_float.h
+++ b/libavcodec/ac3enc_float.h
@@ -34,9 +34,14 @@
 
 typedef float SampleType;
 typedef float CoefType;
+typedef float CoefSumType;
 
 #define SCALE_COEF(a) SCALE_FLOAT((a), 24)
 
+#define MULCOEF(a,b) ((a)*(b))
+
+#define RSHIFT1(a) ((a) * 0.5f)
+
 
 typedef struct AC3MDCTContext {
     const float *window;    ///< MDCT window function
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to