openfl / lime

A foundational Haxe framework for cross-platform development
https://lime.openfl.org/
MIT License
754 stars 371 forks source link

Increased accuracy when getting current audio time using OpenAL SOFT on native #1759

Open ninjamuffin99 opened 8 months ago

ninjamuffin99 commented 8 months ago

First time writing some bindings stuff! so feel free to tell me where I might need to clean up things. (i will clean up random whitespace / imports changes in the morning, bwah!)

wrote some bindings for al_get_sourcedv_soft and broadly followed along side the get_sourcefv stuff.

Using openal soft extension, can get a more precise time of the current playing audio.

Using ninjamuffin99/Lime-Time as sample / benchmark.

(the graphs here are sorta "right to left", and loop back to the bottom every 1000ms.) stats.update(FlxG.sound.music.time % 1000);

Before (60FPS)

image The timing of the audio 'plateaus' a bit for at least a frame, which may not seem like much, however this is an issue if you were to attempt to get the current playing time from BETWEEN a frame (say, on a keyboard input via an event listener) or on higher framerates (my demo is at 60fps)

After (60FPS)

image The values here are ALWAYS being incremented, due to higher precision. No 'plateau' effect.

ninjamuffin99 commented 8 months ago

cleaned up the whitespacing, and removed those unneeded public vars 🤝

mcagabe19 commented 4 months ago

openal soft gives null object referance at iOS IMG_3256

SomeGuyWhoLovesCoding commented 4 months ago

openal soft gives null object referance at iOS IMG_3256

Ikr? LMAO 🤣

MAJigsaw77 commented 4 months ago

Maybe a define needs to be added as openal soft is not on ios or lime should add support for openal soft on ios.

mcagabe19 commented 4 months ago

Maybe a define needs to be added as openal soft is not on ios or lime should add support for openal soft on ios.

OpenAL SOFT is not supported for static_link or for iOS itself so lime needed add support for it

joshtynjala commented 4 months ago

OpenAL SOFT is not supported for static_link or for iOS itself so lime needed add support for it

OpenAL SOFT is LGPL, so as I understand it, it must be dynamically linked.

mcagabe19 commented 4 months ago

OpenAL SOFT is LGPL, so as I understand it, it must be dynamically linked.

Makes sense, but still OpenAL SOFT needs iOS fixes/patches

ACrazyTown commented 2 months ago

Any updates on this?

MAJigsaw77 commented 2 months ago

Any updates on this?

iOS is currently broken

ACrazyTown commented 2 months ago

Any updates on this?

iOS is currently broken

Yeah I saw, I asked to see if there was any progress on fixing it and getting this ready to merge

Dimensionscape commented 2 months ago

We don't use OpenAL Soft when static linking. Instead we use MojoAL.

See: https://github.com/openfl/lime/blob/ca52db81efa10b1bd8c76e43c714faa9dbbc4c94/project/Build.xml#L26

From what I understand, apple devices have the proprietary licensed OpenAL embedded in the system api's(as opposed to OpenAL Soft) and we use that for those targets here: https://github.com/openfl/lime/blob/ca52db81efa10b1bd8c76e43c714faa9dbbc4c94/project/src/media/openal/OpenALBindings.cpp#L2

Any changes need to take into account for our different OpenAL backends.

ninjamuffin99 commented 2 months ago

hmmm I'll have to do lil tests to see how accurate mojoAL is then. It could be that the previous implemtation might work fine on iOS if it's accurate enough

Dimensionscape commented 2 months ago

It feels a little dirty having a function that only works for a specific AL backend, but it sounds like it should be something we can manage uniformly. ✌

ACrazyTown commented 3 weeks ago

Just wondering, would setCurrentTime also have to account for these changes? I see it references AL.BYTE_OFFSET like the old audio time method did so I'm not quite sure