alBnkfNew.c (2552B)
1 #include "libultra_internal.h" 2 #include "libaudio_internal.h" 3 4 #define PATCH(SRC, BASE, TYPE) SRC = (TYPE)((uintptr_t) SRC + (uintptr_t) BASE) 5 6 void alSeqFileNew(ALSeqFile *f, u8 *base) { 7 int i; 8 for (i = 0; i < f->seqCount; i++) { 9 PATCH(f->seqArray[i].offset, base, u8 *); 10 } 11 } 12 13 static void _bnkfPatchBank(ALInstrument *inst, ALBankFile *f, u8 *table) { 14 int i; 15 ALSound *sound; 16 ALWaveTable *wavetable; 17 u8 *table2; 18 19 if (inst->flags) { 20 return; 21 } 22 23 inst->flags = 1; 24 25 for (i = 0; i < inst->soundCount; i++) { 26 PATCH(inst->soundArray[i], f, ALSound *); 27 sound = inst->soundArray[i]; 28 if (sound->flags) { 29 continue; 30 } 31 32 table2 = table; 33 34 sound->flags = 1; 35 PATCH(sound->envelope, f, ALEnvelope *); 36 PATCH(sound->keyMap, f, ALKeyMap *); 37 PATCH(sound->wavetable, f, ALWaveTable *); 38 wavetable = sound->wavetable; 39 if (wavetable->flags) { 40 continue; 41 } 42 43 wavetable->flags = 1; 44 PATCH(wavetable->base, table2, u8 *); 45 if (wavetable->type == 0) { 46 PATCH(wavetable->waveInfo.adpcmWave.book, f, ALADPCMBook *); 47 if (wavetable->waveInfo.adpcmWave.loop != NULL) { 48 PATCH(wavetable->waveInfo.adpcmWave.loop, f, ALADPCMloop *); 49 } 50 } else if (wavetable->type == 1) { 51 if (wavetable->waveInfo.rawWave.loop != NULL) { 52 PATCH(wavetable->waveInfo.rawWave.loop, f, ALRawLoop *); 53 } 54 } 55 } 56 } 57 58 // Force adding another jr $ra. Has to be called or it doesn't get put in the 59 // right place. 60 static void unused(void) { 61 } 62 63 void alBnkfNew(ALBankFile *f, u8 *table) { 64 ALBank *bank; 65 int i; 66 int j; 67 unused(); 68 if (f->revision != AL_BANK_VERSION) { 69 return; 70 } 71 72 for (i = 0; i < f->bankCount; i++) { 73 PATCH(f->bankArray[i], f, ALBank *); 74 if (f->bankArray[i] == NULL) { 75 continue; 76 } 77 78 bank = f->bankArray[i]; 79 if (bank->flags == 0) { 80 bank->flags = 1; 81 if (bank->percussion != NULL) { 82 PATCH(bank->percussion, f, ALInstrument *); 83 _bnkfPatchBank(bank->percussion, f, table); 84 } 85 for (j = 0; j < bank->instCount; j++) { 86 PATCH(bank->instArray[j], f, ALInstrument *); 87 if (bank->instArray[j] != NULL) { 88 _bnkfPatchBank(bank->instArray[j], f, table); 89 } 90 } 91 } 92 } 93 }