shithub: sox

Download patch

ref: 5cb0ea04bbd1c00b2fffd7fe721f00200b2d41d3
parent: 3dd3196e458e37aadcd1ea7d878dbf6e07ac27f3
author: cbagwell <cbagwell>
date: Thu Nov 17 21:06:40 EST 2005

Fix fade effect's fade-out-length to align with man page.

--- a/Changelog
+++ b/Changelog
@@ -40,8 +40,13 @@
     Matthew Hodgson.
   o Add fix to WAV handler to only return data in multiples
     of sample_size*channels to better handle corrupt files.
-  o Fixed bug where "-4" option didn't work with avg effect.
-    (Tom Christie)
+  o Fixed bug where "-4" option didn't work with avg
+    effect (Tom Christie).
+  o Fixed fade's fade-out-length to match man page
+    description as noted by Geoff Kuenning.  This required
+    updates to the sample crossfade scripts.  Also modified fade
+    effect to report when no more samples will be produced to
+    prevent unneeded reading of whole file.
 
 sox-12.17.8
 -----------
--- a/scripts/crossfade.sh
+++ b/scripts/crossfade.sh
@@ -57,7 +57,7 @@
 
 fade_first_opts=
 if [ "$fade_first" != "no" ]; then
-    fade_first_opts="fade t 0 0:0:$fade_length"
+    fade_first_opts="fade t 0 0:0:$fade_length 0:0:$fade_length"
 fi
 
 fade_second_opts=
--- a/scripts/crossfade_cat.sh
+++ b/scripts/crossfade_cat.sh
@@ -49,7 +49,7 @@
 
 fade_first_opts=
 if [ "$fade_first" != "no" ]; then
-    fade_first_opts="fade t 0 0:0:$fade_length"
+    fade_first_opts="fade t 0 0:0:$fade_length 0:0:$fade_length"
 fi
 
 fade_second_opts=
--- a/src/fade.c
+++ b/src/fade.c
@@ -34,7 +34,7 @@
     int endpadwarned;
 } *fade_t;
 
-#define FADE_USAGE "Usage: fade [ type ] fade-in-length [ stop-time [ fade-out-length ] ]\nTimes is hh:mm:ss.fac format.\nFade type one of q, h, t, l or p.\n"
+#define FADE_USAGE "Usage: fade [ type ] fade-in-length [ stop-time [ fade-out-length ] ]\nTime is in hh:mm:ss.frac format.\nFade type one of q, h, t, l or p.\n"
 
 /* prototypes */
 static double fade_gain(st_size_t index, st_size_t range, char fadetype);
@@ -182,13 +182,14 @@
 
         }
         else
-            /* If no start time specified, assume everything
-             * after fadein.
+            /* If user doesn't specify fade out length then
+             * use same length as input side.  This is stored
+             * in in_stop.
              */
-            fade->out_start = fade->in_stop;
+            fade->out_start = fade->out_stop - fade->in_stop;
     }
     else
-        /* If not specified then user doesn't wants to process all 
+        /* If not specified then user wants to process all 
          * of file.  Use a value of zero to indicate this.
          */
         fade->out_stop = 0;
@@ -205,6 +206,8 @@
 
     fade->endpadwarned = 0;
 
+    /* fprintf(stderr, "fade: in_start = %d in_stop = %d out_start = %d out_stop = %d\n", fade->in_start, fade->in_stop, fade->out_start, fade->out_stop); */
+
     return(ST_SUCCESS);
 }
 
@@ -217,7 +220,7 @@
 {
     fade_t fade = (fade_t) effp->priv;
     /* len is total samples, chcnt counts channels */
-    int len = 0, chcnt = 0, t_output = 0;
+    int len = 0, chcnt = 0, t_output = 1, more_output = 1;
     st_sample_t t_ibuf;
 
     len = ((*isamp > *osamp) ? *osamp : *isamp);
@@ -225,7 +228,7 @@
     *osamp = 0;
     *isamp = 0;
 
-    for(; len; len--)
+    for(; len && more_output; len--)
     {
         t_ibuf = (fade->samplesdone < 0 ? 0 : *ibuf);
 
@@ -252,6 +255,9 @@
                               fade->out_fadetype);
             } /* endif fade-out */
 
+            if (!(!fade->do_out || fade->samplesdone < fade->out_stop))
+                more_output = 0;
+
             t_output = 1;
         }
         else
@@ -282,7 +288,14 @@
             fade->samplesdone += 1;
         } /* endif all channels */
     } /* endfor */
-    return(ST_SUCCESS);
+
+    /* If not more samples will be returned, let application know
+     * this.
+     */
+    if (fade->do_out && fade->samplesdone >= fade->out_stop)
+        return ST_EOF;
+    else
+        return ST_SUCCESS;
 }
 
 /*
@@ -317,7 +330,11 @@
             t_chan = 0;
         } /* endif channels */
     } /* endfor */
-    return(ST_SUCCESS);
+
+    if (fade->do_out && fade->samplesdone >= fade->out_stop)
+        return ST_EOF;
+    else
+        return ST_SUCCESS;
 }
 
 /*