Skip to content

Instantly share code, notes, and snippets.

@youpy
Created January 9, 2017 23:53
Show Gist options
  • Save youpy/2e59a7e0cddfa8d232077a50ea22cb91 to your computer and use it in GitHub Desktop.
Save youpy/2e59a7e0cddfa8d232077a50ea22cb91 to your computer and use it in GitHub Desktop.
tape degradation sim (wip)
const c = new AudioContext();
const req = new Request('https://dl.dropboxusercontent.com/u/334064/tmp/wh.mp3');
const source = c.createBufferSource();
const osc = c.createOscillator();
const gain = 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);
});
});
});
const fn = () => {
const t = (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 free to join this conversation on GitHub. Already have an account? Sign in to comment