Skip to content

Instantly share code, notes, and snippets.

@miselaytes-anton
Created May 31, 2018 19:13
Show Gist options
  • Save miselaytes-anton/3b91746a0fdf7de81c55b3d53a082985 to your computer and use it in GitHub Desktop.
Save miselaytes-anton/3b91746a0fdf7de81c55b3d53a082985 to your computer and use it in GitHub Desktop.
const getImpulseBuffer = (audioCtx, impulseUrl) => {
return fetch(impulseUrl)
.then(response => response.arrayBuffer())
.then(arrayBuffer => audioCtx.decodeAudioData(arrayBuffer))
}
const getLiveAudio = (audioCtx) => {
return navigator.mediaDevices.getUserMedia({audio: true})
.then(stream => audioCtx.createMediaStreamSource(stream));
}
async function init(){
const audioCtx = new AudioContext();
const input = await getLiveAudio(audioCtx)
const convolver = audioCtx.createConvolver()
//lets assume there is an mp3 file in root of our project
convolver.buffer = await getImpulseBuffer(audioCtx, '/impulse.mp3')
input.connect(convolver).connect(audioCtx.destination)
}
init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment