-
Notifications
You must be signed in to change notification settings - Fork 112
/
sox.1
4253 lines (4244 loc) · 146 KB
/
sox.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'\" 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 1 "December 31, 2014" "sox" "Sound eXchange"
.SH NAME
SoX \- Sound eXchange, the Swiss Army knife of audio manipulation
.SH SYNOPSIS
.nf
\fBsox\fR [\fIglobal-options\fR] [\fIformat-options\fR] \fIinfile1\fR
[[\fIformat-options\fR] \fIinfile2\fR] ... [\fIformat-options\fR] \fIoutfile\fR
[\fIeffect\fR [\fIeffect-options\fR]] ...
.SP
\fBplay\fR [\fIglobal-options\fR] [\fIformat-options\fR] \fIinfile1\fR
[[\fIformat-options\fR] \fIinfile2\fR] ... [\fIformat-options\fR]
[\fIeffect\fR [\fIeffect-options\fR]] ...
.SP
\fBrec\fR [\fIglobal-options\fR] [\fIformat-options\fR] \fIoutfile\fR
[\fIeffect\fR [\fIeffect-options\fR]] ...
.fi
.SH DESCRIPTION
.SS Introduction
SoX reads and writes audio files in most popular formats and can
optionally apply effects to them. It can combine multiple input
sources, synthesise audio, and, on many systems, act as a general
purpose audio player or a multi-track audio recorder. It also has
limited ability to split the input into multiple output files.
.SP
All SoX functionality is available using just the \fBsox\fR command.
To simplify playing and recording audio, if SoX is invoked as
\fBplay\fR, the output file is automatically set to be the default sound
device, and if invoked as \fBrec\fR, the default sound device is used as an
input source.
Additionally, the
.BR soxi (1)
command provides a convenient way to just query audio file header information.
.SP
The heart of SoX is a library called libSoX. Those interested in
extending SoX or using it in other programs should refer to the libSoX
manual page:
.BR libsox (3).
.SP
SoX is a command-line audio processing tool, particularly suited to making
quick, simple edits and to batch processing.
If you need an interactive, graphical audio editor, use
.BR audacity (1).
.TS
center;
c8 c8 c.
* * *
.TE
.DT
.SP
The overall SoX processing chain can be summarised as follows:
.TS
center;
l.
Input(s) \*(RA Combiner \*(RA Effects \*(RA Output(s)
.TE
.DT
.SP
Note however, that on the SoX command line, the positions of the
Output(s) and the Effects are swapped w.r.t. the logical flow just
shown. Note also that whilst options pertaining to files are placed
before their respective file name, the opposite is true for effects.
To show how this works in practice, here is a selection of examples of
how SoX might be used. The simple
.EX
sox recital.au recital.wav
.EE
translates an audio file in Sun AU format to a Microsoft WAV file, whilst
.EX
sox recital.au \-b 16 recital.wav channels 1 rate 16k fade 3 norm
.EE
performs the same format translation, but also applies four effects
(down-mix to one channel, sample rate change, fade-in, nomalize),
and stores the result at a bit-depth of 16.
.EX
sox \-r 16k \-e signed \-b 8 \-c 1 voice-memo.raw voice-memo.wav
.EE
converts `raw' (a.k.a. `headerless') audio to a self-describing file format,
.EX
sox slow.aiff fixed.aiff speed 1.027
.EE
adjusts audio speed,
.EX
sox short.wav long.wav longer.wav
.EE
concatenates two audio files, and
.EX
sox \-m music.mp3 voice.wav mixed.flac
.EE
mixes together two audio files.
.EX
play \(dqThe Moonbeams/Greatest/*.ogg\(dq bass +3
.EE
plays a collection of audio files whilst applying a bass boosting effect,
.EX
play \-n \-c1 synth sin %\-12 sin %\-9 sin %\-5 sin %\-2 fade h 0.1 1 0.1
.EE
plays a synthesised `A minor seventh' chord with a pipe-organ sound,
.EX
rec \-c 2 radio.aiff trim 0 30:00
.EE
records half an hour of stereo audio, and
.EX
play \-q take1.aiff & rec \-M take1.aiff take1\-dub.aiff
.EE
(with POSIX shell and where supported by hardware)
records a new track in a multi-track recording. Finally,
.EX
.ne 3
rec \-r 44100 \-b 16 \-e signed-integer \-p \\
silence 1 0.50 0.1% 1 10:00 0.1% | \\
sox \-p song.ogg silence 1 0.50 0.1% 1 2.0 0.1% : \\
newfile : restart
.EE
records a stream of audio such as LP/cassette and splits in to multiple
audio files at points with 2 seconds of silence. Also, it does not start
recording until it detects audio is playing and stops after it sees
10 minutes of silence.
.SP
N.B. The above is just an overview of SoX's capabilities; detailed
explanations of how to use \fIall\fR SoX parameters, file formats, and
effects can be found below in this manual, in
.BR soxformat (7),
and in
.BR soxi (1).
.SS File Format Types
SoX can work with `self-describing' and `raw' audio files.
`self-describing' formats (e.g. WAV, FLAC, MP3) have a header that
completely describes the signal and encoding attributes of the audio
data that follows. `raw' or `headerless' formats do not contain this
information, so the audio characteristics of these must be described
on the SoX command line or inferred from those of the input file.
.SP
The following four characteristics are used to describe the format of
audio data such that it can be processed with SoX:
.TP
sample rate
The sample rate in samples per second (`Hertz' or `Hz').
Digital telephony traditionally uses a sample rate of 8000\ Hz (8\ kHz),
though these days, 16 and even 32\ kHz are becoming more common. Audio
Compact Discs use 44100\ Hz (44\*d1\ kHz). Digital Audio Tape and many
computer systems use 48\ kHz. Professional audio systems often use 96
kHz.
.TP
sample size
The number of bits used to store each sample. Today, 16-bit is
commonly used. 8-bit was popular in the early days of computer
audio. 24-bit is used in the professional audio arena. Other sizes are
also used.
.TP
data encoding
The way in which each audio sample is represented (or `encoded'). Some
encodings have variants with different byte-orderings or bit-orderings.
Some compress the audio data so that the stored audio data takes up less
space (i.e. disk space or transmission bandwidth) than the other format
parameters and the number of samples would imply. Commonly-used
encoding types include floating-point, \(*m-law, ADPCM, signed-integer
PCM, MP3, and FLAC.
.TP
channels
The number of audio channels contained in the file. One (`mono') and
two (`stereo') are widely used. `Surround sound' audio typically
contains six or more channels.
.PP
The term `bit-rate' is a measure of the amount of storage occupied by an
encoded audio signal over a unit of time. It can depend on all of the
above and is typically denoted as a number of kilo-bits per second
(kbps). An A-law telephony signal has a bit-rate of 64 kbps. MP3-encoded
stereo music typically has a bit-rate of 128\-196 kbps. FLAC-encoded
stereo music typically has a bit-rate of 550\-760 kbps.
.SP
Most self-describing formats also allow textual `comments' to be
embedded in the file that can be used to describe the audio in some way,
e.g. for music, the title, the author, etc.
.SP
One important use of audio file comments is to convey `Replay Gain'
information. SoX supports applying Replay Gain information (for certain
input file formats only; currently, at least FLAC and Ogg Vorbis), but not
generating it. Note that by default, SoX copies input file comments
to output files that support comments, so output files may contain
Replay Gain information if some was present in the input file. In this
case, if anything other than a simple format conversion was performed
then the output file Replay Gain information is likely to be incorrect
and so should be recalculated using a tool that supports this (not SoX).
.SP
The
.BR soxi (1)
command can be used to display information from audio file headers.
.SS Determining & Setting The File Format
There are several mechanisms available for SoX to use to determine or set the
format characteristics of an audio file. Depending on the circumstances,
individual characteristics may be determined or set using different mechanisms.
.SP
To determine the format of an input file, SoX will use, in order of
precedence and as given or available:
.IP 1. 4
Command-line format options.
.IP 2. 4
The contents of the file header.
.IP 3. 4
The filename extension.
.PP
To set the output file format, SoX will use, in order of
precedence and as given or available:
.IP 1. 4
Command-line format options.
.IP 2. 4
The filename extension.
.IP 3. 4
The input file format characteristics, or the closest
that is supported by the output file type.
.PP
For all files, SoX will exit with an error
if the file type cannot be determined. Command-line format options may
need to be added or changed to resolve the problem.
.SS Playing & Recording Audio
The
.B play
and
.B rec
commands are provided so that basic playing and
recording is as simple as
.EX
play existing-file.wav
.EE
and
.EX
rec new-file.wav
.EE
These two commands are functionally equivalent to
.EX
sox existing-file.wav \-d
.EE
and
.EX
sox \-d new-file.wav
.EE
Of course, further options and effects (as described below) can be
added to the commands in either form.
.TS
center;
c8 c8 c.
* * *
.TE
.DT
.SP
Some systems provide more than one type of (SoX-compatible) audio
driver, e.g. ALSA & OSS, or SUNAU & AO.
Systems can also have more than one audio device (a.k.a. `sound card').
If more than one audio driver has been
built-in to SoX, and the default selected by SoX when recording or playing
is not the one that is wanted, then the
.B AUDIODRIVER
environment variable can be used to override the default. For example
(on many systems):
.EX
set AUDIODRIVER=oss
play ...
.EE
The
.B AUDIODEV
environment variable can be used to override the default audio device,
e.g.
.EX
set AUDIODEV=/dev/dsp2
play ...
sox ... \-t oss
.EE
or
.EX
set AUDIODEV=hw:soundwave,1,2
play ...
sox ... \-t alsa
.EE
Note that the way of setting environment variables varies from system
to system\*mfor some specific examples, see `SOX_OPTS' below.
.SP
When playing a file with a sample rate that is not supported by the
audio output device, SoX will automatically invoke the \fBrate\fR effect
to perform the necessary sample rate conversion. For
compatibility with old hardware, the
default \fBrate\fR quality level is set to `low'. This
can be changed by explicitly specifying the \fBrate\fR
effect with a different quality level, e.g.
.EX
play ... rate \-m
.EE
or by using the
.B \-\-play\-rate\-arg
option (see below).
.TS
center;
c8 c8 c.
* * *
.TE
.DT
.SP
To help with setting a suitable recording level, SoX includes a peak-level
meter which can be invoked (before making the actual recording) as follows:
.EX
rec \-n
.EE
The recording level should be adjusted (using the system-provided mixer
program, not SoX) so that the meter is \fIat most occasionally\fR full
scale, and never `in the red' (an exclamation mark is shown).
See also \fB\-S\fR below.
.SS Accuracy
Many file formats that compress audio discard some of the audio signal
information whilst doing so. Converting to such a format and then converting
back again will not produce an exact copy of the original audio. This
is the case for many formats used in telephony (e.g. A-law, GSM) where
low signal bandwidth is more important than high audio fidelity, and for
many formats used in portable music players (e.g. MP3, Vorbis) where
adequate fidelity can be retained even with the large compression ratios
that are needed to make portable players practical.
.SP
Formats that discard audio signal information are called `lossy'.
Formats that do not are called `lossless'. The term `quality' is used as a
measure of how closely the original audio signal can be reproduced when
using a lossy format.
.SP
Audio file conversion with SoX is lossless when it can be, i.e. when not
using lossy compression, when not reducing the sampling rate or number
of channels, and when the number of bits used in the destination format
is not less than in the source format. E.g. converting from an 8-bit
PCM format to a 16-bit PCM format is lossless but converting from an
8-bit PCM format to (8-bit) A-law isn't.
.SP
.B N.B.
SoX converts all audio files to an internal uncompressed
format before performing any audio processing. This means that
manipulating a file that is stored in a lossy format can cause further
losses in audio fidelity. E.g. with
.EX
sox long.mp3 short.mp3 trim 10
.EE
SoX first decompresses the input MP3 file, then applies the
.B trim
effect, and finally creates the output MP3 file by re-compressing the
audio\*mwith a possible reduction in fidelity above that which
occurred when the input file was created.
Hence, if what is ultimately desired is lossily compressed audio, it is
highly recommended to perform all audio processing using lossless file
formats and then convert to the lossy format only at the final stage.
.SP
.B N.B.
Applying multiple effects with a single SoX invocation will,
in general, produce more accurate results than those produced using
multiple SoX invocations.
.SS Dithering
Dithering is a technique used to maximise the dynamic range of audio
stored at a particular bit-depth. Any distortion introduced by
quantisation is decorrelated by adding a small amount of white noise
to the signal. In most cases, SoX can determine whether the selected
processing requires dither and will add it during output formatting if
appropriate.
.SP
Specifically, by default, SoX automatically adds TPDF dither
when the output bit-depth is less than 24 and any
of the following are true:
.IP \(bu 4
bit-depth reduction has been specified explicitly using a command-line
option
.IP \(bu 4
the output file format supports only bit-depths lower than that of the
input file format
.IP \(bu 4
an effect has increased effective bit-depth within the internal
processing chain
.PP
For example, adjusting volume with
.B vol 0.25
requires two additional bits in which to losslessly store its results
(since 0\*d25 decimal equals 0\*d01 binary). So if the input file
bit-depth is 16, then SoX's internal representation will utilise 18
bits after processing this volume change. In order to store the
output at the same depth as the input, dithering is used to remove the
additional bits.
.SP
Use the
.B \-V
option to see what processing SoX has automatically added. The
.B \-D
option may be given to override automatic dithering. To invoke
dithering manually (e.g. to select a noise-shaping curve), see the
.B dither
effect.
.SS Clipping
Clipping is distortion that occurs when an audio signal level (or
`volume') exceeds the range of the chosen representation. In most
cases, clipping is undesirable and so should be corrected by adjusting
the level prior to the point (in the processing chain) at which it
occurs.
.SP
In SoX, clipping could occur, as you might expect, when using the
.B vol
or
.B gain
effects to increase the audio volume. Clipping could also occur with many
other effects, when converting one format to another, and even when
simply playing the audio.
.SP
Playing an audio file often involves resampling, and processing by
analogue components can introduce a small DC offset and/or
amplification, all of which can produce distortion if the audio signal
level was initially too close to the clipping point.
.SP
For these reasons, it is usual to make sure that an audio
file's signal level has some `headroom', i.e. it does not exceed a particular
level below the maximum possible level for the given representation.
Some standards bodies recommend as much as 9dB headroom, but in most cases,
3dB (\(~~ 70% linear) is enough. Note that this wisdom
seems to have been lost in modern music production; in fact, many CDs,
MP3s, etc. are now mastered at levels \fIabove\fR 0dBFS i.e. the
audio is clipped as delivered.
.SP
SoX's
.B stat
and
.B stats
effects can assist in determining the signal level in an audio file. The
.B gain
or
.B vol
effect can be used to prevent clipping, e.g.
.EX
sox dull.wav bright.wav gain \-6 treble +6
.EE
guarantees that the treble boost will not clip.
.SP
If clipping occurs at any point during processing,
SoX will display a warning message to that effect.
.SP
See also
.B \-G
and the
.B gain
and
.B norm
effects.
.SS Input File Combining
SoX's input combiner can be configured (see OPTIONS below) to
combine multiple files using any of the
following methods: `concatenate', `sequence', `mix', `mix-power',
`merge', or `multiply'.
The default method is `sequence' for
.BR play ,
and `concatenate' for
.B rec
and
.BR sox .
.SP
For all methods other than `sequence', multiple input files must have
the same sampling rate. If necessary, separate SoX invocations can be
used to make sampling rate adjustments prior to combining.
.SP
If the `concatenate' combining method is selected (usually, this will be
by default) then the input files must also have the same number of
channels. The audio from each input will be concatenated in the order
given to form the output file.
.SP
The `sequence' combining method is selected automatically for
.BR play .
It is similar to `concatenate' in that the audio from each input file is
sent serially to the output file. However, here the output file may be
closed and reopened at the corresponding transition between input
files. This may be just what is needed when sending different types of
audio to an output device, but is not generally useful when the output is a
normal file.
.SP
If either the `mix' or `mix-power' combining method is selected then two or
more input files must be given and will be mixed together to form the
output file. The number of channels in each input file need not be the
same, but SoX will issue a warning if they are not and some
channels in the output file will not contain audio from every input
file. A mixed audio file cannot be un-mixed without reference to the
original input files.
.SP
If the `merge' combining method is selected then two or
more input files must be given and will be merged together to form the
output file. The number of channels in each input file need not be the
same. A merged audio file comprises all of the channels from all of the
input files. Un-merging is possible using multiple
invocations of SoX with the
.B remix
effect.
For example, two mono files could be merged to form one stereo file. The
first and second mono files would become the left and right channels of
the stereo file.
.SP
The `multiply' combining method multiplies the sample values of
corresponding channels (treated as numbers in the interval \-1 to +1).
If the number of channels in the input files is not the same, the
missing channels are considered to contain all zero.
.SP
When combining input files, SoX applies any specified effects
(including, for example, the
.B vol
volume adjustment effect) after the audio has been combined. However, it
is often useful to be able to set the volume of (i.e. `balance') the
inputs individually, before combining takes place.
.SP
For all combining methods, input
file volume adjustments can be made manually using the
.B \-v
option (below) which can be given for one or more input files. If it is
given for only some of the input files then the others receive no volume
adjustment. In some circumstances, automatic volume
adjustments may be applied (see below).
.SP
The \fB\-V\fR option (below) can be used to show the input file volume
adjustments that have been selected (either manually or automatically).
.SP
There are some special considerations that need to made when mixing
input files:
.SP
Unlike the other methods, `mix' combining has the
potential to cause clipping in the combiner if no balancing is
performed. In this case, if manual volume adjustments are not given,
SoX will try to ensure that clipping does not occur by automatically
adjusting the
volume (amplitude) of each input signal by a factor of \(S1/\s-2n\s+2,
where n is the number of input files. If this results in audio that is
too quiet or otherwise unbalanced then the input file volumes can be
set manually as described above. Using the
.B norm
effect on the mix is another alternative.
.SP
If mixed audio seems loud enough at some points but
too quiet in others then dynamic range compression should be applied to
correct this\*msee the
.B compand
effect.
.SP
With the `mix-power' combine method, the
mixed volume is approximately equal to that of one of the input signals.
This is achieved by balancing using a factor of
\(S1/\s-2\(srn\s+2 instead of \(S1/\s-2n\s+2.
Note that this balancing factor does not guarantee that clipping will not occur,
but the number of clips will usually be low and the resultant
distortion is generally imperceptible.
.SS Output Files
SoX's default behaviour is to take one or more input files and
write them to a single output file.
This behaviour can be changed by specifying the pseudo-effect `newfile'
within the effects list. SoX will then enter multiple output mode.
In multiple output mode, a new file is created when the effects
prior to the `newfile' indicate they are done.
The effects chain listed after `newfile'
is then started up and its output is saved to the new file.
In multiple output mode, a unique number will automatically be appended
to the end of all filenames. If the filename has an extension
then the number is inserted before the extension. This behaviour can
be customized by placing a %n anywhere in the filename where the
number should be substituted. An optional number can be placed after
the % to indicate a minimum fixed width for the number.
Multiple output mode is not very useful unless an effect that will
stop the effects chain early is
specified before the `newfile'. If end of file is
reached before the effects chain stops itself then no new file
will be created as it would be empty.
The following is an example of splitting the first 60 seconds of an input
file into two 30 second files and ignoring the rest.
.EX
sox song.wav ringtone%1n.wav trim 0 30 : newfile : trim 0 30
.SS Stopping SoX
Usually SoX will complete its processing and exit automatically once
it has read all available audio data from the input files.
.SP
If desired, it can be terminated earlier by sending an
interrupt signal to the process (usually by pressing the
keyboard interrupt key which is normally Ctrl-C). This is a natural requirement
in some circumstances, e.g. when using SoX to make a recording. Note
that when using SoX to play multiple files, Ctrl-C behaves slightly
differently: pressing it once causes SoX to skip to the next file;
pressing it twice in quick succession causes SoX to exit.
.SP
Another option to stop processing early is to use an effect that
has a time period or sample count to determine the stopping
point. The trim effect is an example of this. Once all
effects chains have stopped then SoX will also stop.
.SH FILENAMES
Filenames can be simple file names, absolute or relative path names,
or URLs (input files only). Note that URL support requires that
.BR wget (1)
is available.
.SP
Note:
Giving SoX an input or output filename that is the same as a SoX
effect-name will not work since SoX will treat it as an effect
specification. The only work-around to this is to avoid such
filenames. This is generally not difficult since most audio
filenames have a filename `extension', whilst effect-names do not.
.SS Special Filenames
The following special filenames may be used in certain circumstances
in place of a normal filename on the command line:
.TP
\fB\-\fR
SoX can be used in simple pipeline operations by using the special
filename `\-' which,
if used as an input filename, will cause
SoX will read audio data from `standard input' (stdin),
and which,
if used as the output filename, will cause
SoX will send audio data to `standard output' (stdout).
Note that when using this option for the output file, and sometimes
when using it for an input file, the file-type (see
.B \-t
below) must also be given.
.TP
\fB\(dq\^|\^\fIprogram \fR[\fIoptions\fR] ...\fB\(dq\fR
This can be used in place of an input filename to specify the
the given program's standard output (stdout) be used as an input file.
Unlike
.B \-
(above), this can be used for several inputs to one SoX command. For
example, if `genw' generates mono WAV formatted signals to its
standard output, then the following command makes a stereo file
from two generated signals:
.EX
sox \-M "|genw \-\-imd \-" "|genw \-\-thd \-" out.wav
.EE
For headerless (raw) audio,
.B \-t
(and perhaps other format options) will need to be given, preceding the input
command.
.TP
\fB\(dq\fIwildcard-filename\fB\(dq\fR
Specifies that filename `globbing' (wild-card matching) should be performed
by SoX instead of by the shell. This allows a single set of file options to be
applied to a group of files. For example, if the current directory contains
three `vox' files, file1.vox, file2.vox, and file3.vox, then
.EX
play \-\-rate 6k *.vox
.EE
will be expanded by the `shell' (in most environments) to
.EX
play \-\-rate 6k file1.vox file2.vox file3.vox
.EE
which will treat only the first vox file as having a sample rate of 6k.
With
.EX
play \-\-rate 6k "*.vox"
.EE
the given sample rate option will be applied to all three vox files.
.TP
\fB\-p\fR, \fB\-\-sox\-pipe\fR
This can be used in place of an output filename to specify that
the SoX command should be used as in input pipe to another SoX command.
For example, the command:
.EX
play "|sox \-n \-p synth 2" "|sox \-n \-p synth 2 tremolo 10" stat
.EE
plays two `files' in succession, each with different effects.
.SP
.B \-p
is in fact an alias for `\fB\-t sox \-\fR'.
.TP
\fB\-d\fR, \fB\-\-default\-device\fR
This can be used in place of an input or output filename to specify that
the default audio device (if one has been built into SoX) is to be used.
This is akin to invoking
.B rec
or
.B play
(as described above).
.TP
\fB\-n\fR, \fB\-\-null\fR
This can be used in place of an input or output filename to specify that
a `null file' is to be used. Note that here, `null file' refers to a
SoX-specific mechanism and is not related to any operating-system
mechanism with a similar name.
.SP
Using a null file to input audio is equivalent to
using a normal audio file that contains an infinite amount
of silence, and as such is not generally useful unless used
with an effect that specifies a finite time length
(such as \fBtrim\fR or \fBsynth\fR).
.SP
Using a null file to output audio amounts to discarding the audio
and is useful mainly with effects that produce information about the
audio instead of affecting it (such as \fBnoiseprof\fR or \fBstat\fR).
.SP
The sampling rate associated with a null file
is by default 48\ kHz, but, as with a normal
file, this can be overridden if desired using command-line format
options (see below).
.SS Supported File & Audio Device Types
See
.BR soxformat (7)
for a list and description of the supported file formats and audio device
drivers.
.SH OPTIONS
.SS Global Options
These options can be specified on the command line at any point
before the first effect name.
.SP
The
.B SOX_OPTS
environment variable can be used to provide alternative default values for
SoX's global options.
For example:
.EX
SOX_OPTS="\-\-buffer 20000 \-\-play\-rate\-arg \-hs \-\-temp /mnt/temp"
.EE
Note that setting SOX_OPTS can potentially create unwanted changes in
the behaviour of scripts or other programs that invoke SoX. SOX_OPTS
might best be used for things (such as in the given example) that reflect the
environment in which SoX is being run. Enabling options such as
.B \-\-no\-clobber
as default might be handled better using a shell alias
since a shell alias will not affect operation in scripts etc.
.SP
One way to ensure that a script cannot be affected by SOX_OPTS is to
clear SOX_OPTS at the start of the script, but this of course loses
the benefit of SOX_OPTS carrying some system-wide default options. An
alternative approach is to explicitly invoke SoX with default
option values, e.g.
.EX
SOX_OPTS="\-V \-\-no-clobber"
...
sox \-V2 \-\-clobber $input $output ...
.EE
Note that the way to set environment variables varies from system
to system. Here are some examples:
.SP
Unix bash:
.EX
export SOX_OPTS="\-V \-\-no-clobber"
.EE
Unix csh:
.EX
setenv SOX_OPTS "\-V \-\-no-clobber"
.EE
MS-DOS/MS-Windows:
.EX
set SOX_OPTS=\-V \-\-no-clobber
.EE
MS-Windows GUI: via Control Panel : System : Advanced : Environment
Variables
.SP
Mac OS X GUI: Refer to Apple's Technical Q&A QA1067 document.
.TP
\fB\-\-buffer\fR \fBBYTES\fR, \fB\-\-input\-buffer\fR \fBBYTES\fR
Set the size in bytes of the buffers used for processing audio (default 8192).
.B \-\-buffer
applies to input, effects, and output processing;
.B \-\-input\-buffer
applies only to input processing (for which it overrides
.B \-\-buffer
if both are given).
.SP
Be aware that large values for
.B \-\-buffer
will cause SoX to be become slow to respond to requests to terminate or to skip
the current input file.
.TP
\fB\-\-clobber\fR
Don't prompt before overwriting an existing file with the same name as that
given for the output file. This is the default behaviour.
.TP
\fB\-\-combine concatenate\fR\^|\^\fBmerge\fR\^|\^\fBmix\fR\^|\^\fBmix\-power\fR\^|\^\fBmultiply\fR\^|\^\fBsequence\fR
Select the input file combining method;
for some of these, short options are available:
.B \-m
selects `mix',
.B \-M
selects `merge', and
.B \-T
selects `multiply'.
.SP
See \fBInput File Combining\fR above for a description of the different
combining methods.
.TP
\fB\-D\fR, \fB\-\-no\-dither\fR
Disable automatic dither\*msee `Dithering' above. An example of why this
might occasionally be useful is if a file has been converted from 16 to
24 bit with the intention of doing some processing on it, but in fact
no processing is needed after all and the original 16 bit file has
been lost, then, strictly speaking, no dither is needed if converting the
file back to 16 bit. See also the
.B stats
effect for how to determine the actual bit depth of the audio within a
file.
.TP
\fB\-\-effects\-file \fIFILENAME\fR
Use FILENAME to obtain all effects and their arguments.
The file is parsed as if the values were specified on the
command line. A new line can be used in place of the special \fB:\fR
marker to separate effect chains. For convenience, such markers at the
end of the file are normally ignored; if you want to specify an empty
last effects chain, use an explicit \fB:\fR by itself on the last line
of the file. This option causes any effects specified on the command
line to be discarded.
.TP
\fB\-G\fR, \fB\-\-guard\fR
Automatically invoke the
.B gain
effect to guard against clipping. E.g.
.EX
sox \-G infile \-b 16 outfile rate 44100 dither \-s
.EE
is shorthand for
.EX
sox infile \-b 16 outfile gain \-h rate 44100 gain \-rh dither \-s
.EE
See also
.BR \-V,
.BR \-\-norm,
and the
.B gain
effect.
.TP
\fB\-h\fR, \fB\-\-help\fR
Show version number and usage information.
.TP
\fB\-\-help\-effect \fINAME\fR
Show usage information on the specified effect. The name
\fBall\fR can be used to show usage on all effects.
.TP
\fB\-\-help\-format \fINAME\fR
Show information about the specified file format. The name
\fBall\fR can be used to show information on all formats.
.TP
\fB\-\-i\fR, \fB\-\-info\fR
Only if given as the first parameter to
.BR sox ,
behave as
.BR soxi (1).
.TP
\fB\-m\fR\^|\^\fB\-M\fR
Equivalent to \fB\-\-combine mix\fR and \fB\-\-combine merge\fR, respectively.
.TP
.B \-\-magic
If SoX has been built with the optional `libmagic' library then this
option can be given to enable its use in helping to detect audio file types.
.TP
\fB\-\-multi\-threaded\fR | \fB\-\-single\-threaded\fR
By default, SoX is `single threaded'.
If the \fB\-\-multi\-threaded\fR option is given however then SoX
will process audio channels for most multi-channel
effects in parallel on hyper-threading/multi-core architectures. This
may reduce processing time, though sometimes it may be necessary to use
this option in conjunction with a larger buffer size than is the default
to gain any benefit from multi-threaded processing
(e.g. 131072; see \fB\-\-buffer\fR above).
.TP
\fB\-\-no\-clobber\fR
Prompt before overwriting an existing file with the same name as that
given for the output file.
.SP
.B N.B.
Unintentionally overwriting a file is easier than you might think, for
example, if you accidentally enter
.EX
sox file1 file2 effect1 effect2 ...
.EE
when what you really meant was
.EX
play file1 file2 effect1 effect2 ...
.EE
then, without this option, file2 will be overwritten. Hence, using
this option is recommended. SOX_OPTS (above), a `shell'
alias, script, or batch file may be an appropriate way of permanently
enabling it.
.TP
\fB\-\-norm\fR[\fB=\fIdB-level\fR]
Automatically invoke the
.B gain
effect to guard against clipping and to normalise the audio. E.g.
.EX
sox \-\-norm infile \-b 16 outfile rate 44100 dither \-s
.EE
is shorthand for
.EX
sox infile \-b 16 outfile gain \-h rate 44100 gain \-nh dither \-s
.EE
Optionally, the audio can be normalized to a given level (usually)
below 0 dBFS:
.EX
sox \-\-norm=\-3 infile outfile
.EE
.SP
See also
.BR \-V,
.BR \-G,
and the
.B gain
effect.
.TP
\fB\-\-play\-rate\-arg ARG\fR
Selects a quality option to be used when the `rate' effect is automatically
invoked whilst playing audio. This option is typically set via the
.B SOX_OPTS
environment variable (see above).
.TP
\fB\-\-plot gnuplot\fR\^|\^\fBoctave\fR\^|\^\fBoff\fR
If not set to
.B off
(the default if
.B \-\-plot
is not given), run in a mode that can be used, in conjunction with the
gnuplot program or the GNU Octave program, to assist with the selection
and configuration of many of the transfer-function based effects.
For the first given effect that supports the selected plotting program,
SoX will output commands to plot the effect's transfer function, and
then exit without actually processing any audio. E.g.
.EX
sox \-\-plot octave input-file \-n highpass 1320 > highpass.plt
octave highpass.plt
.EE
.TP
\fB\-q\fR, \fB\-\-no\-show\-progress\fR
Run in quiet mode when SoX wouldn't otherwise do so.
This is the opposite of the \fB\-S\fR option.
.TP
\fB\-R\fR
Run in `repeatable' mode. When this option is given, where
applicable, SoX will embed a fixed time-stamp in the output file (e.g.
\fBAIFF\fR) and will `seed' pseudo random number generators (e.g.
\fBdither\fR) with a fixed number, thus ensuring that successive SoX
invocations with the same inputs and the same parameters yield the
same output.
.TP
\fB\-\-replay\-gain track\fR\^|\^\fBalbum\fR\^|\^\fBoff\fR
Select whether or not to apply replay-gain adjustment to input files.
The default is
.B off
for
.B sox
and
.BR rec ,
.B album
for
.B play
where (at least) the first two input files are tagged with the same Artist and
Album names, and
.B track
for
.B play
otherwise.
.TP
\fB\-S\fR, \fB\-\-show\-progress\fR
Display input file format/header information, and processing progress as
input file(s) percentage complete, elapsed time, and remaining time (if
known; shown in brackets), and the number of samples written to the
output file. Also shown is a peak-level meter, and an indication if
clipping has occurred. The peak-level meter shows up to two channels
and is calibrated for digital audio as follows (right channel shown):
.ne 8
.TS
center;
cI lI cI lI
c l c l.
dB FSD Display dB FSD Display
\-25 \- \-11 ====
\-23 T{
=
T} \-9 ====\-
\-21 =\- \-7 =====
\-19 == \-5 =====\-
\-17 ==\- \-3 ======
\-15 === \-1 =====!
\-13 ===\-
.TE