142
D. Rocchesso: Sound Processing
smoothing
This can be explained by thinking that, on 8 bits, 256 quantization levels
can be represented. A number between -1.0 and +1.0 is recasted into the 8-
bits range by taking the integer part of its product by 128. The problem is
that, when the resulting integer number is represented in two's complement, the
number +1.0 is not representable since, on 8 bits, the largest positive number
that can be represented is 127. Due to the circularity of two's complement
representation, the multiplication 1.0 × 128 produces the number -128, which
is also the representation of -1.0. Therefore, the audio device sees a constant
sequence of numbers equal to the most negative representable number, and it
does not produce any sound, except for the transients due to the initial and final
steps. Once the problem had been discovered and understood, the user could
circumvent it by rescaling the signal in a slightly larger range, e.g., [-1, 1.1].
In the Matlab environment the acquisition and writing of sound files from
and to the disk is done by means of the functions auread(), auwrite(), wavread(),
e wavwrite(). The former couple of functions work with files in au format, while
the latter couple work with files in the popular wav format. In earlier version
of Malab (before version 5) these functions only dealt with 8-bit files, thus pre-
cluding high-quality audio processing. For users of old Matlab versions, two
routines are available for reading and writing 16-bit wav files, called wavr16.m
and wavw16.m, written by F. Caron and modified to ensure Octave compatibil-
ity. An example of usage for wavr16() is
[L,R,format] = wavr16('audiofile.wav')
that returns the right and left channels of the file audiofile.wav, in the
L and R vectors, respectively. The two vectors are identical if the file is mono-
phonic. The returned vector format has four components containing format
information: the kind of encoding (indeed only PCM linear is recognized), the
number of channels, the sample rate, and the number of quantization bits.
An example of invocation of the function wavw16() is
wavw16('audiofile.wav', M, format)
where format is, again, a four-component vector containing format informa-
tion, and M is a one- or two-column matrix containing the channels to be written
in a monophonic or stereophonic file.
Since sounds are handled as monodimensional vectors, sound processing
can be reduced in most cases to vectorial operations. The iterative, sample-by-
sample processing is quite inefficient with interpreters such as Octave or Matlab,
that are optimized to handle matrices. As an example of elementary processing,
consider a simple smoothing operation, obtained by substitution of each input
sound sample with the average between itself and the following sample. Here is
a script that does this operation in Octave, after having loaded a monophonic
sound file:
[L,R,format] = wavr16('ma1.wav');
S = (L + [L(2:length(L)); 0]) / 2; %``smoothed'' sound
The operation is expressed in a very compact way by summation of the vector
L with the vector itself left-shifted by one position
3
. The smoothing operation
may be expressed iteratively as follows:
3
The last element is set to zero to fill the blank left by the left-shift operation on L. The
reader can extend the example in such a way that the input sound is overlapped and summed
with its echo delayed by 200ms.
Next Page >>
<< Previous Page
Back to the Table of Contents