JohanK
Posts: 3
Joined: Mon Apr 18, 2016 12:49 pm

Audio delay when using pulseaudio and gstreamer

Mon Apr 18, 2016 1:06 pm

Hello everybody,

Currently i am working on a voice application for the raspberry pi. It is very important that the audio delay is as low as possible.

I'm using pulseaudio and gstreamer for this because pulseaudio includes some echocancellers, and these echo cancellers are mandatory for the voice application i am working on.

When using gstreamer and alsa, i get an acceptable delay of say 200 ms. I test this by connecting a USB microphone to the pi and sending the audio output of the microphone dierctly to the analog output (speaker output). The gstreamer commands are:

gst-launch-1.0 alsasrc device=plughw:camera ! alsasink sync=false

As mentioned earlier, the delay using alsa only is very acceptable. Next try is the same topology, but using pulseaudio.

gst-launch-1.0 pulsesrc ! pulsesink sync=false

Now, i have a delay of about one second, which way to high!
When googling for this problem, i found this page (https://www.freedesktop.org/wiki/Softwa ... cyControl/ ) were some tips are given to reduce the latency when using pulseaudio. I have implemented these tips by building gstreamer from source and modified pulssrc.c and pulsesink.c according to the documentation, but no improvement.

Can anyone give a hint about reducing the latency when using pulseaudio on raspberry pi. Help is greatly appriciated.

Regards,

JohanK

User avatar
yasriady
Posts: 27
Joined: Wed Apr 08, 2015 2:37 am
Location: Indonesia
Contact: Website

Re: Audio delay when using pulseaudio and gstreamer

Tue Aug 30, 2016 3:25 pm

Hi,

Any update about this issue?
I had similar matter, my Qt application with sound also got high latency.
It has about 1 second delay before playing.
And the sound yielded also not smooth.
If you have any workarround, please let me know.

Thanks a lot guys ..
/Ddy, Batam Island - Indonesia
MyRaspberryPi : Cross Compile, wxWidgets/C++ and Linux Journal at http://yasriady.blogspot.com

User avatar
flatmax
Posts: 336
Joined: Thu May 26, 2016 10:36 pm

Re: Audio delay when using pulseaudio and gstreamer

Wed Aug 31, 2016 9:04 am

If you need low latency audio, USB simply will not cut it. The UAC2 protocol requires blocked audio over USB.
You can probably bring the latency down by milliseconds by using GPIO soundcards.

You should be able to bring your gstreamer latency down to the order of 3 ms using alsa directly. I have clocked a GPIO soundcard down to 0.5 ms latency with low CPU load. As you crank up the CPU load, the required latency (block size) will increase.

To lower the audio latency, work out how to reduce the block size which ALSA is using.

You can also find the theoretical minimum latency using the latency alsa command, which you have to compile yourself for the Pi. Here is an example of using the latency command :
sudo ./latency -r 96000 -f S32_LE -p

Matt
Check the Ultra 2 sound card - use our shop instead of Amazon Europe (Amazon USA is live).
Sound card for the Raspberry Pi with inbuilt microphone : www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card

JohanK
Posts: 3
Joined: Mon Apr 18, 2016 12:49 pm

Re: Audio delay when using pulseaudio and gstreamer

Tue Oct 25, 2016 2:23 pm

We could not decrease the delay when using pulseaudio, so we switched back to alsa. We used the gstreamer line below to measure audio delay and it was around 250 ms, which is acceptable for us.

gst-launch-1.0 alsasrc device=plughw:camera ! alsasink sync=false

Return to “Graphics, sound and multimedia”