Diepzeevogel
Posts: 3
Joined: Wed Jun 07, 2023 7:56 pm

5 USB audio cards through USB 3.0 hub on RPi 4

Wed Jun 07, 2023 8:07 pm

I'm trying to find a way to play 5 different songs on separate headphones all from a single pi.
I found https://github.com/esologic/pear by esologic, that does the job in theory.
It works for 3 usb audio cards without problem, but I get this error:

Code: Select all

Traceback (most recent call last):
  File "/home/cedric/pear/pear.py", line 113, in <module>
    streams = [create_running_output_stream(index) for index in usb_sound_card_indices]
  File "/home/cedric/pear/pear.py", line 113, in <listcomp>
    streams = [create_running_output_stream(index) for index in usb_sound_card_indices]
  File "/home/cedric/pear/pear.py", line 75, in create_running_output_stream
    output = sounddevice.OutputStream(
  File "/home/cedric/.local/lib/python3.9/site-packages/sounddevice.py", line 1494, in __init__
    _StreamBase.__init__(self, kind='output', wrap_callback='array',
  File "/home/cedric/.local/lib/python3.9/site-packages/sounddevice.py", line 898, in __init__
    _check(_lib.Pa_OpenStream(self._ptr, iparameters, oparameters,
  File "/home/cedric/.local/lib/python3.9/site-packages/sounddevice.py", line 2745, in _check
    raise PortAudioError(errormsg, err, hosterror_info)
sounddevice.PortAudioError: Error opening OutputStream: Unanticipated host error [PaErrorCode -9999]: 'No space left on device' [ALSA error -28]
After changing the raspberry pi config.txt file to disable the built in audio, and one more of the audio cards started working.

I'm using a RPi 4 (4GB) running bullseye Raspberry Pi OS lite x64, a cheap USB 3.0 hub with 7 ports and 5 cheap usb audio dongles. All of these work well individually.

I'm assuming this is an issue with the amount of streams that can be opened. Whether that's a raspberry pi limitation or a bandwidth issue with the USB hub I'm using, I'm not sure. I did come across someone online who managed to get 8 working, so now I'm confused as to what is going wrong.
Does anyone have any information that could help?
The project is due in 2 days, so I need to figure this out asap :?

User avatar
thagrol
Posts: 9843
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: 5 USB audio cards through USB 3.0 hub on RPi 4

Wed Jun 07, 2023 10:30 pm

Diepzeevogel wrote:
Wed Jun 07, 2023 8:07 pm
Does anyone have any information that could help?
The developer of pear probably does. Try contacting them through github.

The last line of that traceback gives you the actually error message. Is your SD card full? If you're using tmpfs has that filled up? Do you have sufficient swap space allocated?

Have you looked at the source code file as given in the traceback to see what's going on and what could be causing it? No I'm not going to do that for you.
The project is due in 2 days, so I need to figure this out asap :?
Homework assignment? Work deadline? ...?

I'm afraid urgency on your part doesn't constitute urgency on ours. Web based forums like this one are not real time and are mostly "staffed" by indivuals who volunteer their time and expertise.

You may want to consider paying someone as it could be the only way you'll make that deadline.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

Diepzeevogel
Posts: 3
Joined: Wed Jun 07, 2023 7:56 pm

Re: 5 USB audio cards through USB 3.0 hub on RPi 4

Thu Jun 08, 2023 11:18 am

I get that this isn't a priority for anyone but me and I'm well aware that no one is going to fix it for me.

I've already contacted the developer of pear and changed a few things in his code.
The SD card still has 11 GB of free space, none of the partitions or temp directories are full, I don't think that's the issue.

I was more curious if this is something that was seen here before in one way or another.
Running into bandwidth issues over USB or trouble getting ALSA to send to multiple devices simultaneously and if there's a fix for those issues.
I found https://github.com/raspberrypi/linux/issues/3962 and was wondering if anyone has more information on this issue?

User avatar
thagrol
Posts: 9843
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: 5 USB audio cards through USB 3.0 hub on RPi 4

Thu Jun 08, 2023 11:23 am

Diepzeevogel wrote:
Thu Jun 08, 2023 11:18 am
Running into bandwidth issues over USB or trouble getting ALSA to send to multiple devices simultaneously and if there's a fix for those issues.
I found https://github.com/raspberrypi/linux/issues/3962 and was wondering if anyone has more information on this issue?
The error message you've posted is related to storage not USB bandwidth so I doubt that issue is relevant. Could be wrong about that though.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
thagrol
Posts: 9843
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: 5 USB audio cards through USB 3.0 hub on RPi 4

Thu Jun 08, 2023 11:52 am

Having taken another look at that traceback, the actuall error isn't being thrown by pear. It's in the init function of the class _StreamBase in sounddevice.py.

That make a call to

Code: Select all

_lib.Pa_OpenStream(self._ptr, iparameters, oparameters,
                                  samplerate, blocksize, stream_flags,
                                  callback_ptr, userdata
so it's likely that something that call does needs more space in some storage device than is available.

_lib appears to be a reference to _sounddevice.ffi though it's created using a technique I'm not familiar with (see line 72) and I don't see where _sounddevice exists or is defined. It's not part of the standard library. or of that github repo.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 14820
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: 5 USB audio cards through USB 3.0 hub on RPi 4

Thu Jun 08, 2023 4:14 pm

thagrol wrote:
Thu Jun 08, 2023 11:23 am
Diepzeevogel wrote:
Thu Jun 08, 2023 11:18 am
Running into bandwidth issues over USB or trouble getting ALSA to send to multiple devices simultaneously and if there's a fix for those issues.
I found https://github.com/raspberrypi/linux/issues/3962 and was wondering if anyone has more information on this issue?
The error message you've posted is related to storage not USB bandwidth so I doubt that issue is relevant. Could be wrong about that though.
Error -28 https://elixir.bootlin.com/linux/latest ... base.h#L32

Code: Select all

#define	ENOSPC		28	/* No space left on device */
No space of some form (not necessarily storage) left on the device.

XHCI USB driver (as used by the VLI805) https://elixir.bootlin.com/linux/latest ... ci.c#L2195

Code: Select all

	case COMP_BANDWIDTH_ERROR:
	case COMP_SECONDARY_BANDWIDTH_ERROR:
		dev_warn(&udev->dev,
			 "Not enough bandwidth for new device state.\n");
		ret = -ENOSPC;
		/* FIXME: can we go back to the old state? */
		break;
Checking the kernel logs for any error messages after it happens would be worthwhile.

Diepzeevogel is right that https://github.com/raspberrypi/linux/issues/3962 is likely to be very similar to his issue.
The recommendation in https://github.com/raspberrypi/linux/is ... -733653714 (seeing as P33M is our USB expert) is the most likely to work.
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
thagrol
Posts: 9843
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: 5 USB audio cards through USB 3.0 hub on RPi 4

Thu Jun 08, 2023 4:22 pm

Fair enough. You guys clearly know more about the USB system that I do.

Does USB 2 have enough bandwidth to drive five simultaneous audio streams though?
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

drgeoff
Posts: 13731
Joined: Wed Jan 25, 2012 6:39 pm

Re: 5 USB audio cards through USB 3.0 hub on RPi 4

Thu Jun 08, 2023 4:38 pm

thagrol wrote:
Thu Jun 08, 2023 4:22 pm
Fair enough. You guys clearly know more about the USB system that I do.

Does USB 2 have enough bandwidth to drive five simultaneous audio streams though?
A stereo pair of 16 bit 44.1 kHz (ie CD) is only about 1.5 Mbit/s.
Quis custodiet ipsos custodes?

User avatar
thagrol
Posts: 9843
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: 5 USB audio cards through USB 3.0 hub on RPi 4

Thu Jun 08, 2023 4:48 pm

drgeoff wrote:
Thu Jun 08, 2023 4:38 pm
thagrol wrote:
Thu Jun 08, 2023 4:22 pm
Fair enough. You guys clearly know more about the USB system that I do.

Does USB 2 have enough bandwidth to drive five simultaneous audio streams though?
A stereo pair of 16 bit 44.1 kHz (ie CD) is only about 1.5 Mbit/s.
Yeah, I'm so used to thinking of USB 2 as the poor cousin to USB 3 that I sometimes forget how little bandwidth is actually needed for CD quality audio. Oops. Again.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 14820
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: 5 USB audio cards through USB 3.0 hub on RPi 4

Thu Jun 08, 2023 5:04 pm

USB 2 and USB 3 are actually two independent interfaces down the same connector, so even if you plug a USB 3 hub into a USB 3 port, USB 2 devices plugged into that are limited to the USB 2 480Mbit/s (assuming high speed) from the host.
Run "lsusb -t" and you'll see what I mean. On my system with a USB3 flash drive and a USB 1 keyboard I get

Code: Select all

pi@raspberrypi:~/v4l-utils $ lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
    |__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 3: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 3: Dev 3, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 4: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
Audio interfaces can enumerate as full speed (such a misnamed rate) for 12Mbit/s.
How USB 2 hubs handle downrating a full speed (480Mbit/s) host interface to full speed devices is down to the hub. Hubs are either single or multi TT (Transaction Translator). If it is a single, then you have a 12Mbit/s (before overheads) across all full speed devices.

On top of all this, the VLI805 has some limits on the bandwidth that can be assigned to particular types of transaction.

Without knowing exactly what each device is asking for in terms of interface speed and transfer types, it's very hard to determine exactly what is unhappy or how to potentially get around it.
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Diepzeevogel
Posts: 3
Joined: Wed Jun 07, 2023 7:56 pm

Re: 5 USB audio cards through USB 3.0 hub on RPi 4

Thu Jun 08, 2023 5:26 pm

I followed 6by9's advice and went the usb C hub route. All I had to do was add "dtoverlay=dwc2,dr_mode=host" to /boot/config.txt and everything worked without issue.
It's not very pretty, but at least I know that it works and the deadline can be respected.
Even though it works, I would still like to get it to use the regular USB port.

Honestly I don't understand most of the talk about this VLI805 controller I find online.
@6by9, could you elaborate on how to get the transfer rate and interface speeds?

This is what "lsusb -t" gives me for all devices plugged in right now.

Code: Select all

/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=dwc2/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 1: Dev 3, If 2, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 1: Dev 3, If 0, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 1: Dev 3, If 3, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 1: Dev 3, If 1, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 2: Dev 4, If 0, Class=Hub, Driver=hub/4p, 480M
            |__ Port 1: Dev 6, If 0, Class=Hub, Driver=hub/4p, 480M
                |__ Port 2: Dev 9, If 2, Class=Audio, Driver=snd-usb-audio, 12M
                |__ Port 2: Dev 9, If 0, Class=Audio, Driver=snd-usb-audio, 12M
                |__ Port 2: Dev 9, If 3, Class=Human Interface Device, Driver=usbhid, 12M
                |__ Port 2: Dev 9, If 1, Class=Audio, Driver=snd-usb-audio, 12M
                |__ Port 3: Dev 11, If 3, Class=Human Interface Device, Driver=usbhid, 12M
                |__ Port 3: Dev 11, If 1, Class=Audio, Driver=snd-usb-audio, 12M
                |__ Port 3: Dev 11, If 2, Class=Audio, Driver=snd-usb-audio, 12M
                |__ Port 3: Dev 11, If 0, Class=Audio, Driver=snd-usb-audio, 12M
                |__ Port 4: Dev 12, If 3, Class=Human Interface Device, Driver=usbhid, 12M
                |__ Port 4: Dev 12, If 1, Class=Audio, Driver=snd-usb-audio, 12M
                |__ Port 4: Dev 12, If 2, Class=Audio, Driver=snd-usb-audio, 12M
                |__ Port 4: Dev 12, If 0, Class=Audio, Driver=snd-usb-audio, 12M
            |__ Port 2: Dev 8, If 2, Class=Audio, Driver=snd-usb-audio, 12M
            |__ Port 2: Dev 8, If 0, Class=Audio, Driver=snd-usb-audio, 12M
            |__ Port 2: Dev 8, If 3, Class=Human Interface Device, Driver=usbhid, 12M
            |__ Port 2: Dev 8, If 1, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 3: Dev 5, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        |__ Port 4: Dev 7, If 0, Class=Hub, Driver=hub/4p, 480M
            |__ Port 4: Dev 10, If 0, Class=Vendor Specific Class, Driver=r8152, 480M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
So a single usb audio device is this

Code: Select all

                |__ Port 2: Dev 9, If 2, Class=Audio, Driver=snd-usb-audio, 12M
                |__ Port 2: Dev 9, If 0, Class=Audio, Driver=snd-usb-audio, 12M
                |__ Port 2: Dev 9, If 3, Class=Human Interface Device, Driver=usbhid, 12M
                |__ Port 2: Dev 9, If 1, Class=Audio, Driver=snd-usb-audio, 12M

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 14820
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: 5 USB audio cards through USB 3.0 hub on RPi 4

Thu Jun 08, 2023 5:51 pm

I've not got the time to go into detail now, but will throw in a couple of links for reading material
TTs:
https://www.tomshardware.com/reviews/us ... 677-3.html
https://www.infineon.com/dgdl/Infineon- ... 4c6b726c40
https://en.wikipedia.org/wiki/USB_hub

USB transfer methods (Isochronous/Interrupt/Bulk):
https://en.wikipedia.org/wiki/Universal ... tem_design
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Troubleshooting”