PulseAudio through Jack on Jaunty (Ubuntu 9.04)

June 09, 2009 | categories: Music, Linux | View Comments

From the PulseAudio page on the archlinux wiki:

PulseAudio provides module-jack-source and module-jack-sink which allow PulseAudio to be run as a sound server above the JACK daemon.

What this means is that you can have JACK running at all times and still have sound (both in and out) with applications that aren't JACK- aware. Think of recording the sound of YouTube videos straight into Ardour, or passing your voice through LADSPA effects before sending it to Skype.

However, since this setup doesn't work so well with suspend, and because there's still the rare application that won't even work with PulseAudio (let alone, JACK), I wrote this little script that'll do two things: When called with no argument, it'll kill any existing PulseAudio daemon, start JACK (by means of QJackCtl) and then start the PulseAudio daemon again with a configuration file that loads its module-jack-source and module-jack-sink modules. I put this configuration file into $HOME/etc/pulsejack.pa. The PulseAudio page on the archlinux wiki has instructions on how to create such a configuration file. So here's my shell script:

#!/bin/sh

start() {
    echo "Starting..."
    /usr/bin/pulseaudio -k && echo "Killed pulseaudio"
    eval "/usr/bin/qjackctl.bin -s &" && echo "Started qjackctl"
    sleep 3;
    /usr/bin/pulseaudio -DnF /home/daniel/etc/pulsejack.pa && echo "Started pulseaudio"
}

stop() {
    echo "Stopping..."
    /usr/bin/pulseaudio -k && echo "Killed pulseaudio"
    /usr/bin/killall jackd && echo "Killed jackd"
    /usr/bin/killall qjackctl.bin && echo "Killed qjackctl"
    sleep 1;
    /usr/bin/pulse-session && echo "Started pulse-session"
}

case $1 in
    stop)
        stop;
    ;;
    *)
        start;
    ;;
esac

You can see that there's another function stop that'll kill the JACK daemon and start up PulseAudio with its default configuration file (which lives in /etc/pulse/default.pa).

Now this worked rather well, until I upgraded to Ubuntu 9.04 (Jaunty Jackalope) today. Because suddenly, whatever I tried, PulseAudio seemed to start automatically just before JACK could take control over my audio device, and so JACK died with:

the playback device "hw:0" is already in use. Please stop the
application using it and run JACK again

After a bit of Googling I found out that there's a configuration switch called autospawn in /etc/pulse/client.conf that needs to be set to autospawn = no to turn off this behaviour. With this, my script started to work again.

Further pointers:

More comments can be found at the original blog post.

Read and Post Comments