# 3d spatial audio glitches

**URL:** <https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244>\
**Category:** Bugs\
**Created:** [October 10, 2019, 1:54am UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244 "2019-10-10T01:54:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [October 10, 2019, 1:54am UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/1 "2019-10-10T01:54:31Z")

</div>

Hello, I’m a musician and software dev trying out some different WebGL and WebAudio frameworks for future art projects. I like Babylon.js a lot but I’m getting audio glitches in the 3d spatial sound playground examples @ [https://doc.babylonjs.com/how\_to/playing\_sounds\_and\_music](https://doc.babylonjs.com/how_to/playing_sounds_and_music) . I’m on a 2 year old Windows 10 gaming PC and I don’t have any trouble with other frameworks so I’m thinking it’s a bug in Babylon.js which is a bummer because the sound glitches are a deal-breaker for me. Are there known issues and workarounds for these glitches? Is there a quick fix for them? Does anyone else hear them on their systems?

Cheers,  
~ Andy Fillebrown

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 10, 2019, 2:55pm UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/2 "2019-10-10T14:55:03Z")

</div>

Hey Andy, can you point me to an example that works with another framework

I know that lately win10 had a lot of issues with sound  
I see nothing wrong in our implementation ☹

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 10, 2019, 3:24pm UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/3 "2019-10-10T15:24:54Z")

</div>

