Skip to content

Implement get_latency method for coreaudio on MacOS#119444

Open
mattbearman wants to merge 1 commit into
godotengine:masterfrom
mattbearman:fix-core-audio-get-latency
Open

Implement get_latency method for coreaudio on MacOS#119444
mattbearman wants to merge 1 commit into
godotengine:masterfrom
mattbearman:fix-core-audio-get-latency

Conversation

@mattbearman

@mattbearman mattbearman commented May 13, 2026

Copy link
Copy Markdown

What problem(s) does this PR solve?

Currently calling AudioServer.get_output_latency() on a Mac will always return 0, as the get_latency() function is not defined in the CoreAudio driver, so it falls back to the virtual function in audio_server.h, which just returns 0

This PR adds the get_latency() function in CoreAudio (for Mac only, other devices using CoreAudio, such as iOS, will still report 0 - I'll tackle that in a future PR)

I've tested this on a 2023 M3 MacBook Pro running MacOS 15, and a 2017 Intel MacBook Pro running MacOS 13, with a few different audio devices on each (built in speakers, headphones, USB interfaces), and the latency reported appeared correct in all instances

Additional information

The basis for the latency calculations came from this discussion on the JUCE framework forum, as well as the CoreAudio docs and my own experimentation

Regarding stream latency, in an ideal world when there are multiple streams we'd figure out which stream was currently being used, however I couldn't find a reliable way to do that. The approach here of using the maximum reported stream latency seems like a safe compromise, especially considering every single external audio device I tested reported a stream latency of zero anyway

In my testing only the built in audio devices actually report a stream latency, and they only ever have the one stream 🤷

AI disclosure

I didn't any AI used in the development of this

@Chaosus Chaosus added this to the 4.x milestone May 14, 2026
@mattbearman mattbearman force-pushed the fix-core-audio-get-latency branch from bc1e22a to 64f9395 Compare May 14, 2026 07:16
@mattbearman mattbearman marked this pull request as ready for review May 14, 2026 07:28
@mattbearman mattbearman requested a review from a team as a code owner May 14, 2026 07:28
@Ivorforce Ivorforce requested a review from a team May 14, 2026 08:07
@mattbearman mattbearman force-pushed the fix-core-audio-get-latency branch 3 times, most recently from 44f4a9e to ca1139f Compare July 2, 2026 20:26
@mattbearman mattbearman force-pushed the fix-core-audio-get-latency branch from ca1139f to ad4a7ee Compare July 2, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants