libear
libear copied to clipboard
build for WedAssembly
todo
- [ ] add C++ tests for C API functions (currently only JS)
- [ ] fix use of long for 64 bit types in decorrelation filters (see warning from tests)
- [ ] represent exceptions in C API, and catch exceptions when enabled
- [ ] add more functionality to C API
more ideas for size improvements:
- improve representation in bs2051_layouts.cpp
- the current structure results in a manual call to the std::string constructor and the Channel constructor (with lots of parameters on the stack), for each channel in each layout
- write a POD channel struct which can be stored in static data, and a function that makes a Layout from a char* and a list of channel indexes
- drop pre-computed facets, or at least change the representation of facets to be something like
vector<vector<int>>, as the constructor is huge and using set is unnecessary - turn on wasm bulk memory operations
usage
Build with nix (only tested on linux, but may work on osx):
nix --extra-experimental-features "nix-command flakes" build .#libear_wasm
this puts libear.wasm in result/lib/libear.wasm. Alternatively just use this build:
libear.wasm.zip
There is a JS wrapper here: https://github.com/ebu/libear/blob/wasm_build/src/libear.mjs
There are some tests for that here, which show how to load the library (synchronously) and calculate some gains: https://github.com/ebu/libear/blob/wasm_build/tests/test_libear.mjs
To load from a stream in the browser use something like:
const wasm_buf = fetch('libear.wasm');
let lib = await EARLibrary.from_stream(wasm_buf);
...