网络音频API均衡器 [英] Web audio API equalizer

查看:248
本文介绍了网络音频API均衡器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找使用Web音频API创建音频均衡器: http: //webaudio.github.io/web-audio-api/



我发现了很多有关创建可视化工具的主题,但这当然不是我想要做什么我只是想能够使用频率滑块来改变声音。我发现biquadFilter应该做的工作,但我不能得到一个好的结果。当我改变任何频率值时,声音会一直改变,但是它会降低声音的质量,同时它会改变频率。

我首先加载一个声音: / p>

  Audio.prototype.init = function(callback){
var $ this = this;
this.gainScale = d3.scale.linear()。domain([0,1])。range([ - 40,40]);
this.context = new AudioContext();
this.loadSounds(function(){
$ this.loadSound(0);
$ this.play();
callback.call();
} );
};

一切正常,准备就绪时播放声音。

我有10个频率滑块[32,64,125,250,500,1000,2000,4000,8000,16000]。
对于每个滑块,我创建一个过滤器,并将其连接到源,如下所述:

 音频.prototype.createFilter = function(index,frequency){
if(this.filters == undefined)this.filters = [];
var filter = this.context.createBiquadFilter();
filter = this.context.createBiquadFilter();
filter.type = 2;
filter.frequency.value =频率;
//连接源进行过滤,过滤到目的地。
this.source.connect(filter);
filter.connect(this.context.destination);
this.filters [index] = filter;
};

最后,当我更改滑块的值时,我更新过滤器:

  Audio.prototype.updateFilter = function(index,newVal){
this.filters [index] .frequency.gain = this.gainScale的newval);
};

注意:我的this.gainScale函数在[0,1]中输入一个值并返回一个价值在[-40,40]设置为-40和40之间的增益为每个频率。

希望有任何帮助!


< 1)你不应该使用带通滤波器并行来实现一个均衡器。在其他问题中,双二阶滤波会改变信号不同部分的相位,因此不同的频带将以不同的阶段结束,并且在重新组合时会对声音产生一些潜在的不利影响。 2)你想要的方法是在底端有一个低架滤波器,在顶端有一个高架滤波器,在顶端有一个高架滤波器,中间。这些应该串联(即输入信号连接到一个滤波器,连接到另一个滤波器,连接到另一个滤波器等,只有最后的滤波器应该连接到audiocontext.destination。Q值应该是(如下图所示),滤波器的增益决定了升压/降压(对于平坦的响应,所有的滤波器增益都应该设置为零。)

3) filter.type是一个枚举类型,您应该将其设置为字符串,而不是数字。您可以在这里找到lowshelf,highshelf和peaking。

你可以在我的例子中看到一个简单的三频均衡器DJ应用程序 - https://github.com/cwilso/ wubwubwub / blob / MixTrack / js / tracks.js#L189-L207 设置。要将其修改为多波段均衡器,您需要调整每个滤波器的Q值以使波段不会重叠太多(如果它们重叠,这并不坏),但是如果调谐它们,则波段会更精确) 。您可以使用 http://googlechrome.github.io/ web-audio-samples / samples / audio / frequency-response.html 来检查给定Q和过滤器类型的频率响应。

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 visualizer, but that is of course not what I want to do. I simply want to be able to alter the sound using frequency sliders. I found that the biquadFilter should do the work, but I can't get a good result. The sound is altered consistently when I change any frequency value, but it just lowers the quality of the sound while it should alter the frequencies.

I first load a sound:

Audio.prototype.init = function(callback){
    var $this = this;
    this.gainScale = d3.scale.linear().domain([0,1]).range([-40,40]);
    this.context = new AudioContext();
    this.loadSounds(function(){
        $this.loadSound(0);
        $this.play();
        callback.call();
    });
};

Everything works well, the sound plays when ready.

I have 10 sliders for frequencies [32,64,125,250,500,1000,2000,4000,8000,16000]. For each slider I create a filter and I connect it to the source, as is described here: Creating a 10-Band Equalizer Using Web Audio API :

Audio.prototype.createFilter = function(index,frequency){
    if(this.filters == undefined) this.filters = [];
    var filter = this.context.createBiquadFilter();
    filter = this.context.createBiquadFilter();
    filter.type = 2;
    filter.frequency.value = frequency;
    // Connect source to filter, filter to destination.
    this.source.connect(filter);
    filter.connect(this.context.destination);
    this.filters[index] = filter;
};

Finally, when I change the value of a slider I update the filter:

Audio.prototype.updateFilter = function(index,newVal){
    this.filters[index].frequency.gain = this.gainScale(newVal);
};

NB: my this.gainScale function takes as input a value in [0,1] and returns a value in [-40,40] to set the gain between -40 and 40 for each frequency.

Would appreciate any help !

解决方案

Multiple things here.

1) You shouldn't use bandpass filters in parallel to implement an equalizer. Among other issues, biquad filtering changes the phase of different parts of the signal, and therefore the different bands will end up in different phases, and you'll have some potentially quite bad effects on your sound when it recombines.

2) The approach that you want is have a low shelf filter on the bottom end, a high shelf filter on the top end, and any number of peaking filters in the middle. These should be connected in series (i.e. the input signal connects to one filter, which connects to another filter, which connects to another filter, et al, and only the final filter should get connected to the audiocontext.destination. The Q values should be tuned (see below), and the gain on the filter determines the boost/cut. (For flat response, all filter gains should be set to zero.)

3) filter.type is an enumerated type that you should set as a string, not as a number. "lowshelf", "highshelf" and "peaking" are the ones you're looking for here.

You can see an example of a simple three-band equalizer in my DJ app - https://github.com/cwilso/wubwubwub/blob/MixTrack/js/tracks.js#L189-L207 sets it up. To modify this into a multiband equalizer, you'll need to tweak the Q value of each filter to get the bands to not overlap too much (it's not bad if they do overlap, but your bands will be more precise if you tune them). You can use http://googlechrome.github.io/web-audio-samples/samples/audio/frequency-response.html to examine the frequency response for a given Q and filter type.

这篇关于网络音频API均衡器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