The positionZ
property of the PannerNode
interface specifies the Z coordinate of the audio source's position in 3D Cartesian coordinates, corresponding to the depth axis (behind-in front of the listener). The complete vector is defined by the position of the audio source, given as (positionX
, positionY
, positionZ
), and the orientation of the audio source (that is, the direction in which it's facing), given as (orientationX
, orientationY
, orientationZ
).
Depending on the directionality of the sound (as specified using the attributes coneInnerAngle
, coneOuterAngle
, and codeOuterGain
), the orientation of the sound may alter the perceived volume of the sound as it's being played. If the sound is pointing toward the listener, it will be louder than if the sound is pointed away from the listener.
The AudioParam
contained by this property is read only; however, you can still change the value of the parameter by assigning a new value to its AudioParam.value
property.
Syntax
var positionZ = PannerNode.positionZ; PannerNode.positionZ.value = newPositionZ;
Value
An AudioParam
whose value
is the Z coordinate of the audio source's position, in 3D Cartesian coordinates.
Example
The following example starts an oscillator and moves it in front of the listener after 1 second, behind the listener after 2 seconds, and back to the listener's position after 3 seconds. Note that in this case, the change will mainly affect the timbre and perceived volume of the sound.
const context = new AudioContext();
const osc = new OscillatorNode(context);
const panner = new PannerNode(context);
panner.panningModel = 'HRTF';
panner.positionZ.setValueAtTime(1, context.currentTime + 1);
panner.positionZ.setValueAtTime(-1, context.currentTime + 2);
panner.positionZ.setValueAtTime(0, context.currentTime + 3);
osc.connect(panner)
.connect(context.destination);
osc.start(0);
Specifications
Specification | Status | Comment |
Web Audio APIThe definition of 'positionZ' in that specification. | Working Draft |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
positionZ
|
Chrome
Full support Yes |
Edge
Full support ≤18 |
Firefox
Full support 50 |
IE
No support No |
Opera
Full support Yes |
Safari
No support No |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 50 |
Opera Android
Full support Yes |
Safari iOS
No support No |
Samsung Internet Android
Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
See also
PannerNode.positionZ by Mozilla Contributors is licensed under CC-BY-SA 2.5.