shithub: sox

Download patch

ref: 9060bb6d117723e7425cb0213fb051878a26f387
parent: 0519583288057272ec626e6ad391be44a75574d9
author: robs <robs>
date: Mon Oct 27 03:58:55 EDT 2008

Fix [2007062] Earwax effect can overflow; should clip

--- a/ChangeLog
+++ b/ChangeLog
@@ -64,6 +64,7 @@
   o Fix graph legend display when using --plot octave.  (robs)
   o Fix rare crash with `rate' effect.  (robs)
   o Fix [2190767] `norm' under-amplifying in some cases.  (George Yohng)
+  o Fix [2007062] Earwax effect can overflow; should clip. (robs)
   o Trim will now skip past 2G point correctly. (cbagwell)
   o Improved handling of speed changes in the effects chain.  (robs)
 
--- a/src/earwax.c
+++ b/src/earwax.c
@@ -72,14 +72,15 @@
   size_t i, len = *isamp = *osamp = min(*isamp, *osamp);
 
   while (len--) {       /* update taps and calculate output */
-    sox_sample_t output = 0;
+    double output = 0;
 
     for (i = NUMTAPS - 1; i; --i) {
       p->tap[i] = p->tap[i - 1];
       output += p->tap[i] * filt[i];
     }
-    p->tap[0] = *ibuf++ / 64;
-    *obuf++ = output + p->tap[0] * filt[0];   /* store scaled output */
+    p->tap[0] = *ibuf++ / 64; /* scale output */
+    output += p->tap[0] * filt[0];
+    *obuf++ = SOX_ROUND_CLIP_COUNT(output, effp->clips);
   }
   return SOX_SUCCESS;
 }