Multichannel Audio in Ubuntu 22.04

I would like to present multichannel audio using PsychPortAudio in Matlab under Ubuntu 22.04.
I have installed a Creative Sound Blaster Audigy Fx - 5.1 PCIe Sound Card (https://au.creative.com/p/sound-blaster/sound-blaster-audigy-fx). As it seems, Ubuntu doesn’t have proper driver for Creative products. However, I am able to get output on all 6 channels using speaker-test command in the BASH when I specify the hardware. The device appears in alsamixer and I can adjust the volume for all 5.1 individual channels (FR, FL … etc).

When I use PsychPortAudio(‘GetDevices’) I get the Sound Blaster Audigy listed with 2 input channels and 6 output channels However i can not Open the device (I get improper combination of parameters even when I leave all parameters blank).

Thus, I have used a USB Sound Blaster X-Fi Surround 5.1 Pro
(Sound Blaster X-Fi Surround 5.1 Pro USB Sound Card - Creative Technology (Australia))
Ubuntu recognises the device and all channels are accessible in Sound setting. However, in Matlab, similar to the PCIe card, I can only use 2 channels (not 6), and the sound is distorted on the 2 channels, while in other apps I have clear sound with no issue.

So as the final remedy, I got a 7.1 HDMI Audio extractor for my Graphic card (AMD Radeon 6600). I see multiple hardware using PsychPortAudio ‘GetDevices’ listed as HDMI hardware, all with 8 output channels. I opened them one by one, but none work. I do not get any error in Matlab though, only in the command prompt I get Jackd error (I do not have jackd installed and I didn’t want to install it to mess up with the sound system).

So for the last resort, I tried to use Matlab audioplayer object. audiodevinfo command in Matlab resturn an identical results as PsychPortAudio ‘GetDevices’. However, I had no luck to get proper multichannel output on any of the 3 devices (PCIe, USB and HDMI).

The multichannel system works fine on Windows 11, however, the graphics timing on Windows is as hell, and it often fails in VSynch test (very often). Also I do not have access to parallel port on windows 11, and there is no way to disable WDM to improve graphics in Windows.

I am using a PC (i5 12 Gen processor, 32G Ram and Radeon Graphics).

I appreciate any help or comments on how to get the audio working in Matlab on Ubuntu.

Thank you.

If speaker test works on your 6 channel cards then it is not a principal audio driver problem, just some problem with PsychPortAudio or portaudio (which is also used by Matlab). So it is probably some solvable problem with enough diagnostics applied.

For up to 30 minutes of my paid help, you can post your paid support authentication token generated via help PsychPaidSupportAndServices.

Also post the full Matlab/terminal output for all the steps you’ve taken, commands you’ve run etc., e.g., also at PsychPortAudio('Verbosity', 10), the output for devs = PsychPortAudio('GetDevices') the terminal output of alsa-info.

-mario

Thanks for the reply.
I have to go back to the lab during the weekdays when the system is available (it is shared between 2-3 labs) to to get these info and screenshots, and the support token.

However in case anyone has experience of using multichannel audio in linux-based Matlab, would be great to share. I am aware of list of supported devices in alsa, linux audio and pulseaudio pages. However, these pages are dated, and I can not find the new audio devices which are currently available in the market in these lists, and also these lists are not related to Matlab/PortAudio, as I have the multichannel audio currently working in the linux atm but it does not work in Matlab/PortAudio.

Please avoid screenshots if possible. Use the Matlab diary on function instead to get most output logged to a diary.txt file you can post. Or copy & paste. With Matlab, sometimes part of the lower level debug output goes to a terminal window instead of the Matlab command window, so launching Matlab from a terminal, or even without the GUI in ‘-nodesktop’ mode can be a good idea. At least on Linux and macOS it can help, on Windows it is usually a lost cause for that output.

One should also mention that Matlab ships its own libportaudio.so library which overrides the system provided libraries, so depending on the relative age of the Linux distribution and Matlab version, one may end up with a less or more capable version of Portaudio, compared to running PTB under Octave.

I’ve updated our Wiki page, reachable via …
http://psychtoolbox.org/requirements.html#short-version

… or directly via …

about sound hardware with the current state of affairs, and the template for a list where users could contribute their results if they were inclined to do so.

I have managed to fix the issue with the Creative USB FXi Sound Blaster. But still no lock with HDMI or the PCIe devices.
To be honest I don’t know what I did that it suddenly started to function, so I can not give an informed way to fix the issue, as I was playing with different options, pulseaudio config files .config/pulse and settings, loading modules etc. However, my final bet is, a whole system reboot (and not just Matlab) with those settings may have fixed the issue.

here is the screenshot of how it looks now:

The 5.1 setting on the sound setting on the computer works fine with no issue for the USB FX Sound card:


The output of PsychPortAudio ‘GetDevices’ command:

0	8	'ALSA'	'HDA Intel PCH: ALC897 Analog (hw:0,0)'	2	2	0.00870748299319728	0.0348299319727891	0.00870748299319728	0.0348299319727891	44100
1	8	'ALSA'	'HDA Intel PCH: ALC897 Digital (hw:0,1)'	0	2	-1	-1	0.00870748299319728	0.0348299319727891	44100
2	8	'ALSA'	'HDA Intel PCH: ALC897 Alt Analog (hw:0,2)'	2	0	0.00870748299319728	0.0348299319727891	-1	-1	44100
3	8	'ALSA'	'SB X-Fi Surround 5.1 Pro: USB Audio (hw:1,0)'	2	6	0.00800000000000000	0.0320000000000000	0.00800000000000000	0.0320000000000000	48000
4	8	'ALSA'	'SB X-Fi Surround 5.1 Pro: USB Audio #1 (hw:1,1)'	0	2	-1	-1	0.00870748299319728	0.0348299319727891	44100
5	8	'ALSA'	'HDA ATI HDMI: 0 (hw:2,3)'	0	8	-1	-1	0.00870748299319728	0.0348299319727891	44100
6	8	'ALSA'	'HDA ATI HDMI: 1 (hw:2,7)'	0	8	-1	-1	0.00870748299319728	0.0348299319727891	44100
7	8	'ALSA'	'HDA ATI HDMI: 2 (hw:2,8)'	0	8	-1	-1	0.00870748299319728	0.0348299319727891	44100
8	8	'ALSA'	'HDA ATI HDMI: 3 (hw:2,9)'	0	8	-1	-1	0.00870748299319728	0.0348299319727891	44100
9	8	'ALSA'	'HDA ATI HDMI: 4 (hw:2,10)'	0	8	-1	-1	0.00870748299319728	0.0348299319727891	44100
10	8	'ALSA'	'HDA Creative: ALC898 Analog (hw:3,0)'	2	6	0.00870748299319728	0.0348299319727891	0.00870748299319728	0.0348299319727891	44100
11	8	'ALSA'	'HDA Creative: ALC898 Alt Analog (hw:3,2)'	2	0	0.00870748299319728	0.0348299319727891	-1	-1	44100
12	8	'ALSA'	'sysdefault'	128	128	0.0213333333333333	0.0213333333333333	0.0213333333333333	0.0213333333333333	48000
13	8	'ALSA'	'front'	0	2	-1	-1	0.00870748299319728	0.0348299319727891	44100
14	8	'ALSA'	'surround40'	0	2	-1	-1	0.00870748299319728	0.0348299319727891	44100
15	8	'ALSA'	'surround51'	0	2	-1	-1	0.00870748299319728	0.0348299319727891	44100
16	8	'ALSA'	'surround71'	0	2	-1	-1	0.00870748299319728	0.0348299319727891	44100
17	8	'ALSA'	'iec958'	0	2	-1	-1	0.00870748299319728	0.0348299319727891	44100
18	8	'ALSA'	'spdif'	0	2	-1	-1	0.00870748299319728	0.0348299319727891	44100
19	8	'ALSA'	'samplerate'	128	128	0.00775510204081633	0.0232199546485261	0.00775510204081633	0.0232199546485261	44100
20	8	'ALSA'	'speexrate'	128	128	0.00775510204081633	0.0232199546485261	0.00775510204081633	0.0232199546485261	44100
21	8	'ALSA'	'pulse'	32	32	0.00870748299319728	0.0348299319727891	0.00870748299319728	0.0348299319727891	44100
22	8	'ALSA'	'upmix'	8	8	0.00870748299319728	0.0348299319727891	0.00870748299319728	0.0348299319727891	44100
23	8	'ALSA'	'vdownmix'	6	6	0.00870748299319728	0.0348299319727891	0.00870748299319728	0.0348299319727891	44100
24	8	'ALSA'	'dmix'	0	2	-1	-1	0.0213333333333333	0.0213333333333333	48000
25	8	'ALSA'	'default'	32	32	0.00870748299319728	0.0348299319727891	0.00870748299319728	0.0348299319727891	44100

while matlab is running (from bash), on the terminal I get the following messages:

Gtk-Message: 14:42:51.486: Failed to load module "canberra-gtk-module"
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Cannot connect to server socket err = No such file or directory

The output of PsychPortAudio(‘Open’) when openning the PCIe device (5.1 settings)

ahandle = PsychPortAudio('Open',10,[],[],48000,6);
PTB-INFO: Trying to suspend potentially running PulseAudio server... ... status 0
PTB-DEBUG: PortAudio library lacks PaUtil_SetDebugPrintFunction(). Low-Level PortAudio debugging output unavailable.
PTB-INFO: Using PortAudio V19.7.0-devel, revision 147dd722548358763a8b649b3e4b41dfffbcfbb6
PTB-ERROR: Desired audio parameters for device 10 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]);

The funny thing is this command works fine with the PCIe device, playing the sound on every individual speaker (all 6 channels) correctly:
myself@EEG-Lab:~$ speaker-test --buffer 100000 -D surround51:2,0 -c 6 -t wav

The Alsamixer with PCIe acrd chosen looks like this:

I used to have the HDMI and the PCIe both present in pavucontrol, however, since the FXi is working, they have disappeared:

It will work fine for the purpose of my experiment with this system now , as my experiment doesn’t reply on the exact onset of the stimulus (I have a hardware bit sent to the EEG trigger when sound is present, a bit of electronics involved there), and technically I would like to have some randomness in the start of the stimulus (though just relying on the soundcard delays, it is not detectable by a human). But I am curious how to fix the issue with the PCIe card for future references (?!).

Given that the PsychPortAudio driver, or libportaudio, do not actually use Pulseaudio in any way, it is not impossible but rather unlikely that any of your tinkering with Pulseaudio config files did anything. Maybe the system reboot did.

Those are normal.

Sound onset timing typically should be still somewhat accurate even for USB soundcards, at least better than on Windows or macOS. My last measurements on Ubuntu 20.04 a long time ago with some cheap USB stereo soundcard showed about 6 msecs, not as good as with PCI (sub-millisecond) but also not totally horrible, compared to macOS 10.15 (~8.5 msecs) or Windows-10 21H1 (more than 19 msecs). Linux received improvements since then wrt. low-latency USB audio, so Ubuntu 22.04 should probably be better, but no testing has been performed since 20.04.

Given speaker-test apparently works, it is likely a limitation or bug of libportaudio, which may or may not be fixable. More terminal debug output can be potentially produced by additionally executing setenv('LIBASOUND_DEBUG','1') before calling PsychPortAudio the first time in a session.

But if you are curious, you’ll have to pay for whatever time it takes to debug such things, as explained before. Or just stay curious…

-mario