shithub: sox

Download patch

ref: 3693bd730464be34d129f23692eeb998526f0637
parent: b5ec06e5ec6d8c98b765bca29b66dc01ac140947
author: robs <robs>
date: Sun Mar 22 12:50:55 EDT 2009

fix average RMS calcs

--- a/src/stats.c
+++ b/src/stats.c
@@ -94,16 +94,14 @@
 
     p->sigma_x += d;
     p->sigma_x2 += sqr(d);
-
-    if (!p->avg_sigma_x2)
-      p->avg_sigma_x2 = sqr(d);
     p->avg_sigma_x2 = p->avg_sigma_x2 * p->mult + (1 - p->mult) * sqr(d);
 
-    if (p->avg_sigma_x2 > p->max_sigma_x2)
-      p->max_sigma_x2 = p->avg_sigma_x2;
-    else if (p->avg_sigma_x2 < p->min_sigma_x2 && p->num_samples >= p->tc_samples)
-      p->min_sigma_x2 = p->avg_sigma_x2;
-
+    if (p->num_samples >= p->tc_samples) {
+      if (p->avg_sigma_x2 > p->max_sigma_x2)
+        p->max_sigma_x2 = p->avg_sigma_x2;
+      if (p->avg_sigma_x2 < p->min_sigma_x2)
+        p->min_sigma_x2 = p->avg_sigma_x2;
+    }
     p->last = d;
     p->mask |= *ibuf;
   }