I searched to create a sound equalizer using the web audio API: http://webaudio.imtqy.com/web-audio-api/
I found many threads about creating a visualizer, but this, of course, is not what I want to do. I just want to be able to change the sound with the help of frequency sliders. I found that biquadFilter should do the job, but I cannot get a good result. Sound changes sequentially when I change any frequency value, but it just reduces the sound quality while it needs to change frequencies.
First I load the 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, sound is played 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 described here: Creating a 10-band equalizer using the 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;
Finally, when I change the value of the slider, I update the filter:
Audio.prototype.updateFilter = function(index,newVal){ this.filters[index].frequency.gain = this.gainScale(newVal); };
NB: my function this.gainScale takes the value in [0,1] as the value and returns the value in [-40,40] to set the gain from -40 to 40 for each frequency.
Would thank for any help!