Using the Command-Line Tools in Libsndfile

Using the Command-Line Tools in Libsndfile

with No Comments

libsndfile is a C library written by Erik de Castro Lopo. It is used in a variety of software packages. It includes a collection of command-line programs.

Obtaining and installing libsndfile

Note: Xcode may need to be installed on your computer.

https://developer.apple.com/xcode/

Download the latest version of libsndfile in tar.gz format (when I installed it, the latest version was libsndfile-1.0.27.tar.gz).

http://www.mega-nerd.com/libsndfile/#Download

(The above page no longer appears to be maintained. See the following for obtaining and installing libsndfile:)

https://github.com/libsndfile/libsndfile

Without unarchiving it, move the file to your home directory.

Launch the Terminal app (found at /Applications/Utilities/Terminal.app).

Unarchive the the tar.gz file by invoking the following command in Terminal (make sure to use the name of your version):

tar xzvf libsndfile-1.0.27.tar.gz

Run the configure script by entering each of the following commands in sequence in Terminal (make sure to replace “libsndfile-1.0.27” with the name of your version):

cd libsndfile-1.0.27
./configure
make -s
sudo make install

Put in your password.

You can erase the tar.gz file and the unarchived file from your home folder.

Examples

Note: These examples assume that the audio file(s) you want to edit are in your home folder. Also be sure that you use the correct audio format suffix. In the examples I use .caf, just edit your commands according to what you have (e.g., .aif, .wav, etc.).


De-interleave a multi-channel sound file:

sndfile-deinterleave 3channelfile.caf

Note: Put quotes around the audio file name if it has spaces in it.

The Terminal output will be similar to the following:

Input file : 3channelfile.caf
Output files : 
    3channelfile_00.caf 
    3channelfile_01.caf
    3channelfile_02.caf

The resulting sound files will appear in your home folder.


Interleave multiple mono sound files:

sndfile-interleave monofile_1.caf monofile_2.caf monofile_3.caf -o 3channelfile.caf

Use quotes around audio file names that have spaces in them. Add as many mono sound files as you would like, and name the output anything you would like.


Interleave multiple mono sound files, version 2:

printf "'%s' " *.caf -o "Interleaved Audio File.caf" | xargs sndfile-interleave

As mentioned previously, this command assumes all the mono sound files are in your home directory. It also assumes that all the mono files are .caf. Spaces in the mono sound file names are allowed. The final interleaved file will be named Interleaved Audio File.caf, and will appear in your home folder.

The libsndfile command-line programs

sndfile-cmp

Compare two audio files.


sendfile-concat

Concatenate two or more audio files.


sndfile-convert

Convert a sound files from one format to another.


sndfile-deinterleave

De-interleave a multi-channel file into multiple mono files.


sndfile-info

Display information about a sound file.


sndfile-interleave

Interleave multiple mono files into a single multi-channel file.


sndfile-metadata-get

Get metadata from a sound file.


sndfile-metadata-set

Set metadata in a sound file.


sndfile-play

Play a sound file. Not available in Mac 10.8 and later.


sndfile-salvage

Salvage audio data from WAV files larger than 4GB. See this post.


See the manual page for each program for details (for example, invoke sndfile-cmp -h in the Terminal to see the manual page for sndfile-cmp).

Leave a Reply