三音频滤波器未随着linearRampToValueAtTime加速

问题描述

使用BiQuadFilter上的linearRampTovalueAtTime应用于WebAudio时遇到一些麻烦。
音频正常,并应用了初始低通滤波器。
问题是,一旦我使用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);