wavread

Read Microsoft WAVE (.wav) sound file

Graphical Interface

As an alternative to wavread, use the Import Wizard. To activate the Import Wizard, select Import Data from the File menu.

Syntax

y = wavread(filename)
[y, Fs, nbits] = wavread(filename)
[...] = wavread(filename, N)
[...] = wavread(filename,[N1 N2])
y = wavread(filename, fmt)
siz = wavread(filename,'size')
[y, fs, nbits, opts] = wavread(...)

Description

y = wavread(filename) loads a WAVE file specified by filename, returning the sampled data in y. The filename input is a string enclosed in single quotes. The .wav extension is appended if no extension is given.

[y, Fs, nbits] = wavread(filename) returns the sample rate (Fs) in Hertz and the number of bits per sample (nbits) used to encode the data in the file.

[...] = wavread(filename, N) returns only the first N samples from each channel in the file.

[...] = wavread(filename,[N1 N2]) returns only samples N1 through N2 from each channel in the file.

y = wavread(filename, fmt) specifies the data type format of y used to represent samples read from the file. fmt can be either of the following values.

ValueDescription
'double'y contains double-precision normalized samples. This is the default value, if fmt is omitted.
'native'y contains samples in the native data type found in the file. Interpretation of fmt is case-insensitive, and partial matching is supported.

siz = wavread(filename,'size') returns the size of the audio data contained in filename in place of the actual audio data, returning the vector siz = [samples channels].

[y, fs, nbits, opts] = wavread(...) returns a structure opts of additional information contained in the WAV file. The content of this structure differs from file to file. Typical structure fields include opts.fmt (audio format information) and opts.info (text which may describe title, author, etc.).

Output Scaling

The range of values in y depends on the data format fmt specified. Some examples of output scaling based on typical bit-widths found in a WAV file are given below for both 'double' and 'native' formats.

Native Formats

Number of BitsMATLAB Data TypeData Range
8uint8 (unsigned integer) 0 <= y <= 255
16int16 (signed integer) -32768 <= y <= +32767
24int32 (signed integer) -2^23 <= y <= 2^23-1
32single (floating point) -1.0 <= y < +1.0

Double Formats

Number of BitsMATLAB Data TypeData Range
N<32double-1.0 <= y < +1.0
N=32double-1.0 <= y <= +1.0
Note: Values in y might exceed -1.0 or +1.0 for the case of N=32 bit data samples stored in the WAV file.

wavread supports multi-channel data, with up to 32 bits per sample.

wavread supports Pulse-code Modulation (PCM) data format only.


© 1984-2008 The MathWorks, Inc.