Once we can read the wave file into MATLAB, we can start processing the audio signals by modifying their intensities, or changing their sample rates, and so on. After the audio signals are processed, we need to play them for aural inspection. This section introduces the MATLAB commands for play audio signals.The basic command for playing audio signals is "wavplay". The following example can load a stream of audio signals from the file "handel.mat" and play the signal immediately.
Since the volume of playback is determined by the amplitude of the audio signals, we can change the amplitude to change the volume, as follows.
In the above example, the amplitude is increased gradually, so we can perceive the increasing volume during playback. In particular, "wavplay" assume the input signals are between -1 and 1. When the input signals are out of this bound (too large or too small), we can hear "broken sound". To try this, you can try "wavplay(100*y, fs)" to hear the result. Moreover, we put an extra input argument 'sync' in the above example. This will make "wavplay" to play the signals synchronously. That is, the playback will not start until the previous playback is finished. We shall have more details on this later on.If we change the sample rate during playback, it will affect the time duration as well as the perceived pitch. In the following example, we shall increase the sample rates gradually, so you will hear a shorter sound with high-pitch, similiar to the sound of the Disney cartoon character Donald Fauntleroy Duck.
On the other hand, if we lower the sample rate gradually, we shall get longer and low-pitched sounds. Eventually it will sound like a cow's moo.
If we want to keep the same time duration but increase or decreasing the pitch of audio signals, then we need to perform pitch shift or pitch scaling. It is beyond the scope of this chapter and will be explained in later chapters.If we reverse the audio signals by multiplying by -1, the perception will be exactly the same as the original. (This also serve to demonstrate that human's perception of audio is not affected by its phase.) However, if the reverse the audio signals in time axis, then it will sound like an unknown language. Pleae try the following example.
MATLAB has two modes for playing a stream of audio signals, as follows.The following example can be used to demonstrate these two modes of playback.
- Synchronous: MATLAB will stop all the other execution of commands until the playback is finished.
- Asynchronous: MATLAB will continue the execution of other commands while the playback is proceeded.
After executing the above example, you will hear a synchronous playback with two asynchronous playbacks.When we are using "wavplay(y, fs)", the data type of the variable "y" can assume one of the following types: "double", "single", "int16", "uint8". If the type of "double" is assumed, the range of "y" has to be within -1 and 1. Any out-of-range elements of "y" will be clipped.
MATLAB has another similar command "sound" for playback, which can be used for both Windows and Unix platforms. Please try the following example.
In the above example, we have two playbacks simultaneously at different paces. This is simply because the default mode for "sound" command is asynchronous.Another similar command is "soundsc" which can scale up the audio signals for better playback result. Example follows.
The volume of the original "welcome.wav" is too small. After using "soundsc", the playback result is much better.To achieve better control, MATLAB now provides a more comprehensive command "audioplayer" for audio playback. See the following example.
In the above example, "apObj" is an audio player object created by MATLAB, which contains a number of fields for better control of playback. Then we can use "play" command to do the playback for 3 seconds of the audio player object.If we want to change the sample rate for playback, we need to change the corresponding field in "apObj", as shown in the next example.
Audio Signal Processing and Recognition (音訊處理與辨識)