Skip to content

Listener

The listener represents the position and orientation of the player. Three Steam Audio uses the listener transform when spatializing sources, running occlusion rays, and simulating reflections.

The world exposes a single listener through world.listener. Update it each frame before calling world.step(delta).

import {
const createWorld: (options: WorldOptions) => Promise<World>
createWorld
} from 'three-steam-audio'
import {
class Camera

Abstract base class for cameras. This class should always be inherited when you build a new camera.

Camera
} from 'three'
const
const world: World
world
= await
function createWorld(options: WorldOptions): Promise<World>
createWorld
({
WorldOptions.audioContext: AudioContext
audioContext
: new
var AudioContext: new (contextOptions?: AudioContextOptions) => AudioContext

The AudioContext interface represents an audio-processing graph built from audio modules linked together, each represented by an AudioNode.

MDN Reference

AudioContext
() })
const
const animate: () => void
animate
= () => {
function requestAnimationFrame(callback: FrameRequestCallback): number
requestAnimationFrame
(
const animate: () => void
animate
)
const world: World
world
.
listener: ListenerImpl
listener
.
ListenerImpl.setPosition(position: Vector3Like): void
setPosition
(
const camera: Camera
camera
.
Object3D<Object3DEventMap>.position: Vector3

Object's local position.

@defaultValuenew THREE.Vector3() - that is (0, 0, 0).

position
)
const world: World
world
.
listener: ListenerImpl
listener
.
ListenerImpl.setOrientation(orientation: QuaternionLike): void
setOrientation
(
const camera: Camera
camera
.
Object3D<Object3DEventMap>.quaternion: Quaternion

Object's local rotation as a

THREE.Quaternion Quaternion

.

@defaultValuenew THREE.Quaternion() - that is (0, 0, 0, 1).

quaternion
)
const world: World
world
.
listener: ListenerImpl
listener
.
ListenerImpl.setCamera(camera: Camera | null): void

Sets the render camera used for perspective-corrected spatialization. Call this after updating the camera projection or world matrix.

setCamera
(
const camera: Camera
camera
)
const world: World
world
.
function step(delta: number): void
step
(1 / 60)
}
const animate: () => void
animate
()

When reflections are enabled, you can ask the simulator to compute listener-centric reverb. This is useful for applying ambient reverberation to parts of your mix.

import {
const createWorld: (options: WorldOptions) => Promise<World>
createWorld
} from 'three-steam-audio'
const world: World
world
.
listener: ListenerImpl
listener
.
ListenerImpl.setReverb(settings: false | ReverbSettings): void
setReverb
({
ReverbSettings.reverbScale?: ThreeBand | undefined
reverbScale
: [1.8, 1.6, 1.3],
})
// Disable reverb later:
const world: World
world
.
listener: ListenerImpl
listener
.
ListenerImpl.setReverb(settings: false | ReverbSettings): void
setReverb
(false)

See Reflections and Reverb for how to render reverb through a ReverbBusNode.