read

Recently Igalia gave me a new laptop, a Lenovo “The Beast & The Best” Thinkpad, for everyday work. I decided to install Ubuntu Hardy Heron 64bits, as I had never worked with such operating system, and I am eager to learn benefits and drawbacks of working on a 64bits OS.

Among other features, Hardy comes with PulseAudio, the new sound system which has a lot of features.

As I am playing with Maemo I have installed a scratchbox too. A workmate, Calvaris, wrote about how to install scratchbox in a Linux Amd64.

Now the problem: scratchbox comes with esound to manage the sounds. When I am working within the scratchbox, esound daemon blocks the /dev/dsp device, preventing other applications outside the scratchbox to be able to play. This disturbs me a lot, as I like listening music while working. Of course, we can kill esd daemon to free the dsp device, but in this case I can not play songs inside the scratchbox, which I need to do too.

So, what is the solution? The idea is to use the soundcard to play songs for our Ubuntu applications, while the scratchbox will use a virtual soundcard that will sent the music to another host using networking capabilities of esound. The trick is that the ‘another host’ will be our own host, which will receive the music stream and will play it. Cool, uh?

Lets do it!.

Configuring PulseAudio

The first step is configuring Pulseaudio to be able to receive streams through the network. Therefore, edit /etc/pulse/default.pa and add the following line:

load-module module-esound-protocol-tcp

It is likely that line already exists in the file but commented. In this case, uncomment it.

Now you must restart pulseaudio in order to load the new configuration.

Configuring a Dummy Soundcard

Scratchbox esound daemon requires to have a dsp device even when sending the music through network. So we are going to add a dummy sound card that will be used by the daemon.

Linux kernel provides a driver for a dummy soundcard. To load it, execute as root:

modprobe snd-dummy

A new dsp device, /dev/dsp1, will be created.

Configuring Scratchbox eSound

We must configure esound daemon in scratchbox to use the new dummy soundcard. To do this, enter in the scratchbox and edit /etc/esd.conf file. Search the options line and add at the end:

-d /dev/dsp1

In my case, the esd.conf file contains:

auto_spawn=1
#spawn_options=-promiscuous -nobeeps
spawn_options=-promiscuous -nobeeps -d /dev/dsp1
spawn_wait_ms=500
# default options are used in spawned and non-spawned mode
#default_options=-promiscuous -nobeeps
default_options=-promiscuous -nobeeps -d /dev/dsp1

Thus, scratchbox will use the dummy soundcard, while the real soundcard will remain free for Ubuntu. Of course, being a dummy sound card, don not expect to hear music playing in the scratchbox. To resolve this problem, the last step is send what is playing with esound daemon through the network to our own host to be played through pulseaudio.

Configuring eSound’s Network Transparent Sound

This is the last step. Network sound uses a authentication mechanism. So in order to use network transparency both sides must be authenticated between them. When pulseaudio is launched, an .esd_auth file is created in the home directory. Copying this file to the scratchbox home will allow esd to send music to pulseaudio daemon. After copying the file, restart esound daemon.

Now we can send the sound to the pulseudio daemon. From the scratchbox, execute this:

esdmon | esdcat -s 127.0.0.1 &

esdmon listens all data sent to esound daemon, sending it also to the standard output. On the other hand, esdcat reads all data from the standard input and sends it (in this case) to the localhost. As you can notice, working together means that all sound sent to the dummy sound card is also sent through localhost to the pulseaudio daemon, which in turn sends it to the real soundcard.

Now, you can play songs inside the scratchbox and you will hear them! Moreover, you can be playing at the same time music in the scratchbox and in the host, due to multiplexing capabilities of pulseaudio. So both systems, Ubuntu and scratchbox, will sing duet.

Blog Logo

Juan A. Suárez


Published

Image

Words from the Inside

Uninteresting things from an uninteresting developer

Back to Overview