I reproduce the glitches here as well: [Web Audio Spacialisation](https://mdn.github.io/webaudio-examples/spacialization/)

You need to let the boombox rotate (keep pushing the rotation button)

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [October 10, 2019, 11:07pm UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/4 "2019-10-10T23:07:13Z")

</div>

I think you are correct. What I heard initially at [Babylon.js Playground](https://www.babylonjs-playground.com/?23) seems to be a bad fade out in the audio sample being used, and now that I’m listening more closely to other demos and examples I’m hearing lots of glitches on every framework based on WebAudio on both my Mac and my Windows machines across all browsers, particularly when the panning node crosses the threshold between the right and left ears.

---

<div class="post-metadata">

**Author:** ![thrice](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thrice/32/105_2.png) [@thrice](https://forum.babylonjs.com/u/thrice)\
**Post date:** [October 11, 2019, 12:53am UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/5 "2019-10-11T00:53:24Z")

</div>

Is it a random audio clipping (when it shouldn’t be clipping) noise? I’ve noticed the same thing, and I’m on OSX. It seems to happen the worst when I a game scene is loading up, and the soundtrack starts playing. If I kill the soundtrack and leave just my ambient noise layer which is really soft, I can still hear it clip. The first 30 seconds or so seem to have multiple noticeable clippings, but it eventually stabilizes as time goes on.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 11, 2019, 2:48am UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/6 "2019-10-11T02:48:36Z")

</div>

I pinged the team working on webaudio here at Microsoft. We will see 🙂  
I slightly reduce the speed I update the position and orientation (you can control it with `scene.audioPositioningRefreshRate` which is 500ms by default now)

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [October 11, 2019, 4:19am UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/7 "2019-10-11T04:19:17Z")

</div>

Thanks, the new `scene.audioPositioningRefreshRate` property seems to reduce the number of glitches but they’re not gone. I also tried using different buffer sizes and sample rates when creating the [AudioContext](https://developer.mozilla.org/en-US/docs/Web/API/AudioContextLatencyCategory), but maxing out the buffer size on Chrome doesn’t help, even to 8000+ samples!

Here is an [A-Frame example](https://a-frame-audio-tutorial-complete.glitch.me/) that works well with no glitches at normal listener movement speeds, but the audio still glitches when moving the mouse rapidly.

(continued in next post because I’m currently limited to 2 links per post…)

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [October 11, 2019, 4:20am UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/8 "2019-10-11T04:20:00Z")

</div>

Here are some [A-Frame examples using Google’s Resonance Audio](https://digaverse.github.io/aframe-resonance-audio-component) that run silky smooth no matter how fast I move the mouse!

This makes me think the issue is in the web browser’s pan nodes since Google Resonance Audio doesn’t use the pan nodes. It basically creates it’s own pan node.

[edit] If I move the mouse extremely fast I do hear small glitches in the A-Frame and Google Resonance Audio examples, too, but I don’t think people can turn their heads that fast in VR and I can just rate limit other input devices and sound source speeds to avoid the glitches. I don’t think those workarounds will work in Babylon.js, yet. I might try hacking a Google Resonance Audio node into a Babylon.js sound component to see what happens.

---

<div class="post-metadata">

**Author:** ![thrice](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thrice/32/105_2.png) [@thrice](https://forum.babylonjs.com/u/thrice)\
**Post date:** [October 11, 2019, 5:08am UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/9 "2019-10-11T05:08:27Z")

</div>

In my case I still hear glitches without using any panning or spatial sound, when just playing static soundtrack and or ambient noise, so I don’t think panning is entirely to blame. Especially since I am using spatial audio for the SFX but once the game loads, cpu settles down, and gpu starts working harder, glitches become fewer and fewer. To me it feels like the CPU usage is directly affecting the number of glitches I hear

edit - then again, the boombox demo, which is glitching much harder than anything I’m experiencing, isn’t using much cpu when panning so IDK.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 11, 2019, 11:19am UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/10 "2019-10-11T11:19:12Z")

</div>

> [@docEdub](#):
>
> might try hacking a Google Resonance Audio node into a Babylon.js sound component to see what happens.

Excellent idea!

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [October 12, 2019, 3:52pm UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/11 "2019-10-12T15:52:00Z")

</div>

> > might try hacking a Google Resonance Audio node into a Babylon.js sound component to see what happens.
> 
> Excellent idea!

I got a Google Resonance Audio hack working and it runs smooth as glass. No glitches in the [orbiting cube playground example](https://www.babylonjs-playground.com/#EDVU95).

I gutted a lot of the Babylon.js audio system to get it working, though, so it might not be an apples to apples A/B test against the builtin pan node.

Regardless, I’d like to use Google Resonance Audio source nodes for all my sound sources and I’d like to be able to chain up custom Web Audio nodes for real time synthesis. Can you give me any pointers on how I can add those features to Babylon.js in a way that makes sense? …hopefully in a way that can be pulled into the main Babylon.js repo or can be added on as an extension/plugin?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 14, 2019, 3:20pm UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/12 "2019-10-14T15:20:53Z")

</div>

Hello we have a doc to help you contribute:  
[https://doc.babylonjs.com/how\_to/how\_to\_start](https://doc.babylonjs.com/how_to/how_to_start)

I truly appreciate your willingness to contribute back… This is pretty rare !

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [October 17, 2019, 1:36am UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/13 "2019-10-17T01:36:55Z")

</div>

Thanks. The “Start Contributing to Babylon.js” page will be helpful. Right now I’m wondering where to add the code needed for integrating Google’s resonance audio SDK. Does something like that belong in the BabylonJS/Extensions repository? Would it go in the main BabylonJS/Babylon.js repository? Somewhere else?

There are also some things I’d like to change in the main repository like being able to specify the sample rate and buffer size for the audio engine’s audio context. How would I do that given the audio engine is created automatically? Would I add the audio context creation options to the scene? …maybe add them as properties on the AudioEngine that would be set before the audio context is instantiated?

These are the kind of questions I have right now.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 17, 2019, 4:03pm UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/14 "2019-10-17T16:03:52Z")

</div>

Alright 🙂

1. For Google resonance audio sdk, this is definitely an extension so Extensions repository will be the right place
2. Can you change these values afterwards or do they need to be set at creation time?

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [October 22, 2019, 1:14am UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/15 "2019-10-22T01:14:22Z")

</div>

> [@Deltakosh](#):
>
> 1. For Google resonance audio sdk, this is definitely an extension so Extensions repository will be the right place

Ok, thanks.

  

> [@Deltakosh](#):
>
> 1. Can you change these values afterwards or do they need to be set at creation time?

The sample rate and latency/buffer-size options are set in the [AudioContext constructor](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/AudioContext). They can not be changed after the audio context is created. It’d be nice to have those options exposed by the BabylonJS engine so they can be set before the audio context is created.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 22, 2019, 8:56pm UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/16 "2019-10-22T20:56:06Z")

</div>

Makes sense then we can probably add them here:  
[https://doc.babylonjs.com/api/interfaces/babylon.engineoptions](https://doc.babylonjs.com/api/interfaces/babylon.engineoptions)

If you want you can submit a PR that will add a new audioOptions field as part of this interface. We will then be able to use data from this field to initialize the audio engine

---

<div class="post-metadata">

**Author:** ![agentdavo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/agentdavo/32/6524_2.png) [@agentdavo](https://forum.babylonjs.com/u/agentdavo)\
**Post date:** [January 22, 2020, 6:18pm UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/17 "2020-01-22T18:18:35Z")

</div>

Hey @docEdub and @Deltakosh -any updates related to integrating “Google Resonance Audio” as an extension? Is there a repo I can review?

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [January 22, 2020, 7:51pm UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/18 "2020-01-22T19:51:27Z")

</div>

No, during testing I was not able to resolve the audio glitch issues to my satisfaction so I reimplemented the Google Resonance Audio first order ambisonics in Csound WASM. That implementation works without audio glitches so far but I am not planning to make a Babylon extension with it.

---

<div class="post-metadata">

**Author:** ![agentdavo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/agentdavo/32/6524_2.png) [@agentdavo](https://forum.babylonjs.com/u/agentdavo)\
**Post date:** [January 22, 2020, 8:22pm UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/19 "2020-01-22T20:22:40Z")

</div>

OK, no problem. Looks like A-Frame + Three for my project in the short term then. I’m happy to offer a small financial incentive to bring Babylon + Resonance Audio forward - if that would help.

---

<div class="post-metadata">

**Author:** ![agentdavo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/agentdavo/32/6524_2.png) [@agentdavo](https://forum.babylonjs.com/u/agentdavo)\
**Post date:** [January 22, 2020, 8:23pm UTC](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244/20 "2020-01-22T20:23:12Z")

</div>

FYI - [GitHub - etiennepinchon/aframe-resonance: 🅰️ Google Resonance Audio for A-Frame](https://github.com/etiennepinchon/aframe-resonance)

[Next page](https://forum.babylonjs.com/t/3d-spatial-audio-glitches/6244.md?page=2)
