-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcamerons_lament.html
96 lines (81 loc) · 2.59 KB
/
camerons_lament.html
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
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
font-size:30px;
margin-left:8px;
}
button{
width:100px;
height:50px;
}
#submit{
width:50px;
height:30px;
font-size:40px;
}
#message{
color:#4682b4;
}
textarea{
margin:5%;font-size:40px;
}
</style>
<title>Web Audio API test page</title>
<script type="text/javascript" src="camerons_lament.js"></script>
<script type="text/javascript" src="camerons_lament.json"></script>
</head>
<body>
<p>See <a href="http://www.bbc.co.uk/news/uk-politics-36767880">Cameron hums tune</a> and <a href="http://www.classicfm.com/music-news/latest-news/cameron-humming-cello-piano/">various excellent musical variations</a> and this <a href="http://www.classicfm.com/discover/music-theory/david-cameron-musical-analysis/#6oejlCm1aAMR6fZY.97">musical analysis</a>:
<br />
<img src="http://assets.gcstatic.com/u/apps/asset_manager/uploaded/2016/28/david-cameron-humming-musical-analysis-1468256220-custom-0.png"/>
</p>
<p>Allow microphone access and hum it yourself...</p>
<div class ="stop"><button onclick="play_first_note();return false;">Play first note</button>
<button onclick="stop_listening();return false;">Stop listening</button></div>
<br />
<div id="result"></div>
<div id="message"></div>
<div id="freq"></div>
<div id="amp"></div>
</body>
<script type="text/javascript">
// audio api context
var context;
// keys and associated freqncies
var freqs = [];
var keys = [];
freq_error = 10.0;
for(var key in note_data) {
if(note_data.hasOwnProperty(key)) { //to be safe
freqs.push(key);
keys.push(note_data[key]);
}
}
// Tones
var tones = {};
// Milliseconds of sound
var note_length = 1000
// Element to log to
var log = document.getElementById("message");
get_context();
get_microphone_input();
function play_first_note(){
var a = ["193.00"];
play_array(a, note_length);
}
function encode(text){
var new_array = [];
var arr = text.split(" ");
for(var i =0; i< arr.length; i++){
var index = keys.indexOf(arr[i]);
var f = freqs[index];
if(f){
new_array.push(f);
}
}
return new_array;
}
</script>
</html>