Last week I was working on that little extension. Audio plays a huge role in games and the better control you have over it, the better atmosphere you can create.
With this extension you can create sound sources from mono WAV files, position them and perform other stuff. You also control the position of the listener.
The extension and documentation are on github.
And here is a demonstration.
Keep in mind that only mono WAV files will be positioned. And at the moment a WAV file with embedded metadata will fail to load.
Later on I plan to add effects support. Like reverberation and filters (low pass, high pass). And soundwave generation to be used instead of WAV files (sine, square, etc).
I know Native Extensions arenât available on windows yet, but is it possible to build for Android from windows? If I try to build and launch to an Android target from the editor I get âUnsupported platform x86_64-windowsâ, and if I try to bundle for Android I get this error:
/var/extender/builds/build8338159323363887407/main.cpp:27: error: undefined reference to âopenalâ
collect2: error: ld returned 1 exit status
ext.manifest /OpenAL Extension Demo/content/openal line 1 Problem
(Thatâs just the last bit of the error message of course.)
Currently it only works on macOS. For iOS it compiles, but fails to run. On Android I need to find a replacement for the static_hash.h file, which doesnât compile with g++.
Iâll resolve these issues eventually and when windows support comes for the extension, Iâll also make sure it compiles.
I believe that @sven and @Mathias_Westerdahl have set an internal deadline for native extension support on all platforms to before Kingâs annual company kickoff in May. Iâm not sure if this is still correct though. Maybe @sven and @Mathias_Westerdahl could post weekly updates here on the forum regarding their progress?
Now works on Android!
So to sum up, it now runs on iOS, macOS and Android. Waiting for new platforms to become supported by the extensions system.
As it turns out, on Android Defold doesnât use OpenAL, but it is still bundled in the APK. And itâs OpenAL Soft.
I had to initialize OpenAL by the extension and also manage global pause/resume on app suspend/resume.
openal.init() has to be called now before anything else. Is there a single Lua file/function in Defold that can be called at the very beginning? Before any other game objectâs init() function.
No, not really. I mean you could have a bootstrap collection that consist of a single script and a proxy to the rest of the app, but thatâs not really what youâre after I guess.
Yes, I will init the extension when itâs loaded. Why I wanted to use a Lua function is to be able to turn off the extension without removing it from the project. Sometimes it might be needed.
Since the .102 release supposedly enabled bundling with native extensions for Android, from Windows, I decided to give this another go. But the bundling failed with these errors:
Yeah, I was just being stupid again, I left some duplicates, though Iâm not sure why the error message didnât tell me the folder of the duplicate. Anyway, it works perfectly now, thanks! Sorry I bothered you for no reason, sheesh.