shithub: sox

ref: 30922f4f2ba178d03bcde9d18afc9327c73aa742
dir: /soxexam.7/

View raw version
'\" t
'\" The line above instructs most `man' programs to invoke tbl
'\"
'\" Separate paragraphs; not the same as PP which resets indent level.
.de SP
.if t .sp .5
.if n .sp
..
'\"
'\" Replacement em-dash for nroff (default is too short).
.ie n .ds m " - 
.el .ds m \(em
'\"
'\" Placeholder macro for if longer nroff arrow is needed.
.ds RA \(->
'\"
'\" Decimal point set slightly raised
.if t .ds d \v'-.15m'.\v'+.15m'
.if n .ds d .
'\"
'\" Enclosure macro for examples
.de EX
.SP
.nf
.ft CW
..
.de EE
.ft R
.SP
.fi
..
.TH SoX 7 "January 31, 2007" "soxexam" "Sound eXchange"
.SH NAME
SoX \- Sound eXchange, the Swiss Army knife of audio manipulation
.SH EXAMPLES
.SS Introduction
The core problem is that you need some experience in using effects
in order to say `that any old sound file sounds with effects
absolutely hip'. There isn't any rule-based system which tell you
the correct setting of all the parameters for every effect.
But after some time you will become an expert in using effects.
.SP
Here are some examples which can be used with any music sample.
(For a sample where only a single instrument is playing, extreme
parameter setting may make well-known `typically' or `classical'
sounds. Likewise, for drums, vocals or guitars.)
.SP
Single effects will be explained and some given parameter settings
that can be used to understand the theory by listening to the sound file
with the added effect.
.SP
Using multiple effects in parallel or in series can result either
in a very nice sound or (mostly) in a dramatic overloading in
variations of sounds such that your ear may follow the sound but
you will feel unsatisfied. Hence, for the first time using effects
try to compose them as minimally as possible. We don't regard the
composition of effects in the examples because too many combinations
are possible and you really need a very fast machine and a lot of
memory to play them in real-time.
.SP
However, real-time playing of sounds will greatly speed up learning
and/or tuning the parameter settings for your sounds in order to
get that `perfect' effect.
.SP
Basically, we will use the `play' front-end of SoX since it is easier
to listen sounds coming out of the speaker or earphone instead
of looking at cryptic data in sound files.
.SP
For easy listening of file.xxx (`xxx' is any sound format):
.SP
	play file.xxx effect-name effect-parameters
.SP
Or more SoX-like (for `dsp' output on a UNIX/Linux computer):
.SP
	sox file.xxx \-t oss \-2 \-s /dev/dsp effect-name effect-parameters
.SP
or (for `au' output):
.SP
	sox file.xxx \-t sunau \-2 \-s /dev/audio effect-name effect-parameters
.SP
And for date freaks:
.SP
	sox file.xxx file.yyy effect-name effect-parameters
.SP
Additional options can be used. However, in this case, for real-time
playing you'll need a very fast machine.
.SP
Notes:
.SP
I played all examples in real-time on a Pentium 100 with 32 MB and
Linux 2.0.30 using a self-recorded sample ( 3:15 min long in `wav'
format with 44\*d1 kHz sample rate and stereo 16 bit ).
The sample should not contain any of the effects. However,
if you take any recording of a sound track from radio or tape or CD,
and it sounds like a live concert or ten people are playing the same
rhythm with their drums or funky-grooves, then take any other sample.
(Typically, less then four different instruments and no synthesizer
in the sample is suitable. Likewise, the combination vocal, drums, bass
and guitar.)
.SS Echo
.SP
An echo effect can be naturally found in the mountains, standing somewhere
on a mountain and shouting a single word will result in one or more repetitions
of the word (if not, turn a bit around and try again, or climb to the next
mountain).
.SP
However, the time difference between shouting and repeating is the delay
(time), its loudness is the decay. Multiple echos can have different delays and
decays.
.SP
It is very popular to use echos to play an instrument with itself together,
like some guitar players (Queen's Brian May) or vocalists do.
For music samples of more than one instrument, echo can be used to add a
second sample shortly after the original one.
.SP
This will sound as if you are doubling the number of instruments playing
in the same sample:
.SP
	play file.xxx echo 0\*d8 0\*d88 60 0\*d4
.SP
If the delay is very short, then it sound like a (metallic) robot playing
music:
.SP
	play file.xxx echo 0\*d8 0\*d88 6 0\*d4
.SP
Longer delay will sound like an open air concert in the mountains:
.SP
	play file.xxx echo 0\*d8 0\*d9 1000 0\*d3
.SP
One mountain more, and:
.SP
	play file.xxx echo 0\*d8 0\*d9 1000 0\*d3 1800 0\*d25
.SS Echos
Like the echo effect, echos stand for `ECHO in Sequel', that is the first echos
takes the input, the second the input and the first echos, the third the input
and the first and the second echos, ... and so on.
Care should be taken using many echos (see introduction); a single echos
has the same effect as a single echo.
.SP
The sample will be bounced twice in symmetric echos:
.SP
	play file.xxx echos 0\*d8 0\*d7 700 0\*d25 700 0\*d3
.SP
The sample will be bounced twice in asymmetric echos:
.SP
	play file.xxx echos 0\*d8 0\*d7 700 0\*d25 900 0\*d3
.SP
The sample will sound as if played in a garage:
.SP
	play file.xxx echos 0\*d8 0\*d7 40 0\*d25 63 0\*d3
.SS Chorus
The chorus effect has its name because it will often be used to make a single
vocal sound like a chorus. But it can be applied to other instrument samples
too.
.SP
It works like the echo effect with a short delay, but the delay isn't constant.
The delay is varied using a sinusoidal or triangular modulation. The modulation
depth defines the range the modulated delay is played before or after the
delay. Hence the delayed sound will sound slower or faster, that is the delayed
sound tuned around the original one, like in a chorus where some vocals are
a bit out of tune.
.SP
The typical delay is around 40ms to 60ms, the speed of the modulation is best
near 0\*d25Hz and the modulation depth around 2ms.
.SP
A single delay will make the sample more overloaded:
.SP
	play file.xxx chorus 0\*d7 0\*d9 55 0\*d4 0\*d25 2 \-t
.SP
Two delays of the original samples sound like this:
.SP
	play file.xxx chorus 0\*d6 0\*d9 50 0\*d4 0\*d25 2 \-t 60 0\*d32 0\*d4 1\*d3 \-s
.SP
A big chorus of the sample is (three additional samples):
.SP
	play file.xxx chorus 0\*d5 0\*d9 50 0\*d4 0\*d25 2 \-t 60 0\*d32 0\*d4 2\*d3 \-t 40 0\*d3 0\*d3 1\*d3 \-s
.SS Flanger
The flanger effect is like the chorus effect, but the delay varies between
0ms and maximal 5ms. It sound like wind blowing, sometimes faster or slower
including changes of the speed.
.SP
The flanger effect is widely used in funk and soul music, where the guitar
sound varies frequently slow or a bit faster.
.SP
Now, let's groove the sample:
.SP
	play file.xxx flanger
.SP
listen carefully between the difference of sinusoidal and triangular modulation:
.SP
	play file.xxx flanger triangle
.SS Reverb
A reverberation effect is sometimes needed in concert halls that are too
small or contain so many people that the hall's natural reverberance is
diminished.
.SP
Using the effect is easy:
.EX
	play file.xxx reverb
.EE
gives the default reverberance (50%); or specify the desired reverberance
as a percentage:
.EX
	play file.xxx reverb 80
.EE
For fine tuning, see
.BR sox (1).
.SP
If you run out of machine power or memory, then stop as many applications
as possible.
.SS Phaser
The phaser effect is like the flanger effect, but it uses a reverb instead of
an echo and does phase shifting. You'll hear the difference in the examples
comparing both effects.
The delay modulation can be sinusoidal or triangular, preferable is the
later for multiple instruments. For single instrument sounds,
the sinusoidal phaser effect will give a sharper phasing effect.
The decay shouldn't be to close to 1 which will cause dramatic feedback.
A good range is about 0\*d5 to 0\*d1 for the decay.
.SP
We will take a parameter setting as before (gain-out is
lower since feedback can raise the output dramatically):
.SP
	play file.xxx phaser 0\*d8 0\*d74 3 0\*d4 0\*d5 \-t
.SP
The drunken loudspeaker system (now less alcohol):
.SP
	play file.xxx phaser 0\*d9 0\*d85 4 0\*d23 1\*d3 \-s
.SP
A popular sound of the sample is as follows:
.SP
	play file.xxx phaser 0\*d89 0\*d85 1 0\*d24 2 \-t
.SP
The sample sounds if ten springs are in your ears:
.SP
	play file.xxx phaser 0\*d6 0\*d66 3 0\*d6 2 \-t
.SS Compander
The compander effect allows the dynamic range of a signal to be
compressed or expanded.  It works by calculating the input signal level
averaged over time according to the given attack and decay parameters,
and setting the output signal level according to the given
transfer-function parameters.
.SP
For most situations, the attack time (response to the music getting
louder) should be shorter than the decay time because our ears are more
sensitive to suddenly loud music than to suddenly soft music.
.SP
For example, suppose you are listening to Strauss's `Also Sprach
Zarathustra' in a noisy environment such as a moving vehicle.
If you turn up the volume enough to hear the soft passages over the
road noise, the loud sections will be too loud.
So you could try this:
.EX
	sox asz.flac asz-car.flac compand 0.3,1 6:-70,-60,-20 -5 -90 0.2
.EE
The transfer function (`6:\-70,...') says that very soft sounds (below
\-70dB) will remain unchanged.  This will stop the compander from
boosting the volume on `silent' passages such as between movements.
However, sounds in the range \-60dB to 0dB (maximum
volume) will be boosted so that the 60dB dynamic range of the
original music will be compressed 3-to-1 into a 20dB range, which is
wide enough to enjoy the music but narrow enough to get around the
road noise.  The `6:' selects 6dB soft-knee companding.
The \-5 (dB) output gain is needed to avoid clipping (the number is
inexact, and was derived by experimentation).
The \-90 (dB) for the initial volume will work fine for a clip that starts
with near silence, and the delay of 0\*d2 (seconds) has the effect of causing
the compander to react a bit more quickly to sudden volume changes.
.SP
In order to visualise the transfer function, SoX can be invoked with the
.B \-\-plot
option, e.g.
.EX
	sox -n -n --plot gnuplot compand 0,0 6:-70,-60,-20 -5 > my.plt
	gnuplot my.plt
.EE
The following (one long) command shows how multi-band companding is
typically used in FM radio:
.EX
	play file.xxx vol -3dB filter 8000- 32 100 mcompand \\
	\(dq0.005,0.1 -47,-40,-34,-34,-17,-33\(dq 100 \\
	\(dq0.003,0.05 -47,-40,-34,-34,-17,-33\(dq 400 \\
	\(dq0.000625,0.0125 -47,-40,-34,-34,-15,-33\(dq 1600 \\
	\(dq0.0001,0.025 -47,-40,-34,-34,-31,-31,-0,-30\(dq 6400 \\
	\(dq0,0.025 -38,-31,-28,-28,-0,-25\(dq \\
	vol 15dB highpass 22 highpass 22 filter -17500 256 \\
	vol 9dB lowpass -1 17801
.EE
The audio file is played with a simulated FM radio sound (or broadcast
signal condition if the lowpass filter at the end is skipped).
Note that the pipeline is set up with US-style 75us preemphasis.
.SS Changing the Rate of Playback
You can use stretch to change the rate of playback of an audio sample
while preserving the pitch.  For example to play at half the speed:
.SP
	play file.wav stretch 2
.SP
To play a file at twice the speed:
.SP
	play file.wav stretch 0\*d5
.SP
Other related options are `speed' to change the speed of play
(and changing the pitch accordingly), and pitch, to alter the
pitch of a sample.  For example to speed a sample so it plays in
half the time (for those Mickey Mouse voices):
.SP
	play file.wav speed 2
.SP
To raise the pitch of a sample 1 while note (100 cents):
.SP
	play file.wav pitch 100
.SP
.SS Reducing noise in a recording
First find a period of silence in your recording, such as the beginning or
end of a piece. If the first 1\*d5 seconds of the recording are silent, do
.SP
	sox file.wav \-n trim 0 1\*d5 noiseprof /tmp/profile
.SP
Next, use the noisered effect to actually reduce the noise:
.SP
	play file.wav noisered /tmp/profile
.SS Making a recording
Thanks to Douglas Held for the following suggestion:
.SP
	rec \fIparameters filename other-effects\fR silence 1 5 2%
.SP
This use of the
.B silence
effect allows you to start a recording session but only start writing
to disk once non-silence is detect. For example, use this to
start your favorite command line for recording and walk
over to your record player and start the song.  No periods
of silence will be recorded.
.SS Scripting with SoX
One of the benefits of a command-line tool is that it is easy to use it
in scripts to perform more complex tasks.
In marine radio, a Mayday emergency call is transmitted preceded by a
30-second alert sound.  The alert sound comprises two audio tones at
1300Hz and 2100Hz alternating at a rate of 4Hz.
The following shows how SoX can be used in a script to construct an audio file
containing the alert sound.
The scripting language shown is `Bourne shell' (sh) but it should be
simple to translate this to another scripting language if you do not
have access to sh.
.EX
# Make sure we append to a file that's initially empty:
rm \-f 2tones.raw

for freq in 1300 2200; do
  sox \-c1 \-r8000 \-n \-t raw \- synth 0\*d25 sine $freq vol 0\*d7 >> 2tones.raw
done

# We need 60 copies of 2tones.raw (0\*d5 sec) to get 30 secs of audio:
iterations=60

# Make sure we append to a file that's initially empty:
rm \-f alert.raw

while [ $iterations \-ge 1 ]; do
  cat 2tones.raw >> alert.raw
  iterations=\`expr $iterations \- 1\`
done

# Add a file header and save some disc space:
sox \-s2 \-c1 \-r8000 alert.raw alert.ogg

play alert.ogg
.EE
If you try out the above script, you may want to hit Ctrl-C fairly soon
after the alert tone starts playing\*mit's not a pleasant sound!  The
.B synth
effect is used to generate each of the tones;
.B "\-c1 \-r8000"
selects mono, 8kHz sampling-rate audio (i.e. relatively low fidelity,
suitable for the marine radio transmission channel); each tone is
generated at a length of 0\*d25 seconds to give the required 4Hz
alternation.  Note the use of `raw' as the intermediary file format; a
self-describing (header) format would just get in the way here.  The
self-describing header is added only at the final stage; in this case,
.B .ogg
is chosen, since lossy compression is appropriate for this application.
.SP
There are further practical examples of scripting with SoX available to
download from the SoX web-site [1].
.SH SEE ALSO
.BR sox (1),
.BR soxi (1),
.BR libsox (3)
.SS References
.TP
[1]
.IR "SoX\*mSound eXchange | Scripts" ,
http://sox.sourceforge.net/Docs/Scripts
.SH AUTHORS
This man page was written largely by Juergen Mueller (jmueller@uia.ua.ac.be).
Other SoX authors and contributors are listed in the AUTHORS file that
is distributed with the source code.