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


Monday, July 23, 2018

First sound: cirrus logic configuration

The cirrus logic audio card drive is standard in the linux 4.14.52 kernel supplied by Alpine Linux, and the driver loads when the firmware overlay is installed.  After this, it is necessary to configure the card as desired using the amixer cset capability.  The original versions have been updated for the current driver and can be found at http://www.horus.com/~hias/tmp/cirrus/cirrus-ng-scripts.tgz.  They have been rewritten to use a common function definition script file and the new register names.

I use a Sony Stereo ceramic electret condenser mic ECM-CS3 which needs a 5v mic bias.  The script Record_from_Linein_Micbias.sh sets the cirrus logic card up fine for this and recording works fine.  Playback currently through a pair of earbuds for testing.

The idea is to put the RPi, a battery and the mic in a small satchel bag and put it on the floor in the middle of the acoustic jam sessions to record the tunes.  I plan to setup an Open Sound Control interface on a tablet to adjust the mix, more on that to come.

Friday, July 13, 2018

Dependencies: Building the rest of the lot

Ardour 5.12 has lot of opensource library dependencies.  Many of them are available already built in the Alpine Linux armv7 repository, and the rest have to be built from source.  This is not trivial.  I was able to install 58 tools and libraries with the get_alpine_deps.sh script found on my audiopi gitlab repository.

The other 23 need to be configured and compiled from source.  See ardour_dep_urls.txt.

The gory details of waf, perl, configure etc are not of tremendous interest except where the default process needs a nudge.   I'll document what I did for the following to make them compile and install on Alpine Linux.  I'm using 

./configure --prefix=/usr/local
 ./waf configure --prefix=/usr/local
 perl Makefile.PL PREFIX=/usr/local
  • ExtUtils-MakeMaker-6.64: needed perl-dev installed.  Updated get_alpine_deps.sh.  make test needed fakethr.h, sudo touch /usr/lib/perl5/core_perl/CORE/fakethr.h; same for sudo touch /usr/lib/perl5/core_perl/CORE/perlsfio.h
  • LRDF-0.5.1-rg
  • XML-Parser-2.41
  • XML-Simple-2.22: needed perl-xml-namespacesupport and perl-xml-sax, perl-xml-sax-base installed.  Updated get_alpine_deps.sh
  • aubio-0.3.2
  • gtk-doc-1.21: needed docbook-xsl installed, Updated get_alpine_deps.sh
  • gtk-engines-2.21.0
  • jpeg-9a
  • libart_lgpl-2.3.21
  • libiconv-1.14: edited srclib/stdio.h to comment out _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
  • liblo-0.28
  • lilv-0.24.3: needs lv2, serd, sord installed
  • lv2-1.14.0: install before lilv
  • nss-3.25: export NSPR_INCLUDE_DIR=/usr/local/include/nspr for nss after installing nspr
  • nss-pem-1.0.2
  • rdflib-4.1.2: sudo python setup.py install
  • rubberband-1.8.1: needs vamp sdk installed, needs ladspa-dev installed.  Updated get_alpine_deps.sh
  • serd-0.29.2: install before lilv
  • sord-0.16.1: install before lilv
  • sratom-0.6.0: install before lilv
  • suil-0.10.0
  • vamp-plugin-sdk-2.5: install before rubberband

Reboot: Alpine Linux and Ardour 5.12

Alpine Linux has a Raspberry Pi distribution with a modern kernel (4.14.52).  I installed this on a 32GB SD card and will be compiling and running Ardour 5.12 on this using the Cirrus Logic Audio Card which appears to be unavailable since 2016.   Perhaps the Blokas PiSound would work even better.

Installing Alpine Linux was not hard, following the Classic installation instructions.  To get the Cirrus Logic Audio Card driver working, the device tree overlay for wm5102 needs to be loaded.  There also is a modprobe dependency, put this in /etc/modprobe.d/cirrus.conf

softdep arizona-spi pre: arizona-ldo1

The file  /media/mmcblk0p1/config.txt needs to have the overlay added:
head /media/mmcblk0p1/config.txt
disable_splash=1
boot_delay=0
dtoverlay=vc4-kms-v3d
dtoverlay=rpi-cirrus-wm5102
dtoverlay=pi3-disable-bt
gpu_mem=256
gpu_mem_256=64

This successfully adds the device tree overlay at boot and loads the appropriate modules.

dmesg | tail -19
[ 2271.440909] snd-rpi-cirrus soc:sound: ASoC: CODEC DAI wm5102-aif1 not registered - will retry
[ 2271.444327] wm8804 1-003b: revision E
[ 2271.445857] snd-rpi-cirrus soc:sound: ASoC: CODEC DAI wm5102-aif1 not registered - will retry
[ 2271.483599] arizona spi0.1: Failed to get mclk1: -2
[ 2271.483615] arizona spi0.1: Failed to get mclk2: -2
[ 2271.483939] LDO1: supplied by RPi-Cirrus 1v8
[ 2271.484938] snd-rpi-cirrus soc:sound: ASoC: CODEC DAI wm5102-aif1 not registered - will retry
[ 2271.492410] arizona spi0.1: WM5102 revision C
[ 2271.520832] MICVDD: supplied by RPi-Cirrus 1v8
[ 2271.521795] Adding alias for supply MICVDD,(null) -> MICVDD,spi0.1
[ 2271.522102] Adding alias for supply MICVDD,(null) -> MICVDD,spi0.1
[ 2271.522109] Adding alias for supply DBVDD2,(null) -> DBVDD2,spi0.1
[ 2271.522115] Adding alias for supply DBVDD3,(null) -> DBVDD3,spi0.1
[ 2271.522121] Adding alias for supply CPVDD,(null) -> CPVDD,spi0.1
[ 2271.522130] Adding alias for supply SPKVDDL,(null) -> SPKVDDL,spi0.1
[ 2271.522144] Adding alias for supply SPKVDDR,(null) -> SPKVDDR,spi0.1
[ 2271.523659] snd-rpi-cirrus soc:sound: ASoC: CODEC DAI wm5102-aif1 not registered - will retry
[ 2271.553689] snd-rpi-cirrus soc:sound: ASoC: CODEC DAI wm5102-aif1 not registered - will retry
[ 2271.681956] snd-rpi-cirrus soc:sound: wm5102-aif1 <-> 3f203000.i2s mapping ok

aplay -l

**** List of PLAYBACK Hardware Devices ****

card 0: RPiCirrus [RPi-Cirrus], device 0: WM5102 AiFi wm5102-aif1-0 []

  Subdevices: 1/1
  Subdevice #0: subdevice #0

lsmod
Module                  Size  Used by
snd_soc_wm5102        385024  1
snd_soc_wm_adsp        40960  1 snd_soc_wm5102
gpio_arizona           16384  0
snd_soc_arizona        45056  1 snd_soc_wm5102
arizona_micsupp        16384  1
arizona_spi            16384  0
arizona_ldo1           16384  1
snd_soc_wm8804_i2c     16384  1
snd_soc_rpi_cirrus     20480  0
snd_soc_wm8804         16384  1 snd_soc_wm8804_i2c
snd_soc_bcm2835_i2s    16384  2
snd_soc_core          180224  7 snd_soc_wm8804,snd_soc_rpi_cirrus,snd_soc_wm5102,arizona_micsupp,snd_soc_bcm2835_i2s,snd_soc_arizona,snd_soc_wm_adsp
snd_compress           20480  2 snd_soc_core,snd_soc_wm_adsp
snd_pcm_dmaengine      16384  1 snd_soc_core
snd_pcm                94208  6 snd_soc_wm8804,snd_soc_rpi_cirrus,snd_pcm_dmaengine,snd_soc_bcm2835_i2s,snd_soc_arizona,snd_soc_core
spi_bcm2835            16384  0
snd_timer              32768  1 snd_pcm
i2c_bcm2835            16384  0
snd                    65536  5 snd_compress,snd_soc_rpi_cirrus,snd_timer,snd_soc_core,snd_pcm
...

The modprobe.d file can be found on my audiopi gitlab repository.


Tuesday, May 3, 2016

Ardour and the Pi

I was able to compile (waf) ardour4 on the Raspberry Pi3 and it works fine with the Cirrus Logic Audio Card.  I can record and play back in stereo using the onboard microphones and headphone output.  I will have to try my preamp and AKG condenser microphone and confirm the line in WORKS but I have confidence.

Compiling ardour is not for the fainthearted.  The dependency list is extensive and it took a while on the Pi3 but nothing seemed out of the ordinary for a project of this complexity.

If you are really interested, see http://ardour.org/current_dependencies.html for the dependencies and http://ardour.org/building_linux.html for the procedure.

I had to build a few of the dependencies:
  • atkmm-2.22.7
  • libart_lgpl-2.3.21
  • liblrdf-0.5.0
  • pangomm-2.28.4
 but raspbian has a working jack daemon and it runs fine.
Time to try some plugins and see if the whole system can handle signal processing.

Thanks to all the Ardour and Linux Audio developers who have made this possible!

Thursday, April 7, 2016

Cirrus Logic driver

Building the raspberry pi code is documented at Kernel Building.  I wanted to start with stable linux 4.5 from git.kernel.org because the Cirrus Logic driver is in the mainline starting with v4.5.  But wanting quick results sent me to use a precompiled 4.1.19 kernel from Matthias "Hias" Reichl.
  There are lots of issues with getting the Cirrus Logic Audio Card working.  Hias has a version at RPi Linux driver for Wolfson / Cirrus Logic Audio Card

I used the precompiled version found there.

wget http://www.horus.com/~hias/tmp/cirrus/cirrus-linux-4.1.19.tgz
sudo tar zxf cirrus-linux-4.1.18.tgz -C /

Add the following lines to /boot/config.txt

dtoverlay=rpi-cirrus-wm5102
dtoverlay=i2s-mmap 
 
And add the following lines to /etc/modprobe.d/cirrus.conf

softdep arizona-spi pre: arizona-ldo1 
softdep spi-bcm2708 pre: fixed 
softdep spi-bcm2835 pre: fixed 


Rebooting and note this works.
dmesg | grep arizona
[    7.722414] arizona spi0.1: WM5102 revision C
 

aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpiwsp [snd_rpi_wsp], device 0: WM5102 AiFi wm5102-aif1-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
 

Thanks Hias!

Sunday, March 20, 2016

iozone benchmark results for aligned F2FS on USB

Using the F2FS filesystem on USB makes sense to me.  I ran Iozone on various configurations and came to the conclusion that aligning the USB cylinders on the erase block size of 128k improved write performance, as well as using the F2FS file system.

Details at IOZone Results for raspberry pi 3.

F2FS vs EXT4 on  aligned USB