rezoner / playground

Playground.js is a framework for your javascript based games. It gives you out-of-box access to essentials like mouse, keyboard, sound and well designed architecture that you can expand to your needs.
MIT License
459 stars 50 forks source link

Feature Request: Audio Stereo Panning #34

Closed jackrugile closed 8 years ago

jackrugile commented 8 years ago

I'd love to have any easy way to set the stereo panning for a sound. Similar to playbackRate, it would be nice to have:

app.sound.setStereoPosition(sound, 0); // both
app.sound.setStereoPosition(sound, -1); // only left
app.sound.setStereoPosition(sound, 1); // only right

This is just something simple to have my 2D character's sounds come from where they are on the screen, left and right.

Maybe name it something else, but you know what I mean. Just adding it to my wish list. I know there is a panner node somewhere at work behind the scenes already, too.

Thanks!

rezoner commented 8 years ago

Pushed the update.

app.sound.setPanning(sound, pan);

pan is -1.0 to 1.0

It may work better with mono sounds.

jackrugile commented 8 years ago

You're a wizard. It works perfectly. Thanks for implementing this so fast!

jackrugile commented 8 years ago

Sorry to reopen this again, but it looks like there is an error in Safari showing up:

TypeError: this.context.createStereoPanner is not a function. (In 'this.context.createStereoPanner()', 'this.context.createStereoPanner' is undefined)

getSoundBuffer playground.js:3108

rezoner commented 8 years ago

Sorry for the delay - I have added a shim for createStereoPanner

jackrugile commented 8 years ago

Perfect, thanks! You're very fast by the way, thanks for getting on these changes so quickly.