shithub: sox

Download patch

ref: 7c64111a77167811d77d3a7fc164f667d68f9518
parent: 74f6ba33956f58b83348a82de30a81a267ef59de
author: robs <robs>
date: Sat Feb 10 09:06:48 EST 2007

FR [1641335] Make vibro a special case of synth; vibro -> tremolo

--- a/ChangeLog
+++ b/ChangeLog
@@ -54,6 +54,8 @@
   o Added silence padding effect.  (robs)
   o Added ability for noiseprof to use stdout and noisered to use stdin
     [FR# 1621694].  (Reuben Thomas)
+  o vibro effect name deprecated in favour of tremolo; this effect
+    reimplemented as a special case of synth.  (robs)
 
   Other new features:
 
--- a/sox.1
+++ b/sox.1
@@ -115,7 +115,7 @@
 SoX command line.
 .SP
 The following four characteristics are sufficient to describe
-the format of audio data so that it can be processed with SoX:
+the format of audio data such that it can be processed with SoX:
 .TP
 sample rate
 The sample rate in samples per second (`Hertz' or `Hz').  For
@@ -2029,6 +2029,18 @@
 Apply a treble tone-control effect.
 See the description of the \fBbass\fR effect for details.
 .TP
+\fBtremolo \fIspeed\fR [\fIdepth\fR]
+Apply a tremolo (low frequency amplitude modulation) effect to the audio.
+The tremolo frequency in Hz is given by
+.IR speed ,
+and the depth as a percentage by
+.I depth
+(default 40).
+.SP
+Note: This effect is a special case of the
+.B synth
+effect.
+.TP
 \fBtrim \fIstart\fR [\fIlength\fR]
 Trim can trim off unwanted audio from the beginning and end of the
 audio.  Audio is not sent to the output stream until
@@ -2047,17 +2059,6 @@
 it.  A value of 8000s will wait until 8000 samples are read before
 starting to process audio.
 .TP
-\fBvibro \fIspeed\fR [\fIdepth\fR]
-Apply low frequency sinusoidal amplitude modulation to the audio.
-Otherwise known as `tremolo', in the guitar world
-this effect is often referred to as `vibrato' (which in fact
-varies pitch, not amplitude).
-The modulation frequency in Hz is given by
-.I speed
-(0 to 30), and the modulation depth by
-.I depth
-(0 to 1, default 0\*d5).
-.TP
 \fBvol \fIgain\fR [\fItype\fR [\fIlimitergain\fR]]
 Apply an amplification or an attenuation to the audio signal.
 Unlike the
@@ -2151,6 +2152,11 @@
 \fBrate\fR
 Does the same as \fBresample\fR with no parameters; it exists for
 backwards compatibility.
+.TP
+\fBvibro \fIspeed\fR [\fIdepth\fR]
+This is a deprecated alias for the
+.B tremolo
+effect.  It differs in that the depth parameter ranges from 0 to 1 and defaults to 0\*d5.
 .SH DIAGNOSTICS
 Exit status is 0 for no error, 1 if there is a problem with the
 command-line parameters, or 2 if an error occurs during file processing.
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,7 +23,8 @@
 	  flanger.c mcompand.c mixer.c noiseprof.c \
 	  noisered.c noisered.h pad.c pan.c phaser.c pitch.c polyphas.c \
 	  rabbit.c rate.c repeat.c resample.c reverb.c reverse.c silence.c \
-	  skeleff.c speed.c stat.c stretch.c swap.c synth.c trim.c vibro.c vol.c
+	  skeleff.c speed.c stat.c stretch.c swap.c synth.c synth.h tremolo.c \
+	  trim.c vibro.c vol.c
 
 libst_la_SOURCES = $(formats) $(effects) alsa.c oss.c sunaudio.c handlers.c \
 		   misc.c st_i.h stio.c util.c xmalloc.c xmalloc.h \
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -138,6 +138,7 @@
   st_swap_effect_fn,
   st_synth_effect_fn,
   st_treble_effect_fn,
+  st_tremolo_effect_fn,
   st_trim_effect_fn,
   st_vibro_effect_fn,
   st_vol_effect_fn,
--- a/src/st_i.h
+++ b/src/st_i.h
@@ -354,6 +354,7 @@
 extern const st_effect_t *st_swap_effect_fn(void);
 extern const st_effect_t *st_synth_effect_fn(void);
 extern const st_effect_t *st_treble_effect_fn(void);
+extern const st_effect_t *st_tremolo_effect_fn(void);
 extern const st_effect_t *st_trim_effect_fn(void);
 extern const st_effect_t *st_vibro_effect_fn(void);
 extern const st_effect_t *st_vol_effect_fn(void);
--- a/src/synth.c
+++ b/src/synth.c
@@ -14,7 +14,7 @@
 #include <string.h>
 #include <math.h>
 #include <ctype.h>
-#include "st_i.h"
+#include "synth.h"
 
 static st_effect_t st_synth_effect;
 
@@ -237,7 +237,7 @@
  * Don't do initialization now.
  * The 'info' fields are not yet filled in.
  */
-static int st_synth_getopts(eff_t effp, int n, char **argv) 
+int st_synth_getopts(eff_t effp, int n, char **argv) 
 {
     int argn;
     char *hlp;
@@ -365,7 +365,7 @@
  * Prepare processing.
  * Do all initializations.
  */
-static int st_synth_start(eff_t effp)
+int st_synth_start(eff_t effp)
 {
     int i;
     int c;
@@ -643,7 +643,7 @@
             ov = iv * r ;
             break;
         default:
-            st_fail("synth: internel error 2");
+            st_fail("synth: internal error 2");
             break;
     }
 
@@ -655,7 +655,7 @@
 /*
  * Processed signed long samples from ibuf to obuf.
  */
-static int st_synth_flow(eff_t effp, const st_sample_t *ibuf, st_sample_t *obuf, 
+int st_synth_flow(eff_t effp, const st_sample_t *ibuf, st_sample_t *obuf, 
                   st_size_t *isamp, st_size_t *osamp)
 {
     synth_t synth = (synth_t) effp->priv;
--- /dev/null
+++ b/src/synth.h
@@ -1,0 +1,4 @@
+#include "st_i.h"
+int st_synth_getopts(eff_t, int, char * *);
+int st_synth_start(eff_t);
+int st_synth_flow(eff_t, st_sample_t const *, st_sample_t *, st_size_t *, st_size_t *);
--- /dev/null
+++ b/src/tremolo.c
@@ -1,0 +1,48 @@
+/*
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library.  If not, write to the Free Software Foundation,
+ * Fifth Floor, 51 Franklin Street, Boston, MA 02111-1301, USA.
+ */
+
+/* Effect: tremolo  (c) 2007 robs@users.sourceforge.net */
+
+#include "synth.h"
+
+static int getopts(eff_t effp, int n, char * * argv) 
+{
+  double speed, depth = 40;
+  char dummy;     /* To check for extraneous chars. */
+  char offset[100];
+  char * synth_args[] = {"sine", "fmod", 0, 0};
+
+  if (n < 1 || n > 2 ||
+      sscanf(argv[0], "%lf %c", &speed, &dummy) != 1 || speed < 0 ||
+      (n > 1 && sscanf(argv[1], "%lf %c", &depth, &dummy) != 1) ||
+      depth <= 0 || depth > 100) {
+    st_fail(effp->h->usage);
+    return ST_EOF;
+  }
+  synth_args[2] = argv[0];
+  sprintf(offset, "%g", 100 - depth / 2);
+  synth_args[3] = offset;
+  return st_synth_getopts(effp, array_length(synth_args), synth_args);
+}
+
+st_effect_t const * st_tremolo_effect_fn(void)
+{
+  static st_effect_t driver = {
+    "tremolo", "Usage: tremolo speed_Hz [depth_percent];", ST_EFF_MCHAN,
+    getopts, st_synth_start, st_synth_flow, 0, 0, 0,
+  };
+  return &driver;
+}
--- a/src/vibro.c
+++ b/src/vibro.c
@@ -1,127 +1,48 @@
 /*
- * Sound Tools Vibro effect file.
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
  *
- * Modeled on world-famous Fender(TM) Amp Vibro knobs.
- * 
- * Algorithm: generate a sine wave ranging from
- * 0 + depth to 1.0, where signal goes from -1.0 to 1.0.
- * Multiply signal with sine wave.  I think.
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
+ * General Public License for more details.
  *
- * July 5, 1991
- * Copyright 1991 Lance Norskog And Sundry Contributors
- * This source code is freely redistributable and may be used for
- * any purpose.  This copyright notice must be maintained. 
- * Lance Norskog And Sundry Contributors are not responsible for 
- * the consequences of using this software.
- *
- * April 28, 1998 - Chris Bagwell (cbagwell@sprynet.com)
- *
- *  Rearranged some functions so that they are declared before they are
- *  used.  Clears up some compiler warnings.  Because this functions passed
- *  foats, it helped out some dump compilers pass stuff on the stack
- *  correctly.
- *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library.  If not, write to the Free Software Foundation,
+ * Fifth Floor, 51 Franklin Street, Boston, MA 02111-1301, USA.
  */
 
+/* Effect: "vibro" (= tremolo)  (c) 2007 robs@users.sourceforge.net */
 
-#include <math.h>
-#include <stdlib.h>
-#include "st_i.h"
+#include "synth.h"
 
-static st_effect_t st_vibro_effect;
-
-/* Private data for Vibro effect */
-typedef struct vibrostuff {
-        float           speed;
-        float           depth;
-        short           *sinetab;               /* sine wave to apply */
-        int             mult;                   /* multiplier */
-        unsigned        length;                 /* length of table */
-        int             counter;                /* current counter */
-} *vibro_t;
-
-/*
- * Process options
- */
-static int st_vibro_getopts(eff_t effp, int n, char **argv) 
+static int getopts(eff_t effp, int n, char * * argv) 
 {
-        vibro_t vibro = (vibro_t) effp->priv;
+  double speed, depth = 0.5;
+  char dummy;     /* To check for extraneous chars. */
+  char offset[100];
+  char * synth_args[] = {"sine", "fmod", 0, 0};
 
-        vibro->depth = 0.5;
-        if ((n == 0) || !sscanf(argv[0], "%f", &vibro->speed) ||
-                ((n == 2) && !sscanf(argv[1], "%f", &vibro->depth)))
-        {
-                st_fail(st_vibro_effect.usage);
-                return (ST_EOF);
-        }
-        if ((vibro->speed <= 0.001) || (vibro->speed > 30.0) || 
-                        (vibro->depth < 0.0) || (vibro->depth > 1.0))
-        {
-                st_fail("Vibro: speed must be < 30.0, 0.0 < depth < 1.0");
-                return (ST_EOF);
-        }
-        return (ST_SUCCESS);
+  if (n < 1 || n > 2 ||
+      sscanf(argv[0], "%lf %c", &speed, &dummy) != 1 || speed < 0 ||
+      (n > 1 && sscanf(argv[1], "%lf %c", &depth, &dummy) != 1) ||
+      depth <= 0 || depth > 1) {
+    st_fail(effp->h->usage);
+    return ST_EOF;
+  }
+  synth_args[2] = argv[0];
+  sprintf(offset, "%g", 100 - 50 * depth);
+  synth_args[3] = offset;
+  return st_synth_getopts(effp, array_length(synth_args), synth_args);
 }
 
-/*
- * Prepare processing.
- */
-static int st_vibro_start(eff_t effp)
+st_effect_t const * st_vibro_effect_fn(void)
 {
-        vibro_t vibro = (vibro_t) effp->priv;
-
-        vibro->length = effp->ininfo.rate / vibro->speed;
-        vibro->sinetab = (short*) xmalloc(vibro->length * sizeof(short));
-
-        st_generate_wave_table(ST_WAVE_SINE, ST_SHORT,
-            vibro->sinetab, vibro->length, (1 - vibro->depth) * 256, 256, 0);
-        vibro->counter = 0;
-        return (ST_SUCCESS);
-}
-
-/*
- * Processed signed long samples from ibuf to obuf.
- * Return number of samples processed.
- */
-
-static int st_vibro_flow(eff_t effp, const st_sample_t *ibuf, st_sample_t *obuf, 
-                  st_size_t *isamp, st_size_t *osamp)
-{
-        vibro_t vibro = (vibro_t) effp->priv;
-        register int counter, tablen;
-        int len, done;
-        short *sinetab;
-        st_sample_t l;
-
-        len = ((*isamp > *osamp) ? *osamp : *isamp);
-
-        sinetab = vibro->sinetab;
-        counter = vibro->counter;
-        tablen = vibro->length;
-        for(done = 0; done < len; done++) {
-                l = *ibuf++;
-                /* 24x8 gives 32-bit result */
-                *obuf++ = ((l / 256) * sinetab[counter++ % tablen]);
-        }
-        vibro->counter = counter;
-        /* processed all samples */
-        *isamp = *osamp = len;
-        return (ST_SUCCESS);
-}
-
-static st_effect_t st_vibro_effect = {
-  "vibro",
-  "Usage: vibro speed [ depth ]",
-  0,
-  st_vibro_getopts,
-  st_vibro_start,
-  st_vibro_flow,
-  st_effect_nothing_drain,
-  st_effect_nothing,
-  st_effect_nothing
-};
-
-const st_effect_t *st_vibro_effect_fn(void)
-{
-    return &st_vibro_effect;
+  static st_effect_t driver = {
+    "vibro", "Usage: vibro speed [depth]", ST_EFF_MCHAN,
+    getopts, st_synth_start, st_synth_flow, 0, 0, 0,
+  };
+  return &driver;
 }