Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Copy video stream into canvas

  • Loading branch information...
commit 91903859646b5f67d83d6e5545269658889a24af 1 parent 6c53a38
@damiencornu damiencornu authored
Showing with 7 additions and 4 deletions.
  1. +1 −1  index.html
  2. +6 −3 javascripts/main.js
View
2  index.html
@@ -30,8 +30,8 @@ <h2 id="project_tagline">"Parler pour être vu" v0.2</h2>
<!-- MAIN CONTENT -->
<div id="main_content_wrap" class="outer">
<section id="main_content" class="inner">
+ <video id="camFeed" width="800px" height="600px" autoplay></video>
<canvas id="canvasCarre" width="800px" height="600px"></canvas>
- <video id="camFeed" width="800px" height="600px" autoplay>
</section>
</div>
View
9 javascripts/main.js
@@ -7,6 +7,7 @@ $(function(){
data,
sum,
x,
+ camFeed,
canvasCarre = $('#canvasCarre'),
tabCarre = new Array(),
max = 2000,
@@ -32,8 +33,8 @@ $(function(){
}
function onStream(stream) {
-
- document.getElementById('camFeed').src = webkitURL.createObjectURL(stream);
+ camFeed = document.getElementById('camFeed');
+ camFeed.src = webkitURL.createObjectURL(stream);
context = new webkitAudioContext();
microphone = context.createMediaStreamSource(stream);
@@ -43,7 +44,7 @@ $(function(){
microphone.connect(analyser);
analyser.connect(jsProcessor);
jsProcessor.connect(context.destination);
- window.setInterval(update, 400);
+ window.setInterval(update, 1000 / 24);
jsProcessor.onaudioprocess = function(e){
data = new Uint8Array(10);
analyser.getByteFrequencyData(data);
@@ -61,6 +62,8 @@ $(function(){
contextCanvas.clearRect(0, 0, 800, 600);
+ contextCanvas.drawImage(camFeed, 0, 0, 800, 600);
+
sum = data[0]+data[1]+data[2]+data[3]+data[4]+data[5]+data[6]+data[7]+data[8]+data[9];
x = 160 * (sum-300) / max;
Please sign in to comment.
Something went wrong with that request. Please try again.