Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeQueue + WASM example #255

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ module.exports = function(eleventyConfig) {
'src/audio-worklet/**/*.html',
'src/audio-worklet/**/*.js',
'src/audio-worklet/**/*.mjs',
'src/audio-worklet/**/*.data',
'src/audio-worklet/**/*.wasm',
'src/demos/**/*.css',
'src/demos/**/*.gif',
'src/demos/**/*.html',
Expand Down
5 changes: 5 additions & 0 deletions src/_data/audioworklet_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
This example demonstrates how this library can be used as a channel
between a worker thread and AudioWorklet to send audio data.
href: free-queue/examples/simple-passthrough/
- title: Using FreeQueue with WebAssembly
description: An example demonstrates the usage of FreeQueue with
WebAssembly. It includes an external C/C++ MP3 decoder library to
load and play music with FreeQueue on top of AudioWorklet.
href: free-queue/examples/hello-webassembly/

- title: Migration from ScriptProcessorNode
entries:
Expand Down
2 changes: 1 addition & 1 deletion src/_data/build_info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"3.0.2","revision":"2838fd6","lastUpdated":"2022-08-30","copyrightYear":2022}
{"version":"3.0.2","revision":"d762369","lastUpdated":"2022-09-11","copyrightYear":2022}
35 changes: 35 additions & 0 deletions src/audio-worklet/free-queue/examples/hello-webassembly/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Using FreeQueue with WebAssembly

This example demonstrates how to use FreeQueue with WebAssembly.
It includes an external C/C++ MP3 decoder
([dr_mp3.h](https://github.com/mackron/dr_libs/blob/master/dr_mp3.h))
library to load and play music with FreeQueue on top of AudioWorklet.

## Building

Run `build.sh` for Linux and `build.cmd` for windows to build.
Refer to build scripts for building instructions.

### Emscripten Flags

```
DivyamAhuja marked this conversation as resolved.
Show resolved Hide resolved
// To tell emscriptenm to build for worker environment

// To build and load as an ES6 module
-s ENVIRONMENT=worker
-s MODULARIZE=1
-s EXPORT_NAME=ExampleModule
-s EXPORT_ES6=1

// To run main automatically after loading module.
-s INVOKE_RUN=1

// To enable pthread support
-pthread

-s EXPORTED_RUNTIME_METHODS="['callMain','ccall', 'cwrap']"
-o build/example.js

// Preload mp3 file
--preload-file moonlight.mp3
```
11 changes: 11 additions & 0 deletions src/audio-worklet/free-queue/examples/hello-webassembly/build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mkdir "build"
emcc example.c ^
-sENVIRONMENT=worker ^
-sMODULARIZE=1 ^
-sEXPORT_NAME=ExampleModule ^
-sEXPORT_ES6=1 ^
-sINVOKE_RUN=1 ^
-pthread ^
-sEXPORTED_RUNTIME_METHODS="['callMain','ccall', 'cwrap']" ^
-o build/example.js ^
--preload-file moonlight.mp3
11 changes: 11 additions & 0 deletions src/audio-worklet/free-queue/examples/hello-webassembly/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mkdir -p "build"
DivyamAhuja marked this conversation as resolved.
Show resolved Hide resolved
emcc example.c \
-sENVIRONMENT=worker \
-sMODULARIZE=1 \
-sEXPORT_NAME=ExampleModule \
-sEXPORT_ES6=1 \
-sINVOKE_RUN=1 \
-pthread \
-sEXPORTED_RUNTIME_METHODS="['callMain','ccall', 'cwrap']" \
-o build/example.js \
--preload-file moonlight.mp3
Binary file not shown.
Loading