필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 10월 16일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by