Skip to content

Mix Tracks Live: Buses, Sends and Sidechains ​

The engine carries its own lane mixer, so a playback engine can mix the tracks it plays without a second mixing pass. This page covers the mixing side of RealtimeEngine: lanes, buses and channel strips, the monitor taps that feed a cue bus, group routing and sidechains, live strip controls, and surround group buses with their wide meters.

Transport, telemetry, capture, offline render, automation, clips and MIDI are on the Realtime Engine Guide. The strip model itself is the one the standalone Mixing Engine uses.

Track lanes, buses, and channel strips ​

The engine carries its own realtime-safe lane mixer, so a playback engine can mix the tracks it plays without a second mixing pass. Each track occupies a lane; lanes can feed aux sends into numbered buses; and tracks, buses, and the master each own a full channel strip — the same strip model (EQ, inserts, fader, pan, sends) as the Mixing Engine. Plugin delay compensation (PDC) is recomputed automatically whenever the lane layout is republished.

A track lane therefore has two gain layers. The first is the lane's channel strip, with its own trim, EQ, inserts, fader, and pan (set through setStrip and the setStrip* calls). After it the lane mixer applies a lane fader, the mute/solo gate, and a lane pan (the faderDb / pan automation targets, setTrackSoloMute, and setStripFaderDb / setStripPan). The cue taps and the sidechain key below are defined relative to these two layers.

typescript
// Declare buses first, then the lane order with sends.
engine.setTrackBuses([{ busId: 1, gainDb: 0 }]);
engine.setTrackLanes([
  { trackId: 1, sends: [{ busId: 1, levelDb: -12, enabled: true }] },
  { trackId: 2 }, // a lane with no sends
]);

// Strips take mixer scene objects. A track or master strip is a MixSceneStripInput
// (setStrip takes a track id or 'master'); a bus strip is a MixSceneBusInput.
engine.setStrip(1, vocalStrip);
engine.setBusStrip(1, reverbBus);   // the bus must already exist via setTrackBuses
engine.setStrip('master', masterStrip);

// Tweak one embedded EQ band without rebuilding the strip (band as in eq.parametric):
engine.setStripEqBand(1, 0, { type: 'peak', frequencyHz: 250, gainDb: -2, q: 1.0, enabled: true });

// Bypass an insert in place; resetOnBypass also resets its state.
engine.setStripInsertBypassed(1, 0, { bypassed: true, resetOnBypass: true });

// Queueable solo/mute: track id, then an optional renderFrame (omitted = next block head).
engine.setTrackSoloMute(1, { solo: true, mute: false });
python
engine.set_track_buses([{"bus_id": 1, "gain_db": 0}])
engine.set_track_lanes([
    {"track_id": 1, "sends": [{"bus_id": 1, "level_db": -12, "enabled": True}]},
    {"track_id": 2},
])

engine.set_strip(1, vocal_strip)
engine.set_bus_strip(1, reverb_bus)
engine.set_strip("master", master_strip)

# Strip and band dictionaries use the camelCase keys of the scene format.
engine.set_strip_eq_band(1, 0, {"type": "peak", "frequencyHz": 250, "gainDb": -2, "q": 1.0, "enabled": True})
engine.set_strip_insert_bypassed(1, 0, bypassed=True, reset_on_bypass=True)
engine.set_track_solo_mute(1, solo=True, mute=False)

Lane order follows setTrackLanes(...)

On the raw RealtimeEngine, a successful setTrackLanes(...) call may reorder, remove, or add tracks. The SonareEngine facade's setTrackLanes is append-only: keep every declared id in its order and append new ones; reordering or removing is refused (see AudioWorklet notes). Queued commands, sends, insert automation, and lane state follow the track identity; lane indices are the current positions after the call. On the raw RealtimeEngine, every call rebuilds each lane's sends from scratch from whatever sends array that lane's entry passed — omitting sends clears that lane's sends rather than leaving them untouched. The SonareEngine worklet facade preserves sends on omission by keeping its own JS-side send cache and resending the full list underneath on every call. Re-read any numeric lane or track-insert selector after a topology change.

