Mittwoch, Mai 04, 2016

Using a remote pulseaudio to mitigate Virtualbox soundproblems


I had this problem with audio in my Virtualbox guest, Xubuntu, on my Mac OS X host.
But this should be applicable -- in part or in whole -- to any host which is able to run pulseaudio and ssh and any unix guest which uses pulseaudio as defaultsoundsystem.

What did go wrong?

So i have this Mac from work, but I like working under Linux, xfce, sometimes I install debian, sometimes Xubuntu. This I did in a Xubuntu guest in Virtualbox on a Mac OS X host.
So I like using my Xubuntu, and I use it for most things that work: Watching movies, listening to music, working, everything. So I like the audio to work.

It does mostly work, but not perfect. Sometimes I connect the Macbook to a bluetooth audio receiver or plug in the hdmi to watch something on my tv screen. Sometimes I plug in headphones. All of these are visible in the audio menu up top, which shows a list of all this devices when I alt-click it. I can choose an audio output device from this list and the Mac promptly plays over that device. 
But not the Virtualbox. The Virtualbox just stays on the device it was playing audio over when it got startet. It doesn't switch to what I choose. (Sometimes it did, but not always, and that got very annoying)

The Solution

This one is kind of complicated.

the host

First, you have to install pulseaudio on your host machine, I did this with brew install pulseaudio, using homebrew.

Now, you have to configure your pulseaudio so you can use it over the net:
pulseaudio --dump-conf dumps you the pulseaudio config which includes the path of the file which we have to edit. On my machine it lies under
In this file, there is a commented out line which loads the module
I commented that line in and added some parameters:

load-module module-native-protocol-tcp  auth-ip-acl=;; auth-anonymous=1
(yeah, I googled that, don't really know, what that's doing, although I have an idea, of course. You can adjustt the IP ranges of course, in this example, we will only use the

In the same directory as the there is another config file named daemon.conf. In this file you set allow-exit=no and comment out the exit-idle-time so pulseaudio doesn't exit if it's idle.

the guest

On the guest, you only have to run pax11publish -e -S where is the IP of the host, and you should be able to use the host's pulseaudio to play sound. done.

Automating it

Make sure you have an ssh-server on the host. Have an ssh-client on the guest. Create a keypair on the guest with ssh-keygen and configure everything so that you can connect from the guest to the host without a password.

Install screen on the host using brew install screen screen. Also, create a script:
cat > << EOF
exec > ~/.pulselog 2>&1
echo starting pulse
echo pulse aborted


On the guest, you create a script:
cat > << EOF

ssh -vT "bash -l -c 'screen -S hostaudiopulse -d -m bash ~/'"
pax11publish -e -S

where -- as before -- stands for the host IP.

Add to your autostart on the guest, and you should be all set.

Well d'uh!