How do you play multiple sound files simultaneously?
조회 수: 17 (최근 30일)
이전 댓글 표시
Hi, Are you able to play multiple sound clips in matlab simultaneously? I have tried using the sound(...) function and wavplay(...) function by calling them one after another in the following manner:
wavplay(soundClip1,Fs) wavplay(soundClip2,Fs) wavplay(soundClip3,Fs)
but this only plays the files in succession, not at the same time. The work-around I have been using is to sum the data in each array into one:
mergedClip = soundClip1+soundClip2+soundClip3; wavplay(mergedClip,Fs)
Does anyone know if there is a way to call a matlab audio function so the separate files play together?
Thanks, Matt
댓글 수: 0
채택된 답변
Walter Roberson
2012년 2월 9일
There is no method provided in MATLAB to play multiple sounds simultaneously. There is no method provided in MATLAB to synchronize multiple audio or video events. Or even to synchronize an audio or video event against some trigger or timer. Or to determine a maximum latency for an audio or video event.
The closest that is available is to use a very recent version of a 64 bit MATLAB, a National Instruments (NI) Digital to Analog converter, the new session-based interface, multiple channels synchronized together, and queue the audio, with the analog output feeding in to some kind of analog mixer. (Possibly it could also be done with the legacy interface and non-NI devices; it should work in principle but I have not yet located specific assurances that the channels would be synchronized.)
Other than that... averaging the signals is the method. Not just adding them together, as that would usually saturate the output. mean() is suitable for the task.
댓글 수: 2
Walter Roberson
2023년 4월 20일
In the years since the above answer was posted, MATLAB added audioplayer, which has a play() method. If you use play() rather than playblocking() then anything else that is being play() for a different audioplayer() object will be played at the same time. However, there will not be any synchronization between the objects.
If the sound were going to different output devices, then these days you could use https://www.mathworks.com/help/audio/ref/audiodevicewriter-system-object.html audioDeviceWriter to keep closer synchronization (but still decidedly imperfect)
For single device if you require synchronization, using mean() is still the way to go.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!