-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayingSounds.html
113 lines (95 loc) · 2.66 KB
/
PlayingSounds.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<DOCTYPE! html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Final Project </title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<link rel= "stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script src="script.js"> </script>
</head>
<body>
<div class="draggable" class="melodies">
<p> drag </p>
</div>
<div class="draggable" class="melodies">
<p> drag </p>
</div>
<div class="droppable" class="bar">
<p> drop</p>
</div>
</body>
</html>
<br>
<br>
<center>
<button type="button">Play/Pause</button>
</center>
<script>
window.onclick = function() {
var audio = new window.webkitAudioContext(),
position = 0,
scale = {
c: 261.63,
d: 293.66,
e: 329.63,
f: 349.23,
g: 392,
a: 261.63,
b: 493.88
},
song = "edcdeee-ddd-eee-edcdeee-cddedc---";
setInterval(play, 1000 / 4);
function createOscillator(freq) {
var osc = audio.createOscillator();
osc.frequency.value = freq;
osc.type = "square";
osc.connect(audio.destination);
osc.start(0);
setTimeout(function() {
osc.stop(0);
osc.disconnect(audio.destination);
}, 1000 / 4)
}
function play() {
var note = song.charAt(position),
freq = scale[note];
position += 1;
// if(position >= song.length) {
// position = 0;
// }
if(freq) {
createOscillator(freq);
}
}
};
<!-- // window.onload = function() {
// var audio = new window.webkitAudioContext(),
// osc = audio.createOscillator(),
// position = 0,
// scale = {
// g: 392,
// f: 349.23,
// e: 329.63,
// b: 493.88
// },
// song = "gfefgg-fff-gbb-gfefggggffgfe";
// osc.connect(audio.destination);
// osc.start(0);
// setInterval(play, 1000 / 4);
// function play() {
// var note = song.charAt(position),
// freq = scale[note];
// position += 1;
// if(position >= song.length) {
// position = 0;
// }
// if(freq) {
// osc.frequency.value = freq;
// }
// }
// };
-->