The Windows operating system contains a bug that causes a crash when multiplexing several audio streams through one output device. The SOUND function is asynchronous, meaning that after the SOUND function is called, it immediately returns control back to the command line or to the file from where it was called. When the SOUND function is used in a loop, it almost always has the problem specified above.
To work around this problem, you can use the AUDIOPLAYER function in a loop. The 'Playblocking' method of the AUDIOPLAYER function does not return control until playback has completed. The following code is an example of the syntax to use with the AUDIOPLAYER function:
load handel
ap = audioplayer(y,Fs);
playblocking(ap);
You can also use the WAVPLAY function with the additional input argument 'sync' to force the sound device to finish playing the sound and then return control back to MATLAB. The following is an example of the syntax to use for the WAVPLAY function:
load chirp;
y1 = y; Fs1 = Fs;
load gong;
wavplay(y1,Fs1,'sync')
wavplay(y,Fs)
More information about the WAVPLAY and AUDIOPLAYER functions can be found in the help documentation. You can access the help documentation by using the HELP or DOC commands with the following syntax:
help wavplay
doc waveplay
help audioplayer
doc audioplayer
Best Answer