audioJS

@audio/compile-wam

Status pending calibration

npm0.1.2licenseMIT

Run audio.js atoms as Web Audio Modules / AudioWorklet nodes

Overview

Install
Updated
Family
compile, 2 packages under it

Run audio.js atoms as Web Audio Modules / AudioWorklet nodes.

A single JS factory function with attached metadata becomes a WAM 2.0-shaped plugin — numeric params ride AudioParams, enum/bool params flow over MessagePort, works in browsers and Node (web-audio-api).

Use

This adapter is part of the packed compiler preview. The package includes examples/gain.js, examples/compressor.js and demo/index.html. After installing it, serve the consumer directory over HTTP and open /node_modules/@audio/compile-wam/demo/index.html to audition both processors. The release check runs this installed demo in Chromium, Firefox and WebKit. WAM-shaped metadata does not by itself establish compatibility with an independent WAM host.

import { toWam } from '@audio/compile-wam'
import { gain } from '@audio/compile-wam/examples/gain.js'

const wam = toWam(gain)            // this example is self-contained
await wam.register(audioContext)    // installs the factory as an AudioWorklet processor
const node = wam.create(audioContext, { parameterData: { value: -6 } })
source.connect(node).connect(audioContext.destination)

node.setParam('value', -12)         // numeric → AudioParam, enum/bool → MessagePort
node.onemit = (name, args) => {}    // events.out emissions (meters, detected pitch)
node.dispose()                      // releases the MessagePort (needed after offline render in Node)

For processors that import helpers or capture module-scope values, pass toWam(factory, { url: new URL('./processor.js', import.meta.url).href }) so the worklet imports the original module. The included compressor demo exercises this path.

Any package exposing an audio.js manifest (the "audio" field in its package.json) works — see the contract.

flags: ['restart'] params (attack/release-style coefficients baked at factory time) actually restart: a live setParam on a restart-flagged param re-runs the atom factory against a fresh ctx.params snapshot and swaps in the new process fn — state resets, matching the contract's "reconfigure = new instance" lifecycle rule. streaming: false (whole-render) atoms are refused at toWam() — they hold the entire timeline, so wrapping one in a 128-frame worklet would silently produce wrong output; render those offline via audio/batch instead.

For batch/stream hosting without an AudioContext see audio/batch; for compiling atoms to native plugin formats (CLAP, VST3, AU, LV2) see @audio/compile.