Ribbit uses Emscripten to compile C++ DSP code into WebAssembly for web browser execution. The build process creates two main output files in web/scripts/:
ribbit.js (16KB) - JavaScript glue code and WebAssembly loaderribbit.wasm (103KB) - Compiled WebAssembly binaryInstall the Emscripten SDK (version 4.0.8 or later):
Windows:
# Clone and setup emsdk
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
emsdk install latest
emsdk activate latest
macOS/Linux:
# Clone and setup emsdk
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
# Add to your shell profile
echo 'source "/path/to/emsdk/emsdk_env.sh"' >> $HOME/.bash_profile
Run the build script:
build.bat
call emsdk\emsdk_env.bat
source emsdk/emsdk_env.sh
2. Compile with Emscripten:
```bash
emcc src/ribbit/src/ribbit.cc src/ribbit/src/message_format.cc -o web/scripts/ribbit.js \
-s WASM=1 \
-s EXPORTED_RUNTIME_METHODS=['ccall','cwrap','stringToUTF8','UTF8ToString','lengthBytesUTF8'] \
-s EXPORTED_FUNCTIONS=['_malloc','_free','_createEncoder','_destroyEncoder','_createDecoder','_destroyDecoder','_feed_pointer','_feed_length','_message_pointer','_message_length','_signal_pointer','_signal_length','_payload_pointer','_payload_length','_feedDecoder','_digestFeed','_digestFeedOptimized','_initEncoder','_readEncoder','_pack_contest_message','_unpack_contest_message'] \
-I src/ribbit/include \
-std=c++17 \
-O3 \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=16MB \
-s MAXIMUM_MEMORY=64MB \
-s STACK_SIZE=1MB \
-s MODULARIZE=1 \
-s EXPORT_ES6=0 \
-s ENVIRONMENT=web \
-s FILESYSTEM=0 \
-s ASSERTIONS=0 \
-s MALLOC=emmalloc \
-msimd128 \
--closure 0 \
-flto
| Setting | Value | Description |
|---|---|---|
| Language | C++17 | Modern C++ standard |
| Optimization | O3 | Maximum performance optimization |
| LTO | Enabled | Link-time optimization |
| SIMD | Enabled | SIMD instructions for parallel processing |
| Setting | Value | Description |
|---|---|---|
| Initial Memory | 16MB | Starting heap size |
| Maximum Memory | 64MB | Maximum heap size |
| Stack Size | 1MB | Function call stack |
| Memory Growth | Allowed | Dynamic allocation |
| Allocator | emmalloc | Lightweight malloc implementation |
| Setting | Value | Description |
|---|---|---|
| WASM | Enabled | Generate WebAssembly binary |
| Modularize | Enabled | Creates Module() function |
| Environment | Web | Browser-optimized |
| Filesystem | Disabled | Not needed for this application |
| Assertions | Disabled | Removed for performance |
| Closure Compiler | Disabled | Faster builds |
_malloc - Allocate memory_free - Free memory_createEncoder - Initialize encoder_destroyEncoder - Cleanup encoder_initEncoder - Initialize encoder with message_readEncoder - Read encoded signal_signal_pointer - Get signal buffer pointer_signal_length - Get signal buffer length_createDecoder - Initialize decoder_destroyDecoder - Cleanup decoder_feedDecoder - Feed audio chunk to decoder_digestFeed - Process audio buffer_digestFeedOptimized - Optimized buffer processing_feed_pointer - Get feed buffer pointer_feed_length - Get feed buffer length_payload_pointer - Get payload buffer pointer_payload_length - Get payload buffer length_message_pointer - Get message buffer pointer_message_length - Get message buffer length_pack_contest_message - Pack contest mode message_unpack_contest_message - Unpack contest mode messageccall - Call C function from JavaScriptcwrap - Wrap C function for JavaScriptstringToUTF8 - Convert JS string to UTF-8 bytesUTF8ToString - Convert UTF-8 bytes to JS stringlengthBytesUTF8 - Get UTF-8 byte lengthFixed compilation errors in src/ribbit/src/dsp/complex.hh:
value_type typedef - Required for template metaprogrammingoperator+= - Complex addition assignmentoperator-= - Complex subtraction assignmentoperator*= - Complex multiplication assignmentoperator/= - Complex division assignmentoperator*= (scalar) - Scalar multiplication assignmentoperator/= (scalar) - Scalar division assignmentThese additions ensure compatibility with modern C++ template code and DSP operations used in the FFT, Hilbert transform, and phase-shift keying implementations.
The build process compiles:
ribbit.cc)message_format.cc)Typical build times:
The build generates:
web/scripts/
├── ribbit.js # JavaScript loader and runtime (16KB)
└── ribbit.wasm # WebAssembly binary (103KB)
src/ribbit/src/src/ribbit/include/web/scripts/ directory exists (created automatically by build script)-flto) for better optimization-s ASSERTIONS=0)polar_list_decoder.hh regarding array bounds - this is a pre-existing issue in the upstream code and does not affect functionality