World
A World is created by createWorld() and is the factory for sources, audio nodes, reflection buses, and reverb buses. It also owns the acoustic scene and the listener.
createWorld(options)
Section titled “createWorld(options)”async function createWorld(options: WorldOptions): Promise<World>Creates and initializes a world. This function loads the Steam Audio WASM module, fetches the AudioWorklet processor, and adds it to the provided AudioContext.
WorldOptions
Section titled “WorldOptions”audioContext
: Required. The AudioContext that all audio nodes created from this world will use.
maxSources
: Maximum number of sources that can exist simultaneously. Default: 32.
frameSize
: Number of samples processed per audio frame. Default: 1024.
simulationRate
: How often direct simulation runs, in Hz. Default: 60.
reflectionRate
: How often reflection simulation runs, in Hz. Default: 10.
quality
: Quality preset that affects maxOcclusionSamples. One of 'low', 'medium', 'high'. Default: 'medium'.
reflections
: false to disable reflections, or an object with upper bounds:
maxRays— default4096maxDuration— default2maxOrder— default1diffuseSamples— default32
simulation
: Advanced simulation settings, including maxRays, maxDuration, maxOrder, diffuseSamples, maxOcclusionSamples, rayBatchSize, and pathingVisibilitySamples.
moduleFactory
: Optional custom factory used to instantiate the Emscripten module.
Properties
Section titled “Properties”world.audioContext
: The AudioContext passed to createWorld.
world.listener
: The world’s Listener.
world.scene
: The world’s AcousticScene.
Methods
Section titled “Methods”createSource(settings?)
Section titled “createSource(settings?)”world.createSource(settings?: SourceSettings): SourceCreates a new source. Throws if maxSources would be exceeded. See SourceSettings.
createNode(source)
Section titled “createNode(source)”world.createNode(source: Source): SteamAudioNodeCreates an AudioWorklet node for the given source. The source must have been created by this world.
createReflectionBus(settings?)
Section titled “createReflectionBus(settings?)”world.createReflectionBus(settings?: ReflectionBusSettings): ReflectionBusNodeCreates a bus for rendering per-source reflections. Requires reflections to be enabled for the world.
createReverbBus(settings?)
Section titled “createReverbBus(settings?)”world.createReverbBus(settings?: ReverbBusSettings): ReverbBusNodeCreates a bus for rendering listener reverb. Requires reflections to be enabled for the world.
setReflectionSettings(settings)
Section titled “setReflectionSettings(settings)”world.setReflectionSettings(settings: RuntimeSimulationSettings): voidTunes reflection simulation at runtime. All values are clamped to the maximums declared in WorldOptions.
settings.rays
: Number of reflection rays to trace. Must not exceed maxRays.
settings.bounces
: Maximum number of bounces per ray.
settings.duration
: Simulation duration in seconds. Must not exceed maxDuration.
settings.order
: Ambisonic order. Must not exceed maxOrder.
settings.irradianceMinDistance
: Minimum distance for irradiance sampling.
step(delta)
Section titled “step(delta)”world.step(delta: number): voidAdvances simulation by delta seconds. Runs direct simulation and, if enabled, reflection simulation according to their configured rates. Returns early if the AudioContext is not running.
dispose()
Section titled “dispose()”world.dispose(): voidReleases all native resources, audio nodes, buses, sources, and scene geometry.
SteamAudioError
Section titled “SteamAudioError”class SteamAudioError extends Error { operation: string status: string}Thrown when a world, source, or audio node operation fails. operation identifies the function that failed, and status contains a short description of the failure.