From 32c05e6a3df4481b82e086b8389b19af261e831c Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 6 Aug 2023 01:18:07 +0200 Subject: [PATCH] port: swap sequence headers --- port/include/preprocess.h | 1 + port/src/preprocess.c | 17 +++++++++++++---- src/lib/snd.c | 6 ++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/port/include/preprocess.h b/port/include/preprocess.h index 33faaed1a..5d930dcd5 100644 --- a/port/include/preprocess.h +++ b/port/include/preprocess.h @@ -10,6 +10,7 @@ void preprocessMpConfigs(u8 *data, u32 size); void preprocessFont(u8 *data, u32 size); void preprocessJpnFont(u8 *data, u32 size); void preprocessALBankFile(u8 *data, u32 size); +void preprocessALCMidiHdr(u8 *data, u32 size); void preprocessSequences(u8 *data, u32 size); void preprocessFiringRange(u8 *data, u32 size); void preprocessTexturesList(u8 *data, u32 size); diff --git a/port/src/preprocess.c b/port/src/preprocess.c index dd1121f8f..419229515 100644 --- a/port/src/preprocess.c +++ b/port/src/preprocess.c @@ -48,7 +48,7 @@ static inline u32 swapUnk(u32 x) { assert(0 && "unknown type"); return x; } static inline void preprocessALWaveTable(ALWaveTable *tbl, u8 *bankBase) { - if ((uintptr_t)tbl->base < 0x02000000) { + if ((uintptr_t)tbl->base < 0x02000000 && tbl->len >= 0) { // already swapped (maybe come up with a better check) return; } @@ -94,7 +94,7 @@ static inline void preprocessALWaveTable(ALWaveTable *tbl, u8 *bankBase) static inline void preprocessALSound(ALSound *snd, u8 *bankBase) { - if ((uintptr_t)snd->wavetable < 0x02000000) { + if ((uintptr_t)snd->wavetable < 0x02000000 && (uintptr_t)snd->envelope < 0x02000000 && (uintptr_t)snd->keyMap < 0x02000000) { // already swapped (maybe come up with a better check) return; } @@ -119,7 +119,7 @@ static inline void preprocessALSound(ALSound *snd, u8 *bankBase) static inline void preprocessALInstrument(ALInstrument *inst, u8 *bankBase) { - if ((uintptr_t)inst->soundArray[0] < 0x02000000) { + if ((uintptr_t)inst->soundArray[0] < 0x0500000 && inst->bendRange >= 0) { // already swapped (maybe come up with a better check) return; } @@ -135,7 +135,7 @@ static inline void preprocessALInstrument(ALInstrument *inst, u8 *bankBase) static inline void preprocessALBank(ALBank *bank, u8 *bankBase) { - if ((uintptr_t)bank->instArray[0] < 0x02000000) { + if ((uintptr_t)bank->sampleRate <= 48000) { // already swapped (maybe come up with a better check) return; } @@ -915,6 +915,15 @@ void preprocessALBankFile(u8 *data, u32 size) } } +void preprocessALCMidiHdr(u8 *data, u32 size) +{ + ALCMidiHdr *hdr = (ALCMidiHdr *)data; + PD_SWAP_VAL(hdr->division); + for (s32 i = 0; i < ARRAYCOUNT(hdr->trackOffset); ++i) { + PD_SWAP_VAL(hdr->trackOffset[i]); + } +} + void preprocessSequences(u8 *data, u32 size) { struct seqtable *seq = (struct seqtable *)data; diff --git a/src/lib/snd.c b/src/lib/snd.c index 4efc893ef..1720e73cb 100644 --- a/src/lib/snd.c +++ b/src/lib/snd.c @@ -22,6 +22,9 @@ #include "lib/speaker.h" #include "data.h" #include "types.h" +#ifndef PLATFORM_N64 +#include "preprocess.h" +#endif struct curmp3 { union soundnumhack sfxref; @@ -1628,6 +1631,9 @@ bool seqPlay(struct seqinstance *seq, s32 tracknum) dmaExec(zipstart, g_SeqTable->entries[seq->tracknum].romaddr, ziplen); ziplen = rzipInflate(zipstart, binstart, scratch); +#ifndef PLATFORM_N64 + preprocessALCMidiHdr(binstart, ziplen); +#endif #if VERSION < VERSION_NTSC_1_0 if (ziplen == 0) {