shithub: sox

Download patch

ref: fec8e043105f89327eaa7bd362ae4fbd93b5ce41
parent: bd0eddd5f55b60192837166f8f6cf753c7b3f85f
author: cbagwell <cbagwell>
date: Wed Sep 22 22:09:38 EDT 2004

Added multiband compander effect

--- a/Changelog
+++ b/Changelog
@@ -49,6 +49,8 @@
   o Added patch from Eric Benson that attempts to do a seek()
     if the first effect is trim.  This greatly speeds up
     processing large files.
+  o Daniel Pouzzner implemented a multi-band compander (using
+    the butterworth filters to split the audio into bands).
 
 sox-12.17.5
 -----------
--- /dev/null
+++ b/scripts/fmsim
@@ -1,0 +1,18 @@
+#!/bin/sh
+#
+# fmsim - simulates FM radio sound (or broadcast signal condition if the
+#   lowp at the end is skipped - not that the pipeline is set up with
+#   US-style 75us preemphasis).
+#
+# Thats signed 32-bit 44100Hz audio from stdin and outputs to stdout.
+
+
+../src/sox -V -t raw -r 44100 -s -w -c 2 - -t raw -r 44100 -s -l -c 2 \
+    - vol -3 db filter 8000- 32 100 mcompand ".005,.1 \
+    -47,-40,-34,-34,-17,-33 0 0 0" 100 ".003,.05 \
+    -47,-40,-34,-34,-17,-33 0 0 0" 400 ".000625,.0125 \
+    -47,-40,-34,-34,-15,-33 0 0 0" 1600 ".0001,.025 \
+    -47,-40,-34,-34,-31,-31,-0,-30 0 0 0" 6400 \
+    "0,.025 -38,-31,-28,-28,-0,-25 0 0 0" vol 27 db vol -12 \
+    db highpass 22 highpass 22 filter -17500 256 vol +12 db \
+    vol -3 db lowp 17801
--- a/sox.1
+++ b/sox.1
@@ -94,6 +94,12 @@
 .br
     \fBmask\fR
 .br
+    \fBmcompand\fR "\fIattack1\fR,\fIdecay1\fR[,\fIattack2\fR,\fIdecay2\fR...]
+.br
+             \fIin-dB1\fR,\fIout-dB1\fR[,\fIin-dB2\fR,\fIout-dB2\fR...]
+.br
+             [ \fIgain\fR [ \fIinitial-volume\fR [ \fIdelay\fR ] ] ]" xover_freq
+.br
     \fBpan\fR \fIdirection\fR
 .br
     \fBphaser\fR \fIgain-in gain-out delay decay speed\fR < -s | -t >
@@ -907,6 +913,16 @@
 It tends to mask buzzing voices, for example.
 It adds 1/2 bit of noise to the sound file at the
 output bit depth.
+.TP
+mcompand "\fIattack1,decay1\fR[,\fIattack2,decay2\fR...]
+.TP 
+         \fIin-dB1,out-dB1\fR[,\fIin-dB2,out-dB2\fR...]
+.TP 10
+         [\fIgain\fR [\fIinitial-volume\fR [\fIdelay\fR ] ] ]" \fIxover_freq\fR
+
+Multi-band compander is similar to the single band compander but
+the audio file is first divided up into bands and then the compander
+is ran on each band.  See the \fBcompand\fR effect for definition of its options.  Compand options are specified between double quotes and the crossover frequency for that band is specefied seperately with \fIxover_fre\fR.  This can be repeated multiple times to create multiple bands.
 .TP 10
 pan \fIdirection\fB
 Pan the sound of an audio file from one channel to another.  This is done by
--- a/sox.txt
+++ b/sox.txt
@@ -54,6 +54,9 @@
 	   lowp frequency
 	   lowpass frequency
 	   mask
+	   mcompand "attack1,decay1[,attack2,decay2...]
+		    in-dB1,out-dB1[,in-dB2,out-dB2...]
+		    [ gain [ initial-volume [ delay ] ] ]" xover_freq
 	   pan direction
 	   phaser gain-in gain-out delay decay speed < -s | -t >
 	   pick [ -1 | -2 | -3 | -4 | -l | -r | -f | -b ]
