---
 libavcodec/ac3enc.h          |    2 ++
 libavcodec/ac3enc_fixed.c    |    1 +
 libavcodec/ac3enc_template.c |   24 ++++++++++++++++++------
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index c8fe0c9..890c753 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -52,6 +52,7 @@
 #define MAC_COEF(d,a,b) ((d)+=(a)*(b))
 #define COEF_MIN (-16777215.0/16777216.0)
 #define COEF_MAX ( 16777215.0/16777216.0)
+#define NEW_CPL_COORD_THRESHOLD 0.03
 typedef float SampleType;
 typedef float CoefType;
 typedef float CoefSumType;
@@ -60,6 +61,7 @@ typedef float CoefSumType;
 #define MAC_COEF(d,a,b) MAC64(d,a,b)
 #define COEF_MIN -16777215
 #define COEF_MAX  16777215
+#define NEW_CPL_COORD_THRESHOLD 503317
 typedef int16_t SampleType;
 typedef int32_t CoefType;
 typedef int64_t CoefSumType;
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index 951b73d..f1dc98b 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -29,6 +29,7 @@
 #define CONFIG_FFT_FLOAT 0
 #undef CONFIG_AC3ENC_FLOAT
 #include "ac3enc.h"
+#include "eac3enc.h"
 
 #define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED
 #include "ac3enc_opts_template.c"
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 74f4b21..fa09809 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -121,12 +121,16 @@ static void apply_mdct(AC3EncodeContext *s)
 /**
  * Calculate a single coupling coordinate.
  */
-static inline float calc_cpl_coord(float energy_ch, float energy_cpl)
+static inline CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType 
energy_cpl)
 {
+#if CONFIG_AC3ENC_FLOAT
     float coord = 0.125;
     if (energy_cpl > 0)
         coord *= sqrtf(energy_ch / energy_cpl);
     return FFMIN(coord, COEF_MAX);
+#else
+    return 1048576;
+#endif
 }
 
 
@@ -140,9 +144,12 @@ static inline float calc_cpl_coord(float energy_ch, float 
energy_cpl)
  */
 static void apply_channel_coupling(AC3EncodeContext *s)
 {
+    LOCAL_ALIGNED_16(CoefType, cpl_coords,      [AC3_MAX_BLOCKS], 
[AC3_MAX_CHANNELS][16]);
 #if CONFIG_AC3ENC_FLOAT
-    LOCAL_ALIGNED_16(float,   cpl_coords,       [AC3_MAX_BLOCKS], 
[AC3_MAX_CHANNELS][16]);
     LOCAL_ALIGNED_16(int32_t, fixed_cpl_coords, [AC3_MAX_BLOCKS], 
[AC3_MAX_CHANNELS][16]);
+#else
+#define fixed_cpl_coords cpl_coords
+#endif
     int blk, ch, bnd, i, j;
     CoefSumType energy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}};
     int cpl_start, num_cpl_coefs;
@@ -174,9 +181,11 @@ static void apply_channel_coupling(AC3EncodeContext *s)
         /* coefficients must be clipped in order to be encoded */
         clip_coefficients(&s->dsp, cpl_coef, num_cpl_coefs);
 
+#if CONFIG_AC3ENC_FLOAT
         /* scale coupling coefficients from float to 24-bit fixed-point */
         s->ac3dsp.float_to_fixed24(&block->fixed_coef[CPL_CH][cpl_start],
                                    cpl_coef, num_cpl_coefs);
+#endif
     }
 
     /* calculate energy in each band in coupling channel and each fbw channel 
*/
@@ -240,11 +249,11 @@ static void apply_channel_coupling(AC3EncodeContext *s)
                     } else {
                         CoefSumType coord_diff = 0;
                         for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
-                            coord_diff += fabs(cpl_coords[blk-1][ch][bnd] -
-                                               cpl_coords[blk  ][ch][bnd]);
+                            coord_diff += FFABS(cpl_coords[blk-1][ch][bnd] -
+                                                cpl_coords[blk  ][ch][bnd]);
                         }
                         coord_diff /= s->num_cpl_bands;
-                        if (coord_diff > 0.03)
+                        if (coord_diff > NEW_CPL_COORD_THRESHOLD)
                             block->new_cpl_coords[ch] = 1;
                     }
                 }
@@ -291,9 +300,11 @@ static void apply_channel_coupling(AC3EncodeContext *s)
         if (!block->cpl_in_use)
             continue;
 
+#if CONFIG_AC3ENC_FLOAT
         s->ac3dsp.float_to_fixed24(fixed_cpl_coords[blk][1],
                                    cpl_coords[blk][1],
                                    s->fbw_channels * 16);
+#endif
         s->ac3dsp.extract_exponents(block->cpl_coord_exp[1],
                                     fixed_cpl_coords[blk][1],
                                     s->fbw_channels * 16);
@@ -337,7 +348,8 @@ static void apply_channel_coupling(AC3EncodeContext *s)
 
     if (CONFIG_EAC3_ENCODER && s->eac3)
         ff_eac3_set_cpl_states(s);
-#endif /* CONFIG_AC3ENC_FLOAT */
+
+#undef fixed_cpl_coords
 }
 
 
-- 
1.7.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to