shithub: sox

Download patch

ref: 0ecff9d8c61d217c25a5857eb853a3955df53108
parent: 788a88b7f53da9af5750eda73e493ba9670328e5
author: robs <robs>
date: Wed Apr 1 05:16:40 EDT 2009

experimental divide effect

--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -28,17 +28,17 @@
 
 # Format with: !xargs echo|tr ' ' '\n'|sort|column|expand|sed 's/^/  /'
 set(effects_srcs
-  bend            dither          input           rate            stats
-  biquad          earwax          loudness        remix           stretch
-  biquads         echo            mcompand        repeat          swap
-  chorus          echos           mixer           reverb          synth
-  compand         fade            noiseprof       reverse         tempo
-  compandt        fft4g           noisered        silence         tremolo
-  contrast        filter          output          sinc            trim
-  crop            fir             overdrive       skeleff         vol
-  dcshift         firfit          pad             speed
-  delay           flanger         pan             splice
-  dft_filter      gain            phaser          stat
+  bend            dither          gain            phaser          stat
+  biquad          divide          input           rate            stats
+  biquads         earwax          loudness        remix           stretch
+  chorus          echo            mcompand        repeat          swap
+  compand         echos           mixer           reverb          synth
+  compandt        fade            noiseprof       reverse         tempo
+  contrast        fft4g           noisered        silence         tremolo
+  crop            filter          output          sinc            trim
+  dcshift         fir             overdrive       skeleff         vol
+  delay           firfit          pad             speed
+  dft_filter      flanger         pan             splice
 )
 set(formats_srcs
   8svx            dat             ima-fmt         s3-fmt          u3-fmt
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -59,7 +59,7 @@
 libsox_la_SOURCES += \
 	band.h bend.c biquad.c biquad.h biquads.c chorus.c compand.c crop.c \
 	compandt.c compandt.h contrast.c dcshift.c delay.c dft_filter.c \
-	dft_filter.h dither.c dither.h earwax.c echo.c \
+	dft_filter.h dither.c dither.h divide.c earwax.c echo.c \
 	echos.c effects.c effects.h effects_i.c effects_i_dsp.c fade.c fft4g.c \
 	fft4g.h fifo.h filter.c fir.c firfit.c flanger.c gain.c input.c \
 	ladspa.c loudness.c mcompand.c mcompand_xover.h mixer.c noiseprof.c \
--- /dev/null
+++ b/src/divide.c
@@ -1,0 +1,68 @@
+/* libSoX effect: divide   Copyright (c) 2009 robs@users.sourceforge.net
+ *
+ * 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"
+#include <string.h>
+
+typedef struct {
+  sox_sample_t * last;
+} priv_t;
+
+static int start(sox_effect_t * effp)
+{
+  priv_t * p = (priv_t *)effp->priv;
+  p->last = lsx_calloc(effp->in_signal.channels, sizeof(*p->last));
+  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 i, len =  min(*isamp, *osamp) / effp->in_signal.channels;
+  *osamp = *isamp = len * effp->in_signal.channels;
+
+  while (len--) {
+    double divisor = *obuf++ = *ibuf++;
+    if (divisor) {
+      double out, mult = 1. / SOX_SAMPLE_TO_FLOAT_64BIT(divisor,);
+      for (i = 1; i < effp->in_signal.channels; ++i) {
+        out = *ibuf++ * mult;
+        p->last[i] = *obuf++ = SOX_ROUND_CLIP_COUNT(out, effp->clips);
+      }
+    }
+    else for (i = 1; i < effp->in_signal.channels; ++i, ++ibuf)
+      *obuf++ = p->last[i];
+  }
+  return SOX_SUCCESS;
+}
+
+static int stop(sox_effect_t * effp)
+{
+  priv_t * p = (priv_t *)effp->priv;
+  free(p->last);
+  return SOX_SUCCESS;
+}
+
+sox_effect_handler_t const * lsx_divide_effect_fn(void)
+{
+  static sox_effect_handler_t handler = {
+    "divide", NULL, SOX_EFF_MCHAN | SOX_EFF_GAIN | SOX_EFF_DEPRECATED,
+    NULL, start, flow, NULL, stop, NULL, sizeof(priv_t)
+  };
+  return &handler;
+}
--- a/src/effects.h
+++ b/src/effects.h
@@ -30,6 +30,7 @@
   EFFECT(delay)
   EFFECT(dft_filter) /* abstract */
   EFFECT(dither)
+  EFFECT(divide)
   EFFECT(earwax)
   EFFECT(echo)
   EFFECT(echos)