shithub: sox

Download patch

ref: 3f980b27d33ed0f73990cd0c4539ab70776e5dfd
parent: 1f952517947a77f08fc0c983869de48051ec33ca
author: robs <robs>
date: Tue Jul 15 03:28:03 EDT 2008

try to solve glitch/delay problems with internet streams

--- a/src/formats.c
+++ b/src/formats.c
@@ -376,6 +376,9 @@
   }
 
   if (!(ft->handler.flags & SOX_FILE_NOSTDIO)) {
+    sox_size_t   input_bufsiz = sox_globals.input_bufsiz?
+        sox_globals.input_bufsiz : sox_globals.bufsiz;
+
     if (!strcmp(path, "-")) { /* Use stdin if the filename is "-" */
       if (sox_globals.stdin_in_use_by) {
         sox_fail("`-' (stdin) already in use by `%s'", sox_globals.stdin_in_use_by);
@@ -387,6 +390,10 @@
     }
     else if ((ft->fp = xfopen(path, "rb")) == NULL) {
       sox_fail("can't open input file `%s': %s", path, strerror(errno));
+      goto error;
+    }
+    if (setvbuf (ft->fp, NULL, _IOFBF, sizeof(char) * input_bufsiz)) {
+      sox_fail("Can't set read buffer");
       goto error;
     }
     ft->seekable = is_seekable(ft);
--- a/src/libsox.c
+++ b/src/libsox.c
@@ -47,6 +47,7 @@
   output_message,
   sox_false,
   8192,
+  0,
   NULL, NULL, NULL};
 
 void sox_output_message(FILE *file, const char *filename, const char *fmt, va_list ap)
--- a/src/sox.c
+++ b/src/sox.c
@@ -1174,6 +1174,7 @@
     {"comment-file"    , required_argument, NULL, 0},
     {"comment"         , required_argument, NULL, 0},
     {"endian"          , required_argument, NULL, 0},
+    {"input-buffer"    , required_argument, NULL, 0},
     {"interactive"     ,       no_argument, NULL, 0},
     {"help-effect"     , required_argument, NULL, 0},
     {"help-format"     , required_argument, NULL, 0},
@@ -1256,8 +1257,8 @@
       case 1:
 #define SOX_BUFMIN 16
         if (sscanf(optarg, "%i %c", &i, &dummy) != 1 || i <= SOX_BUFMIN) {
-        sox_fail("Buffer size `%s' must be > %d", optarg, SOX_BUFMIN);
-        exit(1);
+          sox_fail("Buffer size `%s' must be > %d", optarg, SOX_BUFMIN);
+          exit(1);
         }
         sox_globals.bufsiz = i;
         break;
@@ -1288,26 +1289,34 @@
         break;
 
       case 6:
-        interactive = sox_true;
+        if (sscanf(optarg, "%i %c", &i, &dummy) != 1 || i <= SOX_BUFMIN) {
+          sox_fail("Buffer size `%s' must be > %d", optarg, SOX_BUFMIN);
+          exit(1);
+        }
+        sox_globals.input_bufsiz = i;
         break;
 
       case 7:
-        usage_effect(optarg);
+        interactive = sox_true;
         break;
 
       case 8:
-        usage_format(optarg);
+        usage_effect(optarg);
         break;
 
       case 9:
-        sox_effects_globals.plot = enum_option(option_index, plot_methods);
+        usage_format(optarg);
         break;
 
       case 10:
-        replay_gain_mode = enum_option(option_index, rg_modes);
+        sox_effects_globals.plot = enum_option(option_index, plot_methods);
         break;
 
       case 11:
+        replay_gain_mode = enum_option(option_index, rg_modes);
+        break;
+
+      case 12:
         display_SoX_version(stdout);
         exit(0);
         break;
--- a/src/sox.h
+++ b/src/sox.h
@@ -181,7 +181,7 @@
  * to perform file I/O.  It can be useful to pass in similar sized
  * data to get max performance.
  */
-  sox_size_t   bufsiz;
+  sox_size_t   bufsiz, input_bufsiz;
 
 /* private: */
   char const * stdin_in_use_by;