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

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

Sun May 05, 2013 7:41 pm

JulianBrooks wrote:My feeling is that there's a massive difference between people who are occasionally scaling upwards into overclocking and RPi's setup for audio usage where we want to be running flat-out all the time.
I'm running almost flat-out all the time (High overclock preset). I could go higher regarding arm_freq but from what I've understood it is best to stick to the settings raspi-config is proposing.
JulianBrooks wrote:Would anyone care to share their overclocking settings for experimentation (obviously at the users own risk)? Perhaps the whole config.txt would be super-helpful, certainly for me as the minimal image I've built my RPi on has nothing at all in that file atm.
Mine is here: https://github.com/AutoStatic/configs/b ... config.txt
But iirc I've made no manual changes, the config only reflects settings done by raspi-config.
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

Fri May 17, 2013 7:07 pm

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/

tom
Posts: 4
Joined: Thu May 23, 2013 2:05 pm

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

Thu May 23, 2013 2:17 pm

hi,
great info, audiostatic!
reading the posts, it seems that it can run as expected.
i've followed the instructions and i get to work an edirol ua1-ex.
however, if i listen carefully, there a small clicks now and then without seeing any xruns or the cpu being at max. where should i look further?
i'm using darkice to get audio recorded out of the pi. i've also tried jacktrip and get the same clicks. i would love to know if these clicks can made go away..
thanks

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

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

Thu May 23, 2013 8:04 pm

Hi Tom,

Try raising your Frames/Period setting, for streaming you don't need low latency I think. Try setting it reasonably high, like 2048. You're probably suffering from xruns while using the softmode option for JACK. What are your current JACK settings?

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/

tom
Posts: 4
Joined: Thu May 23, 2013 2:05 pm

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

Fri May 24, 2013 3:07 pm

hello Jeremy,

thanks for you answer. I already have a high periods/frame setting on both ends .. and see no x-runs.
I will do more test and post the results here!

best regards
Thomas

JulianBrooks
Posts: 35
Joined: Wed Mar 20, 2013 1:08 pm

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

Fri May 24, 2013 3:13 pm

Hey Jeremy,

Another overclocking question...

I notice you don't run turbomode (turbomode=0) and am wondering if it's better without and just have cpufreq at performance. I'm presuming that this stops turbomode still attempting to scale the cpu whereas performance is flat out. Is this a correct guess?

Cheers,

Julian

JulianBrooks
Posts: 35
Joined: Wed Mar 20, 2013 1:08 pm

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

Fri May 24, 2013 3:48 pm

Also -

I'm not sure how to get your startup script to work. Would you mind walking me through it please?

I tried adding the commands to /etc/rc.local but it ain't worked.

Cheers,

Julian

tom
Posts: 4
Joined: Thu May 23, 2013 2:05 pm

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

Sat May 25, 2013 5:14 pm

hi Jeremy,

i found out the problem happens early. I recorded on the RPi a source that is known to be click-less into a file (with edirol ua1-ex) and then analyze the file. the file seems to have the clicks, that always look similar in the spectrum.

here is some output of the system:

pi@raspberrypi ~ $ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
performance

(950)
-------
pi@raspberrypi ~ $ df -h | grep shm
tmpfs 128M 24M 105M 19% /run/shm
--------
pi@raspberrypi ~ $ cat /proc/asound/cards
0 [UA1EX ]: USB-Audio - UA-1EX
EDIROL UA-1EX at usb-bcm2708_usb-1.3, full speed
-------
pi@raspberrypi ~ $ jackd -p16 -t2000 -dalsa -dhw:0 -p1024 -n3 -r44100 -C
jackdmp 1.9.9
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2012 Grame.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
JACK server starting in realtime mode with priority 10
creating alsa driver ... -|hw:0|1024|3|44100|0|0|nomon|swmeter|-|32bit
control device hw:0
configuring for 44100Hz, period = 1024 frames (23.2 ms), buffer = 3 periods
ALSA: final selected sample format for capture: 16bit little-endian
ALSA: use 3 periods for capture

(no x-runs)
--------

pi@raspberrypi ~ $ jack_rec -f /run/shm/a_jack_rec.raw -d 10 -b 16 "system:capture_1" "system:capture_2"
disk thread finished
(no overruns)
--------

