Digital Sound & Music: Concepts, Applications, & Science, Chapter 2, last updated 6/25/2013

37

This reads an array of audio samples into y, assuming that the file is in the current folder of

MATLAB. (You can set this through the Current Folder window at the top of MATLAB.) If

you want to know the sampling rate and bit depth (the number of bits per sample) of the audio

file, you can get this information with

[y, sr, b] = wavread('HornsE04Mono.wav');

sr now contains the sampling rate and b contains the bit depth. The Workspace window shows

you the values in these variables.

Figure 2.40 Workspace in MATLAB showing results of wavread function

You can play the sound with

sound(y, sr);

Once you've read in a WAV file and have it stored in an array, you can easily do

mathematical operations on it. For example, you can make it quieter by multiplying by a number

less than 1, as in

y = y * 0.5;

You can also write out the new form of the sound file, as in

wavwrite(y, 'HornsNew.wav');

2.3.5 Modeling Sound in Octave

Octave is a freeware, open-source version of MATLAB distributed by GNU. It has many but not

all of the functions of MATLAB. There are versions of Octave for Linux, UNIX, Windows, and

Mac OS X.

If you try to do the above exercise in Octave, most of the functions are the same. The

fplot function is the same in Octave as in MATLAB except that for colors, you must put a digit