@@ -192,9 +195,9 @@
 		 ADPCM, IMA_ADPCM, GSM, or Floating-point.
 		 U-law	(actually shorthand for mu-law) and A-law are the U.S.
 		 and international standards for logarithmic  telephone	 sound
-		 compression.	When uncompressed u-law has roughly the preci-
-		 sion of 14-bit PCM audio and A-law has roughly the  precision
-		 of 13-bit PCM audio.
+		 compression.	 When	uncompressed  u-law  has  roughly  the
+		 precision of 14-bit PCM audio and A-law has roughly the  pre-
+		 cision of 13-bit PCM audio.
 		 A-law	and  u-law  data is sometimes encoded using a reversed
 		 bit-ordering (ie. MSB becomes LSB).  Internally,  SoX	under-
 		 stands	 how to work with this encoding but there is currently
@@ -605,11 +608,11 @@
 		 the fourth (optional) parameter is an initial	volume	to  be
 		 assumed  for  each channel when the effect starts.  This per-
 		 mits the user to supply a nominal level initially,  so	 that,
-		 for example, a very large gain is not applied to initial sig-
-		 nal levels before the companding action has begun to operate:
-		 it  is quite probable that in such an event, the output would
-		 be severely clipped while the compander gain properly adjusts
-		 itself.
+		 for  example,	a  very	 large	gain is not applied to initial
+		 signal levels before the companding action has begun to oper-
+		 ate:  it  is quite probable that in such an event, the output
+		 would be severely clipped while the compander	gain  properly
+		 adjusts itself.
 
 		 The  fifth  (optional)	 parameter is a delay in seconds.  The
 		 input signal is analyzed immediately to control  the  compan-
@@ -674,9 +677,9 @@
 		 stop-time is not specified.
 		 All times can be specified in either periods of time or  sam-
 		 ple   counts.	  To  specify  time  periods  use  the	format
-		 hh:mm:ss.frac format.	To specify using sample counts,	 spec-
-		 ify  the  number  of samples and append the letter ’s’ to the
-		 sample count (for example 8000s).
+		 hh:mm:ss.frac	format.	  To  specify  using  sample   counts,
+		 specify  the  number  of samples and append the letter ’s’ to
+		 the sample count (for example 8000s).
 		 An optional type can be specified to change the type of enve-
 		 lope.	 Choices are q for quarter of a sinewave, h for half a
 		 sinewave, t for linear slope, l for logarithmic,  and	p  for
@@ -733,6 +736,20 @@
 		 created by the process of  playing  a	sound  digitally.   It
 		 tends	to  mask buzzing voices, for example.  It adds 1/2 bit
 		 of noise to the sound file at the output bit depth.
+
+       mcompand "attack1,decay1[,attack2,decay2...]
+
+		in-dB1,out-dB1[,in-dB2,out-dB2...]
+
+		[gain [initial-volume [delay ] ] ]" xover_freq
+
+		 Multi-band compander is similar to the single band  compander
+		 but  the  audio  file is first divided up into bands and then
+		 the compander is ran on each band.  See  the  compand	effect
+		 for definition of its options.	 Compand options are specified
+		 between double quotes and the crossover  frequency  for  that
+		 band  is  specefied  seperately  with xover_fre.  This can be
+		 repeated multiple times to create multiple bands.
 
        pan direction
 		 Pan the sound of an audio file from one channel  to  another.
--- a/src/Makefile.dos
+++ b/src/Makefile.dos
@@ -22,7 +22,7 @@
 EOBJ	= avg.obj band.obj bandpass.obj breject.obj btrworth.obj chorus.obj \
 	  compand.obj copy.obj dcshift.obj deemphas.obj earwax.o \
 	  echo.obj echos.obj fade.obj filter.obj flanger.obj highp.obj \
