From 40e2cd872c3320d92cedb103841da974c9679580 Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Mon, 11 Jul 2022 22:19:52 -0400 Subject: [PATCH] Removed legacy audio mode and fixed ganon sound bug --- soh/include/variables.h | 4 - soh/include/z64audio.h | 1 - soh/soh/OTRGlobals.cpp | 51 - soh/soh/OTRGlobals.h | 6 - soh/soh/stubs.c | 1673 +------------------------------- soh/src/code/audio_heap.c | 15 +- soh/src/code/audio_load.c | 438 +++------ soh/src/code/audio_playback.c | 52 +- soh/src/code/audio_seqplayer.c | 35 +- soh/src/code/z_kankyo.c | 6 +- 10 files changed, 141 insertions(+), 2140 deletions(-) diff --git a/soh/include/variables.h b/soh/include/variables.h index 64b8c75c703..64256a28442 100644 --- a/soh/include/variables.h +++ b/soh/include/variables.h @@ -171,10 +171,6 @@ extern "C" #define gTatumsPerBeat (D_8014A6C0[1]) extern const AudioContextInitSizes D_8014A6C4; extern s16 gOcarinaSongItemMap[]; - extern u8 gSoundFontTable[]; - extern u8 gSequenceFontTable[]; - extern u8 gSequenceTable[]; - extern u8 gSampleBankTable[]; extern u8 D_80155F50[]; extern u8 D_80157580[]; extern u8 D_801579A0[]; diff --git a/soh/include/z64audio.h b/soh/include/z64audio.h index 719bb78eeb4..3911bb6c451 100644 --- a/soh/include/z64audio.h +++ b/soh/include/z64audio.h @@ -20,7 +20,6 @@ #define CALC_RESAMPLE_FREQ(sampleRate) ((float)sampleRate / (s32)gAudioContext.audioBufferParameters.frequency) -extern bool gUseLegacySD; extern char* fontMap[256]; typedef enum { diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index ff875500682..227de777c1f 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1329,57 +1329,6 @@ extern "C" int16_t OTRGetRectDimensionFromRightEdge(float v) { return ((int)ceilf(OTRGetDimensionFromRightEdge(v))); } -extern "C" void bswapSoundFontSound(SoundFontSound* swappable) { - swappable->sample = (SoundFontSample*)BOMSWAP32((u32)(uintptr_t(swappable->sample))); - swappable->tuningAsU32 = BOMSWAP32((u32)(swappable->tuningAsU32 & 0xFFFFFFFF)); -} - -extern "C" void bswapDrum(Drum* swappable) { - bswapSoundFontSound(&swappable->sound); - swappable->envelope = (AdsrEnvelope*)BOMSWAP32((u32)uintptr_t(swappable->envelope)); -} - -extern "C" void bswapInstrument(Instrument* swappable) { - swappable->envelope = (AdsrEnvelope*)BOMSWAP32((u32)uintptr_t(swappable->envelope)); - bswapSoundFontSound(&swappable->lowNotesSound); - bswapSoundFontSound(&swappable->normalNotesSound); - bswapSoundFontSound(&swappable->highNotesSound); -} - -extern "C" void bswapSoundFontSample(SoundFontSample* swappable) { - u32 origBitfield = BOMSWAP32(swappable->asU32); - - swappable->codec = (origBitfield >> 28) & 0x0F; - swappable->medium = (origBitfield >> 24) & 0x03; - swappable->unk_bit26 = (origBitfield >> 22) & 0x01; - swappable->unk_bit25 = (origBitfield >> 21) & 0x01; - swappable->size = (origBitfield) & 0x00FFFFFF; - - swappable->sampleAddr = (u8*)BOMSWAP32((u32)uintptr_t(swappable->sampleAddr)); - swappable->loop = (AdpcmLoop*)BOMSWAP32((u32)uintptr_t(swappable->loop)); - swappable->book = (AdpcmBook*)BOMSWAP32((u32)uintptr_t(swappable->book)); -} - -extern "C" void bswapAdpcmLoop(AdpcmLoop* swappable) { - swappable->start = (u32)BOMSWAP32((u32)swappable->start); - swappable->end = (u32)BOMSWAP32((u32)swappable->end); - swappable->count = (u32)BOMSWAP32((u32)swappable->count); - - if (swappable->count != 0) { - for (int i = 0; i < 16; i++) { - swappable->state[i] = (s16)BOMSWAP16(swappable->state[i]); - } - } -} - -extern "C" void bswapAdpcmBook(AdpcmBook* swappable) { - swappable->order = (u32)BOMSWAP32((u32)swappable->order); - swappable->npredictors = (u32)BOMSWAP32((u32)swappable->npredictors); - - for (int i = 0; i < swappable->npredictors * swappable->order * sizeof(s16) * 4; i++) - swappable->book[i] = (s16)BOMSWAP16(swappable->book[i]); -} - extern "C" bool AudioPlayer_Init(void) { if (OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer() != nullptr) { return OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer()->Init(); diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 9a2a36ae074..9c209a0a8ae 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -74,12 +74,6 @@ float OTRGetDimensionFromLeftEdge(float v); float OTRGetDimensionFromRightEdge(float v); int16_t OTRGetRectDimensionFromLeftEdge(float v); int16_t OTRGetRectDimensionFromRightEdge(float v); -void bswapDrum(Drum* swappable); -void bswapInstrument(Instrument* swappable); -bool bswapSoundFontSound(SoundFontSound* swappable); -void bswapSoundFontSample(SoundFontSample* swappable); -void bswapAdpcmLoop(AdpcmLoop* swappable); -void bswapAdpcmBook(AdpcmBook* swappable); char* ResourceMgr_LoadFileRaw(const char* resName); bool AudioPlayer_Init(void); int AudioPlayer_Buffered(void); diff --git a/soh/soh/stubs.c b/soh/soh/stubs.c index 0074bc16b5e..10a865d1e97 100644 --- a/soh/soh/stubs.c +++ b/soh/soh/stubs.c @@ -439,1678 +439,7 @@ OSYieldResult osSpTaskYielded(OSTask* task) } - void osViExtendVStart(u32 arg0) { -} - -#if 0 -AudioTable gSoundFontTable = { 0 }; -#else -AudioTable gSoundFontTable = { 0x0026, - 0x0000, - 0x00000000, - { 0 }, - { - { - 0x00000000, - 0x00003AA0, - 0x02, - 0x00, - 0x00FF, - 0x5C04, - 0x0088, - }, - { - 0x00003AA0, - 0x000017B0, - 0x02, - 0x00, - 0x00FF, - 0x3301, - 0x0029, - }, - { - 0x00005250, - 0x00000CE0, - 0x02, - 0x02, - 0x00FF, - 0x1500, - 0x0000, - }, - { - 0x00005F30, - 0x000015D0, - 0x02, - 0x02, - 0x01FF, - 0x1040, - 0x0000, - }, - { - 0x00007500, - 0x00000100, - 0x02, - 0x02, - 0x02FF, - 0x0200, - 0x0000, - }, - { - 0x00007600, - 0x00000B60, - 0x02, - 0x02, - 0x01FF, - 0x0D40, - 0x0000, - }, - { - 0x00008160, - 0x00000520, - 0x02, - 0x02, - 0x01FF, - 0x0F00, - 0x0000, - }, - { - 0x00008680, - 0x00000840, - 0x02, - 0x02, - 0x03FF, - 0x0A40, - 0x0000, - }, - { - 0x00008EC0, - 0x00000B20, - 0x02, - 0x02, - 0x01FF, - 0x0A40, - 0x0000, - }, - { - 0x000099E0, - 0x00000FC0, - 0x02, - 0x02, - 0x01FF, - 0x0D40, - 0x0000, - }, - { - 0x0000A9A0, - 0x00000B00, - 0x02, - 0x02, - 0x01FF, - 0x0E40, - 0x0000, - }, - { - 0x0000B4A0, - 0x00000390, - 0x02, - 0x02, - 0x01FF, - 0x0400, - 0x0000, - }, - { - 0x0000B830, - 0x00000320, - 0x02, - 0x02, - 0x01FF, - 0x0300, - 0x0000, - }, - { - 0x0000BB50, - 0x000006F0, - 0x02, - 0x02, - 0x01FF, - 0x1000, - 0x0000, - }, - { - 0x0000C240, - 0x00000390, - 0x02, - 0x02, - 0x05FF, - 0x0500, - 0x0000, - }, - { - 0x0000C5D0, - 0x00000B40, - 0x02, - 0x02, - 0x01FF, - 0x1000, - 0x0000, - }, - { - 0x0000D110, - 0x000009E0, - 0x02, - 0x02, - 0x06FF, - 0x0A40, - 0x0000, - }, - { - 0x0000DAF0, - 0x00000560, - 0x02, - 0x02, - 0x01FF, - 0x0F00, - 0x0000, - }, - { - 0x0000E050, - 0x00000CC0, - 0x02, - 0x01, - 0x01FF, - 0x0D40, - 0x0000, - }, - { - 0x0000ED10, - 0x000003A0, - 0x02, - 0x02, - 0x01FF, - 0x0400, - 0x0000, - }, - { - 0x0000F0B0, - 0x00000AA0, - 0x02, - 0x02, - 0x01FF, - 0x0A40, - 0x0000, - }, - { - 0x0000FB50, - 0x00000A60, - 0x02, - 0x02, - 0x01FF, - 0x0A40, - 0x0000, - }, - { - 0x000105B0, - 0x00000BF0, - 0x02, - 0x02, - 0x01FF, - 0x0B40, - 0x0000, - }, - { - 0x000111A0, - 0x000001F0, - 0x02, - 0x02, - 0x01FF, - 0x0400, - 0x0000, - }, - { - 0x00011390, - 0x00000860, - 0x02, - 0x02, - 0x01FF, - 0x0900, - 0x0000, - }, - { - 0x00011BF0, - 0x000005B0, - 0x02, - 0x02, - 0x01FF, - 0x0800, - 0x0000, - }, - { - 0x000121A0, - 0x00000250, - 0x02, - 0x02, - 0x01FF, - 0x0F00, - 0x0000, - }, - { - 0x000123F0, - 0x000004E0, - 0x02, - 0x02, - 0x01FF, - 0x0C00, - 0x0000, - }, - { - 0x000128D0, - 0x000004C0, - 0x02, - 0x02, - 0x01FF, - 0x0500, - 0x0000, - }, - { - 0x00012D90, - 0x00000C00, - 0x02, - 0x02, - 0x01FF, - 0x0C40, - 0x0000, - }, - { - 0x00013990, - 0x00000270, - 0x02, - 0x02, - 0x01FF, - 0x0500, - 0x0000, - }, - { - 0x00013C00, - 0x00000640, - 0x02, - 0x02, - 0x01FF, - 0x0800, - 0x0000, - }, - { - 0x00014240, - 0x00001300, - 0x02, - 0x02, - 0x01FF, - 0x1040, - 0x0000, - }, - { - 0x00015540, - 0x000011A0, - 0x02, - 0x02, - 0x01FF, - 0x1040, - 0x0000, - }, - { - 0x000166E0, - 0x00001720, - 0x02, - 0x02, - 0x01FF, - 0x1040, - 0x0000, - }, - { - 0x00017E00, - 0x00000DE0, - 0x02, - 0x01, - 0x01FF, - 0x0F40, - 0x0000, - }, - { - 0x00018BE0, - 0x00000660, - 0x02, - 0x01, - 0x01FF, - 0x0F00, - 0x0000, - }, - { - 0x00019240, - 0x00012B60, - 0x02, - 0x02, - 0x00FF, - 0x0200, - 0x0000, - }, - } - }; -#endif - -#if 0 -AudioTable gSequenceTable = { 0 }; -#else -AudioTable gSequenceTable = { 0x006E, - 0x0000, - 0x00000000, - { 0 }, - { - { - 0x00000000, - 0x00006A90, - 0x02, - 0x00, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00006A90, - 0x00001040, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00007AD0, - 0x00002500, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00009FD0, - 0x00000AB0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0000AA80, - 0x00000890, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0000B310, - 0x00000980, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0000BC90, - 0x00000B80, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0000C810, - 0x000007A0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0000CFB0, - 0x000005C0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0000D570, - 0x00000730, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0000DCA0, - 0x000006A0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0000E340, - 0x00000740, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0000EA80, - 0x00000900, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0000F380, - 0x000006F0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0000FA70, - 0x00000820, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00010290, - 0x000006B0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00010940, - 0x000007C0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00011100, - 0x00000800, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00011900, - 0x000009F0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000122F0, - 0x00000960, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00012C50, - 0x000005F0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00013240, - 0x00000650, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00013890, - 0x00000580, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00013E10, - 0x00000670, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00014480, - 0x00000170, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000145F0, - 0x00001AB0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000160A0, - 0x000010F0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00017190, - 0x00000F30, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000180C0, - 0x00000310, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000183D0, - 0x00000710, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00018AE0, - 0x00001100, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00019BE0, - 0x00000570, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0001A150, - 0x000001B0, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0001A300, - 0x00000630, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0001A930, - 0x00000150, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0001AA80, - 0x00000560, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0001AFE0, - 0x00000230, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0001B210, - 0x000004C0, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0001B6D0, - 0x000009A0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0001C070, - 0x000028D0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0001E940, - 0x000004D0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0001EE10, - 0x00000A00, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0001F810, - 0x00001240, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00020A50, - 0x00000450, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00020EA0, - 0x00001720, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000225C0, - 0x000005A0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00022B60, - 0x000012E0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00023E40, - 0x000025A0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000263E0, - 0x00000A20, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00026E00, - 0x000011A0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00027FA0, - 0x00000540, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000284E0, - 0x00000490, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00028970, - 0x00000510, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00028E80, - 0x00000790, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00029610, - 0x00000590, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00029BA0, - 0x000005B0, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0002A150, - 0x00001310, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0002B460, - 0x000001C0, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0002B620, - 0x00000980, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0002BFA0, - 0x00000390, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0002C330, - 0x00000F90, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0002D2C0, - 0x000003E0, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0002D6A0, - 0x00000960, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0002E000, - 0x00001A00, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0002FA00, - 0x00001A80, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00031480, - 0x00000660, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00031AE0, - 0x00001AD0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000335B0, - 0x000005B0, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00033B60, - 0x000000B0, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00033C10, - 0x00000140, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00033D50, - 0x00000170, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00033EC0, - 0x00000080, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00033F40, - 0x00000130, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00034070, - 0x000000D0, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00034140, - 0x00000480, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000345C0, - 0x00000410, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000349D0, - 0x00001020, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000359F0, - 0x00000B70, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00036560, - 0x00000E10, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00037370, - 0x000004A0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00037810, - 0x000011A0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000389B0, - 0x00000210, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00038BC0, - 0x00000A30, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000395F0, - 0x00000300, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000398F0, - 0x00000310, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00039C00, - 0x00000EC0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0003AAC0, - 0x00000470, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00000028, - 0x00000000, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0003AF30, - 0x000003A0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0003B2D0, - 0x00000220, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0003B4F0, - 0x00000720, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0003BC10, - 0x00001130, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0003CD40, - 0x00001890, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0003E5D0, - 0x00000490, - 0x02, - 0x01, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0003EA60, - 0x00000160, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0003EBC0, - 0x00001DC0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00040980, - 0x00000360, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00040CE0, - 0x00000AC0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000417A0, - 0x00000CD0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00042470, - 0x00000580, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000429F0, - 0x00001730, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00044120, - 0x000011B0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x000452D0, - 0x00000640, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00045910, - 0x00002610, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00047F20, - 0x000034A0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0004B3C0, - 0x000018B0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0004CC70, - 0x000008A0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0004D510, - 0x00001370, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0004E880, - 0x000008A0, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0004F120, - 0x00000960, - 0x02, - 0x02, - 0x0000, - 0x0000, - 0x0000, - }, - } }; -#endif - -#if 0 -AudioTable gSampleBankTable = { 0 }; -#else -AudioTable gSampleBankTable = { 0x0007, - 0x0000, - 0x00000000, - { 0 }, - { - { - 0x00000000, - 0x003EB2A0, - 0x02, - 0x04, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x00000000, - 0x00000000, - 0x02, - 0x04, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x003EB2A0, - 0x00005CD0, - 0x02, - 0x04, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x003F0F70, - 0x0001D0B0, - 0x02, - 0x04, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x0040E020, - 0x0000A5D0, - 0x02, - 0x04, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x004185F0, - 0x0000FAB0, - 0x02, - 0x04, - 0x0000, - 0x0000, - 0x0000, - }, - { - 0x004280A0, - 0x000292F0, - 0x02, - 0x04, - 0x0000, - 0x0000, - 0x0000, - }, - } - }; -#endif - -#if 0 -u8 gSequenceFontTable[1] = { 0 }; -#else -u8 gSequenceFontTable[0x1C0] = { - 0xDC, - 0x00, - 0xDF, - 0x00, - 0xE1, - 0x00, - 0xE3, - 0x00, - 0xE5, - 0x00, - 0xE7, - 0x00, - 0xE9, - 0x00, - 0xEB, - 0x00, - 0xED, - 0x00, - 0xEF, - 0x00, - 0xF1, - 0x00, - 0xF3, - 0x00, - 0xF5, - 0x00, - 0xF7, - 0x00, - 0xF9, - 0x00, - 0xFB, - 0x00, - 0xFD, - 0x00, - 0xFF, - 0x00, - 0x01, - 0x01, - 0x03, - 0x01, - 0x05, - 0x01, - 0x07, - 0x01, - 0x09, - 0x01, - 0x0B, - 0x01, - 0x0D, - 0x01, - 0x0F, - 0x01, - 0x11, - 0x01, - 0x13, - 0x01, - 0x15, - 0x01, - 0x17, - 0x01, - 0x19, - 0x01, - 0x1B, - 0x01, - 0x1D, - 0x01, - 0x1F, - 0x01, - 0x21, - 0x01, - 0x23, - 0x01, - 0x25, - 0x01, - 0x27, - 0x01, - 0x29, - 0x01, - 0x2B, - 0x01, - 0x2D, - 0x01, - 0x2F, - 0x01, - 0x31, - 0x01, - 0x33, - 0x01, - 0x35, - 0x01, - 0x37, - 0x01, - 0x39, - 0x01, - 0x3B, - 0x01, - 0x3D, - 0x01, - 0x3F, - 0x01, - 0x41, - 0x01, - 0x43, - 0x01, - 0x45, - 0x01, - 0x47, - 0x01, - 0x49, - 0x01, - 0x4B, - 0x01, - 0x4D, - 0x01, - 0x4F, - 0x01, - 0x51, - 0x01, - 0x53, - 0x01, - 0x55, - 0x01, - 0x57, - 0x01, - 0x59, - 0x01, - 0x5B, - 0x01, - 0x5D, - 0x01, - 0x5F, - 0x01, - 0x61, - 0x01, - 0x63, - 0x01, - 0x65, - 0x01, - 0x67, - 0x01, - 0x69, - 0x01, - 0x6B, - 0x01, - 0x6D, - 0x01, - 0x6F, - 0x01, - 0x71, - 0x01, - 0x73, - 0x01, - 0x75, - 0x01, - 0x77, - 0x01, - 0x79, - 0x01, - 0x7B, - 0x01, - 0x7D, - 0x01, - 0x7F, - 0x01, - 0x81, - 0x01, - 0x83, - 0x01, - 0x85, - 0x01, - 0x87, - 0x01, - 0x89, - 0x01, - 0x8B, - 0x01, - 0x8D, - 0x01, - 0x8F, - 0x01, - 0x91, - 0x01, - 0x93, - 0x01, - 0x95, - 0x01, - 0x97, - 0x01, - 0x99, - 0x01, - 0x9B, - 0x01, - 0x9D, - 0x01, - 0x9F, - 0x01, - 0xA1, - 0x01, - 0xA3, - 0x01, - 0xA5, - 0x01, - 0xA7, - 0x01, - 0xA9, - 0x01, - 0xAB, - 0x01, - 0xAD, - 0x01, - 0xAF, - 0x01, - 0xB1, - 0x01, - 0xB3, - 0x01, - 0xB5, - 0x01, - 0xB7, - 0x01, - 0x02, 0x01, 0x00, 0x01, 0x02, 0x01, 0x03, 0x01, - 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, - 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, - 0x03, 0x01, 0x03, 0x01, 0x0B, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, 0x03, - 0x01, 0x23, 0x01, 0x03, 0x01, 0x23, 0x01, 0x03, 0x01, 0x23, 0x01, 0x12, 0x01, 0x07, 0x01, 0x08, 0x01, 0x09, 0x01, - 0x09, 0x01, 0x0A, 0x01, 0x03, 0x01, 0x0C, 0x01, 0x03, 0x01, 0x1E, 0x01, 0x0D, 0x01, 0x0E, 0x01, 0x03, 0x01, 0x03, - 0x01, 0x12, 0x01, 0x12, 0x01, 0x12, 0x01, 0x12, 0x01, 0x12, 0x01, 0x03, 0x01, 0x23, 0x01, 0x09, 0x01, 0x03, 0x01, - 0x0F, 0x01, 0x09, 0x01, 0x05, 0x01, 0x10, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x03, 0x01, 0x00, 0x01, 0x00, - 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x03, 0x01, 0x09, 0x01, 0x08, 0x01, 0x13, 0x01, 0x14, 0x01, - 0x09, 0x01, 0x15, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x03, 0x01, 0x16, 0x01, 0x13, 0x01, 0x09, 0x01, 0x17, - 0x01, 0x12, 0x01, 0x24, 0x01, 0x18, 0x01, 0x19, 0x01, 0x13, 0x01, 0x20, 0x01, 0x1B, 0x01, 0x1C, 0x01, 0x1D, 0x01, - 0x03, 0x01, 0x1F, 0x01, 0x20, 0x01, 0x20, 0x01, 0x09, 0x01, 0x21, 0x01, 0x22, 0x01, 0x21, 0x01, 0x09, 0x01, 0x20, - 0x01, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/soh/src/code/audio_heap.c b/soh/src/code/audio_heap.c index 25f66e4a71b..189d7313382 100644 --- a/soh/src/code/audio_heap.c +++ b/soh/src/code/audio_heap.c @@ -10,8 +10,6 @@ void AudioHeap_DiscardSampleCaches(void); void AudioHeap_DiscardSampleBank(s32 sampleBankId); void AudioHeap_DiscardSampleBanks(void); -extern bool gUseLegacySD; - f32 func_800DDE20(f32 arg0) { return 256.0f * gAudioContext.audioBufferParameters.unkUpdatesPerFrameScaled / arg0; } @@ -1205,15 +1203,6 @@ void AudioHeap_DiscardSampleCacheEntry(SampleCacheEntry* entry) { void AudioHeap_UnapplySampleCache(SampleCacheEntry* entry, SoundFontSample* sample) { - if (!gUseLegacySD) - return; - - if (sample != NULL) { - if (sample->sampleAddr == entry->allocatedAddr) { - sample->sampleAddr = entry->sampleAddr; - sample->medium = entry->origMedium; - } - } } SampleCacheEntry* AudioHeap_AllocPersistentSampleCacheEntry(size_t size) { @@ -1248,6 +1237,8 @@ void AudioHeap_DiscardSampleCaches(void) { s32 fontId; s32 j; + return; + numFonts = gAudioContext.soundFontTable->numEntries; for (fontId = 0; fontId < numFonts; fontId++) { sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1; @@ -1317,6 +1308,8 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) { u32* fakematch; s32 pad[4]; + return; + sampleBankTable = gAudioContext.sampleBankTable; numFonts = gAudioContext.soundFontTable->numEntries; change.oldAddr = AudioHeap_SearchCaches(SAMPLE_TABLE, CACHE_EITHER, sampleBankId); diff --git a/soh/src/code/audio_load.c b/soh/src/code/audio_load.c index aced2fe94b8..eff3e5f8730 100644 --- a/soh/src/code/audio_load.c +++ b/soh/src/code/audio_load.c @@ -82,8 +82,6 @@ char* fontMap[256]; uintptr_t fontStart; uint32_t fontOffsets[8192]; -bool gUseLegacySD = false; - void AudioLoad_DecreaseSampleDmaTtls(void) { u32 i; @@ -483,26 +481,15 @@ void AudioLoad_AsyncLoadFont(s32 fontId, s32 arg1, s32 retData, OSMesgQueue* ret u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) { s32 index; - if (!gUseLegacySD) - { - if (seqId == 255) - return NULL; - - SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); + if (seqId == 255) + return NULL; - if (sDat.numFonts == 0) - return NULL; + SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); - return sDat.fonts; - } else { - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; + if (sDat.numFonts == 0) + return NULL; - *outNumFonts = gAudioContext.sequenceFontTable[index++]; - if (*outNumFonts == 0) { - return NULL; - } - return &gAudioContext.sequenceFontTable[index]; - } + return sDat.fonts; } void AudioLoad_DiscardSeqFonts(s32 seqId) { @@ -578,38 +565,19 @@ s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) { s32 numFonts; s32 fontId; - if (gUseLegacySD && seqId >= gAudioContext.numSequences) { - return 0; - } - AudioSeq_SequencePlayerDisable(seqPlayer); fontId = 0xFF; - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; - numFonts = gAudioContext.sequenceFontTable[index++]; - - if (gUseLegacySD) { - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; - numFonts = gAudioContext.sequenceFontTable[index++]; + //index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; + //numFonts = gAudioContext.sequenceFontTable[index++]; - while (numFonts > 0) { - fontId = gAudioContext.sequenceFontTable[index++]; + SequenceData seqData2 = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); - AudioLoad_SyncLoadFont(fontId); // NOTE: If this is commented out, then enemies will play child link sounds... - - numFonts--; - } - } - else + for (int i = 0; i < seqData2.numFonts; i++) { - SequenceData seqData2 = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); - - for (int i = 0; i < seqData2.numFonts; i++) - { - fontId = seqData2.fonts[i]; - AudioLoad_SyncLoadFont(fontId); // NOTE: If this is commented out, then enemies will play child link sounds... - numFonts--; - } + fontId = seqData2.fonts[i]; + AudioLoad_SyncLoadFont(fontId); // NOTE: If this is commented out, then enemies will play child link sounds... + //numFonts--; } seqData = AudioLoad_SyncLoadSeq(seqId); @@ -620,10 +588,7 @@ s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) { AudioSeq_ResetSequencePlayer(seqPlayer); seqPlayer->seqId = seqId; - if (gUseLegacySD) - seqPlayer->defaultFont = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId); - else - seqPlayer->defaultFont = fontId; + seqPlayer->defaultFont = fontId; seqPlayer->seqData = seqData; seqPlayer->enabled = 1; @@ -667,8 +632,8 @@ uintptr_t AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 return ret; } - cachePolicy = sampleBankTable->entries[sampleBankId].cachePolicy; - if (cachePolicy == 4 || noLoad == true) { + //cachePolicy = sampleBankTable->entries[sampleBankId].cachePolicy; + if (/* cachePolicy == 4 || */ noLoad == true) { *outMedium = sampleBankTable->entries[sampleBankId].medium; return sampleBankTable->entries[realTableId].romAddr; } @@ -695,31 +660,24 @@ SoundFontData* AudioLoad_SyncLoadFont(u32 fontId) { return NULL; } - if (!gUseLegacySD) { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont - (fontMap[fontId]); - - sampleBankId1 = sf->sampleBankId1; - sampleBankId2 = sf->sampleBankId2; - } else { + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); - sampleBankId1 = gAudioContext.soundFonts[realFontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFonts[realFontId].sampleBankId2; - } + sampleBankId1 = sf->sampleBankId1; + sampleBankId2 = sf->sampleBankId2; relocInfo.sampleBankId1 = sampleBankId1; relocInfo.sampleBankId2 = sampleBankId2; - if (sampleBankId1 != 0xFF) { - relocInfo.baseAddr1 = AudioLoad_TrySyncLoadSampleBank(sampleBankId1, &relocInfo.medium1, false); - } else { + //if (sampleBankId1 != 0xFF) { + //relocInfo.baseAddr1 = AudioLoad_TrySyncLoadSampleBank(sampleBankId1, &relocInfo.medium1, false); + //} else { relocInfo.baseAddr1 = 0; - } + //} - if (sampleBankId2 != 0xFF) { - relocInfo.baseAddr2 = AudioLoad_TrySyncLoadSampleBank(sampleBankId2, &relocInfo.medium2, false); - } else { + //if (sampleBankId2 != 0xFF) { + //relocInfo.baseAddr2 = AudioLoad_TrySyncLoadSampleBank(sampleBankId2, &relocInfo.medium2, false); + //} else { relocInfo.baseAddr2 = 0; - } + //} ret = AudioLoad_SyncLoad(FONT_TABLE, fontId, &didAllocate); if (ret == NULL) { @@ -752,7 +710,7 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { char* seqData = 0; SoundFont* fnt; - if (!gUseLegacySD && tableType == SEQUENCE_TABLE) + if (tableType == SEQUENCE_TABLE) { SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[id]); seqData = sData.seqData; @@ -761,7 +719,7 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { cachePolicy = sData.cachePolicy; romAddr = 0; } - else if (!gUseLegacySD && tableType == FONT_TABLE) + else if (tableType == FONT_TABLE) { fnt = ResourceMgr_LoadAudioSoundFont(fontMap[id]); size = sizeof(SoundFont); @@ -771,12 +729,12 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { } else { - table = AudioLoad_GetLoadTable(tableType); - size = table->entries[realId].size; + //table = AudioLoad_GetLoadTable(tableType); + //size = table->entries[realId].size; //size = ALIGN16(size); - medium = table->entries[id].medium; - cachePolicy = table->entries[id].cachePolicy; - romAddr = table->entries[realId].romAddr; + //medium = table->entries[id].medium; + //cachePolicy = table->entries[id].cachePolicy; + //romAddr = table->entries[realId].romAddr; } switch (cachePolicy) { @@ -811,13 +769,13 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { if (medium == MEDIUM_UNK) { AudioLoad_SyncDmaUnkMedium(romAddr, ret, size, (s16)table->unkMediumParam); } else { - if (!gUseLegacySD && tableType == SEQUENCE_TABLE && seqData != NULL) { + if (tableType == SEQUENCE_TABLE && seqData != NULL) { AudioLoad_SyncDma(seqData, ret, size, medium); - } else if (!gUseLegacySD && tableType == FONT_TABLE) { + } else if (tableType == FONT_TABLE) { AudioLoad_SyncDma(fnt, ret, size, medium); } else { - AudioLoad_SyncDma(romAddr, ret, size, medium); + //AudioLoad_SyncDma(romAddr, ret, size, medium); } } @@ -843,17 +801,17 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 id) { - if ((tableType == SEQUENCE_TABLE || tableType == FONT_TABLE) && !gUseLegacySD) { + if ((tableType == SEQUENCE_TABLE || tableType == FONT_TABLE)) { return id; } - AudioTable* table = AudioLoad_GetLoadTable(tableType); + //AudioTable* table = AudioLoad_GetLoadTable(tableType); // If the size is 0, then this entry actually redirects to another entry. // The rom address is actually an index into the same table where the "real" data is. - if (table->entries[id].size == 0) { - id = table->entries[id].romAddr; - } + //if (table->entries[id].size == 0) { + //id = table->entries[id].romAddr; + //} return id; } @@ -906,77 +864,37 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo s32 numInstruments = 0; s32 numSfx = 0; - if (gUseLegacySD) { - numDrums = gAudioContext.soundFonts[fontId].numDrums; - numInstruments = gAudioContext.soundFonts[fontId].numInstruments; - numSfx = gAudioContext.soundFonts[fontId].numSfx; - } else { - sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); - numDrums = sf->numDrums; - numInstruments = sf->numInstruments; - numSfx = sf->numSfx; - } + sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + numDrums = sf->numDrums; + numInstruments = sf->numInstruments; + numSfx = sf->numSfx; void** ptrs = (void**)mem; #define BASE_OFFSET(x) (void*)((u32)(x) + (u32)(mem)) reloc2 = ptrs[0]; - if ((reloc2 != 0 || !gUseLegacySD) && (numDrums != 0)) + if ((numDrums != 0)) { ptrs[0] = BASE_OFFSET(reloc2); for (i = 0; i < numDrums; i++) { - if (gUseLegacySD) - reloc = ((Drum**)ptrs[0])[i]; + drum = sf->drums[i]; - if (reloc != 0 || !gUseLegacySD) + if (!drum->loaded) { - if (gUseLegacySD) - { - reloc = BASE_OFFSET(reloc); - ((Drum**)ptrs[0])[i] = drum = reloc; - } - - if (!gUseLegacySD) - drum = sf->drums[i]; - - if (!drum->loaded) - { - if (!gUseLegacySD) - { - AudioLoad_RelocateSample(&sf->drums[i]->sound, mem, relocInfo, fontOffsets[fontId]); - //reloc = drum->envelope; - drum->loaded = 1; - } - else - { - AudioLoad_RelocateSample(&drum->sound, mem, relocInfo, fontOffsets[fontId]); - reloc = drum->envelope; - drum->envelope = BASE_OFFSET(reloc); - drum->loaded = 1; - } - } + AudioLoad_RelocateSample(&sf->drums[i]->sound, mem, relocInfo, fontOffsets[fontId]); + drum->loaded = 1; } } } reloc2 = ptrs[1]; - if ((reloc2 != 0 || !gUseLegacySD) && (numSfx != 0)) { + if (numSfx != 0) { ptrs[1] = BASE_OFFSET(reloc2); for (i = 0; i < numSfx; i++) { reloc = (SoundFontSound*)ptrs[1] + i; - if (reloc != 0 || !gUseLegacySD) - { - if (!gUseLegacySD) { - AudioLoad_RelocateSample(&sf->soundEffects[i].sample, mem, relocInfo, fontOffsets[fontId]); - } else { - sfx = reloc; - if (sfx->sample != NULL) { - AudioLoad_RelocateSample(sfx, mem, relocInfo, fontOffsets[fontId]); - } - } - } + AudioLoad_RelocateSample(&sf->soundEffects[i].sample, mem, relocInfo, fontOffsets[fontId]); } } @@ -984,46 +902,28 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo numInstruments = 0x7E; } - int startI = gUseLegacySD ? 2 : 0; - int startEC = gUseLegacySD ? 2 + numInstruments - 1 : numInstruments - 1; - //for (i = 2; i <= 2 + numInstruments - 1; i++) { + int startI = 0; + int startEC = numInstruments - 1; for (i = startI; i <= startEC; i++) { - if (!gUseLegacySD || ptrs[i] != NULL) - { - ptrs[i] = BASE_OFFSET(ptrs[i]); - - if (gUseLegacySD) - inst = ptrs[i]; - else - inst = sf->instruments[i]; - - if (inst != NULL && !inst->loaded) { - if (inst->normalRangeLo != 0) - { - AudioLoad_RelocateSample(&inst->lowNotesSound, mem, relocInfo, fontOffsets[fontId]); - } - AudioLoad_RelocateSample(&inst->normalNotesSound, mem, relocInfo, fontOffsets[fontId]); - if (inst->normalRangeHi != 0x7F) { - AudioLoad_RelocateSample(&inst->highNotesSound, mem, relocInfo, fontOffsets[fontId]); - } + ptrs[i] = BASE_OFFSET(ptrs[i]); + inst = sf->instruments[i]; - reloc = inst->envelope; - - if (gUseLegacySD) - inst->envelope = BASE_OFFSET(reloc); - - inst->loaded = 1; + if (inst != NULL && !inst->loaded) { + if (inst->normalRangeLo != 0) + { + AudioLoad_RelocateSample(&inst->lowNotesSound, mem, relocInfo, fontOffsets[fontId]); + } + AudioLoad_RelocateSample(&inst->normalNotesSound, mem, relocInfo, fontOffsets[fontId]); + if (inst->normalRangeHi != 0x7F) { + AudioLoad_RelocateSample(&inst->highNotesSound, mem, relocInfo, fontOffsets[fontId]); } + + reloc = inst->envelope; + inst->loaded = 1; } } #undef BASE_OFFSET - - if (gUseLegacySD) { - gAudioContext.soundFonts[fontId].drums = ptrs[0]; - gAudioContext.soundFonts[fontId].soundEffects = ptrs[1]; - gAudioContext.soundFonts[fontId].instruments = (Instrument**)(ptrs + 2); - } } void AudioLoad_SyncDma(uintptr_t devAddr, u8* addr, size_t size, s32 medium) { @@ -1209,24 +1109,6 @@ s32 AudioLoad_AssertValidAddr(uintptr_t ramAddr, uintptr_t startAddr, size_t siz #define BASE_ROM_OFFSET(x) (uintptr_t)((uintptr_t)(x) + (uintptr_t)(romAddr)) void AudioLoad_InitSwapFontSampleHeaders(SoundFontSample* sample, uintptr_t romAddr) { - size_t maxSoundFontSize = 0x3AA0; // soundFont 0 is the largest size at 0x3AA0 - AdpcmLoop* loop; - AdpcmBook* book; - - if (((uintptr_t)sample->loop > maxSoundFontSize) || ((uintptr_t)sample->book > maxSoundFontSize) ) { - bswapSoundFontSample(sample); - - loop = (AdpcmLoop*)BASE_ROM_OFFSET(sample->loop); - if ((uint32_t)loop->end > (uint32_t)0xFFFF) { - bswapAdpcmLoop(loop); - } - - book = (AdpcmBook*)BASE_ROM_OFFSET(sample->book); - if (book->order > 0xFFFF) { - bswapAdpcmBook(book); - } - } - return; } void AudioLoad_InitSwapFont(void) { @@ -1273,7 +1155,6 @@ void AudioLoad_InitSwapFont(void) { if (drumList[i] != NULL) { drum = (Drum*)BASE_ROM_OFFSET(drumList[i]); - bswapDrum(drum); sample = (SoundFontSample*)BASE_ROM_OFFSET(drum->sound.sample); AudioLoad_InitSwapFontSampleHeaders(sample, romAddr); @@ -1289,7 +1170,6 @@ void AudioLoad_InitSwapFont(void) { for (i = 0; i < numSfxs; i++) { sfx = &sfxList[i]; - bswapSoundFontSound(sfx); if (sfx->sample != NULL) { SoundFontSample* sample = (SoundFontSample*)BASE_ROM_OFFSET(sfx->sample); @@ -1309,7 +1189,6 @@ void AudioLoad_InitSwapFont(void) { if (instList[i] != NULL) { inst = BASE_ROM_OFFSET(instList[i]); - bswapInstrument(inst); if (inst->normalRangeLo != 0) { sample = (SoundFontSample*)BASE_ROM_OFFSET(inst->lowNotesSound.sample); @@ -1402,79 +1281,50 @@ void AudioLoad_Init(void* heap, size_t heapSize) { gAudioContext.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioContext.audioInitPool, AIBUF_LEN * sizeof(s16)); } - gAudioContext.sequenceTable = (AudioTable*)gSequenceTable; - gAudioContext.soundFontTable = (AudioTable*)gSoundFontTable; - gAudioContext.sampleBankTable = (AudioTable*)gSampleBankTable; - gAudioContext.sequenceFontTable = gSequenceFontTable; - gAudioContext.numSequences = gAudioContext.sequenceTable->numEntries; + //gAudioContext.sequenceTable = (AudioTable*)gSequenceTable; + //gAudioContext.soundFontTable = (AudioTable*)gSoundFontTable; + //gAudioContext.sampleBankTable = (AudioTable*)gSampleBankTable; + //gAudioContext.sequenceFontTable = gSequenceFontTable; + //gAudioContext.numSequences = gAudioContext.sequenceTable->numEntries; gAudioContext.audioResetSpecIdToLoad = 0; gAudioContext.resetStatus = 1; AudioHeap_ResetStep(); - uintptr_t seqStart = ResourceMgr_LoadFileRaw(_AudioseqSegmentRomStart); - uintptr_t bankStart = ResourceMgr_LoadFileRaw(_AudiobankSegmentRomStart); - uintptr_t tableStart = ResourceMgr_LoadFileRaw(_AudiotableSegmentRomStart); + int seqListSize = 0; + char** seqList = ResourceMgr_ListFiles("audio/sequences*", &seqListSize); - // If we have the old audioseq files present (and this is a 32-bit build), use the legacy audio system - if (seqStart != NULL && bankStart != NULL && tableStart != NULL) - gUseLegacySD = true; - - fontStart = bankStart; - - AudioLoad_InitTable(gAudioContext.sequenceTable, seqStart, 0); - AudioLoad_InitTable(gAudioContext.soundFontTable, bankStart, 0); - AudioLoad_InitTable(gAudioContext.sampleBankTable, tableStart, 0); - - if (gUseLegacySD) - numFonts = gAudioContext.soundFontTable->numEntries; - - if (gUseLegacySD) + for (size_t i = 0; i < seqListSize; i++) { - gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); - - for (i = 0; i < numFonts; i++) { - AudioLoad_InitSoundFontMeta(i); - } + SequenceData sDat = ResourceMgr_LoadSeqByName(seqList[i]); - AudioLoad_InitSwapFont(); - } else { - int seqListSize = 0; - char** seqList = ResourceMgr_ListFiles("audio/sequences*", &seqListSize); - - for (size_t i = 0; i < seqListSize; i++) - { - SequenceData sDat = ResourceMgr_LoadSeqByName(seqList[i]); - - char* str = malloc(strlen(seqList[i]) + 1); - strcpy(str, seqList[i]); + char* str = malloc(strlen(seqList[i]) + 1); + strcpy(str, seqList[i]); - sequenceMap[sDat.seqNumber] = str; - } + sequenceMap[sDat.seqNumber] = str; + } - free(seqList); + free(seqList); - int fntListSize = 0; - char** fntList = ResourceMgr_ListFiles("audio/fonts*", &fntListSize); + int fntListSize = 0; + char** fntList = ResourceMgr_ListFiles("audio/fonts*", &fntListSize); - for (int i = 0; i < fntListSize; i++) - { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fntList[i]); + for (int i = 0; i < fntListSize; i++) + { + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fntList[i]); - char* str = malloc(strlen(fntList[i]) + 1); - strcpy(str, fntList[i]); + char* str = malloc(strlen(fntList[i]) + 1); + strcpy(str, fntList[i]); - fontMap[sf->fntIndex] = str; - } + fontMap[sf->fntIndex] = str; + } numFonts = fntListSize; free(fntList); gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); - } - if (temp_v0_3 = AudioHeap_Alloc(&gAudioContext.audioInitPool, D_8014A6C4.permanentPoolSize), temp_v0_3 == NULL) { // cast away const from D_8014A6C4 @@ -1648,11 +1498,6 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* isDone) { AudioTable* seqTable; size_t size; - if (gUseLegacySD && seqId >= gAudioContext.numSequences) { - *isDone = 0; - return -1; - } - seqId = AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId); seqTable = AudioLoad_GetLoadTable(SEQUENCE_TABLE); slowLoad = &gAudioContext.slowLoads[gAudioContext.slowLoadPos]; @@ -1663,19 +1508,11 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* isDone) { slowLoad->sample.sampleAddr = NULL; slowLoad->isDone = isDone; - if (!gUseLegacySD) - { - SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); - char* seqData = sData.seqData; - size = sData.seqDataSize; - slowLoad->curDevAddr = seqData; - slowLoad->medium = sData.medium; - } else { - size = seqTable->entries[seqId].size; - size = ALIGN16(size); - slowLoad->curDevAddr = seqTable->entries[seqId].romAddr; - slowLoad->medium = seqTable->entries[seqId].medium; - } + SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); + char* seqData = sData.seqData; + size = sData.seqDataSize; + slowLoad->curDevAddr = seqData; + slowLoad->medium = sData.medium; slowLoad->curRamAddr = ramAddr; slowLoad->status = LOAD_STATUS_START; @@ -1889,61 +1726,10 @@ void AudioLoad_AsyncDma(AudioAsyncLoad* asyncLoad, size_t size) { void AudioLoad_AsyncDmaUnkMedium(uintptr_t devAddr, uintptr_t ramAddr, size_t size, s16 arg3) { } -#define RELOC(v, base) (reloc = (uintptr_t)((uintptr_t)(v) + (uintptr_t)(base))) - -void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo, int fontId) { - size_t maxSoundBankSize = 0x3EB2A0; // sample bank 0 is largest size at 0x3EB2A0 - if (gUseLegacySD) - { - // NOTE: This is hack to detect whether or not the sample has been relocated. - if ((uintptr_t)mem <= maxSoundBankSize) { - assert("mem for sound font bank is too low."); - } - } - - SoundFontSample* sample; - void* reloc; - - // NOTE: Seems precarious to assume the RAM is never <= 0x3EB2A0, but it largely works. - if ((uintptr_t)sound->sample < maxSoundBankSize || !gUseLegacySD) - { - if (!gUseLegacySD) { - SoundFontSample* sample2 = sound; - } else { - sample = sound->sample = RELOC(sound->sample, mem); - - if (sample->size != 0 && sample->unk_bit25 != 1) { - sample->loop = RELOC(sample->loop, mem); - sample->book = RELOC(sample->book, mem); - - // Resolve the sample medium 2-bit bitfield into a real value based on relocInfo. - switch (sample->medium) { - case 0: - sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr1); - sample->medium = relocInfo->medium1; - break; - case 1: - sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr2); - sample->medium = relocInfo->medium2; - break; - case 2: - case 3: - // Invalid? This leaves sample->medium as MEDIUM_CART and MEDIUM_DISK_DRIVE - // respectively, and the sampleAddr unrelocated. - break; - } - - sample->unk_bit25 = 1; - if (sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) { - gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; - } - } - } - } +void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo, int fontId) +{ } -#undef RELOC - void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo, s32 async) { AudioPreloadReq* preload; AudioPreloadReq* topPreload; @@ -2190,17 +1976,11 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, RelocInfo* relocInfo gAudioContext.numUsedSamples = 0; - if (!gUseLegacySD) { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); - numDrums = sf->numDrums; - numInstruments = sf->numInstruments; - numSfx = sf->numSfx; - } else { - numDrums = gAudioContext.soundFonts[fontId].numDrums; - numInstruments = gAudioContext.soundFonts[fontId].numInstruments; - numSfx = gAudioContext.soundFonts[fontId].numSfx; - } + numDrums = sf->numDrums; + numInstruments = sf->numInstruments; + numSfx = sf->numSfx; for (i = 0; i < numInstruments; i++) { instrument = Audio_GetInstrumentInner(fontId, i); @@ -2326,15 +2106,11 @@ void AudioLoad_LoadPermanentSamples(void) { fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.permanentCache[i].id); //fontId = gAudioContext.permanentCache[i].id; - if (!gUseLegacySD) { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); - relocInfo.sampleBankId1 = sf->sampleBankId1; - relocInfo.sampleBankId2 = sf->sampleBankId2; - } else { - relocInfo.sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1; - relocInfo.sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2; - } + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + relocInfo.sampleBankId1 = sf->sampleBankId1; + relocInfo.sampleBankId2 = sf->sampleBankId2; + /* if (relocInfo.sampleBankId1 != 0xFF) { relocInfo.sampleBankId1 = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, relocInfo.sampleBankId1); relocInfo.medium1 = sampleBankTable->entries[relocInfo.sampleBankId1].medium; @@ -2344,6 +2120,8 @@ void AudioLoad_LoadPermanentSamples(void) { relocInfo.sampleBankId2 = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, relocInfo.sampleBankId2); relocInfo.medium2 = sampleBankTable->entries[relocInfo.sampleBankId2].medium; } + */ + AudioLoad_PreloadSamplesForFont(fontId, false, &relocInfo); } } diff --git a/soh/src/code/audio_playback.c b/soh/src/code/audio_playback.c index 85811f68e75..b2017b5146c 100644 --- a/soh/src/code/audio_playback.c +++ b/soh/src/code/audio_playback.c @@ -288,7 +288,8 @@ void Audio_ProcessNotes(void) { f32 resampRate = gAudioContext.audioBufferParameters.resampleRate; - if (!gUseLegacySD && !noteSubEu2->bitField1.isSyntheticWave && noteSubEu2->sound.soundFontSound != NULL && + // CUSTOM SAMPLE CHECK + if (!noteSubEu2->bitField1.isSyntheticWave && noteSubEu2->sound.soundFontSound != NULL && noteSubEu2->sound.soundFontSound->sample != NULL && noteSubEu2->sound.soundFontSound->sample->sampleRateMagicValue == 'RIFF') { resampRate = CALC_RESAMPLE_FREQ(noteSubEu2->sound.soundFontSound->sample->sampleRate); @@ -330,24 +331,12 @@ Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) { } int instCnt = 0; + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); - if (gUseLegacySD) { - instCnt = gAudioContext.soundFonts[fontId].numInstruments; - inst = gAudioContext.soundFonts[fontId].instruments[instId]; - - if (instId >= gAudioContext.soundFonts[fontId].numInstruments) - if (instId >= instCnt) { - gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000; - return NULL; - } - } else { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); - - if (instId >= sf->numInstruments) - return NULL; + if (instId >= sf->numInstruments) + return NULL; - inst = sf->instruments[instId]; - } + inst = sf->instruments[instId]; if (inst == NULL) { gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000; @@ -369,18 +358,10 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) { return NULL; } - if (gUseLegacySD) { - if (drumId >= gAudioContext.soundFonts[fontId].numDrums) { - gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000; - return NULL; - } - - drum = gAudioContext.soundFonts[fontId].drums[drumId]; - } else { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); - drum = sf->drums[drumId]; - } - + + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + drum = sf->drums[drumId]; + if (drum == NULL) { gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000; } @@ -400,17 +381,8 @@ SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId) { return NULL; } - if (gUseLegacySD) { - if (sfxId >= gAudioContext.soundFonts[fontId].numSfx) { - gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000; - return NULL; - } - - sfx = &gAudioContext.soundFonts[fontId].soundEffects[sfxId]; - } else { - SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); - sfx = &sf->soundEffects[sfxId]; - } + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + sfx = &sf->soundEffects[sfxId]; if (sfx == NULL) { gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000; diff --git a/soh/src/code/audio_seqplayer.c b/soh/src/code/audio_seqplayer.c index 6e33e94e167..3ae70719cee 100644 --- a/soh/src/code/audio_seqplayer.c +++ b/soh/src/code/audio_seqplayer.c @@ -3,7 +3,6 @@ #include "ultra64.h" #include "global.h" -extern bool gUseLegacySD; extern char* sequenceMap[256]; #define PORTAMENTO_IS_SPECIAL(x) ((x).mode & 0x80) @@ -1062,18 +1061,14 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { result = (u8)parameters[0]; command = (u8)parameters[0]; - if (seqPlayer->defaultFont != 0xFF) { - if (gUseLegacySD) { - offset = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId]; - lowBits = gAudioContext.sequenceFontTable[offset]; - command = gAudioContext.sequenceFontTable[offset + lowBits - result]; - } else { - SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqPlayer->seqId]); - command = sDat.fonts[sDat.numFonts - result - 1]; - } + if (seqPlayer->defaultFont != 0xFF) + { + SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqPlayer->seqId]); + command = sDat.fonts[sDat.numFonts - result - 1]; } - if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, command)) { + if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, command)) + { channel->fontId = command; } @@ -1178,18 +1173,16 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { result = (u8)parameters[0]; command = (u8)parameters[0]; - if (seqPlayer->defaultFont != 0xFF) { - if (gUseLegacySD) { - offset = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId]; - lowBits = gAudioContext.sequenceFontTable[offset]; - command = gAudioContext.sequenceFontTable[offset + lowBits - result]; - } else { - SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqPlayer->seqId]); - command = sDat.fonts[sDat.numFonts - result - 1]; - } + if (seqPlayer->defaultFont != 0xFF) + { + SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqPlayer->seqId]); + int8_t idx = (sDat.numFonts - result - 1); + + command = sDat.fonts[abs(idx)]; } - if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, command)) { + if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, command)) + { channel->fontId = command; } diff --git a/soh/src/code/z_kankyo.c b/soh/src/code/z_kankyo.c index 9eb91118b20..de654dfbb20 100644 --- a/soh/src/code/z_kankyo.c +++ b/soh/src/code/z_kankyo.c @@ -2095,10 +2095,8 @@ void func_80075B44(GlobalContext* globalCtx) { { // OTRTODO: This is where corrupt audio happens. Commenting this out seems to not introduce any side effects? // Further investigation is needed... - - if (gUseLegacySD) - Audio_SetNatureAmbienceChannelIO(NATURE_CHANNEL_CRITTER_4 << 4 | NATURE_CHANNEL_CRITTER_5, - CHANNEL_IO_PORT_1, 1); + //Audio_SetNatureAmbienceChannelIO(NATURE_CHANNEL_CRITTER_4 << 4 | NATURE_CHANNEL_CRITTER_5, + //CHANNEL_IO_PORT_1, 1); } globalCtx->envCtx.unk_E0++; break;