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 Vector3

@example const a = new THREE.Vector3( 1, 0, 0 ); const b = new THREE.Vector3( 0, 1, 0 ); const c = new THREE.Vector3(); c.crossVectors( a, b );

Vector3
,
class Quaternion

Implementation of a quaternion. This is used for rotating things without incurring in the dreaded gimbal lock issue, amongst other advantages.

@example const quaternion = new THREE.Quaternion(); quaternion.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), Math.PI / 2 ); const vector = new THREE.Vector3( 1, 0, 0 ); vector.applyQuaternion( quaternion );

Quaternion
} 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: Listener
listener
.
Listener.setPosition: (position: Vector3Like) => void
setPosition
(
const camera: {
position: Vector3;
quaternion: Quaternion;
}
camera
.
position: Vector3
position
)
const world: World
world
.
listener: Listener
listener
.
Listener.setOrientation: (orientation: QuaternionLike) => void
setOrientation
(
const camera: {
position: Vector3;
quaternion: Quaternion;
}
camera
.
quaternion: Quaternion
quaternion
)
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: Listener
listener
.
Listener.setReverb: (settings: false | ReverbSettings) => void
setReverb
({
ReverbSettings.enabled?: boolean | undefined
enabled
: true,
ReverbSettings.reverbScale?: ThreeBand | undefined
reverbScale
: [1.8, 1.6, 1.3],
})
// Disable reverb later:
const world: World
world
.
listener: Listener
listener
.
Listener.setReverb: (settings: false | ReverbSettings) => void
setReverb
(false)

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