The StereoPannerNode
interface of the Web Audio API represents a simple stereo panner node that can be used to pan an audio stream left or right. It is an AudioNode
audio-processing module that positions an incoming audio stream in a stereo image using a low-cost equal-power panning algorithm.
The pan
property takes a unitless value between -1
(full left pan) and 1
(full right pan). This interface was introduced as a much simpler way to apply a simple panning effect than having to use a full PannerNode
.
[[File:../../../../../media.prod.mdn.mozit.cloud/attachments/2015/02/11/10105/76d371b11a6ea444d7c79281438e4e04/StereoPannerNode.png]]
Number of inputs | 1
|
Number of outputs | 1
|
Channel count mode | "clamped-max"
|
Channel count | 2
|
Channel interpretation | "speakers"
|
Constructor
StereoPannerNode()
- Creates a new instance of a
StereoPannerNode
object.
Properties
Inherits properties from its parent, AudioNode
.
StereoPannerNode.pan
Read only- Is an a-rate
AudioParam
representing the amount of panning to apply.
Methods
No specific method; inherits methods from its parent, AudioNode
.
Example
In our [[../../../../../../mdn.github.io/webaudio-examples/stereo-panner-node/index|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
and a 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);
Specifications
Specification | Status | Comment |
Web Audio APIThe definition of 'StereoPannerNode' in that specification. | Working Draft | Initial definition |
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
StereoPannerNode
|
Chrome
Full support 41 |
Edge
Full support 12 |
Firefox
Full support 37 |
IE
No support No |
Opera
Full support 28 |
Safari
No support No |
WebView Android
Full support 41 |
Chrome Android
Full support 41 |
Firefox Android
Full support 37 |
Opera Android
Full support 28 |
Safari iOS
No support No |
Samsung Internet Android
Full support 4.0 |
StereoPannerNode() constructor
|
Chrome Full support 55 Full support 55 Notes' Before Chrome 59, the default values were not supported. |
Edge
Full support ≤79 |
Firefox
Full support 53 |
IE
No support No |
Opera
Full support 42 |
Safari
No support No |
WebView Android Full support 55 Full support 55 Notes' Before Chrome 59, the default values were not supported. |
Chrome Android Full support 55 Full support 55 Notes' Before Chrome 59, the default values were not supported. |
Firefox Android
Full support 53 |
Opera Android
Full support 42 |
Safari iOS
No support No |
Samsung Internet Android Full support 6.0 Full support 6.0 Notes' Before Samsung Internet 7.0, the default values were not supported. |
pan
|
Chrome
Full support 41 |
Edge
Full support 12 |
Firefox
Full support 37 |
IE
No support No |
Opera
Full support 28 |
Safari
No support No |
WebView Android
Full support 41 |
Chrome Android
Full support 41 |
Firefox Android
Full support 37 |
Opera Android
Full support 28 |
Safari iOS
No support No |
Samsung Internet Android
Full support 4.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.'
- See implementation notes.
See also
StereoPannerNode by Mozilla Contributors is licensed under CC-BY-SA 2.5.