Skip to content

Instantly share code, notes, and snippets.

@Patrick-web
Created May 10, 2021 16:20
Show Gist options
  • Save Patrick-web/5696c8af6c7dcaf37979f5b793880092 to your computer and use it in GitHub Desktop.
Save Patrick-web/5696c8af6c7dcaf37979f5b793880092 to your computer and use it in GitHub Desktop.
var context = new (window.AudioContext || window.webkitAudioContext)();
var mediaElement = document.querySelector("audio");
var source = context.createMediaElementSource(mediaElement);
let band1 = document.querySelector("#band1");
let band2 = document.querySelector("#band2");
let band3 = document.querySelector("#band3");
let band4 = document.querySelector("#band4");
let band5 = document.querySelector("#band5");
var band1Filter = context.createBiquadFilter();
var band2Filter = context.createBiquadFilter();
var band3Filter = context.createBiquadFilter();
var band4Filter = context.createBiquadFilter();
var band5Filter = context.createBiquadFilter();
band1Filter.type = "peaking";
band1Filter.frequency.value = 60;
band1Filter.gain.value = 0;
band1Filter.q = Math.SQRT1_2;
band2Filter.type = "peaking";
band2Filter.frequency.value = 230;
band2Filter.gain.value = 0;
band2Filter.q = Math.SQRT1_2;
band3Filter.type = "peaking";
band3Filter.frequency.value = 910;
band3Filter.gain.value = 0;
band3Filter.q = Math.SQRT1_2;
band4Filter.type = "peaking";
band4Filter.frequency.value = 4000;
band4Filter.gain.value = 0;
band4Filter.q = Math.SQRT1_2;
band5Filter.type = "peaking";
band5Filter.frequency.value = 14000;
band5Filter.gain.value = 0;
band5Filter.q = Math.SQRT1_2;
const filters = [
band1Filter,
band2Filter,
band3Filter,
band4Filter,
band5Filter,
];
source.connect(band1Filter);
band1Filter.connect(band2Filter);
band2Filter.connect(band3Filter);
band3Filter.connect(band4Filter);
band4Filter.connect(context.destination);
[band1, band2, band3, band4].forEach((band, index) => {
band.addEventListener("input", () => {
filters[index].gain.value = band.value;
});
});
@Patrick-web
Copy link
Author

An ANCTUAL JavaScript 5 band Equalizer

Implementation of a 5 band equalizer in JavaScript. The frequencies chosen are copied from the same frequencies the native android equalizer uses.

An Equalizer is not a freaking visualizer. Damn all those articles that put JavaScript visualizer in their title when the article clearly just shows how to make a visualizer !!!

I may have made some mistakes because of my lack of knowledge in sound production, do go ahead and correct me🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment