Passed through USB soundcard in Virtual Box glitchy

I have the current version of HA 0.114.4 with HASSOS 4.12 in a VirtualBox VM with host Mint 20.

I have passed through a USB sound card that works fine on the host, and am using the local VLC Telnet Add-on to play to it. However, the sound is glitchy and it stutters. In the VLC Telnet config, I can change the IP address to point to a telnet version of VLC running on the host and the audio is fine, so it’s only sound output on the VM that stutters.

I have tried three different USB soundcards of different makes and they all exhibit the same problem.

I’ve searched for glitchy audio in VirtualBox forums - people have indeed experienced this but the answer is invariably to make sure the emulated controller in the VM settings is USB 3.0 (xHCI) rather than the older OHCI and EHCI variants, however this has had no effect with me. I’ve tried different combinations of this together with the audio driver settings in VB (ALSA, Pulse, OSS) and controller settings (Intel HD Audio, ICH AC97) but can’t find any combination that works.

I notice that with the soundcards that have power/status lights on them, once the VM has booted up this light starts flashing continuously. It’s as though it’s continuously losing and regaining power, or otherwise encountering a problem. I’ve tried the devices in different USB slots and also on the end of a powered hub. This symptom does not occur with the sound card on the host. The light is solid for most of the boot sequence but when it gets to where it says “udev is starting”, that’s when it starts to blink.

I also get messages on the VM console that I don’t see when the soundcard is not passed through/connected to the VM - kauditd-printk-skb: n callbacks suppressed, with the n is sometimes very high figures. I believe this is something to do with the Linux kernel suppressing duplicate error messages.

I just wonder if there is something in the Linux kernel that the HASSOS image ships with that is not compatible with certain USB devices. Does anyone have any knowledge of what is going on?

I found usb passthrough to be unreliable when I was passing through my zigbee and zwave usb sticks. Instead I use usbip its a package that allows a “server” to share its usb devices with a “client” over the network… on the client machine the usb device works just the same as any other locally connected usb device. Not saying its the answer to your problems but it might possibly help

For what it’s worth, I’ve got a workaround.

To test what was going wrong with the HASSOS VM, I tried installing Windows 10 and Mint 20 into new VMs to pass through the USB device via VirtualBox and they both worked better than the Home Assistant OS. No glitches. So that proves there’s an incompatibility within HASSOS and it’s not necessariuly VirtualBox that’s the problem. However, I did notice that the activity light on the device was still flashing continuously and CPU usage on the VM was up considerably. When connected normally, the activity LED only flashes when something is actually being played. So I think a USB audio device passthrough is causing continuous polling or sampling and this symptom is actually independent of the glitching issue.

In order to play to an audio device within HA, I was using the local VLC add-on together with the vlc_telnet integration to create a media player to play to. It could well be that it’s this add-on that is causing the gltichiness. However I don’t know off-hand of any other way of creating a media player local to HASSOS that can be played to.

Turning this on its head, instead of using a player and audio device local to HASS OS, how about passing it up to a USB device on the host system. My VM has a bridged adaptor so it can talk to the host as though it was just another machine on the network.

So I set up a VLC telnet daemon (instructions can be found on the web for how to do this) to listen on a certain port and output to a certain audio device and it was therefore just a case of changing the IP address and port number in the HA integration to play to that instance of VLC instead of the local instance.

I’ve also found that you can create multiple instances of VLC telnet daemons on different ports and connected to different audio devices. You then define separate vlc_telnet intergrations in HA for each of them so you can effectively output to different speakers from HA.