Recent Posts

Archives

Topics


« | Main | »

Sharing sound between Pulseaudio instances in Ubuntu Karmic 9.10

By insanity | November 9, 2009

The goal of this post is to respond to a query about how to synchronize soundcards across several Ubuntu-based computers together using pulseaudio. I will present two methods, demonstrating the GUI tools that are available, before showing how to come up with the manually-edited files. In theory, at the end of this post you will have multiple linux computers able to play sound from a single source using Pulseaudio’s Multicast/RTP abilities.

I must warn, the sound quality is VERY dependant on your network speeds and CPU loads at either end.  If you are running a lot of programs on either the server or the client, the sound will be erratic.  See the bugs on the pulseaudio website.  I was unable to get the sound to run very smoothly for any length of time on between two Ubuntu VM’s on pulseaudio version 0.9.19-0ubuntu4.  The specific bugs are:

Either way, it is a fun exercise in pulseaudio configuration.  In order to demonstrate this I have set up two Ubuntu VM’s using VirtualBox on a local network.

Graphical Setup

The first step is to install the tools we’re going to use to configure this. Install PulseAudio Device Chooserm PulseAudio Volume Control and PulseAudio Preferences. Select these items from the Ubuntu Software Centre. You can easily reduce the list to these items by searching for pulseaudio in the search bar as shown in the following screenshot:

Screenshot of Ubuntu Software Center installing Pulseaudio

Screenshot of Ubuntu Software Center installing Pulseaudio

Once this is installed, you can launch it by selecting it from Applications menu.

Open the Pulseaudio Device Chooser

Open the Pulseaudio Device Chooser

This will put an audio plug icon up near the clock. Left-click (or primary click) . Select “Configure local Sound Server” and change to the Multicast/RTP tab in the Preferences window:

PulseAudio Preferences

PulseAudio Preferences

Server Computer

The first computer set-up will be the server. This is the computer you will be controlling & playing the sound from. On this computer you will need to open up rhythmbox or your chosen audio program that supports pulseaudio output. Totem or VLC also fit this prescription.

On the server computer you will want to “Enable Mutlicast/RTP sender”. If you want to play the sound out this server computer’s speakers, select “Send audio from local speakers”. If you want to be more specific about what is sent, I would recommend you select “Create separate audio device for Multicast/RTP”. For my setup, I want to be able to send only music to the stream when I want it, so I am going to chose the second option.

Client Computer(s)

The client computers will all need to be set up with the “Enable Multicast/RTP receiver” option enabled. Assuming the networks are working properly, you should immediately start hearing music on all the client computers!

Manual Configuration

If you don’t have the benefits of a running Xserver, or want to configure these settings to work on a headless machine, you will need to be manually configuring the pulseaudio config files. The pulseaudio config files are stored in /etc/pulse/system.pa if you’re running in daemon mode, and /etc/pulse/default.pa if you’re running in a per user setup (this is the default method in Ubuntu). I’m going to write this assuming you are using daemon-mode, so we will be editing /etc/pulse/system.pa.

Server Computer

To setup the server computer, you need to edit the configuration. In a terminal or on a console with admin access type the following:

sudo nano /etc/pulse/system.pa

In this file, find and uncomment the lines that look like:

load-module module-null-sink sink_name=rtp format=s16be channels=2 rate=44100 description="RTP Multicast Sink"
load-module module-rtp-send source=rtp.monitor

(If these don’t exist, just add them to the end of the file)

Once this is done, restart the pulseaudio server by running:

sudo /etc/init.d/pulseaudio restart

Client Computer(s)

The client computer will be done by editing /etc/pulse/system.pa (alternatively, you can copy this file to ~/pulse/default.pa). Edit this file by typing:

sudo nano /etc/pulse/system.pa

In this file, find and uncomment the lines that look like:

### Load the RTP reciever module (also configured via paprefs, see above)
#load-module module-rtp-recv

Again, if this doesn’t exist, just add them to the end of the file.

Once you’ve saved this, apply the changes the same way you did previously… by restarting pulseaudio:

sudo /etc/init.d/pulseaudio restart

Once again, assuming the network is behaving correctly, you should be hearing sound out both ends.

Troubleshooting & More Information

Troubleshooting guides are well written on the pulseaudio site. If you have any issues I would suggest reading the wonderful article at http://www.pulseaudio.org/wiki/HowToListenToTheRtpStream. The key thing is to check that you can see the broadcast packets (see the tcpdump section in the article).

Another good tip is to start the pulseaudio server in non-daemon mode. This will allow you to see and interact with the pulseaudio from the command line. To do this, stop any existing pulseaudio servers with the following command:

sudo /etc/init.d/pulseaudio stop # in system or daemon mode or
pulseaudio -k # for single user mode

To start pulseaudio server, run the following:

sudo pulseaudio --system -Cv # in system or daemon mode or
pulseaudio -Cv # for single user mode

Take note of any errors you see when starting this. Once the server is started, you can list the modules loaded by typing the following in the pulseaudio console:

list-modules

For more information on how to load modules see http://www.pulseaudio.org/wiki/Modules, and specifically http://www.pulseaudio.org/wiki/Modules#RTPSDPSAPTransport.

More information about the commands that can be run in the pulseaudio console, see http://www.pulseaudio.org/wiki/CLI

Topics: General, Linux, Networking, Software | No Comments »

Comments