Created
December 17, 2012 12:00
-
-
Save epicure/4317796 to your computer and use it in GitHub Desktop.
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
var ac = new webkitAudioContext(); | |
var cap = {}; | |
navigator.webkitGetUserMedia({audio: true}, function(stream) { | |
cap.mic = ac.createMediaStreamSource(stream); | |
}, null); | |
// 여기까지 일단 실행하고~ 마이크 입력을 허락해 주고. | |
var analyser = ac.createAnalyser(); | |
var buff = new Uint8Array(analyser.frequencyBinCount); | |
var g = document.createElement('canvas').getContext('2d'); | |
g.canvas.width = 512; | |
g.canvas.height = 256; | |
document.body.appendChild(g.canvas); | |
cap.mic.connect(analyser); | |
var update = function() { | |
var i, x, y; | |
g.clearRect(0, 0, g.canvas.width, g.canvas.height); | |
analyser.getByteTimeDomainData(buff); | |
y = g.canvas.height * 0.5; | |
for(i = 0; i < buff.length; i++) { | |
x = i / buff.length * g.canvas.width; | |
g.beginPath(); | |
g.moveTo(x, y); | |
g.lineTo(x, y + (buff[i] / 255 - 0.5) * g.canvas.height); | |
g.stroke(); | |
} | |
}; | |
var loop = function() { | |
update(); | |
webkitRequestAnimationFrame(loop); | |
}; | |
loop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment