Difference between revisions of "JACK Audio Connection Kit"

From ArchWiki
Jump to: navigation, search
(Playing nice with ALSA)
m
Line 138: Line 138:
  
 
Remember to start it as a '''user'''. If you start it with "jackd -d alsa" as user X, it won't work for user Y.
 
Remember to start it as a '''user'''. If you start it with "jackd -d alsa" as user X, it won't work for user Y.
 +
 +
== gstreamer ==
 +
Example: watching a live stream without gconf
 +
gst-launch-0.10 playbin2 uri=http://streamer.stackingdwarves.net/bewerungeroom.ogv audio-sink="jackaudiosink"
 +
 +
Setting gstreamer to use jack using gconftool-2
 +
gconftool-2 --type string --set /system/gstreamer/0.10/audio/default/audiosink "jackaudiosink buffer-time=2000000"
 +
gconftool-2 --type string --set /system/gstreamer/0.10/audio/default/musicaudiosink "jackaudiosink buffer-time=2000000"
 +
gconftool-2 --type string --set /system/gstreamer/0.10/audio/default/chataudiosink "jackaudiosink buffer-time=2000000"
 +
 +
Further information: http://jackaudio.org/gstreamer_via_jack
  
 
=Related Articles=
 
=Related Articles=
 
[[Pro Audio]]
 
[[Pro Audio]]

Revision as of 11:00, 6 May 2011

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:JACK Audio Connection Kit#)

If you know anything about JACK, please expand this article. I've uninstalled it, so I can't really expand it any further.

Install

Multiprocessor implementation (soon: JACK2)

JACK2 is currently available in the [community] and can be installed from there

pacman -S jack2


You can compile Jack2 with the new dbus-based control system or the 'classic' interface. Which one you have depends on whether you compiled Jack2 with the --dbus configure option or not.

Jack2 without --dbus executes similarly to Jack1. With --dbus, control is done using the jack_control utility. Run `jack_control` to see what it does. The important commands are listed below:

jack_control start  -  starts the jack server
jack_control stop  - stops the jack server
jack_control ds alsa  -  selects alsa as the driver (backend)
jack_control eps realtime True  -  set engine parameters, such as realtime
jack_control dps period 256  -  set the driver parameter period to 256

You may also need to play with the driver parameters nperiods and rate.

JACK

Alternatively, there is the normal version from the extra repository, install it with:

pacman -S jack

Jack for a multi-user system

So, you have a descent multiuser system as it was designed more than 20 years ago, and now some developers decided that sound is only for a mono-user system... No I can not believe it !

Warning: Before following the below instructions, please note that there is a security risk to any service running as root, and, more importantly, the developers for jack do not test it for running as root. In other words, it could eat your babies, data, or both

Fortunately some time ago someone convinced the developers to allow jack to run as a system wide daemon. Here is the procedure to follow:

Create a /etc/profile.d/jack.sh file containing:

export JACK_PROMISCUOUS_SERVER=""

Replace /etc/rc.d/jack-audio-connection-kit with the following content

#!/bin/bash 

. /etc/rc.conf
. /etc/rc.d/functions

# source application-specific settings
[ -f /etc/conf.d/jack-audio-connection-kit ] && . /etc/conf.d/jack-audio-connection-kit

PID=`pidof -o %PPID /usr/bin/jackd`

[ -n "$JACKUSER" ] && HOME="/home/$JACKUSER"
[ -z "$JACK_PARAMS" ] && JACK_PARAMS=$(sed 's:/usr/bin/jackd ::' $HOME/.jackdrc)

case "$1" in
  start)
    stat_busy "Starting JACK"
    if [ -z "$PID" ]; then
      if [ -n "$JACKUSER" ]; then
        su - $JACKUSER -c 'export JACK_PROMISCUOUS_SERVER="" && . /etc/conf.d/jack-audio-connection-kit && umask 0000 && /usr/bin/jackd $JACK_PARAMS &> /dev/null &'
      else
	export JACK_PROMISCUOUS_SERVER=""
	umask 0000
        /usr/bin/jackd $JACK_PARAMS &> /dev/null &
      fi
    fi

    if [ ! -z "$PID" -o $? -gt 0 ]; then
      stat_fail
    else
      add_daemon jack
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping JACK"
    [ ! -z "$PID" ]  && kill $PID &> /dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else
      rm_daemon jack
      stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  *)
    echo "usage: $0 {sta|stop|restart}"
esac
exit 0

Where my /etc/conf.d/jack-audio-connection-kit is

# Configuration for starting JACK at boot

# Uncomment this to run as user (recommended)
#JACKUSER="root"

# Uncomment this to not source ~/.jackdrc
JACK_PARAMS="-R -P89 -dalsa -dhw:1 -r48000 -p512 -n3"

Playing nice with ALSA

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

pacman -S alsa-plugins

And enable it by editing (or creating) /etc/asound.conf (system wide settings) to have these lines:

# convert alsa API over jack API
# use it with
# % aplay foo.wav

# use this as default
pcm.!default {
type plug
slave { pcm "jack" }
}

ctl.mixer0 {
type hw
card 1
}

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

You needn't restart your computer or anything. Just edit the alsa config 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 won't work for user Y.

gstreamer

Example: watching a live stream without gconf

gst-launch-0.10 playbin2 uri=http://streamer.stackingdwarves.net/bewerungeroom.ogv audio-sink="jackaudiosink"

Setting gstreamer to use jack using gconftool-2

gconftool-2 --type string --set /system/gstreamer/0.10/audio/default/audiosink "jackaudiosink buffer-time=2000000"
gconftool-2 --type string --set /system/gstreamer/0.10/audio/default/musicaudiosink "jackaudiosink buffer-time=2000000"
gconftool-2 --type string --set /system/gstreamer/0.10/audio/default/chataudiosink "jackaudiosink buffer-time=2000000"

Further information: http://jackaudio.org/gstreamer_via_jack

Related Articles

Pro Audio