Web/API/BaseAudioContext/createStereoPanner

From Get docs

The createStereoPanner() method of the 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.


Syntax

baseAudioContext.createStereoPanner();

Returns

A StereoPannerNode.

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 'createStereoPanner()' in that specification. Working Draft  

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
createStereoPanner Chrome

Full support 42

Edge

Full support ≤18

Firefox Full support 53

Notes'

Full support 53

Notes'

Notes' Originally implemented on AudioContext in Firefox 37.

IE

No support No

Opera

No support No

Safari

No support No

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android Full support 53

Notes'

Full support 53

Notes'

Notes' Originally implemented on AudioContext in Firefox Android 37.

Opera Android

No support No

Safari iOS

No support No

Samsung Internet Android

Full support Yes

Legend

Full support  
Full support
No support  
No support
See implementation notes.'
See implementation notes.


See also