Audio · class

AmbientLoop

Explained in Your first game.

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

Constructor

new

constructor(scheduleAt: ScheduleClock, source: AudioBufferSourceNode, gainNode: GainNode, panNode: StereoPannerNode | null)
ParameterTypeDescription
scheduleAtScheduleClockthe instant this loop's changes land on. See ScheduleClock.
sourceAudioBufferSourceNodethe looping buffer source, already started.
gainNodeGainNodeits level, initially silent.
panNodeStereoPannerNode | nullpresent only where the browser supports stereo panning.

Methods

setGain

setGain(gain: number): void

0 is silent, 1 is the buffer at its authored level.

ParameterTypeDescription
gainnumber

setRate

setRate(rate: number): void

Pitch the bed, for a loop whose state should be audible.

ParameterTypeDescription
ratenumber
More

Ramped like gain and pan rather than set, because a stepped playback rate on a continuous source is a click. Change-gated by the same rule: a rate written every frame would schedule sixty ramps a second.

setPan

setPan(pan: number): void

-1 hard left, 0 centre, 1 hard right. A no-op without stereo panning.

ParameterTypeDescription
pannumber

stop

stop(): void