issue with running several sound statements...only last statement will play sound

1 view (last 30 days)
I have 4 sound statements in a row. When program is run, only the last sound statement plays wav file. However if I place a breakpoint at first sound statement and then stepthru, all of them play wav file. Is there a statement that needs to go in between sound statements?
%Listen to the sound at the different stages... sound(anlgSig,origSampRate,resolution); %play the original sound sound(sampledSig, reSampRate,resolution); %play the resampled sound signal sound(quantizedSig,reSampRate,resolution); %play the quantized signal sound(recoveredSig(1:length(quantizedSig)),reSampRate,resolution);%play the recovered sound at the receiver

Accepted Answer

Geoff Hayes
Geoff Hayes on 16 Oct 2014
Franklin - since your four sound function calls follow one after the other, all four sounds are playing at roughly the same time. You have a couple of options. The first is to put a pause in between each call to sound given the number of samples being played and the sample rate.
% play the original sound
sound(sampledSig, reSampRate,resolution);
pause(ceil(length(sampledSig)/reSampRate));
% play the resampled sound signal
sound(quantizedSig,reSampRate,resolution);
pause(ceil(length(quantizedSig)/reSampRate));
% etc.
The other option is to use the audioplayer
% play the original sound
player = audioplayer(sampledSig, reSampRate,resolution);
playblocking(player);
% play the resampled sound signal
player = audioplayer(quantizedSig,reSampRate,resolution);
playblocking(player);
% etc.
We use the playblocking function to play the sound and not return control until the playback has completed. A nicer alternative to a pause.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!