Wednesday, August 1, 2018

Jack configuration: running with low latency

I have been using the jack audio connection kit  on linux since I can recall and ardour since 1999, and trust them to run well together.  I tried both jack1 and jack2 on the RPi3 and both run fine, so I went with jack2 as it can use more than one cpu.  I wrote an OpenRC start/stop/status script that handles the desired ulimit settings, as I could not get pam limits.conf to work in Alpine.   I built my own jackd from jack2 git source so I could do without the dbus configuration, trying to keep this simple.

#!/sbin/openrc-run
#
# Copyright (C) 2018, Samuel S Chessman
# SPDX-License-Identifier: GPL-3.0-or-later

# Start the jackd audio daemon as root for rt/memlock
# the settings below are in /etc/conf.d/jackd
#name=jackd
#pidfile=/var/run/jackd.pid
#command_user="sam:realtime"
#command="/usr/local/bin/jackd"
#command_args="-t 200 -p 2048 -R -n default -d alsa -s -n2 -r96000 -p 512 -dhw:RPiCirrus"
#command_background=true

# set the jackd ulimit
ulimit -r 99
ulimit -l 131072
ulimit -e unlimited

# set the users ulimit on ssh login
PID=$(cat /var/run/sshd.pid)
prlimit  -p $PID  --rtprio=99
prlimit  -p $PID  --memlock=134217728
prlimit  -p $PID  --nice=-20

depend() {
        after alsa
        after sshd
}
status() {
        if [ -e ${pidfile} ] ; then
                su $user -c "jack_lsp -A"
                eend $? "jackd is not running"
        else
                eerror "jackd is not running"
        fi
}

To have this run at boot:
rc-update add jackd default

There is a status command:
/etc/init.d/jackd status
system:capture_1
   alsa_pcm:hw:RPiCirrus:out1
system:capture_2
   alsa_pcm:hw:RPiCirrus:out2
system:playback_1
   alsa_pcm:hw:RPiCirrus:in1
system:playback_2
   alsa_pcm:hw:RPiCirrus:in2    

This corresponds to what ALSA and jack_lsp are reporting.
aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: vc4hdmi [vc4-hdmi], device 0: MAI PCM vc4-hdmi-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: RPiCirrus [RPi-Cirrus], device 0: WM5102 AiFi wm5102-aif1-0 []
  Subdevices: 0/1
  Subdevice #0: subdevice #0
oscar:/opt/audiopi$ jack_lsp
system:capture_1
system:capture_2
system:playback_1
system:playback_2


No comments:

Post a Comment