PsychPortAudio on Ubuntu 18.04 -- needs EngineTunables setting to avoid hangs


I’m making the move to Linux from macOS, using a Dell Lattitude 9510 laptop running Ubuntu 18.04.5 LTS.

I’ve installed Matlab, matlab-support, PTB, GStreamer and the PTB dependencies (via sudo apt build-dep psychtoolbox-3). All the graphics stuff works fine, as does sound played in video or sounds files via GStreamer [Screen(‘PlayMovie’)].

I’m having trouble with PsychPortAudio. Any use of it (BasicSoundDemo, or my own code) causes Matlab to hang when either a) calling PsychPortAudio(‘Stop’), or b) if PsychPortAudio(‘Stop’) is omitted, upon the subsequent call to PsychPortAudio(‘Start’). When I say “hang”, I mean that the Matlab IDE still responds to mouse and KB input, but considers itself “busy”, and CTRL+C won’t interrupt it. [Edit: this occurs regardless of which sound device I tell PsychPortAudio to use]

I then found that this hang can be stopped by switching the output device between the internal speaker and headphones in the Ubuntu sound settings. As soon as a new device is chosen, the sound plays and Matlab returns to normal.

Setting PsychPortAudio(‘EngineTunables’, [], [], [], 0) instructs PTB not to suspend the audio server during playback, and this prevents the problem from occurring. I don’t totally understand why, but perhaps someone with more Linux knowledge can explain?

One issue with this approach is that the timestamps returned by PsychPortAudio(‘Start’) are ~two hours in the future. I don’t know if this is because I’m not specifying a ‘when’ variable telling the function when to start. If I do this, then the code hangs again, and even changing audio device doesn’t release it.

As it stands, I’m happy with this approach as I can run my experiment. Hopefully this post will be helpful to someone else in the future. If anyone with a better understanding of this stuff has any insights into why this is working (or knows of a better workaround than that which I have attempted) it would be great to hear.



At this time, using Ubuntu 20.04.2 LTS would possibly be a better choice, given 18.04.5’s age by now, approaching retirement age wrt. PTB, as far as i am concerned.

Your problem is not a general one, given that PTB was and is tested also on 18.04-LTS and sound works just fine. Must be specific to your laptops sound hardware or setup.

Timing and timestamping while Pulseaudio is running is not supported, and has known problems like these. Given that suspending the sound server always worked fine and also gives better performance / latency / timing anyway, there wasn’t need to improve this.

Diagnosing this further would require paying for my time via help PsychPaidSupportAndServices. For now this is just a one-off problem for one specific piece of laptop hardware and not a priority.