How to run the jack audio connection seamlessly in gnome on Fedora

On the coattails of Lennarts excellent post about the status of the Linux audio landscape, I would like to give the more adventurous Fedora user some tips on how to experiment with some of these other technologies.

Problem: The user would like to run 'foo' server in conjunction with Pulseaudio in either gnome or kde without too much 'tinkering'. Tinkering means changing absolutely no files outside of /home without the aid of yum or some otherwise simple and reproducible command. Furthermore, these changes should work reliably across setups.


1) So in this case, the 'foo' server is jack. There are a number of programs I would like to work with that work with Jack instead of Pulse. Jack is essentially lower level than Pulse, so this solution is geared towards things that work underneath Pulse, thus tools that have to be running before Pulse is. Since jack is the defacto audio daemon for Freeeee and a favourite by the developers, Fedora users might want to become more familiar with it.

2) To the best of my knowledge, Gnome starts Pulseaudio by calling up the legacy ESD. Since Pulse wraps ESD nicely, it starts up instead using a systemwide default configuration. KDE on the other hand has a directory for systemwide and user specific start up scripts to be run. Pulse is included as a systemwide script. If the user is a member of pulse-rt, then it automatically uses realtime mode settings. Otherwise it resorts to defaults. We're assuming you want realtime settings.

# usermod -G pulse-rt

Nicely enough, we shouldn't need to do anything more for jack to run in realtime mode as well.

3) Although we can hack the KDE systemwide directories to start jackd as well, or just change the user specific ones, it provides no guarantees that jack can be started before pulse. Furthemore, this is not a possible solution for gnome.

When the user logins from gdm or kdm, the display manager searches for some .dekstop files that specify all the possible desktop environments available to the user. These .desktop files have links to different programs, such as 'gnome-session' or 'startkde'. These programs start up the comprehensive desktop environment. The user can also specify their own script or program to be run on the startup of the X server. This script is stored in a per-user basis at ~/.xsession . Although this is considered a 'legacy' method, it is quite commonly used in more minimalist setups. In order to enable this 'legacy' feature, run:

# yum install xorg-x11-xinit-session

Then create your ~/.xsession script.

$ vi ~/.xsession

and fill it with the following example

#! /bin/sh

jackd --realtime -d alsa &

and finally make it executable

$ chmod +x ~/.xsession

Notice that in the .xsession file, the command for jackd has an ampersand '&' after it. This means that the program is run 'in the background'. gnome-session does not have the ampersand. When gnome-session is finished, then the X server dies. If you replace it with any other program, remember, once that program dies, the X server dies with it. (Try it with xterm or firefox, and see what happens when you close it down.)

You can of course experiment further with .xsession and put any programs you want to start, regardless of which DE you use.

4) Finally, Pulse must be configured to work with Jack. I used a config provided by jebba, one of the Freeeee developers. It goes in ~/.pulse/ .

$ vi ~/.pulse/

Then fill it with this

load-module module-jack-sink channels=2 channel_map=front-left,front-right
#load-module module-jack-source channels=2 channel_map=front-left,front-right
load-module module-native-protocol-unix
## The following is not mandatory
load-module module-volume-restore
load-module module-default-device-restore
load-module module-rescue-streams
.ifexists /usr/lib/pulse-0.9/modules//
load-module module-x11-publish
## The following can conflict with this config.
#.ifexists /usr/lib/pulse-0.9/modules//
#load-module module-gconf
set-default-sink jack_out
set-default-source jack_in

# no
#load-module module-alsa-sink
#load-module module-alsa-source device=hw:1,0
#load-module module-oss device="/dev/dsp" sink_name=output source_name=input
#load-module module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
#load-module module-null-sink
#load-module module-pipe-sink

### Load several protocols
load-module module-esound-protocol-unix
# no workie
#load-module module-native-protocol-unix

### Network access (may be configured with paprefs, so leave this commented
### here if you plan to use paprefs)
load-module module-esound-protocol-tcp
load-module module-native-protocol-tcp
load-module module-zeroconf-publish

load-module module-rtp-recv
load-module module-null-sink sink_name=rtp format=s16be channels=2 rate=44100 description="martin RTP Multicast Sink"
load-module module-rtp-send source=rtp.monitor

### Publish connection data in the X11 root window
load-module module-x11-publish

5) Finally, log out of your Gnome or KDE session, to come back to your login screen. Under 'session type' you should see a new option for 'Custom' next to KDE and Gnome. Login using that session type. Remember, Gnome or KDE will load up, depending on which you have put in .xsession . If you don't see that option, you may need to restart your computer, in order to restart your display manager. (If you're savy, you can just 'init 3' and then 'init 5' from the command line as root.)

6) One of the nice things about this configuration is that if either Pulse or Jack die, for any reason at all, you only need to open up a terminal and run the following commands.

$ killall pulseaudio ; killall jackd
$ jackd --realtime -d alsa & && pulseaudio &

Since they both now have sane default configurations, there is very little muck that has to be typed in at the command line to restart them.

Happy Hacking!

2 flames:

Kevin Kofler zei

Now if only there was a solution to use JACK apps without reconfiguring PA to work over JACK... Either JACK should work on top of PA (which sucks for latency, so real professionals won't want to use that configuration, but if you're just going to use a JACK app once to do something quickly, it would just work) or (ideally) PA should emulate the JACK protocol as it does with ESD (but I have no idea how hard that is - I know aRts is essentially impossible to emulate due to it wanting to handle decoding and even video (!) in the sound server, but I don't know how wacky the JACK protocol is, i.e. if it's more like ESD or more like aRts).

I posted a hackish solution for using JACK on top of PA here:
but it comes with an awfully huge latency (about half a second), so I can't recommend that solution for any serious use. It's also incredibly dumb (running 2 apps in the terminal just to echo the PA source to the PA sink - unlike JACK which has sources, sinks and connections, PA has sources, sinks and clients, you have to run an actual client to connect a source to a sink, and if you don't want to code your own echoing client, you even need 2 clients in a pipe; the problem is that the PA JACK integration puts in JACK as PA sources and sinks, which works for PA on top of JACK, but for JACK on top of PA, we'd want JACK as a PA client, not a PA source or sink).

Yankee zei

As for Pulse replacing Jack, i think you would have to talk to Lennart about that, and i think he doesn't want to do that.

My solution implies you want jack at least most of the time, if not some of the time. It uses more CPU, but if you run it in realtime mode, the latency is still very low.

There's really very very very little reason why you would want to run Jack on top of Pulse though.