SoX

SoX (Sound eXchange) is a cross-platform command line program for doing things with audio.
It can be used to convert between different audio formats, trim, join and mix files, add effects, play and record files, change sample rates and bit depths and many other common audio tasks. It is sometimes likened to a command line sibling to Audacity.

One of the great strengths of SoX is that as a command line utility it can easily be used with batch processing scripts.

Today I have been looking at the “Compander” effect because I had need of an aggressive, fast compressor/limiter effect.

A brief summary of the available commands is given by:

sox -h

A brief summary of the effects commands is given by

sox --help-effect <effect>

so for the Compander the brief help can be shown with:

sox  --help-effect compand

This gives:

sox: SoX v14.3.1

Effect usage:

compand attack1,decay1{,attack2,decay2} [soft-knee-dB:]in-dB1[,out-dB1]{,in-dB2,out-dB2} [gain [initial-volume-dB [delay]]]
	where {} means optional and repeatable and [] means optional.
	dB values are floating point or -inf'; times are in seconds.

I found this to be a bit more than slightly cryptic, so I looked in the SoX manual http://sox.sourceforge.net/sox.html#index


… more to follow

I find the compand gain transfer function confusing, but a bit of experimentation produced the heavy compression that I was after.

sox infile.wav outfile.wav compand 0,0.1 -80.1,-inf,-80,-160,-48,-24,-24,-6,-12,-1.5,-6,-0.3 -1 -6 gain -n -0.1

The attack is 0 (as fast as possible) and the decay (release) is 0.1 seconds

The next parameter is the gain transfer function.
The examples in the manual show an odd number of values which is rather confusing IMHO, but taken in pairs is a bit easier to follow:
-80.1,-inf, (below -80.1 dB the sound is gated)
-80,-160, (from 80 dB the ratio is 1:2 compression >> 2:1 expansion)
-48,-24, (from -48 dB the ratio is 2:1 compression)
-24,-6, (from -24 dB the ratio is 4:1 compression)
-12,-1.5, (from -12 dB the ratio is 8:1 compression)
-6,-0.3 (from -6 dB the ratio is 20:1 compression)

Overall the effect produces an increasing amount of compression as the input level rises.

The next parameter (-1) provides 1 dB of headroom.
The final parameter (-6) sets an assumed initial level of -6 dB.

Following the compander effect is the “gain” effect.
The parameters (-n -0.1) tells the gain effect to normalise to -0.1 dB