Instantly share code, notes, and snippets.
Save youpy/2e59a7e0cddfa8d232077a50ea22cb91 to your computer and use it in GitHub Desktop.
tape degradation sim (wip)
This file contains hidden or 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
constc=newAudioContext(); | |
constreq=newRequest('https://dl.dropboxusercontent.com/u/334064/tmp/wh.mp3'); | |
constsource=c.createBufferSource(); | |
constosc=c.createOscillator(); | |
constgain=c.createGain(); | |
osc.frequency.value=0.4; | |
gain.gain.value=0.0; | |
osc.connect(gain) | |
source.loop=true; | |
fetch(req).then((res)=>{ | |
res.arrayBuffer().then((buffer)=>{ | |
c.decodeAudioData(buffer,(decodedData)=>{ | |
source.buffer=decodedData; | |
source.connect(c.destination); | |
gain.connect(source.playbackRate); | |
osc.start(0); | |
source.start(0); | |
}); | |
}); | |
}); | |
constfn=()=>{ | |
constt=(Math.random() *0.1) +0.05; | |
gain.gain.exponentialRampToValueAtTime(3.0,c.currentTime +t); | |
gain.gain.exponentialRampToValueAtTime(Math.random() *0.02,c.currentTime +(t *2)); | |
setTimeout(()=>{ | |
fn(); | |
},Math.random() *4000); | |
}; | |
fn(); |
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment