Skip to content

Instantly share code, notes, and snippets.

@nulltask
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save nulltask/33882c71f4a6504fb566 to your computer and use it in GitHub Desktop.

Select an option

Save nulltask/33882c71f4a6504fb566 to your computer and use it in GitHub Desktop.
testing test pattern
<!doctype html>
<html>
<meta charset="utf-8">
<title>test pattern</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
overflow: hidden;
}
</style>
<body>
<canvas width="1024" height="1024"></canvas><script>
var buf = 1024;
var au = new Audio();
au.autoplay = true;
au.loop = true;
// au.src = 'sensuous.m4a';
au.src = 'ri.m4a';
var context = new AudioContext();
var source = context.createMediaElementSource(au);
var processor = context.createScriptProcessor(buf, 2, 2);
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');
canvas.height = buf;
var lc = [];
var rc = [];
processor.onaudioprocess = function(e) {
var il = lc = e.inputBuffer.getChannelData(0);
var ir = rc = e.inputBuffer.getChannelData(1);
var ol = e.outputBuffer.getChannelData(0);
var or = e.outputBuffer.getChannelData(1);
for (var i = 0, l = processor.bufferSize; i < l; ++i) {
ol[i] = il[i];
or[i] = ir[i];
}
};
requestAnimationFrame(function() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0, l = canvas.height; i < l; ++i) {
ctx.beginPath();
ctx.moveTo(0, i);
if (lc[i] < 0) {
ctx.strokeStyle = 'white';
} else {
ctx.strokeStyle = 'black';
}
ctx.lineTo(canvas.width / 2, i);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(canvas.width / 2, canvas.height - i);
if (rc[i] < 0) {
ctx.strokeStyle = 'white';
} else {
ctx.strokeStyle = 'black';
}
ctx.lineTo(canvas.width, canvas.height - i);
ctx.closePath();
ctx.stroke();
}
requestAnimationFrame(arguments.callee);
});
source.connect(processor);
processor.connect(context.destination);
function fit() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.onresize = fit;
fit();
window.onclick = function(e) {
au.paused ? au.play() : au.pause();
e.preventDefault();
};
</script></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment