From f6153e92468d944a92f991f0221a573086a70e88 Mon Sep 17 00:00:00 2001 From: Carl Woffenden Date: Fri, 1 Nov 2024 18:36:11 +0100 Subject: [PATCH] Work-in-progress (Off home!) --- test/webaudio/audioworklet_in_out_stereo.c | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/webaudio/audioworklet_in_out_stereo.c diff --git a/test/webaudio/audioworklet_in_out_stereo.c b/test/webaudio/audioworklet_in_out_stereo.c new file mode 100644 index 0000000000000..1e801d0cb09f7 --- /dev/null +++ b/test/webaudio/audioworklet_in_out_stereo.c @@ -0,0 +1,35 @@ +#include +#include + +#define AUDIO_STACK_SIZE 2048 + +EM_JS(bool, addAudio, (EMSCRIPTEN_WEBAUDIO_T ctxHnd, const char* url, const char* label), { + var context = emscriptenGetAudioObject(ctxHnd); + if (context) { + var audio = document.createElement('audio'); + audio.src = UTF8ToString(url); + audio.loop = true; + var track = context.createMediaElementSource(audio); + track.connect(context.destination); + + var button = document.createElement('button'); + button.innerHTML = UTF8ToString(label); + button.onclick = () => { + if (context.state == 'suspended') { + context.resume(); + } + audio.play(); + }; + + document.body.appendChild(button); + return true; + } + return false; +}); + +int main() { + EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(NULL); + + addAudio(context, "audio_files/emscripten-beat.mp3", "Play Beat"); + addAudio(context, "audio_files/emscripten-bass.mp3", "Play Bass"); +}