How can we start different sessions simultaneously?
9 次查看(过去 30 天)
显示 更早的评论
Dear all,
I want to play two different stereo audio (one using my internal laptop audiocard, and the other uaing an external audiocard).
I defined two sessions:
d=daq.getDevices;
dev=d(6);
dev2=d(5);
s1 = daq.createSession('directsound');
noutchan1 = 2;
addAudioOutputChannel(s1, dev.ID, 1:noutchan1);
s2=daq.createSession('directsound');
noutchan2=2;
addAudioOutputChannel(s2, dev2.ID, 1:noutchan2);
after defining my stereo sound like ([audio1L,audio1R] and [audio2L,audio2R]) I run both of them in foreground like below:
queueOutputData(s1,[audio1L,audio1R]);
queueOutputData(s2,[audio2L,audio2R]);
startForeground(s1);
startForeground(s2);
when I run both of them using "startForeground", the first session plays primarily and then the second sound plays afterward.
Is there a way to start two different sessions simultaneously?
Thanks
回答(2 个)
PIYUSH AGGARWAL
2019-6-17
try enclosing the section of the code wfere you are running the foreground in a parfor (Parallel For loop) loop.This automatically assigns workers to your code & runs the section enclosed in the parfor parallely.
You can further refer to the documentation page & see examples.
4 个评论
PIYUSH AGGARWAL
2019-6-19
Hi Mehrdad,
Then I guess you need to share the entire code with me so that I can help you in debugging it. Have you tried debugging at your end? If not, just try to do it by adding breakpoints in the code & see which exact line is causing the issue. I'm positive that it has to do with something related to invalid dot accessing of some illegal data type. Also please share the error message.
Regards,
Piyush
Walter Roberson
2019-6-19
"Is there a way to start two different sessions simultaneously?"
No. And parfor or spmd will not help for this purpose. Starting a session takes a number of software steps and communications with hardware, so even if you succesfully issued two startForeground at the exact same time, the data recording would probably not start at the same time.
There are two approaches that can be followed:
- Do not bother being overly concerned about starting two sessions at the same time. But do use recording mechanisms that record timestamps for the samples, and then have your MATLAB code synchronize the streams according to the timestamps; or
- Do not bother being overly concerned about starting two sessions at the same time. However, configure a common trigger (probably a hardware trigger) for both of them so that even though the sessions might not start at the same time, the hardware starts recording data at the same time.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 National Instruments Frame Grabbers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!