AudioListener

The AudioListener interface represents the position and orientation of the unique person listening to the audio scene, and is used in audio spatialization. All PannerNodes spatialize in relation to the AudioListener stored in the BaseAudioContext.listener attribute.

It is important to note that there is only one listener per context and that it isn't an AudioNode.

We see the position, up and front vectors of an AudioListener, with the up and front vectors at 90° from the other.

Properties

Note: The position, forward, and up value are set and retrieved using different syntaxes. Retrieval is done by accessing, for example, AudioListener.positionX, while setting the same property is done with AudioListener.positionX.value. This is why these values are not marked read only, which is how they appear in the specification's IDL.

AudioListener.positionX

Represents the horizontal position of the listener in a right-hand cartesian coordinate system. The default is 0.

AudioListener.positionY

Represents the vertical position of the listener in a right-hand cartesian coordinate system. The default is 0.

AudioListener.positionZ

Represents the longitudinal (back and forth) position of the listener in a right-hand cartesian coordinate system. The default is 0.

AudioListener.forwardX

Represents the horizontal position of the listener's forward direction in the same cartesian coordinate system as the position (positionX, positionY, and positionZ) values. The forward and up values are linearly independent of each other. The default is 0.

AudioListener.forwardY

Represents the vertical position of the listener's forward direction in the same cartesian coordinate system as the position (positionX, positionY, and positionZ) values. The forward and up values are linearly independent of each other. The default is 0.

AudioListener.forwardZ

Represents the longitudinal (back and forth) position of the listener's forward direction in the same cartesian coordinate system as the position (positionX, positionY, and positionZ) values. The forward and up values are linearly independent of each other. The default is -1.

AudioListener.upX

Represents the horizontal position of the top of the listener's head in the same cartesian coordinate system as the position (positionX, positionY, and positionZ) values. The forward and up values are linearly independent of each other. The default is 0.

AudioListener.upY

Represents the vertical position of the top of the listener's head in the same cartesian coordinate system as the position (positionX, positionY, and positionZ) values. The forward and up values are linearly independent of each other. The default is 1.

AudioListener.upZ

Represents the longitudinal (back and forth) position of the top of the listener's head in the same cartesian coordinate system as the position (positionX, positionY, and positionZ) values. The forward and up values are linearly independent of each other. The default is 0.

Methods

AudioListener.setOrientation()

Sets the orientation of the listener.

AudioListener.setPosition()

Sets the position of the listener.

Note: Although these methods are deprecated they are currently the only way to set the orientation and position in Firefox, Internet Explorer and Safari.

Deprecated features

AudioListener.dopplerFactor

A double value representing the amount of pitch shift to use when rendering a doppler effect.

AudioListener.speedOfSound

Is a double value representing the speed of sound, in meters per second.

In a previous version of the specification, the dopplerFactor and speedOfSound properties and the setPosition() method could be used to control the doppler effect applied to AudioBufferSourceNodes connected downstream — these would be pitched up and down according to the relative speed of the PannerNode and the AudioListener. These features had a number of problems:

  • Only AudioBufferSourceNodes were pitched up or down, not other source nodes.
  • The behavior to adopt when an AudioBufferSourceNode was connected to multiple PannerNodes was unclear.
  • Because the velocity of the panner and the listener were not AudioParams, the pitch modification could not be smoothly applied, resulting in audio glitches.

Because of these issues, these properties and methods have been removed.

The setOrientation() and setPosition() methods have been replaced by setting their property value equivilents. For example setPosition(x, y, z) can be achieved by setting positionX.value, positionY.value, and positionZ.value respectively.

Example

See BaseAudioContext.createPanner() for example code.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
AudioListener
14
12
25
No
15
6
≤37
18
25
14
Yes
1.0
dopplerFactor
14-56
12-79
25-63
No
15-43
6-14.1
≤37-56
18-56
25-63
14-43
6-14.5
1.0-6.0
forwardX
52
79
No
Supports a deprecated way of setting orientation - the setOrientation() method.
No
39
14.1
52
52
No
Supports a deprecated way of setting orientation - the setOrientation() method.
41
14.5
6.0
forwardY
52
79
No
Supports a deprecated way of setting orientation - the setOrientation() method.
No
39
14.1
52
52
No
Supports a deprecated way of setting orientation - the setOrientation() method.
41
14.5
6.0
forwardZ
52
79
No
Supports a deprecated way of setting orientation - the setOrientation() method.
No
39
14.1
52
52
No
Supports a deprecated way of setting orientation - the setOrientation() method.
41
14.5
6.0
positionX
52
79
No
Supports a deprecated way of setting orientation - the setOrientation() method.
No
39
14.1
52
52
No
Supports a deprecated way of setting orientation - the setOrientation() method.
41
14.5
6.0
positionY
52
79
No
Supports a deprecated way of setting orientation - the setOrientation() method.
No
39
14.1
52
52
No
Supports a deprecated way of setting orientation - the setOrientation() method.
41
14.5
6.0
positionZ
52
79
No
Supports a deprecated way of setting orientation - the setOrientation() method.
No
39
14.1
52
52
No
Supports a deprecated way of setting orientation - the setOrientation() method.
41
14.5
6.0
setOrientation
14
12
25
No
15
6
≤37
18
25
14
Yes
1.0
setPosition
14
12
25
No
15
6
≤37
18
25
14
Yes
1.0
speedOfSound
14-56
12-79
25-63
No
15-43
6-14.1
≤37-56
18-56
25-63
14-43
6-14.5
1.0-6.0
upX
52
79
No
Supports a deprecated way of setting orientation - the setOrientation() method.
No
39
14.1
52
52
No
Supports a deprecated way of setting orientation - the setOrientation() method.
41
14.5
6.0
upY
52
79
No
Supports a deprecated way of setting orientation - the setOrientation() method.
No
39
14.1
52
52
No
Supports a deprecated way of setting orientation - the setOrientation() method.
41
14.5
6.0
upZ
52
79
No
Supports a deprecated way of setting orientation - the setOrientation() method.
No
39
14.1
52
52
No
Supports a deprecated way of setting orientation - the setOrientation() method.
41
14.5
6.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/AudioListener