Ubuntu 22.04: Issue with audio device in BasicSoundOutputDemo

Hi everyone :slight_smile:

When I run the BasicSoundOutputDemo (Psychtoolbox-3 - BasicSoundOutputDemo), it crashes when trying to open a PortAudio audio device. I get these errors :


PTB-INFO: Choosing deviceIndex 0 [HDA Intel PCH: ALC269VB Analog (hw:0,0)] as default output audio device.
PTB-ERROR: Desired audio parameters for device -1 unsupported by audio device: Illegal combination of I/O devices
PTB-ERROR: This could be, e.g., due to an unsupported combination of audio sample rate, audio channel count/allocation, or audio sample format.
PTB-ERROR: On Linux you may be able to use ALSA audio converter plugins to make this work.
Error in function Open: Usage error
Failed to open PortAudio audio device due to unsupported combination of audio parameters.

Could not open device at wanted playback frequency of 48000 Hz. Will retry with device default frequency.
Sound may sound a bit out of tune, 


PTB-INFO: Choosing deviceIndex 0 [HDA Intel PCH: ALC269VB Analog (hw:0,0)] as default output audio device.
PTB-ERROR: Desired audio parameters for device -1 unsupported by audio device: Illegal combination of I/O devices
PTB-ERROR: This could be, e.g., due to an unsupported combination of audio sample rate, audio channel count/allocation, or audio sample format.
PTB-ERROR: On Linux you may be able to use ALSA audio converter plugins to make this work.
Error in function Open: Usage error
Failed to open PortAudio audio device due to unsupported combination of audio parameters.
Error using PsychPortAudio
Usage:

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

Error in BasicSoundOutputDemo (line 90)
pahandle = PsychPortAudio(‘Open’, device, , 0, , nrchannels);

I am using :

  • Linux Ubuntu 22.04 LTS (“The Jammy Jellyfish”)
  • MATLAB R2023a
  • 3.0.19 - Flavor: Debian package - psychtoolbox-3 (3.0.19.0.dfsg1-2~nd20.04+1)
  • Only one monitor (which is my XScreen0) with built-in speakers

I have ALSA audio converter already installed.

Thank you in advance for your help!

Hi

Could be somehow related to Audio-related crash: "Desired audio parameters for device -1 unsupported by audio device: Illegal combination of I/O devices" - symptoms sound similar.

Problem seems to be restricted to Ubuntu 22.04 LTS so far, and only to some sound hardware and only under some unclear conditions. I could not reproduce it with Ubuntu 22.04 LTS on any of my machines, despite having even some identical hardware.

That issue is unresolved so far, and I think it would take an unknown number of hours of work time to dig deeper, so it won’t happen without users paying for it.

Does sound work otherwise, ie. with other applications?

Maybe follow all steps in that linked issue and report all wanted information? Definitely post your paid support membership authentication token, which your lab surely has bought, or I won’t even be able to do the most basic evaluation of your problem.

That said, if the problem is related, then a simple support membership won’t pay enough for a quick fix, and trying to fix this will cost substantial money. Just getting some replacement sound-card, e.g., a cheap USB one, if timing is of less importance, might be the cheapest and fastest solution at the moment.

Unfortunately, due to the lack of funding (not) provided by the vast majority of our short-sighted users, I can no longer afford to deal with such issues for free or for cheap.

Also: My 1 week vacation has basically started just now, so even if you have a paid membership, any non-trivial attempt at a solution will have to wait for at least 1 week.

-mario

While my main dev machine never sees this error, I have seen the error on several lab machines at random (all Dells with built0in sound, on 22.04). I have still to find an easy set of steps to reproduce, without which it is impossible for Mario to fix. I can only repeat what I did on the other thread (which you should read through thoroughly), sometimes selecting a different audio device works, but you need to step through the list manually till you find one that works. Buying another sound output device could also work around any issues with the built-in sound


Thank you very much for your answers.

I indeed need to specify an audio port (in my case number 3) in the parameters for the code to run as port 0 is selected by default.
However, the program seems to crash unpredictably with either the same error as above or the following one :

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.

Following that, in the PC settings, when testing output audio device, no sound is emitted. However when I run alsamixer, everything is on’. Running PsychPortAudio('Close') in Matlab does not help either. Logging out then logging back in my Linux session solves the issue temporarily as this is a never-ending cycle.

This problem hinders the smooth running of my experiment as I resort to the use of EyeLink (an eye tracking system), which includes sound outputs that are necessary (beeps).

Regards,

Jiji

To solve the problem with the eyelink (which we also use), you can create a custom version of PsychEyelinkDispatchCallback and edit it to remove the use of Beeper and add your own code. I use a universal audioManager that is available to all functions that stops these sorts of crashes. The other recommended solution is to “chain” Snd to PsychPortAudio so it uses the same audio handle, but I had some remaining instability with this solution, so prefer to use a global audioManager.

Here is my custom eyelink callback (you pass it in the defaults structure), where you can see I use my own beep function:

My audioManager is here: opticka/audioManager.m at master · iandol/opticka · GitHub

My eyelinkManager that allows you to specify which callback to pass: opticka/eyelinkManager.m at master · iandol/opticka · GitHub

At least at the moment for me, this is all working with 22.04 for me.

Hi all,

First I would like to thank @mariokleiner and @Ian-Max-Andolina for providing me with different possible solutions.

I finally found a way to make sound work on Linux with Psychtoolbox and Eyelink programs. Please note that this solved my issue but might not work for you.

The idea is to separate visual output from audio output. I display my experiment stimulus on the screen but don’t emit sound from this same screen (that has built-in speakers). Instead, I plugged in to the PC jack a pair of speakers from which the sound for my experiment will be output.

Prerequisite : Know which audio port you’re manipulating

Run this in a Matlab terminal to display the indexes of each available audio port on your computer :

d = PsychPortAudio('GetDevices')
[{d.DeviceIndex}',{d.DeviceName}']

For example, port number 5 is my system default port :

{[ 5]}    {'sysdefault'}

Procedure :

First, check with alsamixer that the channel you are interested in is not muted (for me “Headphone” since I use the jack socket):

Then in a linux terminal run the following commands :

  $ sudo apt install pavucontrol
  $ pavucontrol

This is the PulseAudio VolUme Control configuration panel.

In “Output Devices”, select one device as your default output audio device (for me “Headphones”), then run :

 $ pulseaudio -k

to apply your changes. Preferably, disconnect from your session and restart your computer. Log back into Matlab and select the audio port that corresponds to “system default” port in your programs (see Prerequisite section; for me it’s port of index 5).

Your code should run just fine. Be careful not to unplug the speakers or you would have to restart Matlab and maybe your computer (I mean, in my case this is necessary
).

Extra ways to test your audio output:

You can test the device output set as “default” on your system with this linux command :

$ speaker-test -c 2 

In Matlab you can also run :

PsychPortAudioTimingTest(0,5)

That’s it for me, I hope this can help some of you.

Cheers,

Jiji

1 Like