cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: libsndfile and GNU Octave cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85:
cannam@85:

libsndfile and GNU Octave

cannam@85:

cannam@85: GNU Octave is a high-level interactive cannam@85: language for numerical computations. cannam@85: There are currently two development streams, a stable 2.0.X series and a cannam@85: development 2.1.X series. cannam@85: Octave reads and writes data in binary formats that were originally developed cannam@85: for cannam@85: MATLAB. cannam@85: Version 2.0.X of Octave uses binary data files compatible with MATLAB cannam@85: version 4.2 while Octave 2.1.X uses binary data files compatible cannam@85: with MATLAB version 5.0 as well as being able to read the older MATLAB 4.2 cannam@85: format. cannam@85:

cannam@85:

cannam@85: From version 1.0.1 of libsndfile onwards, libsndfile has the ability of reading cannam@85: and writing a small subset of the binary data files used by both versions cannam@85: of GNU Octave. cannam@85: This gives people using GNU Octave for audio based work an easy method of cannam@85: moving audio data between GNU Octave and other programs which use libsndfile. cannam@85:

cannam@85:

cannam@85: For instance it is now possible to do the following: cannam@85:

cannam@85: cannam@85: cannam@85:

cannam@85: Another example would be using the MAT4 or MAT5 file formats as a format which cannam@85: can be easily loaded into Octave for viewing/analyzing as well as a format cannam@85: which can be played with command line players such as the one included with cannam@85: libsndfile. cannam@85:

cannam@85: cannam@85:

Details

cannam@85:

cannam@85: Octave, like most programming languages, uses variables to store data, and cannam@85: Octave variables can contain both arrays and matrices. cannam@85: It is also able to store one or more of these variables in a file. cannam@85: When reading Octave files, libsndfile expects a file to contain two cannam@85: variables and their associated data. cannam@85: The first variable should contain a variable holding the file sample rate cannam@85: while the second variable contains the audio data. cannam@85:

cannam@85:

cannam@85: For example, to generate a sine wave and store it as a binary file which cannam@85: is compatible with libsndfile, do the following: cannam@85:

cannam@85:
cannam@85:         octave:1 > samplerate = 44100 ;
cannam@85:         octave:2 > wavedata = sin ((0:1023)*2*pi/1024) ;
cannam@85:         octave:3 > save sine.mat samplerate wavedata 
cannam@85: 
cannam@85: cannam@85:

cannam@85: The process of reading and writing files compatible with libsndfile can be cannam@85: made easier by use of two Octave script files : cannam@85:

cannam@85:
cannam@85:         octave:4 > [data fs] = sndfile_load ("sine.mat") ;
cannam@85:         octave:5 > sndfile_save ("sine2.mat", data, fs) ;
cannam@85: 
cannam@85:

cannam@85: In addition, libsndfile contains a command line program which which is able cannam@85: to play the correct types of Octave files. cannam@85: Using this command line player sndfile-play and a third Octave script cannam@85: file allows Octave data to be played from within Octave on any of the platforms cannam@85: which sndfile-play supports (at the moment: Linux, MacOS X, Solaris and cannam@85: Win32). cannam@85:

cannam@85:
cannam@85:         octave:6 > sndfile_play (data, fs) ;
cannam@85: 
cannam@85:

cannam@85: These three Octave scripts are installed automatically in Octave's site cannam@85: script directory when libsndfile is installed (except on Win32) ie when cannam@85: libsndfile is being installed into /usr/local, the Octave scripts will cannam@85: be installed in /usr/local/share/octave/site/m/. cannam@85:

cannam@85: cannam@85:

cannam@85: There are some other Octave scripts for audio to be found cannam@85: here. cannam@85:

cannam@85: cannam@85:
cannam@85: cannam@85: cannam@85:
cannam@85:

cannam@85: The libsndfile home page is here : cannam@85: cannam@85: http://www.mega-nerd.com/libsndfile/. cannam@85:

cannam@85: cannam@85: cannam@85: