Search:  
Gentoo Wiki

Jack

This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Contents

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.

Installing necessary software

In order for JACK to be of any use to you, you need three pieces of software:

  1. driver for your sound card (alsa)
  2. JACK
  3. software, which can use jack (like the jack output driver for xmms or mplayer)

If you already have alsa installed skip the next section.

This howto was written with a 2.6 kernel, and alsa. Other configurations may or may not work. If you get them to work, please post!

About the JACK USE flag

Emerging jack will tie in jack to your system but it couldn't hurt to add it to your /etc/make.conf.

This is quoting from the JackIt FAQ.

Currently (as of 2.6.7) JACK has a serious problem creating  SCHED_FIFO  threads for 
real-time processing. It is unclear whether this is a bug in JACK, in the new Native 
PThreads Library (NPTL), or in the 2.6 kernel. At the moment no one has a solution, 
but there is a workaround: define  LD_ASSUME_KERNEL=2.4.19  in the environment of the 
jackd process and of every JACK client. The easiest way to do this is setting it in 
 ~/.profile , or wherever you customarily define global environment variables. Glibc 
developer Ulrich Drepper  explains the operation  of  LD_ASSUME_KERNEL in more detail.
emerge jack-audio-connection-kit

Installing alsa and or alsa-plugins

Follow the normal configuration of alsa at http://www.gentoo.org/doc/en/alsa-guide.xml Then make sure jack is in your use flags and:

  emerge -av alsa-plugins

Installing jack

You need to have jack-audio-connection-kit installed. The ebuild has quite a few USE-flags some of which are listed here:

Of course having alsa is a must. Having caps is only useful with 2.4 kernels. Now we are ready to

emerge --oneshot jack-audio-connection-kit

We use --oneshot because the applications which use jackd will depend on jack-audio-connection-kit and we don't want to have redundant stuff in our world file, do we?

Getting applications to use JACK

Now that we have jack installed we want our applications be able to use jack. You need to turn on jack support in your packages with the following one liner:

emerge -avuDN world

( --ask (-a): Ask before installing or updating, --verbose (-v):be Verbose, --update (-u):Update and installed packages where possible, --deep (-D):perform Deep dependency checks, --newuse (-N):recompile packages that need it with the New use flags)

Other packages might be in the list too. If you don't want to recompile everything in the list you can use emerge --oneshot <packages>.

Configuring JACK

Realtime mode

You don't have to use the realtime mode in order to use jack, but it should make your audio experience better in some cases. 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

Be sure to read that page as it contains important information.

realtime-lsm (deprecated since 2.6.24)

Warning: This method is deprecated and will not work with kernels including and after 2.6.24.

For more information see bug 87577 and bug 101766.

In gentoo you need to install realtime-lsm. That ebuild needs the following configuration for your running kernel:

(Preemptible Kernel is not needed but highly recommended!)

Linux Kernel Configuration: for jack
*Processor type and features --->
        Preemption Model (Preemptible Kernel (Low-Latency Desktop))  --->
  [*]   Preempt The Big Kernel Lock
*Security options  ---> 
  [*] Enable different security models
*Security options  ---> 
  <M> Default Linux Capabilities

Make sure you compile "Default Linux Capabilities" as a Module, or realtime-lsm will NOT work!

Now you are ready to emerge realtime-lsm:

emerge realtime-lsm

After you have the ebuild installed you might want to do the following tricks to get the module automatically loaded at boot:

echo "realtime" >> /etc/modules.autoload.d/kernel-2.6
update-modules

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

RLIMITS

with PAM

Make sure you have PAM version 0.99 or later installed.

eix -e pam

If you don't have eix, see this page. Or just do:

emerge -p pam

Then edit /etc/security/limits.conf

File: /etc/security/limits.conf
 # rtprio
 @audio - rtprio 90
 @audio - nice -5
 @audio - memlock 500000

This sets the RT priority to 90, nices RT tasks to -5, and grants a memlock of ~500MB.

without PAM

If you do not use PAM, there is a tool to set RLIMITS priorities:

wget http://www.physics.adelaide.edu.au/~jwoithe/set_rlimits-1.2.0.tgz
File: /etc/security/limits.conf
 @audio  /usr/bin/jackd          nice=-1 rtprio=85
 @audio  /usr/bin/qjackctl       nice=-1 rtprio=84
 @audio  /usr/bin/ardour         nice=-1 rtprio=83
 @audio  /usr/bin/hydrogen       nice=-1 rtprio=82
 @audio  /usr/bin/jackeq         nice=-1 rtprio=81
 @audio  /usr/bin/jack-rack      nice=-1 rtprio=80
 @audio  /usr/bin/jamin          nice=-1 rtprio=79
 @audio  /usr/bin/qsynth         nice=-1 rtprio=78
 @audio  /usr/bin/rosegarden     nice=-1 rtprio=77
 @audio  /usr/bin/seq24          nice=-1 rtprio=76
 @audio  /usr/bin/specimen       nice=-1 rtprio=75
 @audio  /usr/bin/vkeybd         nice=-1 rtprio=74
 @audio  /usr/bin/zynaddsubfx    nice=-1 rtprio=73
 @audio	/usr/bin/ams		nice=-1	rtprio=72
 @audio	/usr/bin/amsynth	nice=-1	rtprio=71

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

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:

jackd -d alsa

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

jackd -R -dalsa

You can find configuration options in the man page has:

man jackd

Remember to start the daemon as a normal user. Running these things as root is bad and you should know that! If you start the daemon as root you also need to run the software using it as root and we all know what that means.

If you are having problems starting jackd as a normal user and it is failing with errors like:

cannot create /var/run/jack/jack-1000 directory (Permission denied)
cannot create server sockets
cannot create engine

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:

chown root:audio /var/run/jack/

Using graphical tools

qjackctl is a nice tool to configure and start jackd. The interface should be easy to grasp.

# emerge qjackctl

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.

Now it's time to configure qjackctl to work with your soundcard. Click the Setup button on the main panel to get to the configuration screens. Here's a picture of the settings I use for a CrystalSound cs4624 (Hercules Fortissimo III) card...they should work well for any stereo editing tasks. 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.

qjackctl Settings

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. If it works, you are ready to move on to the next step. F Click the OK button to apply the changes, then click the Start button on the main qjackctl panel to test everything out. If everything goes as planned, your JACK server should start and qjackctl will monitor it's status

qjackctl running


Now you're all ready to fire up some fine audio software like Ardour, ReZound, JAMin, and/or Timemachine and get to work.

Configuring software to use JACK

Any application that uses ALSA

ALSA contains a JACK plugin, which means that you could "set once(in ALSA), use anywhere".

Make sure that alsa-jack is installed. Usually, it comes with alsa-plugins when using USE flag "jack" to install it.

File: ~/.asoundrc or /etc/asound.conf
pcm.jackplug {
    type plug
    slave { pcm "jack" }
}

pcm.jack {
    type jack
    playback_ports {
        0 alsa_pcm:playback_1
        1 alsa_pcm:playback_2
    }
    capture_ports {
        0 alsa_pcm:capture_1
        1 alsa_pcm:capture_2
    }
}

Then, you can test it by using:

aplay -Djackplug somefile
arecord -Djackplug somefile

If you are satisfied, you may want to make it the default. You can replace the jackplug in the above config file with !default.

Note that if you really set it to !default, many applications may not work (in my case, only xine can support it). You could use artsdsp or esddsp and set the output system be JACK. Also if you restart the alsasound script, the JACK Server will be killed. You need to start it again by yourself.

Reference: ALSA Documentation

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. The "best" solution seems to be 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.

oss2jack

Update: There is a seperate HOWTO for oss2jack now which includes links to working ebuilds and further instructions.

These are the old instructions for installing oss2jack manually:

We need to get oss2jack and fusd-kor, both have not been integrated into the official portage tree, but are avaliable 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, {{Filename|/etc/modprobe.d/fusd]] and /etc/udev/rules.d/30-fusd.rules:

File: /etc/modprobe.d/fusd
alias /dev/fusd kfusd
alias /dev/fusd/control kfusd
alias /dev/fusd/status kfusd

Afterwards run update-modules.

File: /etc/udev/rules.d/30-fusd.rules
SUBSYSTEM=="fusd", NAME="fusd/%k", GROUP="audio", MODE="0666"


Then, after adding "media-sound/fusd-kor-1.10.11" to /etc/portage/profile/package.provided continue with

emerge -av oss2jack

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 wan't 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!

xmms

First you need to install the jack output plugin

emerge xmms-jack

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:

mplayer -ao jack

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

File: ~/.mplayer/config
ao=jack

Even though the ebuild didn't pull it, i had to

emerge bio2jack

to get mplayer play nice.

MythTV

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

Pro audio production applications

In order to get really low latency with jack, you need full premption in the kernel and the ability to fix the tasks priority.

Full preemption: the easiest way is to install the rt-sources kernel package. It is part of the pro audio production applications portage overlay. Be aware at it is an unsupported software branch. It is plenty of really good sound applications in this overlay.

Task priority: To get the realtime lsm module at work and the lowest latency, you must install rtirq from this overlay. It will change the realtime scheduling policy and priority of relevant system driver IRQ handlers and of softwares from users in the audio group. Another way to archive the same thing is to install pam-Rlimits (pam from the overlay).

Audigy and Live sound cards owners must read the files in the kernel documentation -> sound -> alsa -> Audigy-mixer.txt + SB-Live-mixer.txt and emu10k1-jack.txt.

Kernel Configuration

Block layer -> Support for Large Block Devices
            -? IO Schedulers -> select the 3 options + -> Default I/O scheduler -> <Anticipatory> (Choice may differ here, it is always possible to change it with the proc file system) 
Processor types and features -> Preemption Mode (Complete Preemption (Real-Time))
Processor types and features -> HPET Timer Support + Timer frequency (1000Hz)
Device Drivers -> Character Devices -> < > HPET Control RTC IRQ (totherwise MuSE will not run, maybe fixed with museseq 0.8)
Device Drivers -> Sound -> Alsa -> Sequencer support + all the OSS options + all the RTC options
Device Drivers -> Sound -> Alsa -> Generic devices -> <M> Virtual MIDI soundcard

You must select your soundcard.

Security options -> [*] Enable different security models
                    <M> Defaults Linux Capabilities (This MUST be a module.)
                    <M> Realtime Capabilities


You must install the rtirq package from the audio pro overlay and add it in a runlevel (not needed with pam-Rlimits). Those scripts will configure both the hardware and software priorities. You must be in the audio group.

Before using a such realtime kernel you must check at you don't have any shared irq:

cat /proc/interrupts

The result must be something like:

           CPU0
  0:  362645597  IO-APIC-edge   [........N/  0]  pit
  1:     221484  IO-APIC-edge   [........./  1]  i8042
  7:          0  IO-APIC-edge   [........./  0]  parport0
  8:    4817899  IO-APIC-edge   [........./  0]  rtc
 14:    5138971  IO-APIC-edge   [........./  0]  ide0
 15:     221989  IO-APIC-edge   [........./  0]  ide1
169:    2873093  IO-APIC-level  [........./  0]  acpi, ohci_hcd:usb1
177:         92  IO-APIC-level  [........./  0]  Ensoniq AudioPCI
185:    7792883  IO-APIC-level  [........./  0]  EMU10K1
193:          0  IO-APIC-level  [........./  0]  ohci_hcd:usb2
201:         16  IO-APIC-level  [........./  0]  ohci_hcd:usb3
209:   12251405  IO-APIC-level  [........./  0]  ehci_hcd:usb4
217:   27795559  IO-APIC-level  [........./  0]  ohci1394, eth0
225:         10  IO-APIC-level  [........./  0]  bttv0
NMI:          0
LOC:      48347
ERR:          0
MIS:          0

In order to troubleshoot a shared irq, you have to read the manual of your motherboard, move cards from slot to slot and/or change the irq's for the PCI slots in the BIOS if it is possible (Some motherboard can do that, other can't). Avoid VIA chipsets because they have a buggy PCI implementation (and SiS too by personal experience). Ardour system requirment

For more on this, look at Realtime (RT) Kernel Howto and DAW Digital Audio Workstation Howto.

Troubleshooting

cannot load driver module alsa

If get something like the following when trying to start jackd:

Code: jackd
loading driver ..
creating alsa driver ... hw:0

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.

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.

External Links

Gentoo Linux Documentation - How to Enable Realtime for Multimedia Applications

Retrieved from "http://www.gentoo-wiki.info/Jack"

Last modified: Sat, 19 Jul 2008 06:28:00 +0000 Hits: 68,856