Update pad parser to handle fractional pitch and trim length correctly
This commit is contained in:
@@ -167,10 +167,15 @@ export function collectPads(files: TarFile[], sounds: Sound[]) {
|
||||
const soundId = (file.data[2] << 8) + file.data[1];
|
||||
const sound = sounds.find((s) => s.id === soundId);
|
||||
const pitch = file.data[17] <= 12 ? file.data[17] : -(256 - file.data[17]); // pitch from -12 to +12
|
||||
const pitchDecimal = file.data[26];
|
||||
const pitchFraction = (file.data[26] ?? 0) / 100;
|
||||
const pan = (file.data[18] >= 240 ? -(256 - file.data[18]) : file.data[18]) / 16; // normalized pan
|
||||
const trimLeft = (file.data[6] << 16) + (file.data[5] << 8) + file.data[4];
|
||||
const trimRight = trimLeft + (file.data[10] << 16) + (file.data[9] << 8) + file.data[8];
|
||||
const trimLength = new DataView(
|
||||
file.data.buffer,
|
||||
file.data.byteOffset,
|
||||
file.data.byteLength,
|
||||
).getUint32(8, true);
|
||||
const trimRight = trimLeft + trimLength;
|
||||
|
||||
result[group.id].push({
|
||||
pad: i,
|
||||
@@ -187,12 +192,12 @@ export function collectPads(files: TarFile[], sounds: Sound[]) {
|
||||
trimRight,
|
||||
playMode: file.data[23] === 0 ? 'oneshot' : file.data[23] === 1 ? 'key' : 'legato',
|
||||
soundLength: sound ? calculateSoundLength(sound) : 0,
|
||||
pitch: Math.max(-12, Math.min(12, parseFloat(`${pitch}.${pitchDecimal}`))),
|
||||
pitch: Math.max(-12, Math.min(12, pitch + pitchFraction)),
|
||||
rootNote: file.data[24],
|
||||
timeStretch: timeStretch(file.data[21]),
|
||||
timeStretchBpm: Number(bytesToFloat32(file.data.slice(12, 16)).toFixed(2)),
|
||||
timeStretchBars: timeStretchBars(file.data[25]),
|
||||
inChokeGroup: file.data[22] === 1,
|
||||
inChokeGroup: file.data[22] !== 0,
|
||||
midiChannel: file.data[3],
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user