emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.36k stars 3.25k forks source link

How to export emscriptenRegisterAudioObject? #22072

Closed evoyy closed 3 weeks ago

evoyy commented 3 weeks ago

The documentation states that there is a function emscriptenRegisterAudioObject() that can be used to pass an AudioContext instance from JavaScript to WebAssembly:

In a larger application that integrates existing Web Audio libraries, you may already have an AudioContext created via some other library, in which case you would instead register that context to be visible to WebAssembly by calling the function emscriptenRegisterAudioObject().

https://emscripten.org/docs/api_reference/wasm_audio_worklets.html#programming-example

How can I export this function? I have tried adding it to EXPORTED_RUNTIME_METHODS as follows:

emcc \
    -lembind \
    -o build/output.js \
    -s EXPORT_NAME=createMyModule \
    -s EXPORTED_RUNTIME_METHODS="[emscriptenRegisterAudioObject]" \
    -s MODULARIZE \
    demo.cpp

However this results in the following warning:

warning: invalid item in EXPORTED_RUNTIME_METHODS: emscriptenRegisterAudioObject

evoyy commented 3 weeks ago

Resolved. I needed: -sAUDIO_WORKLET