forked from darius/bytebeat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sawtooth.html
69 lines (58 loc) · 1.53 KB
/
sawtooth.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
<!DOCTYPE html>
<head>
<title>Sawtooth</title>
</head>
<body>
[Fork <a href="https://github.com/darius/bytebeat">darius/bytebeat</a>
to help write this tutorial.]
<p>The simplest audible program is
<form id="form">
<input id="code0" type="text" size="40" value="t">
<input id="play" type="submit" value="Play it">
<input id="reset" type="submit" value="Reset">
</form>
<audio id="player" autoplay="true" controls></audio>
<p>
<canvas id="viz" height="256" width="938"></canvas>
<p id="error" style="color: red">
<p>Try doubling the frequency.
</p>
<script src="../bytebeat.js"></script>
<script>
//'use strict';
// Utilities for URLs & DOM, etc.
function dbg(msg) {
if (window.console)
console.log(msg);
}
function byId(id) {
return document.getElementById(id);
}
// Actual page logic
var code0 = byId('code0');
var player = byId('player');
var viz = byId('viz');
var error = byId('error');
if (typeof(player.play) === 'undefined')
alert("Your browser doesn't seem to support HTML5 audio. Sorry.");
function reset() {
code0.value = "t";
}
function play() {
error.innerHTML = '';
try {
var composers = [compileComposer(code0.value)];
var seconds = 30;
var rate = 8000;
showAudioVisual(makeSound(composers, seconds, rate, 1),
player, viz);
} catch (err) {
error.innerHTML = '' + err;
}
return false;
}
code0.focus();
byId('play').onclick = play;
byId('reset').onclick = reset;
</script>
</body>