[Portaudio] Reported latency

Erik Ronström erik.ronstrom at doremir.com
Mon Dec 7 17:48:41 EST 2015

Hi List,

(Apologies if this has been asked before, but I haven’t yet found an answer by searching the web)

I want to synchronize recorded audio with the track that was played back during recording. As far as I understand, this means offsetting the recorded audio by (inputLatency + outputLatency). The problem is that I cannot make sense of the latency values that PortAudio reports.

There seems to be four latency values of interest here: the suggested latency (set by PaStreamParameters), the ”actual” latency (as reported by PaStreamInfo), the difference between inputBufferAdcTime and outputBufferDacTime in PaStreamCallback, and finally, the ”real-world” actual latency.

To get the ”real-world” latency I recorded the backtrack playing from the computer speaker directly into the internal microphone, and looked at the audio file. I did this several times, and there is no measurable difference between the offsets of the different recordings.

These are the values of one test (input/output, rounded to ms):
Suggested Latency: 0.010 / 0.010
”Actual” Latency (PaStreamInfo): 0.059 / 0.020
Diff ADC/DAC: 0.035
”Real-world”: 0.044

And another:
Suggested Latency: 0.040 / 0.040
”Actual” Latency (PaStreamInfo): 0.233 / 0.061
Diff ADC/DAC: 0.110
”Real-world”: 0.157

I’m certainly not an expert on these matters, but to me the values reported by PaStreamInfo looks weird – the input latency cannot possibly be 59 ms when the recorded ”echo” starts 44 ms into the file?! Furthermore, I would have expected some sort of match between the PaStreamInfo latency values and the ADC/DAC diff. Here, I can see no obvious relation between them.

The ADC/DAC diff seems to be closest to the real-world values, and in the first example, I could have just accepted the 9 ms diff for the unknown latency which lays outside of the knowledge of PortAudio. But in that case, it wouldn’t have increased so much in the second example, I would rather have expected a constant addition.

How is this supposed to be done? Is it even possible to have the system roundtrip latency automatically calculated? (But even if the answer is no, the values reported by PaStreamInfo still don’t make any sense IMO!)

Best regards

PS. I’m on CoreAudio, Mac OS X 10.10

More information about the Portaudio mailing list