Skip to content

Commit

Permalink
Work-in-progress
Browse files Browse the repository at this point in the history
(Off home!)
  • Loading branch information
cwoffenden committed Nov 7, 2024
1 parent 6140011 commit f6153e9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/webaudio/audioworklet_in_out_stereo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <emscripten/em_js.h>
#include <emscripten/webaudio.h>

#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");
}

0 comments on commit f6153e9

Please sign in to comment.