THREE.Audio 过滤器未使用 linearRampToValueAtTime 增加

THREE.Audio filter not ramping up with linearRampToValueAtTime

我在应用于 WebAudio 的 BiQuadFilter 上使用 linearRampToValueAtTime 时遇到了一些问题。
音频工作正常,并应用了初始低通滤波器。
问题是,当我使用 linearRamp 方法调高频率时,它似乎忽略了 endTime 参数(或者更好的是,时间不正确)。

一些代码可以更好地解释它。
这是实例:

this.audioLoader.load( 'public/media/soundtrack-es_cobwebs_in_the_sky.mp3', buffer => {
    this.sounds.soundtrack = new THREE.Audio(this.listener);
    const audioContext = this.sounds.soundtrack.context;

    this.biquadFilter = audioContext.createBiquadFilter();
    this.biquadFilter.type = "lowpass"; // Low pass filter
    this.biquadFilter.frequency.setValueAtTime(200, audioContext.currentTime);

    this.sounds.soundtrack.setBuffer(buffer);
    this.sounds.soundtrack.setFilter(this.biquadFilter);
    this.sounds.soundtrack.setVolume(0.5);
    this.sounds.soundtrack.play();
})

到这里为止,一切看起来都还不错。声音会根据需要减弱。
然后,在某个事件之后,有一个镜头转换,我想让声音逐渐打开。

作为 endTime 参数,我将传递 2 秒 + 内部上下文增量。

this.sounds.soundtrack.filters[0].frequency.linearRampToValueAtTime(2400, 2 + this.sounds.soundtrack.context.currentTime);

希望在两秒钟内听到斜坡,但声音 立即 响起。 我错过了什么?

将使用上一个事件作为 startTime 应用线性斜坡。在您的情况下,这将是 audioContext.currentTime 在您创建过滤器的时间点。如果时间足够长,那么听起来好像斜坡直接跳到最终值。您可以通过在坡道之前插入一个新事件来解决这个问题。

const currentTime = this.sounds.soundtrack.context.currentTime;
const filter = this.sounds.soundtrack.filters[0];

filter.frequency.setValueAtTime(200, currentTime);
filter.frequency.linearRampToValueAtTime(2400, currentTime + 2);