Audio · class

MixBus

Explained in Your first game.

class MixBus
import { MixBus } from '@driftengine/audio';

Constructor

new

constructor(name: string, context: BaseAudioContext, scheduleAt: ScheduleClock, options?: BusOptions)
ParameterTypeDescription
namestring
contextBaseAudioContext
scheduleAtScheduleClock
options?BusOptions

Properties

NameTypeDescription
namereadonlystring
inputreadonlyGainNodeThe fader. Sources and child buses connect here.
tapreadonlyGainNodeWhere sends listen from. Unity, always.
outputreadonlyGainNodeWhat the parent hears. Unity, always.
parentreadonlyMixBus | null
onSoloChanged(() => void) | nullSet by the console when it adopts this bus, so a solo anywhere re-resolves the whole tree.

Accessors

NameTypeDescription
childrengetreadonly MixBus[]
levelgetnumber
mutedgetboolean
soloedgetboolean
sendTargetsgetreadonly MixBus[]Every return this bus feeds, for a snapshot to capture.
duckedTogetnumberWhat this bus is ducked to, 1 when it is not. See duck.

Methods

feedFromInput

feedFromInput(node: AudioNode): void

Feed a node from this bus's signal as it arrives, before any insert. See inputTaps.

ParameterTypeDescription
nodeAudioNode

insert

insert(insert: MixInsert, options?: InsertOptions): void

Append a stage to this bus's own signal path. See InsertOptions.postSend.

ParameterTypeDescription
insertMixInsert
options?InsertOptions

send

send(returnBus: MixBus, amount: number): void

Feed a return bus from this one, at amount.

ParameterTypeDescription
returnBusMixBus
amountnumber
More

Idempotent per target: asking twice moves the existing send rather than building a second one, because this is called from per-frame code in every consumer that has ever used it and a send node per frame is a graph that grows until the page stops.

sendAmount

sendAmount(returnBus: MixBus): number

What this bus was last asked to send to that return, or 0 if it has never sent to it.

ParameterTypeDescription
returnBusMixBus

setLevel

setLevel(level: number): void
ParameterTypeDescription
levelnumber

fadeLevel

fadeLevel(level: number, seconds: number): void

Move to a level over an explicit time, rather than at the fader's own smoothing.

ParameterTypeDescription
levelnumber
secondsnumber
More

A fader is a control and wants to feel immediate; a snapshot recall is an edit and takes as long as it was asked to take. Both write the same mirrored level, so the mix knows where it is either way — which AudioGraph.fadeMusic deliberately does not do, because a fade there is part of an edit that has to return to the player's setting when it is over.

duck

duck(factor: number, seconds: number): void

Move over the top of the fader and back, without moving the fader.

ParameterTypeDescription
factornumber
secondsnumber
More

duck(0, 0.4) takes this bus away over four tenths of a second; duck(1, 0.4) brings it back to exactly whatever the fader is set to, including a setting the player changed in between. Cost: this is a second thing multiplying into one parameter, so a caller that ducks and forgets to release leaves a bus quiet with a fader that says otherwise — which is why duckedTo is readable rather than private.

setMute

setMute(muted: boolean): void
ParameterTypeDescription
mutedboolean

setSolo

setSolo(soloed: boolean): void
ParameterTypeDescription
soloedboolean

setSoloGate

setSoloGate(gate: number): void

Written by the console alone. 1 is audible, 0 is silenced by somebody else's solo.

ParameterTypeDescription
gatenumber