diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5f3b0fb..bce5147 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,7 +30,6 @@ jobs: working-directory: ${{runner.workspace}}/sfizz-webaudio/build run: | cmake --build . --config "$BUILD_TYPE" -j 2 - echo "export default Module;" >> sfizz.wasm.js - name: Inspect directory working-directory: ${{runner.workspace}}/sfizz-webaudio run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a67a40..de81d18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ add_executable(sfizz-webaudio) target_sources(sfizz-webaudio PRIVATE sfizz_webaudio.cpp) target_link_libraries(sfizz-webaudio PRIVATE sfizz::sfizz) set_target_properties(sfizz-webaudio PROPERTIES - LINK_FLAGS "--bind -s ENVIRONMENT=web -s ALLOW_MEMORY_GROWTH=1 -s SINGLE_FILE=1 -s WASM=1 -s WASM_ASYNC_COMPILATION=0" +LINK_FLAGS "--bind -s ENVIRONMENT=web -s ALLOW_MEMORY_GROWTH=1 -s SINGLE_FILE=1 -s WASM=1 -s WASM_ASYNC_COMPILATION=0 -s EXPORTED_FUNCTIONS=\"['_malloc']\" -s EXPORT_ES6=1" OUTPUT_NAME sfizz.wasm ) diff --git a/README.md b/README.md index 5da788b..59abbdf 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ mkdir build cd build emcmake cmake -DCMAKE_BUILD_TYPE=Release .. make -j -echo "export default Module;" >> sfizz.wasm.js ``` From the `build` directory, you may then host the result on `localhost:8000` using python as diff --git a/sfizz-processor.js b/sfizz-processor.js index c8f020c..df124e3 100644 --- a/sfizz-processor.js +++ b/sfizz-processor.js @@ -21,6 +21,8 @@ import Module from './build/sfizz.wasm.js'; import WASMAudioBuffer from './util/WASMAudioBuffer.js'; +const SfizzModule = new Module(); + // Web Audio API's render block size const NUM_FRAMES = 128; @@ -29,9 +31,9 @@ class SfizzProcessor extends AudioWorkletProcessor { super(); // Create an instance of Synthesizer and WASM memory helper. Then set up an // event handler for MIDI data from the main thread. - this._synth = new Module.SfizzWrapper(sampleRate); - this._leftBuffer = new WASMAudioBuffer(Module, NUM_FRAMES, 1, 1); - this._rightBuffer = new WASMAudioBuffer(Module, NUM_FRAMES, 1, 1); + this._synth = new SfizzModule.SfizzWrapper(sampleRate); + this._leftBuffer = new WASMAudioBuffer(SfizzModule, NUM_FRAMES, 1, 1); + this._rightBuffer = new WASMAudioBuffer(SfizzModule, NUM_FRAMES, 1, 1); this._activeVoices = 0; this.port.onmessage = this._handleMessage.bind(this); }