From 66946534a14334fc1c1e16ace252de7d167b2420 Mon Sep 17 00:00:00 2001 From: engineer124 <47598039+engineer124@users.noreply.github.com> Date: Mon, 4 Jul 2022 12:19:39 -0400 Subject: [PATCH] Audio Misc Cleanup 2 (#1303) * Misc cleanup * PR Suggestions --- include/functions.h | 6 +-- src/code/audio_heap.c | 111 +++++++++++++++++++------------------- src/code/audio_load.c | 2 +- src/code/audio_playback.c | 8 +-- src/code/code_800E4FE0.c | 22 ++++---- 5 files changed, 72 insertions(+), 77 deletions(-) diff --git a/include/functions.h b/include/functions.h index 1a36124afb..c76445a46d 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1780,10 +1780,8 @@ void* AudioHeap_AllocDmaMemory(AudioAllocPool* pool, u32 size); void* AudioHeap_AllocDmaMemoryZeroed(AudioAllocPool* pool, u32 size); void* AudioHeap_AllocZeroed(AudioAllocPool* pool, u32 size); void* AudioHeap_Alloc(AudioAllocPool* pool, u32 size); -void AudioHeap_AllocPoolInit(AudioAllocPool* pool, void* ramAddr, u32 size); -void AudioHeap_PersistentCacheClear(AudioPersistentCache* persistent); -void AudioHeap_TemporaryCacheClear(AudioTemporaryCache* temporary); -void AudioHeap_PopCache(s32 tableType); +void AudioHeap_InitPool(AudioAllocPool* pool, void* ramAddr, u32 size); +void AudioHeap_PopPersistentCache(s32 tableType); void AudioHeap_InitMainPools(s32 initPoolSize); void* AudioHeap_AllocCached(s32 tableType, s32 size, s32 cache, s32 id); void* AudioHeap_SearchCaches(s32 tableType, s32 cache, s32 id); diff --git a/src/code/audio_heap.c b/src/code/audio_heap.c index 0f5abc4425..fbce1d5a96 100644 --- a/src/code/audio_heap.c +++ b/src/code/audio_heap.c @@ -91,13 +91,13 @@ void AudioHeap_ReleaseNotesForFont(s32 fontId) { for (i = 0; i < gAudioContext.numNotes; i++) { Note* note = &gAudioContext.notes[i]; - NotePlaybackState* state = ¬e->playbackState; + NotePlaybackState* playbackState = ¬e->playbackState; - if (state->fontId == fontId) { - if (state->priority != 0 && state->adsr.action.s.state == ADSR_STATE_DECAY) { - state->priority = 1; - state->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; - state->adsr.action.s.release = true; + if (playbackState->fontId == fontId) { + if ((playbackState->priority != 0) && (playbackState->adsr.action.s.state == ADSR_STATE_DECAY)) { + playbackState->priority = 1; + playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + playbackState->adsr.action.s.release = true; } } } @@ -201,19 +201,19 @@ void* AudioHeap_Alloc(AudioAllocPool* pool, u32 size) { * Initialize a pool to allocate memory from the specified address, up to the specified size. * Store the metadata of this pool in AudioAllocPool* pool */ -void AudioHeap_AllocPoolInit(AudioAllocPool* pool, void* ramAddr, u32 size) { +void AudioHeap_InitPool(AudioAllocPool* pool, void* ramAddr, u32 size) { pool->curRamAddr = pool->startRamAddr = (u8*)ALIGN16((u32)ramAddr); pool->size = size - ((u32)ramAddr & 0xF); pool->numEntries = 0; } -void AudioHeap_PersistentCacheClear(AudioPersistentCache* persistent) { +void AudioHeap_InitPersistentCache(AudioPersistentCache* persistent) { persistent->pool.numEntries = 0; persistent->numEntries = 0; persistent->pool.curRamAddr = persistent->pool.startRamAddr; } -void AudioHeap_TemporaryCacheClear(AudioTemporaryCache* temporary) { +void AudioHeap_InitTemporaryCache(AudioTemporaryCache* temporary) { temporary->pool.numEntries = 0; temporary->pool.curRamAddr = temporary->pool.startRamAddr; temporary->nextSide = 0; @@ -228,7 +228,7 @@ void AudioHeap_ResetPool(AudioAllocPool* pool) { pool->curRamAddr = pool->startRamAddr; } -void AudioHeap_PopCache(s32 tableType) { +void AudioHeap_PopPersistentCache(s32 tableType) { AudioCache* loadedCache; AudioAllocPool* persistentPool; AudioPersistentCache* persistent; @@ -275,60 +275,57 @@ void AudioHeap_PopCache(s32 tableType) { } void AudioHeap_InitMainPools(s32 initPoolSize) { - AudioHeap_AllocPoolInit(&gAudioContext.initPool, gAudioContext.audioHeap, initPoolSize); - AudioHeap_AllocPoolInit(&gAudioContext.sessionPool, gAudioContext.audioHeap + initPoolSize, - gAudioContext.audioHeapSize - initPoolSize); + AudioHeap_InitPool(&gAudioContext.initPool, gAudioContext.audioHeap, initPoolSize); + AudioHeap_InitPool(&gAudioContext.sessionPool, gAudioContext.audioHeap + initPoolSize, + gAudioContext.audioHeapSize - initPoolSize); gAudioContext.externalPool.startRamAddr = NULL; } -void AudioHeap_SessionPoolsInit(AudioSessionPoolSplit* split) { +void AudioHeap_InitSessionPools(AudioSessionPoolSplit* split) { gAudioContext.sessionPool.curRamAddr = gAudioContext.sessionPool.startRamAddr; - AudioHeap_AllocPoolInit(&gAudioContext.miscPool, AudioHeap_Alloc(&gAudioContext.sessionPool, split->miscPoolSize), - split->miscPoolSize); - AudioHeap_AllocPoolInit(&gAudioContext.cachePool, AudioHeap_Alloc(&gAudioContext.sessionPool, split->cachePoolSize), - split->cachePoolSize); + AudioHeap_InitPool(&gAudioContext.miscPool, AudioHeap_Alloc(&gAudioContext.sessionPool, split->miscPoolSize), + split->miscPoolSize); + AudioHeap_InitPool(&gAudioContext.cachePool, AudioHeap_Alloc(&gAudioContext.sessionPool, split->cachePoolSize), + split->cachePoolSize); } -void AudioHeap_CachePoolInit(AudioCachePoolSplit* split) { +void AudioHeap_InitCachePools(AudioCachePoolSplit* split) { gAudioContext.cachePool.curRamAddr = gAudioContext.cachePool.startRamAddr; - AudioHeap_AllocPoolInit(&gAudioContext.persistentCommonPool, - AudioHeap_Alloc(&gAudioContext.cachePool, split->persistentCommonPoolSize), - split->persistentCommonPoolSize); - AudioHeap_AllocPoolInit(&gAudioContext.temporaryCommonPool, - AudioHeap_Alloc(&gAudioContext.cachePool, split->temporaryCommonPoolSize), - split->temporaryCommonPoolSize); + AudioHeap_InitPool(&gAudioContext.persistentCommonPool, + AudioHeap_Alloc(&gAudioContext.cachePool, split->persistentCommonPoolSize), + split->persistentCommonPoolSize); + AudioHeap_InitPool(&gAudioContext.temporaryCommonPool, + AudioHeap_Alloc(&gAudioContext.cachePool, split->temporaryCommonPoolSize), + split->temporaryCommonPoolSize); } -void AudioHeap_PersistentCachesInit(AudioCommonPoolSplit* split) { +void AudioHeap_InitPersistentPoolsAndCaches(AudioCommonPoolSplit* split) { gAudioContext.persistentCommonPool.curRamAddr = gAudioContext.persistentCommonPool.startRamAddr; - AudioHeap_AllocPoolInit(&gAudioContext.seqCache.persistent.pool, - AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->seqCacheSize), - split->seqCacheSize); - AudioHeap_AllocPoolInit(&gAudioContext.fontCache.persistent.pool, - AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->fontCacheSize), - split->fontCacheSize); - AudioHeap_AllocPoolInit(&gAudioContext.sampleBankCache.persistent.pool, - AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->sampleBankCacheSize), - split->sampleBankCacheSize); - AudioHeap_PersistentCacheClear(&gAudioContext.seqCache.persistent); - AudioHeap_PersistentCacheClear(&gAudioContext.fontCache.persistent); - AudioHeap_PersistentCacheClear(&gAudioContext.sampleBankCache.persistent); + AudioHeap_InitPool(&gAudioContext.seqCache.persistent.pool, + AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->seqCacheSize), split->seqCacheSize); + AudioHeap_InitPool(&gAudioContext.fontCache.persistent.pool, + AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->fontCacheSize), + split->fontCacheSize); + AudioHeap_InitPool(&gAudioContext.sampleBankCache.persistent.pool, + AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->sampleBankCacheSize), + split->sampleBankCacheSize); + AudioHeap_InitPersistentCache(&gAudioContext.seqCache.persistent); + AudioHeap_InitPersistentCache(&gAudioContext.fontCache.persistent); + AudioHeap_InitPersistentCache(&gAudioContext.sampleBankCache.persistent); } -void AudioHeap_TemporaryCachesInit(AudioCommonPoolSplit* split) { +void AudioHeap_InitTemporaryPoolsAndCaches(AudioCommonPoolSplit* split) { gAudioContext.temporaryCommonPool.curRamAddr = gAudioContext.temporaryCommonPool.startRamAddr; - AudioHeap_AllocPoolInit(&gAudioContext.seqCache.temporary.pool, - AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->seqCacheSize), - split->seqCacheSize); - AudioHeap_AllocPoolInit(&gAudioContext.fontCache.temporary.pool, - AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->fontCacheSize), - split->fontCacheSize); - AudioHeap_AllocPoolInit(&gAudioContext.sampleBankCache.temporary.pool, - AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->sampleBankCacheSize), - split->sampleBankCacheSize); - AudioHeap_TemporaryCacheClear(&gAudioContext.seqCache.temporary); - AudioHeap_TemporaryCacheClear(&gAudioContext.fontCache.temporary); - AudioHeap_TemporaryCacheClear(&gAudioContext.sampleBankCache.temporary); + AudioHeap_InitPool(&gAudioContext.seqCache.temporary.pool, + AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->seqCacheSize), split->seqCacheSize); + AudioHeap_InitPool(&gAudioContext.fontCache.temporary.pool, + AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->fontCacheSize), split->fontCacheSize); + AudioHeap_InitPool(&gAudioContext.sampleBankCache.temporary.pool, + AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->sampleBankCacheSize), + split->sampleBankCacheSize); + AudioHeap_InitTemporaryCache(&gAudioContext.seqCache.temporary); + AudioHeap_InitTemporaryCache(&gAudioContext.fontCache.temporary); + AudioHeap_InitTemporaryCache(&gAudioContext.sampleBankCache.temporary); } void* AudioHeap_AllocCached(s32 tableType, s32 size, s32 cache, s32 id) { @@ -933,24 +930,24 @@ void AudioHeap_Init(void) { // Session Pool Split (split into Cache and Misc pools) gAudioContext.sessionPoolSplit.miscPoolSize = miscPoolSize; gAudioContext.sessionPoolSplit.cachePoolSize = cachePoolSize; - AudioHeap_SessionPoolsInit(&gAudioContext.sessionPoolSplit); + AudioHeap_InitSessionPools(&gAudioContext.sessionPoolSplit); // Cache Pool Split (split into Persistent and Temporary pools) gAudioContext.cachePoolSplit.persistentCommonPoolSize = persistentSize; gAudioContext.cachePoolSplit.temporaryCommonPoolSize = temporarySize; - AudioHeap_CachePoolInit(&gAudioContext.cachePoolSplit); + AudioHeap_InitCachePools(&gAudioContext.cachePoolSplit); // Persistent Pool Split (split into Sequences, SoundFonts, Samples pools) gAudioContext.persistentCommonPoolSplit.seqCacheSize = spec->persistentSeqCacheSize; gAudioContext.persistentCommonPoolSplit.fontCacheSize = spec->persistentFontCacheSize; gAudioContext.persistentCommonPoolSplit.sampleBankCacheSize = spec->persistentSampleBankCacheSize; - AudioHeap_PersistentCachesInit(&gAudioContext.persistentCommonPoolSplit); + AudioHeap_InitPersistentPoolsAndCaches(&gAudioContext.persistentCommonPoolSplit); // Temporary Pool Split (split into Sequences, SoundFonts, Samples pools) gAudioContext.temporaryCommonPoolSplit.seqCacheSize = spec->temporarySeqCacheSize; gAudioContext.temporaryCommonPoolSplit.fontCacheSize = spec->temporaryFontCacheSize; gAudioContext.temporaryCommonPoolSplit.sampleBankCacheSize = spec->temporarySampleBankCacheSize; - AudioHeap_TemporaryCachesInit(&gAudioContext.temporaryCommonPoolSplit); + AudioHeap_InitTemporaryPoolsAndCaches(&gAudioContext.temporaryCommonPoolSplit); AudioHeap_ResetLoadStatus(); @@ -1133,13 +1130,13 @@ void AudioHeap_InitSampleCaches(u32 persistentSampleCacheSize, u32 temporarySamp if (ramAddr == NULL) { gAudioContext.persistentSampleCache.pool.size = 0; } else { - AudioHeap_AllocPoolInit(&gAudioContext.persistentSampleCache.pool, ramAddr, persistentSampleCacheSize); + AudioHeap_InitPool(&gAudioContext.persistentSampleCache.pool, ramAddr, persistentSampleCacheSize); } ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.miscPool, temporarySampleCacheSize); if (ramAddr == NULL) { gAudioContext.temporarySampleCache.pool.size = 0; } else { - AudioHeap_AllocPoolInit(&gAudioContext.temporarySampleCache.pool, ramAddr, temporarySampleCacheSize); + AudioHeap_InitPool(&gAudioContext.temporarySampleCache.pool, ramAddr, temporarySampleCacheSize); } gAudioContext.persistentSampleCache.numEntries = 0; gAudioContext.temporarySampleCache.numEntries = 0; diff --git a/src/code/audio_load.c b/src/code/audio_load.c index c1ef5b947e..8c77f3beb2 100644 --- a/src/code/audio_load.c +++ b/src/code/audio_load.c @@ -1234,7 +1234,7 @@ void AudioLoad_Init(void* heap, u32 heapSize) { *((u32*)&gAudioHeapInitSizes.permanentPoolSize) = 0; } - AudioHeap_AllocPoolInit(&gAudioContext.permanentPool, ramAddr, gAudioHeapInitSizes.permanentPoolSize); + AudioHeap_InitPool(&gAudioContext.permanentPool, ramAddr, gAudioHeapInitSizes.permanentPoolSize); gAudioContextInitalized = true; osSendMesg(gAudioContext.taskStartQueueP, (OSMesg)gAudioContext.totalTaskCount, OS_MESG_NOBLOCK); } diff --git a/src/code/audio_playback.c b/src/code/audio_playback.c index 0d596dacad..571a3a0c45 100644 --- a/src/code/audio_playback.c +++ b/src/code/audio_playback.c @@ -759,12 +759,12 @@ Note* Audio_FindNodeWithPrioLessThan(AudioListItem* list, s32 limit) { void Audio_NoteInitForLayer(Note* note, SequenceLayer* layer) { s32 pad[3]; s16 instId; - NotePlaybackState* playback = ¬e->playbackState; + NotePlaybackState* playbackState = ¬e->playbackState; NoteSubEu* sub = ¬e->noteSubEu; note->playbackState.prevParentLayer = NO_LAYER; note->playbackState.parentLayer = layer; - playback->priority = layer->channel->notePriority; + playbackState->priority = layer->channel->notePriority; layer->notePropertiesNeedInit = true; layer->bit3 = true; layer->note = note; @@ -789,8 +789,8 @@ void Audio_NoteInitForLayer(Note* note, SequenceLayer* layer) { Audio_BuildSyntheticWave(note, layer, instId); } - playback->fontId = layer->channel->fontId; - playback->stereoHeadsetEffects = layer->channel->stereoHeadsetEffects; + playbackState->fontId = layer->channel->fontId; + playbackState->stereoHeadsetEffects = layer->channel->stereoHeadsetEffects; sub->bitField1.reverbIndex = layer->channel->reverbIndex & 3; } diff --git a/src/code/code_800E4FE0.c b/src/code/code_800E4FE0.c index 28b2e9aea1..c1a75de4af 100644 --- a/src/code/code_800E4FE0.c +++ b/src/code/code_800E4FE0.c @@ -333,7 +333,7 @@ void func_800E5584(AudioCmd* cmd) { break; case 0xE3: - AudioHeap_PopCache(cmd->asInt); + AudioHeap_PopPersistentCache(cmd->asInt); break; default: @@ -596,7 +596,7 @@ s8 func_800E60C4(s32 playerIdx, s32 port) { } void Audio_InitExternalPool(void* ramAddr, u32 size) { - AudioHeap_AllocPoolInit(&gAudioContext.externalPool, ramAddr, size); + AudioHeap_InitPool(&gAudioContext.externalPool, ramAddr, size); } void Audio_DestroyExternalPool(void) { @@ -834,8 +834,8 @@ void func_800E66A0(void) { s32 func_800E66C0(s32 arg0) { s32 phi_v1; - NotePlaybackState* temp_a2; - NoteSubEu* temp_a3; + NotePlaybackState* playbackState; + NoteSubEu* noteSubEu; s32 i; Note* note; TunedSample* tunedSample; @@ -843,13 +843,13 @@ s32 func_800E66C0(s32 arg0) { phi_v1 = 0; for (i = 0; i < gAudioContext.numNotes; i++) { note = &gAudioContext.notes[i]; - temp_a2 = ¬e->playbackState; + playbackState = ¬e->playbackState; if (note->noteSubEu.bitField0.enabled) { - temp_a3 = ¬e->noteSubEu; - if (temp_a2->adsr.action.s.state != 0) { + noteSubEu = ¬e->noteSubEu; + if (playbackState->adsr.action.s.state != 0) { if (arg0 >= 2) { - tunedSample = temp_a3->tunedSample; - if (tunedSample == NULL || temp_a3->bitField1.isSyntheticWave) { + tunedSample = noteSubEu->tunedSample; + if (tunedSample == NULL || noteSubEu->bitField1.isSyntheticWave) { continue; } if (tunedSample->sample->medium == MEDIUM_RAM) { @@ -859,8 +859,8 @@ s32 func_800E66C0(s32 arg0) { phi_v1++; if ((arg0 & 1) == 1) { - temp_a2->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; - temp_a2->adsr.action.s.release = 1; + playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + playbackState->adsr.action.s.release = 1; } } }