How can we start different sessions simultaneously?

5 visualizaciones (últimos 30 días)
Mehrdad Bahadori
Mehrdad Bahadori el 17 de Jun. de 2019
Comentada: devd dfgfds;xxx el 4 de Jun. de 2021
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

Respuestas (2)

PIYUSH AGGARWAL
PIYUSH AGGARWAL el 17 de Jun. de 2019
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 comentarios
Mehrdad Bahadori
Mehrdad Bahadori el 18 de Jun. de 2019
I conrrected my script here and then ran yours also. still the same error :(
PIYUSH AGGARWAL
PIYUSH AGGARWAL el 19 de Jun. de 2019
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

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 19 de Jun. de 2019
"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:
  1. 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
  2. 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.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by