-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
49 lines (49 loc) · 1.36 KB
/
test.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
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"/>
<meta name="format-detection" content="telephone=no"/>
<title>8-bit Noise Test</title>
</head>
<body>
<h1>8位噪波测试</h1>
<div id="root"></div>
<script src="8bitNoise.js"></script>
<script>
(function () {
var AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext;
var ctx = new AudioContext();
var node;
function start(freq) {
if (node) {
stop();
}
node = ctx.create8bitNoise(freq);
node.connect(ctx.destination);
node.start(0);
}
function stop() {
if (node) {
node.stop(0);
}
}
var btn;
var root = document.getElementById('root');
for (var i = 1; i <= 16; i ++) {
btn = document.createElement('button');
btn.innerHTML = '噪波' + i;
btn.onmousedown = (function (f) {
return function () {
start(f);
}
})(i);
root.appendChild(btn);
}
document.onmouseup = function () {
stop();
};
})();
</script>
</body>
</html>