Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create very basic left/right equal power panning with createPanner();

I am looking at the web audio API spec and the panning node uses three values to create a 3D spectrum for sound. I was wondering if in order to create a basic 2D "equal power" panner the programmer needs to do the formulaic programming to scale this ... or if I am over thinking it and there is a simpler way to do it.

EDIT

There is now a stereoPanner node being introduced.

like image 267
William Avatar asked Jan 17 '13 11:01

William


1 Answers

here's an even simpler (less formulaic?) way to achieve 2D panning:

( full code here )

<input type="range" name="pan" id="pan" min="-1" max="1" step="any" />
<script>
var panner = context.createPanner();
panner.panningModel = 'equalpower';

function pan(event) {
    var x = this.valueAsNumber,
        y = 0,
        z = 1 - Math.abs(x);
    panner.setPosition(x,y,z);
}

document.getElementById('pan').addEventListener(pan);
</script>
like image 157
code_monk Avatar answered Oct 08 '22 22:10

code_monk