Problems with Opening PsychAudioPort multiple times in parallel on Ubuntu

nrchannels = 2
pahandle1 = PsychPortAudio(‘Open’, [], 1, [], [], nrchannels, [], 0.015);
pahandle2 = PsychPortAudio(‘Open’, [], 1, [], [], nrchannels, [], 0.015);
pahandle3 = PsychPortAudio(‘Open’, [], 1, [], [], nrchannels, [], 0.015);

Get the following error:

PTB-ERROR: Failed to open audio device 3. PortAudio reports this error: Device unavailable
PTB-ERROR: Could not open audio device, most likely because it is already in use by a previous call to
PTB-ERROR: PsychPortAudio(‘Open’, …). You can open each audio device only once per session. If you need
PTB-ERROR: multiple independent devices simulated on one physical audio device, look into use of audio
PTB-ERROR: slave devices. See help for this by typing ‘PsychPortAudio OpenSlave?’.
Error in function Open: Usage error
Audio device unavailable. Most likely tried to open device multiple times.
Error using PsychPortAudio
Usage:

pahandle = PsychPortAudio(‘Open’ [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][,
suggestedLatency][, selectchannels][, specialFlags=0]);

Error in PAPI_Pro_main (line 321)
pahandle1 = PsychPortAudio(‘Open’, [], 1, [], [], nrchannels, [], 0.015);

How do I fix it? Already installed all the dependencies to run Psychtoolbox on Linux. Sometimes the PsychPortAudio opens the devise but other time I get this error.

do you close it after you open it (so before you run your script again)? It may be in use from a previous session?

Hi,

Now I close it after I open each one of the portaudio, but now I get an error later in the script:
Error in function FillBuffer: Usage error
Invalid audio device handle provided.

for the line:
PsychPortAudio(‘FillBuffer’, pahandle1, S1);
what does that error mean and how do I fix it?

Close them at the end of your script, they need to be open until you no longer need them

Unless you want to use three separate physical sound cards simultaneously, that is the wrong approach. Use of audio slave devices (PsychPortAudio OpenSlave?), as described in PTB’s output, is the way to go if you want to use one physical sound card. We have multiple demos for this, e.g. BasicAMAndMixScheduleDemo.m. If you need further help with the approach from myself, please get your lab to buy priority support.

-mario