PannerNode
interface represents the position and behavior of an audio source signal in space. It is an
AudioNode
audio-processing module describing its position with right-hand Cartesian coordinates, its movement using a velocity vector and its directionality using a directionality cone.
A
PannerNode
always has exactly one input and one output: the input can be
mono
or
stereo
but the output is always
stereo
(2 channels); you can't have panning effects without at least two audio channels!
| 输入数 |
1
|
|---|---|
| 输出数 |
1
|
| 通道计数模式 |
"clamped-max"
|
| 通道计数 |
2
|
| 通道解释 |
"speakers"
|
PannerNode.PannerNode
PannerNode
对象实例。
继承的特性来自其父级,
AudioNode
.
The orientation and position value are set and retrieved using different syntaxes, since they're stored as
AudioParam
values. Retrieval is done by accessing, for example,
PannerNode.positionX
. While setting the same property is done with
PannerNode.positionX.value
. This is why these values are not marked read only, which is how they appear in the WebIDL.
PannerNode.coneInnerAngle
Is a double value describing the angle, in degrees, of a cone inside of which there will be no volume reduction.
PannerNode.coneOuterAngle
coneOuterGain
属性。
PannerNode.coneOuterGain
coneOuterAngle
attribute. Its default value is
0
, meaning that no sound can be heard.
PannerNode.distanceModel
"linear"
,
"inverse"
and
"exponential"
。默认值为
"inverse"
.
PannerNode.maxDistance
A double value representing the maximum distance between the audio source and the listener, after which the volume is not reduced any further.
PannerNode.orientationX
AudioParam
cannot be directly changed, its value can be altered using its
value
property. The default is value is 1.
PannerNode.orientationY
AudioParam
cannot be directly changed, its value can be altered using its
value
property. The default is value is 0.
PannerNode.orientationZ
AudioParam
cannot be directly changed, its value can be altered using its
value
property. The default is value is 0.
PannerNode.panningModel
An enumerated value determining which spatialisation algorithm to use to position the audio in 3D space.
PannerNode.positionX
AudioParam
cannot be directly changed, its value can be altered using its
value
property. The default is value is 0.
PannerNode.positionY
AudioParam
cannot be directly changed, its value can be altered using its
value
property. The default is value is 0.
PannerNode.positionZ
AudioParam
cannot be directly changed, its value can be altered using its
value
property. The default is value is 0.
PannerNode.refDistance
rolloffFactor
and
distanceModel
.
PannerNode.rolloffFactor
A double value describing how quickly the volume is reduced as the source moves away from the listener. This value is used by all distance models.
继承方法来自其父级
AudioNode
.
PannerNode.setPosition()
AudioListener
object stored in the
AudioContext.listener
attribute.)
PannerNode.setOrientation()
Defines the direction the audio source is playing in.
PannerNode.setVelocity()
PannerNode
had a velocity that could pitch up or down
AudioBufferSourceNode
s connected downstream. This feature was not clearly specified and had a number of issues, so it was removed from the specification.
In the following example, you can see an example of how the
createPanner()
方法,
AudioListener
and
PannerNode
would be used to control audio spatialisation. Generally you will define the position in 3D space that your audio listener and panner (source) occupy initially, and then update the position of one or both of these as the application is used. You might be moving a character around inside a game world for example, and wanting delivery of audio to change realistically as your character moves closer to or further away from a music player such as a stereo. In the example you can see this being controlled by the functions
moveRight()
,
moveLeft()
, etc., which set new values for the panner position via the
PositionPanner()
函数。
To see a complete implementation, check out our panner-node example ( view the source code ) — this demo transports you to the 2.5D "Room of metal", where you can play a track on a boom box and then walk around the boom box to see how the sound changes!
Note how we have used some feature detection to either give the browser the newer property values (like
AudioListener.forwardX
) for setting position, etc. if it supports those, or older methods (like
AudioListener.setOrientation()
) if it still supports those but not the new properties.
// set up listener and panner position information
var WIDTH = window.innerWidth;
var HEIGHT = window.innerHeight;
var xPos = Math.floor(WIDTH/2);
var yPos = Math.floor(HEIGHT/2);
var zPos = 295;
// define other variables
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();
var panner = audioCtx.createPanner();
panner.panningModel = 'HRTF';
panner.distanceModel = 'inverse';
panner.refDistance = 1;
panner.maxDistance = 10000;
panner.rolloffFactor = 1;
panner.coneInnerAngle = 360;
panner.coneOuterAngle = 0;
panner.coneOuterGain = 0;
if(panner.orientationX) {
panner.orientationX.setValueAtTime(1, audioCtx.currentTime);
panner.orientationY.setValueAtTime(0, audioCtx.currentTime);
panner.orientationZ.setValueAtTime(0, audioCtx.currentTime);
} else {
panner.setOrientation(1,0,0);
}
var listener = audioCtx.listener;
if(listener.forwardX) {
listener.forwardX.setValueAtTime(0, audioCtx.currentTime);
listener.forwardY.setValueAtTime(0, audioCtx.currentTime);
listener.forwardZ.setValueAtTime(-1, audioCtx.currentTime);
listener.upX.setValueAtTime(0, audioCtx.currentTime);
listener.upY.setValueAtTime(1, audioCtx.currentTime);
listener.upZ.setValueAtTime(0, audioCtx.currentTime);
} else {
listener.setOrientation(0,0,-1,0,1,0);
}
var source;
var play = document.querySelector('.play');
var stop = document.querySelector('.stop');
var boomBox = document.querySelector('.boom-box');
var listenerData = document.querySelector('.listener-data');
var pannerData = document.querySelector('.panner-data');
leftBound = (-xPos) + 50;
rightBound = xPos - 50;
xIterator = WIDTH/150;
// listener will always be in the same place for this demo
if(listener.positionX) {
listener.positionX.setValueAtTime(xPos, audioCtx.currentTime);
listener.positionY.setValueAtTime(yPos, audioCtx.currentTime);
listener.positionZ.setValueAtTime(300, audioCtx.currentTime);
} else {
listener.setPosition(xPos,yPos,300);
}
listenerData.innerHTML = 'Listener data: X ' + xPos + ' Y ' + yPos + ' Z ' + 300;
// panner will move as the boombox graphic moves around on the screen
function positionPanner() {
if(panner.positionX) {
panner.positionX.setValueAtTime(xPos, audioCtx.currentTime);
panner.positionY.setValueAtTime(yPos, audioCtx.currentTime);
panner.positionZ.setValueAtTime(zPos, audioCtx.currentTime);
} else {
panner.setPosition(xPos,yPos,zPos);
}
pannerData.innerHTML = 'Panner data: X ' + xPos + ' Y ' + yPos + ' Z ' + zPos;
}
注意 : In terms of working out what position values to apply to the listener and panner, to make the sound appropriate to what the visuals are doing on screen, there is quite a bit of math involved, but you will soon get used to it with a bit of experimentation.
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web 音频 API
The definition of 'PannerNode' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
PannerNode
|
Chrome 14 | Edge ≤18 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
PannerNode()
构造函数
|
Chrome 55 | Edge ≤79 | Firefox 53 | IE 不支持 No | Opera 42 | Safari ? |
WebView Android
55
注意事项
|
Chrome Android
55
注意事项
|
Firefox Android 53 | Opera Android 42 | Safari iOS ? |
Samsung Internet Android
6.0
注意事项
|
coneInnerAngle
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
coneOuterAngle
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
coneOuterGain
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
distanceModel
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
maxDistance
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
orientationX
|
Chrome Yes | Edge ≤18 | Firefox 50 | IE 不支持 No | Opera Yes | Safari 不支持 No | WebView Android Yes | Chrome Android Yes | Firefox Android 50 | Opera Android Yes | Safari iOS 不支持 No | Samsung Internet Android Yes |
orientationY
|
Chrome Yes | Edge ≤18 | Firefox 50 | IE 不支持 No | Opera Yes | Safari 不支持 No | WebView Android Yes | Chrome Android Yes | Firefox Android 50 | Opera Android Yes | Safari iOS 不支持 No | Samsung Internet Android Yes |
orientationZ
|
Chrome Yes | Edge ≤18 | Firefox 50 | IE 不支持 No | Opera Yes | Safari 不支持 No | WebView Android Yes | Chrome Android Yes | Firefox Android 50 | Opera Android Yes | Safari iOS 不支持 No | Samsung Internet Android Yes |
panningModel
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
positionX
|
Chrome Yes | Edge ≤18 | Firefox 50 | IE 不支持 No | Opera Yes | Safari 不支持 No | WebView Android Yes | Chrome Android Yes | Firefox Android 50 | Opera Android Yes | Safari iOS 不支持 No | Samsung Internet Android Yes |
positionY
|
Chrome Yes | Edge ≤18 | Firefox 50 | IE 不支持 No | Opera Yes | Safari 不支持 No | WebView Android Yes | Chrome Android Yes | Firefox Android 50 | Opera Android Yes | Safari iOS 不支持 No | Samsung Internet Android Yes |
positionZ
|
Chrome Yes | Edge ≤18 | Firefox 50 | IE 不支持 No | Opera Yes | Safari 不支持 No | WebView Android Yes | Chrome Android Yes | Firefox Android 50 | Opera Android Yes | Safari iOS 不支持 No | Samsung Internet Android Yes |
refDistance
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
rolloffFactor
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
setOrientation
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
setPosition
|
Chrome 14 | Edge 12 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS ? | Samsung Internet Android 1.0 |
setVelocity
弃用
|
Chrome 不支持 14 — 56 | Edge 不支持 12 — 79 | Firefox 不支持 25 — 63 | IE 不支持 No | Opera 不支持 15 — 43 | Safari 6 | WebView Android 不支持 ? — 56 | Chrome Android 不支持 18 — 56 | Firefox Android 不支持 26 — 63 | Opera Android 不支持 14 — 43 | Safari iOS ? | Samsung Internet Android 不支持 1.0 — 6.0 |
完整支持
不支持
兼容性未知
弃用。不要用于新网站。
见实现注意事项。
PannerNode
AnalyserNode
AudioBuffer
AudioBufferSourceNode
AudioContext
AudioContextOptions
AudioDestinationNode
AudioListener
AudioNode
AudioNodeOptions
AudioParam
AudioProcessingEvent
AudioScheduledSourceNode
AudioWorklet
AudioWorkletGlobalScope
AudioWorkletNode
AudioWorkletProcessor
BaseAudioContext
BiquadFilterNode
ChannelMergerNode
ChannelSplitterNode
ConstantSourceNode
ConvolverNode
DelayNode
DynamicsCompressorNode
GainNode
IIRFilterNode
MediaElementAudioSourceNode
MediaStreamAudioDestinationNode
MediaStreamAudioSourceNode
OfflineAudioCompletionEvent
OfflineAudioContext
OscillatorNode
PeriodicWave
StereoPannerNode
WaveShaperNode