К содержимому
sound·design галерея

← Все справочники · исходный .md · справочники написаны для агента, поэтому на английском

Deployment: where the sound runs

Contents

  1. Choosing a mode
  2. Baked assets
  3. Kernels (AudioWorklet and offline)
  4. Native Web Audio graph: tract, spatial, mixer
  5. Rendering Web Audio on a server
  6. Web Audio practices and traps
  7. Handing sounds to game engines

1. Choosing a mode

QuestionIf yes
Linear media, or an engine with its own audio pipeline?Bake WAVs (plus variations)
Must the sound follow a continuously changing value (speed, force, intensity, RPM)?Kernel
Must it never repeat over long sessions with tiny download size?Kernel
Is it a heavy designed one-shot (cinematic hit, speech line, shatter)?Bake, then place it with the graph
Does it need 3D position, HRTF, rooms, user-controlled mix in a page?Graph around baked/kernel sources
Must CI or a build step produce/verify the audio without a browser?offline render (kernel path, or the graph on the server emulation)

Costs: baked = download size and repetition; kernel = CPU on the audio thread (budget ~10–20 % of one core in total; one kernel is typically < 2 %) and a worklet module to load; graph = native and cheap except convolvers and HRTF panners (a few dozen of each at most).

Hybrid is the norm: bake what is expensive and fixed, keep one or two responsive layers live, do placement and space in the graph. Example — a vehicle: baked ignition and door one-shots, Engine kernel with rpm/load from the simulation, SpatialSource for position and Doppler, zone reverb from the AmbienceMixer.

2. Baked assets

import * as sd from '<skill>/lib/node.js';
const buf = sd.master(sd.impact({ character: 'metal', weight: 0.8, seed: 4 }), { target: -16 });
sd.save('out/hit_metal_01.wav', buf, { bitDepth: 16, lens: 'impact', meta: { gen: 'impact', seed: 4 } });

3. Kernels

A kernel is a class with static params = { name: [default, min, max, description] }, a constructor (sr, opts), set(name, value) and process(L, R, n). The same instance code runs:

Writing one:

import { Kernel, register } from '<skill>/lib/core/kernel.js';
export class Geiger extends Kernel {
  static params = { rate: [5, 0, 2000, 'clicks per second'], tone: [2500, 200, 8000, 'click pitch Hz'], gain: [1, 0, 4, ''] };
  constructor(sr, opts) { super(sr, opts); this.a = 0; this.ph = 0; }
  process(L, R, n) {
    this.smooth(n);                                   // glide params toward their targets
    const p = this.p, r = this.rng, k = Math.exp(-1 / (this.sr * 0.004));
    for (let i = 0; i < n; i++) {
      if (r.next() < p.rate / this.sr) this.a = r.range(0.5, 1);
      this.ph += 2 * Math.PI * p.tone / this.sr; const y = Math.sin(this.ph) * this.a * p.gain; this.a *= k;
      L[i] = y; R[i] = y;
    }
  }
}
register('geiger', Geiger);

Rules of the audio thread: no allocation in process (create arrays in the constructor), no Math.random (use this.rng — reproducible), no I/O, guard recursive filters against NaN, smooth every parameter that a user can move (this.smooth), keep per-sample work proportional to voices you control. A page UI can be generated from Class.params (see templates/browser/index.html): that table is the contract between sound designer and integrator.

4. Native Web Audio graph

lib/webaudio/index.js (works with any BaseAudioContext):

5. Rendering Web Audio on a server

OptionNotes
Kernel path (renderKernel, spatialize, renderScene, lib/core/fx)no Web Audio at all; fastest; deterministic. Default for producing assets
web-audio-api (npm, pure JS, WPT-tested)bun add web-audio-api in the skill folder (already an optional dependency). renderOffline() picks it up automatically. Full node set incl. AudioWorklet, HRTF panner, convolver. Speed: simple graphs ≫ realtime, convolver/HRTF-heavy graphs ≈ 0.5–2× realtime. Use it to render and test the exact graph a page will run
node-web-audio-api (npm, Rust bindings)faster DSP; needs system audio libraries on Linux (e.g. libpipewire-0.3), works out of the box on macOS/Windows; Node only. webAudio() falls back to it if installed
Headless Chromium (Playwright/Puppeteer: run OfflineAudioContext in the page, return the samples)bit-exact browser behaviour; heavy to install. Only when the browser's own implementation is what is under test

Gotcha: on the server an AudioWorkletNode's open MessagePort keeps the process alive; renderOffline closes kernel ports for you — if you build contexts by hand, call node.port.close() or process.exit() when done. Emulations differ slightly from browsers in compressor curves and HRTF data: assert on measurements with tolerances (compare.mjs), not on sample equality.

6. Web Audio practices and traps

7. Handing sounds to game engines