WAM Platform API
The WAM (Web Audio Module) implementation enables iPlug2 plugins to run in web browsers using WebAssembly and the Web Audio API.Overview
TheIPlugWAM class implements the WAM specification, allowing audio plugins to run as AudioWorklet processors in modern web browsers. The plugin runs in the AudioWorkletGlobalScope, sandboxed from the main JavaScript thread.
WAM (Web Audio Module) is a standard for audio plugins on the web, using WebAssembly for DSP and the Web Audio API for audio routing. iPlug2 compiles your C++ plugin to WASM for near-native performance in the browser.
Core Class
IPlugWAM
Defined in:IPlug/WEB/IPlugWAM.h
IPlugAPIBase- Core iPlug API interfaceIPlugProcessor- Audio processing interfaceWAM::Processor- WAM processor base class
The WAM processor runs in the AudioWorkletGlobalScope, completely isolated from the main thread. All communication with the UI uses message passing.
Key Methods
WAM Lifecycle
init
bufsize- Buffer size in framessr- Sample rate in HzpDesc- Descriptor information
nullptr on success, error message on failure
terminate
resize
bufsize- New buffer size in frames
Audio Processing
onProcess
pAudio- Audio bus with input/output bufferspData- Additional processing data
MIDI Handling
onMidi
status- MIDI status bytedata1- First data bytedata2- Second data byte
onSysex
pData- SysEx data buffersize- Data size in bytes
Parameter Handling
onParam
idparam- Parameter IDvalue- New parameter value
Messaging
WAM uses a message-passing system for communication between the UI and audio processor.onMessage (String Data)
verb- Message verb (command)res- Resource identifierdata- String data
onMessage (Numeric Data)
verb- Message verbres- Resource identifierdata- Numeric data
onMessage (Binary Data)
verb- Message verbres- Resource identifierdata- Binary data buffersize- Data size in bytes
IPlug Processor Overrides
SetLatency
samples- Latency in samples
Latency compensation is handled by the Web Audio API automatically.
SendMidiMsg
msg- MIDI message
false (MIDI output not supported)
SendSysEx
msg- SysEx message
false (SysEx output not supported)
Editor Delegate Overrides
WAM overrides editor communication methods to use the WAM messaging system:SendControlValueFromDelegate
ctrlTag- Control tagnormalizedValue- Normalized value (0.0 to 1.0)
SendControlMsgFromDelegate
ctrlTag- Control tagmsgTag- Message tagdataSize- Data size in bytespData- Message data
SendParameterValueFromDelegate
paramIdx- Parameter indexvalue- Parameter valuenormalized- Whether value is normalized
SendArbitraryMsgFromDelegate
msgTag- Message tagdataSize- Data size in bytespData- Message data
Factory Function
MakePlug
info- Instance information (empty for WAM)
Building for Web
Emscripten Compilation
WAM plugins compile to WebAssembly using Emscripten:Build Configuration
Emscripten compiler flags (in build scripts):Optimization
Emscripten Flags:
-O3- Maximum optimization-Os- Optimize for size--closure- Google Closure Compiler
Features
WASM Options:
AUDIO_WORKLET=1- Enable AudioWorkletALLOW_MEMORY_GROWTH=1- Dynamic memoryMODULARIZE=1- Module export
Web Audio Integration
HTML Integration
WAM API Usage
Limitations
Threading: JavaScript is single-threaded. All audio processing must complete within the AudioWorklet processing callback.
Best Practices
Code Size
Minimize WASM binary size. Users download it on page load. Use
-Os optimization and link-time optimization.Startup Time
Optimize initialization. The
init() method should complete quickly to avoid blocking the audio thread.UI Performance
Keep UI lightweight. Use efficient graphics and minimize DOM manipulation for smooth performance.
Browser Testing
Test in multiple browsers. Chrome, Firefox, Safari, and Edge have different WASM performance characteristics.
Common Issues
Related Documentation
- IPlugAPIBase - Base API functionality
- IPlugProcessor - Audio processing interface
- Web Build Guide - Building for web platforms
- WAM Specification - Official WAM documentation
- Emscripten Documentation - WebAssembly compiler docs