Skip to main content
A SoundDefinition is either a single layer or a multi-layer sound. It’s plain JSON, so the same shape works in defineSound, generated sound files and theme files. Times are in seconds, frequencies in Hz, and detune in cents.

Layer

Source
required
The signal generator. See sources.
Envelope
Amplitude envelope. Defaults to a short 0.5 second fade. See envelope.
Filter | Filter[]
Filters applied before the envelope. See filters.
number
default:"0.5"
Output gain, 0 to 1.
number
Stereo pan, -1 to 1. Don’t combine with panner.
Panner3D
3D position. See 3D panner.
number
Start delay relative to when the sound is triggered.
LFO | LFO[]
Periodic modulation. See LFO.
Effect[]
Effects chain applied after the envelope. See effects.

Multi-layer sound

Layer[]
required
Layers that play together.
Effect[]
Effects applied to the sum of all layers.

Sources

  • frequency (required): a fixed value, or { start, end } for a pitch sweep.
  • detune: cents.
  • fm: frequency modulation. ratio is modulator to carrier, depth is the modulation index.
color: white (default), pink or brown.
harmonics lists the amplitude of each harmonic, starting with the fundamental. frequency works like an oscillator’s.
  • url: fetched, decoded and cached after the first load. Or pass a decoded buffer in code.
  • playbackRate (default 1), detune.
  • loop, loopStart, loopEnd.
{ type: "stream", stream: MediaStream } plays live input such as a microphone. Code only, and only with a real-time AudioContext.
A DC offset (default 1), useful as a control signal.

Envelope

Filters

A biquad filter:
Or an IIR filter: { "type": "iir", "feedforward": number[], "feedback": number[] }.

LFO

Effects

Most effects take a mix from 0 (dry) to 1 (wet).

3D panner

positionX, positionY and positionZ are required. Optional: orientationX/Y/Z, panningModel (HRTF default, or equalpower), distanceModel (inverse default, linear, exponential), maxDistance, refDistance, rolloffFactor, coneInnerAngle, coneOuterAngle, coneOuterGain. Position the listener with setListener or useListener.