shithub: sox

Download patch

ref: f1424234f9a2ad986f316a9731d31fad6047679b
parent: 2b1a8636761cd1516ecdb90090d28a399ee5c10c
author: robs <robs>
date: Wed Sep 17 02:47:44 EDT 2008

Allow effects to use getopt

--- a/ChangeLog
+++ b/ChangeLog
@@ -37,14 +37,21 @@
   14.1.1   E key                   pitch                   14.1.1 + 6 months
   14.1.1   E pan                   ~= mixer/remix          14.1.1 + 6 months
 
+File formats:
+
+  o Fix WAV write on 64-bit arch.  (robs)
+  o Fix writing PRC ADPCM files.  (Silas Brown)
+
 Effects:
 
   o New `riaa' effect; RIAA vinyl playback EQ.  (robs)
-  o For `rate' effect, change default phase to intermediate; phase,
-    band-width and aliasing now configurable.  (robs)
   o New -b option for the norm effect; can be used to fix stereo
     imbalance.  (robs)
+  o Change default settings for `rate' effect; add -s -L options to
+    be compatible with SoX v14.1.0; phase response, band-width and
+    aliasing now configurable; see man page for details.  (robs)
   o Fix broken audio pass-through with noiseprof effect.  (robs)
+  o Improved documentation for the `stat' effect.  (robs)
   o New --effects-file option to read effects and arguments from
     a file instead of command line. (cbagwell)
 
@@ -66,10 +73,7 @@
     no samplerate.pc exists. (cbagwell)
   o [2038855] external lpc10 lib patch.  (Oden Eriksson, Mandriva)
   o Fix memory leaks in effects chain when restarting effects.
-  o Fix WAV write on 64-bit arch.  (robs)
   o Fixed pkg-config CFLAGS. (evilynux)
-  o Improved documentation for the `stat' effect.  (robs)
-  o Fix writing PRC ADPCM files.  (Silas Brown)
 
 Internal improvements:
 
@@ -76,6 +80,7 @@
   o Fixed all compiler warnings (with gcc 4.3.1, 64-bit arch.).  (robs)
   o Updates to internal effects chain API.  (cbagwell)
   o Retire old FFT routines (speeds up noisered effect).  (robs)
+  o Allow effects to use getopt.  (robs)
 
 
 sox-14.1.0	2008-7-29
--- a/src/effects.c
+++ b/src/effects.c
@@ -16,6 +16,7 @@
  */
 
 #include "sox_i.h"
+#include "getopt.h"
 #include <assert.h>
 #include <string.h>
 #ifdef HAVE_STRINGS_H
@@ -83,7 +84,14 @@
 
 int sox_effect_options(sox_effect_t *effp, int argc, char * const argv[])
 {
-    return effp->handler.getopts(effp, argc, (char * *)argv);
+  int result, callers_optind = optind, callers_opterr = opterr;
+
+  if (effp->handler.flags & SOX_EFF_GETOPT)
+    --argv, ++argc; /* FIXME: push this processing back up the stack */
+  optind = 1, opterr = 0;
+  result = effp->handler.getopts(effp, argc, (char * *)argv);
+  optind = callers_optind, opterr = callers_opterr;
+  return result;
 } /* sox_effect_options */
 
 /* Effects chain: */
--- a/src/sox.h
+++ b/src/sox.h
@@ -432,6 +432,7 @@
 #define SOX_EFF_MCHAN    16          /* Effect can handle multi-channel */
 #define SOX_EFF_NULL     32          /* Effect does nothing */
 #define SOX_EFF_DEPRECATED 64        /* Effect is living on borrowed time */
+#define SOX_EFF_GETOPT   128         /* Effect uses getopt */
 
 typedef enum {sox_plot_off, sox_plot_octave, sox_plot_gnuplot} sox_plot_t;
 typedef struct sox_effect sox_effect_t;
--- a/src/spectrogram.c
+++ b/src/spectrogram.c
@@ -93,11 +93,10 @@
 static int getopts(sox_effect_t * effp, int argc, char **argv)
 {
   priv_t * p = (priv_t *)effp->priv;
-  int c, callers_optind = optind, callers_opterr = opterr;
+  int c;
 
   assert(array_length(p->bit_rev_table) >= (size_t)dft_br_len(MAX_DFT_SIZE));
 
-  --argv, ++argc, optind = 1, opterr = 0;                /* re-jig for getopt */
   p->pixels_per_sec = 100, p->y_size = 2, p->dB_range = 120;/* non-0 defaults */
   p->spectrum_points = 249, p->perm = 1;
   p->out_name = "spectrogram.png", p->comment = "Created by SoX";
@@ -123,8 +122,7 @@
   p->gain = -p->gain;
   --p->y_size, --p->perm;
   p->spectrum_points += 2;
-  argc -= optind, optind = callers_optind, opterr = callers_opterr;
-  return argc || p->win_type == INT_MAX? lsx_usage(effp) : SOX_SUCCESS;
+  return optind !=argc || p->win_type == INT_MAX? lsx_usage(effp) : SOX_SUCCESS;
 }
 
 static double make_window(priv_t * p, int end)
@@ -509,7 +507,8 @@
 sox_effect_handler_t const * sox_spectrogram_effect_fn(void)
 {
   static sox_effect_handler_t handler = {
-    "spectrogram", 0, 0, getopts, start, flow, drain, stop, 0, sizeof(priv_t)};
+    "spectrogram", NULL, SOX_EFF_GETOPT,
+    getopts, start, flow, drain, stop, NULL, sizeof(priv_t)};
   static char const * lines[] = {
     "[options]",
     "\t-x num\tX-axis pixels/second, default 100",