How to use JACK and Pulseaudio/ALSA at the same time on the same audio device?
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.
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.
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
The relevant fragment of ~/.config/rncbc.org/QjackCtl.conf:
[Settings]
Server=jack_control start
Driver=alsa
InDevice="hw:PCH,0"
OutDevice="hw:PCH,0"
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"
"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,
- 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
- Jack is started over d-bus:
jack_control start
- Pulse automatically detects jack start over D-Bus and loads jack sink and jack source.
- 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!
- Jackd stopped by Qjackctl over dbus - "Enable D-bus interface" option.
- jack-source and jack-sink are removed from Pulseaudio automatically by d-bus
- the default sink in Pulse audio is switched to audio card because jack-out disappears
- 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
- jackd (from package pulseaudio-utils)
- jack_control (from package ack-audio-connection-kit-dbus)
- Qjackctl (from package pulseaudio-utils)
- pactl to control Pulseaudio from scripts (from package pulseaudio-utils)