From 93a6a1eb9abd2f70a28c6c87260580d6725bd85b Mon Sep 17 00:00:00 2001 From: engineer124 <47598039+engineer124@users.noreply.github.com> Date: Mon, 13 Jun 2022 09:47:53 +1000 Subject: [PATCH] Audio_Init_Params.c Cleanup (#1273) * Document Audio Heap Init Sizes * Swap order * Another small change * Another * Plural * swap order * Reverb Settings * Return comment * more cleanup * Fix data names --- include/variables.h | 2 +- include/z64audio.h | 6 +-- src/code/audio_heap.c | 12 +++--- src/code/audio_init_params.c | 84 ++++++++++++++++++++++-------------- src/code/audio_load.c | 16 +++---- src/code/code_800EC960.c | 2 +- 6 files changed, 70 insertions(+), 52 deletions(-) diff --git a/include/variables.h b/include/variables.h index 21a97a9293..e302603433 100644 --- a/include/variables.h +++ b/include/variables.h @@ -159,7 +159,7 @@ extern s32 __osPfsLastChannel; extern const s16 D_8014A6C0[]; #define gTatumsPerBeat (D_8014A6C0[1]) -extern const AudioContextInitSizes D_8014A6C4; +extern const AudioHeapInitSizes gAudioHeapInitSizes; extern s16 gOcarinaSongItemMap[]; extern u8 gSoundFontTable[]; extern u8 gSequenceFontTable[]; diff --git a/include/z64audio.h b/include/z64audio.h index f13c6e759a..67a98fb408 100644 --- a/include/z64audio.h +++ b/include/z64audio.h @@ -864,9 +864,9 @@ typedef struct { /* 0x2980 */ s32 audioErrorFlags; /* 0x2984 */ volatile u32 resetTimer; /* 0x2988 */ char unk_2988[0x8]; - /* 0x2990 */ AudioAllocPool audioSessionPool; // A sub-pool to main pool, contains all sub-pools and data that changes every audio reset + /* 0x2990 */ AudioAllocPool sessionPool; // A sub-pool to main pool, contains all sub-pools and data that changes every audio reset /* 0x29A0 */ AudioAllocPool externalPool; // pool allocated externally to the audio heap. Never used in game - /* 0x29B0 */ AudioAllocPool audioInitPool;// A sub-pool to the main pool, contains all sub-pools and data that persists every audio reset + /* 0x29B0 */ AudioAllocPool initPool;// A sub-pool to the main pool, contains all sub-pools and data that persists every audio reset /* 0x29C0 */ AudioAllocPool miscPool; // A sub-pool to the session pool. /* 0x29D0 */ char unk_29D0[0x20]; // probably two unused pools /* 0x29F0 */ AudioAllocPool cachePool; // The common pool for cache entries @@ -932,7 +932,7 @@ typedef struct { /* 0x00 */ u32 heapSize; // total number of bytes allocated to the audio heap. Must be <= the size of `gAudioHeap` (ideally about the same size) /* 0x04 */ u32 initPoolSize; // The entire audio heap is split into two pools. /* 0x08 */ u32 permanentPoolSize; -} AudioContextInitSizes; // size = 0xC +} AudioHeapInitSizes; // size = 0xC typedef struct { /* 0x00 */ f32 unk_00; diff --git a/src/code/audio_heap.c b/src/code/audio_heap.c index 147ce16b9d..905e69649c 100644 --- a/src/code/audio_heap.c +++ b/src/code/audio_heap.c @@ -275,18 +275,18 @@ void AudioHeap_PopCache(s32 tableType) { } void AudioHeap_InitMainPools(s32 initPoolSize) { - AudioHeap_AllocPoolInit(&gAudioContext.audioInitPool, gAudioContext.audioHeap, initPoolSize); - AudioHeap_AllocPoolInit(&gAudioContext.audioSessionPool, gAudioContext.audioHeap + initPoolSize, + AudioHeap_AllocPoolInit(&gAudioContext.initPool, gAudioContext.audioHeap, initPoolSize); + AudioHeap_AllocPoolInit(&gAudioContext.sessionPool, gAudioContext.audioHeap + initPoolSize, gAudioContext.audioHeapSize - initPoolSize); gAudioContext.externalPool.startRamAddr = NULL; } void AudioHeap_SessionPoolsInit(AudioSessionPoolSplit* split) { - gAudioContext.audioSessionPool.curRamAddr = gAudioContext.audioSessionPool.startRamAddr; + gAudioContext.sessionPool.curRamAddr = gAudioContext.sessionPool.startRamAddr; AudioHeap_AllocPoolInit(&gAudioContext.miscPool, - AudioHeap_Alloc(&gAudioContext.audioSessionPool, split->miscPoolSize), split->miscPoolSize); + AudioHeap_Alloc(&gAudioContext.sessionPool, split->miscPoolSize), split->miscPoolSize); AudioHeap_AllocPoolInit(&gAudioContext.cachePool, - AudioHeap_Alloc(&gAudioContext.audioSessionPool, split->cachePoolSize), + AudioHeap_Alloc(&gAudioContext.sessionPool, split->cachePoolSize), split->cachePoolSize); } @@ -925,7 +925,7 @@ void AudioHeap_Init(void) { temporarySize = spec->temporarySeqCacheSize + spec->temporaryFontCacheSize + spec->temporarySampleBankCacheSize + 0x10; cachePoolSize = persistentSize + temporarySize; - miscPoolSize = gAudioContext.audioSessionPool.size - cachePoolSize - 0x100; + miscPoolSize = gAudioContext.sessionPool.size - cachePoolSize - 0x100; if (gAudioContext.externalPool.startRamAddr != NULL) { gAudioContext.externalPool.curRamAddr = gAudioContext.externalPool.startRamAddr; diff --git a/src/code/audio_init_params.c b/src/code/audio_init_params.c index 0cebdf5964..d515c45801 100644 --- a/src/code/audio_init_params.c +++ b/src/code/audio_init_params.c @@ -10,79 +10,97 @@ const s16 D_8014A6C0[] = { 0x0030, // gTatumsPerBeat }; -const AudioContextInitSizes D_8014A6C4 = { 0x37F00, 0xE0E0, 0xBCE0 }; +// TODO: Extract from table? +#define NUM_SOUNDFONTS 38 +#define SFX_SEQ_SIZE 0x6A90 +#define SFX_SOUNDFONT_1_SIZE 0x3AA0 +#define SFX_SOUNDFONT_2_SIZE 0x17B0 -ReverbSettings D_80133420[][3] = { +// Sizes of everything on the init pool +#define AI_BUFFERS_SIZE (AIBUF_LEN * sizeof(s16) * ARRAY_COUNT(gAudioContext.aiBuffers)) +#define SOUNDFONT_INFO_SIZE (NUM_SOUNDFONTS * sizeof(SoundFont)) +#define PERMANENT_POOL_SIZE (SFX_SEQ_SIZE + SFX_SOUNDFONT_1_SIZE + SFX_SOUNDFONT_2_SIZE) + +const AudioHeapInitSizes gAudioHeapInitSizes = { + ALIGN16(sizeof(gAudioHeap) - 0x100), // audio heap size + ALIGN16(PERMANENT_POOL_SIZE + AI_BUFFERS_SIZE + SOUNDFONT_INFO_SIZE), // init pool size + ALIGN16(PERMANENT_POOL_SIZE), // permanent pool size +}; + +#define DEFAULT_REVERB_SETTINGS \ + { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 } + +ReverbSettings sReverbSettings[][3] = { { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, { 1, 0x20, 0x0800, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x0000, 0x0, 0x0 }, }, { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, { 1, 0x30, 0x1800, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x0000, 0xB, 0xB }, }, { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, { 1, 0x38, 0x2800, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x0000, 0x7, 0x7 }, }, { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, { 1, 0x50, 0x5000, 0, 0, 0x7FFF, 0x1000, 0x1000, 0xFF, 0x3000, 0x7, 0x7 }, }, { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, { 1, 0x40, 0x5000, 0, 0, 0x7FFF, 0x1800, 0x1800, 0xFF, 0x3000, 0x7, 0x7 }, }, { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, { 1, 0x40, 0x5C00, 0, 0, 0x7FFF, 0x2000, 0x2000, 0xFF, 0x3000, 0x4, 0x4 }, }, { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, { 1, 0x30, 0x6000, 0, 0, 0x7FFF, 0x1000, 0x1000, 0xFF, 0x3000, 0xA, 0xA }, }, { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, { 1, 0x30, 0x6800, 0, 0, 0x7FFF, 0x1400, 0x1400, 0xFF, 0x3000, 0x6, 0x6 }, }, { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, { 2, 0x50, 0x5000, 0, 0, 0x7FFF, 0xD000, 0x3000, 0xFF, 0x3000, 0x0, 0x0 }, }, { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, { 1, 0x20, 0x0000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x0000, 0x0, 0x0 }, }, { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, { 1, 0x30, 0x1800, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x0000, 0xB, 0xB }, }, { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, }, { - { 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, + DEFAULT_REVERB_SETTINGS, { 1, 0x40, 0x5000, 0, 0, 0x7FFF, 0x0000, 0x0000, 0xFF, 0x3000, 0x0, 0x0 }, }, }; AudioSpec gAudioSpecs[18] = { - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x4000, 0x2880, 0, 0, 0 }, - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[1], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[2], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 23, 4, 0, 0, 2, D_80133420[4], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 23, 4, 0, 0, 2, D_80133420[5], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[6], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[7], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 23, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[9], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 23, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 28, 3, 0, 0, 2, D_80133420[10], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x2800, 0x2880, 0, 0, 0 }, - { 32000, 1, 28, 3, 0, 0, 1, D_80133420[11], 0x300, 0x200, 0x7FFF, 0, 0x4800, 0, 0x4000, 0, 0, 0, 0 }, - { 32000, 1, 28, 3, 0, 0, 1, D_80133420[11], 0x300, 0x200, 0x7FFF, 0, 0, 0, 0x4000, 0x4800, 0, 0, 0 }, - { 32000, 1, 22, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 22, 4, 0, 0, 2, D_80133420[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 16, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 22050, 1, 24, 4, 0, 0, 2, D_80133420[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, - { 32000, 1, 24, 4, 0, 0, 2, D_80133420[2], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3600, 0x2600, 0, 0, 0 }, + { 32000, 1, 24, 4, 0, 0, 2, sReverbSettings[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x4000, 0x2880, 0, 0, 0 }, + { 32000, 1, 24, 4, 0, 0, 2, sReverbSettings[1], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 32000, 1, 24, 4, 0, 0, 2, sReverbSettings[2], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 32000, 1, 23, 4, 0, 0, 2, sReverbSettings[4], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 32000, 1, 23, 4, 0, 0, 2, sReverbSettings[5], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 32000, 1, 24, 4, 0, 0, 2, sReverbSettings[6], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 32000, 1, 24, 4, 0, 0, 2, sReverbSettings[7], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 32000, 1, 23, 4, 0, 0, 2, sReverbSettings[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 32000, 1, 24, 4, 0, 0, 2, sReverbSettings[9], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 32000, 1, 23, 4, 0, 0, 2, sReverbSettings[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 32000, 1, 28, 3, 0, 0, 2, sReverbSettings[10], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x2800, 0x2880, 0, 0, 0 }, + { 32000, 1, 28, 3, 0, 0, 1, sReverbSettings[11], 0x300, 0x200, 0x7FFF, 0, 0x4800, 0, 0x4000, 0, 0, 0, 0 }, + { 32000, 1, 28, 3, 0, 0, 1, sReverbSettings[11], 0x300, 0x200, 0x7FFF, 0, 0, 0, 0x4000, 0x4800, 0, 0, 0 }, + { 32000, 1, 22, 4, 0, 0, 2, sReverbSettings[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 32000, 1, 22, 4, 0, 0, 2, sReverbSettings[8], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 32000, 1, 16, 4, 0, 0, 2, sReverbSettings[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 22050, 1, 24, 4, 0, 0, 2, sReverbSettings[0], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3800, 0x2880, 0, 0, 0 }, + { 32000, 1, 24, 4, 0, 0, 2, sReverbSettings[2], 0x300, 0x200, 0x7FFF, 0x7F0, 0xE00, 0, 0x3600, 0x2600, 0, 0, 0 }, }; diff --git a/src/code/audio_load.c b/src/code/audio_load.c index 8aabbd62ef..9c171cf0a9 100644 --- a/src/code/audio_load.c +++ b/src/code/audio_load.c @@ -1188,7 +1188,7 @@ void AudioLoad_Init(void* heap, u32 heapSize) { if (heap == NULL) { gAudioContext.audioHeap = gAudioHeap; - gAudioContext.audioHeapSize = D_8014A6C4.heapSize; + gAudioContext.audioHeapSize = gAudioHeapInitSizes.heapSize; } else { void** hp = &heap; gAudioContext.audioHeap = *hp; @@ -1200,11 +1200,11 @@ void AudioLoad_Init(void* heap, u32 heapSize) { } // Main Pool Split (split entirety of audio heap into initPool and sessionPool) - AudioHeap_InitMainPools(D_8014A6C4.initPoolSize); + AudioHeap_InitMainPools(gAudioHeapInitSizes.initPoolSize); // Initialize the audio interface buffers for (i = 0; i < 3; i++) { - gAudioContext.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioContext.audioInitPool, AIBUF_LEN * sizeof(s16)); + gAudioContext.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioContext.initPool, AIBUF_LEN * sizeof(s16)); } // Set audio tables pointers @@ -1225,19 +1225,19 @@ void AudioLoad_Init(void* heap, u32 heapSize) { AudioLoad_InitTable(gAudioContext.soundFontTable, _AudiobankSegmentRomStart, 0); AudioLoad_InitTable(gAudioContext.sampleBankTable, _AudiotableSegmentRomStart, 0); numFonts = gAudioContext.soundFontTable->numEntries; - gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); + gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.initPool, numFonts * sizeof(SoundFont)); for (i = 0; i < numFonts; i++) { AudioLoad_InitSoundFontMeta(i); } - ramAddr = AudioHeap_Alloc(&gAudioContext.audioInitPool, D_8014A6C4.permanentPoolSize); + ramAddr = AudioHeap_Alloc(&gAudioContext.initPool, gAudioHeapInitSizes.permanentPoolSize); if (ramAddr == NULL) { - // cast away const from D_8014A6C4 - *((u32*)&D_8014A6C4.permanentPoolSize) = 0; + // cast away const from gAudioHeapInitSizes + *((u32*)&gAudioHeapInitSizes.permanentPoolSize) = 0; } - AudioHeap_AllocPoolInit(&gAudioContext.permanentPool, ramAddr, D_8014A6C4.permanentPoolSize); + AudioHeap_AllocPoolInit(&gAudioContext.permanentPool, ramAddr, gAudioHeapInitSizes.permanentPoolSize); gAudioContextInitalized = true; osSendMesg(gAudioContext.taskStartQueueP, (OSMesg)gAudioContext.totalTaskCount, OS_MESG_NOBLOCK); } diff --git a/src/code/code_800EC960.c b/src/code/code_800EC960.c index bbd3435997..dcb1c05859 100644 --- a/src/code/code_800EC960.c +++ b/src/code/code_800EC960.c @@ -2873,7 +2873,7 @@ void AudioDebug_Draw(GfxPrint* printer) { case PAGE_HEAP_INFO: SETCOL(255, 255, 255); GfxPrint_SetPos(printer, 3, 4); - GfxPrint_Printf(printer, "TOTAL %d", D_8014A6C4.heapSize); + GfxPrint_Printf(printer, "TOTAL %d", gAudioHeapInitSizes.heapSize); GfxPrint_SetPos(printer, 3, 5); GfxPrint_Printf(printer, "DRIVER %05X / %05X",