PositionalAudio: Stuttering with WebXR when close to the audio’s origin.

WebXR does not seem to be compatible with positional audio, specifically when put in VR mode. The audio would start stuttering once you are near the audio source and I suspect it is because the audio listener is switching between the left eye position and right eye position rapidly.

However, positional audio seems to work fine in A-Frame, which is based on three.js, so I wonder if there is an easy fix to this, or even if its expected behavior?

To Reproduce

  1. Set up a XR enabled renderer
  2. Add a PositionalAudio object to the scene with anything in the audioBuffer
  3. Enter XR mode and approach the object. Audio stutters.

Code

The code is a bit too long to be put here so I created a repo.

Live example

Hosted with github pages here.

Expected behavior

AudioListener would follow the position of the XR camera.

Platform:

  • Device: [Desktop, Mobile, VR]
  • OS: [Windows, MacOS, Linux, Android, iOS]
  • Browser: [Chrome, Firefox, Safari, Edge]
  • Three.js version: [r123]

1 possible answer(s) on “PositionalAudio: Stuttering with WebXR when close to the audio’s origin.

  1. Confirming that this seems to be solved! I’ve checked with both a VR and AR project where previously audio stuttered as you moved away from the audio source.

    Seems like camera.getWorldPosition() was returning multiple inconsistent locations per frame so distance from camera to audio source was fluctuating with frame rate.

    I had problems with this 6 months ago, but worked around the problem by making positional audio effectively only directional by setting refDistance to a high value. I was planning to submit a bug report at some time but happily it is fixed !!!