Skip to content

Add AudioSource.latency#1896

Open
ACrazyTown wants to merge 6 commits intoopenfl:8.4.0-devfrom
ACrazyTown:feat/get-sound-latency
Open

Add AudioSource.latency#1896
ACrazyTown wants to merge 6 commits intoopenfl:8.4.0-devfrom
ACrazyTown:feat/get-sound-latency

Conversation

@ACrazyTown
Copy link
Contributor

This PR adds a latency field to AudioSource that returns the estimated playback latency of the sound.

On native targets (that use OpenAL Soft) the same method from #1759 is used, although exposing it as a seperate field instead of applying it directly to the sound's time.

HTML5 uses AudioContext.baseLatency and AudioContext.outputLatency

In the case where it's not possible to query the playback latency (eg. Flash) 0 is returned.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS will give null since it uses mojoal instead if OpenAL SOFT.

@MAJigsaw77
Copy link
Contributor

iOS will give null since it uses mojoal instead if OpenAL SOFT.

@ACrazyTown Since some platforms might use mojoAl or something else for example, I'd suggest checking if the extension is supported first AL.isExtensionPresent("AL_SOFT_source_latency").

@ACrazyTown
Copy link
Contributor Author

@mcagabe19 @MAJigsaw77 The native C++ functions will return null if LIME_OPENALSOFT is not defined. This is later checked on the Haxe side:

public function getLatency():Float
{
var offsets = AL.getSourcedvSOFT(handle, AL.SEC_OFFSET_LATENCY_SOFT, 2);
if (offsets != null)
return offsets[1] * 1000;
return 0;
}

Is that not enough?

@MAJigsaw77
Copy link
Contributor

@mcagabe19 @MAJigsaw77 The native C++ functions will return null if LIME_OPENALSOFT is not defined. This is later checked on the Haxe side:

public function getLatency():Float
{
var offsets = AL.getSourcedvSOFT(handle, AL.SEC_OFFSET_LATENCY_SOFT, 2);
if (offsets != null)
return offsets[1] * 1000;
return 0;
}

Is that not enough?

It's not because openal soft can be there, but the platform might not support latency, in any case that check should make it fine if added.

@ACrazyTown
Copy link
Contributor Author

If it is problematic to add this to the AudioSource API (as Lime uses 3 different OpenAL backends depending on the configuration and only OpenAL Soft can query latency) would it be better to just reduce this to binding the necessary functions and exposing them in Haxe thru OpenALAudioContext or whatever? If so, would be nice to also review #1912 so the backend specific functions can be hidden behind a proper conditional

@ACrazyTown ACrazyTown changed the base branch from 8.3.0-Dev to develop October 19, 2025 11:06
@ACrazyTown ACrazyTown changed the base branch from develop to 8.4.0-dev November 4, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants