createStereoPanner()
方法在
BaseAudioContext
interface creates a
StereoPannerNode
, which can be used to apply stereo panning to an audio source. It positions an incoming audio stream in a stereo image using a low-cost
equal-power
panning algorithm.
baseAudioContext.createStereoPanner();
A
StereoPannerNode
.
In our
StereoPannerNode example
(
see source code
) HTML we have a simple
<audio>
element along with a slider
<input>
to increase and decrease pan value. In the JavaScript we create a
MediaElementAudioSourceNode
和
StereoPannerNode
, and connect the two together using the
connect()
method. We then use an
oninput
event handler to change the value of the
StereoPannerNode.pan
parameter and update the pan value display when the slider is moved.
Moving the slider left and right while the music is playing pans the music across to the left and right speakers of the output, respectively.
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var myAudio = document.querySelector('audio');
var panControl = document.querySelector('.panning-control');
var panValue = document.querySelector('.panning-value');
pre.innerHTML = myScript.innerHTML;
// Create a MediaElementAudioSourceNode
// Feed the HTMLMediaElement into it
var source = audioCtx.createMediaElementSource(myAudio);
// Create a stereo panner
var panNode = audioCtx.createStereoPanner();
// Event handler function to increase panning to the right and left
// when the slider is moved
panControl.oninput = function() {
panNode.pan.setValueAtTime(panControl.value, audioCtx.currentTime);
panValue.innerHTML = panControl.value;
}
// connect the MediaElementAudioSourceNode to the panNode
// and the panNode to the destination, so we can play the
// music and adjust the panning using the controls
source.connect(panNode);
panNode.connect(audioCtx.destination);
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web 音频 API
The definition of 'createStereoPanner()' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
createStereoPanner
|
Chrome 42 | Edge ≤18 |
Firefox
53
|
IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android Yes | Chrome Android Yes |
Firefox Android
53
|
Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android Yes |
完整支持
不支持
见实现注意事项。
BaseAudioContext
createAnalyser()
createBiquadFilter()
createBuffer()
createBufferSource()
createChannelMerger()
createChannelSplitter()
createConstantSource()
createConvolver()
createDelay()
createDynamicsCompressor()
createGain()
createIIRFilter()
createOscillator()
createPanner()
createPeriodicWave()
createScriptProcessor()
createStereoPanner()
createWaveShaper()
decodeAudioData()
AnalyserNode
AudioBuffer
AudioBufferSourceNode
AudioContext
AudioContextOptions
AudioDestinationNode
AudioListener
AudioNode
AudioNodeOptions
AudioParam
AudioProcessingEvent
AudioScheduledSourceNode
AudioWorklet
AudioWorkletGlobalScope
AudioWorkletNode
AudioWorkletProcessor
BiquadFilterNode
ChannelMergerNode
ChannelSplitterNode
ConstantSourceNode
ConvolverNode
DelayNode
DynamicsCompressorNode
GainNode
IIRFilterNode
MediaElementAudioSourceNode
MediaStreamAudioDestinationNode
MediaStreamAudioSourceNode
OfflineAudioCompletionEvent
OfflineAudioContext
OscillatorNode
PannerNode
PeriodicWave
StereoPannerNode
WaveShaperNode