MAX_TRACK_LANES (Node, WASM and Python; C SONARE_ENGINE_MAX_TRACK_LANES) is the most lanes setTrackLanes accepts, 32; a longer list is refused with at most 32 track lanes are supported. To change one lane's sends or output bus without restating the lane list, use setTrackSends(trackId, sends) and setTrackOutputBus(trackId, busId) (C sonare_engine_set_track_sends / sonare_engine_set_track_output_bus, Python set_track_sends / set_track_output_bus). Each leaves the lane's other fields and every other lane unchanged, and an unchanged send list keeps its in-flight level ramps. They throw for an unknown track id, an undeclared bus, a duplicate send bus, or a send level outside the send range. On the raw RealtimeEngine the lane must already be declared through setTrackLanes; the worklet facade's setTrackSends creates the lane when the track has none.

A centered mono lane plays at unity for every pan law, including a lane whose strip the engine created for a send or insert or built from a scene spec; panning it still moves it.

Structural strip calls belong on the control thread

setTrackLanes, setTrackBuses, setStrip and setBusStrip build internal structures and must not run concurrently with process(...) — issue them between renders or while stopped. The lightweight live controls are setTrackSoloMute (queued sample-accurately) and the EQ-band updates, which mutate one band in place.

A bus insert chain sees the summed signal, once ​

A bus insert chain is stateful and usually non-linear: a compressor's envelope, a saturator's transfer curve, a reverb's tail. It therefore has to see the sum of everything feeding the bus, once per block. A compressor fed two partial signals separately is not the same processor as one fed their sum, and a reverb run twice would advance its tail twice per block.

Clip audio and hosted-instrument audio are two contributors to the same buses, so they are aggregated into one block before any strip, send, or bus chain runs. Every lane, every bus chain, and every strip smoother along the way then advances exactly once per block, however many sources produced audio. That merged pass needs a non-empty instrument rack and inactive plugin delay compensation. With PDC in play the clip bus is rendered into its own scratch buffer and delayed so it lands phase-aligned with the internally delayed instruments. A project with no hosted instruments has only one contributor and needs no merge.

With a saturating or compressing insert on a group bus, this is the difference between hearing it act on the group and hearing it act on each source that feeds the group.

Solo and mute ramps take their full time

Each lane is finished once per block, so its fader, pan, and gate smoothers are not advanced a second time by another source; within the block they still run sample by sample. The gate — the smoother behind solo and mute — has a 10 ms time constant, against 5 ms for the lane fader and pan, so a solo or mute change is a short audible ramp rather than a step. These times are fixed; setParamSmoothingMs does not change them.

ENGINE · LANE MIXERIDLE
The engine lane mixer — faders and mutes inside the playback engine

Three MIDI clips loop through the realtime engine: each track occupies a lane with its own channel strip, and the lanes sum into a master strip carrying the engine’s true-peak limiter. The faders call the strip setters and the mutes call setSoloMute — every band below is the engine’s separate solo previews through the master chain, re-rendered through renderOffline as you move the controls.

Lead fader
0 dB
Bass fader
3 dB
Drums fader
-8 dB
Mute lead
Mute bass
Mute drums

Track monitor taps: off, PFL, and AFL ​

