shithub: sox

Download patch

ref: c087ed916c26e51986bd2b17df57d98988435427
parent: 41bb7cc1dd2f4ec895d9ef7340534eec236e3270
author: Rob Sykes <robs@users.sourceforge.net>
date: Thu Dec 29 09:42:31 EST 2011

fix bug when fading out immediately after fading in could fail due to rounding to integer numbers of samples

--- a/src/fade.c
+++ b/src/fade.c
@@ -170,17 +170,19 @@
          */
         fade->out_stop = 0;
 
-    /* Sanity check for fade times vs total time */
-    if (fade->in_stop > fade->out_start && fade->out_start != 0)
-    { /* Fades too long */
-        lsx_fail("Fade: End of fade-in should not happen before beginning of fade-out");
-        return(SOX_EOF);
-    } /* endif fade time sanity */
+    if (fade->out_start) {              /* Sanity check */
+      if (fade->in_stop > fade->out_start)
+        --fade->in_stop;                /* 1 sample grace for rounding error. */
+      if (fade->in_stop > fade->out_start) {
+        lsx_fail("fade-out overlaps fade-in");
+        return SOX_EOF;
+      }
+    }
 
     fade->samplesdone = fade->in_start;
     fade->endpadwarned = 0;
 
-    lsx_debug("fade: in_start = %lu in_stop = %lu out_start = %lu out_stop = %lu", (unsigned long)fade->in_start, (unsigned long)fade->in_stop, (unsigned long)fade->out_start, (unsigned long)fade->out_stop);
+    lsx_debug("in_start = %lu in_stop = %lu out_start = %lu out_stop = %lu", (unsigned long)fade->in_start, (unsigned long)fade->in_stop, (unsigned long)fade->out_start, (unsigned long)fade->out_stop);
 
     if (fade->in_start == fade->in_stop && !truncate &&
         fade->out_start == fade->out_stop)