-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathumd.html
36 lines (33 loc) · 926 Bytes
/
umd.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
<body>
<button>play</button>
</body>
<script src="../dist/1.x/ByteBeat.js"></script>
<script>
/* global ByteBeatNode */
document.querySelector('button').addEventListener('click', playPause);
let g_context;
let g_byteBeatNode;
let g_playing = false;
async function init() {
g_context = new AudioContext();
g_context.resume(); // needed for safari
await ByteBeatNode.setup(g_context);
g_byteBeatNode = new ByteBeatNode(g_context);
g_byteBeatNode.setType(ByteBeatNode.Type.byteBeat);
g_byteBeatNode.setExpressionType(ByteBeatNode.ExpressionType.infix);
g_byteBeatNode.setDesiredSampleRate(8000);
await g_byteBeatNode.setExpressions(['((t >> 10) & 42) * t']);
}
async function playPause() {
if (!g_context) {
await init();
}
if (!g_playing) {
g_playing = true;
g_byteBeatNode.connect(g_context.destination);
} else {
g_playing = false;
g_byteBeatNode.disconnect();
}
}
</script>