shithub: sox

Download patch

ref: ce8890345b99bc622658c7f3476340645a29b9ca
parent: 37052e1b3dccae3eccef61ed37e3930019e3d89d
author: robs <robs>
date: Thu Feb 26 12:41:16 EST 2009

seek hack for crop; fix soxi with invalid option

--- a/src/crop.c
+++ b/src/crop.c
@@ -140,7 +140,6 @@
   return &handler;
 }
 
-#if 0
 size_t sox_crop_get_start(sox_effect_t * effp)
 {
   return ((priv_t *)effp->priv)->pos[0].at;
@@ -151,6 +150,7 @@
   ((priv_t *)effp->priv)->pos[0].at = 0;
 }
 
+#if 0
 /*---------------------- emulation of the `trim' effect ----------------------*/
 
 static int trim_getopts(sox_effect_t * effp, int argc, char * * argv)
--- a/src/sox.c
+++ b/src/sox.c
@@ -1252,6 +1252,19 @@
       }
     }
   }
+  else if (input_count == 1 && effects_chain->length > 1 && strcmp(effects_chain->effects[1][0].handler.name, "crop") == 0) {
+    if (files[0]->ft->handler.seek && files[0]->ft->seekable){
+      uint64_t offset = sox_crop_get_start(&effects_chain->effects[1][0]);
+      if (offset && sox_seek(files[0]->ft, offset, SOX_SEEK_SET) == SOX_SUCCESS) {
+        read_wide_samples = offset / files[0]->ft->signal.channels;
+        /* Assuming a failed seek stayed where it was.  If the seek worked then
+         * reset the start location of crop so that it thinks user didn't
+         * request a skip.  */
+        sox_crop_clear_start(&effects_chain->effects[1][0]);
+        lsx_debug("optimize_crop successful");
+      }
+    }
+  }
 }
 
 static sox_bool overwrite_permitted(char const * filename)
@@ -1715,7 +1728,7 @@
   size_t i;
   static char const * lines[] = {
 "SPECIAL FILENAMES (infile, outfile):",
-"-                        Pipe/redirect input/output (stdin/stdout); use with -t",
+"-                        Pipe/redirect input/output (stdin/stdout); may need -t",
 "-d, --default-device     Use the default audio device (where available)",
 "-n, --null               Use the `null' file handler; e.g. with synth effect",
 "-p, --sox-pipe           Alias for `-t sox -'",
@@ -1729,8 +1742,8 @@
 "--buffer BYTES           Set the size of all processing buffers (default 8192)",
 "--combine concatenate    Concatenate multiple input files (default for sox, rec)",
 "--combine sequence       Sequence multiple input files (default for play)",
-"--effects-file FILENAME  File containing effects and options",
 "-D, --no-dither          Don't dither automatically",
+"--effects-file FILENAME  File containing effects and options",
 "-G, --guard              Use temporary files to guard against clipping",
 "-h, --help               Display version number and usage information",
 "--help-effect NAME       Show usage of effect NAME, or NAME=all for all",
@@ -2489,11 +2502,10 @@
     }
     else if (opt == 'T')
       do_total = sox_true;
-    else type = 1 + (strchr(opts, opt) - opts);
-  if (type > Annotation) {
-    printf("Usage: soxi [-V[level]] [-T] [-t|-r|-c|-s|-d|-D|-b|-B|-e|-a] infile1 ...\n");
-    return -1;
-  }
+    else if ((type = 1 + (strchr(opts, opt) - opts)) > Annotation) {
+      printf("Usage: soxi [-V[level]] [-T] [-t|-r|-c|-s|-d|-D|-b|-B|-e|-a] infile1 ...\n");
+      return -1;
+    }
   if (type == Full)
     do_total = sox_true;
   else if (do_total && (type < Samples || type > Duration_secs)) {
--- a/src/sox.h
+++ b/src/sox.h
@@ -534,6 +534,8 @@
  */
 size_t sox_trim_get_start(sox_effect_t * effp);
 void sox_trim_clear_start(sox_effect_t * effp);
+size_t sox_crop_get_start(sox_effect_t * effp);
+void sox_crop_clear_start(sox_effect_t * effp);
 
 typedef int (* sox_playlist_callback_t)(void *, char *);
 sox_bool sox_is_playlist(char const * filename);