How to use JACK and Pulseaudio/ALSA at the same time on the same audio device?

Whenever I launch hydrogen it breaks my audio in all other applications which use Pulse, for example, I can no longer play videos in Chrome after having launched Hydrogen once, until I restart my PC or do sudo alsa force-reload. I have found people with similar issues, but no actual guide to fix this, often there are links to http://jackaudio.org/pulseaudio_and_jack (which has moved to http://jackaudio.org/faq/pulseaudio_and_jack.html ) I am using Ubuntu Studio 14.04 64bit.

ALTERNATIVELY if this is truly impossible to achieve, can someone tell me how to use Jack on one soundcard and Pulse on another? This way I could plug in a USB sound card only when I need JACK.

Please don't make me use windows.


Solution 1:

As of 16.04, things become a lot simpler :)

Just install qjackctl and pulseaudio-module-jack module:

apt-get install qjackctl pulseaudio-module-jack

Then configure qjackctl to run the following command after startup. Copy it into "Setup..." > "Options" > "Execute script after Startup":

pacmd set-default-sink jack_out

And that's it. Pulseaudio will recognize (through D-Bus) that JACK started, and automatically will route audio to it. When JACK is stopped Pulseaudio will revert to normal routing and start sending audio directly to card again.

So (almost) by default Pulseaudio implements the setup detailed above by mmv-ru.

Solution 2:

This Youtube video: "Jack and PulseAudio Together as Friends - Linux" seemed to have some answers:

The key to the solution appeared to be making sure pulseaudio-module-jack is installed with:

aptitude install pulseaudio-module-jack

then sudo editing the /etc/pulse/default.pa file to include two lines under the load audio drivers manually section:

load-module module-jack-sink
load-module module-jack-source

then - I think - restarting pulseaudio. I just restarted the PC (lazy, I know) and it worked a treat... firing up Ardour no longer killed pulseaudio, they played happily together.

Solution 3:

My solution working on Fedora 23.

dnf install jack-audio-connection-kit jack-audio-connection-kit-dbus qjackctl

Don't touch /etc/pulse/default.pa !

Configure qjackctl

Settings

The relevant fragment of ~/.config/rncbc.org/QjackCtl.conf:

[Settings]
Server=jack_control start
Driver=alsa
InDevice="hw:PCH,0"
OutDevice="hw:PCH,0"

Options

The names of the sinks for pactl can be found by:

pacmd list-sinks

Here's one more fragment of ~/.config/rncbc.org/QjackCtl.conf to show the full commands

[Options]
...
StartupScript=true
StartupScriptShell=pactl suspend-sink alsa_output.pci-0000_00_1b.0.analog-stereo 1
PostStartupScript=true
PostStartupScriptShell=pactl set-default-sink jack_out
ShutdownScript=false
ShutdownScriptShell="pactl unload-module module-jack-sink; pactl load-module module-jack-source"
PostShutdownScript=true
PostShutdownScriptShell="pactl suspend-sink alsa_output.pci-0000_00_1b.0.analog-stereo 0; pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo"

Misc "Enable D-Bus interface" is important for Qjackctl itself.

How it works

Now on boot the PC runs with PulseAudio only, everything automatically works as without Jack.

After launching Qjackctl,

  1. The Qjackctl startup script suspends the primary audio card in Pulseaudio and allows Jack to get access to it: pactl suspend-sink alsa_output.pci-0000_00_1b.0.analog-stereo 1
  2. Jack is started over d-bus: jack_control start
  3. Pulse automatically detects jack start over D-Bus and loads jack sink and jack source.
  4. Qjackctl after the startup script changes the default sink in Pulse to jack_out: pactl set-default-sink jack_out (at first it looks unnecessary, as all running PA clients are switched to the new sink, but new apps will get stuck on the suspended sink without this command)

So the system is reconfigured to use "Pulse on top of Jack". (I skip hardware input suspend, because I don't use it anyway)

If "Stop JACK audio server on application exit" is not checked, I can close Qjackctl and rerun it without disturbing the setup.

After stopping Jack by Qjackctl, everything returns to plain uncluttered Pulse!

  1. Jackd stopped by Qjackctl over dbus - "Enable D-bus interface" option.
  2. jack-source and jack-sink are removed from Pulseaudio automatically by d-bus
  3. the default sink in Pulse audio is switched to audio card because jack-out disappears
  4. Qjackctl after Shutdown script re-activates the audio card in Pulseaudio: pactl suspend-sink alsa_output.pci-0000_00_1b.0.analog-stereo 1

Tools Used

  1. jackd (from package pulseaudio-utils)
  2. jack_control (from package ack-audio-connection-kit-dbus)
  3. Qjackctl (from package pulseaudio-utils)
  4. pactl to control Pulseaudio from scripts (from package pulseaudio-utils)
  5. LANG=C pacmd list-sinks|grep -E "index:|name:|alsa.long_card_name =|alsa.name =" or LANG=C pactl list sinks|grep -E "(Sink #|Name:|alsa.long_card_name =|alsa.name =)" to detect alsa device name