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 10:46 am

rpad wrote: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?
When you think about this seems indeed quite odd.
rpad wrote: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. 40MHz 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.
Probably all true, I'm still reading in on the innards of the Raspberry Pi and how these relate to audio performance.
rpad wrote:Hard to believe this does not work, but it looks like a bug in either the driver or jackd.
I'll do some more tests, also with plain ALSA, and report back.
rpad wrote:(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.)
Thanks and I'm with you, going to dig a bit deeper to try figuring out why JACK doesn't work properly with the onboard audio.
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 11:13 am

rpad wrote: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.
Try decreasing the JACK buffersize with for instance:

Code: Select all

jack_bufsize 1024
In my case this eliminates the choppiness.
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 11:38 am

AutoStatic wrote:Try decreasing the JACK buffersize with for instance:

Code: Select all

jack_bufsize 1024
In my case this eliminates the choppiness.
OK, this works for me too. I have to admit I didn't know this command existed.

However, there is something odd going on here. After I start jackd with

Code: Select all

jackd -P85 -p16 -t2000 -d alsa -P -p 1024 -r 44100 &
the default jack_bufsize is reported as

Code: Select all

pi@raspberrypi ~ $ jack_bufsize 
1024
Audio played at this point with alsaplayer -o jack is choppy. The odd thing is if I call

Code: Select all

jack_bufsize 1024
the choppiness disappears.

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 11:58 am

Yeah it's weird but it seems to work around the choppiness issue. In all my RPi scripts that invoke JACKified software I use jack_bufsize (to actually reset it to the same value) to reinitialize the JACK engine. This also applies to USB interfaces so the choppiness might be JACK related.
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 12:00 pm

Also odd: If I plug in my usb midi keyboard, the choppiness re-appears until I run jack_bufsize again. And while the audio is choppy, it is also slowed down noticeably. It sounds like the audio is over-running and playback is paused until some resource becomes available. I would have thought this should appear as an xrun in my console running jackd ... maybe this part of the new kernel patch is not working?

IDE
Posts: 52
Joined: Fri Jan 13, 2012 12:28 am
Contact: Website

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

Tue May 28, 2013 5:08 pm

omg thank you for this thread. spot on for what i was looking for.

I have an Audio4 sound card and I'd be interested to work with xwax.

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

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

Wed May 29, 2013 9:03 am

rpad wrote:Also odd: If I plug in my usb midi keyboard, the choppiness re-appears until I run jack_bufsize again. And while the audio is choppy, it is also slowed down noticeably. It sounds like the audio is over-running and playback is paused until some resource becomes available. I would have thought this should appear as an xrun in my console running jackd ... maybe this part of the new kernel patch is not working?
Or maybe it could be related to the fact that the RPi has no RTC? Just a shot in the dark though. JACK uses a clocksource and since the RPi doesn't have a hardware one things might get out of sync.
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

Wed May 29, 2013 10:26 am

I think the kernel provides an accurate clock anyway; the lack of RTC just means there is no way to know the absolute time when the PI is powered on.

If I understand you correctly you were able to reproduce the stuttering audio too - and the jack_bufsize workaround fixed it for both of us.

Do you have to use jack_bufsize to prevent similar problems with USB audio? If so this points to the bug being more likely in jackd than the new kernel driver for the onboard audio.

My current stab in the dark guess is that the new kernel ALSA driver is providing a fixed length DMA buffer, where other ALSA drivers would allow this to very. Just a guess as I dont know enough about either jack or ALSA. If this is so then the driver should be modified to accept different DMA buffer lengths?

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

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

Wed May 29, 2013 10:43 am

rpad wrote:I think the kernel provides an accurate clock anyway; the lack of RTC just means there is no way to know the absolute time when the PI is powered on.
Yeah, that's actually true.
rpad wrote:If I understand you correctly you were able to reproduce the stuttering audio too - and the jack_bufsize workaround fixed it for both of us.
Yes.
rpad wrote:Do you have to use jack_bufsize to prevent similar problems with USB audio? If so this points to the bug being more likely in jackd than the new kernel driver for the onboard audio.
Same with USB audio yes, I also use jack_bufsize to prevent choppiness. But I highly doubt if it's JACK. I've been using JACK for years on a wide variety of hardware and I've never ran into issues like this.
rpad wrote:My current stab in the dark guess is that the new kernel ALSA driver is providing a fixed length DMA buffer, where other ALSA drivers would allow this to very.
I've had this issue ever since I've seriously started using my RPi (December 2012) so I think it is unrelated to the new driver. Unfortunately the default kernel doesn't create threaded IRQs (which is weird because it's a PREEMPT kernel but somehow the whole irq section of the kernel config seems to be missing) otherwise I could have taken a look on that level too, maybe elevating certain IRQ threads would help.
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 Jun 03, 2013 10:40 am

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/

emmef
Posts: 1
Joined: Mon Jun 03, 2013 5:52 pm

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

Mon Jun 03, 2013 6:07 pm

My impression is that setting the kernel timer to 1000Hz (instead of 100Hz) might improve stable and low-latency audio handling. It would cost some extra idle CPU/power use but when the Pi is used for DSP that shouldn't be a problem ;)

Does anyone know if my impression is correct?

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

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

Tue Jun 04, 2013 8:34 am

emmef wrote:My impression is that setting the kernel timer to 1000Hz (instead of 100Hz) might improve stable and low-latency audio handling. It would cost some extra idle CPU/power use but when the Pi is used for DSP that shouldn't be a problem ;)

Does anyone know if my impression is correct?
The kernel config has CONFIG_NO_HZ=y and that should work ok for low-latency audio handling. Not sure how this relates to CONFIG_HZ though. I've done a little check and I think the kernel timer interrupt frequency is ok:

Code: Select all

pi@jj-rpi ~/bin $ ./frequency-test 
kernel timer interrupt frequency is approx. 4016 Hz or higher
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/

rogera
Posts: 2
Joined: Wed Jun 05, 2013 8:26 am

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

Wed Jun 05, 2013 8:46 am

Hi

Just watched your video - great work!

I am starting a project to try to use Raspberry Pi as a small pipe organ synthesiser using fluidsynth and soundfonts.
I see that Raspyfi has been released with an audio bug fix for streaming audio, still in beta but version 1.0 is expected soon. I wondered whether this would fix the problems mentioned above of drop out, pops etc?
Has you tried this or run amsynth with Raspyfi at all.

Could you tell me what usb audio output sound card you used?

Thanks
rogera

rogera
Posts: 2
Joined: Wed Jun 05, 2013 8:26 am

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

Wed Jun 05, 2013 8:52 am

Sorry, should have given the link

http://www.raspyfi.com/raspberry-pi-usb-audio-fix/

rogera

Vanfanel
Posts: 433
Joined: Sat Aug 18, 2012 5:58 pm

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

Wed Jun 05, 2013 2:04 pm

Have you guys seen this?

http://martinezjavier.wordpress.com/201 ... sa-driver/

Native mmap support is already on the latest Raspbian image. Wasn't that the main problem with jack the Pi?

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

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

Wed Jun 05, 2013 2:47 pm

Hi rogera,

The audio bug fix is the so-called fiq_split patch. I guess we'll have to wait for that fix to make it into Raspbian, or maybe it's already there, not sure. Afaik this patch fixes issues with USB2.0 interfaces and I've only tested USB1.1 interfaces so far. I could test the patch but at the moment I don't have much time to do so. Same goes for testing Raspyfi.
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

Wed Jun 05, 2013 2:50 pm

Vanfanel wrote:Have you guys seen this?

http://martinezjavier.wordpress.com/201 ... sa-driver/
Hi Vanfanel, yup: http://www.raspberrypi.org/phpBB3/viewt ... 16#p340016
Vanfanel wrote:Native mmap support is already on the latest Raspbian image. Wasn't that the main problem with jack the Pi?
Yes, it was one of the main problems together with the use of packed structs in the JACK source code. Both have been resolved but the onboard audio still doesn't play nice with JACK.
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/

anwe79
Posts: 26
Joined: Sat Oct 08, 2011 10:30 pm

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

Sat Jun 15, 2013 12:56 pm

Thanks for the help AutoStatic and others. I'd given up on Jackd on the Pi for a while, but now I'm up and running.
I got the source of jackd from debian experimental, (which contains a patch to disable the problematic code), disabled dbus in the config and built it with dpkg-buildpackage. It was quite straightforward really.I also filed a bug report to Raspbian since I couldn't find one on this issue.

On to other problems; I'm using an el-cheapo USB card for testing purposes, but can't get duplex going without issues. Inputs or outputs only work ok, but duplex just ends in lots of xruns. It kindof works with the -s option to the alsa backend, but audio is quite bad then, with intermittent crackle.

I'm not sure if it's a driver issue or if it's to do with the environment on the Pi. (The card is listed as a CM109 in lsusb, uses the CM109/snd_usb_audio driver, and looks a lot like the "HF209-B" from this site:https://sites.google.com/site/bifferboa ... ound-cards.)

It was dirt cheap so no major loss, but I need to find something that works well with duplex and jackd (and hopefully doesn't cost an arm and a leg).

Any suggestions of a USB card that works well with Jackd and duplex on the Pi?
Maybe I should start another thread about it?

/Andreas

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

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

Sat Jun 15, 2013 6:47 pm

anwe79 wrote:I'm not sure if it's a driver issue or if it's to do with the environment on the Pi. (The card is listed as a CM109 in lsusb, uses the CM109/snd_usb_audio driver, and looks a lot like the "HF209-B" from this site:https://sites.google.com/site/bifferboa ... ound-cards.)
I'm using a similar card and duplex works fine. What are your JACK settings?
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/

jacob
Posts: 1
Joined: Sun Aug 18, 2013 3:22 am
Location: Wellington, New Zealand

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

Mon Aug 19, 2013 9:30 am

One thing I note gives me a significate performance bost restricting the number of audio channels in use. For example, my jackd init parameters look like:

jackd -R -P70 -p16 -t2000 -d alsa -dhw:0 -p 128 -n 3 -r 44100 --shorts -i1 -o2

The USB audio interface I'm using it a guitar effects processor (Zoom G2.1Nu), which presents stereo in/stereo out, but the jack ALSA options '-i1 -o2' restricts this to mono in/stereo out, and stability is much improved

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

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

Mon Aug 19, 2013 1:02 pm

Never thought about this actually. Thanks for the tip.
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/

rbn
Posts: 143
Joined: Tue Dec 27, 2011 8:32 pm
Location: Near Peterborough
Contact: Website

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

Wed Sep 18, 2013 3:51 pm

Hi
I have a 256Mb model B Pi and I am trying to work through your setup. I have installed jack1 OK from the added repository, and am trying to use a UA-25 for the audio usb device. However the Pi does not seem to see this. I see references to it as the Pi boots, but lsusb doesn't see it and jack can't find it. What am I missing to configure it? I have put the step into cmdline.txt to forece usb1.1 mode (dwc_otg.speed=1) and also the step to enable usb audio to be the default setting in alsa-base.conf

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

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

Wed Sep 18, 2013 6:04 pm

rbn wrote:Hi
I have a 256Mb model B Pi and I am trying to work through your setup. I have installed jack1 OK from the added repository, and am trying to use a UA-25 for the audio usb device. However the Pi does not seem to see this. I see references to it as the Pi boots, but lsusb doesn't see it and jack can't find it. What am I missing to configure it? I have put the step into cmdline.txt to forece usb1.1 mode (dwc_otg.speed=1) and also the step to enable usb audio to be the default setting in alsa-base.conf
Do the leds on your UA-25 light up? What are you using to power your RPi?
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/

rbn
Posts: 143
Joined: Tue Dec 27, 2011 8:32 pm
Location: Near Peterborough
Contact: Website

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

Thu Sep 19, 2013 8:17 am

1.2A 5v supply. They don't light

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

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

Thu Sep 19, 2013 5:57 pm

rbn wrote:1.2A 5v supply. They don't light
Then your UA-25 probably doesn't get enough power. I've got an UA-25 too and I'm using it with a powered USB hub and a power supply of over 3.5A.
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”