Monthly Archives: March 2013

Playing with the sampling rate

1. Writing a user-specified sampling rate to the header of an audio file:

sox -r 48k source.wav destiny.wav

Audio applications will now interpret destiny.wav as a 48 KHz file, even if this is different from the sampling rate originally used to record the file. In that case the pitch and duration of the file with be changed (akin to altering the playback speed of analogue media). I use this occasionally to fix things (or to break them on purpose..).

2. Resampling:

sox source.wav -r 48k destiny.wav

modifies the audio data in the file without altering the pitch and duration of the recording. The rate effect can be used for the same purpose:

sox source.wav destiny.wav rate -v 48k

(-v = Very High Quality Resampling, the documentation recommends to use this option for bit depths > 16 bit)
For further options see here and here.

3. The speed effect is actually a combination of #1 and #2:

sox source.wav destiny.wav speed 1.0884

changes the playback speed of the source file by a certain ratio, and resamples it back to the source sampling rate.


1. Override the default bit rate:

sox myfile.wav -C 192 myfile.mp3

converts myfile.wav to myfile.mp3 with a user-specified bit rate (here, 192 Kbps). Further options that can be passed to the LAME encoder (encoding performance, VBR) are described here:

2. Convert all wav files in a directory to mp3 with a shell command:

for a in *.wav; do sox "$a" -C 192 "$a".mp3; done