Tools for Sound Processing
141
[x, fs, sampleformat] = auload('filename.ext') Reads an audio wave-
form from a file. Returns the audio samples in data, one column per chan-
nel, one row per time slice. Also returns the sample rate and stored format
(one of ulaw, alaw, char, short, long, float, double). The sample value will
be normalized to the range [-1,1) regardless of the stored format. This
does not do any level correction or DC offset correction on the samples.
ausave('filename.ext', x, fs, format) Writes an audio file with the ap-
propriate header. The extension on the filename determines the layout of
the header. Currently supports .wav and .au layouts. Data is a matrix of
audio samples, one row time step, one column per channel. Fs defaults to
8000 Hz. Format is one of ulaw, alaw, char, short, long, float, double
B.1.1
Digression
In Matlab versions older than 5, the function sound had a bug that is worth
analyzing because it sheds some light on risks that may be connected with the
internal representations of integer numbers. Let us construct a sound as a casual
sequence of numbers having values 1 and -1:
Fs = 8192;
W=rand(size(0:Fs)) - 0.5;
for i = 1:length(W)
if (W(i)>0) W(i) = 1.0;
else W(i) = -1.0;
end;
end;
In order to be convinced that such sound is a spectrally-rich noise we can
plot its spectrum, that would look like that of fig. 1.
Surprisingly enough, in old Matlab versions on Intel-compatible architectures
if the sound W was played using sound(W) the audio outcome was, at most, a
couple of clicks corresponding to the start and end transients.
5
10
15
20
25
30
35
40
45
50
0
500
1000
1500
2000
2500
3000
3500
4000
4500
dB
Hz
line 1
Figure 1: Spectrum of a random 1 and -1 sequence
Next Page >>
<< Previous Page
Back to the Table of Contents