How do I play more than one sound file concurrently with audioDeviceWriter?
4 次查看(过去 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!