shithub: sox

Download patch

ref: 3b1bd3aab4f4e150607603fb3ab2c050a5d2364c
parent: e88bfd2ca91dd41cefdd882b7859d68fca48820e
author: robs <robs>
date: Mon Jul 9 14:53:52 EDT 2007

Commonalise some macros

--- a/src/flanger.c
+++ b/src/flanger.c
@@ -103,42 +103,15 @@
 
 
 
-#define NUMERIC_PARAMETER(p, min, max) { \
-  char * end_ptr; \
-  double d; \
-  if (argc == 0) break; \
-  d = strtod(*argv, &end_ptr); \
-  if (end_ptr != *argv) { \
-    if (d < min || d > max || *end_ptr != '\0') \
-      return sox_usage(effp); \
-    f->p = d; \
-    --argc, ++argv; \
-  } \
-}
-
-
-
-#define TEXTUAL_PARAMETER(p, enum_table) { \
-  enum_item const * e; \
-  if (argc == 0) break; \
-  e = find_enum_text(*argv, enum_table); \
-  if (e != NULL) { \
-    f->p = e->value; \
-    --argc, ++argv; \
-  } \
-}
-
-
-
 static int sox_flanger_getopts(sox_effect_t * effp, int argc, char *argv[])
 {
-  flanger_t f = (flanger_t) effp->priv;
+  flanger_t p = (flanger_t) effp->priv;
 
   /* Set non-zero defaults: */
-  f->delay_depth  = 2;
-  f->delay_gain   = 71;
-  f->speed        = 0.5;
-  f->channel_phase= 25;
+  p->delay_depth  = 2;
+  p->delay_gain   = 71;
+  p->speed        = 0.5;
+  p->channel_phase= 25;
 
   do { /* break-able block */
     NUMERIC_PARAMETER(delay_min    , 0  , 10 )
@@ -163,14 +136,14 @@
       "shape = %s\n"
       "phase = %g%%\n"
       "interp= %s",
-      f->delay_min,
-      f->delay_depth,
-      f->feedback_gain,
-      f->delay_gain,
-      f->speed,
-      sox_wave_enum[f->wave_shape].text,
-      f->channel_phase,
-      interp_enum[f->interpolation].text);
+      p->delay_min,
+      p->delay_depth,
+      p->feedback_gain,
+      p->delay_gain,
+      p->speed,
+      sox_wave_enum[p->wave_shape].text,
+      p->channel_phase,
+      interp_enum[p->interpolation].text);
 
   return SOX_SUCCESS;
 }
--- a/src/noisered.c
+++ b/src/noisered.c
@@ -16,19 +16,6 @@
 #include <string.h>
 #include <assert.h>
 
-#define NUMERIC_PARAMETER(p, min, max) { \
-  char * end_ptr; \
-  double d; \
-  if (argc == 0) break; \
-  d = strtod(*argv, &end_ptr); \
-  if (end_ptr != *argv) { \
-    if (d < min || d > max || *end_ptr != '\0') \
-      return sox_usage(effp); \
-    this->p = d; \
-    --argc, ++argv; \
-  } \
-}
-
 typedef struct chandata {
     float *window;
     float *lastwindow;
@@ -51,15 +38,15 @@
  */
 static int sox_noisered_getopts(sox_effect_t * effp, int argc, char **argv)
 {
-  reddata_t this = (reddata_t) effp->priv;
+  reddata_t p = (reddata_t) effp->priv;
 
   if (argc > 0) {
-    this->profile_filename = argv[0];
+    p->profile_filename = argv[0];
     ++argv;
     --argc;
   }
 
-  this->threshold = 0.5;
+  p->threshold = 0.5;
   do {     /* break-able block */
     NUMERIC_PARAMETER(threshold, 0, 1);
   } while (0);
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -327,4 +327,29 @@
 #include "effects.h"
 #undef EFFECT
 
+#define NUMERIC_PARAMETER(name, min, max) { \
+  char * end_ptr; \
+  double d; \
+  if (argc == 0) break; \
+  d = strtod(*argv, &end_ptr); \
+  if (end_ptr != *argv) { \
+    if (d < min || d > max || *end_ptr != '\0') {\
+      sox_fail("parameter `%s' must be between %g and %g", #name, (double)min, (double)max); \
+      return sox_usage(effp); \
+    } \
+    p->name = d; \
+    --argc, ++argv; \
+  } \
+}
+
+#define TEXTUAL_PARAMETER(name, enum_table) { \
+  enum_item const * e; \
+  if (argc == 0) break; \
+  e = find_enum_text(*argv, enum_table); \
+  if (e != NULL) { \
+    p->name = e->value; \
+    --argc, ++argv; \
+  } \
+}
+
 #endif