Skip to content

Commit a399572

Browse files
committed
Use XmlHttpRequest and binary files instead of JS string encoding
1 parent bba57c0 commit a399572

11 files changed

+52
-32
lines changed

modfile.js

+15-21
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,21 @@ function ModFile(mod) {
4343
}
4444

4545
var identifier = mod.substr(1080, 4);
46-
switch(identifier) {
47-
case '2CHN':
48-
this.channelCount = 2;
49-
break;
50-
case 'M.K.':
51-
case 'FLT4':
52-
case 'M!K!':
53-
case '4CHN':
54-
this.channelCount = 4;
55-
break;
56-
case '6CHN':
57-
this.channelCount = 6;
58-
break;
59-
case '8CHN':
60-
case 'OCTA':
61-
case 'CD81':
62-
this.channelCount = 8;
63-
break;
64-
default:
65-
console.log("Warning: unknown identifier " + identifier + ". Assuming 4 channels.");
66-
this.channelCount = 4;
46+
47+
var channelCountByIdentifier = {
48+
'TDZ1': 1, '1CHN': 1, 'TDZ2': 2, '2CHN': 2, 'TDZ3': 3, '3CHN': 3,
49+
'M.K.': 4, 'FLT4': 4, 'M!K!': 4, '4CHN': 4, 'TDZ4': 4, '5CHN': 5, 'TDZ5': 5,
50+
'6CHN': 6, 'TDZ6': 6, '7CHN': 7, 'TDZ7': 7, '8CHN': 8, 'TDZ8': 8, 'OCTA': 8, 'CD81': 8,
51+
'9CHN': 9, 'TDZ9': 9,
52+
'10CH': 10, '11CH': 11, '12CH': 12, '13CH': 13, '14CH': 14, '15CH': 15, '16CH': 16, '17CH': 17,
53+
'18CH': 18, '19CH': 19, '20CH': 20, '21CH': 21, '22CH': 22, '23CH': 23, '24CH': 24, '25CH': 25,
54+
'26CH': 26, '27CH': 27, '28CH': 28, '29CH': 29, '30CH': 30, '31CH': 31, '32CH': 32
55+
}
56+
57+
this.channelCount = channelCountByIdentifier[identifier];
58+
if (!this.channelCount) {
59+
//console.log("Warning: unknown identifier " + identifier + ". Assuming 4 channels.");
60+
this.channelCount = 4;
6761
}
6862

6963
var patternOffset = 1084;

modplayer.html

+37-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
<script type="text/javascript" src="modplayer.js"></script>
66
<script type="text/javascript" src="dynamicaudio-min.js"></script>
77

8-
<script type="text/javascript" src="mods/ambpower.mod.js"></script>
9-
108
<script type="text/javascript">
11-
var modFile = new ModFile(mod);
12-
//console.log(modFile);
13-
var modPlayer = new ModPlayer(modFile, 44100);
9+
var modPlayer;
1410
var dynamicAudio;
1511

1612
function init() {
@@ -20,6 +16,7 @@
2016
var playing = false;
2117
function play() {
2218
playing = true;
19+
// initially buffer 10 seconds (44100 * 2(stereo) * 10)
2320
dynamicAudio.write(modPlayer.getSamples(882000));
2421
bufferMoreData();
2522
}
@@ -34,10 +31,44 @@
3431
function stop() {
3532
playing = false;
3633
}
34+
35+
function loadRemote(path) {
36+
var fetch = new XMLHttpRequest();
37+
fetch.open('GET', path);
38+
fetch.overrideMimeType("text/plain; charset=x-user-defined");
39+
fetch.onreadystatechange = function() {
40+
if(this.readyState == 4 && this.status == 200) {
41+
/* munge response into a binary string */
42+
var t = this.responseText || "" ;
43+
var ff = [];
44+
var mx = t.length;
45+
var scc= String.fromCharCode;
46+
for (var z = 0; z < mx; z++) {
47+
ff[z] = scc(t.charCodeAt(z) & 255);
48+
}
49+
var binString = ff.join("");
50+
51+
var modFile = new ModFile(binString);
52+
//console.log(modFile);
53+
//var modFile = new ModFile(mod);
54+
modPlayer = new ModPlayer(modFile, 44100);
55+
play();
56+
document.getElementById('status').innerText = '';
57+
}
58+
}
59+
document.getElementById('status').innerText = 'loading...';
60+
fetch.send();
61+
}
3762
</script>
3863
</head>
3964
<body onload="init()">
40-
<button onclick="play()">play</button>
65+
<ul>
66+
<li><a href="javascript:loadRemote('mods/ambpower.mod')">Ambient Power (Vogue / Triton)</a></li>
67+
<li><a href="javascript:loadRemote('mods/dope.mod')">Dope / Onward Ride (Jugi / Complex)</a></li>
68+
<li><a href="javascript:loadRemote('mods/mindkick.mod')">Mindkick (Mindfuck / Mentasm)</a></li>
69+
<li><a href="javascript:loadRemote('mods/sundance.mod')">Sundance (Purple Motion / Future Crew)</a></li>
70+
</ul>
4171
<button onclick="stop()">stop</button>
72+
<div id="status"></div>
4273
</body>
4374
</html>

mods/ambpower.mod

320 KB
Binary file not shown.

mods/ambpower.mod.js

-1
This file was deleted.

mods/dope.mod

935 KB
Binary file not shown.

mods/dope.mod.js

-1
This file was deleted.

mods/mindkick.mod

370 KB
Binary file not shown.

mods/mindkick.mod.js

-1
This file was deleted.

mods/sundance.mod

289 KB
Binary file not shown.

mods/sundance.mod.js

-1
This file was deleted.

mods/trackers_forever.mod.js

-1
This file was deleted.

0 commit comments

Comments
 (0)