analyze file with baudline, results here
http://lowres.ch/rpi/normal.png
http://lowres.ch/rpi/click.png

(to check, the clicks can be heard for instance at around 950 ms and 1400 ms in this 10 sec sample)
http://lowres.ch/rpi/a_jack_rec_cd.raw
http://lowres.ch/rpi/a_jack_rec_cd.wav

i wonder why there can be clicks if no x-runs are reported and no resampling is involved. is this an issue of jack or of the audiointerface maybe? i used the ua1-ex on another machine (not via jack) but without similar issues. i am a bit stuck now..

thanks for the help,
Thomas

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

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

Sat May 25, 2013 7:26 pm

Try the jackd -S option:

Code: Select all

jackd -S -p16 -t2000 -dalsa -dhw:0 -p1024 -n3 -r44100 -C
This disables Jack2's asynchronous functionality and make it behave like good ol' Jack1. If you still get glitches you could try the ALSA -s softmode option:

Code: Select all

jackd -p16 -t2000 -dalsa -dhw:0 -p1024 -n3 -r44100 -C -s
Or maybe even a combination of both options.
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 May 25, 2013 7:30 pm

JulianBrooks wrote:Hey Jeremy,

Another overclocking question...

I notice you don't run turbomode (turbomode=0) and am wondering if it's better without and just have cpufreq at performance. I'm presuming that this stops turbomode still attempting to scale the cpu whereas performance is flat out. Is this a correct guess?

Cheers,

Julian
Hi Julian, not sure what you mean. Afaik the RPi's CPU will start scaling as soon as you overclock it.
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 May 25, 2013 7:41 pm

JulianBrooks wrote:Also -

I'm not sure how to get your startup script to work. Would you mind walking me through it please?

I tried adding the commands to /etc/rc.local but it ain't worked.

Cheers,

Julian
Which startup script are you referring to? The jackstart script? You probably can't just run it from rc.local. It will try running JACK as root which is inconvenient because then you have to run everything you want to connect using JACK as root. And JACK probably won't start, afaik starting JACK from init requires modifying a PAM setting.
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/

JulianBrooks
Posts: 35
Joined: Wed Mar 20, 2013 1:08 pm

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

Sat May 25, 2013 8:40 pm

Hi Julian, not sure what you mean. Afaik the RPi's CPU will start scaling as soon as you overclock it.
Hi Jeremy,

Sorry, not expressing myself very well...

I noticed from your config.txt that you had
forceturbo=0
. I'd also come across a post (sorry can't put my finger on the reference atm) where it was saying (paraphrased) that the RPi foundation had come up with turbomode=1 because so many people are overclocking and this is a way of keeping the warranty as turbomode still scales the cpu down when it's below a certain level of activity.

Whereas, for audio, we require the cpu to be running flat out because in the time it takes for the cpu to scale upwards our audio moment has already arrived (or gone with a crackle and a crunch).

So I was asking if my interpretation was correct that having forceturbo=0 is better for audio with cpufreq running the performance governor. Or perhaps I'm just plain missing what's really happening here (it does happen).

Hope that helps,

Julian

JulianBrooks
Posts: 35
Joined: Wed Mar 20, 2013 1:08 pm

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

Sat May 25, 2013 8:50 pm

Also - yes, it was the jackscript I was referring to (not thinking clearly yesterday obviously).

I spent a bit of time reading around and starting to get my head around startup scripts.

Still some work to do but getting it together...albeit slowly.

I'll be experimenting with them again in a day or so so will get back to you with any specific issues re jack etc if I can't figure it out.

In typical linux-style thinking "oh, Ill just do this" and expecting all to be fine 1st go is somewhat overly-optimistic. I need to dig a little deeper.

Cheers,

Julian

tom
Posts: 4
Joined: Thu May 23, 2013 2:05 pm

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

Sun May 26, 2013 2:48 pm

Hello again!

Still no luck here. close, but not good enough :)

i found other threads related in one or the other way here:
http://www.raspberrypi.org/phpBB3/viewt ... p?p=257512
https://github.com/raspberrypi/firmware/issues/19

for now i give up, after trying quite a few combinations of possibly important parameters to make it work as expected, stripped down to the minimum, with updated firmware, ext. powersupply, different RPis, different audio interfaces etc.
it was a bit of fun, and also hours and hours of hunting down weird behavior (..)

just to add that: i figured it records a different sound (with external audio interfaces), if the RCA is plugged in or not. as if it would be some analog thing.. not sure how come

greetings

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

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

Mon May 27, 2013 7:55 am

@tom, which audio interfaces did you try? And did you also try with Jack1? I haven't ran into these issues yet, I'm currently using the following interfaces: And the different sound depending on a RCA plug being connected or not, isn't that some kind of grounding issue?
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

Mon May 27, 2013 7:58 am

JulianBrooks wrote:I noticed from your config.txt that you had
forceturbo=0
. I'd also come across a post (sorry can't put my finger on the reference atm) where it was saying (paraphrased) that the RPi foundation had come up with turbomode=1 because so many people are overclocking and this is a way of keeping the warranty as turbomode still scales the cpu down when it's below a certain level of activity.

Whereas, for audio, we require the cpu to be running flat out because in the time it takes for the cpu to scale upwards our audio moment has already arrived (or gone with a crackle and a crunch).

So I was asking if my interpretation was correct that having forceturbo=0 is better for audio with cpufreq running the performance governor. Or perhaps I'm just plain missing what's really happening here (it does happen).

Hope that helps
It sure does, thanks. I have to dig up where I got setting this option to 0 from. At the moment you already know more about the forceturbo option then I do ;)
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

Mon May 27, 2013 9:10 am

JulianBrooks wrote:I'll be experimenting with them again in a day or so so will get back to you with any specific issues re jack etc if I can't figure it out.
No problem. Make sure though you're running JACK as the pi user (or any other normal user). If you use something like su -l username -c command in /etc/rc.local make sure you uncomment the following line in /etc/pam.d/su:

Code: Select all

#session    required   pam_limits.so
Otherwise JACK might fail to start due to insufficient permissions.
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/

rpad
Posts: 8
Joined: Mon May 27, 2013 7:26 pm

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

Mon May 27, 2013 7:40 pm

Hello,

I've been struggling all day getting jack to play nicely with the new mmap enabled alsa drivers.

After and rpi-update I can confirm that the alsa drivers are indeed using mmap. This seems to work fine.

And I've installed the patched jack1 as described at http://wiki.linuxaudio.org/wiki/raspberrypi.

So, I want to play with the newly mmap capable internal bcm2835 device, rather than having to use an external usbb soundcard. I think this will be a very popular scenario once the kernel update spreads around more generally. This also should also mitigate the usb problems which are carefully worked around on the linuxaudio site.

I'm starting jackd with

Code: Select all

jackd -P70 -p16 -t2000 -d alsa -P -p 1024 -r 44100 &
and it starts up nicely. However the audio output is very choppy and stutters a lot. I'm not seeing any xruns in qjackctl. I see this behaviour both at standard CPU speed, and overclocked to the max.

I've been playing around with options all afternoon but this thing has me beaten right now. Any suggestions would be gratefully received.

Can anyone give me a working jack1/jack2 invocation for the internal alsa diver?

Cheers!

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

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

Tue May 28, 2013 6:58 am

Hi rpad, try the ALSA softmode option (-s) and higher sample rates (the -r option at 48000, 88200 or maybe even 96000). I've had little succes with the onboard audio and JACK myself so far. Haven't really looked into it too because I'm ok with the USB interfaces I'm using.
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/

rpad
Posts: 8
Joined: Mon May 27, 2013 7:26 pm

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

Tue May 28, 2013 8:13 am

Thanks. I tried softmode and the 48k sample rate already, also I tried both jack1 and jack2, but the problem persists.

I'll try an even higher sample rate ... !

Given the newness of this kernel patch, I might be in terra incognita. However Javier Martinez did mention he had tested it with jack2. It definitely works fine with aplay -M in the non jack case.

It would be very appealing to work with the inboard audio and not have to use external usb sound card. I'm thinking a great lightweight synth could be just a usb midi keyboard and a pi ...

Cheers,

rpad
Posts: 8
Joined: Mon May 27, 2013 7:26 pm

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

Tue May 28, 2013 9:20 am

Update: higher sample rates and/or softmode make no difference. The audio is still choppy. Nothing obvious on the console output when I run jackd -v in the foreground either.

I don't have an /etc/asound.conf.

I wonder if this is a bug in the updated ALSA bcm2835 driver from Javier Martinez?

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

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

Tue May 28, 2013 9:34 am

...Or a result of the implementation of the onboard audio? I get the idea that the onboard audio just can't cope with real-time, low-latency audio. As for portability/weight, I'm currently using this USB interface and it works even at 48/48000*2 = 2ms of system latency: http://dx.com/p/virtual-5-1-surround-us ... card-22475
It's small, sounds a bit better (as it's 16bit), also has a mic input and runs well at lower latencies.
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

Tue May 28, 2013 9:59 am

From http://martinezjavier.wordpress.com/201 ... uote]Since hardware buffers can’t be directly mapped to user-space memory, an intermediate buffer is needed. This intermediate buffer is mapped to user-space so applications can store the audio samples there. Once user-space has finished writing the PCM samples they are pushed to VideoCore as vchiq messages.[/quote]So when using the onboard audio an extra buffer gets introduced. This is also probably why I can't set frames/period lower than 256:

Code: Select all

$ jackd -P84 -p32 -t2000 -d alsa -dhw:ALSA -p128 -n2 -r48000 -s -P &
[1] 5174
pi@jj-rpi ~ $ jackd 0.122.0
Copyright 2001-2009 Paul Davis, Stephane Letz, Jack O'Quinn, Torben Hohn and others.
jackd comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details

JACK compiled with System V SHM support.
loading driver ..
apparent rate = 48000
creating alsa driver ... hw:ALSA|-|128|2|48000|0|0|nomon|swmeter|soft-mode|32bit
configuring for 48000Hz, period = 128 frames (2.7 ms), buffer = 2 periods
ALSA: final selected sample format for playback: 16bit little-endian
ALSA: cannot set period size to 128 frames for playback
ALSA: cannot configure playback channel
cannot load driver module alsa
And for a responsive synth, drum or any other real-time audio application 256 frames/period doesn't really cut it.
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/

rpad
Posts: 8
Joined: Mon May 27, 2013 7:26 pm

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

Tue May 28, 2013 10:18 am

It seems -p1024 is the minimum value needed to avoid xruns. I agree the the intermediate buffer would appear to be the reason you cant go below -p256.

However, if the hardware couldn't cope with it then surely it would be a waste of time to do the work needed to update the kernel driver to support mmap?

As far as I understand the GPU handles the low level audio out, and the GPU is a pretty powerful beast. And the PWM processing is all done by the GPU, so it won't block the CPU. The issue was that it does not share address space with the CPU, which makes the mmap mode more tricky to implement. 40KHz PWM at 11 bits is never going to give as good audio quality signal as external USB, but the latency should be much less as it won't have to go through the USB subsystem. Hence your need for the -n 3 parameter when using an external sound card.

Hard to believe this does not work, but it looks like a bug in either the driver or jackd.

(BTW I really appreciate the work you've done in debugging the configuration for external USB ... I just anticipate the need to explain how to get jackd etc working with the internal sound as well. And its hard to believe that the hardware just wont support this mode of operation.)

rpad
Posts: 8
Joined: Mon May 27, 2013 7:26 pm

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

Tue May 28, 2013 10:43 am

OK, here's what I've found. Suppose I accept lots of latency, and so go with the following:

Code: Select all

pi@raspberrypi ~ $ jackd -C -R -d alsa -P -p 8192 -r44100
jackd 0.122.0
Copyright 2001-2009 Paul Davis, Stephane Letz, Jack O'Quinn, Torben Hohn and others.
jackd comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details

JACK compiled with System V SHM support.
loading driver ..
apparent rate = 44100
creating alsa driver ... hw:0|-|8192|2|44100|0|0|nomon|swmeter|-|32bit
control device hw:0
configuring for 44100Hz, period = 8192 frames (185.8 ms), buffer = 2 periods
ALSA: final selected sample format for playback: 16bit little-endian
ALSA: use 2 periods for playback
Now playback is much less choppy. But it is still choppy. It looks like this is some sort of buffer copying issue which is not being picked up as xruns by jackd (which is strange). That's as far as I have got with this.

Return to “Graphics, sound and multimedia”