JACK Audio Connection Kit

From Wikipedia:JACK Audio Connection Kit:

JACK Audio Connection Kit (or JACK; a recursive acronym) is a professional sound server daemon that provides real-time, low-latency connections for both audio and MIDI data between applications that implement its API.

Installation

There are three different implementations of the JACK API: jackAUR, jack2 and pipewire-jack. For an overview, refer to #Comparison of JACK implementations.

Install one of the above packages. For 32-bit application support, also install the lib32-jackAUR, or package (respectively) from the multilib repository.

For the official JACK example-clients and tools install .

For an alternative ALSA MIDI support in jack2 install .

For dbus support with jack2 install jack2-dbus.

Configuration

Depending on your use-case and hardware, the system may need further configuration, to allow a JACK implementation to use additional resources or to function properly.

Latency

The latency of a running JACK instance (i.e. how much time is spent processing one block of audio) is defined by its /sample rate ratio.

When looking at as an example, these parameters are defined by the and flags (respectively).

Realtime scheduling and additional resources

All JACK implementations may make use of elevated realtime scheduling priority, which allows them to make use of the CPU cycles more often than other applications (see e.g. in ).

The package provides the realtime system group, which is permitted elevated and unlimited with a sysctl drop-in configuration file and is permitted to alter the system's file, which may be used by applications to prevent the CPU to use higher C states.

Install the package and add your user to the realtime group to be able to use realtime scheduling priority that is higher than the default.

Realtime kernel and advanced modifications

A kernel facilitating the realtime kernel patchset (such as linux-rt or ) may be used in situations where very low latencies are required. Refer to professional audio for further information and other advanced modifications.

Starting the audio graph

The different JACK implementations have varying ways of starting the audio graph.

Jack

Jack1 only supports starting via the executable or by using one of the graphical frontends, that support starting via the library interface.

Jack2

Jack2 supports starting via the executable, the script (provided by the jack2-dbus package), the systemd user service (refer to /etc/jack/example.conf for configuration documentation) or by using one of the graphical frontends, that support starting via the library or dbus interface.

Pipewire-jack

Pipewire's JACK implementation does not provide the executable or dbus integration. The audio graph is started by the systemd user service.

Comparison of JACK implementations

The following table lists the current implementations of the JACK API and their differing feature sets.

NameMaintenanceLanguageSMP supportJackd executableDbus integrationSystemd integrationFirewire supportALSA MIDI supportMulti soundcard supportNetwork support
jackAURInactiveCALSA/libffadoBuiltinnetJACK1/ /
jack2ActiveC/C++ALSA/libffadoBuiltin/ Builtin/netJACK2/ /
pipewire-jackActiveC/C++ALSABuiltinBuiltin/

Comparison of JACK control GUIs

The following table lists control GUIs for JACK and their differing features and levels of support towards the JACK implementations.

Namejack1 start/ stopjack2 start/ stoppipewire-jack start/ stopPatchbaySave graph connections support
(Catia) (LADISH via Claudia is unsupported)
carla

Tips and tricks

Applications for interacting with JACK and its audio graph

  • Carla Fully-featured plugin host, with support for many audio drivers and plugin formats.
https://kx.studio/Applications:Carla || carla
  • PatchMatrix JACK patch bay in flow matrix style.
https://git.open-music-kontrollers.ch/lad/patchmatrix/about/ || patchmatrix

Using MIDI devices

JACK can handle one soundcard very well, and an arbitrary number of MIDI devices (connected e.g. via USB). If you start JACK and want to use a MIDI keyboard or a synthesizer or some other pure MIDI device, you have to start JACK with a proper soundcard (one that actually outputs or inputs PCM sound). As soon you have done that, you can connect the MIDI device. E.g. with QjackCtl (), you click on the connect button and you will find your device listed under JACK-MIDI or ALSA-MIDI, depending on the driver.

For JACK-MIDI, you may want to set the MIDI Driver to seq or raw in QjackCtl Setup > Settings. This should make your MIDI device appear under the MIDI tab. You can also change the name of the client (from a generic "midi_capture_1" to something more descriptive), if you enable Setup > Display > Enable client/port aliases and then Enable client/port aliases editing (rename).

For ALSA-MIDI, make sure to turn on Enable ALSA Sequencer support in QjackCtl Setup > Misc. This will add the ALSA tab in QjackCtl Connect window where your MIDI controller will show up.

For bridging ALSA-MIDI to JACK-MIDI, you may consider using a2jmidid (). The following command will export all available ALSA MIDI ports to JACK MIDI ports:

$ a2j_control --ehw && a2j_control --start

They will be visible in QjackCtl under the MIDI tab labelled "a2j" client. You can automate starting of a2jmidid by adding to QjackCtl Setup > Options > Execute script after Startup:

  • Q: What is the difference between JACK-MIDI and ALSA-MIDI?
  • A: The former has improved timing and sample accurate MIDI event alignment. It extends or may even replace the latter but at this point they both co-exist.

To install some M-Audio MIDI keyboards, you will need the firmware package midisport-firmwareAUR in the AUR. Also, the snd_usb_audio module has to be available. For more information about specific USB MIDI devices, see https://alsa.opensrc.org/USBMidiDevices.

A shell-based example setup

JACK2 can be directly launched with the jackd executable, or controlled with the D-Bus-based jack_control binary. jack_control makes it easy to start and configure JACK2 via a shell script. Note that you must install the package to use jack_control. For the a2j_control commands you also need installed (see #Using MIDI devices for more information).

Create a shell script that can be executed at X login:

The above will start a working JACK instance which other programs can then utilize. Details of each line follow. When discovering your own best configuration, it is helpful to do trial and error using QjackCtl's GUI with a non-D-Bus JACK2 version.

Details of the shell-based example setup

$ jack_control start

Starts JACK if it is not already started.

$ jack_control ds alsa

Sets JACK to use the ALSA driver set.

$ jack_control dps device hw:HD2

Sets JACK to use ALSA-compatible sound card named HD2. One can find the names with cat /proc/asound/cards. Most ALSA tutorials and default configurations use card numbers, but this can get confusing when external MIDI devices are in use; names make it easier.

$ jack_control dps rate 48000

Sets JACK to use 48000 khz sampling. Happens to work very well with this card. Some cards only do 44100, many will go much higher. The higher you go, the lower your latency, but the better your card and your CPU have to be, and software has to support this as well.

$ jack_control dps nperiods 2

Sets JACK to use 2 periods. 2 is right for motherboard, PCI, PCI-X, etc.; 3 for USB.

$ jack_control dps period 64

Sets JACK to use 64 frames per period. Lower is less latency, but the setting in this script gives 2.67 ms latency, which is nicely low without putting too much stress on the particular hardware this example was built for. If a USB sound system were in use it might be good to try 32. Anything less than 3-4 ms should be fine for realtime synthesis and/or FX, 5 ms is the smallest a human being can detect. QjackCtl will tell you how you are doing; at no-load, which means no clients attached, you will want a max of 3-5% CPU usage, and if you cannot get that without xruns (the red numbers which mean the system cannot keep up with the demands), you will have to improve your hardware.

$ sleep 10

Wait for the above to settle.

$ a2j_control --ehw && a2j_control --start

Start the ALSA-to-JACK MIDI bridge. Good for mixing in applications which take MIDI input through ALSA but not JACK.

$ sleep 10

Wait for the above to settle.

$ qjackctl &

Load QjackCtl. GUI configuration tells it to run in the system tray. It will pick up the JACK session started by D-Bus just fine, and very smoothly too. It maintains the patchbay, the connections between these applications and any other JACK-enabled applications to be started manually. The patchbay is set up using manual GUI, but connections pre-configured in the patchbay are automatically created by QjackCtl itself when applications are started.

A GUI-based example setup

This example setup utilizes a more GUI focused configuration and management of JACK

  • Install and .
  • Install , and tell your GUI window/desktop system to run it at startup.
  • Make sure QjackCtl is told to:
    • use the D-Bus interface,
    • run at startup,
    • save its configuration to the default location,
    • start the JACK audio server on application startup,
    • enable the system tray icon, and
    • start minimized to system tray.
  • Reboot.
  • After logging in, you will see QjackCtl in your system tray. Left-click on it.
  • Tweak settings in the QjackCtl GUI to lower latency. The Frame Size, Frame Buffer, and Bitrate settings all affect latency. Larger frame sizes lower latency, lower frame buffers lower latency, and higher bitrate settings lower latency, but all increase load on the sound card and your CPU. A Latency of about ~5ms is desirable for direct monitoring of instruments or microphones, as the latency begins to become perceptible at higher latencies.

An alternative GUI-based setup

If you use JACK for demanding tasks, but every now and then, it is possible to suspend a running pulseaudio session with QjackCtl just when you are using it. On a virgin config, modify the "Server prefix" option in the "Settings" > "Advanced" submenu, so that it states :

   pasuspender -- jackd

The pulseaudio session should resume fine after you close QjackCtl. Tip courtesy of this post.

Playing nice with ALSA

To allow Alsa programs to play while jack is running you must install the jack plugin for alsa with .

And enable it by editing (or creating) /etc/asound.conf (system wide settings) to have these lines if you have a simple 2-channel setup:

If you have a different number of output/input channels or your first two channels are not the ones you wish to route audio to, you cannot use the predefined jack pcm source from , but rather something like:

You need not restart your computer or anything. Just edit the ALSA configuration files, start up jack, and there you go...

Remember to start it as a user. If you start it with jackd -d alsa as user X, it will not work for user Y.

Another approach, using ALSA loopback device (more complex but probably more robust), is described in this article.

GStreamer

GStreamer requires the package to work with JACK, which contains the jackaudiosink plugin that adds JACK playback support.

Further information (outdated): https://jackaudio.org/faq/gstreamer_via_jack.html

PulseAudio

If you need to keep PulseAudio installed (in the event it is required by other packages, like gnome-settings-daemon), you may want to prevent it from spawning automatically with X and taking over from JACK.

Edit , uncomment "autospawn" and set it to "no":

;autospawn = yes
autospawn = no

If you want both to play along, see: PulseAudio/Examples#PulseAudio through JACK

Cadence and other JACK GUI applications are known to write values to . These values override any system-wide defaults enabling unexpected behavior (e.g. flat volumes). Refer to PulseAudio#Configuration on how to update these configurations.

Firewire

In order to prevent ALSA from messing around with your firewire devices you have to blacklist all firewire related kernel modules. This also prevents PulseAudio from using firewire. Create the following file:

The list of modules is the most recent available at the time of writing at Alsa Firewire Improve Repository.

Now you can unload your loaded firewire modules or reboot.

Network / remote audio

JACK can be configured to send audio data over a network to a "master" machine, which then outputs the audio to a physical device. This can be useful to mix audio from a number of "slave" computers without requiring additional cables or hardware mixers, and keeping the audio path digital for as long as possible (as hardware mixers with digital inputs are very rare).

The configuration is very simple, however it requires a network that supports multicast traffic (i.e. IGMP snooping must be enabled on managed network switches), and it requires all machines be running the same JACK major version (JACK1 or JACK2) as the protocols are not interoperable between versions. For JACK2, the module must be loaded:

The option tells the netmanager to automatically map any incoming connections to the default audio device. Without this, each incoming connection would have to be manually mapped on each connection. You can use -i -h instead to see all available options, however note that the options are printed in the server output, the command will not show anything.

On the client, JACK must be started in network mode:

slave$ jackd -d net

The two machines will connect and on the master the new audio source will be visible:

If you passed the option to as above, then the remote system will now be able to play audio.

Troubleshooting

"Cannot lock down memory area (Cannot allocate memory)" message on startup

See Realtime process management#Configuring PAM and ensure that the user is in the realtime user group.

jack2 and qjackctl errors

Still having the "Cannot allocate memory" and/or "Cannot connect to server socket err = No such file or directory" error(s) when pressing qjackctl's start button?

Please delete , , . Kill jackdbus and restart from scratch :) (Thanks to nedko)

Also try running

$ fuser /dev/snd/*

and check the resulting PID's with

$ ps ax | grep [PID here]

This will hopefully show the conflicting programs.

"ALSA: cannot set channel count to 1 for capture" error in logs

Change ALSA input and output channels from 1 to 2

Crackling or pops in audio

Your CPU or sound card is too weak to handle your settings for JACK. Lower the bitrate, lower the frame size, and raise the frame period in small increments until crackling stops. You can also try changing the sampling rate to 44100 or whatever is natively supported. This allows jack to send audio to the system without having to resample. In with , this is accomplished with

jack_control dps rate 44100

VLC - no audio after starting JACK

Run VLC and change the following menu options:

  • Tools > Preferences
  • Show settings: All
  • Audio > Output modules > Audio output module: JACK audio output
  • Audio > Output modules > JACK: Automatically connect to writable clients (enable)
gollark: Possibly. What hardware do you have?
gollark: Technically the Intel iGPU *is* a GPU.
gollark: How strange. Must be a graphics problem.
gollark: That was me.
gollark: What if we destroy the imperial system by making a *new* subtly incompatible imperial system?

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.