Skip to content

Commit c50a056

Browse files
committed
basic proof of concept
1 parent 05bb9f6 commit c50a056

9 files changed

+474
-0
lines changed

index.html

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<script src="microphone.js"></script>
5+
<script src="js/raphael.js"></script>
6+
<script language="JavaScript" src="js/custom.js"></script>
7+
<link rel="stylesheet" type="text/css" href="style.css" />
8+
</head>
9+
<body>
10+
11+
<script>
12+
var mic = new Microphone(function(){//this function is called when user allow us to access microphone.
13+
14+
//sample handler
15+
mic.onSamplesAvailable = function(data,channelCount){
16+
console.log(data);
17+
};
18+
19+
//set sample rate
20+
mic.sampleRate = 44100;
21+
22+
//get list of microphones available
23+
console.log(mic.getMicrophoneList());
24+
25+
//get sample rate
26+
console.log(mic.sampleRate);
27+
28+
//get microphone name in use
29+
console.log(mic.name);
30+
31+
//starts streaming
32+
mic.start();
33+
34+
//stops streaming after 1 second
35+
setTimeout(function(){
36+
mic.stop();
37+
},2000);
38+
});
39+
</script>
40+
<div>
41+
SCREEEEAAAAAM!!!!!!!!!!!
42+
<input type=button value="Game Start" onClick="game()">
43+
</div>
44+
<div id="draw">
45+
</div>
46+
47+
</body>
48+
</html>

js/custom.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function game() {
2+
3+
var padel_y_position = 15;
4+
var paper = Raphael('draw');
5+
6+
var field = paper.rect(10, 10, 700, 700);
7+
field.attr({
8+
stroke: 'black',
9+
fill: 'white',
10+
});
11+
12+
var padel = paper.rect(15, padel_y_position, 30, 100);
13+
padel.attr({
14+
fill: 'blue',
15+
cursor: 'pointer',
16+
opacity: 0.6,
17+
stroke: 'steelblue',
18+
});
19+
20+
var ball = paper.circle(65, 70, 15);
21+
ball.attr({
22+
fill: 'grey',
23+
opacity: 0.7,
24+
stroke: 'none',
25+
});
26+
27+
var start = padel.click(function() {
28+
if (padel_y_position >= 15 && padel_y_position <= 600){
29+
padel_y_position += 15;
30+
}
31+
else {
32+
padel_y_position = 600;
33+
}
34+
padel.animate({y: padel_y_position}, 1000, 'linear');
35+
});
36+
37+
var pushup = ball.click(function(){
38+
if (padel_y_position >= 15){
39+
padel_y_position = padel_y_position - 15;
40+
}
41+
else {
42+
padel_y_position = 15;
43+
}
44+
padel.animate({y: padel_y_position}, 1000, 'linear');
45+
});
46+
};

js/raphael.js

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

microphone.js

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
microphone.js
3+
Morteza Milani ([email protected])
4+
https://github.com/milani/microphone.js
5+
Published under MIT license
6+
*/
7+
8+
var Mic = {
9+
mics : [],
10+
push : function(object){
11+
this.mics[object.id] = object;
12+
},
13+
ready : function(id){
14+
this.mics[id].ready();
15+
},
16+
muted : function(id){
17+
this.mics[id].onMute();
18+
},
19+
data : function(id,data){
20+
this.mics[id].onSamplesAvailable(data,1);
21+
},
22+
error : function(id,code,message){
23+
this.mics[id].onError(id,code,message);
24+
}
25+
}
26+
27+
function Microphone(options,callback){
28+
29+
var defaults = {
30+
mode : 2, //Available modes: Recording -> 1, Streaming -> 2
31+
sampleRate : 44100,
32+
gain : 50,
33+
swfPath : 'microphone.swf',
34+
debugging : true
35+
}
36+
37+
var validRates = {
38+
'44': true,
39+
'22': true,
40+
'11': true,
41+
'8' : true,
42+
'5' : true
43+
}
44+
45+
if(typeof options == "function"){
46+
callback = options;
47+
options = {};
48+
}
49+
50+
options = options || {};
51+
52+
for (var index in defaults) {
53+
if (options[index] !== undefined) {
54+
defaults[index] = options[index];
55+
}
56+
}
57+
58+
defaults.sampleRate = parseInt(defaults.sampleRate / 1000);
59+
60+
if( ! validRates[defaults.sampleRate]){
61+
defaults.sampleRate = 8;
62+
}
63+
64+
this.id = 'mic' + new Date().getTime();
65+
66+
var objectHTML = '<object id="' + this.id + '" type="application/x-shockwave-flash" data="' + defaults.swfPath + '" width="215" height="138"><param name="movie" value="' + defaults.swfPath + '" /><param name="FlashVars" value="debugging=' + defaults.debugging + '&amp;rate='+defaults.sampleRate+'&amp;id=' + this.id + '&amp;mode=' + defaults.mode + '" /></object>';
67+
68+
Mic.push(this);
69+
70+
var self = this;
71+
72+
function insertIntoDom(htmlStr){
73+
var frag = document.createDocumentFragment(),
74+
temp = document.createElement('div');
75+
temp.innerHTML = htmlStr;
76+
while (temp.firstChild) {
77+
frag.appendChild(temp.firstChild);
78+
}
79+
document.body.appendChild(frag);
80+
81+
self.swf = document.getElementById(self.id);
82+
83+
}
84+
85+
this.readyState = false;
86+
87+
this.ready = function(){
88+
this.readyState = true;
89+
if(callback) callback.call(this);
90+
}
91+
92+
insertIntoDom(objectHTML);
93+
}
94+
95+
Microphone.prototype = {
96+
get STREAM(){
97+
return 2;
98+
},
99+
get RECORD(){
100+
return 1;
101+
},
102+
get sampleRate(){
103+
return this.swf.getRate() * 1000;
104+
},
105+
set sampleRate(val){
106+
this.swf.setRate(parseInt(val/1000));
107+
},
108+
get channelCount(){
109+
return 1; //flash supports only mono microphones
110+
},
111+
get name(){
112+
return this.swf.getName();
113+
},
114+
set index(val){
115+
this.swf.setMic(val);
116+
},
117+
set loopBack(val){
118+
this.swf.enableLoopBack(val);
119+
},
120+
set onMute(func){
121+
this.onMute = func;
122+
},
123+
on : function(event,callback){
124+
this[event] = callback;
125+
},
126+
getMicrophoneList: function(){
127+
return this.swf.getMicrophoneList();
128+
},
129+
start: function(){
130+
this.swf.start();
131+
},
132+
stop: function(){
133+
this.swf.stop();
134+
},
135+
isReady : function(){
136+
return this.readyState;
137+
}
138+
}
139+

microphone.swf

2.14 KB
Binary file not shown.

src/Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
FLEXBUILDER := mxmlc
3+
4+
main:
5+
$(FLEXBUILDER) -static-link-runtime-shared-libraries microphone.as
6+
7+
clean:
8+
rm -f microphone.swf
9+

0 commit comments

Comments
 (0)