How do I play more than one sound file concurrently with audioDeviceWriter?
3 ビュー (過去 30 日間)
古いコメントを表示
Hi,
Is it possible to play more than one sound file at the same time using audioDeviceWriter? I am using the following snippet of code to play note recordings when midi keys are pressed:
msgs = midireceive(app.device1);
for i = 1:numel(msgs)
msg = msgs(i);
if isNoteOn(msg) == true && msg.Velocity > 0
% select note file
if msg.Note == 48
app.fileReader = dsp.AudioFileReader('OrganArchive\Processed Audio\Swell\Oboe\Audio\Close\C1\S.wav');
else
app.fileReader = dsp.AudioFileReader('OrganArchive\Processed Audio\Swell\Oboe\Audio\Close\A2\S.wav');
end
% Play sound
while ~isDone(app.fileReader) && msg.Velocity > 0
audioData = app.fileReader();
app.deviceWriter(audioData);
drawnow;
if msg.Velocity == 0 || isNoteOff(msg) == true
break;
end
end
My problem is that when more than one key is pressed, they are played one after the other rather than at the same time. How can I get them to play together?
Thanks in advance and please don't hesitate to ask any questions.
0 件のコメント
回答 (2 件)
Brey Laude
2021 年 4 月 15 日
Check this out https://www.mathworks.com/help/audio/ref/audioplayerrecorder-system-object.html
0 件のコメント
Jimmy Lapierre
2021 年 5 月 3 日
If you use audioDeviceWriter (or audioPlayerRecorder), you need to manage each frame yourself, including adding any signals that need to be played at the same time. You might also need to break down your sound into smaller frames for your player to be more responsive.
It might be easier to use sound, which can play multiple sounds at the same time. Or audioplayer, if you maintain multiple copies of the object.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Simulation, Tuning, and Visualization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!