How do you play multiple sound files simultaneously?
9 ビュー (過去 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!