JACK
This article describes the setup of a playing sound with JACK (JACK Audio Connection Kit).
JACK is a sound server for professional audio production, that provides low-latency communication for applications that implement the JACK API (like mpv).
JACK is designed to work with only one active audio interface (sound card), because of technical reasons needed to guarantee audio quality, latency, and synchronization. Remember, JACK is designed for studio quality work, not for ease of use. If more, or different, inputs and outputs are needed, use a different audio interface. It may be possible to get multiple interfaces working at the same time with JACK, but it is not trivial, and results may vary.
When the JACK daemon is running, usual system sound may no longer be output. To restore sound there are several options[1], such as configuring applications to output to JACK, using a second soundcard, or bridging.
Installation
JACK uses ALSA for accessing the sound card hardware, be sure ALSA is working.
There are two implementations of the JACK API, both implementations are considered equivalent. JACK2 is usually the one to go for, JACK 1 is no longer under active development.
JACK is the original implementation, it uses a C API and has built-in Linux MIDI integration. JACK2 is a re-implementation in C++ that has support for multiprocessing and D-Bus, while MIDI support is handled by ALSA. Visit what are the differences between JACK 1 and JACK2 for an in-depth comparison.
USE flags
USE flags for media-sound/jack2 Jackdmp jack implemention for multi-processor machine
+alsa
|
Add support for media-libs/alsa-lib (Advanced Linux Sound Architecture) |
+classic
|
Enable building of jackd |
+tools
|
Pull basic tools (e.g. jack_lsp/connect) from media-sound/jack-example-tools |
dbus
|
Enable dbus support for anything that needs it (gpsd, gnomemeeting, etc) |
doc
|
Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally |
ieee1394
|
Enable FireWire/iLink IEEE1394 support (dv, camera, ...) |
libsamplerate
|
Build with support for converting sample rates using libsamplerate |
metadata
|
Enable metadata API |
opus
|
Enable Opus audio codec support |
pam
|
Add basic realtime configuration via sys-auth/realtime-base |
systemd
|
Enable use of systemd-specific libraries and features like socket activation or session tracking |
Emerge
Emerge the sound server:
root #
emerge --ask media-sound/jack2
JACK2 will successfully compile with LTO enabled, but incoming connections will suffer a segmentation fault, fail to see ports, or fail to connect to open ports. Be sure to compile without LTO for a functional experience.
The JACK 1 package is media-sound/jack-audio-connection-kit (link provides a list of JACK 1 USE flags).
Global JACK USE flag
The global jack
USE flag enables support for JACK in other packages, so they can submit sound to a JACK server:
root #
euse -E jack
The euse command is part of app-portage/gentoolkit.
After setting this, be sure to update the system so the changes take effect:
root #
emerge --ask --changed-use --deep @world
Additional software
There is a JACK configuration and control software package media-sound/cadence:
root #
emerge --ask media-sound/cadence
Another alternative is media-sound/qjackctl:
root #
emerge --ask media-sound/qjackctl
See the article on music production for software to use with JACK.
The JACK website has a page on sofware that uses JACK.
Configuration
Sound server
All users that need JACK should be in the audio group:
root #
usermod -a -G audio $USERNAME
JACK can be configured using the jack_control utility. A basic configuration script for JACK could look like:
jack_control start
jack_control ds alsa
jack_control dps device hw:2,0
jack_control dps rate 48000
jack_control dps nperiods 2
jack_control dps period 64
To determine the appropriate playback device (instead of hw:2,0):
user $
aplay -l
Bridging
JACK can route sound which was sent to other sound systems like PulseAudio[2] and ALSA through itself.
ALSA
To use the ALSA only applications with JACK, you will need 2 things: the snd_aloop module and the jack ALSA plugin.
The snd-aloop is the Loopback virtual sound card. This will be used as the default ALSA sound card. That allow the ALSA applications to use it without the need to change their default configuration, the jack ALSA plugin will then route these applications to the JACK graph.
ALSA application <=> Loopback <=> ALSA jack plugin <=> JACK
Loopback device
Kernel configuration
Activate the following kernel options:
Device Drivers --->
<M> Sound card support
<M> Advanced Linux Sound Architecture --->
<*> Generic Sound Devices --->
<M> Generic loopback driver (PCM)
To configure the Loopback as the default ALSA sound card, we need to create the file /etc/modprobe.d/alsa.conf. Example with several sound cards, it's probably an overkill due to the evolution of the default ALSA configuration, but it has been working from years on several computers with very minor changes. It can also be used in other cases when the computer have several sound cards and a constancy order between reboot is a must.
Sound card 0 is the Loopback virtual device, sound card 1 and 2 are the built-in audio card which have 2 devices, one being the HDMI, sound card 3 is for an USB card.
# Alsa kernel modules' configuration file.
options snd slots=snd-aloop,snd-hda-intel,snd-hda-intel,snd-usb-audio
options snd-hda-intel index=1,2 model=1002:1637,1022:15e3
The cards index start from 0. For more details about that file, see Alsa Opensrc Org support page for multiple sound cards configuration.
To get the model strings, use lspci (or lsusb for USB cards):
root #
lspci
04:00.1 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] Renoir Radeon High Definition Audio Controller
04:00.6 Audio device: Advanced Micro Devices, Inc. [AMD] Family 17h/19h HD Audio Controller
root #
lspci -s 04:00.1 -n
04:00.1 0403: 1002:1637
root #
lspci -s 04:00.6 -n
04:00.6 0403: 1022:15e3
We instruct the kernel to load the virtual sound card:
snd-aloop
Jack ALSA plugin
The jack ALSA plugin provide a better and more elegant solution than the previous ones like the zita-ajbridge (see Using an ALSA Loopback device and zita-ajbridge on the ProAudio Gentoo overlay wiki - the author of zita-ajbridge will maybe disagree on that...).
Installation:
USE flags for media-plugins/alsa-plugins ALSA extra plugins
+mix
|
Enables upmix and vdownmix plugin |
+usb_stream
|
Enables usb_stream plugin |
arcam_av
|
Enables Arcam AV control plugin |
debug
|
Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces |
ffmpeg
|
Enable ffmpeg/libav-based audio/video codec support |
jack
|
Add support for the JACK Audio Connection Kit |
libsamplerate
|
Build with support for converting sample rates using libsamplerate |
oss
|
Add support for OSS (Open Sound System) |
pulseaudio
|
Add sound server support via media-libs/libpulse (may be PulseAudio or PipeWire) |
speex
|
Add support for the speex audio codec (used for speech) |
We need at least the jack USE flag.
root #
emerge --ask media-plugins/alsa-plugins
Configuration:
pcm.!default {
type plug
slave { pcm "jack" }
}
pcm.jack {
type jack
playback_ports {
0 system:playback_1
1 system:playback_2
}
capture_ports {
0 system:capture_1
1 system:capture_2
}
}
ctl.mixer0 {
type hw
card 0
}
That file is necessary when using qjackctl or the command line to manage the JACK server. Cadence will manage it for You: On its System
tab, select Bridge Type: ALSA -> Jack (Plugin)
.
Now, You can configure JACK to use the wanted and real sound card as usual, and all the ALSA applications will be available as per magic into the JACK graph.
PulseAudio
To use PulseAudio's JACK module media-sound/pulseaudio needs to have the jack
USE flag enabled.
In order to route all audio from PulseAudio to JACK, the JACK sink needs to be configured:
user $
pactl load-module module-jack-sink channels=2
user $
pactl load-module module-jack-source
user $
pacmd set-default-sink jack_out
PulseAudio will recognize that JACK started and will bridge its audio to JACK.
Troubleshooting
"Cannot use real-time scheduling" error
Some applications may show a permission error when trying to connect to Jack, for example:
ERROR: JACK: Cannot create thread res = 1
ERROR: JACK: JackClient::AcquireSelfRealTime error
ERROR: JACK: Cannot use real-time scheduling (RR/5) (1: Operation not permitted)
Adding the current user to the realtime group should solve this:
root #
usermod -a -G realtime $USERNAME
Log out and log back in to apply group change.
See also
- ALSA — describes the setup of a sound card with ALSA (Advanced Linux Sound Architecture).
- PipeWire — low-latency, graph-based, processing engine and server, for interfacing with audio and video devices.
- PulseAudio — a multi-platform, open source, sound server that provides a number of features on top of the low-level audio interface ALSA