Web audio API equalizer

后端 未结 2 609
被撕碎了的回忆
被撕碎了的回忆 2021-02-06 04:16

I have been looking around for creating an audio equalizer using the Web audio API: http://webaudio.github.io/web-audio-api/

I found a lot of threads about creating a vi

2条回答
  •  情歌与酒
    2021-02-06 04:37

    One issue is that you want your sliders to be controlling the gain of the filter at a given frequency, not the filter frequency itself. According to the spec the gain of a bandpass filter is not controllable which is a bit limiting. Fortunately you can put a gain node at the end of each filter.

    var filter = this.context.createBiquadFilter();
    filter = this.context.createBiquadFilter();
    filter.type = 2;
    filter.frequency.value = frequency;
    
    var gain = this.context.createGainNode();
    
    // Connect source to filter, filter to the gain, gain to destination.
    this.source.connect(filter);
    filter.connect(gain);
    gain.connect(this.context.destination);
    this.filters[index] = filter;
    this.gains[index] = gain;
    

    Next you'll need to connect your slider up to the gain parameter of the gain control. I don't really know web audio so I'll leave that to you. The last thing is that you need to to specify the Q of the filter. I get the impression from your list of frequencies that you're trying to create octave wide filters so the Q factor is probably going to be around 1.414. You're really going to need to do a bit of research if you want to get this right.

提交回复
热议问题