-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.html
42 lines (37 loc) · 2.06 KB
/
example.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>pl_synth Example</title>
<script type="text/javascript" src="release/pl_synth_wasm.min.js"></script>
</head>
<body>
<button onclick="play_sound()">play sound</button>
<button onclick="play_song()">play music</button>
<script type="text/javascript">
let ctx = new (window.webkitAudioContext||window.AudioContext)();
let soundBuffer = null;
let songBuffer = null;
pl_synth_wasm_init(ctx, (synth) => {
soundBuffer = synth.sound([7,3,140,1,232,3,8,,9,1,139,3,,4611,1403,34215,256,4,1316,255,,,,1,,1,7,255]);
songBuffer = synth.song([8481,[[[7,,,,121,1,7,,,,91,3,,100,1212,5513,100,,6,19,3,121,6,21,,1,1,29],[1,2,1,2,1,2,,,1,2,1,2],[[138,145,138,150,138,145,138,150,138,145,138,150,138,145,138,150,136,145,138,148,136,145,138,148,136,145,138,148,136,145,138,148],[135,145,138,147,135,145,138,147,135,145,138,147,135,145,138,147,135,143,138,146,135,143,138,146,135,143,138,146,135,143,138,146]]],[[7,,,,192,1,6,,9,,192,1,25,137,1111,16157,124,1,982,89,6,25,6,77,,1,3,69],[,,1,2,1,2,3,3,3,3,3,3],[[138,138,,138,140,,141,,,,,,,,,,136,136,,136,140,,141],[135,135,,135,140,,141,,,,,,,,,,135,135,,135,140,,141,,140,140],[145,,,,145,143,145,150,,148,,146,,143,,,,145,,,,145,143,145,139,,139,,,142,142]]],[[7,,,1,255,,7,,,1,255,,,100,,3636,174,2,500,254,,27],[1,1,1,1,,,1,1,1,1,1,1],[[135,135,,135,139,,135,135,135,,135,139,,135,135,135,,135,139,,135,135,135,,135,139,,135,135,135,,135]]],[[8,,,1,200,,7,,,,211,3,210,50,200,6800,153,4,11025,254,6,32,5,61,,1,4,60],[1,1,1,1,,,1,1,1,1,1,1],[[,,,,140,,,,,,,,140,,,,,,,,140,,,,,,,,140]]]]]);
});
let play_sound = () => {
let source = ctx.createBufferSource();
source.buffer = soundBuffer;
source.connect(ctx.destination);
source.start();
}
let play_song = () => {
let source = ctx.createBufferSource();
source.buffer = songBuffer;
source.connect(ctx.destination);
source.start();
}
// The audio context needs to be "unlocked" by a user action :/
document.body.addEventListener('click', ev => {
ctx.resume();
}, {once: true});
</script>
</body>
</html>