JACK

This article is about the Jack Audio Connection Kit (JACK) and its configuration.

What is Jack?
From the homepage http://jackaudio.org/ :

JACK is a low-latency audio server, written for POSIX conformant operating systems such as GNU/Linux and Apple's OS X. It can connect a number of different applications to an audio device, as well as allowing them to share audio between themselves. Its clients can run in their own processes (ie. as normal applications), or they can run within the JACK server (ie. as a "plugin").

JACK was designed from the ground up for professional audio work, and its design focuses on two key areas: synchronous execution of all clients, and low latency operation.

Why use JACK?
JACK is the way to go if you want to do some serious audio work like creation of audio or multimedia content. Otherwise, you don't need it.

In short, whereas cables will let you to interconnect your music hardwares on a stage or a studio, JACK will let you to do the same with the hardware and software audio components of your computer with the mouse in qjackctl.

Installing necessary software
In order for JACK to be of any use to you, you need three distinct components:
 * 1) ALSA driver for your sound card.
 * 2) JACK itself
 * 3) software which makes use of JACK (such as the JACK output driver for XMMS or MPlayer)

Kernel Configuration
You don't have to use the realtime mode in order to use jack, but it is needed for low latencies, which is one of the two primary goals of JACK. In order for you to use the realtime mode you need to have some options turned on in the kernel. You can find more information in the jack FAQ.

Make sure that the following option (GROUP_SCHED) is disabled, otherwise you won't be able to use realtime scheduling as a normal user (on kernels >=2.6.25). If you get errors like 'cannot use real-time scheduling (FIFO at priority 10) ... (1: Operation not permitted)', this is most probably the culprit.

Or, you may still use realtime scheduling with GROUP_SCHED enabled, if you add the following PAM configuration file (see /etc/security/limits.conf for details):

The nice setting is not necessary it is an option that has been made up. See the original post here http://ardour.org/node/3434

If you need support for a kernel <= 2.6.24, please refer to the Troubleshooting section.

and related settings
We'll first make sure we have the relevant USE flags enabled. Open up (or  if you're using paludis), look at this list of USE flags and enable what you think suits you best. Save your USE flags and continue with installing JACK below.
 * : Adds support for optimizations for G4 and G5/ppc970 processors (PPC/PPC64 architecture only).
 * : Adds support for media-libs/alsa-lib. (don't even think of disabling this...)
 * : Compile in a tmpfs path (deprecated, not used in newer jack versions)
 * : Enables programs to output to or input from JACK.
 * : Adds support for the crossplatform portaudio audio API.
 * : Adds LASH Audio Session Handler support

Installing jack
You need to have jack-audio-connection-kit installed.

Starting jack manually
Here's some info about starting it manually, but there are graphical programs like qjackctl to help your life. You can read about those in the next section. The jack daemon starts with the following command:

If you want to run jack in realtime mode, use the following command:

Using graphical tools
QJackCtl is a nice tool to configure and start jackd. The interface should be easy to grasp.

QJackCtl is designed to start and pass options to JACK for you. It can also provide a system tray icon. This program is a must have for anyone who wishes to experience the power and flexibility of JACK. While the default configuration could work, you should try fiddling around with it anyway. For example, if you want to do playback in 5.1 or 7.1, you'll need to adjust the number of output channels accordingly. It's very important to change the server path to jackd, it never seems to work with either of the other two options selected.

After you've adjusted the settings to meet your preferences and sound card, click OK to save the changes, and then press the Start button on the main qjackctl panel to test the jack server.

Starting JACK at boot time
It is possible to start jackd at boot time and as a regular user with a boot script.

Create and save those 2 files. Don't forget to adjust JACKDUSER to the wanted user name (the same as yours I guess).

We need to make executable:

Adding the script into the default run-level:

Before restarting your system or starting this script, you must be sure that jackd is configured for $JACKUSER or jackd will fail. This is because the script will read. If this file doesn't exist, the easiect way to create it is to run QJackCtl as explained above.

Note: You will find this boot script into the Pro-Audio Gentoo Overlay, where it is known as.

Note on Realtime: Due to a limitation in the implementation of start-stop-daemon, it is not possible to start jackd in realtime mode as a non-root user by this method if using pam_limits. start-stop-daemon does not implement support for pam_sessions, meaning that changes to limits.conf have no effect in this context.

Where to go from here
Now that (hopefully) you got JACK working, you have the ability to produce sound in real-time. If you were not interested in realtime audio in the first place, you should probably have just used PulseAudio or ALSA. Assuming you wanted realtime audio, you are probably planning to make music. And to make music, you need a studio. Specifically, a music studio.

Configuring software to use JACK
Aside from JACK-only software, which is generally made for musicians, you may want other software to output or input with JACK too. How to go about this depends on the application.

Applications which support JACK natively
Some applications, for example MPlayer, support JACK natively. Often, you'll need to enable the use flag, which you have probably done globally already above. Remerge the packages which support that JACK use flag now.

xmms
First you need to install the jack output plugin

Then you need change the output plugin in preferences to jack Driver. If you get an error saying that you don't have your soundcard configured properly then it's likely that you don't have jackd running.

MPlayer
You can manually start MPlayer using JACK with the following command:

Or you can make JACK your default in /etc/mplay.conf and/or /etc/mplayplugin.conf:

If you wish to specify which jack ports you want Mplayer to connect to, then do the following:

[1-2] represents the port numbers listed as your jack system playback ports, for your device. If, for example, you use system:playback_3, and system:playback_4, for your speaker outputs, then the command would be:

MythTV
In the mythfrontend, set the Audiodevice from /dev/dsp to JACK:.

ALSA plug
ALSA contains a JACK plugin, which enables ALSA-only applications to output to JACK using ALSA's emulation plug. First, make sure that alsa-jack is installed. Usually, it comes with alsa-plugins when its USE flag is enabled.

Then, you can test it by using:

If you are satisfied, you can rename jackplug to !default to make it the default output device.

PulseAudio and JACK
An alternative to the alsa plug is to use pulseaudio.

The following will add a software volume control for pulseaudio.

We need to tell pulseaudio to load the jack sink and sources.

After that, you should be able to use pulseaudio with jack. Kill it with It will start again automatically.

One PulseAudio JACK Sink and one PluseAudio Jack Source must appear into qjackctl.

As many programs are now using pulseaudio, those settings will enable them to use jack. Even Phono from kde will work with it. If it doesn't, launch the Pulse Audio Device Manager: and choose Jack Sink as default sink. If this doesn't work either, logout and login again.

Jack2 Dbus Configuration
If you use use the "dbus" flag with jack, it becomes easier to add pulseaudio to the mix. Emerge qjackctl and jack-audio-connection-kit with dbus, and follow the directions at https://wiki.archlinux.org/index.php/PulseAudio#PulseAudio_through_JACK_the_new_new_way to get pulseaudio to startup. This is more stable and reliable, as it ensures that jack always starts first.

Jack and Loopback device as Alsa-to-Jack bridge
If you don't want any other audio layer such as Pulseaudio, etc, in between Jack and the lower level layer (ALSA), you can make a permanent bridge between ALSA and JACK with the ALSA Loopback device. This will work with any ALSA software inclusive firefox and flash. This more complex but more robust approach is well documented in this document: Jack and Loopback device as Alsa-to-Jack bridge.

You must desactivate pulseadio:

The alternative is to remove pulseaudio from your system, but be warned that this will remove Gnome. It can be good to make a backup of your system before to proccess:

This last command will show you some needed USE flags changes and blocking programs. Made the needed changes in /etc/portage/package.use and re-launch the emerge command. If needed, unmerge the blocking programs:

It can append that portage want to unmerge more programs than necessary. You can always try to re-install them later.

When emerge is done updating world, poursue as usual:

You are done. You get a pulseaudio free system, and at the same time, it also is gnome free and *kit free.

For automounting of the plugable devices see pmount-gui + *kit free lxde

Any application that uses OSS
OSS applications are not so easy to get running with jack. One way which does not seem to work is the oss -> aoss -> alsa -> jack chain. Another possibility is to to use a sound daemon like arts (which can be configured to use jack as backend), this results in the chain: oss -> arts -> jack, which only works for playback though. Yet another solution is to use oss2jack, which allows you to do oss -> jack directly, but requires some work (which is rewarded by a high compatibility, every oss application I tried worked). The fusd-kor ebuild did not work for me, the compilation failed. Finally, you could also use PulseAudio, but not all applications support it, and it generally adds a bit of latency.

oss2jack
Note : The following is outdated because oss2jack is masked (depend on the realtime-lsm module).

We need to get oss2jack and fusd-kor, both have not been integrated into the official portage tree, but are available here: http://gentoo-sunrise.org/svn/reviewed/media-sound/oss2jack/ (please view the relevant docs on PORTDIR_OVERLAY if you don't know how to use external ebuilds with emerge). The fusd-kor ebuild did not work for me, so I installed fusd-kor manually following the instructions from http://fort2.xdas.com/~kor/oss2jack/install.html - substituting the kfusd/kfusd.c with the file from http://hg.konstruktiv.org/fusd/file/2df3a93d0724/kfusd/ (the changes were needed for >= 2.6.19 compatibility).

Create two new files, and :

Afterwards run

Then, after adding "media-sound/fusd-kor-1.10.11" to continue with

Now everything should be working: - make sure jackd is running - modprobe kfusd (this should spawn devices called /dev/fusd/control and /dev/fusd/status) run oss2jack (or oss2jack -n X if you want oss2jack to be accessible via /dev/dspX), this should create the devices /dev/dsp (or /dev/dspX if you used the -n parameter) Run your oss application, and point them to the /dev/dsp devices which you assigned to oss2jack. Enjoy!

Needed Softwares
Be sure to install firefox, mplayerplug-in, netscape-flash, nspluginwrapper and libjackasyn.

I use the mplayerplug-in because it will play more video formats than gnome-mplayer or gecko-mediaplayer at that time of writing (February 2009).

On amd64, be sure to install the last netscape-flash version. Also on amd64, if mplayerplug-in fail due to "cannot find -lgio-2.0", see bug238990 and emerge it without the USE flag.

Configuration
You will need the ALSA plug into your asoundrc file as explained before.

Mplayerplug-in must be configured to use JACK by default, and ALSA if JACK is not running.

Netscape-flash, very old way
For netscape-flash to work with firefox and JACK, you must launch firefox with:

Note: After my last system update, jacklaunch just hangs. The good news is that flash in firefox works with jack as usual:

Netscape-flash, old way
After a system update, I was getting no sound with mplayer. I removed ~/.asoundrc and mplayer was working again, as well than all the other audio softwares, but at the exception of netscape-jack. After a while, I found a jack plugin for the flash player. It is into the pro-audio overlay, so it is just to run

This is with the last svn jack2 code from the pro-audio overlay, and I don't use a .asoundrc file anymore. Just start firefox as usual.

Netscape-flash, new way
Use the ALSA Loopback device as explained before.

Test
You must now be able to play the videos at www.humanitysong.org with JACK and Firefox.

Timidity++
It is possible to run timidity++ as a MIDI server for jack. This way, timidity++ will appear into QJackCtl like 4 ALSA MIDI input ports. You can use it in order to play your MIDI files if your sound card lack a MIDI synthesizer, (or if you want to use big sound fonts...).

You must have the jack use flag for Timidity++.

Starting the Timidity++ server at boot time
In order to start the JACK Timidity++ server at boot time, jackd must be running and Timidity++ must be run under the same user than jackd.

When installing Timidity++, emerge will install the boot script, and you will have to modify it. Here are the modified files:

Don't forget to adjust TIMIDITY_USER to the same user than defined into

Adding the script into the default run-level:

Netjack
With Netjack it's possible to transport audio over a network. Netjack is more complicated to set up than, but has an additional benefit. Playing audio over a network is easy with PulseAudio, but editing is not really possible. Yes, you can edit with when  is installed with, but it is buggy. A much better solution is something like with.

Homework
Before starting, read up on some concepts in the walk through. A Linux User article offers sound information too.

You should now know that a slave is where the applications are, but audio hardware is not. A master is located where the audio hardware is, but the applications are not.

Master
Install > with :

Under make sure that PCM is > 0.

Slave
Install with .  is now deprecated.

Make sure your applications such as are built with.

Sound server on Master
Run the Master sound server:

Sound server on Slave
, because realtime hasn't been setup here.

Connect Slave to Master
On Master:

This produces a response on the running jackd on Master and Slave.

The netsource ports then need to be connected to the system ports. They can be listed with

On Slave:

Boom: sound erupts from your speakers.

is a gui for connecting Jack ports. However, because we are working on Master, which doesn't have a graphical environment to run such applications the connections have to be constructed manually with.

Master
The sleeps allow time for things to connect up.

cannot load driver module alsa
If get something like the following when trying to start jackd: jackd I got this first but it can easily be corrected by lowering the Frames/Period setting. Use -p option to jackd or qjackctl to do this.

Failed to start jackd
If you are having problems starting jackd as a normal user and it is failing with errors like: Output then check the ownership of /var/run/jack as it may be set to root:root. Running the following as root will fix this and allow users in the audio group to start jack:

Could not open/initialize audio device -> no sound.
If you get this message trying to have mplayer play sound through Jack, probably Jack support isn't compiled into your mplayer. You will need to get libbio2jack before attempting a compile.

If you have a recent bio2jack version, you may run into a little compatibility problem while compiling with jack support enabled. It turns out that 'JACK_GetJackLatency' has been changed to 'JACK_GetJackOutputLatency' in one of the recent bio2jack versions. All that is needed is to make two or three small changes to ao_jack.c and it will compile fine. The CVS version of MPlayer already contains a better JACK output driver that doesn't use libbio2jack at all.

Cannot use real-time scheduling
If you are unable to use realtime scheduling as a normal user (in spite of properly configured PAM/set_rlimits), and get errors like: Output then please see 'Kernel configuration'.

realtime-lsm (deprecated from a long time ago and removed since 2.6.24)
Kernel versions before 2.6.24 can use realtime-lsm. If you have a newer kernel, or if you can anyway, please use the RLIMITS option below.

Compile and install your kernel, and then reboot. Now enable the USE flag and emerge realtime-lsm:

The easiest way to make sure it gets loaded at boot time is to add it to :

Make sure you added the user who should be capable of using realtime features to the group realtime, which gets created by realtime-lsm. You can check that the realtime module is in use in the qjackctl status window.

With PAM
Make sure you have PAM version 0.99 or later installed.

Then edit :

Save and close. Log out and log back in, and you should have realtime capabilities if you're in the audio group.

Without PAM
If you do not want or cannot use PAM, there is a tool to set RLIMITS priorities, called set_rlimits.


 * Untar it and see the included README and manpage what to do with it ;)
 * A sample set_rlimits.conf entry could look like this:

Note: this sample is respectfully taken from: http://ubuntustudio.com/wiki/index.php/Breezy:Using_set_rlimits

There is also an ebuild for set_rlimits in ProAudio overlay http://proaudio.tuxfamily.org/wiki/index.php?title=Main_Page