shithub: sox

Download patch

ref: 1fdbf2dc755989f40985fa3e43761ba16b57e879
parent: 0616603970338b131a5abe19a0ee825faebf4f85
author: robs <robs>
date: Mon Mar 10 20:08:31 EDT 2008

contrast enhancement effect

--- a/AUTHORS
+++ b/AUTHORS
@@ -19,7 +19,8 @@
                 24bit support for popular formats, MP3 tags & duration support.
 		Effects: key, tempo, pad, bass, treble, delay, new reverb, new
 		flanger, soft-knee companding, speed via resampling, filters
-		makeover inc. gnuplot & octave plotting, splice, remix, norm;
+		makeover inc. gnuplot & octave plotting, splice, remix, norm,
+		contrast;
 		new effects chain with buffering and any # channels.
                 Others: open input files via URL, file multiply/merge, play
                 multiple files with mixed format types, play with replay-gain,
--- a/ChangeLog
+++ b/ChangeLog
@@ -47,6 +47,7 @@
   o New `remix' effect; complements the mixer effect.  (robs)
   o New `norm' (normalise) effect.  (robs)
   o New `delay' effect; delay one or more channels.  (robs)
+  o New `contrast' enhancement effect [FR 708923].  (robs)
   o Fix crash on 64-bit arch. with tempo & key effects.  (Sami Liedes)
   o Fix synth max. level setting for some output encodings.  (robs)
   o `gain' alias for the vol effect.  (robs)
--- a/soxeffect.7
+++ b/soxeffect.7
@@ -230,6 +230,22 @@
 .B mcompand
 for a multiple-band companding effect.
 .TP
+\fBcontrast [\fIenhancement-amount\fR]
+Comparable to compression, this effect modifies an audio signal to 
+make it sound louder.
+.I enhancement-amount
+controls the amount of the enhancement and is a number in the range 0\-100.
+Note that
+.I enhancement-amount
+= 0 still gives a significant contrast enhancement.
+.B contrast
+is often used in conjunction with the
+.B norm
+effect as follows:
+.EX
+	sox infile outfile norm -i contrast
+.EE
+.TP
 \fBdcshift \fIshift\fR [\fIlimitergain\fR]
 DC Shift the audio, with basic linear amplitude formula.
 This is most useful if your audio tends to not be centered around
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -19,15 +19,15 @@
 
 # Format with: !xargs echo|tr ' ' '\n'|sort|column|expand|sed 's/^/  /'
 set(effects_srcs
-  FFT             earwax          mixer           remix           stat
-  biquad          echo            noiseprof       repeat          stretch
-  biquads         echos           noisered        resample        swap
-  chorus          effects         normalise       reverb          synth
-  compand         fade            pad             reverse         tempo
-  compandt        filter          pan             silence         tremolo
-  dcshift         flanger         phaser          skeleff         trim
-  delay           key             pitch           speed           vol
-  dither          mcompand        polyphas        splice
+  biquad          earwax          mcompand        polyphas        splice
+  biquads         echo            mixer           remix           stat
+  chorus          echos           noiseprof       repeat          stretch
+  compand         effects         noisered        resample        swap
+  compandt        fade            normalise       reverb          synth
+  contrast        FFT             pad             reverse         tempo
+  dcshift         filter          pan             silence         tremolo
+  delay           flanger         phaser          skeleff         trim
+  dither          key             pitch           speed           vol
 )
 set(formats_srcs
   8svx            cvsd-fmt        htk             s1-fmt          u2-fmt
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -198,7 +198,7 @@
 	  pan.c phaser.c pitch.c polyphas.c rabbit.c remix.c repeat.c \
 	  resample.c reverb.c reverse.c silence.c skeleff.c speed.c	\
 	  splice.c stat.c stretch.c swap.c synth.c tempo.c tremolo.c trim.c \
-	  vol.c normalise.c delay.c
+	  vol.c normalise.c delay.c contrast.c
 libsfx_la_CFLAGS = @SAMPLERATE_CFLAGS@
 libsfx_la_LIBADD = @SAMPLERATE_LIBS@ libsox.la
 
--- /dev/null
+++ b/src/contrast.c
@@ -1,0 +1,54 @@
+/*
+ * Effect: Contrast Enhancement        (c) 2008 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 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.
+ */
+
+#include "sox_i.h"
+#include <math.h>
+
+typedef struct {double contrast;} priv_t;
+assert_static(sizeof(priv_t) <= SOX_MAX_EFFECT_PRIVSIZE, PRIVSIZE_too_big);
+
+static int create(sox_effect_t * effp, int argc, char * * argv)
+{
+  priv_t * p = (priv_t *)effp->priv;
+
+  p->contrast = 75;
+  do {NUMERIC_PARAMETER(contrast, 0, 100)} while (0);
+  p->contrast /= 750;
+  return argc?  sox_usage(effp) : SOX_SUCCESS;
+}
+
+static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
+    sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
+{
+  priv_t * p = (priv_t *)effp->priv;
+  sox_size_t len = *isamp = *osamp = min(*isamp, *osamp);
+
+  while (len--) {
+    double d = *ibuf++ * (-M_PI_2 / SOX_SAMPLE_MIN);
+    *obuf++ = sin(d + p->contrast * sin(d * 4)) * SOX_SAMPLE_MAX;
+  }
+  return SOX_SUCCESS;
+}
+
+sox_effect_handler_t const * sox_contrast_effect_fn(void)
+{
+  static sox_effect_handler_t handler = {
+    "contrast", "[enhancement]", SOX_EFF_MCHAN, create, 0, flow, 0, 0, 0
+  };
+  return &handler;
+}
--- a/src/effects.h
+++ b/src/effects.h
@@ -7,6 +7,7 @@
   EFFECT(bass)
   EFFECT(chorus)
   EFFECT(compand)
+  EFFECT(contrast)
   EFFECT(dcshift)
   EFFECT(deemph)
   EFFECT(delay)
--- a/src/soxio.c
+++ b/src/soxio.c
@@ -52,11 +52,8 @@
 
 #ifdef HAVE_LIBLTDL
 static sox_bool plugins_initted = sox_false;
-#endif
 
-/* FIXME: Use vasprintf */
-#ifdef HAVE_LIBLTDL
-#define MAX_NAME_LEN 1024
+#define MAX_NAME_LEN 1024 /* FIXME: Use vasprintf */
 static int init_format(const char *file, lt_ptr data)
 {
   lt_dlhandle lth = lt_dlopenext(file);
@@ -78,7 +75,6 @@
       }
     }
   }
-
   return 0;
 }
 #endif
@@ -603,7 +599,7 @@
   set_output_format(ft);
 
   /* FIXME: doesn't cover the situation where
-   * codec changes audio length (e.g. 8svx, gsm): */
+   * codec changes audio length due to block alignment (e.g. 8svx, gsm): */
   if (signal->rate && signal->channels)
     ft->length = ft->length * ft->signal.rate / signal->rate *
       ft->signal.channels / signal->channels + .5;