How can I execute the “sound” function in matlab and then execute the rest afterwards? (Blocking)

조회 수: 14 (최근 30일)
for example,I have the following code to make simple a music player,but "sound" function non-blocking(asynchronous) to evaluate,how can i play musics one by one?(I know "audioplayer" object can be used to play my music,but audioplayer is not recommend to use in for loop)
%% 音乐播放器
folder = fullfile(matlabroot,'toolbox','audio','samples');
audis = audioDatastore(folder);
audis = shuffle(audis);
for i = 1:length(audis.Files)
filename = audis.Files{i};
fprintf('%s\n',filename);
[y,Fs] = audioread(filename);
sound(y,Fs) % non-blocking ?
end

채택된 답변

Walter Roberson
Walter Roberson 2021년 7월 31일
sound() cannot be made blocking.
In your situation, if you have the DSP toolbox then dsp.AudioDeviceWriter https://www.mathworks.com/help/dsp/ref/audiodevicewriter-system-object.html is what is recommended; if you have the Audio System Toolbox then AudioDeviceWriter https://www.mathworks.com/help/audio/ref/audiodevicewriter-system-object.html?searchHighlight=audiodevicewriter&s_tid=srchtitle

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by