lime icon indicating copy to clipboard operation
lime copied to clipboard

Update OpenAL Soft and allow seamless changing of the output device

Open ACrazyTown opened this issue 1 year ago • 6 comments

This PR adds bindings and implements OpenAL Soft's reopenDeviceSOFT and ALC_SOFT_system_events extension. In order to take advantage of this functionality, I had to update OpenAL Soft, which required forcing latest hxcpp (git, until there's a new stable release). New versions of OpenAL Soft require the C++17 standard and current hxcpp doesn't seem to have an official way to use it. (Maybe it could be done via compilerflags in the Build.xml?)

With these changes, Lime will automatically listen to changes to the default audio output device and switch playback to those devices seamlessly. Also reopenDeviceSOFT allows for manually switching the output device in the app.

This is currently a draft, I'm waiting for a new hxcpp release and a new stable OpenAL Soft release (which should be sometime soon!), as well as figuring out a few other things. I'm opening this right now for discussion and feedback

Currently I only tested it on Windows x64 C++ ~~(I've also had it working on Hashlink but ever since I've merged this change into 9.0.0-dev I keep getting a strange and seemingly unrelated error: FATAL ERROR : Invalid signature for function lime@hl_cairo_get_matrix : PDOiOiB_iiii__OiOiB_iiii_ required but PDOdddddd__Odddddd_ found in hdll)~~. I will try getting the changes to work on other targets as soon as I figure out HL & Neko.

Closes https://github.com/openfl/lime/issues/1515, https://github.com/openfl/openfl/issues/2642

ACrazyTown avatar Sep 23 '24 16:09 ACrazyTown

I've also had it working on Hashlink but ever since I've merged this change into 9.0.0-dev I keep getting a strange and seemingly unrelated error: FATAL ERROR : Invalid signature for function lime@hl_cairo_get_matrix : PDOiOiB_iiii__OiOiB_iiii_ required but PDOdddddd__Odddddd_ found in hdll

Try lime rebuild hl to bring your hdll up to date.

player-03 avatar Sep 23 '24 21:09 player-03

Try lime rebuild hl to bring your hdll up to date.

I've done that, tried doing a clean rebuild of both lime and my testing project. I keep getting the same error. Could this commit https://github.com/openfl/lime/commit/71442d09f4719e7fc48d98f7b5cd885865c95225 be related? It doesn't seem to be in 9.0 branch

ACrazyTown avatar Sep 23 '24 21:09 ACrazyTown

Oh yeah, if you don't have that merged, you'll need it. Edit: ok, merged into 9.0.0-Dev. You can pull from there.

player-03 avatar Sep 23 '24 21:09 player-03

Okay, I think I did the merge right. Hashlink seems to be fixed and working fine now!

ACrazyTown avatar Sep 24 '24 13:09 ACrazyTown

I've gotten Mac to build and work!

I only have Linux, Android & Neko left to figure out, though CI for them will always fail because it uses an older hxcpp version

ACrazyTown avatar Sep 28 '24 18:09 ACrazyTown

Tested out Linux & it seems to work. I assume Android would also work with just an updated config but I don't know how I'd even test that... Neko seems to crash whenever it tries to dispatch the callback, I'm assuming it's threading related. I'm not sure what the alternative to hxcpp's gc_set_top_of_stack and hl's hl_register_thread would be on Neko.

ACrazyTown avatar Oct 05 '24 13:10 ACrazyTown

I'll undraft this PR now as I think it should be pretty much ready to go except for a few concerns:

  1. Neko support - Neko is crashing when the callback is supposed to be dispatched, probably because of threading? I assume to fix it I'd use neko_thread_register() but I can't figure out how to call functions from the Neko API in the C++ code as I can't seem to include the neko_vm.h header.

  2. Callback userParam - Not sure how to tackle this. When setting a callback OpenAL Soft keeps a reference to a user specified value. Seems like it's not possible to directly set a Haxe value here because it may get collected by the GC before the callback gets dispatched causing issues when sending it back as it would point to invalid memory.

  3. ~~Failing Android CI - Android CI was failing on my fork because the compiler version it uses seems to have a bug. This was resolved in a newer commit of OpenAL Soft but it isn't in a stable release yet. Lime seems to only use stable releases so I don't know if its cool to use the commit with the fix~~ EDIT: This was fixed with https://github.com/openfl/lime/pull/1841/commits/4270cfde9deeea01be462010702bb2da316ea36d

ACrazyTown avatar Dec 10 '24 20:12 ACrazyTown