emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exposing emscripten's AudioContext to external JS

opened this issue · comments

Currently, the AL object in library_openal.js is squirreled in a closure and only accessible by the associated AL functions. Is there a way we can get at it from outside?

My particular use case is I want to mutate the buffer from JS without having to call alBufferData (which requires copying stuff onto the emscripten heap)

I also need this in order to decode compressed audio (mp3, ogg) using the browser's machinery and then feed that decompressed audio into emscripten OpenAL. Right now there's no way to do that since the browser's decoder produces an AudioBuffer and there's no way to feed that buffer or its samples (float32, sadly) directly into the emscripten context.

Maybe I am misunderstanding something. But the AL object, like GL and FS and so forth, should be a toplevel object in the main scope, and not hidden in a closure?

At present it's not. It's a closure-level local, hence this issue.

Maybe we aren't talking about the same object? When I build I see this in the main scope:

  var AL={ contexts:[], currentContext: null, [..]

Yes. It's trapped within the closure, so you can't access it from outside.

To be clearer: I want something like (this is what I did by hand):

var AL=Module["OpenAL"]={contexts:[], ...

Oh ok, you can do that by exporting it, e.g. -s EXPORTED_FUNCTIONS='["_main", "AL"]' will export both main() and the AL object, on Module.

(Yes, the name is a little confusing since it just mentions functions. I also noticed now that it shows a warning, even though it works. It would be nice to fix those.)

Wonderful, thanks!

Great! @mispy , is that what you were looking for too?

AL is now available by default. This issue can be closed.

Thanks @ValdikSS, closing.