[FFmpeg-devel] [PATCH] avfilter/af_dynaudnorm: remove pow2

Ganesh Ajjanagadde gajjanagadde at gmail.com
Wed Nov 25 14:00:48 CET 2015


pow2 is being used for trivial squaring. Its name is not good: is this
2^x or x^2? In any case, using x * x is IMHO more readable in this
context.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
---
 libavfilter/af_dynaudnorm.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/libavfilter/af_dynaudnorm.c b/libavfilter/af_dynaudnorm.c
index 5f412f5..72e3ce8 100644
--- a/libavfilter/af_dynaudnorm.c
+++ b/libavfilter/af_dynaudnorm.c
@@ -309,11 +309,6 @@ static inline double fade(double prev, double next, int pos,
     return fade_factors[0][pos] * prev + fade_factors[1][pos] * next;
 }
 
-static inline double pow2(const double value)
-{
-    return value * value;
-}
-
 static inline double bound(const double threshold, const double val)
 {
     const double CONST = 0.8862269254527580136490837416705725913987747280611935; //sqrt(PI) / 2.0
@@ -352,7 +347,7 @@ static double compute_frame_rms(AVFrame *frame, int channel)
             const double *data_ptr = (double *)frame->extended_data[c];
 
             for (i = 0; i < frame->nb_samples; i++) {
-                rms_value += pow2(data_ptr[i]);
+                rms_value += data_ptr[i] * data_ptr[i];
             }
         }
 
@@ -360,7 +355,7 @@ static double compute_frame_rms(AVFrame *frame, int channel)
     } else {
         const double *data_ptr = (double *)frame->extended_data[channel];
         for (i = 0; i < frame->nb_samples; i++) {
-            rms_value += pow2(data_ptr[i]);
+            rms_value += data_ptr[i] * data_ptr[i];
         }
 
         rms_value /= frame->nb_samples;
@@ -503,7 +498,7 @@ static double compute_frame_std_dev(DynamicAudioNormalizerContext *s,
             const double *data_ptr = (double *)frame->extended_data[c];
 
             for (i = 0; i < frame->nb_samples; i++) {
-                variance += pow2(data_ptr[i]);  // Assume that MEAN is *zero*
+                variance += data_ptr[i] * data_ptr[i];  // Assume that MEAN is *zero*
             }
         }
         variance /= (s->channels * frame->nb_samples) - 1;
@@ -511,7 +506,7 @@ static double compute_frame_std_dev(DynamicAudioNormalizerContext *s,
         const double *data_ptr = (double *)frame->extended_data[channel];
 
         for (i = 0; i < frame->nb_samples; i++) {
-            variance += pow2(data_ptr[i]);      // Assume that MEAN is *zero*
+            variance += data_ptr[i] * data_ptr[i];      // Assume that MEAN is *zero*
         }
         variance /= frame->nb_samples - 1;
     }
-- 
2.6.2



More information about the ffmpeg-devel mailing list