audio

@audio/plugin0.1.5

Processor contract and targets

JavaScript audio processors to AudioWorklet nodes and experimental macOS VST3 plugins

Status
pending calibration
Updated
Family
2 packages under it: vst, wam
Category
build
Licence
MIT
Dependencies
2 packages, all permissive: MIT
Tests
at least 152 in audiojs/plugin's CI at 6f0ae92

Run JavaScript audio processors in an AudioWorklet, or build experimental macOS VST3 and CLAP plugins from the same source.

A processor is a function that returns a function: its state lives in the closure, and properties on it describe its parameters, channels and identity. This package exports the implemented adapters and the host fixture suite. The contract, 1.0, is the common shape; the guide covers writing and checking processors, the names the catalogue shares, the mapping onto the plugin formats and what each host keeps.

Status

Target Implemented scope Still to establish
@audio/plugin-wam JavaScript AudioWorklet that keeps the contract's host duties 2 to 10, shown in Node by the fixture suite and its own tests: automation read at audio rate, notes, transport, buffers, state, restart values handed over to a new instance (built on the render thread, so duty 1 in part); WAM-shaped metadata Independent WAM host interoperability; the fixture suite in a browser (there, the package check renders gain and drives the demo)
@audio/plugin-vst Experimental macOS builder on jz 1.0.x, VST3 (toVst3) and CLAP (toClap): mono and stereo buses; parameters, state, latency and tails, ctx.transport; both builds split a block where a value changes and keep calls to 32 frames while one moves, by one shared file A build from the published jz package; validation by a third-party host, validator or DAW; events; Windows and Linux builds
audio/batch Offline/stream hosting in the audio engine Separate package and release lifecycle
AU, LV2, general CLI Planned No target adapters yet; Logic requires AU

This package was @audio/compile, its members @audio/compile-wam and @audio/compile-vst; under those names @audio/compile@0.1.3 (documentation only), @audio/compile-wam@0.1.2 and @audio/compile-vst@0.0.1 are on npm, the last two published 2026-11-16 from b6abfee. The package checks prepare @audio/plugin@0.1.4, @audio/plugin-wam@0.1.2 and @audio/plugin-vst@0.0.1 archives. Only the AudioWorklet path is being prepared for use now. The native lane builds on jz 1.0.x's public options; no third-party host has validated a build. Testing the VST package's exports is not evidence that a released compiler can build it.

Try the packed preview

From this repository, with Node and Python 3 installed:

npm ci
npx playwright install chromium firefox webkit
npm run pack:preview

This installs real tarballs in temporary consumers without workspace links, checks Node exports and the standalone adapter, renders gain in Chromium/Firefox/WebKit and exercises the shipped demo. On success, the AudioWorklet archive is saved in .work/preview/; native archives remain internal packaging fixtures until the native release gate below passes.

Install the standalone AudioWorklet archive into a new directory (replace /path/to/plugin with this checkout):

mkdir audio-preview
cd audio-preview
npm init -y
npm install /path/to/plugin/.work/preview/audio-plugin-wam-0.1.2.tgz
python3 -m http.server 8080 --bind 127.0.0.1

Open http://127.0.0.1:8080/node_modules/@audio/plugin-wam/demo/index.html. Start the tone, change gain/compressor controls, then stop. The demo and processors are included in the package and use local imports; no CDN or bundler is needed. This is a development example, not a finished effect UI.

Release checks

npm test                      # workspace suites + installed tarballs in three browsers
npm run test:package          # package/export checks and installed browser demo only

Native release gate. jz 1.0.x is published, and @audio/plugin-vst declares it as an optional peer (^1.0.3). The lane compiles with jz's public options and requires its real-time run: no heap growth, nothing written past __jz_heap, no host call. jz's static proof, memory: { fixed: ['process'] }, is reported but cannot pass yet: process calls the atom's closure through the closure table, which the public options keep exported. host: 'native', which closes it, is proposed for jz 1.1.0. Before adding the native package-build CI job or claiming a working native release, build from the installed jz package and pass npm test on macOS; development checkouts and existing fixtures are not a substitute. CI runs on Linux with SKIP_NATIVE_LANE=1, the switch that says the native lane is not under test; without it, the tests that need jz fail rather than skip. No compiler snapshot is pinned by this preview.

Not built yet: AU and LV2 targets, Windows and Linux builds, note and MIDI events, and validation by a third-party host.

The AudioWorklet leaf can be released independently. Hold the native leaf and the umbrella's native dependency until the native release gate passes; then release verified leaves before the umbrella and verify exact public versions in a fresh consumer. npm run pack:preview and the tests do not publish anything.

Packages

Target adapters live in packages/plugin-*, following the other audiojs families. Use the umbrella or depend directly on a target:

import { toWam } from '@audio/plugin'
// Or: import { toWam } from '@audio/plugin-wam'

@audio/plugin-wam has no JZ or native-tool dependency; @audio/plugin-vst takes jz as an optional peer, installed only by those who build. The Node entry also exports toVst3 and toClap; browser consumers use toWam. The former @audio/wam source has moved here. Migrate consumers when the replacement release is available; do not remove a working dependency in favor of an unpublished package.

@audio/plugin-vst contains the native builder; see its scope and API. AU and LV2 adapters remain planned.

Run npm test for all implemented target suites. The native fixture is a separate npm run test:vst because it needs the local native toolchain and host.

The contract

export const gain = (ctx) => (inputs, outputs, params) => {
  const x = inputs[0], y = outputs[0], g = 10 ** (params.gain[0] / 20)
  for (let c = 0; c < y.length; c++)
    for (let i = 0; i < y[c].length; i++) y[c][i] = x[c][i] * g
}
gain.params = {
  gain: { type: 'number', min: -60, max: 24, default: 0, unit: 'dB', smoothing: 0.01 },
}

Ship it in your package's audio.js, named by an "audio": "./audio.js" field in package.json, so tools find it without importing it. See CONTRACT.md for the full shape and GUIDE.md for the rest.

A host checks itself against the contract with the fixture suite @audio/plugin/conformance (an unchanged copy of audio's test/conformance.js): for (let { name, run } of duties) await run(host), where host(processor, opts) renders one instance and resolves to { output, emitted }; the file's header lists the options.

Development fixtures (macOS)

The following experiments predate the public VST builder. Their private fixture limitations are separate from the current builder scope.

npm run test:vst -- /tmp/audiojs-gain

Builds the existing packages/plugin-wam/examples/gain.js atom with local JZ, translates its WASM with wasm2c, and packages a native Gain.vst3. Loads it through ../host/packages/host-vst and compares stereo samples with both JS and WASM. Covers 44.1/48 kHz, six block sizes, short blocks, silence, repeated processing, heap growth, overlapping instances, and gain changes from −60 to +6 dB. No DAW or audio device required.

Requires the sibling built host-vst project, local JZ, Xcode command line tools, and Homebrew WABT. Override paths with AUDIO_ROOT, JZ_ROOT, WABT_ROOT, and SDKROOT. WASM and native build outputs stay in the supplied output directory (a temporary directory by default).

This is a gain automation fixture, not the general plugin compiler. The atom source is unchanged. The native shell exposes its gain parameter; controller writes reach DSP only through VST3 parameter queues. Its state blob exposes heap diagnostics and the number of delivered updates for the test. Padding short blocks is valid here because gain is stateless. Compiler-specific value decoding stays in the small DSP adapters behind the common VST shell. SIMD is disabled for this first integration check.

The host applies setParam(id, normalizedValue) at the next block boundary; multiple writes coalesce, and consumed updates are not replayed. Within-block sample-offset automation is not implemented by this fixture. Validate with an independent VST3 host/validator before treating the bundle as distributable.

Stateful lifecycle

npm run test:vst -- --stateful --compiler=jz
npm run test:vst -- --stateful --compiler=porffor

The stereo one-pole fixture keeps closure state between callbacks and receives actual frame counts, including short blocks. Both backends pass 12,438 checks against the same JS processor: parameter changes, independent overlapping instances, close/reopen, last-close arena release, and zero callback heap growth. The frame-count argument is private to this fixture, not a new audio atom API. Porffor's shared arena remains alive until its final instance closes. Concurrent audio threads and within-block parameter automation are still unvalidated.

Porffor and native timing

npm run test:vst -- /tmp/gain-jz --compiler=jz --bench
npm run test:vst -- /tmp/gain-porffor --compiler=porffor --bench

--compiler=jz|porffor selects the complete build chain (default: jz). The older --porffor spelling remains an alias. Unknown compiler names fail before building. Compiler selection belongs to the target builder, never to atom metadata or the host.

The current @audio/plugin-vst builder accepts { compiler: 'jz' } and rejects Porffor. The dual-backend fixture below is separate experimental work; the general CLI is still planned. Keep the processor contract, plugin identity, parameter behavior and lifecycle tests common; keep compiler layouts inside adapters. A compiler option selects a supported chain, not an arbitrary list of passes.

Both builds use the unchanged gain atom, the same VST shell and sample tests, and Clang -O2 -ffp-contract=off. JZ emits scalar WASM, translated by WABT; Porffor emits C directly. PORFFOR_ROOT selects its source checkout (defaults to the sibling porffor); its npm package is not used. The Porffor mode does not require JZ or WABT. Generated C symbol signatures are checked before linking.

--bench builds a native host loop and writes benchmark.json with compiler and host revisions, CPU, flags, binary size, and block timings. At 48 kHz it warms 2,000 blocks, then measures 20,000 blocks at each of 64/128/512/1024 frames. Buffers are preallocated and output is checked. Timing includes native host, plugin and buffer-copy costs; compilation, loading, JS/NAPI calls and audio hardware are outside the measured loop. Compare median and p99, plus the worst observed time against the block deadline. Gain is a small integration fixture, so these results do not establish performance on larger DSP programs or prove hard real-time deadlines. Run comparisons sequentially on an otherwise idle machine.

The experimental Porffor adapter uses --no-gc: each instance has independent buffers and closure state, but the shared arena retains allocations until the last plugin instance closes. Concurrent processing threads and general runtime embedding are not validated. This is an offline feasibility test, not a complete Porffor plugin backend.

The stateful VST fixture also renders 4,000 blocks across two simultaneous worker audio threads, comparing each instance against the JavaScript atom and checking fixed callback heaps. Setup and teardown are serialized. This does not yet cover automation points inside a block or a public VST builder.