JS_Sound_SetPosition times grows over time

I guess it’s more like a Chromium bug, but I also see that Unity uses deprecated method, at least on 2020.2.

JS_Sound_SetPosition use the deprecated PannerNode.setPosition

I noticed that the times of the JS_Sound_SetPosition function grows over time.

Replacing it with separately update PannerNode.positionX.value PannerNode.positionY.value and PannerNode.positionZ.value
results with similar times growth over time.

Is it a known issue? fixed on later versions? any alternatives?

Thanks

Something is wrong with the the webgl audio since the beginning.

My projects always worked fine with the unity web player but when i have switched to the webgl, sometime the sound is distorted or the sound just stop for few seconds and then come back.

Sometime it’s when a lot of sounds is played and sometime it happen when rotate the audio listener. So JS_Sound_SetPosition can be a part of the problem but not completely.

They have made some fixe in the 2021.2 version but after a quick test, the problem is still present.

I will not continue to open my mouth because i’m not able to reproduce it easily and because it happen randomly in my games.

I guess the correct way would be to use the setValueAtTime method for each axis. I’ll try it later

1 Like

Well, the Unity Web Player was a Native Browser Add-On. It had the performance of the native desktop, and was dependent mostly on Unity’s implementation.

WebGL, WebAudio and other Web APIs that Unity use now to build for the web, are based on the Browser implementations, and are limited because of user privacy and other concerns. So they are sandboxed and some features have more tests for every call than their native equivalent/counterpart.

Calling

    WEBAudio.audioInstances[channelInstance].panner.positionX.setValueAtTime(x, WEBAudio.audioContext.currentTime);
    WEBAudio.audioInstances[channelInstance].panner.positionY.setValueAtTime(y, WEBAudio.audioContext.currentTime);
    WEBAudio.audioInstances[channelInstance].panner.positionZ.setValueAtTime(z, WEBAudio.audioContext.currentTime);

Instead of

    WEBAudio.audioInstances[channelInstance].panner.setPosition(x, y, z);

Had the same results… the time it takes to run this method grows over time…

Which browser are you observing this behavior?

I do recall debugging an issue in the past with the time taken in Web Audio API growing as time passes. That ended up being a Chrome garbage collection bug, which they did fix back then. If you are able to create a test case, we could look again.

It’s in the Oculus Browser. It’s based on Chromium.
If you have a link to the bug, I can share it with the Oculus Browser devs.

If it’s this, looks like it’s still open
https://bugs.chromium.org/p/chromium/issues/detail?id=1133233&q=component%3ABlink>WebAudio&can=1

Oh no, indeed, the issue is still open. Sorry, I forgot about the status of the bug. Let’s hope rtoy is able to reply there, not sure what caused them to drop the issue after observing it themselves as well.

2 Likes

Seems like still not fixed.

If you don’t care about spatial sound, you can disable it by adding a .jslib file.
Assets\Plugins\WebGL\audio_setposition_fix.jslib

var LibrarySoundFix = {
  JS_Sound_SetPosition: function (channelInstance, x, y, z) {
    return;
  }
};
mergeInto(LibraryManager.library, LibrarySoundFix);
1 Like