User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
Contact: Website

RPi and real-time, low-latency audio

Tue Feb 12, 2013 7:50 pm

Dear all,

I've started a Wiki page on how to set up your RPi so it can handle low-latency audio. I've also described some common bottlenecks when doing low-latency audio on the RPi and how to work around them. It's work in progress so if you have anything to add or you've spotted inconsistencies or even plain errors let me know. Or edit the article yourself of course, that's what Wiki's are for.

http://wiki.linuxaudio.org/wiki/raspberrypi

With the optimizations described in the article I can achieve system latencies well below 10ms so this opens up possibilities for using the RPi as a real-time effects processor, amp emulator, synth or sampler.

Regards,

Jeremy
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/

richardp
Posts: 117
Joined: Thu Jan 12, 2012 11:46 am

Re: RPi and real-time, low-latency audio

Tue Feb 12, 2013 9:18 pm

Nice writeup.
I am attempting a similar thing using Gstreamer/ALSA (low latency, not synth) - It works, but not for any length of time. After about 5 minutes USB Audio output stops.

My end goal is to make a motorbike intercom using commodity devices, and I want a Pi to be part of it :D

Code: Select all

gst-launch -v alsasrc device=hw:1 do-timestamp=true ! audioconvert ! queue ! audioresample  ! queue ! alsasink device=hw:0
Have not investigated much in to it as to where the data is going, but I suspect its the renown USB data loss problem.

Richard
RaspberryPi's galore
Solid run CuBox
ODroid U2

akavir
Posts: 13
Joined: Tue Feb 12, 2013 5:02 am

Re: RPi and real-time, low-latency audio

Tue Feb 12, 2013 9:42 pm

Used the guide last night and got my pi working with my USB Lexicon Omega. Even when I disable the ethernet, I still can't start JACK in full duplex. But I'm very encouraged by the fact that I've already tested capturing 4 analog inputs simultaneously with Ardour 2.8 with no errors and still CPU and RAM headroom to play with. I've been able to open fx chains like guitarix, and invada plugins. If I can just get full duplex, the game is on! Great write up, I've been trying for a while now to get JACK to play nice and your binaries work like a charm! The only things is, you need to update your wiki steps for the new package names you uploaded yesterday, other than that the guide works greats and I can't wait to push the limits of this little beast even farther! With the 1Ghz Turbo mode overclock, the Rpi is actually pretty snappy!

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
Contact: Website

Re: RPi and real-time, low-latency audio

Tue Feb 12, 2013 10:10 pm

akavir wrote:Used the guide last night and got my pi working with my USB Lexicon Omega. Even when I disable the ethernet, I still can't start JACK in full duplex.
Does the Lexicon Omega have something like a class compliant setting/switch? I've found that with my Edirol UA-25 I have to disable Advance mode in order to make it work in full duplex with JACK.
akavir wrote:But I'm very encouraged by the fact that I've already tested capturing 4 analog inputs simultaneously with Ardour 2.8 with no errors and still CPU and RAM headroom to play with. I've been able to open fx chains like guitarix, and invada plugins.
How awesome is that, Ardour on the RPi!
akavir wrote:If I can just get full duplex, the game is on! Great write up, I've been trying for a while now to get JACK to play nice and your binaries work like a charm!
Thanks! And good to know they work for others too.
akavir wrote:The only things is, you need to update your wiki steps for the new package names you uploaded yesterday, other than that the guide works greats and I can't wait to push the limits of this little beast even farther!
I'm planning on setting up a repository. Once that's done I'll add it to the Wiki.
akavir wrote:With the 1Ghz Turbo mode overclock, the Rpi is actually pretty snappy!
Ok cool, Turbo mode makes my setup unstable so I'm running at 950MHz now.
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/

akavir
Posts: 13
Joined: Tue Feb 12, 2013 5:02 am

Re: RPi and real-time, low-latency audio

Tue Feb 12, 2013 10:29 pm

I'm planning on setting up a repository.
Awesome. Could I have the patched source you used to make the binary? I would also like to experiment under Arch ARM. Still having a heck of a time trying to get the patch to work the jack source i've downloaded. If I could start with your source that I know works, it would be greatly appreciated!
Does the Lexicon Omega have something like a class compliant setting/switch?
Unfortunately not. I'll do some investigating into the driver side of things and see what can be done then. Or switch to a different card. My goal is a build an audio rackmount on-stage/live/in-studio computer for fx processing and MIDI sample triggering. I've got a client that's very interested in it, and I've nearly exceeded their expectations already.(BTW, I'm i2productions for linuxmusicians. I've hijacked your thread over there for the past week, and other people are showing interest in the platform!)
How awesome is that, Ardour on the RPi!
More awesome than I could have imagined. I was planning on basing this unit of a much less involved DAW, but Ardour and the Rpi have exceeded expectations on this one!
Ok cool, Turbo mode makes my setup unstable so I'm running at 950MHz now.
Amazing how different a bunch of boards can be that are supposed to be "all the same"! I've overclocked from day one in Raspian with 0 issues. Though I've had serious issues trying to overlock with Arch ARM.

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
Contact: Website

Re: RPi and real-time, low-latency audio

Wed Feb 13, 2013 9:03 am

akavir wrote:Awesome. Could I have the patched source you used to make the binary? I would also like to experiment under Arch ARM. Still having a heck of a time trying to get the patch to work the jack source i've downloaded. If I could start with your source that I know works, it would be greatly appreciated!
Jack1:

Code: Select all

wget http://jackaudio.org/downloads/jack-audio-connection-kit-0.121.3.tar.gz
wget https://github.com/AutoStatic/jack-armel/raw/master/jack1_stable_armel.diff
tar zxvf jack-audio-connection-kit-0.121.3.tar.gz
cd jack-audio-connection-kit-0.121.3
patch -p1 -i ../jack1_stable_armel.diff
Jack2:

Code: Select all

wget https://dl.dropbox.com/u/28869550/jack-1.9.9.5.tar.bz2
wget https://github.com/AutoStatic/jack-armel/raw/master/jack2_armel.diff
tar jxvf jack-1.9.9.5.tar.bz2
cd jack-1.9.9.5
patch -p1 -i ../jack2_armel.diff
akavir wrote:Unfortunately not. I'll do some investigating into the driver side of things and see what can be done then. Or switch to a different card. My goal is a build an audio rackmount on-stage/live/in-studio computer for fx processing and MIDI sample triggering.
Should be feasible as long as the fx aren't too heavy on CPU :)
akavir wrote:I've got a client that's very interested in it, and I've nearly exceeded their expectations already.(BTW, I'm i2productions for linuxmusicians. I've hijacked your thread over there for the past week, and other people are showing interest in the platform!)
No problem, I'll check out the thread and chime in again :)
akavir wrote:Amazing how different a bunch of boards can be that are supposed to be "all the same"! I've overclocked from day one in Raspian with 0 issues. Though I've had serious issues trying to overlock with Arch ARM.
I should look into it a bit more. What setting for core_freq are you using? guitarix segfaults after a while when I use Turbo mode. Could be the GUI but I've got a patch for running guitarix headless (well, more or less) so maybe that does work better with Turbo mode enabled.
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/

akavir
Posts: 13
Joined: Tue Feb 12, 2013 5:02 am

Re: RPi and real-time, low-latency audio

Thu Feb 14, 2013 12:01 am

Thanks for all the source links. I have also now tested both your JACK1 and JACK2 binaries and they both WORK LIKE A CHARM! Also, I figure how to start my Lexicon Omega in full duplex. First off I have to completely disable the ethernet, disabling turbo is not enough(I'm not using a powered hub, didn't think it would make a difference since the Omega has it's own power supply, but will try soon.) The Omega is capable of 4 simulateous inputs of analog recording and 2 outs. It seems that I can't get more than a total of 4. If I set JACK to start with only 2in and 2 outs it's just fine. Also with 4 ins capture only fine. But 4ins/2outs simultaneous seems to be too much for the USB, and will sometimes freeze the pi(again will try powered hub.) I'm a happy guy. It would be nice to have all ins and outs working, but this will give me everything I need, and my client is fine with 2 ins/outs.

A BIG THANK YOU TO AUTOSTATIC!!! YOU, AND TALENTED PROGRAMMERS HAVE MADE THIS ALL POSSIBLE!!

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
Contact: Website

Re: RPi and real-time, low-latency audio

Thu Feb 14, 2013 7:19 pm

akavir wrote:First off I have to completely disable the ethernet, disabling turbo is not enough(I'm not using a powered hub, didn't think it would make a difference since the Omega has it's own power supply, but will try soon.)
How did you disable it? By unbinding the driver?
akavir wrote:The Omega is capable of 4 simulateous inputs of analog recording and 2 outs. It seems that I can't get more than a total of 4. If I set JACK to start with only 2in and 2 outs it's just fine. Also with 4 ins capture only fine. But 4ins/2outs simultaneous seems to be too much for the USB, and will sometimes freeze the pi(again will try powered hub.)
Great find! Setting it up like this actually equals to a class compliant set-up. I'll add this to the Wiki page. What sample rate are you using?
akavir wrote:A BIG THANK YOU TO AUTOSTATIC!!! YOU, AND TALENTED PROGRAMMERS HAVE MADE THIS ALL POSSIBLE!!
You're welcome. All the puzzle pieces were there, I just finished most of the puzzle. Well, a few pieces are still missing but we'll find those too :)
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/

akavir
Posts: 13
Joined: Tue Feb 12, 2013 5:02 am

Re: RPi and real-time, low-latency audio

Thu Feb 14, 2013 7:44 pm

AutoStatic wrote:How did you disable it? By unbinding the driver?
Yes. echo -n "1-1.1:1.0" | sudo tee /sys/bus/usb/drivers/smsc95xx/unbind
AutoStatic wrote:What sample rate are you using?
44100

Yesterday afternoon everything with my pi was almost exactly the way I wanted it to be. Now it's all taken a turn for the worse and I have no idea why. The pi is seemly choosing when it wants to start JACK. Sometimes I fire it up and it works for a bit, but most of the time now it just crashes as soon as it starts with seemingly no real error message. At the same time it did actually connect to all 4 ins/2outs for about 2 minutes before the pi froze as I was changing modules in guitarix. Definitely not out of the water yet.

Also I have had absolutely 0 luck compiling JACK on ARCH. I was able to straight up compile your sources and patch here on raspian, but no matter what I do Arch seems to refuse to build JACK with ALSA support. In fact the only thing it will build support for is OSS. Anyway, still a multitude of bugs to be worked out, but I'm getting there on my project.

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
Contact: Website

Re: RPi and real-time, low-latency audio

Sat Feb 16, 2013 2:25 pm

I've been asked to create an img file of my RPi setup. I'm a bit reluctant to this (I'm actually opposed to these kind of things as a DIY person) but if more people are interested I could take a stab at it. Such an image would comprise:
  • Working jackd installation, most probably Jack1 as I use that myself.
  • Preconfigured optimizations (nic in non-turbo mode, disabled services, overclocked by default, performance CPU governor).
  • Option to set USB controller to USB1.1 mode.
Let me know if you're interested.
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
Contact: Website

Re: RPi and real-time, low-latency audio

Sat Feb 16, 2013 2:31 pm

I've found reports on the net that people are using the nrpacks option for the snd-usb-audio kernel module to improve the sound and/or performance of the USB audio interface. Does anyone here have experience with that? If I have to believe the USB audio guru (Clemens Ladisch) you don't need to set this option: http://lists.linuxaudio.org/pipermail/l ... 66765.html
Which makes me wonder if using this option does anything at all.
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/

akavir
Posts: 13
Joined: Tue Feb 12, 2013 5:02 am

Re: RPi and real-time, low-latency audio

Sun Feb 17, 2013 2:34 am

Even though I'm working on 3 different distros on the pi right now trying different things out, I would love to try an img of your working setup. I'd like to see if I'm just missing something with the little tweaks.

Just because it's a DIY project, it's still nice to give people starting points!

audioplastic
Posts: 12
Joined: Tue Jan 15, 2013 12:51 am
Location: Cambridge

Re: RPi and real-time, low-latency audio

Wed Feb 20, 2013 1:28 am

Just found this thread and I'm extremely interested! I'm working on an embedded device. I need to process 4 inputs in real time with a stereo output. Any news on operating the full 6 channels simultaneously?

akavir
Posts: 13
Joined: Tue Feb 12, 2013 5:02 am

Re: RPi and real-time, low-latency audio

Wed Feb 20, 2013 4:40 am

I'm still stugling to get 2in/2out duplex to work correctly. At least as far as JACK is concerned. I think it may be achieved from a command line interface. The less overhead you give the system, the better chance you have. I got JACK to load my interface with 4in/2outs, only once, and it crashed as soon as I tried to load any JACK enabled app. Still playing around. If you end up with something cool, post it here!

Here's another extremely important tip I learned this week. I was getting this awesome distortion in my audio, no matter what i did, and whether or not it was capture or playback. I found out it had to do with my wireless Logitech usb dongle for keyboard/mouse. Also another logitech just wireless mouse I have. As soon as I pull the dongle, the audio becomes as clear as one would expect. Just a general tip for all working with the Rpi and audio. If you're getting distortion, check that first! I spent almost a week trying to track down the problem internally, and all it took was pulling the dongle(Though I supposed this means I need a wired key/mouse for til further testing is done)!

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
Contact: Website

Re: RPi and real-time, low-latency audio

Wed Feb 20, 2013 8:59 am

For the record and maybe I should add this to the Wiki article too, I'm not using a DE (so basically no X). I'm connecting to the RPi over SSH (with X forwarding enabled) and then I start up my apps from the terminal. If the application needs X (like guitarix) it uses X on the machine from which I connect over SSH. Also I don't use any other peripherals, so no WiFi dongles, no wireless keyboards/mice, I need as much USB bandwidth as possible.
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/

audioplastic
Posts: 12
Joined: Tue Jan 15, 2013 12:51 am
Location: Cambridge

Re: RPi and real-time, low-latency audio

Wed Feb 20, 2013 11:40 am

Hi again. I'm considering using this as the core for my embedded project to keep size down, as I need to build a custom analogue input stage anyhow ...

http://www.minidsp.com/products/usb-aud ... sbstreamer

It has a maximum of 10 in / 10 out. In theory, should this be configurable as 4-in, 2-out with the RPi forced into USB 1.1 mode?

An alternative would be to stack two of these to obtain 4 input channels . . .

http://www.minidsp.com/products/usb-aud ... nistreamer

With which version would I be most likely to have success? I must admit that I'm fairly new to the inner workings of linux audio.

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
Contact: Website

Re: RPi and real-time, low-latency audio

Wed Feb 20, 2013 12:55 pm

audioplastic wrote:Hi again. I'm considering using this as the core for my embedded project to keep size down, as I need to build a custom analogue input stage anyhow ...

http://www.minidsp.com/products/usb-aud ... sbstreamer

It has a maximum of 10 in / 10 out. In theory, should this be configurable as 4-in, 2-out with the RPi forced into USB 1.1 mode?
No. It's a USB2 audio interface so it won't work on an USB port that only does USB1.1 Also the USBstreamer is an USB2 device that needs a Windows driver so I highly doubt if it will work with Linux.
audioplastic wrote:An alternative would be to stack two of these to obtain 4 input channels . . .

http://www.minidsp.com/products/usb-aud ... nistreamer

With which version would I be most likely to have success? I must admit that I'm fairly new to the inner workings of linux audio.
The latter as the ministreamer is a class compliant USB1 device so it should work ootb on the RPi. I wonder though if two of these will work (4 input channels) because they share the same host controller. So if you use either 4 input channels on a single device or 2x2 input channels on two separate devices, the throughput is the same. And a Lexicon Omega doesn't work reliably (yet) unless you force it to use 2 input channels instead of 4.
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/

akavir
Posts: 13
Joined: Tue Feb 12, 2013 5:02 am

Re: RPi and real-time, low-latency audio

Wed Feb 20, 2013 4:45 pm

AutoStatic wrote: And a Lexicon Omega doesn't work reliably (yet) unless you force it to use 2 input channels instead of 4.
And it still doesn't work "reliably" in Duplex. Still crashes after a few minutes of serious JACK throughput.

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
Contact: Website

Re: RPi and real-time, low-latency audio

Sun Mar 03, 2013 8:47 pm

The Wiki has had some updates. I'm also in the process of packaging some newer versions of music software for the RPi and thinking about setting up a repository. Would anyone be interested in such an audio repository?
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/

Elskayann
Posts: 1
Joined: Fri Mar 08, 2013 9:59 pm

Re: RPi and real-time, low-latency audio

Fri Mar 08, 2013 10:01 pm

Yes Autostatic it would be great to have a repo with the audio software for the Pi. Your wiki is already of a great help. Thanks!!

toxibunny
Posts: 1382
Joined: Thu Aug 18, 2011 9:21 pm

Re: RPi and real-time, low-latency audio

Sat Mar 09, 2013 11:47 pm

Yes please!
note: I may or may not know what I'm talking about...

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
Contact: Website

Re: RPi and real-time, low-latency audio

Tue Mar 12, 2013 8:49 pm

Repository has been created. Add it with:

Code: Select all

sudo -i
wget -O - http://rpi.autostatic.com/autostatic.gpg.key|apt-key add -
wget -O /etc/apt/sources.list.d/autostatic-audio-raspbian.list http://rpi.autostatic.com/autostatic-audio-raspbian.list
apt-get update
At the moment the repo contains guitarix 0.25.2, jackd1 0.121.3 and jackd2 1.9.8 (the latter two patched for ARM). This is more or less a personal repo so I'll only add stuff I really need myself. You can do package requests of course but I can't guarantee they'll be honored.
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
Contact: Website

Re: RPi and real-time, low-latency audio

Sun Mar 24, 2013 2:45 pm

So what can you do with this stuff?

Virtual guitar amplifier with guitarix:
The Infinite Repeat - Bow Down

Drum sampler with jalv and drumkv1:
Image
Image
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/

vmsda
Posts: 32
Joined: Tue Mar 12, 2013 5:02 pm

Re: RPi and real-time, low-latency audio

Tue Mar 26, 2013 9:42 pm

If I do everything the wiki suggests as far as usb audio is concerned, do I stand a chance of playing my 192khz/24bit downloads, or is this type of throughput just too much for the Pi?
Samsung 900X, Ubuntu 12.04 host, VirtualBox, Windows 7 guest.
Raspberry Pi running 2013-02-09-wheezy-raspbian.img; Edimax EW-7811Un 802.11b/g/n adapter; Plugable USB2.0 4-port Hub.

User avatar
AutoStatic
Posts: 326
Joined: Tue Jan 01, 2013 10:27 pm
Contact: Website

Re: RPi and real-time, low-latency audio

Tue Mar 26, 2013 10:40 pm

vmsda wrote:If I do everything the wiki suggests as far as usb audio is concerned, do I stand a chance of playing my 192khz/24bit downloads, or is this type of throughput just too much for the Pi?
Yes it is. Switching to USB1.1 mode disables the ability to use higher sample rates than 96kHz.
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
RPi and audio blog: https://autostatic.com/tag/raspberrypi/

Return to “Graphics, sound and multimedia”