shithub: sox

Download patch

ref: f28662dc0291b488396a129dee6e60930776483d
parent: a6e11f636cee8f7864b18318043d841417b30e86
author: rrt <rrt>
date: Fri Jan 26 19:36:42 EST 2007

Fix feature request #1621694: allow stdin/out to be used with noisered/prof.

--- a/src/noiseprof.c
+++ b/src/noiseprof.c
@@ -64,7 +64,10 @@
     int i;
    
     if (data->output_filename != NULL) {
-        data->output_file = fopen(data->output_filename, "w");
+        if (strcmp(data->output_filename, "-") != 0)
+          data->output_file = fopen(data->output_filename, "w");
+        else
+          data->output_file = stdout;
         if (data->output_file == NULL) {
             st_fail("Couldn't open output file %s: %s",
                     data->output_filename, strerror(errno));            
@@ -200,9 +203,8 @@
 
     free(data->chandata);
 
-    if (data->output_file != stderr && data->output_file != stdout) {
+    if (data->output_file != stderr && data->output_file != stdout)
         fclose(data->output_file);
-    }       
     
     return (ST_SUCCESS);
 }
--- a/src/noisered.c
+++ b/src/noisered.c
@@ -73,7 +73,7 @@
     int fchannels = 0;
     int channels = effp->ininfo.channels;
     int i;
-    FILE* ifd;
+    FILE* ifp;
 
     data->chandata = (chandata_t*)xcalloc(channels, sizeof(*(data->chandata)));
     data->bufdata = 0;
@@ -84,8 +84,11 @@
     }
 
     /* Here we actually open the input file. */
-    ifd = fopen(data->profile_filename, "r");
-    if (ifd == NULL) {
+    if (strcmp(data->profile_filename, "-") == 0)
+      ifp = stdin;
+    else
+      ifp = fopen(data->profile_filename, "r");
+    if (ifp == NULL) {
         st_fail("Couldn't open profile file %s: %s",
                 data->profile_filename, strerror(errno));            
         return ST_EOF;
@@ -94,7 +97,7 @@
     while (1) {
         int i1;
         float f1;
-        if (2 != fscanf(ifd, " Channel %d: %f", &i1, &f1))
+        if (2 != fscanf(ifp, " Channel %d: %f", &i1, &f1))
             break;
         if (i1 != fchannels) {
             st_fail("noisered: Got channel %d, expected channel %d.",
@@ -104,7 +107,7 @@
 
         data->chandata[fchannels].noisegate[0] = f1;
         for (i = 1; i < FREQCOUNT; i ++) {
-            if (1 != fscanf(ifd, ", %f", &f1)) {
+            if (1 != fscanf(ifp, ", %f", &f1)) {
                 st_fail("noisered: Not enough datums for channel %d "
                         "(expected %d, got %d)", fchannels, FREQCOUNT, i);
                 return ST_EOF;
@@ -118,7 +121,8 @@
                 channels, fchannels);
         return ST_EOF;
     }
-    fclose(ifd);
+    if (strcmp(data->profile_filename, "-") != 0)
+      fclose(ifp);
 
     return (ST_SUCCESS);
 }