From Schmid.wiki
Jump to: navigation, search

Sox Cheat Sheet

Note double dashes, even on single-letter parameters:

sox --i file.wav                  # get info
sox in.wav out.wav trim 48000s 48000s # out.wav is in.wav trimmed to [48000;96000] samples
                                      # note that in.wav and out.wav cannot be the same file!

Copy samples [48000;96000] to [0;48000] using two temporary files:

sox input.wav tmp1.wav trim 48000s 48000s
sox input.wav tmp2.wav trim 0s 48000s
sox tmp1.flac tmp2.flac output.wav

Remove DC offset using highpass filter:

sox input.wav output.wav highpass 10 # 10 Hz, 12dB/octave

Sample-Accurate Editing with Audacity

When exporting loops from a DAW such as Ableton Live, glitches may occur when either unsynchronized sample loops or unsynchronized time-varying effects are used. For example, Ableton effects such as Chorus or Reverb that uses Spin or Chorus will often result in imperfect loops. To obtain glitch-free loops, we can either ensure that we only use time-invariant effects such as delay, or we can fix the loop in post-processing.

Looping Using Sync Point

Possible sync point

If a looped waveform has a point where all loops are audibly the same, for example a point with complete silence, we can use this point to loop the waveform perfectly. We call such a point a sync point.

We want to create a glitch-free loop from a waveform that has a sync point. The input waveform must at least contain a full loop followed by the part until the sync point.

We create the glitch-free loop by copying from the start of the second loop to the sync point to the start of the first loop.

In this example, we assume that there is a sync point after exactly 2 beats. We then want to copy the first 2 beats of the second loop to the first 2 beats of the first loop. We need the input waveform to contain at least 2 beats more than a full loop.

Example, assuming a sample rate of 44100 smp/s:

loop tempo        : 140 BPM
beat_duration(140): 18900 smp
loop length       : 24*4 beats
                    = 24*4*60*44100/140 smp
                    = 1814400 smp
2 beats length    : 2*18900 smp = 37800 smp
To be specific, we want to copy the range [1814400;1814400+37800] to [0;37800].

Audacity-looping1.png

We manually enter the selection and copy:

Selection Start: 1814400 samples
Length         :   37800 samples

Audacity-looping2.png

Then change the selection:

Selection Start:       0 samples
Length         :   37800 samples 

Audacity-looping3.png

And paste. We can finalize the loop by selecting [0;1814400]:

Selection Start:       0 samples
Length         : 1814400 samples

Audacity-looping4.png

And Trim. We now have a perfectly loopable waveform of exactly 24*4 beats.

Audacity-looping5.png

We can accomplish the same using Sox:

sox input-26bars.flac tmp\input-start.flac trim 1814400s 37800s
sox input-26bars.flac tmp\input-end.flac   trim 37800s 1776600s
sox tmp\input-start.flac tmp\input-end.flac output-24bars.wav