-	  highpass.obj lowp.obj lowpass.obj mask.obj phaser.obj \
+	  highpass.obj lowp.obj lowpass.obj mask.obj mcompand.obj phaser.obj \
 	  pitch.obj pan.obj polyphase.obj rate.obj repeat.obj resample.obj \
 	  reverb.obj reverse.obj silence.obj speed.obj stat.obj \
 	  stretch.obj swap.obj synth.obj trim.obj vibro.obj vol.obj
--- a/src/Makefile.gcc
+++ b/src/Makefile.gcc
@@ -28,8 +28,8 @@
 EOBJ    = avg.o band.o bandpass.o breject.o btrworth.o chorus.o compand.o \
           copy.o dcshift.o deemphas.o earwax.o echo.o echos.o fade.o \
 	  filter.o flanger.o highp.o highpass.o lowp.o lowpass.o \
-	  mask.o pan.o phaser.o pitch.o polyphas.o rate.o repeat.o \
-	  resample.o reverb.o reverse.o silence.o speed.o \
+	  mask.o mcompand.o pan.o phaser.o pitch.o polyphas.o rate.o \
+	  repeat.o resample.o reverb.o reverse.o silence.o speed.o \
 	  stat.o stretch.o swap.o synth.o trim.o vibro.o vol.o
 
 SOUNDLIB = libst.a
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -49,7 +49,7 @@
 EOBJ	= avg.o band.o bandpass.o breject.o btrworth.o chorus.o compand.o \
 	  copy.o dcshift.o deemphas.o earwax.o echo.o echos.o \
 	  fade.o filter.o flanger.o highp.o highpass.o lowp.o \
-	  lowpass.o mask.o pan.o phaser.o pitch.o polyphas.o \
+	  lowpass.o mask.o mcompand.o pan.o phaser.o pitch.o polyphas.o \
 	  rate.o repeat.o resample.o reverb.o reverse.o silence.o speed.o \
 	  stat.o stretch.o swap.o synth.o trim.o vibro.o vol.o
 
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -465,6 +465,9 @@
         {"mask", ST_EFF_MCHAN,
                 st_mask_getopts, st_effect_nothing, st_mask_flow,
                 st_effect_nothing_drain, st_effect_nothing},
+        {"mcompand", ST_EFF_MCHAN,
+                st_mcompand_getopts, st_mcompand_start, st_mcompand_flow,
+                st_mcompand_drain, st_mcompand_stop},
         {"pan", ST_EFF_MCHAN | ST_EFF_CHAN,
                 st_pan_getopts, st_pan_start, st_pan_flow,
                 st_effect_nothing_drain, st_pan_stop},
--- a/src/play.in
+++ b/src/play.in
@@ -72,7 +72,7 @@
 # loop over arguments
 while [ $# -ne 0 ]; do
     case "$1" in
-	avg|band|bandpass|bandreject|chorus|compand|copy|cut|deemph|earwax|echo|echos|fade|filter|flanger|highp|highpass|lowp|lowpass|map|mask|pan|phaser|pick|pitch|polyphase|rate|repeat|resample|reverb|reverse|silence|speed|split|stat|stretch|swap|trim|vibro|vol)
+	avg|band|bandpass|bandreject|chorus|compand|copy|cut|deemph|earwax|echo|echos|fade|filter|flanger|highp|highpass|lowp|lowpass|map|mask|mcompand|pan|phaser|pick|pitch|polyphase|rate|repeat|resample|reverb|reverse|silence|speed|split|stat|stretch|swap|trim|vibro|vol)
 	    effects="$@"
 	    break
 	    ;;
--- a/src/st_i.h
+++ b/src/st_i.h
@@ -487,6 +487,13 @@
 int st_mask_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
                  st_size_t *isamp, st_size_t *osamp);
 
+int st_mcompand_getopts(eff_t effp, int argc, char **argv);
+int st_mcompand_start(eff_t effp);
+int st_mcompand_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,
+                     st_size_t *isamp, st_size_t *osamp);
+int st_mcompand_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
+int st_mcompand_stop(eff_t effp);
+
 int st_pan_getopts(eff_t effp, int argc, char **argv);
 int st_pan_start(eff_t effp);
 int st_pan_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf,