lime icon indicating copy to clipboard operation
lime copied to clipboard

Add AudioSource.latency

Open ACrazyTown opened this issue 11 months ago • 4 comments

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 https://github.com/openfl/lime/pull/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.

ACrazyTown avatar Jan 22 '25 22:01 ACrazyTown

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").

MAJigsaw77 avatar Jan 23 '25 03:01 MAJigsaw77

@mcagabe19 @MAJigsaw77 The native C++ functions will return null if LIME_OPENALSOFT is not defined. This is later checked on the Haxe side: https://github.com/openfl/lime/blob/3f9041ab7d63c7c1cbc397dc482dd8cd2a0e7401/src/lime/_internal/backend/native/NativeAudioSource.hx#L592-L599 Is that not enough?

ACrazyTown avatar Jan 23 '25 08:01 ACrazyTown

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

https://github.com/openfl/lime/blob/3f9041ab7d63c7c1cbc397dc482dd8cd2a0e7401/src/lime/_internal/backend/native/NativeAudioSource.hx#L592-L599

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.

MAJigsaw77 avatar Jan 23 '25 08:01 MAJigsaw77

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 https://github.com/openfl/lime/pull/1912 so the backend specific functions can be hidden behind a proper conditional

ACrazyTown avatar Jul 16 '25 11:07 ACrazyTown