[#19] handle loops of length 0
also more robust way to find sample offsets to load in the file
This commit is contained in:
parent
2679587654
commit
8b3f318f60
1 changed files with 16 additions and 11 deletions
27
xm.js
27
xm.js
|
|
@ -787,8 +787,8 @@ function load(arrayBuf) {
|
||||||
// FIXME: ignoring keymaps for now and assuming 1 sample / instrument
|
// FIXME: ignoring keymaps for now and assuming 1 sample / instrument
|
||||||
// var keymap = getarray(dv, idx+0x21);
|
// var keymap = getarray(dv, idx+0x21);
|
||||||
var samphdrsiz = dv.getUint32(idx+0x1d, true);
|
var samphdrsiz = dv.getUint32(idx+0x1d, true);
|
||||||
console.log("hdrsiz %d; instrument %d: '%s' %d samples, samphdrsiz %d",
|
console.log("hdrsiz %d; instrument %s: '%s' %d samples, samphdrsiz %d",
|
||||||
hdrsiz, i, instname, nsamp, samphdrsiz);
|
hdrsiz, (i+1).toString(16), instname, nsamp, samphdrsiz);
|
||||||
idx += hdrsiz;
|
idx += hdrsiz;
|
||||||
var totalsamples = 0;
|
var totalsamples = 0;
|
||||||
var samps = [];
|
var samps = [];
|
||||||
|
|
@ -802,7 +802,10 @@ function load(arrayBuf) {
|
||||||
var samppan = dv.getUint8(idx+15);
|
var samppan = dv.getUint8(idx+15);
|
||||||
var sampnote = dv.getInt8(idx+16);
|
var sampnote = dv.getInt8(idx+16);
|
||||||
var sampname = getstring(dv, idx+18, 22);
|
var sampname = getstring(dv, idx+18, 22);
|
||||||
var sampleoffset = idx + nsamp * samphdrsiz + totalsamples;
|
var sampleoffset = totalsamples;
|
||||||
|
if (samplooplen === 0) {
|
||||||
|
samptype &= ~3;
|
||||||
|
}
|
||||||
console.log("sample %d: len %d name '%s' loop %d/%d vol %d offset %s",
|
console.log("sample %d: len %d name '%s' loop %d/%d vol %d offset %s",
|
||||||
j, samplen, sampname, samploop, samplooplen, sampvol, sampleoffset.toString(16));
|
j, samplen, sampname, samploop, samplooplen, sampvol, sampleoffset.toString(16));
|
||||||
console.log(" type %d note %s(%d) finetune %d pan %d",
|
console.log(" type %d note %s(%d) finetune %d pan %d",
|
||||||
|
|
@ -816,24 +819,26 @@ function load(arrayBuf) {
|
||||||
'len': samplen, 'loop': samploop,
|
'len': samplen, 'loop': samploop,
|
||||||
'looplen': samplooplen, 'note': sampnote, 'fine': sampfinetune,
|
'looplen': samplooplen, 'note': sampnote, 'fine': sampfinetune,
|
||||||
'pan': samppan, 'type': samptype, 'vol': sampvol,
|
'pan': samppan, 'type': samptype, 'vol': sampvol,
|
||||||
'sampledata': ConvertSample(
|
'fileoffset': sampleoffset
|
||||||
new Uint8Array(arrayBuf, sampleoffset, samplen), samptype & 16),
|
|
||||||
};
|
};
|
||||||
// length / pointers are all specified in bytes; fixup for 16-bit samples
|
// length / pointers are all specified in bytes; fixup for 16-bit samples
|
||||||
if (samptype & 16) {
|
samps.push(samp);
|
||||||
|
idx += samphdrsiz;
|
||||||
|
totalsamples += samplen;
|
||||||
|
}
|
||||||
|
for (j = 0; j < nsamp; j++) {
|
||||||
|
var samp = samps[j];
|
||||||
|
samp.sampledata = ConvertSample(
|
||||||
|
new Uint8Array(arrayBuf, idx + samp.fileoffset, samp.len), samp.type & 16);
|
||||||
|
if (samp.type & 16) {
|
||||||
samp.len /= 2;
|
samp.len /= 2;
|
||||||
samp.loop /= 2;
|
samp.loop /= 2;
|
||||||
samp.looplen /= 2;
|
samp.looplen /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// unroll short loops and any pingpong loops
|
// unroll short loops and any pingpong loops
|
||||||
if ((samp.type & 3) && (samp.looplen < 2048 || (samp.type & 2))) {
|
if ((samp.type & 3) && (samp.looplen < 2048 || (samp.type & 2))) {
|
||||||
UnrollSampleLoop(samp);
|
UnrollSampleLoop(samp);
|
||||||
}
|
}
|
||||||
samps.push(samp);
|
|
||||||
|
|
||||||
idx += samphdrsiz;
|
|
||||||
totalsamples += samplen;
|
|
||||||
}
|
}
|
||||||
idx += totalsamples;
|
idx += totalsamples;
|
||||||
inst.samplemap = samplemap;
|
inst.samplemap = samplemap;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue