I have successfully setup pulse audio asynchronous playback stream using pa_stream_connect_playback()
call.
Now I am facing a problem of synchronizing my UI with the playback. In my render loop I need to estimate current playing sample from the beginning of playback:
loop {
let current_sample = ???
// handle inputs and render UI synchronized to current_sample
}
I tried to use pa_stream_get_timing_info().read_index
but it jumps in big increments.
What is the best strategy to have good synchronization?
Should I query pa_stream_get_timing_info
on every frame and use current latency as a compensation for current clock read instead? This gets especially complicated in the presence of pa_stream_cork
calls and occasional underflows.
Is there a more precise way?
I have discovered the pa_stream_get_time
function. Its implementation has all the details I need.