-
Notifications
You must be signed in to change notification settings - Fork 1
/
audioBufferTest.html
37 lines (30 loc) · 1.01 KB
/
audioBufferTest.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
<!DOCTYPE HTML>
<html>
<head>
<title>trvial audio generator node example</title>
</head>
<body>
'enter' -- play tone <br>
'esc' -- stop tone
<script type="text/javascript">
var context = webkitAudioContext && new webkitAudioContext();
context = context || (AudioContext && new AudioContext());
var t = 0;
var node = context.createJavaScriptNode(256, 0, 1);
node.onaudioprocess = function (event) {
var outBuf = event.outputBuffer;
var channel = outBuf.getChannelData(0);
var count = channel.length;
for(var i = 0; i < count; i++) {
channel[i] = Math.sin(t++/10);
}
}
document.onkeydown = function(event) {
if(event.keyCode == 13)
node.connect(context.destination);
if(event.keyCode == 27)
node.disconnect();
}
</script>
</body>
</html>