jzpwood
Posts: 2
Joined: Sat Oct 12, 2019 3:15 pm

"Realtime" audio output using RPi?

Sat Oct 12, 2019 3:28 pm

I'm working on a project that will require some system to generate low latency (0-5ms RT) audio in response to SPI inputs.

I'll want to load short sound files into RAM, then manipulate the samples before sending them out on an audio bus.

I thought this should be fairly simple using the RPi platform, but I'm yet to find a straight answer or examples of where this has been done.

I was hoping there would be a simple C++ library where I can just shove samples into a buffer at regular intervals and let the Pi and a USB audio interface do the rest, but it seems that even getting HID audio devices to work is not trivial, let alone reducing the latency to acceptable levels.

Using an SPI audio codec might be an option, but I'm not sure if the Pi would be able to meet the timing requirements, and it seems a little over-complicated since I can do this whole thing in 5 minutes on windows, albeit without the SPI input.

Thanks all.

knute
Posts: 473
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: "Realtime" audio output using RPi?

Sat Oct 12, 2019 7:22 pm

Java has a very simple sound API that works just fine on a Pi. As to the 0-5ms latency I don't know. I think that would be affected by the USB sound card's buffering. In any case that is a really short time, even 1 cycle of 800hz tone takes 1.25ms. What are you using the sound for?

MikeDB
Posts: 85
Joined: Sun Oct 12, 2014 8:27 am

Re: "Realtime" audio output using RPi?

Sat Oct 12, 2019 7:52 pm

Just use a standard I2S codec for analogue in and out. You can edit the ALSA libraries to reduce the buffer sizes to 9 (but not 8) to minimize latency, or write your own as it's a simple interface to program and then you can set the buffer size to 1

jzpwood
Posts: 2
Joined: Sat Oct 12, 2019 3:15 pm

Re: "Realtime" audio output using RPi?

Sun Oct 13, 2019 10:49 am

knute wrote:
Sat Oct 12, 2019 7:22 pm
Java has a very simple sound API that works just fine on a Pi. As to the 0-5ms latency I don't know. I think that would be affected by the USB sound card's buffering. In any case that is a really short time, even 1 cycle of 800hz tone takes 1.25ms. What are you using the sound for?
I'm using it to create an electronic drum kit of sorts, so low latency is really crucial here. I know it can be done on windows, with a fast processor and low buffer size, but I'm thinking about going down an ARM Microcontroller route so I can respond in realtime without any interruptions from an OS.
MikeDB wrote: Just use a standard I2S codec for analogue in and out. You can edit the ALSA libraries to reduce the buffer sizes to 9 (but not 8) to minimize latency, or write your own as it's a simple interface to program and then you can set the buffer size to 1
That sounds like a good option, do all of the Pi models include I2S as standard on the GPIO pins?

User avatar
Burngate
Posts: 6013
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: "Realtime" audio output using RPi?

Mon Oct 14, 2019 10:08 am

jzpwood wrote:
Sun Oct 13, 2019 10:49 am
... I'm thinking about going down an ARM Microcontroller route so I can respond in realtime without any interruptions from an OS.
You do know that a Pi isn't a Microcontroller - it's a fully-fledged computer, running an operating system (usually Raspbian, but there are others - RISCOS is closer to what you want, but you could write your own)

Return to “General discussion”