shithub: sox

Download patch

ref: 339d38d10cbcf13f72694d9503e02d691f673e6c
parent: 28303e73b9099ada0b5cd7ae8520b3658f571315
author: Ulrich Klauer <ulrich@chirlu.de>
date: Mon Sep 26 12:12:24 EDT 2011

Make interactive skipping more robust

Check that we don't jump outside the input file with '<'/'>' in interactive
mode.

Move the 'R' example out of the if(seekable) {...}, as it doesn't need
seeking.

NB. All this is only compiled in if MORE_INTERACTIVE is #defined.

--- a/src/sox.c
+++ b/src/sox.c
@@ -1264,27 +1264,35 @@
     {
       if (ch == '>')
       {
-        read_wide_samples += files[current_input]->ft->signal.rate*30;
-        sox_seek(files[current_input]->ft, read_wide_samples,
-                 SOX_SEEK_SET);
+        uint64_t jump = files[current_input]->ft->signal.rate*30; /* 30 sec. */
+        if (input_wide_samples == 0 ||
+                  read_wide_samples+jump < input_wide_samples) {
+          read_wide_samples += jump;
+          sox_seek(files[current_input]->ft, read_wide_samples,
+                   SOX_SEEK_SET);
+          /* FIXME: Do something if seek fails. */
+        }
       }
       if (ch == '<')
       {
-        read_wide_samples -= files[current_input]->ft->signal.rate*30;
+        uint64_t jump = files[current_input]->ft->signal.rate*30; /* 30 sec. */
+        read_wide_samples = jump < read_wide_samples ?
+            read_wide_samples-jump : 0;
         sox_seek(files[current_input]->ft, read_wide_samples,
                  SOX_SEEK_SET);
+        /* FIXME: Do something if seek fails. */
       }
-      if (ch == 'R')
-      {
-        /* Not very useful, eh!  Sample though of the place you
-         * could change the value to effects options
-         * like vol or speed or mixer.
-         * Modify values in user_effargs[current_eff_chain][xxx]
-         * and then chain will be drain()ed and restarted whence
-         * this function is existed.
-         */
-        user_restart_eff = sox_true;
-      }
+    }
+    if (ch == 'R')
+    {
+      /* Not very useful, eh!  Sample though of the place you
+       * could change the value to effects options
+       * like vol or speed or mixer.
+       * Modify values in user_effargs[current_eff_chain][xxx]
+       * and then chain will be drain()ed and restarted whence
+       * this function is existed.
+       */
+      user_restart_eff = sox_true;
     }
 #endif
     switch (ch) {