shithub: sox

Download patch

ref: 3fa0b14620e9c84c1fac5eb6e70b5db93b2bf4af
parent: 5fce40be10e904ddbc195b93bccfd212c3d91e73
author: robs <robs>
date: Sat Jan 13 14:57:25 EST 2007

Allow rec ifile to use ofile fopts (rate,chans).

--- a/src/sox.c
+++ b/src/sox.c
@@ -308,11 +308,11 @@
       st_fail("Too many filenames; maximum is %d input files and 1 output file", MAX_INPUT_FILES);
       exit(1);
     }
-    file_count++;
 
     for (i = 0; i < file_count; i++)
       file_opts[i + 1] = file_opts[i];
 
+    file_count++;
     set_device(fo);
     file_opts[0] = fo;
   }
@@ -341,10 +341,29 @@
     if (combine_method == SOX_MIX && !uservolume)
       file_opts[i]->volume = 1.0 / input_count;
       
-    file_desc[i] = st_open_read(file_opts[i]->filename,
+    if (!rec || i) {
+      file_desc[i] = st_open_read(file_opts[i]->filename,
                                 &file_opts[i]->signal, 
                                 file_opts[i]->filetype);
-    if (!file_desc[i])
+      if (!file_desc[i])
+        /* st_open_read() will call st_warn for most errors.
+         * Rely on that printing something. */
+        exit(2);
+    }
+  }
+  if (rec) { /* Set the recording sample rate & # of channels: */
+    if (input_count > 1) {   /* Get them from the next input file: */
+      file_opts[0]->signal.rate = file_desc[1]->signal.rate;
+      file_opts[0]->signal.channels = file_desc[1]->signal.channels;
+    }
+    else { /* Get them from the output file (which is not open yet): */
+      file_opts[0]->signal.rate = file_opts[1]->signal.rate;
+      file_opts[0]->signal.channels = file_opts[1]->signal.channels;
+    }
+    file_desc[0] = st_open_read(file_opts[0]->filename,
+                              &file_opts[0]->signal, 
+                              file_opts[0]->filetype);
+    if (!file_desc[0])
       /* st_open_read() will call st_warn for most errors.
        * Rely on that printing something. */
       exit(2);