Created
May 10, 2021 16:20
-
-
Save Patrick-web/5696c8af6c7dcaf37979f5b793880092 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An ANCTUAL JavaScript 5 band Equalizer