ref: a2fec7d4c67b8b7cea4604c449b413cc124e6ba8
parent: 42f5e3e079a4af7721934193b6854c9baeba4b93
author: robs <robs>
date: Sat Nov 15 14:43:37 EST 2008
new overdrive effect
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -28,16 +28,16 @@
# Format with: !xargs echo|tr ' ' '\n'|sort|column|expand|sed 's/^/ /'
set(effects_srcs
- bend earwax mixer remix stretch
- biquad echo noiseprof repeat swap
- biquads echos noisered resample synth
- chorus fade normalise reverb tempo
- compand fft4g output reverse tremolo
- compandt filter pad silence trim
- contrast flanger pan skeleff vol
- dcshift input phaser speed
- delay loudness polyphas splice
- dither mcompand rate stat
+ bend earwax mixer rate stat
+ biquad echo noiseprof remix stretch
+ biquads echos noisered repeat swap
+ chorus fade normalise resample synth
+ compand fft4g output reverb tempo
+ compandt filter overdrive reverse tremolo
+ contrast flanger pad silence trim
+ dcshift input pan skeleff vol
+ delay loudness phaser speed
+ dither mcompand polyphas splice
)
set(formats_srcs
8svx dat ima-fmt s3-fmt u3-fmt
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -268,7 +268,7 @@
polyphas.c rabbit.c rate.c rate_filters.h rate_half_fir.h \
rate_poly_fir0.h rate_poly_fir.h remix.c repeat.c resample.c reverb.c \
reverse.c silence.c skeleff.c speed.c splice.c stat.c swap.c stretch.c \
- synth.c tempo.c tremolo.c trim.c vol.c
+ synth.c tempo.c tremolo.c trim.c vol.c overdrive.c
if HAVE_PNG
libsox_la_SOURCES += spectrogram.c
endif
--- a/src/effects.h
+++ b/src/effects.h
@@ -51,6 +51,7 @@
EFFECT(norm)
EFFECT(oops)
EFFECT(output)
+ EFFECT(overdrive)
EFFECT(pad)
EFFECT(pan)
EFFECT(phaser)
--- /dev/null
+++ b/src/overdrive.c
@@ -1,0 +1,78 @@
+/* libSoX effect: Overdrive (c) 2008 [email protected]
+ *
+ * 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.1 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,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "sox_i.h"
+
+typedef struct {
+ double gain, colour, last_in, last_out, b0, b1, a1;
+} priv_t;
+
+static int create(sox_effect_t * effp, int argc, char * * argv)
+{
+ priv_t * p = (priv_t *)effp->priv;
+ p->gain = p->colour = 20;
+ do {
+ NUMERIC_PARAMETER(gain, 0, 100)
+ NUMERIC_PARAMETER(colour, 0, 100)
+ } while (0);
+ p->gain = dB_to_linear(p->gain);
+ p->colour /= 200;
+ return argc? lsx_usage(effp) : SOX_SUCCESS;
+}
+
+static int start(sox_effect_t * effp)
+{
+ priv_t * p = (priv_t *)effp->priv;
+ double fc = 10;
+ double w0 = 2 * M_PI * fc / effp->in_signal.rate;
+
+ if (p->gain == 1)
+ return SOX_EFF_NULL;
+
+ if (w0 > M_PI) {
+ lsx_fail("frequency must be less than half the sample-rate (Nyquist rate)");
+ return SOX_EOF;
+ }
+ p->a1 = -exp(-w0);
+ p->b0 = (1 - p->a1)/2;
+ p->b1 = -p->b0;
+ return SOX_SUCCESS;
+}
+
+static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
+ sox_sample_t * obuf, size_t * isamp, size_t * osamp)
+{
+ priv_t * p = (priv_t *)effp->priv;
+ size_t dummy = 0, len = *isamp = *osamp = min(*isamp, *osamp);
+ while (len--) {
+ double d = SOX_SAMPLE_TO_FLOAT_64BIT(*ibuf++, dummy);
+ d *= p->gain;
+ d += p->colour;
+ d = d < -1? -2./3 : d > 1? 2./3 : d - d * d * d * (1./3);
+ p->last_out = p->b0 * d + p->b1 * p->last_in - p->a1 * p->last_out;
+ p->last_in = d;
+ *obuf++ = SOX_FLOAT_64BIT_TO_SAMPLE(p->last_out, dummy);
+ }
+ return SOX_SUCCESS;
+}
+
+sox_effect_handler_t const * sox_overdrive_effect_fn(void)
+{
+ static sox_effect_handler_t handler = {"overdrive", "[gain [colour]]",
+ SOX_EFF_MCHAN, create, start, flow, NULL, NULL, NULL, sizeof(priv_t)};
+ return &handler;
+}