[AudioI] Low latency tricks for Raspberry Pi

Ted Rippert ted.rippert at gmail.com
Thu Mar 3 21:52:20 UTC 2022


As requested, here is short write up on some tricks I use to achieve low latency Audio on my Raspberry Pi. I’m going to be brief, so please go to https://linuxmusicians.com <https://linuxmusicians.com/> and search for threads on Low Latency and isolated CPUs for very extensive discussions. I’m assuming you already know your way around basic linux tasks.

I generally use Guitarix and Rakarrack-Plus for FX software. These work well with this setup. Other software may or may not depending on how it works.

The first thing you want to do is edit /boot/config.txt. You should have already modified this file to get the Audio Injector card to work. Now you just want to add this line to the end of the file:

force_turbo=1

This keeps the CPUs at their maximum clock speed all the time. Switching clock speeds cause xruns (crackling noises) in the audio. Your CPU will get hot using this, so make sure you have adequate cooling.

Next you want to copy your /boot/cmdline.txt file to back it up, and make another copy that you will modify. Here are the contents of my two files on a Raspberry Pi OS Buster system:

>cat /boot/cmdline.txt_orig
console=serial0,115200 console=tty1 root=PARTUUID=c1654665-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles

>cat /boot/cmdline.txt_isocpus 
console=serial0,115200 console=tty1 root=PARTUUID=c1654665-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles isolcpus=2-3 nohz_full=2-3 rcu_nocbs=2-3 nowatchdog acpi_irq_nobalance

Now I can just copy one of these files over to /boot/cmdline.txt and reboot to either run normally or with CPU cores 2 and 3 isolated from system tasks. The isocpus file also stops the OS from distributing interrupts across the cores, so most interrupts end up on core 0. You can isolate fewer or more CPUs, but this is a setup that works for me pretty well.

Once booted into and isolated CPU mode, this is how I start my audio system running:

jackd --silent -P 75 -d alsa -p 64 -r 96000 -X seq & 
jack_wait -w; 
TID=`ps -o tid,rtprio -L $!|egrep -o -m 1 '^\s.+[0-9]+\s+[0-9]'| head -n1 | awk '{print $1;}'`;
taskset -p -c 1 $TID

taskset -c 2 rakarrack-plus -n >/dev/null 2>&1 &

taskset -c 3 guitarix -N -C -p 7000 >/dev/null 2>&1 &

I am running both Guitarix and Rakarrack-plus with no GUI, and controlling them with MIDI. You can run them with the GUI, but they will create much more xruns. If you minimize the GUI, they will become much quieter, so that is how I set them up, and test them and then run them without the GUI when I just want to play the presets I’ve already made. 

Note that I have some code that finds the realtime thread for jack and puts it on CPU 1, which avoids it conflicting with the interrupts on CPU 0.

Also note that I run jack at 96000 samples per second. I’ve found that this is the best setting for low latency. The 64 sample block size yields 2.1 ms round trip latency, and this really only works well on an RPi 4 with no GUI, or at least minimized GUI. On an Rpi 3, try 128 samples block size and you will get 4.3 ms round trip latency which is generally very good. Or, you can use the 4.3 ms setting on an RPi 4 and keep the GUIs open. Also, more complicated presets take more CPU power, so you may need to increase the block size to avoid xruns if you are regularly using complex setups.

I like to use Manjaro Arm linux, as it comes stock with a Low Latency kernel, and you can easily setup lots of good audio packages just by installing the pro-audio package group. Also Manjaro is based on Arch linux so you can use the AUR to install and compile the latest versions of most packages. Still, you can get good results this way with the Standard Raspberry Pi OS.

Hope this is helpful,
Ted
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.audioinjector.net/pipermail/people/attachments/20220303/47bff307/attachment-0001.htm>


More information about the People mailing list