Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: libsndfile and GNU Octave Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40:
Chris@40:

libsndfile and GNU Octave

Chris@40:

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

Chris@40:

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

Chris@40:

Chris@40: For instance it is now possible to do the following: Chris@40:

Chris@40: Chris@40: Chris@40:

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

Chris@40: Chris@40:

Details

Chris@40:

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

Chris@40:

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

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

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

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

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

Chris@40:
Chris@40:         octave:6 > sndfile_play (data, fs) ;
Chris@40: 
Chris@40:

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

Chris@40: Chris@40:

Chris@40: There are some other Octave scripts for audio to be found Chris@40: here. Chris@40:

Chris@40: Chris@40:
Chris@40: Chris@40: Chris@40:
Chris@40:

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

Chris@40: Chris@40: Chris@40: