网络音频 API - 删除过滤器

Web Audio API - Removing filter

我正在构建一个具有多种图形模式的可视化工具。对于其中的一些,我需要计算正在播放的曲目的节拍,据我所知,然后我需要应用如下所示的低通滤波器,以增强最有可能保持鼓声的频率:

var filter = context.createBiquadFilter();

source.connect(filter);
filter.connect(context.destination);

filter.type = 'lowpass';

但是如果我想关闭过滤器怎么办?每次需要移除过滤器时是否都必须重新连接信号源?这会对性能产生负面影响吗?

相关问题:如果我有来自同一音频源的两个两个源并对其中一个应用过滤器,我会经历多少性能损失?

根据文章 WebAudio intro | html5rocks,我必须通过断开源和本身来打开和关闭过滤器,如下所示:

  this.source.disconnect(0);
  this.filter.disconnect(0);
  // Check if we want to enable the filter.
  if (filterShouldBeEnabled) {
    // Connect through the filter.
    this.source.connect(this.filter);
    this.filter.connect(context.destination);
  } else {
    // Otherwise, connect directly.
    this.source.connect(context.destination);
  }

how much performance loss would I experience if I have two two sources, from the same audio source, and apply the filter to one of them

您可以将单个音频节点连接到多个目的地,因此您永远不需要重复的源来传播它。如果您同时需要过滤和原始音频,您可以相应地设置您的连接:

var filter = context.createBiquadFilter();

source.connect(filter);
source.connect(context.destination);
filter.connect(context.destination);

filter.type = "lowpass";

无论如何,将 FilterNode 的类型 属性 设置为 "allpass" 将有效地禁用所有过滤,而无需重新连接:

filter.type = "allpass"