Author Archives: admin

Installing sox with mp3 support: 64-bit and ARM

Nowadays, the right way to install sox on macOS is Homebrew. Simply by using the following command in the terminal:

brew install sox

This installs sox and all its dependencies on macOS 10.12 Sierra and higher including building/patching libmad for both 64-bit Intel and ARM (Apple silicon) architectures.

https://formulae.brew.sh/formula/sox

Checked and working here on both High Sierra (64-bit Intel) and Big Sur (ARM).

Building sox with mp3 support (UPDATED). Works on OSX 10.9 Mavericks.

This is a revised set of instructions to get sox working on OSX with mp3 support. I recently went through the process that I explained in a previous post on a fresh OSX 10.9 Mavericks system. It was quite straightforward to get sox+mp3 working based on those instructions. I realized, though, that some small changes were needed to make it work.

1. Download sox, and the lame and libmad tarballs: sox-14.4.1, lame-3.99.5, libmad-0.15.1b. Build all three from source forcing a 32-bit build (libmad is a bit old):

2. Build libmad using the following configure flags:

./configure CFLAGS="-m32 -arch i386" LDFLAGS="-arch i386" --enable-shared --disable-static
sudo make
sudo make install

3. Build lameĀ using the following configure flags:

./configure CFLAGS="-m32 -arch i386" LDFLAGS="-arch i386" --enable-shared --disable-static
sudo make
sudo make install

4. Build sox with libmad and lame support using the following options:

./configure CFLAGS="-m32 -arch i386" LDFLAGS="-L/usr/local/lib" CPPFLAGS="-I/path/to/your/libmad-0.15.1b -I/path/to/your/lame-3.99.5/include" --with-mad --with-lame
sudo make -s
sudo make install

NOTE: You will need to substitute the “/path/to/your” bit with the real folders where the libmad and lame sources are located on your hard disk (probably in your Downloads/ folder if you didn’t move them).

After running the ./configure line in step #4 you should check the list of optional file formats to make sure that everything went well, i.e. mp3 is now active (“mp3=yes”):

Disclaimer: this may or may not work for you. On my computer the previous steps produce a fully functional sox binary with mp3 encoding/decoding capabilities. Good luck and thanks for your feedback.

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.

mp3

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: http://sox.sourceforge.net/soxformat.html

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

Building sox with mp3 support on OSX (old)

The instructions in this post have been updated, here.

Hi, it took me a bit to figure out how to build sox with mp3 support on OSX, so I thought that sharing how I did it might help others:

1. Download sox, and the lame and libmad tarballs: sox-14.4.1, lame-3.99.5, libmad-0.15.1b. There’s people that claim that it is possible to take advantage of a preexisting installation of the libraries but that didn’t work for me. What works on my system (OSX 10.6.8 / MBP i7 / 64-bit kernel) is to build all three from source forcing a 32-bit build (libmad is a bit old):

2. Build libmad using the following configure flags:

./configure CFLAGS="-m32 -arch i386" LDFLAGS="-arch i386" --enable-shared --disable-static
sudo make
sudo make install

3. Build lameĀ using the following configure flags:

./configure CFLAGS="-m32 -arch i386" LDFLAGS="-arch i386" --enable-shared --disable-static
sudo make
sudo make install

4. Build sox with libmad and lame support using the following options:

./configure CFLAGS="-m32 -arch i386" LDFLAGS="-arch i386" --with-mad --with-lame
sudo make -s
sudo make install

After running the ./configure line in step #4 you should check the list of optional file formats to make sure that everything went well, i.e. mp3 is now active (“mp3=yes”):

Disclaimer: this may or may not work for you. On my computer the previous steps produce a fully functional sox binary with mp3 encoding/decoding capabilities. With this post I am trying to help to the best of my knowledge, but don’t make me responsible if those instructions fail to work for you or even break your computer.

Good luck!