简体   繁体   English

Web Audio API-删除过滤器

[英]Web Audio API - Removing filter

I'm building a visualiser with multiple graphic modes. 我正在建立具有多个图形模式的可视化工具。 For a few of them I need to calculate the beat of the track being played, and as I understand I then need to apply a lowpass filter like the following, to enhance frequencies that are most probable to hold drum sounds: 对于其中的一些,我需要计算正在播放的曲目的节拍,据我了解,然后需要应用如下所示的低通滤波器,以增强最有可能保留鼓声的频率:

var filter = context.createBiquadFilter();

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

filter.type = 'lowpass';

But what if I want to turn the filter off? 但是,如果我想关闭过滤器怎么办? Do I have to re-connect the source every time I need to remove the filter? 每次需要删除过滤器时,我都必须重新连接信号源吗? Would this have any negative effect on performance? 这会对性能产生负面影响吗?

Related question: 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? 相关问题:如果我有两个来自同一音频源的两个源并将滤波器应用于其中一个,会遇到多少性能损失?

According to article WebAudio intro | 根据文章WebAudio介绍| html5rocks , I would have to toggle the filter on and off, by disconnecting the source and itself like so: 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 如果我有两个来自同一个音频源的两个源,并将滤波器应用于其中一个,我会遇到多少性能损失

You can connect a single audio node to multiple destinations, thus you never need a duplicate source just to spread-connect it. 您可以将单个音频节点连接到多个目标,因此,您不需要扩散源就可以使用重复的源。 If you need filtered and raw audio simultaneously, you can just setup your connections accordingly: 如果您需要同时过滤和原始音频,则可以相应地设置连接:

var filter = context.createBiquadFilter();

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

filter.type = "lowpass";

Anyways, setting the type property of a FilterNode to "allpass" will effectively disable all filtering, without having to reconnect: 无论如何,将FilterNode的type属性设置为"allpass"将有效地禁用所有过滤,而无需重新连接:

filter.type = "allpass"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM