【问题标题】:Web Audio with Three.js position 3D sounds具有 Three.js 位置 3D 声音的 Web 音频
【发布时间】:2014-09-04 08:19:04
【问题描述】:

我有一个带有 3d 声音的全景播放器,我正试图在 Three.js 中实现并尝试遵循这个 http://www.html5rocks.com/en/tutorials/webaudio/positional_audio/

摄像机是固定的,3D 声音放置在场景周围,我希望摄像机是否面向场景会影响音量。

这样就创建了声音(其中位置是一个向量3)

function playSound(buffer, looping, position, volume) {
    var sound = {};
    sound.source = context.createBufferSource();
    sound.volume = context.createGain();
    sound.source.connect(sound.volume);
    sound.volume.connect(mainVolume);

     var gainNode = context.createGain();
     gainNode.gain.value = volume;
     sound.source.connect(gainNode);


    sound.source.buffer = buffer;
     if(looping)
         sound.source.loop = true;
     sound.source.connect(context.destination);
     sound.source.start();

     sound.panner = context.createPanner();
     sound.position = position;

     //sound.panner.updateMatrixWorld();
     sound.volume.connect(sound.panner);
     sound.panner.connect(mainVolume);

     sceneSounds.push( sound );
 }

这很好用。

在渲染循环上

   lat = Math.max(-85, Math.min(85, lat));
    phi = THREE.Math.degToRad(90 - lat);
    theta = THREE.Math.degToRad(lon);

    target.x = 512 * Math.sin(phi) * Math.cos(theta);
    target.y = 512 * Math.cos(phi);
    target.z = 512 * Math.sin(phi) * Math.sin(theta);

    camera.lookAt(target);

    if(sceneSounds.length > 0)
        updateSceneSounds( target );

我用相机目标调用这个

function updateSceneSounds( target )
{

    for(var s in sceneSounds){
        var sound = sceneSounds[s];
        distance = sound.position.distanceTo( target );

        console.log( distance );

    }
}

距离在 400 到 500 之间的数字,我认为这不会真正有帮助,并且可能是使用错误的值。

有任何线索或想法是解决此问题的最佳方法吗?

【问题讨论】:

    标签: javascript three.js html5-audio


    【解决方案1】:

    我今天刚刚添加了这个功能。这是我的实现:

    https://github.com/mrdoob/three.js/commit/5ba54f71665ff4cd714d0db26c5a32c2b1c1cc8c

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 2019-09-17
      • 1970-01-01
      相关资源
      最近更新 更多