-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbeep.html
More file actions
131 lines (103 loc) · 2.96 KB
/
beep.html
File metadata and controls
131 lines (103 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div {
margin:1%;
font-size:20px;
}
button{
width:50px;
height:30px;
}
#submit{
width:50px;
height:30px;
font-size:20px;
}
#message{
color:#4682b4;
}
textarea{
margin:1%;
font-size:20px;
}
</style>
<title>Web Audio API test page</title>
<script type="text/javascript" src="beep.js"></script>
</head>
<body>
<div>Message sent: <div id="message"></div></div>
<div>Open the <a href="listen.html">listener</a> in a new window</div>
<div>Type something below to transmit it. Use numbers, letters and spaces only.</div>
<div>
<form onsubmit="play_from_form();return false;">
<textarea cols="20" rows="5" id="text_to_play">hello beep</textarea>
<br />
<input type="submit" value="play" id="submit"/>
</form>
</div>
</body>
<script type="text/javascript">
// audio api context
var context;
// characters we want to encode
var alphabet = "0123456789*#.|! abcdefghijklmnopqrstuvwxyz&";
// hi and low frequencies
var hi = 3400;
var low = 400;
// encoding parameters
var start_array = ['#','*','#'];
var dupe = "|";
var caps = "!";
// keys and associated freqncies
var freqs = [];
var keys = [];
// Tones
var tones = {};
// Milliseconds of sound
var note_length = 150;
// Element to log to
var log = document.getElementById("message");
init();
get_context();
/* encode and play an example IP address */
function test(){
var ip_text = "192.168.1.11";
var ip_array = encode(ip_text);
play_array(ip_array, note_length, log);
}
/* encode and play text from the from */
function play_from_form(){
var text = document.getElementById("text_to_play").value;
if(text && text!=""){
var text_array = encode(text);
play_array(text_array, note_length, log);
}
}
/* shows basic idea */
function tinytest(){
var text = "123";
var text_array = text.split("");
var count = 0;
var i = text_array[count];
var index = keys.indexOf(i);
var freq = freqs[index];
console.log("playing "+freq);
play_note(freq);
var interval = setInterval(function(){
stop_playing_note(freq);
count = count+1;
if(text_array[count]){
var j = text_array[count];
var index = keys.indexOf(j);
freq = freqs[index];
console.log("playing "+freq);
play_note(freq);
}else{
clearInterval(interval);
}
},note_length);
}
</script>
</html>