0

I'm looking at the Audio and PositionalAudio objects, and I cannot find a way to manually pan the audio left or right. Assigning a sound to the PositionalAudio object gives me a panner object inside, but I cannot find any custom adjustments I can make to change the panning.

enter image description here

I am able to manually set the volume based on distance in my animation loop with setVolume on the sound I want to adjust, but I cannot find anything for panning.

Note, you can see I tried changing the position.x property, but it has no effect.

Chewie The Chorkie
  • 4,896
  • 9
  • 46
  • 90

1 Answers1

0

The thing about PositionalAudio is that it automatically pans left/right based on its position to the AudioListener. The AudioListener is usually attached to the camera so the viewer gets the effect of 3D positional audio:

  • If the audio source is to the left of the listener, it'll come out of the left speakers.
  • Center: both speakers
  • Right: right speaker

You can see this automatic panning in action in this demo. (I'm not sure why this demo drowns you with 4 audio sources simultaneously. I recommend you mute all audio sources except for the second sphere, then move around it to see how the panning occurs automatically)

Allowing a pan control would defeat the purpose of 3D positional audio. If you want to override the panning, I guess you could apply a filter with AudioListener.setFilter() and pass in a StereoPannerNode, but like I said, that would defeat the purpose of 3D audio.

M -
  • 26,908
  • 11
  • 49
  • 81
  • Unfortunately, their 3D panning is not sophisticated enough for my needs. I'll see if the StereoPannerNode could work. I did not know setFilter() could do that. Thank you! – Chewie The Chorkie Jun 12 '20 at 19:30
  • 1
    Cool. Make sure you use [AudioListener.context](https://threejs.org/docs/#api/en/audio/AudioListener.context) to get audio context you're already using, instead of creating a new one. – M - Jun 12 '20 at 19:34
  • StereoPannerNode is not supported by Safari, sadly. I am probably going to continue with this audio end of stuff with p5.js, since it has support for almost all browsers and has other neat features such as convolution reverb. – Chewie The Chorkie Jun 12 '20 at 19:35
  • Yeah, Safari has dismal WebAudio support. It's really frustrating. Are you sure the p5.js features will work in Safari? – M - Jun 12 '20 at 19:45
  • The examples work in Safari, but I can't get them to work with the library itself. It says "web audio is not supported by this browser". I'm confused since the examples appear to work themselves. – Chewie The Chorkie Jun 12 '20 at 20:00