OpenAL extension - 3D audio, pitch, doppler effect and other stuff


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

Contribution is welcome.


Integrating Wwise with Defold
How to compile native extension with C++11 features? (DEF-2594) (SOLVED)
Live sound manipulation

Wow, this is great stuff! I’ll play around with it when I get home.

1 Like


Amazing stuff Sergey. Thanks a lot!!!

1 Like


Yessss, awesome! Thanks for sharing it!

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

1 Like


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.

1 Like


OK, cool. Yeah, I can’t wait until Native Extensions are operational for all platforms. I get the impression that’ll take quite a while though. :confused:



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?



Updated the extension. Now works on iOS and handles WAV files with metadata.



I’ve changed how string hashing works in the extension and now it compiles for Android.
However it still doesn’t work on Android for some reason.

alGetString(AL_VERSION) and alGetString(AL_RENDERER) return null.



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.

1 Like


Can you perhaps call it in the Initialize() function in the extension?

1 Like


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.



In those cases, I usually just rename the manifest to “ext.manifest_” and use code like if myextension then ...

1 Like


Removed openal.init(), added openal.get_info().

1 Like


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:

The full error log for the first one here: (a .txt renamed to a .lua so the forum would let me upload it)
Ross_OpenAL_Ext_build_error_log.lua (8.6 KB)



Please download the latest revision of the extension from GitHub. There is no static_hash.c anymore.

1 Like


Oh wow . . . I can’t believe I was that stupid, sorry! Now I’m just getting this:

Conflicting output resource 'build/default/sounds/campfire.wav‘ generated by the following input files: [sounds\campfire.wav, sounds\car.wav, sounds\cat.wav, sounds\waterfall.wav] <-> [sounds\campfire.wav, sounds\car.wav, sounds\cat.wav, sounds\waterfall.wav]



Um. I really don’t know what that means. Try removing all the sounds, building and then adding them back one by one?



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. :blush: