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!