sm64coopdx/lib/src/alBnkfNew.c

94 lines
2.5 KiB
C
Raw Normal View History

2019-08-25 04:46:40 +00:00
#include "libultra_internal.h"
#include "libaudio_internal.h"
2019-10-05 19:08:05 +00:00
#define PATCH(SRC, BASE, TYPE) SRC = (TYPE)((uintptr_t) SRC + (uintptr_t) BASE)
2019-08-25 04:46:40 +00:00
void alSeqFileNew(ALSeqFile *f, u8 *base) {
int i;
for (i = 0; i < f->seqCount; i++) {
2019-10-05 19:08:05 +00:00
PATCH(f->seqArray[i].offset, base, u8 *);
2019-08-25 04:46:40 +00:00
}
}
static void _bnkfPatchBank(ALInstrument *inst, ALBankFile *f, u8 *table) {
int i;
ALSound *sound;
ALWaveTable *wavetable;
u8 *table2;
2019-09-01 19:50:50 +00:00
if (inst->flags) {
2019-08-25 04:46:40 +00:00
return;
2019-09-01 19:50:50 +00:00
}
2019-08-25 04:46:40 +00:00
inst->flags = 1;
for (i = 0; i < inst->soundCount; i++) {
PATCH(inst->soundArray[i], f, ALSound *);
sound = inst->soundArray[i];
2019-09-01 19:50:50 +00:00
if (sound->flags) {
2019-08-25 04:46:40 +00:00
continue;
2019-09-01 19:50:50 +00:00
}
2019-08-25 04:46:40 +00:00
table2 = table;
sound->flags = 1;
PATCH(sound->envelope, f, ALEnvelope *);
PATCH(sound->keyMap, f, ALKeyMap *);
PATCH(sound->wavetable, f, ALWaveTable *);
wavetable = sound->wavetable;
2019-09-01 19:50:50 +00:00
if (wavetable->flags) {
2019-08-25 04:46:40 +00:00
continue;
2019-09-01 19:50:50 +00:00
}
2019-08-25 04:46:40 +00:00
wavetable->flags = 1;
PATCH(wavetable->base, table2, u8 *);
if (wavetable->type == 0) {
PATCH(wavetable->waveInfo.adpcmWave.book, f, ALADPCMBook *);
2019-09-01 19:50:50 +00:00
if (wavetable->waveInfo.adpcmWave.loop != NULL) {
2019-08-25 04:46:40 +00:00
PATCH(wavetable->waveInfo.adpcmWave.loop, f, ALADPCMloop *);
2019-09-01 19:50:50 +00:00
}
2019-08-25 04:46:40 +00:00
} else if (wavetable->type == 1) {
2019-09-01 19:50:50 +00:00
if (wavetable->waveInfo.rawWave.loop != NULL) {
2019-08-25 04:46:40 +00:00
PATCH(wavetable->waveInfo.rawWave.loop, f, ALRawLoop *);
2019-09-01 19:50:50 +00:00
}
2019-08-25 04:46:40 +00:00
}
}
}
// Force adding another jr $ra. Has to be called or it doesn't get put in the
// right place.
2020-06-02 16:44:34 +00:00
static void unused(void) {
2019-08-25 04:46:40 +00:00
}
void alBnkfNew(ALBankFile *f, u8 *table) {
ALBank *bank;
int i;
int j;
unused();
2019-09-01 19:50:50 +00:00
if (f->revision != AL_BANK_VERSION) {
2019-08-25 04:46:40 +00:00
return;
2019-09-01 19:50:50 +00:00
}
2019-08-25 04:46:40 +00:00
for (i = 0; i < f->bankCount; i++) {
PATCH(f->bankArray[i], f, ALBank *);
2019-09-01 19:50:50 +00:00
if (f->bankArray[i] == NULL) {
2019-08-25 04:46:40 +00:00
continue;
2019-09-01 19:50:50 +00:00
}
2019-08-25 04:46:40 +00:00
bank = f->bankArray[i];
if (bank->flags == 0) {
bank->flags = 1;
if (bank->percussion != NULL) {
PATCH(bank->percussion, f, ALInstrument *);
_bnkfPatchBank(bank->percussion, f, table);
}
for (j = 0; j < bank->instCount; j++) {
PATCH(bank->instArray[j], f, ALInstrument *);
if (bank->instArray[j] != NULL) {
_bnkfPatchBank(bank->instArray[j], f, table);
}
}
}
}
}