forked from y2361547758/hca.js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoneclick.html
61 lines (54 loc) · 2.27 KB
/
oneclick.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
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1>HCA decoder demo</h1>
<a href="./">Full version</a>
<hr>
<button disabled id="webaudioplaybtn">Play</button><br>
<button disabled id="webaudiostopbtn">Stop</button><br>
<script type="module">
const hcaJsUrl = new URL("hca.js", document.baseURI);
var hcaJsModule, hcaJsObjUrl, HCAInfo, HCAWorker, HCAWebAudioLoopPlayer;
// HCAWorker instance
var worker = null;
// HCAWebAudioLoopPlayer instance
var webAudioLoopPlayer = null;
if (worker == null) {
if (hcaJsObjUrl == null) {
const response = await fetch(hcaJsUrl.href);
const blob = new Blob([await response.arrayBuffer()], {type: "text/javascript"});
hcaJsObjUrl = URL.createObjectURL(blob);
}
if (hcaJsModule == null) {
hcaJsModule = await import(hcaJsObjUrl);
}
if (HCAInfo == null) HCAInfo = hcaJsModule.HCAInfo;
if (HCAWorker == null) HCAWorker = hcaJsModule.HCAWorker;
if (HCAWebAudioLoopPlayer == null) HCAWebAudioLoopPlayer = hcaJsModule.HCAWebAudioLoopPlayer;
worker = await HCAWorker.create(hcaJsObjUrl);
console.log("started background worker");
}
try {
let response = await fetch("bgm22_battle01_hca.hca");
let hca = new Uint8Array(await response.arrayBuffer());
let decrypted = await worker.decrypt(hca, 0x01395C51, 0x00000000);
let newPlayer = await HCAWebAudioLoopPlayer.create(decrypted, worker);
if (webAudioLoopPlayer != null) await webAudioLoopPlayer.stop();
webAudioLoopPlayer = newPlayer;
webaudioplaybtn.disabled = false;
} catch (e) {
alert(e, e.stack);
}
webaudioplaybtn.addEventListener("click", (ev) => {
if (webAudioLoopPlayer != null) webAudioLoopPlayer.play();
webaudioplaybtn.disabled = true;
webaudiostopbtn.disabled = false;
});
webaudiostopbtn.addEventListener("click", async (ev) => {
if (webAudioLoopPlayer != null) await webAudioLoopPlayer.stop();
webaudiostopbtn.disabled = true;
});
</script>
</body>
</html>