ConvolverNode

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.

ConvolverNode 接口是一个对给定 AudioBuffer 上执行线性卷积的 AudioNode,一般用来做音频混响效果。每一个 ConvolverNode 都会有一个输入值和输出值。

备注: 更多线性卷积理论的相关信息,请参阅Convolution article on Wikipedia.

Number of inputs 1
Number of outputs 1
Channel count mode "clamped-max"
Channel count 1, 2, or 4
Channel interpretation "speakers"

构造函数

ConvolverNode()

创建一个新的 ConvolverNode 对象实例。

属性

继承其父级的属性*, AudioNode*.

ConvolverNode.buffer

一个被 ConvolverNode 用来产生混响效果的单声道、立体声或四声道的音频缓冲器,包含了 (可能是多声道) 脉冲反应 (IR)。

ConvolverNode.normalize

布尔值,在设置缓冲区属性时,可绝定是否对来自 buffer 的脉冲反应按等功率归一化进行缩放。

方法

没有具体的方法,从其父继承方法,AudioNode.

ConvolverNode 例子

下面的示例展示了 AudioContext 创建卷积节点的基础用法。

备注: 你需要找到一个脉冲反应来完成下面的示例。可查看此处 的实例。

js
let audioCtx = new window.AudioContext();

async function createReverb() {
    let convolver = audioCtx.createConvolver();

    // 从文件加载脉冲反应
    let response     = await fetch("path/to/impulse-response.wav");
    let arraybuffer  = await response.arrayBuffer();
    convolver.buffer = await audioCtx.decodeAudioData(arraybuffer);

    return convolver;
}

...

let reverb = await createReverb();

// someOtherAudioNode -> reverb -> destination
someOtherAudioNode.connect(reverb);
reverb.connect(audioCtx.destination);

规范

Specification
Web Audio API
# ConvolverNode

浏览器兼容性

BCD tables only load in the browser

参见