JACK

From Gentoo Wiki
Jump to:navigation Jump to:search
This page contains changes which are not marked for translation.

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).

Tip
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.
Note
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
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
tools Pull basic tools (e.g. jack_lsp/connect) from media-sound/jack-example-tools

Emerge

Emerge the sound server:

root #emerge --ask media-sound/jack2
Warning
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:

CODE A basic configuration
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.

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:

CODE Error message
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

References