[pulseaudio-discuss] how to get accurate stream latency information during underrun

Tanu Kaskinen tanuk at iki.fi
Sat Oct 7 17:35:44 UTC 2017


On Fri, 2017-09-29 at 11:46 +0200, Ludovic Guégan wrote:
> Hi everyone,
> 
> First, i am new to PulseAudio and the mailing list, so let me say it: Thank
> you all !
> 
> In the context of my application, it is important to accurately estimate
> the audio latency in order to synchronize the speaker output with some
> motor movements.
> 
> I used to query the audio latency using pa_stream_get_latency(), but the
> returned information does not seems to correspond to observed latency in
> the following situation:
> 
> When my application stops sending data (after the underflow event), the
> value returned by pa_stream_get_latency() stays constant and does not
> decrease.
> 
> When writing again data into the stream (long after the underflow event and
> without any cork/uncork operation), the sound is outputted to the speaker
> without the latency delay advertised by pa_stream_get_latency().
> 
> Since this is the first time i use the PulseAudio API, i might not
> understand correctly the purpose of pa_stream_get_latency() and I wonder
> what is the correct way to obtain the most accurate estimation of the
> latency ?

During an underrun you can't get exact latency information. When you
resume playing audio, a part of the device buffer may or may not get
rewritten, and it's not known in advance how much will be rewritten.

I recommend playing silence instead of playing nothing in your
application.

-- 
Tanu

https://www.patreon.com/tanuk


More information about the pulseaudio-discuss mailing list