Web Audio API - how to use AudioPannerNode for regular LR panning
-
17-06-2021 - |
题
AudioPannerNode is a processing node which positions / spatializes an incoming audio stream in three-dimensional space. Is there a way to use it for regular LR panning, having in mind it uses a 3D cartesian coordinate system in conjunction with a listener whose position and orientation is used together with the panner's position and orientation to determine how the audio will be spatialized? Or I should just skip the AudioPannerNode, and try to achieve this with LR gain nodes?
解决方案
LR panning is pretty straightforward, and you can use either of the approaches you describe. I would err on using the spatialized model (grounded in a physics engine), since otherwise you need to tweak your own balance.
Even though you're not doing 3D, you can project down to 2D, and play with front/rear balance as well, rather than going straight to 1D.
More information about spatialized audio in the Web Audio API can be found in the Web Audio for Games article.