rserota / wad

Web Audio DAW. Use the Web Audio API for dynamic sound synthesis. It's like jQuery for your ears.
MIT License
1.9k stars 160 forks source link

Sound panning impacts volume: is this normal ? #23

Closed warpdesign closed 9 years ago

warpdesign commented 9 years ago

instance = sound.play({ panning: [8, 0, 0], volume: 1.0, loop: loop || false });

And sound plays at very low volume. If I remove panning parameter, it plays at normal volume.

rserota commented 9 years ago

Yeah, that's right. In Web Audio, you don't directly set the left/right stereo balance. Panning describes the distance between the listener and the sound source. By default, panning is [0, 0, 0], so it's like the sound is playing from inside your head. If you pan the sound in any direction, it gets further away from the listener, and seems quieter.

I would recommend you pan all sounds away from the user on the z-axis ( e.g. [0, 0, 5] ). This will make it seem less jarring if you then pan the sound on the x-axis. Panning from [-5, 0, 0] to [5, 0, 0] will probably sound irritating, like a bee buzzing around your head, but panning from [-5, 0, 5] to [5, 0, 5] will sound more natural.

notthetup commented 9 years ago

Found this algorithm on stackoverflow that converts a -90: 90 deg parameter to the appropriate setPosition call.

function panPositionSetter( panValue ) {
                var xDeg = parseInt( panValue );
                var zDeg = xDeg + 90;
                if ( zDeg > 90 ) {
                    zDeg = 180 - zDeg;
                }
                var x = Math.sin( xDeg * ( Math.PI / 180 ) );
                var z = Math.sin( zDeg * ( Math.PI / 180 ) );
                panner_.setPosition( x, 0, z );
            }