Three.js: THREE.PositionalAudio bugs/errors

Created on 29 Nov 2018  路  10Comments  路  Source: mrdoob/three.js

Three.js version
  • all
Browser
  • all
OS
  • [ ] Windows

Hi, I have been working with ThreeJS for a long time, and I really like it.
Recently I found a few errors, unfortunately, I did not make the minimum demo, because It is difficult to create such a situation in which errors can be reproduced.
But I will describe what the problem is.
Both problems are related THREE.PositionalAudio.
1) At first I found one unpleasant moment with the fact that if you move far from the source of THREE.PositionalAudio,
the sound may start to cracking if there are several other objects on the stage (again, it is difficult to create an example that will show this).
But if you change the position / rotation of THREE.PositionalAudio, then the crash disappears. I did not find a solution.
Made simple if the sound is played so that a small rotation of the source automatically occurs.
The problem is similar to this #12632, but my sound is cracking all the time, if you move far away, there may be a problem at the browser level, not ThreeJS.

2) This problem is more critical.
If you create a positional sound, add it to the scene, then play and stop (immediately or after a while).
Minimum part sample:

var loader = new THREE.AudioLoader();
loader.load(
'path_to_sound.mp3',
function ( buffer )
{
    a = new THREE.PositionalAudio(sound_listener);
    a.setBuffer(buffer);
    scene.add(a);
    a.play();
    a.stop();
});

After a while (depending on the scene complexity and processor power), the load on the CPU begins to grow. And begins to fall FPS on the eyes.
This is due to the moment the sound.stop(). If you play the sound and do not stop, or he is ending, then everything will be fine.
At repeated play / stop this situation is not reproduced.
I tried to understand and find a mistake for 2 days, but, unfortunately, not everything is so obvious. The only thing that I understood is that it is most likely that the problem is somewhere in this place:

THREE.PositionalAudio

updateMatrixWorld: ( function () {
    ...
    panner.positionX.linearRampToValueAtTime( position.x, endTime );
    panner.positionY.linearRampToValueAtTime( position.y, endTime );
    panner.positionZ.linearRampToValueAtTime( position.z, endTime );
    panner.orientationX.linearRampToValueAtTime( orientation.x, endTime );
    panner.orientationY.linearRampToValueAtTime( orientation.y, endTime );
    panner.orientationZ.linearRampToValueAtTime( orientation.z, endTime );
    ...
})()

I was able to fix the problem in this way:

THREE.PositionalAudio

updateMatrixWorld: ( function () {
    ...
    return function updateMatrixWorld( force ) {
        THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
        if (!this.isPlaying)        // this is 
            return;                 // fix
        var panner = this.panner;
    ...
    };
} )()

All 10 comments

Both problems might be related to the browser's implementation of Web Audio. Without any live demos which demonstrate the issues, it will be hard to provide any form of bug fix or feedback.

Yes, I understand that and I also think that it is related to Web Audio. But I suggested a potential solution to problem 2, maybe it can be included in the update of the engine, if I correctly suggested a fix.

First, provide a live example that demonstrate the issue 馃槈

I would create an example, I tried, but in the minimum scene set it is difficult to reproduce the problem.
But anyway, thanks for the replies.

We are getting very much the same issue (as problem 2) where these lines in updateMatrixWorld start to take longer and longer, killing FPS:
panner.setPosition( position.x, position.y, position.z );
panner.setOrientation( orientation.x, orientation.y, orientation.z );

These two calls may take 10+ ms. We are on Chrome M66, 3JS 0.97

@osov Why did you close the issue? Have you resolved it without necessity to modify 3js?

These two calls may take 10+ ms. We are on Chrome M66, 3JS 0.97

Hmm... Is that a browser issue? Do you get the same with Firefox?

@mrdoob: this is Chrome-specific issue.
I've created a new issue for the problem 2: https://github.com/mrdoob/three.js/issues/15422
Have a look, it has more info about the issue.

@osov Why did you close the issue? Have you resolved it without necessity to modify 3js?

Because I can not provide the minimum demo.

@osov Why did you close the issue? Have you resolved it without necessity to modify 3js?

Because I can not provide the minimum demo.

Anyway, thanks for finding this issue and solution to it, currently your fix is integrated into dev r99.

Was this page helpful?
0 / 5 - 0 ratings