Skip to content

Instantly share code, notes, and snippets.

@koopa
Last active January 24, 2020 13:49
Show Gist options
  • Save koopa/51b2054abddbade5e394f794faf98759 to your computer and use it in GitHub Desktop.
Save koopa/51b2054abddbade5e394f794faf98759 to your computer and use it in GitHub Desktop.
unnormalized / quiet video fix
let nodes = {}
const audioCtx = new AudioContext()
const getNodes = ()=>{
if(nodes.eq) return nodes
const videoElement = document.querySelector("video")
const source = audioCtx.createMediaElementSource(videoElement)
nodes['gain'] = audioCtx.createGain()
nodes['eq'] = audioCtx.createBiquadFilter();
nodes['eq'].type = "bandpass";
source.connect(nodes['gain'])
nodes['gain'].connect(nodes['eq'])
nodes['eq'].connect(audioCtx.destination)
return nodes
}
const setDetune = (v) => { getNodes().eq.detune.setValueAtTime(v, audioCtx.currentTime); }
const setGain = (v) => { getNodes().eq.gain.setValueAtTime(v, audioCtx.currentTime) ;}
const setQ = (v) => { getNodes().eq.Q.setValueAtTime(v, audioCtx.currentTime); }
const setFreq = (v) => { getNodes().eq.frequency.setValueAtTime(v, audioCtx.currentTime); }
const eq = (f,q,g,d=0) => {
setFreq(f);
setQ(q);
setGain(g);
setDetune(d);
}
const incVol = (gain=2)=>{
getNodes().gain.value *= gain
}
incVol(2)
eq(900, 1.5, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment