Created
December 3, 2012 03:16
-
-
Save kevincennis/4192424 to your computer and use it in GitHub Desktop.
crush me maybe
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 url = 'http://static1.kevincennis.com/sounds/callmemaybe.mp3' | |
, audio = new Audio(url) | |
, context = new webkitAudioContext() | |
, waveShaper = context.createWaveShaper() | |
, bassify = context.createBiquadFilter() | |
, sourceNode | |
audio.addEventListener('canplaythrough', function(){ | |
sourceNode = context.createMediaElementSource(audio) | |
sourceNode.connect(waveShaper) | |
waveShaper.connect(bassify) | |
bassify.connect(context.destination) | |
bassify.type = 3 | |
bassify.frequency.value = 80 | |
bassify.gain.value = 10 | |
waveShaper.curve = boneCrushingDistortion(50); | |
audio.currentTime = 28.3 | |
audio.play() | |
}, false) | |
function boneCrushingDistortion(amt){ | |
var steps = 1e4 | |
, curve = new Float32Array(steps) | |
, deg = Math.PI / 180 | |
, phase | |
, i = 0 | |
for ( ; i < steps; i++ ) { | |
phase = i * 2 / steps - 1 | |
curve[i] = (3 + amt) * phase * 20 * deg / (Math.PI + amt * Math.abs(phase)) | |
} | |
return curve | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment