Hi Rick, audio on the web is quite the mess unfortunately (not emscripten's 
fault, mostly WebAudio's).

First, if everything compiles but you don't hear anything, it's most likely 
because browsers started to disable autoplay quite recently, and I think 
none of the existing API wrappers in emscripten handle this case (you 
basically need to "resume" the webaudio context in a user input handler). I 
think Chrome prints a warning on the JS console if a webpage initializes a 
webaudio context and starts it from outside a user gesture, so this at 
least gives a hint where the autoplay was blocked.

Apart from that problem, both the SDL1 and OpenAL audio wrappers appear to 
work. 

This demo uses OpenAL: 
http://floooh.github.io/oryol-samples/wasm/SoundTest.html

This demo uses the SoLoud audio library with the SDL1 backend: 
http://floooh.github.io/oryol-samples/wasm/SoloudMOD.html

SoLoud is here: https://github.com/jarikomppa/soloud

(if you don't hear anything in Chrome, that's because I haven't handled the 
WebAudio activation in this code yet).

If you just need simple buffer streaming, you can sokol_audio.h a try, this 
is my own minimalistic cross-platform audio library:

https://github.com/floooh/sokol/blob/master/sokol_audio.h

Unlikely the emscripten API wrappers, this uses a WebAudio 
ScriptProcessingNode to feed audio samples, instead of pushing small audio 
buffers. I found this to be the only (current) solution to provide a sample 
stream to WebAudio without glitching.

sokol_audio.h also has a very simple fix for the autoplay problem: Audio 
will be activated on the first click, touch or keypress:

https://github.com/floooh/sokol/blob/cb3f4093d917c5e4e8d9e4d9825cc901a7d6e2f9/sokol_audio.h#L1276-L1278

Here's a simple MOD player using sokol_audio.h (remeber to click into the 
page to activate audio):

https://floooh.github.io/sokol-html5/wasm/modplay-sapp.html

...and the Tiny Emulators use this as well:

https://floooh.github.io/tiny8bit/

Please note that ScriptProcessorNode is deprecated though, I'm planning to 
add audio worklet support in the future, but for the common case where the 
main thread needs to provide the sample stream, this will essentially do 
the same thing as ScriptProcessorNode, just with a lot more code (yeah, I 
don't really understand why ScriptProcessorNode has been deprecated, it's 
doing a good job for use cases like the emulators, where the main thread 
must generate the audio samples).

I hope this helps :)
-Floh.

On Friday, 15 March 2019 23:42:18 UTC+1, Rick Battagline wrote:
>
> So according to the emscripten faq:
>
> https://emscripten.org/docs/getting_started/FAQ.html
>
> I should be able to use SDL 1 Audio, SDL 2 Audio or OpenAL.  I have not 
> found any specific tutorials for any of these online, and when I try to run 
> generic code using SDL or OpenAL, nothing seems to work.  SDL2 gives me 
> some python errors during the compile, SDL1 gives me an error in 
> SDL_endian.h and OpenAL doesn't seem to support alutLoadWAVFile.
>
> I'm considering just writing my audio in JavaScript and making calls to it 
> from inside Emscripten, but I'm not sure this is the best way to make the 
> audio work.
>
> Any suggestions would be appreciated.
>
> Thanks
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to