javascript – 使用Three.js PositionalAudio制作一个圆锥形声音

我正在用PositionalAudio创建一个声音数组:

 var newVoice = new THREE.PositionalAudio(listener);
 newVoice.setBuffer(buffer);
 newVoice.setRefDistance(20);
 newVoice.autoplay = true;
 newVoice.setLoop(true);
 voices.push(newVoice);

而且我已将这些声音附加到立方体上,但我想只允许用户听到声音,如果它们从30度的角度直接面向立方体.在30度锥体之外的任何东西都应该是沉默的.

我看到documentation here,但唯一有效的参数就是我使用’setRefDistance’的参数.其他人不起作用.我正在使用r74.

有任何想法吗?要点是:https://gist.github.com/evejweinberg/949e297c34177199386f945549a45c06

最佳答案 Three.js Audio是Web音频API的包装器.您可以将所有设置应用于panner,这可以使用getOutput()获得:

var sound = new THREE.PositionalAudio( listener );
var panner = sound.getOutput();
panner.coneInnerAngle = innerAngleInDegrees;
panner.coneOuterAngle = outerAngleInDegrees;
panner.coneOuterGain = outerGainFactor;

coneInnerAngle: A parameter for directional audio sources, this is an angle, inside of which there will be no volume reduction. The default value is 360.

coneOuterAngle: A parameter for directional audio sources, this is an angle, outside of which the volume will be reduced to a constant value of coneOuterGain. The default value is 360.

coneOuterGain: A parameter for directional audio sources, this is the amount of volume reduction outside of the coneOuterAngle. The default value is 0.

资料来源:

> https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html
> http://www.html5rocks.com/en/tutorials/webaudio/positional_audio/

点赞