PortAudio / portaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.
Other
1.39k stars 291 forks source link

JACK: do not subtract buffer size from port latency #886

Closed stefanha closed 2 months ago

stefanha commented 4 months ago

The latency calculation subtracts the size of one buffer from JACK's port latency value. I suspect this adjustment was made so that jackd's "asynchronous mode" appears to have the user's requested latency value even though jackd adds one extra buffer, thus increasing the real latency.

When jackd runs in "synchronous mode" or the more recent pipewire-jack implementation is used, PortAudio reports incorrect latency values of 0 seconds because the latency is exactly one buffer.

Fix the calculation to produce the real latency.

RossBencina commented 4 months ago

related #641

stefanha commented 4 months ago

@RossBencina I have pushed a new commit that replaces the deprecated jack_port_get_latency() API with jack_port_get_latency_range() in order to fix #641.

stefanha commented 4 months ago

Hi @RossBencina, please let me know if you have any comments. Thanks!

RossBencina commented 3 months ago

I've assigned this to myself since I need to put in the time to review our specifications and think about why this is correct.

RossBencina commented 2 months ago

@stefanha sorry about the delay.

I've checked the calculations against our documentation (https://github.com/PortAudio/portaudio/wiki/BufferingLatencyAndTimingImplementationGuidelines) and Phil and I have agreed that this looks like the correct fix, given that the old code was computing zero latency in both the input and output cases.

One more thing: I'm unclear about the JACK "asynchronous mode" vs "synchronous mode" thing. Is it the case that PortAudio/JACK no longer ever uses "asynchronous mode" under any circumstances?

stefanha commented 2 months ago

One more thing: I'm unclear about the JACK "asynchronous mode" vs "synchronous mode" thing. Is it the case that PortAudio/JACK no longer ever uses "asynchronous mode" under any circumstances?

@RossBencina Thanks for taking a look at this! The latency reported by the PortAudio JACK host API was incorrect in both modes. Asynchronous mode adds latency, so it is not accurate to subtract the extra latency. I believe the the state of JACK implementations is:

Either way, the latency reported by the JACK host API was not accurate and this fix will ensure that the real latency is reported.

RossBencina commented 2 months ago

Merged! Thank you!