Each configured track lane can contribute to a separate cue/monitor bus. Queue a mode with setTrackMonitorMode(trackId, mode, renderFrame?); trackId is a declared track id (an unknown one is a RangeError); renderFrame, when omitted, applies at the next block head, and mode is 'off', 'pfl', or 'afl' (a number is a TypeError).

  • off: the lane contributes nothing to the monitor bus.
  • PFL (pre-fader listen, see buses and sends): taps after the lane strip (including the strip's own fader) and its plugin-delay compensation, but before the lane fader, gate, and pan. It remains audible there when the lane is muted or solo-gated.
  • AFL (after-fader listen): taps after the fader, gate, and pan. For a surround lane it is after fader/gate and the surround plane placement; stereo AFL is post-pan.

PFL behaves like a pre-fader send and AFL like a post-fader send. The demo below lets you hear the difference when the fader moves.

MIXER · SENDSIDLE
Pre-fader vs post-fader sends — drag the fader

One channel feeds two sends and the main output. Pull the channel fader down: the POST-fader send and the MAIN output follow it, because they are tapped after the fader; the PRE-fader send is tapped before it and stays put. Press play to hear it — the dry tone (post-fader) fades out while the pre-fader send (a stand-in for a reverb/aux return) keeps sounding even with the fader all the way down. That is why a vocal reverb fed pre-fader does not disappear when you ride the vocal down — the classic routing surprise.

Channel fader
0 dB
Where PFL and AFL tap the lane
pre-faderpost-faderLane strip + PDCFader, gate, panMain outputPFL tapAFL tapCue / monitor bus
PFL listens before the fader, gate, and pan, so it stays audible on a muted lane; AFL listens after them.

The monitor bus sums every lane with a PFL/AFL tap. The ordinary process(...) path folds that bus into the main output for compatibility, so a cued lane is heard there twice (at unity, a PFL lane comes out 6 dB louder) and a muted lane under PFL still reaches the main output. Offline renders, bounces, stem bounces and freezes contain the program output only, whatever the PFL/AFL or solo monitor state. Call process(..., { withMonitor: true }) (or build the worklet engine with cueOutput: true) whenever the program and cue outputs must stay separate. The default fold into the main output doubles cued lanes.

typescript
engine.setTrackMonitorMode(1, 'pfl');
const { output, monitor } = engine.process([leftBlock, rightBlock], { withMonitor: true });
engine.setTrackMonitorMode(1, 'off');

WASM and Node return { output, monitor }; Python uses set_track_monitor_mode(1, 'afl') and receives the same result from process(channels, with_monitor=True). In Python, process and render_offline return float32 NumPy arrays. The C entry point is sonare_engine_set_track_monitor_mode.

Send PFL/AFL to a separate cue output ​

On the worklet SonareEngine, pass cueOutput: true when creating the node to give it a second output carrying only the cue bus; route output 0 to the program destination and output 1 to headphones or another device. Without this option the node keeps one output and the folded mix, sample for sample.

typescript
import { SonareEngine } from '@libraz/libsonare/worklet';

const engine = await SonareEngine.create(audioCtx, {
  moduleUrl: '/sonare-engine-worklet.js',
  numChannels: 2,
  cueOutput: true,
});
engine.setTrackMonitorMode(trackId, 'pfl');
engine.node.connect(audioCtx.destination, 0);
engine.node.connect(cueDestination, 1);

For a custom zero-copy worklet path, call prepareChannels(...) and prepareMonitorChannels(...) from a message handler, before audio processing begins. On each render block, call processPrepared(numFrames, { withMonitor: true }) and read the program and cue views with channelBuffer(...) and monitorChannelBuffer(...). The preparation calls allocate; the prepared processing path is allocation-free. process(channels, { withMonitor: true }) remains the copy-in alternative outside that hot path.

Group routing, sidechains, and live strip controls ​

Beyond the lane/send graph (a sidechain key lets one signal drive another lane's compressor, which is how ducking works), a few realtime-safe controls reshape routing and pan without rebuilding a strip. The diagram shows where each one attaches:

Group routing and sidechain key taps
outputBusIdoutputBusIdafter strip,before fadersidechain keysend, preFadersend, postFaderbefore gainDbsidechain keyLane stripFader, gate, panBus insertsBus gainDbMasterLane key tapBus key tap
A lane feeds a bus through its output and its sends; a bus feeds the master or another bus the same way. Key taps are read before the lane fader and before the bus gainDb. A destination narrower than its source receives a BS.775 downmix.
GoalRaw RealtimeEngineSonareEngine worklet API
Fold a lane into a group bus (or pass busId 0 to restore it to the master mix)lane outputBusId in setTrackLanes(...) (0 or absent = master mix), or setTrackOutputBus(trackId, busId) for one lane (null routes to the master mix)setTrackOutputBus(target, busId) (null restores the master mix)
Replace one lane's aux sends (an empty array clears them)setTrackSends(trackId, sends)setTrackSends(target, sends)
Fold a bus into another bus, or send it a copybus outputBusId and sends in setTrackBuses(...) (0/absent output = master mix)same fields on setTrackBuses(...)
Check a sidechain binding without applying itcanSetStripSidechain(ref, insertIndex, source) (ref is a track id or 'master'), canSetBusSidechain(busId, insertIndex, source)same names
Key a strip's insert off a track or a bus (ducking)setStripSidechain(ref, insertIndex, source) (source is { kind: 'track' | 'bus', id }, null clears)same
Key a bus insert off a track or another bussetBusSidechain(busId, insertIndex, source) (null clears)same
Pan a stripsetStripPan(ref, pan)setStripPan(target, pan)
Pan law / pan modesetStripPanLaw(...), setStripPanMode(...)same names
Independent L/R (dual) pansetStripDualPan(ref, left, right)same
Per-strip sample delaysetStripChannelDelaySamples(ref, samples)same
Set one insert parameter by namesetStripInsertParam(ref, insertIndex, { name, value }) (bus: setBusInsertParam(busId, ...))same names
Bypass an insertsetStripInsertBypassed(ref, insertIndex, { bypassed, resetOnBypass? }) (bus: setBusInsertBypassed(busId, ...))same names

Bus pan, pan law, pan mode and dual pan have setBusPan, setBusPanLaw, setBusPanMode and setBusDualPan.

setStripInsertParam(...) is the realtime automation entry point — it addresses a parameter by the key reported by masteringInsertParamInfo(name), so a host can change an insert's automatable parameters live without rebuilding the strip. On the worklet API, target is a track id or name.

The kind of a sidechain source is 'track' (a lane's post-strip signal, before its lane fader) or 'bus' (a bus's processed signal, before its own gainDb, folded to stereo when it is wider); a source id of 0 is a RangeError, and Python takes the same names on set_strip_sidechain / set_bus_sidechain. A master insertIndex counts its pre-fader inserts first, then its post-fader ones, the same order every other master insert setter uses. Both keys share the lane sidechain binding table (32 entries) and are control-thread-only, like setTrackBuses itself.

A lane sidechain key is taken from the source lane after its strip and before its lane fader, then delay-compensated to the destination strip input. The engine renders lanes in sidechain-key order, so the result is independent of the order passed to setTrackLanes(...) and of the render block size. A self-key, a cycle, a full binding table, or an alignment beyond the delay ceiling is refused and leaves the binding unchanged. The compensation is included in the reported engine latency. setStripChannelDelaySamples(...) shifts only that strip; it does not become PDC or change the reported latency.

MIXER · SIDECHAIN DUCKIDLE
Ducking: a voice pulls the music bed down

A voice (top) keys dynamics.sidechainRouter on a music bed, as in the commentaryDucking scene. The middle lane is the bed before (grey) and after (teal) the duck; the bottom lane is the gain reduction between them, capped at 18 dB. At the defaults the bed sits about 10 dB down under the voice, but the 100 ms release lets it swell back to about −2 dB in each 150 ms gap between phrases: that swing is the pumping. Raise the release to 500 ms and the bed stays near −11 dB through the sentence, coming back only in the long pause. Press play to hear the mix.

Release
100 ms
Threshold
-30 dB
Ratio
4
typescript
// Route bus 2's output into bus 1, with a pre-fader send to the same bus,
// then duck bus 1's compressor off bus 2's own signal.
engine.setTrackBuses([
  { busId: 1, gainDb: 0 },
  { busId: 2, gainDb: -6, outputBusId: 1, sends: [{ busId: 1, levelDb: -12, sendTiming: 'preFader' }] },
]);
engine.setBusStrip(1, busCompBus);          // insert 0 on the bus is a compressor
engine.setStrip('master', masterCompStrip); // insert 0 on the master is a compressor
engine.setTrackLanes([{ trackId: 1 }, { trackId: 2 }]);
engine.setBusSidechain(1, 0, { kind: 'bus', id: 2 });         // insert 0 on bus 1, keyed from bus 2
engine.setStripSidechain('master', 0, { kind: 'track', id: 1 }); // insert 0 on the master, keyed from track 1

Each canSet*Sidechain call takes the arguments of its setter and returns a SidechainCheck, { ok, reason? }, without changing anything; reason is absent exactly when ok is true, and otherwise names the first check the setter would fail: 'invalidTarget', 'insertOutOfRange', 'undeclaredSource', 'invalidSourceKind', 'selfKey', 'cycle', 'tableFull', or 'planRefused'. A UI can use it to gray out an impossible key source before offering it. insertOutOfRange on a lane means its strip has no such insert (a lane with no strip has none), and undeclaredSource that the source track has no declared lane; the bus form reports the same. planRefused means only an alignment past the delay ceiling or an overflow. Python has the same two methods (can_set_strip_sidechain, can_set_bus_sidechain) returning a SidechainCheck whose reason is the same value in snake_case ('self_key', 'insert_out_of_range', ...); they are control-thread only.

typescript
engine.setTrackLanes([{ trackId: 1 }, { trackId: 2 }]);
engine.setStrip(1, compStrip); // insert 0 on track 1 is a compressor
engine.canSetStripSidechain(1, 0, { kind: 'track', id: 1 });  // { ok: false, reason: 'selfKey' }
engine.canSetStripSidechain(1, 0, { kind: 'track', id: 2 });  // { ok: true }

A bus's output, a send, or a sidechain key that lands on a narrower destination — a smaller bus, the master at its rendered width, or a stereo key tap — is folded through the ITU-R BS.775 downmix the surround section below uses; a wider destination receives the source planes on the same indices. Configuring a bus list is validated as one dependency graph over every output, send, and bus-sourced key: a cycle, a reference to an undeclared bus, a bus routed to itself, or removing a bus a lane still targets is refused and leaves the previous configuration in place.

Surround group buses and wide meters ​

A bus declared with a surround channelLayout ('mono', 'stereo', '5.1' or '7.1') becomes a surround group bus: it sums into the master plane-by-plane and exposes per-plane meters. A lane routed to it is folded to a point source, then placed from its strip surroundPan values. azimuth, divergence, and lfe are active; elevation and distance are reserved. The mixer graph and project bounce render a surround bus at the same width and follow the same rules; only the standalone Mixer (processStereo) stays stereo-only.

A strip fed by a surround bus — the return strip on the far side of a bus output or send — runs at the bus's own width rather than folding it to stereo and re-scattering it: its fader, inserts and sends all act on every plane, and only a strip with a stereo (or narrower) main output keeps its pan and width stages. A destination narrower than a bus's width — another bus, the master at its rendered channel count, or a sidechain key tap, which is always stereo — receives an ITU-R BS.775 downmix (see Channel Formats) rather than the front pair alone; a wider destination receives the source planes on their own indices unchanged. A surround bus, and the master when it is built wider than stereo, refuses a non-default pan or width for the same reason it already refused pan — there is no stereo image on a speaker bed to narrow, widen, or move.

typescript
engine.setTrackBuses([{ busId: 1, channelLayout: '5.1' }]);  // a 5.1 group bus
engine.setTrackLanes([{ trackId: 1, outputBusId: 1 }]);  // route the lane into it
engine.setStrip(1, {});  // the lane needs a strip before it can be placed
engine.setStripSurroundPan(1, { azimuth: -30, divergence: 0, lfe: 0 });
python
engine.set_track_buses([{"bus_id": 1, "channel_layout": "5.1"}])
engine.set_track_lanes([{"track_id": 1, "output_bus_id": 1}])
engine.set_strip(1, {})
engine.set_strip_surround_pan(1, azimuth=-30, divergence=0, lfe=0)

A track lane's sourceChannelLayout must be stereo (the default): setTrackLanes refuses a mono, 5.1, or 7.1 layout with a SonareError coded NotSupported (code 6; Python SonareError; C SONARE_ERROR_NOT_SUPPORTED) because lane audio is always folded from stereo to a point source before surround placement. A C caller zero-initializing SonareEngineTrackLane reads as mono and must set SONARE_CHANNEL_LAYOUT_STEREO.

Move a lane's placement live with setStripSurroundPan(ref, { azimuth, divergence, lfe }) (on RealtimeEngine and, with a track id or name, on the SonareEngine worklet facade). Omitted fields default to a centered point source. A non-finite field, or a track that has a lane but no strip yet (call setStrip first), throws a RangeError (Python SonareValueError). The placement glides with a time constant of about 5 ms rather than clicking, holding total power constant through the move.

Output plane order is the canonical L R C LFE Ls Rs for 5.1 and L R C LFE Ls Rs Lss Rss for 7.1. A SonareEngine with numChannels 6 or 8 renders that many planes, but the Web Audio default destination is 2-channel 'speakers', so the browser mixes them down to stereo unless the app first raises audioContext.destination.channelCount (up to destination.maxChannelCount). The interpretation only matters while the counts differ: 'speakers' has defined down-mixes for mono, stereo, quad and 5.1 sources and falls back to 'discrete' for any other count such as 8, and 'discrete' copies the leading planes and drops the rest. With equal counts the planes pass through unchanged in either mode.

Set outputBusId: 0 in setTrackLanes, or call setTrackOutputBus(1, null) (on the raw engine and on the SonareEngine facade alike), to fold the lane back onto the master mix.

On a main-thread or offline engine, read surround meters with drainMeterTelemetry(maxRecords?), whose records carry every plane and treat a stereo target's left and right as planes 0 and 1; it is the one meter drain. The drains pop the same single-consumer telemetry queue, so call only one per engine instance; running two on one engine makes their records starve each other.

In an AudioWorklet, the SonareEngine meter snapshot of a target wider than stereo keeps its stereo fields and adds numChannels plus the per-channel arrays peakDb, rmsDb, truePeakDbtp, and inputPeakDb, on both the postMessage and the SharedArrayBuffer ring paths. The worklet keeps its meter interval per target, so one target's records never delay another's.