diff --git a/include/variables.h b/include/variables.h index fd6c58c1c3..f04847e12c 100644 --- a/include/variables.h +++ b/include/variables.h @@ -218,7 +218,7 @@ extern u16 gAudioSfxSwapSource[10]; extern u16 gAudioSfxSwapTarget[10]; extern u8 gAudioSfxSwapMode[10]; extern ActiveSequence gActiveSeqs[4]; -extern AudioContext gAudioContext; +extern AudioContext gAudioCtx; extern void(*D_801755D0)(void); extern u32 __osMalloc_FreeBlockTest_Enable; diff --git a/include/z64audio.h b/include/z64audio.h index 759ec1ab79..bd06b0e835 100644 --- a/include/z64audio.h +++ b/include/z64audio.h @@ -7,7 +7,7 @@ #define TATUMS_PER_BEAT 48 -#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((u32)(ptr) != (u32)&gAudioContext.sequenceChannelNone) +#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((u32)(ptr) != (u32)&gAudioCtx.sequenceChannelNone) #define SEQ_NUM_CHANNELS 16 #define MAX_CHANNELS_PER_BANK 3 diff --git a/src/code/audio_effects.c b/src/code/audio_effects.c index 75a0937cea..6844d8ae57 100644 --- a/src/code/audio_effects.c +++ b/src/code/audio_effects.c @@ -124,7 +124,7 @@ f32 Audio_GetVibratoFreqScale(VibratoState* vib) { return 1.0f; } - //! @bug this probably meant to compare with gAudioContext.sequenceChannelNone. + //! @bug this probably meant to compare with gAudioCtx.sequenceChannelNone. //! -1 isn't used as a channel pointer anywhere else. if (channel != ((SequenceChannel*)(-1))) { if (vib->extentChangeTimer) { @@ -264,7 +264,7 @@ f32 Audio_AdsrUpdate(AdsrState* adsr) { break; default: - adsr->delay *= gAudioContext.audioBufferParameters.updatesPerFrameScaled; + adsr->delay *= gAudioCtx.audioBufferParameters.updatesPerFrameScaled; if (adsr->delay == 0) { adsr->delay = 1; } diff --git a/src/code/audio_heap.c b/src/code/audio_heap.c index 504b56244e..fd61dc9846 100644 --- a/src/code/audio_heap.c +++ b/src/code/audio_heap.c @@ -16,7 +16,7 @@ void AudioHeap_DiscardSampleBanks(void); * i.e. (256.0f * `updatesPerFrameInvScaled`) is just `updatesPerFrameInv` */ f32 AudioHeap_CalculateAdsrDecay(f32 scaleInv) { - return (256.0f * gAudioContext.audioBufferParameters.updatesPerFrameInvScaled) / scaleInv; + return (256.0f * gAudioCtx.audioBufferParameters.updatesPerFrameInvScaled) / scaleInv; } /** @@ -25,45 +25,45 @@ f32 AudioHeap_CalculateAdsrDecay(f32 scaleInv) { void AudioHeap_InitAdsrDecayTable(void) { s32 i; - gAudioContext.adsrDecayTable[255] = AudioHeap_CalculateAdsrDecay(0.25f); - gAudioContext.adsrDecayTable[254] = AudioHeap_CalculateAdsrDecay(0.33f); - gAudioContext.adsrDecayTable[253] = AudioHeap_CalculateAdsrDecay(0.5f); - gAudioContext.adsrDecayTable[252] = AudioHeap_CalculateAdsrDecay(0.66f); - gAudioContext.adsrDecayTable[251] = AudioHeap_CalculateAdsrDecay(0.75f); + gAudioCtx.adsrDecayTable[255] = AudioHeap_CalculateAdsrDecay(0.25f); + gAudioCtx.adsrDecayTable[254] = AudioHeap_CalculateAdsrDecay(0.33f); + gAudioCtx.adsrDecayTable[253] = AudioHeap_CalculateAdsrDecay(0.5f); + gAudioCtx.adsrDecayTable[252] = AudioHeap_CalculateAdsrDecay(0.66f); + gAudioCtx.adsrDecayTable[251] = AudioHeap_CalculateAdsrDecay(0.75f); for (i = 128; i < 251; i++) { - gAudioContext.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(251 - i); + gAudioCtx.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(251 - i); } for (i = 16; i < 128; i++) { - gAudioContext.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(4 * (143 - i)); + gAudioCtx.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(4 * (143 - i)); } for (i = 1; i < 16; i++) { - gAudioContext.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(60 * (23 - i)); + gAudioCtx.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(60 * (23 - i)); } - gAudioContext.adsrDecayTable[0] = 0.0f; + gAudioCtx.adsrDecayTable[0] = 0.0f; } void AudioHeap_ResetLoadStatus(void) { s32 i; for (i = 0; i < 0x30; i++) { - if (gAudioContext.fontLoadStatus[i] != LOAD_STATUS_PERMANENTLY_LOADED) { - gAudioContext.fontLoadStatus[i] = LOAD_STATUS_NOT_LOADED; + if (gAudioCtx.fontLoadStatus[i] != LOAD_STATUS_PERMANENTLY_LOADED) { + gAudioCtx.fontLoadStatus[i] = LOAD_STATUS_NOT_LOADED; } } for (i = 0; i < 0x30; i++) { - if (gAudioContext.sampleFontLoadStatus[i] != LOAD_STATUS_PERMANENTLY_LOADED) { - gAudioContext.sampleFontLoadStatus[i] = LOAD_STATUS_NOT_LOADED; + if (gAudioCtx.sampleFontLoadStatus[i] != LOAD_STATUS_PERMANENTLY_LOADED) { + gAudioCtx.sampleFontLoadStatus[i] = LOAD_STATUS_NOT_LOADED; } } for (i = 0; i < 0x80; i++) { - if (gAudioContext.seqLoadStatus[i] != LOAD_STATUS_PERMANENTLY_LOADED) { - gAudioContext.seqLoadStatus[i] = LOAD_STATUS_NOT_LOADED; + if (gAudioCtx.seqLoadStatus[i] != LOAD_STATUS_PERMANENTLY_LOADED) { + gAudioCtx.seqLoadStatus[i] = LOAD_STATUS_NOT_LOADED; } } } @@ -71,8 +71,8 @@ void AudioHeap_ResetLoadStatus(void) { void AudioHeap_DiscardFont(s32 fontId) { s32 i; - for (i = 0; i < gAudioContext.numNotes; i++) { - Note* note = &gAudioContext.notes[i]; + for (i = 0; i < gAudioCtx.numNotes; i++) { + Note* note = &gAudioCtx.notes[i]; if (note->playbackState.fontId == fontId) { if (note->playbackState.unk_04 == 0 && note->playbackState.priority != 0) { @@ -81,7 +81,7 @@ void AudioHeap_DiscardFont(s32 fontId) { } Audio_NoteDisable(note); Audio_AudioListRemove(¬e->listItem); - AudioSeq_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, ¬e->listItem); + AudioSeq_AudioListPushBack(&gAudioCtx.noteFreeLists.disabled, ¬e->listItem); } } } @@ -89,14 +89,14 @@ void AudioHeap_DiscardFont(s32 fontId) { void AudioHeap_ReleaseNotesForFont(s32 fontId) { s32 i; - for (i = 0; i < gAudioContext.numNotes; i++) { - Note* note = &gAudioContext.notes[i]; + for (i = 0; i < gAudioCtx.numNotes; i++) { + Note* note = &gAudioCtx.notes[i]; NotePlaybackState* playbackState = ¬e->playbackState; 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.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv; playbackState->adsr.action.s.release = true; } } @@ -106,9 +106,9 @@ void AudioHeap_ReleaseNotesForFont(s32 fontId) { void AudioHeap_DiscardSequence(s32 seqId) { s32 i; - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - if (gAudioContext.seqPlayers[i].enabled && gAudioContext.seqPlayers[i].seqId == seqId) { - AudioSeq_SequencePlayerDisable(&gAudioContext.seqPlayers[i]); + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + if (gAudioCtx.seqPlayers[i].enabled && gAudioCtx.seqPlayers[i].seqId == seqId) { + AudioSeq_SequencePlayerDisable(&gAudioCtx.seqPlayers[i]); } } } @@ -128,8 +128,8 @@ void AudioHeap_WritebackDCache(void* ramAddr, u32 size) { void* AudioHeap_AllocZeroedAttemptExternal(AudioAllocPool* pool, u32 size) { void* ramAddr = NULL; - if (gAudioContext.externalPool.startRamAddr != NULL) { - ramAddr = AudioHeap_AllocZeroed(&gAudioContext.externalPool, size); + if (gAudioCtx.externalPool.startRamAddr != NULL) { + ramAddr = AudioHeap_AllocZeroed(&gAudioCtx.externalPool, size); } if (ramAddr == NULL) { ramAddr = AudioHeap_AllocZeroed(pool, size); @@ -140,8 +140,8 @@ void* AudioHeap_AllocZeroedAttemptExternal(AudioAllocPool* pool, u32 size) { void* AudioHeap_AllocAttemptExternal(AudioAllocPool* pool, u32 size) { void* ramAddr = NULL; - if (gAudioContext.externalPool.startRamAddr != NULL) { - ramAddr = AudioHeap_Alloc(&gAudioContext.externalPool, size); + if (gAudioCtx.externalPool.startRamAddr != NULL) { + ramAddr = AudioHeap_Alloc(&gAudioCtx.externalPool, size); } if (ramAddr == NULL) { ramAddr = AudioHeap_Alloc(pool, size); @@ -237,18 +237,18 @@ void AudioHeap_PopPersistentCache(s32 tableType) { switch (tableType) { case SEQUENCE_TABLE: - loadedCache = &gAudioContext.seqCache; - loadStatus = gAudioContext.seqLoadStatus; + loadedCache = &gAudioCtx.seqCache; + loadStatus = gAudioCtx.seqLoadStatus; break; case FONT_TABLE: - loadedCache = &gAudioContext.fontCache; - loadStatus = gAudioContext.fontLoadStatus; + loadedCache = &gAudioCtx.fontCache; + loadStatus = gAudioCtx.fontLoadStatus; break; case SAMPLE_TABLE: - loadedCache = &gAudioContext.sampleBankCache; - loadStatus = gAudioContext.sampleFontLoadStatus; + loadedCache = &gAudioCtx.sampleBankCache; + loadStatus = gAudioCtx.sampleFontLoadStatus; break; } @@ -275,57 +275,56 @@ void AudioHeap_PopPersistentCache(s32 tableType) { } void AudioHeap_InitMainPools(s32 initPoolSize) { - AudioHeap_InitPool(&gAudioContext.initPool, gAudioContext.audioHeap, initPoolSize); - AudioHeap_InitPool(&gAudioContext.sessionPool, gAudioContext.audioHeap + initPoolSize, - gAudioContext.audioHeapSize - initPoolSize); - gAudioContext.externalPool.startRamAddr = NULL; + AudioHeap_InitPool(&gAudioCtx.initPool, gAudioCtx.audioHeap, initPoolSize); + AudioHeap_InitPool(&gAudioCtx.sessionPool, gAudioCtx.audioHeap + initPoolSize, + gAudioCtx.audioHeapSize - initPoolSize); + gAudioCtx.externalPool.startRamAddr = NULL; } void AudioHeap_InitSessionPools(AudioSessionPoolSplit* split) { - gAudioContext.sessionPool.curRamAddr = gAudioContext.sessionPool.startRamAddr; - AudioHeap_InitPool(&gAudioContext.miscPool, AudioHeap_Alloc(&gAudioContext.sessionPool, split->miscPoolSize), + gAudioCtx.sessionPool.curRamAddr = gAudioCtx.sessionPool.startRamAddr; + AudioHeap_InitPool(&gAudioCtx.miscPool, AudioHeap_Alloc(&gAudioCtx.sessionPool, split->miscPoolSize), split->miscPoolSize); - AudioHeap_InitPool(&gAudioContext.cachePool, AudioHeap_Alloc(&gAudioContext.sessionPool, split->cachePoolSize), + AudioHeap_InitPool(&gAudioCtx.cachePool, AudioHeap_Alloc(&gAudioCtx.sessionPool, split->cachePoolSize), split->cachePoolSize); } void AudioHeap_InitCachePools(AudioCachePoolSplit* split) { - gAudioContext.cachePool.curRamAddr = gAudioContext.cachePool.startRamAddr; - AudioHeap_InitPool(&gAudioContext.persistentCommonPool, - AudioHeap_Alloc(&gAudioContext.cachePool, split->persistentCommonPoolSize), + gAudioCtx.cachePool.curRamAddr = gAudioCtx.cachePool.startRamAddr; + AudioHeap_InitPool(&gAudioCtx.persistentCommonPool, + AudioHeap_Alloc(&gAudioCtx.cachePool, split->persistentCommonPoolSize), split->persistentCommonPoolSize); - AudioHeap_InitPool(&gAudioContext.temporaryCommonPool, - AudioHeap_Alloc(&gAudioContext.cachePool, split->temporaryCommonPoolSize), + AudioHeap_InitPool(&gAudioCtx.temporaryCommonPool, + AudioHeap_Alloc(&gAudioCtx.cachePool, split->temporaryCommonPoolSize), split->temporaryCommonPoolSize); } void AudioHeap_InitPersistentPoolsAndCaches(AudioCommonPoolSplit* split) { - gAudioContext.persistentCommonPool.curRamAddr = gAudioContext.persistentCommonPool.startRamAddr; - 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), + gAudioCtx.persistentCommonPool.curRamAddr = gAudioCtx.persistentCommonPool.startRamAddr; + AudioHeap_InitPool(&gAudioCtx.seqCache.persistent.pool, + AudioHeap_Alloc(&gAudioCtx.persistentCommonPool, split->seqCacheSize), split->seqCacheSize); + AudioHeap_InitPool(&gAudioCtx.fontCache.persistent.pool, + AudioHeap_Alloc(&gAudioCtx.persistentCommonPool, split->fontCacheSize), split->fontCacheSize); + AudioHeap_InitPool(&gAudioCtx.sampleBankCache.persistent.pool, + AudioHeap_Alloc(&gAudioCtx.persistentCommonPool, split->sampleBankCacheSize), split->sampleBankCacheSize); - AudioHeap_InitPersistentCache(&gAudioContext.seqCache.persistent); - AudioHeap_InitPersistentCache(&gAudioContext.fontCache.persistent); - AudioHeap_InitPersistentCache(&gAudioContext.sampleBankCache.persistent); + AudioHeap_InitPersistentCache(&gAudioCtx.seqCache.persistent); + AudioHeap_InitPersistentCache(&gAudioCtx.fontCache.persistent); + AudioHeap_InitPersistentCache(&gAudioCtx.sampleBankCache.persistent); } void AudioHeap_InitTemporaryPoolsAndCaches(AudioCommonPoolSplit* split) { - gAudioContext.temporaryCommonPool.curRamAddr = gAudioContext.temporaryCommonPool.startRamAddr; - 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), + gAudioCtx.temporaryCommonPool.curRamAddr = gAudioCtx.temporaryCommonPool.startRamAddr; + AudioHeap_InitPool(&gAudioCtx.seqCache.temporary.pool, + AudioHeap_Alloc(&gAudioCtx.temporaryCommonPool, split->seqCacheSize), split->seqCacheSize); + AudioHeap_InitPool(&gAudioCtx.fontCache.temporary.pool, + AudioHeap_Alloc(&gAudioCtx.temporaryCommonPool, split->fontCacheSize), split->fontCacheSize); + AudioHeap_InitPool(&gAudioCtx.sampleBankCache.temporary.pool, + AudioHeap_Alloc(&gAudioCtx.temporaryCommonPool, split->sampleBankCacheSize), split->sampleBankCacheSize); - AudioHeap_InitTemporaryCache(&gAudioContext.seqCache.temporary); - AudioHeap_InitTemporaryCache(&gAudioContext.fontCache.temporary); - AudioHeap_InitTemporaryCache(&gAudioContext.sampleBankCache.temporary); + AudioHeap_InitTemporaryCache(&gAudioCtx.seqCache.temporary); + AudioHeap_InitTemporaryCache(&gAudioCtx.fontCache.temporary); + AudioHeap_InitTemporaryCache(&gAudioCtx.sampleBankCache.temporary); } void* AudioHeap_AllocCached(s32 tableType, s32 size, s32 cache, s32 id) { @@ -342,18 +341,18 @@ void* AudioHeap_AllocCached(s32 tableType, s32 size, s32 cache, s32 id) { switch (tableType) { case SEQUENCE_TABLE: - loadedCache = &gAudioContext.seqCache; - loadStatus = gAudioContext.seqLoadStatus; + loadedCache = &gAudioCtx.seqCache; + loadStatus = gAudioCtx.seqLoadStatus; break; case FONT_TABLE: - loadedCache = &gAudioContext.fontCache; - loadStatus = gAudioContext.fontLoadStatus; + loadedCache = &gAudioCtx.fontCache; + loadStatus = gAudioCtx.fontLoadStatus; break; case SAMPLE_TABLE: - loadedCache = &gAudioContext.sampleBankCache; - loadStatus = gAudioContext.sampleFontLoadStatus; + loadedCache = &gAudioCtx.sampleBankCache; + loadStatus = gAudioCtx.sampleFontLoadStatus; break; } @@ -372,28 +371,28 @@ void* AudioHeap_AllocCached(s32 tableType, s32 size, s32 cache, s32 id) { if (tableType == FONT_TABLE) { if (loadStatusEntry0 == LOAD_STATUS_MAYBE_DISCARDABLE) { - for (i = 0; i < gAudioContext.numNotes; i++) { - if (gAudioContext.notes[i].playbackState.fontId == temporaryCache->entries[0].id && - gAudioContext.notes[i].noteSubEu.bitField0.enabled) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + if (gAudioCtx.notes[i].playbackState.fontId == temporaryCache->entries[0].id && + gAudioCtx.notes[i].noteSubEu.bitField0.enabled) { break; } } - if (i == gAudioContext.numNotes) { + if (i == gAudioCtx.numNotes) { AudioLoad_SetFontLoadStatus(temporaryCache->entries[0].id, LOAD_STATUS_DISCARDABLE); loadStatusEntry0 = LOAD_STATUS_DISCARDABLE; } } if (loadStatusEntry1 == LOAD_STATUS_MAYBE_DISCARDABLE) { - for (i = 0; i < gAudioContext.numNotes; i++) { - if (gAudioContext.notes[i].playbackState.fontId == temporaryCache->entries[1].id && - gAudioContext.notes[i].noteSubEu.bitField0.enabled) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + if (gAudioCtx.notes[i].playbackState.fontId == temporaryCache->entries[1].id && + gAudioCtx.notes[i].noteSubEu.bitField0.enabled) { break; } } - if (i == gAudioContext.numNotes) { + if (i == gAudioCtx.numNotes) { AudioLoad_SetFontLoadStatus(temporaryCache->entries[1].id, LOAD_STATUS_DISCARDABLE); loadStatusEntry1 = LOAD_STATUS_DISCARDABLE; } @@ -414,54 +413,54 @@ void* AudioHeap_AllocCached(s32 tableType, s32 size, s32 cache, s32 id) { // Check if there is a side which isn't in active use, if so, evict that one. if (tableType == SEQUENCE_TABLE) { if (loadStatusEntry0 == LOAD_STATUS_COMPLETE) { - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - if (gAudioContext.seqPlayers[i].enabled && - gAudioContext.seqPlayers[i].seqId == temporaryCache->entries[0].id) { + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + if (gAudioCtx.seqPlayers[i].enabled && + gAudioCtx.seqPlayers[i].seqId == temporaryCache->entries[0].id) { break; } } - if (i == gAudioContext.audioBufferParameters.numSequencePlayers) { + if (i == gAudioCtx.audioBufferParameters.numSequencePlayers) { temporaryCache->nextSide = 0; goto done; } } if (loadStatusEntry1 == LOAD_STATUS_COMPLETE) { - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - if (gAudioContext.seqPlayers[i].enabled && - gAudioContext.seqPlayers[i].seqId == temporaryCache->entries[1].id) { + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + if (gAudioCtx.seqPlayers[i].enabled && + gAudioCtx.seqPlayers[i].seqId == temporaryCache->entries[1].id) { break; } } - if (i == gAudioContext.audioBufferParameters.numSequencePlayers) { + if (i == gAudioCtx.audioBufferParameters.numSequencePlayers) { temporaryCache->nextSide = 1; goto done; } } } else if (tableType == FONT_TABLE) { if (loadStatusEntry0 == LOAD_STATUS_COMPLETE) { - for (i = 0; i < gAudioContext.numNotes; i++) { - if (gAudioContext.notes[i].playbackState.fontId == temporaryCache->entries[0].id && - gAudioContext.notes[i].noteSubEu.bitField0.enabled) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + if (gAudioCtx.notes[i].playbackState.fontId == temporaryCache->entries[0].id && + gAudioCtx.notes[i].noteSubEu.bitField0.enabled) { break; } } - if (i == gAudioContext.numNotes) { + if (i == gAudioCtx.numNotes) { temporaryCache->nextSide = 0; goto done; } } if (loadStatusEntry1 == LOAD_STATUS_COMPLETE) { - for (i = 0; i < gAudioContext.numNotes; i++) { - if (gAudioContext.notes[i].playbackState.fontId == temporaryCache->entries[1].id && - gAudioContext.notes[i].noteSubEu.bitField0.enabled) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + if (gAudioCtx.notes[i].playbackState.fontId == temporaryCache->entries[1].id && + gAudioCtx.notes[i].noteSubEu.bitField0.enabled) { break; } } - if (i == gAudioContext.numNotes) { + if (i == gAudioCtx.numNotes) { temporaryCache->nextSide = 1; goto done; } @@ -618,15 +617,15 @@ void* AudioHeap_SearchRegularCaches(s32 tableType, s32 cache, s32 id) { switch (tableType) { case SEQUENCE_TABLE: - loadedCache = &gAudioContext.seqCache; + loadedCache = &gAudioCtx.seqCache; break; case FONT_TABLE: - loadedCache = &gAudioContext.fontCache; + loadedCache = &gAudioCtx.fontCache; break; case SAMPLE_TABLE: - loadedCache = &gAudioContext.sampleBankCache; + loadedCache = &gAudioCtx.sampleBankCache; break; } @@ -738,15 +737,15 @@ void AudioHeap_UpdateReverbs(void) { s32 i; s32 j; - if (gAudioContext.audioBufferParameters.specUnk4 == 2) { + if (gAudioCtx.audioBufferParameters.specUnk4 == 2) { count = 2; } else { count = 1; } - for (i = 0; i < gAudioContext.numSynthesisReverbs; i++) { + for (i = 0; i < gAudioCtx.numSynthesisReverbs; i++) { for (j = 0; j < count; j++) { - AudioHeap_UpdateReverb(&gAudioContext.synthesisReverbs[i]); + AudioHeap_UpdateReverb(&gAudioCtx.synthesisReverbs[i]); } } } @@ -755,13 +754,13 @@ void AudioHeap_UpdateReverbs(void) { * Clear the current Audio Interface Buffer */ void AudioHeap_ClearCurrentAiBuffer(void) { - s32 curAiBufferIndex = gAudioContext.curAiBufIndex; + s32 curAiBufferIndex = gAudioCtx.curAiBufIndex; s32 i; - gAudioContext.aiBufLengths[curAiBufferIndex] = gAudioContext.audioBufferParameters.minAiBufferLength; + gAudioCtx.aiBufLengths[curAiBufferIndex] = gAudioCtx.audioBufferParameters.minAiBufferLength; for (i = 0; i < AIBUF_LEN; i++) { - gAudioContext.aiBuffers[curAiBufferIndex][i] = 0; + gAudioCtx.aiBuffers[curAiBufferIndex][i] = 0; } } @@ -770,55 +769,55 @@ s32 AudioHeap_ResetStep(void) { s32 j; s32 sp24; - if (gAudioContext.audioBufferParameters.specUnk4 == 2) { + if (gAudioCtx.audioBufferParameters.specUnk4 == 2) { sp24 = 2; } else { sp24 = 1; } - switch (gAudioContext.resetStatus) { + switch (gAudioCtx.resetStatus) { case 5: - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - AudioSeq_SequencePlayerDisableAsFinished(&gAudioContext.seqPlayers[i]); + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + AudioSeq_SequencePlayerDisableAsFinished(&gAudioCtx.seqPlayers[i]); } - gAudioContext.audioResetFadeOutFramesLeft = 2 / sp24; - gAudioContext.resetStatus--; + gAudioCtx.audioResetFadeOutFramesLeft = 2 / sp24; + gAudioCtx.resetStatus--; break; case 4: - if (gAudioContext.audioResetFadeOutFramesLeft != 0) { - gAudioContext.audioResetFadeOutFramesLeft--; + if (gAudioCtx.audioResetFadeOutFramesLeft != 0) { + gAudioCtx.audioResetFadeOutFramesLeft--; AudioHeap_UpdateReverbs(); } else { - for (i = 0; i < gAudioContext.numNotes; i++) { - if (gAudioContext.notes[i].noteSubEu.bitField0.enabled && - gAudioContext.notes[i].playbackState.adsr.action.s.state != ADSR_STATE_DISABLED) { - gAudioContext.notes[i].playbackState.adsr.fadeOutVel = - gAudioContext.audioBufferParameters.updatesPerFrameInv; - gAudioContext.notes[i].playbackState.adsr.action.s.release = true; + for (i = 0; i < gAudioCtx.numNotes; i++) { + if (gAudioCtx.notes[i].noteSubEu.bitField0.enabled && + gAudioCtx.notes[i].playbackState.adsr.action.s.state != ADSR_STATE_DISABLED) { + gAudioCtx.notes[i].playbackState.adsr.fadeOutVel = + gAudioCtx.audioBufferParameters.updatesPerFrameInv; + gAudioCtx.notes[i].playbackState.adsr.action.s.release = true; } } - gAudioContext.audioResetFadeOutFramesLeft = 8 / sp24; - gAudioContext.resetStatus--; + gAudioCtx.audioResetFadeOutFramesLeft = 8 / sp24; + gAudioCtx.resetStatus--; } break; case 3: - if (gAudioContext.audioResetFadeOutFramesLeft != 0) { - gAudioContext.audioResetFadeOutFramesLeft--; + if (gAudioCtx.audioResetFadeOutFramesLeft != 0) { + gAudioCtx.audioResetFadeOutFramesLeft--; AudioHeap_UpdateReverbs(); } else { - gAudioContext.audioResetFadeOutFramesLeft = 2 / sp24; - gAudioContext.resetStatus--; + gAudioCtx.audioResetFadeOutFramesLeft = 2 / sp24; + gAudioCtx.resetStatus--; } break; case 2: AudioHeap_ClearCurrentAiBuffer(); - if (gAudioContext.audioResetFadeOutFramesLeft != 0) { - gAudioContext.audioResetFadeOutFramesLeft--; + if (gAudioCtx.audioResetFadeOutFramesLeft != 0) { + gAudioCtx.audioResetFadeOutFramesLeft--; } else { - gAudioContext.resetStatus--; + gAudioCtx.resetStatus--; AudioHeap_DiscardSampleCaches(); AudioHeap_DiscardSampleBanks(); } @@ -826,17 +825,17 @@ s32 AudioHeap_ResetStep(void) { case 1: AudioHeap_Init(); - gAudioContext.resetStatus = 0; + gAudioCtx.resetStatus = 0; for (i = 0; i < 3; i++) { - gAudioContext.aiBufLengths[i] = gAudioContext.audioBufferParameters.maxAiBufferLength; + gAudioCtx.aiBufLengths[i] = gAudioCtx.audioBufferParameters.maxAiBufferLength; for (j = 0; j < AIBUF_LEN; j++) { - gAudioContext.aiBuffers[i][j] = 0; + gAudioCtx.aiBuffers[i][j] = 0; } } break; } - if (gAudioContext.resetStatus < 3) { + if (gAudioCtx.resetStatus < 3) { return false; } @@ -854,66 +853,61 @@ void AudioHeap_Init(void) { s32 i; s32 j; s32 pad2; - AudioSpec* spec = &gAudioSpecs[gAudioContext.audioResetSpecIdToLoad]; // Audio Specifications + AudioSpec* spec = &gAudioSpecs[gAudioCtx.audioResetSpecIdToLoad]; // Audio Specifications - gAudioContext.sampleDmaCount = 0; + gAudioCtx.sampleDmaCount = 0; // audio buffer parameters - gAudioContext.audioBufferParameters.samplingFrequency = spec->samplingFrequency; - gAudioContext.audioBufferParameters.aiSamplingFrequency = - osAiSetFrequency(gAudioContext.audioBufferParameters.samplingFrequency); - gAudioContext.audioBufferParameters.samplesPerFrameTarget = - ALIGN16(gAudioContext.audioBufferParameters.samplingFrequency / gAudioContext.refreshRate); - gAudioContext.audioBufferParameters.minAiBufferLength = - gAudioContext.audioBufferParameters.samplesPerFrameTarget - 0x10; - gAudioContext.audioBufferParameters.maxAiBufferLength = - gAudioContext.audioBufferParameters.samplesPerFrameTarget + 0x10; - gAudioContext.audioBufferParameters.updatesPerFrame = - ((gAudioContext.audioBufferParameters.samplesPerFrameTarget + 0x10) / 0xD0) + 1; - gAudioContext.audioBufferParameters.samplesPerUpdate = (gAudioContext.audioBufferParameters.samplesPerFrameTarget / - gAudioContext.audioBufferParameters.updatesPerFrame) & - ~7; - gAudioContext.audioBufferParameters.samplesPerUpdateMax = gAudioContext.audioBufferParameters.samplesPerUpdate + 8; - gAudioContext.audioBufferParameters.samplesPerUpdateMin = gAudioContext.audioBufferParameters.samplesPerUpdate - 8; - gAudioContext.audioBufferParameters.resampleRate = - 32000.0f / (s32)gAudioContext.audioBufferParameters.samplingFrequency; - gAudioContext.audioBufferParameters.updatesPerFrameInvScaled = - (1.0f / 256.0f) / gAudioContext.audioBufferParameters.updatesPerFrame; - gAudioContext.audioBufferParameters.updatesPerFrameScaled = - gAudioContext.audioBufferParameters.updatesPerFrame / 4.0f; - gAudioContext.audioBufferParameters.updatesPerFrameInv = 1.0f / gAudioContext.audioBufferParameters.updatesPerFrame; + gAudioCtx.audioBufferParameters.samplingFrequency = spec->samplingFrequency; + gAudioCtx.audioBufferParameters.aiSamplingFrequency = + osAiSetFrequency(gAudioCtx.audioBufferParameters.samplingFrequency); + gAudioCtx.audioBufferParameters.samplesPerFrameTarget = + ALIGN16(gAudioCtx.audioBufferParameters.samplingFrequency / gAudioCtx.refreshRate); + gAudioCtx.audioBufferParameters.minAiBufferLength = gAudioCtx.audioBufferParameters.samplesPerFrameTarget - 0x10; + gAudioCtx.audioBufferParameters.maxAiBufferLength = gAudioCtx.audioBufferParameters.samplesPerFrameTarget + 0x10; + gAudioCtx.audioBufferParameters.updatesPerFrame = + ((gAudioCtx.audioBufferParameters.samplesPerFrameTarget + 0x10) / 0xD0) + 1; + gAudioCtx.audioBufferParameters.samplesPerUpdate = + (gAudioCtx.audioBufferParameters.samplesPerFrameTarget / gAudioCtx.audioBufferParameters.updatesPerFrame) & ~7; + gAudioCtx.audioBufferParameters.samplesPerUpdateMax = gAudioCtx.audioBufferParameters.samplesPerUpdate + 8; + gAudioCtx.audioBufferParameters.samplesPerUpdateMin = gAudioCtx.audioBufferParameters.samplesPerUpdate - 8; + gAudioCtx.audioBufferParameters.resampleRate = 32000.0f / (s32)gAudioCtx.audioBufferParameters.samplingFrequency; + gAudioCtx.audioBufferParameters.updatesPerFrameInvScaled = + (1.0f / 256.0f) / gAudioCtx.audioBufferParameters.updatesPerFrame; + gAudioCtx.audioBufferParameters.updatesPerFrameScaled = gAudioCtx.audioBufferParameters.updatesPerFrame / 4.0f; + gAudioCtx.audioBufferParameters.updatesPerFrameInv = 1.0f / gAudioCtx.audioBufferParameters.updatesPerFrame; // SampleDma buffer size - gAudioContext.sampleDmaBufSize1 = spec->sampleDmaBufSize1; - gAudioContext.sampleDmaBufSize2 = spec->sampleDmaBufSize2; + gAudioCtx.sampleDmaBufSize1 = spec->sampleDmaBufSize1; + gAudioCtx.sampleDmaBufSize2 = spec->sampleDmaBufSize2; - gAudioContext.numNotes = spec->numNotes; - gAudioContext.audioBufferParameters.numSequencePlayers = spec->numSequencePlayers; - if (gAudioContext.audioBufferParameters.numSequencePlayers > 4) { - gAudioContext.audioBufferParameters.numSequencePlayers = 4; + gAudioCtx.numNotes = spec->numNotes; + gAudioCtx.audioBufferParameters.numSequencePlayers = spec->numSequencePlayers; + if (gAudioCtx.audioBufferParameters.numSequencePlayers > 4) { + gAudioCtx.audioBufferParameters.numSequencePlayers = 4; } - gAudioContext.unk_2 = spec->unk_14; - gAudioContext.tempoInternalToExternal = (u32)(gAudioContext.audioBufferParameters.updatesPerFrame * 2880000.0f / - gTatumsPerBeat / gAudioContext.unk_2960); + gAudioCtx.unk_2 = spec->unk_14; + gAudioCtx.tempoInternalToExternal = + (u32)(gAudioCtx.audioBufferParameters.updatesPerFrame * 2880000.0f / gTatumsPerBeat / gAudioCtx.unk_2960); - gAudioContext.unk_2870 = gAudioContext.refreshRate; - gAudioContext.unk_2870 *= gAudioContext.audioBufferParameters.updatesPerFrame; - gAudioContext.unk_2870 /= gAudioContext.audioBufferParameters.aiSamplingFrequency; - gAudioContext.unk_2870 /= gAudioContext.tempoInternalToExternal; + gAudioCtx.unk_2870 = gAudioCtx.refreshRate; + gAudioCtx.unk_2870 *= gAudioCtx.audioBufferParameters.updatesPerFrame; + gAudioCtx.unk_2870 /= gAudioCtx.audioBufferParameters.aiSamplingFrequency; + gAudioCtx.unk_2870 /= gAudioCtx.tempoInternalToExternal; - gAudioContext.audioBufferParameters.specUnk4 = spec->unk_04; - gAudioContext.audioBufferParameters.samplesPerFrameTarget *= gAudioContext.audioBufferParameters.specUnk4; - gAudioContext.audioBufferParameters.maxAiBufferLength *= gAudioContext.audioBufferParameters.specUnk4; - gAudioContext.audioBufferParameters.minAiBufferLength *= gAudioContext.audioBufferParameters.specUnk4; - gAudioContext.audioBufferParameters.updatesPerFrame *= gAudioContext.audioBufferParameters.specUnk4; + gAudioCtx.audioBufferParameters.specUnk4 = spec->unk_04; + gAudioCtx.audioBufferParameters.samplesPerFrameTarget *= gAudioCtx.audioBufferParameters.specUnk4; + gAudioCtx.audioBufferParameters.maxAiBufferLength *= gAudioCtx.audioBufferParameters.specUnk4; + gAudioCtx.audioBufferParameters.minAiBufferLength *= gAudioCtx.audioBufferParameters.specUnk4; + gAudioCtx.audioBufferParameters.updatesPerFrame *= gAudioCtx.audioBufferParameters.specUnk4; - if (gAudioContext.audioBufferParameters.specUnk4 >= 2) { - gAudioContext.audioBufferParameters.maxAiBufferLength -= 0x10; + if (gAudioCtx.audioBufferParameters.specUnk4 >= 2) { + gAudioCtx.audioBufferParameters.maxAiBufferLength -= 0x10; } // Determine the length of the buffer for storing the audio command list passed to the rsp audio microcode - gAudioContext.maxAudioCmds = gAudioContext.numNotes * 0x10 * gAudioContext.audioBufferParameters.updatesPerFrame + - spec->numReverbs * 0x18 + 0x140; + gAudioCtx.maxAudioCmds = + gAudioCtx.numNotes * 0x10 * gAudioCtx.audioBufferParameters.updatesPerFrame + spec->numReverbs * 0x18 + 0x140; // Calculate sizes for various caches on the audio heap persistentSize = @@ -921,62 +915,61 @@ void AudioHeap_Init(void) { temporarySize = spec->temporarySeqCacheSize + spec->temporaryFontCacheSize + spec->temporarySampleBankCacheSize + 0x10; cachePoolSize = persistentSize + temporarySize; - miscPoolSize = gAudioContext.sessionPool.size - cachePoolSize - 0x100; + miscPoolSize = gAudioCtx.sessionPool.size - cachePoolSize - 0x100; - if (gAudioContext.externalPool.startRamAddr != NULL) { - gAudioContext.externalPool.curRamAddr = gAudioContext.externalPool.startRamAddr; + if (gAudioCtx.externalPool.startRamAddr != NULL) { + gAudioCtx.externalPool.curRamAddr = gAudioCtx.externalPool.startRamAddr; } // Session Pool Split (split into Cache and Misc pools) - gAudioContext.sessionPoolSplit.miscPoolSize = miscPoolSize; - gAudioContext.sessionPoolSplit.cachePoolSize = cachePoolSize; - AudioHeap_InitSessionPools(&gAudioContext.sessionPoolSplit); + gAudioCtx.sessionPoolSplit.miscPoolSize = miscPoolSize; + gAudioCtx.sessionPoolSplit.cachePoolSize = cachePoolSize; + AudioHeap_InitSessionPools(&gAudioCtx.sessionPoolSplit); // Cache Pool Split (split into Persistent and Temporary pools) - gAudioContext.cachePoolSplit.persistentCommonPoolSize = persistentSize; - gAudioContext.cachePoolSplit.temporaryCommonPoolSize = temporarySize; - AudioHeap_InitCachePools(&gAudioContext.cachePoolSplit); + gAudioCtx.cachePoolSplit.persistentCommonPoolSize = persistentSize; + gAudioCtx.cachePoolSplit.temporaryCommonPoolSize = temporarySize; + AudioHeap_InitCachePools(&gAudioCtx.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_InitPersistentPoolsAndCaches(&gAudioContext.persistentCommonPoolSplit); + gAudioCtx.persistentCommonPoolSplit.seqCacheSize = spec->persistentSeqCacheSize; + gAudioCtx.persistentCommonPoolSplit.fontCacheSize = spec->persistentFontCacheSize; + gAudioCtx.persistentCommonPoolSplit.sampleBankCacheSize = spec->persistentSampleBankCacheSize; + AudioHeap_InitPersistentPoolsAndCaches(&gAudioCtx.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_InitTemporaryPoolsAndCaches(&gAudioContext.temporaryCommonPoolSplit); + gAudioCtx.temporaryCommonPoolSplit.seqCacheSize = spec->temporarySeqCacheSize; + gAudioCtx.temporaryCommonPoolSplit.fontCacheSize = spec->temporaryFontCacheSize; + gAudioCtx.temporaryCommonPoolSplit.sampleBankCacheSize = spec->temporarySampleBankCacheSize; + AudioHeap_InitTemporaryPoolsAndCaches(&gAudioCtx.temporaryCommonPoolSplit); AudioHeap_ResetLoadStatus(); // Initialize notes - gAudioContext.notes = AudioHeap_AllocZeroed(&gAudioContext.miscPool, gAudioContext.numNotes * sizeof(Note)); + gAudioCtx.notes = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, gAudioCtx.numNotes * sizeof(Note)); Audio_NoteInitAll(); Audio_InitNoteFreeList(); - gAudioContext.noteSubsEu = - AudioHeap_AllocZeroed(&gAudioContext.miscPool, gAudioContext.audioBufferParameters.updatesPerFrame * - gAudioContext.numNotes * sizeof(NoteSubEu)); + gAudioCtx.noteSubsEu = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, gAudioCtx.audioBufferParameters.updatesPerFrame * + gAudioCtx.numNotes * sizeof(NoteSubEu)); // Initialize audio binary interface command list buffers for (i = 0; i != 2; i++) { - gAudioContext.abiCmdBufs[i] = - AudioHeap_AllocDmaMemoryZeroed(&gAudioContext.miscPool, gAudioContext.maxAudioCmds * sizeof(Acmd)); + gAudioCtx.abiCmdBufs[i] = + AudioHeap_AllocDmaMemoryZeroed(&gAudioCtx.miscPool, gAudioCtx.maxAudioCmds * sizeof(Acmd)); } // Initialize the decay rate table for adsr - gAudioContext.adsrDecayTable = AudioHeap_Alloc(&gAudioContext.miscPool, 256 * sizeof(f32)); + gAudioCtx.adsrDecayTable = AudioHeap_Alloc(&gAudioCtx.miscPool, 256 * sizeof(f32)); AudioHeap_InitAdsrDecayTable(); // Initialize reverbs for (i = 0; i < 4; i++) { - gAudioContext.synthesisReverbs[i].useReverb = 0; + gAudioCtx.synthesisReverbs[i].useReverb = 0; } - gAudioContext.numSynthesisReverbs = spec->numReverbs; - for (i = 0; i < gAudioContext.numSynthesisReverbs; i++) { + gAudioCtx.numSynthesisReverbs = spec->numReverbs; + for (i = 0; i < gAudioCtx.numSynthesisReverbs; i++) { ReverbSettings* settings = &spec->reverbSettings[i]; - SynthesisReverb* reverb = &gAudioContext.synthesisReverbs[i]; + SynthesisReverb* reverb = &gAudioCtx.synthesisReverbs[i]; reverb->downsampleRate = settings->downsampleRate; reverb->windowSize = settings->windowSize * 64; @@ -992,9 +985,9 @@ void AudioHeap_Init(void) { reverb->unk_08 = settings->unk_12; reverb->useReverb = 8; reverb->leftRingBuf = - AudioHeap_AllocZeroedAttemptExternal(&gAudioContext.miscPool, reverb->windowSize * SAMPLE_SIZE); + AudioHeap_AllocZeroedAttemptExternal(&gAudioCtx.miscPool, reverb->windowSize * SAMPLE_SIZE); reverb->rightRingBuf = - AudioHeap_AllocZeroedAttemptExternal(&gAudioContext.miscPool, reverb->windowSize * SAMPLE_SIZE); + AudioHeap_AllocZeroedAttemptExternal(&gAudioCtx.miscPool, reverb->windowSize * SAMPLE_SIZE); reverb->nextRingBufPos = 0; reverb->unk_20 = 0; reverb->curFrame = 0; @@ -1014,16 +1007,16 @@ void AudioHeap_Init(void) { if (reverb->downsampleRate != 1) { reverb->unk_0E = 0x8000 / reverb->downsampleRate; - reverb->unk_30 = AudioHeap_AllocZeroed(&gAudioContext.miscPool, sizeof(RESAMPLE_STATE)); - reverb->unk_34 = AudioHeap_AllocZeroed(&gAudioContext.miscPool, sizeof(RESAMPLE_STATE)); - reverb->unk_38 = AudioHeap_AllocZeroed(&gAudioContext.miscPool, sizeof(RESAMPLE_STATE)); - reverb->unk_3C = AudioHeap_AllocZeroed(&gAudioContext.miscPool, sizeof(RESAMPLE_STATE)); - for (j = 0; j < gAudioContext.audioBufferParameters.updatesPerFrame; j++) { - ramAddr = AudioHeap_AllocZeroedAttemptExternal(&gAudioContext.miscPool, DMEM_2CH_SIZE); + reverb->unk_30 = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(RESAMPLE_STATE)); + reverb->unk_34 = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(RESAMPLE_STATE)); + reverb->unk_38 = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(RESAMPLE_STATE)); + reverb->unk_3C = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(RESAMPLE_STATE)); + for (j = 0; j < gAudioCtx.audioBufferParameters.updatesPerFrame; j++) { + ramAddr = AudioHeap_AllocZeroedAttemptExternal(&gAudioCtx.miscPool, DMEM_2CH_SIZE); reverb->items[0][j].toDownsampleLeft = ramAddr; reverb->items[0][j].toDownsampleRight = ramAddr + DMEM_1CH_SIZE / SAMPLE_SIZE; - ramAddr = AudioHeap_AllocZeroedAttemptExternal(&gAudioContext.miscPool, DMEM_2CH_SIZE); + ramAddr = AudioHeap_AllocZeroedAttemptExternal(&gAudioCtx.miscPool, DMEM_2CH_SIZE); reverb->items[1][j].toDownsampleLeft = ramAddr; reverb->items[1][j].toDownsampleRight = ramAddr + DMEM_1CH_SIZE / SAMPLE_SIZE; } @@ -1031,8 +1024,8 @@ void AudioHeap_Init(void) { if (settings->lowPassFilterCutoffLeft != 0) { reverb->filterLeftState = - AudioHeap_AllocDmaMemoryZeroed(&gAudioContext.miscPool, 2 * (FILTER_BUF_PART1 + FILTER_BUF_PART2)); - reverb->filterLeft = AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, FILTER_SIZE); + AudioHeap_AllocDmaMemoryZeroed(&gAudioCtx.miscPool, 2 * (FILTER_BUF_PART1 + FILTER_BUF_PART2)); + reverb->filterLeft = AudioHeap_AllocDmaMemory(&gAudioCtx.miscPool, FILTER_SIZE); AudioHeap_LoadLowPassFilter(reverb->filterLeft, settings->lowPassFilterCutoffLeft); } else { reverb->filterLeft = NULL; @@ -1040,8 +1033,8 @@ void AudioHeap_Init(void) { if (settings->lowPassFilterCutoffRight != 0) { reverb->filterRightState = - AudioHeap_AllocDmaMemoryZeroed(&gAudioContext.miscPool, 2 * (FILTER_BUF_PART1 + FILTER_BUF_PART2)); - reverb->filterRight = AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, FILTER_SIZE); + AudioHeap_AllocDmaMemoryZeroed(&gAudioCtx.miscPool, 2 * (FILTER_BUF_PART1 + FILTER_BUF_PART2)); + reverb->filterRight = AudioHeap_AllocDmaMemory(&gAudioCtx.miscPool, FILTER_SIZE); AudioHeap_LoadLowPassFilter(reverb->filterRight, settings->lowPassFilterCutoffRight); } else { reverb->filterRight = NULL; @@ -1050,21 +1043,21 @@ void AudioHeap_Init(void) { // Initialize sequence players AudioSeq_InitSequencePlayers(); - for (j = 0; j < gAudioContext.audioBufferParameters.numSequencePlayers; j++) { + for (j = 0; j < gAudioCtx.audioBufferParameters.numSequencePlayers; j++) { AudioSeq_InitSequencePlayerChannels(j); - AudioSeq_ResetSequencePlayer(&gAudioContext.seqPlayers[j]); + AudioSeq_ResetSequencePlayer(&gAudioCtx.seqPlayers[j]); } // Initialize two additional sample caches for individual samples AudioHeap_InitSampleCaches(spec->persistentSampleCacheSize, spec->temporarySampleCacheSize); - AudioLoad_InitSampleDmaBuffers(gAudioContext.numNotes); + AudioLoad_InitSampleDmaBuffers(gAudioCtx.numNotes); // Initialize Loads - gAudioContext.preloadSampleStackTop = 0; + gAudioCtx.preloadSampleStackTop = 0; AudioLoad_InitSlowLoads(); AudioLoad_InitScriptLoads(); AudioLoad_InitAsyncLoads(); - gAudioContext.unk_4 = 0x1000; + gAudioCtx.unk_4 = 0x1000; AudioLoad_LoadPermanentSamples(); intMask = osSetIntMask(OS_IM_NONE); @@ -1075,9 +1068,9 @@ void AudioHeap_Init(void) { void* AudioHeap_SearchPermanentCache(s32 tableType, s32 id) { s32 i; - for (i = 0; i < gAudioContext.permanentPool.numEntries; i++) { - if (gAudioContext.permanentCache[i].tableType == tableType && gAudioContext.permanentCache[i].id == id) { - return gAudioContext.permanentCache[i].ramAddr; + for (i = 0; i < gAudioCtx.permanentPool.numEntries; i++) { + if (gAudioCtx.permanentCache[i].tableType == tableType && gAudioCtx.permanentCache[i].id == id) { + return gAudioCtx.permanentCache[i].ramAddr; } } return NULL; @@ -1085,16 +1078,16 @@ void* AudioHeap_SearchPermanentCache(s32 tableType, s32 id) { void* AudioHeap_AllocPermanent(s32 tableType, s32 id, u32 size) { void* ramAddr; - s32 index = gAudioContext.permanentPool.numEntries; + s32 index = gAudioCtx.permanentPool.numEntries; - ramAddr = AudioHeap_Alloc(&gAudioContext.permanentPool, size); - gAudioContext.permanentCache[index].ramAddr = ramAddr; + ramAddr = AudioHeap_Alloc(&gAudioCtx.permanentPool, size); + gAudioCtx.permanentCache[index].ramAddr = ramAddr; if (ramAddr == NULL) { return NULL; } - gAudioContext.permanentCache[index].tableType = tableType; - gAudioContext.permanentCache[index].id = id; - gAudioContext.permanentCache[index].size = size; + gAudioCtx.permanentCache[index].tableType = tableType; + gAudioCtx.permanentCache[index].id = id; + gAudioCtx.permanentCache[index].size = size; //! @bug UB: missing return. "ramAddr" is in v0 at this point, but doing an //! explicit return uses an additional register. @@ -1128,20 +1121,20 @@ void* AudioHeap_AllocSampleCache(u32 size, s32 fontId, void* sampleAddr, s8 medi void AudioHeap_InitSampleCaches(u32 persistentSampleCacheSize, u32 temporarySampleCacheSize) { void* ramAddr; - ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.miscPool, persistentSampleCacheSize); + ramAddr = AudioHeap_AllocAttemptExternal(&gAudioCtx.miscPool, persistentSampleCacheSize); if (ramAddr == NULL) { - gAudioContext.persistentSampleCache.pool.size = 0; + gAudioCtx.persistentSampleCache.pool.size = 0; } else { - AudioHeap_InitPool(&gAudioContext.persistentSampleCache.pool, ramAddr, persistentSampleCacheSize); + AudioHeap_InitPool(&gAudioCtx.persistentSampleCache.pool, ramAddr, persistentSampleCacheSize); } - ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.miscPool, temporarySampleCacheSize); + ramAddr = AudioHeap_AllocAttemptExternal(&gAudioCtx.miscPool, temporarySampleCacheSize); if (ramAddr == NULL) { - gAudioContext.temporarySampleCache.pool.size = 0; + gAudioCtx.temporarySampleCache.pool.size = 0; } else { - AudioHeap_InitPool(&gAudioContext.temporarySampleCache.pool, ramAddr, temporarySampleCacheSize); + AudioHeap_InitPool(&gAudioCtx.temporarySampleCache.pool, ramAddr, temporarySampleCacheSize); } - gAudioContext.persistentSampleCache.numEntries = 0; - gAudioContext.temporarySampleCache.numEntries = 0; + gAudioCtx.persistentSampleCache.numEntries = 0; + gAudioCtx.temporarySampleCache.numEntries = 0; } SampleCacheEntry* AudioHeap_AllocTemporarySampleCacheEntry(u32 size) { @@ -1156,7 +1149,7 @@ SampleCacheEntry* AudioHeap_AllocTemporarySampleCacheEntry(u32 size) { u8* startRamAddr; u8* endRamAddr; - cache = &gAudioContext.temporarySampleCache; + cache = &gAudioCtx.temporarySampleCache; allocBefore = cache->pool.curRamAddr; ramAddr = AudioHeap_Alloc(&cache->pool, size); if (ramAddr == NULL) { @@ -1177,8 +1170,8 @@ SampleCacheEntry* AudioHeap_AllocTemporarySampleCacheEntry(u32 size) { allocAfter = cache->pool.curRamAddr; index = -1; - for (i = 0; i < gAudioContext.preloadSampleStackTop; i++) { - preload = &gAudioContext.preloadSampleStack[i]; + for (i = 0; i < gAudioCtx.preloadSampleStackTop; i++) { + preload = &gAudioCtx.preloadSampleStack[i]; if (preload->isFree == false) { startRamAddr = preload->ramAddr; endRamAddr = preload->ramAddr + preload->sample->size - 1; @@ -1237,7 +1230,7 @@ void AudioHeap_UnapplySampleCacheForFont(SampleCacheEntry* entry, s32 fontId) { s32 drumId; s32 sfxId; - for (instId = 0; instId < gAudioContext.soundFontList[fontId].numInstruments; instId++) { + for (instId = 0; instId < gAudioCtx.soundFontList[fontId].numInstruments; instId++) { inst = Audio_GetInstrumentInner(fontId, instId); if (inst != NULL) { if (inst->normalRangeLo != 0) { @@ -1250,14 +1243,14 @@ void AudioHeap_UnapplySampleCacheForFont(SampleCacheEntry* entry, s32 fontId) { } } - for (drumId = 0; drumId < gAudioContext.soundFontList[fontId].numDrums; drumId++) { + for (drumId = 0; drumId < gAudioCtx.soundFontList[fontId].numDrums; drumId++) { drum = Audio_GetDrum(fontId, drumId); if (drum != NULL) { AudioHeap_UnapplySampleCache(entry, drum->tunedSample.sample); } } - for (sfxId = 0; sfxId < gAudioContext.soundFontList[fontId].numSfx; sfxId++) { + for (sfxId = 0; sfxId < gAudioCtx.soundFontList[fontId].numSfx; sfxId++) { soundEffect = Audio_GetSoundEffect(fontId, sfxId); if (soundEffect != NULL) { AudioHeap_UnapplySampleCache(entry, soundEffect->tunedSample.sample); @@ -1271,10 +1264,10 @@ void AudioHeap_DiscardSampleCacheEntry(SampleCacheEntry* entry) { s32 sampleBankId2; s32 fontId; - numFonts = gAudioContext.soundFontTable->numEntries; + numFonts = gAudioCtx.soundFontTable->numEntries; for (fontId = 0; fontId < numFonts; fontId++) { - sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1; + sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2; if (((sampleBankId1 != 0xFF) && (entry->sampleBankId == sampleBankId1)) || ((sampleBankId2 != 0xFF) && (entry->sampleBankId == sampleBankId2)) || entry->sampleBankId == 0) { if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, fontId) != NULL) { @@ -1300,7 +1293,7 @@ SampleCacheEntry* AudioHeap_AllocPersistentSampleCacheEntry(u32 size) { SampleCacheEntry* entry; void* ramAddr; - cache = &gAudioContext.persistentSampleCache; + cache = &gAudioCtx.persistentSampleCache; ramAddr = AudioHeap_Alloc(&cache->pool, size); if (ramAddr == NULL) { return NULL; @@ -1328,10 +1321,10 @@ void AudioHeap_DiscardSampleCaches(void) { s32 fontId; s32 j; - numFonts = gAudioContext.soundFontTable->numEntries; + numFonts = gAudioCtx.soundFontTable->numEntries; for (fontId = 0; fontId < numFonts; fontId++) { - sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1; + sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2; if ((sampleBankId1 == 0xFF) && (sampleBankId2 == 0xFF)) { continue; } @@ -1340,12 +1333,12 @@ void AudioHeap_DiscardSampleCaches(void) { continue; } - for (j = 0; j < gAudioContext.persistentSampleCache.numEntries; j++) { - AudioHeap_DiscardSampleCacheForFont(&gAudioContext.persistentSampleCache.entries[j], sampleBankId1, + for (j = 0; j < gAudioCtx.persistentSampleCache.numEntries; j++) { + AudioHeap_DiscardSampleCacheForFont(&gAudioCtx.persistentSampleCache.entries[j], sampleBankId1, sampleBankId2, fontId); } - for (j = 0; j < gAudioContext.temporarySampleCache.numEntries; j++) { - AudioHeap_DiscardSampleCacheForFont(&gAudioContext.temporarySampleCache.entries[j], sampleBankId1, + for (j = 0; j < gAudioCtx.temporarySampleCache.numEntries; j++) { + AudioHeap_DiscardSampleCacheForFont(&gAudioCtx.temporarySampleCache.entries[j], sampleBankId1, sampleBankId2, fontId); } } @@ -1397,8 +1390,8 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) { u32* fakematch; s32 pad[4]; - sampleBankTable = gAudioContext.sampleBankTable; - numFonts = gAudioContext.soundFontTable->numEntries; + sampleBankTable = gAudioCtx.sampleBankTable; + numFonts = gAudioCtx.soundFontTable->numEntries; change.oldAddr = (u32)AudioHeap_SearchCaches(SAMPLE_TABLE, CACHE_EITHER, sampleBankId); if (change.oldAddr == 0) { return; @@ -1424,8 +1417,8 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) { } for (fontId = 0; fontId < numFonts; fontId++) { - sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1; + sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2; if ((sampleBankId1 != 0xFF) || (sampleBankId2 != 0xFF)) { if (!AudioLoad_IsFontLoadComplete(fontId) || AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, fontId) == NULL) { @@ -1438,7 +1431,7 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) { continue; } - for (instId = 0; instId < gAudioContext.soundFontList[fontId].numInstruments; instId++) { + for (instId = 0; instId < gAudioCtx.soundFontList[fontId].numInstruments; instId++) { inst = Audio_GetInstrumentInner(fontId, instId); if (inst != NULL) { if (inst->normalRangeLo != 0) { @@ -1451,14 +1444,14 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) { } } - for (drumId = 0; drumId < gAudioContext.soundFontList[fontId].numDrums; drumId++) { + for (drumId = 0; drumId < gAudioCtx.soundFontList[fontId].numDrums; drumId++) { drum = Audio_GetDrum(fontId, drumId); if (drum != NULL) { AudioHeap_ChangeStorage(&change, drum->tunedSample.sample); } } - for (sfxId = 0; sfxId < gAudioContext.soundFontList[fontId].numSfx; sfxId++) { + for (sfxId = 0; sfxId < gAudioCtx.soundFontList[fontId].numSfx; sfxId++) { soundEffect = Audio_GetSoundEffect(fontId, sfxId); if (soundEffect != NULL) { AudioHeap_ChangeStorage(&change, soundEffect->tunedSample.sample); @@ -1474,7 +1467,7 @@ void AudioHeap_DiscardSampleBanks(void) { AudioTemporaryCache* temporary; u32 i; - cache = &gAudioContext.sampleBankCache; + cache = &gAudioCtx.sampleBankCache; temporary = &cache->temporary; if (temporary->entries[0].id != -1) { diff --git a/src/code/audio_init_params.c b/src/code/audio_init_params.c index 28ccec031e..56b8999930 100644 --- a/src/code/audio_init_params.c +++ b/src/code/audio_init_params.c @@ -1,7 +1,7 @@ #include "global.h" u8 D_8016F0E0[0xA0]; // unused -AudioContext gAudioContext; +AudioContext gAudioCtx; void (*D_801755D0)(void); s32 D_801755D8[3]; // unused @@ -17,7 +17,7 @@ const s16 D_8014A6C0[] = { #define SFX_SOUNDFONT_2_SIZE 0x17B0 // Sizes of everything on the init pool -#define AI_BUFFERS_SIZE (AIBUF_SIZE * ARRAY_COUNT(gAudioContext.aiBuffers)) +#define AI_BUFFERS_SIZE (AIBUF_SIZE * ARRAY_COUNT(gAudioCtx.aiBuffers)) #define SOUNDFONT_LIST_SIZE (NUM_SOUNDFONTS * sizeof(SoundFont)) #define PERMANENT_POOL_SIZE (SFX_SEQ_SIZE + SFX_SOUNDFONT_1_SIZE + SFX_SOUNDFONT_2_SIZE) diff --git a/src/code/audio_load.c b/src/code/audio_load.c index c234538f34..b32b47963e 100644 --- a/src/code/audio_load.c +++ b/src/code/audio_load.c @@ -75,33 +75,33 @@ s32 gAudioContextInitialized = false; void AudioLoad_DecreaseSampleDmaTtls(void) { u32 i; - for (i = 0; i < gAudioContext.sampleDmaListSize1; i++) { - SampleDma* dma = &gAudioContext.sampleDmas[i]; + for (i = 0; i < gAudioCtx.sampleDmaListSize1; i++) { + SampleDma* dma = &gAudioCtx.sampleDmas[i]; if (dma->ttl != 0) { dma->ttl--; if (dma->ttl == 0) { - dma->reuseIndex = gAudioContext.sampleDmaReuseQueue1WrPos; - gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1WrPos] = i; - gAudioContext.sampleDmaReuseQueue1WrPos++; + dma->reuseIndex = gAudioCtx.sampleDmaReuseQueue1WrPos; + gAudioCtx.sampleDmaReuseQueue1[gAudioCtx.sampleDmaReuseQueue1WrPos] = i; + gAudioCtx.sampleDmaReuseQueue1WrPos++; } } } - for (i = gAudioContext.sampleDmaListSize1; i < gAudioContext.sampleDmaCount; i++) { - SampleDma* dma = &gAudioContext.sampleDmas[i]; + for (i = gAudioCtx.sampleDmaListSize1; i < gAudioCtx.sampleDmaCount; i++) { + SampleDma* dma = &gAudioCtx.sampleDmas[i]; if (dma->ttl != 0) { dma->ttl--; if (dma->ttl == 0) { - dma->reuseIndex = gAudioContext.sampleDmaReuseQueue2WrPos; - gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2WrPos] = i; - gAudioContext.sampleDmaReuseQueue2WrPos++; + dma->reuseIndex = gAudioCtx.sampleDmaReuseQueue2WrPos; + gAudioCtx.sampleDmaReuseQueue2[gAudioCtx.sampleDmaReuseQueue2WrPos] = i; + gAudioCtx.sampleDmaReuseQueue2WrPos++; } } } - gAudioContext.unused2628 = 0; + gAudioCtx.unused2628 = 0; } void* AudioLoad_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, s32 medium) { @@ -115,24 +115,22 @@ void* AudioLoad_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, s32 bufferPos; u32 i; - if (arg2 != 0 || *dmaIndexRef >= gAudioContext.sampleDmaListSize1) { - for (i = gAudioContext.sampleDmaListSize1; i < gAudioContext.sampleDmaCount; i++) { - dma = &gAudioContext.sampleDmas[i]; + if (arg2 != 0 || *dmaIndexRef >= gAudioCtx.sampleDmaListSize1) { + for (i = gAudioCtx.sampleDmaListSize1; i < gAudioCtx.sampleDmaCount; i++) { + dma = &gAudioCtx.sampleDmas[i]; bufferPos = devAddr - dma->devAddr; if (0 <= bufferPos && (u32)bufferPos <= dma->size - size) { // We already have a DMA request for this memory range. - if (dma->ttl == 0 && - gAudioContext.sampleDmaReuseQueue2RdPos != gAudioContext.sampleDmaReuseQueue2WrPos) { + if (dma->ttl == 0 && gAudioCtx.sampleDmaReuseQueue2RdPos != gAudioCtx.sampleDmaReuseQueue2WrPos) { // Move the DMA out of the reuse queue, by swapping it with the // read pos, and then incrementing the read pos. - if (dma->reuseIndex != gAudioContext.sampleDmaReuseQueue2RdPos) { - gAudioContext.sampleDmaReuseQueue2[dma->reuseIndex] = - gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2RdPos]; - gAudioContext - .sampleDmas[gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2RdPos]] + if (dma->reuseIndex != gAudioCtx.sampleDmaReuseQueue2RdPos) { + gAudioCtx.sampleDmaReuseQueue2[dma->reuseIndex] = + gAudioCtx.sampleDmaReuseQueue2[gAudioCtx.sampleDmaReuseQueue2RdPos]; + gAudioCtx.sampleDmas[gAudioCtx.sampleDmaReuseQueue2[gAudioCtx.sampleDmaReuseQueue2RdPos]] .reuseIndex = dma->reuseIndex; } - gAudioContext.sampleDmaReuseQueue2RdPos++; + gAudioCtx.sampleDmaReuseQueue2RdPos++; } dma->ttl = 32; *dmaIndexRef = (u8)i; @@ -144,16 +142,16 @@ void* AudioLoad_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, goto search_short_lived; } - if (gAudioContext.sampleDmaReuseQueue2RdPos != gAudioContext.sampleDmaReuseQueue2WrPos && arg2 != 0) { + if (gAudioCtx.sampleDmaReuseQueue2RdPos != gAudioCtx.sampleDmaReuseQueue2WrPos && arg2 != 0) { // Allocate a DMA from reuse queue 2, unless full. - dmaIndex = gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2RdPos]; - gAudioContext.sampleDmaReuseQueue2RdPos++; - dma = gAudioContext.sampleDmas + dmaIndex; + dmaIndex = gAudioCtx.sampleDmaReuseQueue2[gAudioCtx.sampleDmaReuseQueue2RdPos]; + gAudioCtx.sampleDmaReuseQueue2RdPos++; + dma = gAudioCtx.sampleDmas + dmaIndex; hasDma = true; } } else { search_short_lived: - dma = gAudioContext.sampleDmas + *dmaIndexRef; + dma = gAudioCtx.sampleDmas + *dmaIndexRef; i = 0; again: bufferPos = devAddr - dma->devAddr; @@ -162,31 +160,30 @@ void* AudioLoad_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, if (dma->ttl == 0) { // Move the DMA out of the reuse queue, by swapping it with the // read pos, and then incrementing the read pos. - if (dma->reuseIndex != gAudioContext.sampleDmaReuseQueue1RdPos) { - gAudioContext.sampleDmaReuseQueue1[dma->reuseIndex] = - gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1RdPos]; - gAudioContext - .sampleDmas[gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1RdPos]] + if (dma->reuseIndex != gAudioCtx.sampleDmaReuseQueue1RdPos) { + gAudioCtx.sampleDmaReuseQueue1[dma->reuseIndex] = + gAudioCtx.sampleDmaReuseQueue1[gAudioCtx.sampleDmaReuseQueue1RdPos]; + gAudioCtx.sampleDmas[gAudioCtx.sampleDmaReuseQueue1[gAudioCtx.sampleDmaReuseQueue1RdPos]] .reuseIndex = dma->reuseIndex; } - gAudioContext.sampleDmaReuseQueue1RdPos++; + gAudioCtx.sampleDmaReuseQueue1RdPos++; } dma->ttl = 2; return dma->ramAddr + (devAddr - dma->devAddr); } - dma = gAudioContext.sampleDmas + i++; - if (i <= gAudioContext.sampleDmaListSize1) { + dma = gAudioCtx.sampleDmas + i++; + if (i <= gAudioCtx.sampleDmaListSize1) { goto again; } } if (!hasDma) { - if (gAudioContext.sampleDmaReuseQueue1RdPos == gAudioContext.sampleDmaReuseQueue1WrPos) { + if (gAudioCtx.sampleDmaReuseQueue1RdPos == gAudioCtx.sampleDmaReuseQueue1WrPos) { return NULL; } // Allocate a DMA from reuse queue 1. - dmaIndex = gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1RdPos++]; - dma = gAudioContext.sampleDmas + dmaIndex; + dmaIndex = gAudioCtx.sampleDmaReuseQueue1[gAudioCtx.sampleDmaReuseQueue1RdPos++]; + dma = gAudioCtx.sampleDmas + dmaIndex; hasDma = true; } @@ -195,9 +192,8 @@ void* AudioLoad_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, dma->ttl = 3; dma->devAddr = dmaDevAddr; dma->sizeUnused = transfer; - AudioLoad_Dma(&gAudioContext.currAudioFrameDmaIoMsgBuf[gAudioContext.curAudioFrameDmaCount++], OS_MESG_PRI_NORMAL, - OS_READ, dmaDevAddr, dma->ramAddr, transfer, &gAudioContext.currAudioFrameDmaQueue, medium, - "SUPERDMA"); + AudioLoad_Dma(&gAudioCtx.currAudioFrameDmaIoMsgBuf[gAudioCtx.curAudioFrameDmaCount++], OS_MESG_PRI_NORMAL, OS_READ, + dmaDevAddr, dma->ramAddr, transfer, &gAudioCtx.currAudioFrameDmaQueue, medium, "SUPERDMA"); *dmaIndexRef = dmaIndex; return (devAddr - dmaDevAddr) + dma->ramAddr; } @@ -208,76 +204,75 @@ void AudioLoad_InitSampleDmaBuffers(s32 numNotes) { s32 t2; s32 j; - gAudioContext.sampleDmaBufSize = gAudioContext.sampleDmaBufSize1; - gAudioContext.sampleDmas = - AudioHeap_Alloc(&gAudioContext.miscPool, - 4 * gAudioContext.numNotes * sizeof(SampleDma) * gAudioContext.audioBufferParameters.specUnk4); - t2 = 3 * gAudioContext.numNotes * gAudioContext.audioBufferParameters.specUnk4; + gAudioCtx.sampleDmaBufSize = gAudioCtx.sampleDmaBufSize1; + gAudioCtx.sampleDmas = AudioHeap_Alloc(&gAudioCtx.miscPool, 4 * gAudioCtx.numNotes * sizeof(SampleDma) * + gAudioCtx.audioBufferParameters.specUnk4); + t2 = 3 * gAudioCtx.numNotes * gAudioCtx.audioBufferParameters.specUnk4; for (i = 0; i < t2; i++) { - dma = &gAudioContext.sampleDmas[gAudioContext.sampleDmaCount]; - dma->ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.miscPool, gAudioContext.sampleDmaBufSize); + dma = &gAudioCtx.sampleDmas[gAudioCtx.sampleDmaCount]; + dma->ramAddr = AudioHeap_AllocAttemptExternal(&gAudioCtx.miscPool, gAudioCtx.sampleDmaBufSize); if (dma->ramAddr == NULL) { break; } else { - AudioHeap_WritebackDCache(dma->ramAddr, gAudioContext.sampleDmaBufSize); - dma->size = gAudioContext.sampleDmaBufSize; + AudioHeap_WritebackDCache(dma->ramAddr, gAudioCtx.sampleDmaBufSize); + dma->size = gAudioCtx.sampleDmaBufSize; dma->devAddr = 0; dma->sizeUnused = 0; dma->unused = 0; dma->ttl = 0; - gAudioContext.sampleDmaCount++; + gAudioCtx.sampleDmaCount++; } } - for (i = 0; (u32)i < gAudioContext.sampleDmaCount; i++) { - gAudioContext.sampleDmaReuseQueue1[i] = i; - gAudioContext.sampleDmas[i].reuseIndex = i; + for (i = 0; (u32)i < gAudioCtx.sampleDmaCount; i++) { + gAudioCtx.sampleDmaReuseQueue1[i] = i; + gAudioCtx.sampleDmas[i].reuseIndex = i; } - for (i = gAudioContext.sampleDmaCount; i < 0x100; i++) { - gAudioContext.sampleDmaReuseQueue1[i] = 0; + for (i = gAudioCtx.sampleDmaCount; i < 0x100; i++) { + gAudioCtx.sampleDmaReuseQueue1[i] = 0; } - gAudioContext.sampleDmaReuseQueue1RdPos = 0; - gAudioContext.sampleDmaReuseQueue1WrPos = gAudioContext.sampleDmaCount; - gAudioContext.sampleDmaListSize1 = gAudioContext.sampleDmaCount; - gAudioContext.sampleDmaBufSize = gAudioContext.sampleDmaBufSize2; + gAudioCtx.sampleDmaReuseQueue1RdPos = 0; + gAudioCtx.sampleDmaReuseQueue1WrPos = gAudioCtx.sampleDmaCount; + gAudioCtx.sampleDmaListSize1 = gAudioCtx.sampleDmaCount; + gAudioCtx.sampleDmaBufSize = gAudioCtx.sampleDmaBufSize2; - for (j = 0; j < gAudioContext.numNotes; j++) { - dma = &gAudioContext.sampleDmas[gAudioContext.sampleDmaCount]; - dma->ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.miscPool, gAudioContext.sampleDmaBufSize); + for (j = 0; j < gAudioCtx.numNotes; j++) { + dma = &gAudioCtx.sampleDmas[gAudioCtx.sampleDmaCount]; + dma->ramAddr = AudioHeap_AllocAttemptExternal(&gAudioCtx.miscPool, gAudioCtx.sampleDmaBufSize); if (dma->ramAddr == NULL) { break; } else { - AudioHeap_WritebackDCache(dma->ramAddr, gAudioContext.sampleDmaBufSize); - dma->size = gAudioContext.sampleDmaBufSize; + AudioHeap_WritebackDCache(dma->ramAddr, gAudioCtx.sampleDmaBufSize); + dma->size = gAudioCtx.sampleDmaBufSize; dma->devAddr = 0U; dma->sizeUnused = 0; dma->unused = 0; dma->ttl = 0; - gAudioContext.sampleDmaCount++; + gAudioCtx.sampleDmaCount++; } } - for (i = gAudioContext.sampleDmaListSize1; (u32)i < gAudioContext.sampleDmaCount; i++) { - gAudioContext.sampleDmaReuseQueue2[i - gAudioContext.sampleDmaListSize1] = i; - gAudioContext.sampleDmas[i].reuseIndex = i - gAudioContext.sampleDmaListSize1; + for (i = gAudioCtx.sampleDmaListSize1; (u32)i < gAudioCtx.sampleDmaCount; i++) { + gAudioCtx.sampleDmaReuseQueue2[i - gAudioCtx.sampleDmaListSize1] = i; + gAudioCtx.sampleDmas[i].reuseIndex = i - gAudioCtx.sampleDmaListSize1; } - for (i = gAudioContext.sampleDmaCount; i < 0x100; i++) { - gAudioContext.sampleDmaReuseQueue2[i] = gAudioContext.sampleDmaListSize1; + for (i = gAudioCtx.sampleDmaCount; i < 0x100; i++) { + gAudioCtx.sampleDmaReuseQueue2[i] = gAudioCtx.sampleDmaListSize1; } - gAudioContext.sampleDmaReuseQueue2RdPos = 0; - gAudioContext.sampleDmaReuseQueue2WrPos = gAudioContext.sampleDmaCount - gAudioContext.sampleDmaListSize1; + gAudioCtx.sampleDmaReuseQueue2RdPos = 0; + gAudioCtx.sampleDmaReuseQueue2WrPos = gAudioCtx.sampleDmaCount - gAudioCtx.sampleDmaListSize1; } s32 AudioLoad_IsFontLoadComplete(s32 fontId) { if (fontId == 0xFF) { return true; - } else if (gAudioContext.fontLoadStatus[fontId] >= LOAD_STATUS_COMPLETE) { + } else if (gAudioCtx.fontLoadStatus[fontId] >= LOAD_STATUS_COMPLETE) { return true; - } else if (gAudioContext.fontLoadStatus[AudioLoad_GetRealTableIndex(FONT_TABLE, fontId)] >= LOAD_STATUS_COMPLETE) { + } else if (gAudioCtx.fontLoadStatus[AudioLoad_GetRealTableIndex(FONT_TABLE, fontId)] >= LOAD_STATUS_COMPLETE) { return true; } else { return false; @@ -287,10 +282,9 @@ s32 AudioLoad_IsFontLoadComplete(s32 fontId) { s32 AudioLoad_IsSeqLoadComplete(s32 seqId) { if (seqId == 0xFF) { return true; - } else if (gAudioContext.seqLoadStatus[seqId] >= LOAD_STATUS_COMPLETE) { + } else if (gAudioCtx.seqLoadStatus[seqId] >= LOAD_STATUS_COMPLETE) { return true; - } else if (gAudioContext.seqLoadStatus[AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId)] >= - LOAD_STATUS_COMPLETE) { + } else if (gAudioCtx.seqLoadStatus[AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId)] >= LOAD_STATUS_COMPLETE) { return true; } else { return false; @@ -300,9 +294,9 @@ s32 AudioLoad_IsSeqLoadComplete(s32 seqId) { s32 AudioLoad_IsSampleLoadComplete(s32 sampleBankId) { if (sampleBankId == 0xFF) { return true; - } else if (gAudioContext.sampleFontLoadStatus[sampleBankId] >= LOAD_STATUS_COMPLETE) { + } else if (gAudioCtx.sampleFontLoadStatus[sampleBankId] >= LOAD_STATUS_COMPLETE) { return true; - } else if (gAudioContext.sampleFontLoadStatus[AudioLoad_GetRealTableIndex(SAMPLE_TABLE, sampleBankId)] >= + } else if (gAudioCtx.sampleFontLoadStatus[AudioLoad_GetRealTableIndex(SAMPLE_TABLE, sampleBankId)] >= LOAD_STATUS_COMPLETE) { return true; } else { @@ -311,34 +305,33 @@ s32 AudioLoad_IsSampleLoadComplete(s32 sampleBankId) { } void AudioLoad_SetFontLoadStatus(s32 fontId, s32 loadStatus) { - if ((fontId != 0xFF) && (gAudioContext.fontLoadStatus[fontId] != LOAD_STATUS_PERMANENTLY_LOADED)) { - gAudioContext.fontLoadStatus[fontId] = loadStatus; + if ((fontId != 0xFF) && (gAudioCtx.fontLoadStatus[fontId] != LOAD_STATUS_PERMANENTLY_LOADED)) { + gAudioCtx.fontLoadStatus[fontId] = loadStatus; } } void AudioLoad_SetSeqLoadStatus(s32 seqId, s32 loadStatus) { - if ((seqId != 0xFF) && (gAudioContext.seqLoadStatus[seqId] != LOAD_STATUS_PERMANENTLY_LOADED)) { - gAudioContext.seqLoadStatus[seqId] = loadStatus; + if ((seqId != 0xFF) && (gAudioCtx.seqLoadStatus[seqId] != LOAD_STATUS_PERMANENTLY_LOADED)) { + gAudioCtx.seqLoadStatus[seqId] = loadStatus; } } void AudioLoad_SetSampleFontLoadStatusAndApplyCaches(s32 sampleBankId, s32 loadStatus) { if (sampleBankId != 0xFF) { - if (gAudioContext.sampleFontLoadStatus[sampleBankId] != LOAD_STATUS_PERMANENTLY_LOADED) { - gAudioContext.sampleFontLoadStatus[sampleBankId] = loadStatus; + if (gAudioCtx.sampleFontLoadStatus[sampleBankId] != LOAD_STATUS_PERMANENTLY_LOADED) { + gAudioCtx.sampleFontLoadStatus[sampleBankId] = loadStatus; } - if ((gAudioContext.sampleFontLoadStatus[sampleBankId] == LOAD_STATUS_PERMANENTLY_LOADED) || - (gAudioContext.sampleFontLoadStatus[sampleBankId] == LOAD_STATUS_COMPLETE)) { + if ((gAudioCtx.sampleFontLoadStatus[sampleBankId] == LOAD_STATUS_PERMANENTLY_LOADED) || + (gAudioCtx.sampleFontLoadStatus[sampleBankId] == LOAD_STATUS_COMPLETE)) { AudioHeap_ApplySampleBankCache(sampleBankId); } } } void AudioLoad_SetSampleFontLoadStatus(s32 sampleBankId, s32 loadStatus) { - if ((sampleBankId != 0xFF) && - (gAudioContext.sampleFontLoadStatus[sampleBankId] != LOAD_STATUS_PERMANENTLY_LOADED)) { - gAudioContext.sampleFontLoadStatus[sampleBankId] = loadStatus; + if ((sampleBankId != 0xFF) && (gAudioCtx.sampleFontLoadStatus[sampleBankId] != LOAD_STATUS_PERMANENTLY_LOADED)) { + gAudioCtx.sampleFontLoadStatus[sampleBankId] = loadStatus; } } @@ -363,16 +356,16 @@ SoundFontData* AudioLoad_SyncLoadSeqFonts(s32 seqId, u32* outDefaultFontId) { s32 fontId; s32 i; - if (seqId >= gAudioContext.numSequences) { + if (seqId >= gAudioCtx.numSequences) { return NULL; } fontId = 0xFF; - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; - numFonts = gAudioContext.sequenceFontTable[index++]; + index = ((u16*)gAudioCtx.sequenceFontTable)[seqId]; + numFonts = gAudioCtx.sequenceFontTable[index++]; while (numFonts > 0) { - fontId = gAudioContext.sequenceFontTable[index++]; + fontId = gAudioCtx.sequenceFontTable[index++]; fontData = AudioLoad_SyncLoadFont(fontId); numFonts--; } @@ -385,7 +378,7 @@ void AudioLoad_SyncLoadSeqParts(s32 seqId, s32 arg1) { s32 pad; u32 defaultFontId; - if (seqId < gAudioContext.numSequences) { + if (seqId < gAudioCtx.numSequences) { if (arg1 & 2) { AudioLoad_SyncLoadSeqFonts(seqId, &defaultFontId); } @@ -408,7 +401,7 @@ s32 AudioLoad_SyncLoadSample(Sample* sample, s32 fontId) { if (sample->medium == MEDIUM_UNK) { AudioLoad_SyncDmaUnkMedium((u32)sample->sampleAddr, sampleAddr, sample->size, - gAudioContext.sampleBankTable->unkMediumParam); + gAudioCtx.sampleBankTable->unkMediumParam); } else { AudioLoad_SyncDma((u32)sample->sampleAddr, sampleAddr, sample->size, sample->medium); } @@ -462,23 +455,23 @@ void AudioLoad_AsyncLoadFont(s32 fontId, s32 arg1, s32 retData, OSMesgQueue* ret } u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) { - s32 index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; + s32 index = ((u16*)gAudioCtx.sequenceFontTable)[seqId]; - *outNumFonts = gAudioContext.sequenceFontTable[index++]; + *outNumFonts = gAudioCtx.sequenceFontTable[index++]; if (*outNumFonts == 0) { return NULL; } - return &gAudioContext.sequenceFontTable[index]; + return &gAudioCtx.sequenceFontTable[index]; } void AudioLoad_DiscardSeqFonts(s32 seqId) { s32 fontId; - s32 index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; - s32 numFonts = gAudioContext.sequenceFontTable[index++]; + s32 index = ((u16*)gAudioCtx.sequenceFontTable)[seqId]; + s32 numFonts = gAudioCtx.sequenceFontTable[index++]; while (numFonts > 0) { numFonts--; - fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.sequenceFontTable[index++]); + fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioCtx.sequenceFontTable[index++]); if (AudioHeap_SearchPermanentCache(FONT_TABLE, fontId) == NULL) { AudioLoad_DiscardFont(fontId); AudioLoad_SetFontLoadStatus(fontId, LOAD_STATUS_NOT_LOADED); @@ -488,7 +481,7 @@ void AudioLoad_DiscardSeqFonts(s32 seqId) { void AudioLoad_DiscardFont(s32 fontId) { u32 i; - AudioCache* pool = &gAudioContext.fontCache; + AudioCache* pool = &gAudioCtx.fontCache; AudioPersistentCache* persistent; if (fontId == pool->temporary.entries[0].id) { @@ -508,11 +501,11 @@ void AudioLoad_DiscardFont(s32 fontId) { } s32 AudioLoad_SyncInitSeqPlayer(s32 playerIdx, s32 seqId, s32 arg2) { - if (gAudioContext.resetTimer != 0) { + if (gAudioCtx.resetTimer != 0) { return 0; } - gAudioContext.seqPlayers[playerIdx].skipTicks = 0; + gAudioCtx.seqPlayers[playerIdx].skipTicks = 0; AudioLoad_SyncInitSeqPlayerInternal(playerIdx, seqId, arg2); // Intentionally missing return. Returning the result of the above function // call matches but is UB because it too is missing a return, and using the @@ -521,34 +514,34 @@ s32 AudioLoad_SyncInitSeqPlayer(s32 playerIdx, s32 seqId, s32 arg2) { } s32 AudioLoad_SyncInitSeqPlayerSkipTicks(s32 playerIdx, s32 seqId, s32 skipTicks) { - if (gAudioContext.resetTimer != 0) { + if (gAudioCtx.resetTimer != 0) { return 0; } - gAudioContext.seqPlayers[playerIdx].skipTicks = skipTicks; + gAudioCtx.seqPlayers[playerIdx].skipTicks = skipTicks; AudioLoad_SyncInitSeqPlayerInternal(playerIdx, seqId, 0); // Missing return, see above. } s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) { - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx]; u8* seqData; s32 index; s32 numFonts; s32 fontId; - if (seqId >= gAudioContext.numSequences) { + if (seqId >= gAudioCtx.numSequences) { return 0; } AudioSeq_SequencePlayerDisable(seqPlayer); fontId = 0xFF; - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; - numFonts = gAudioContext.sequenceFontTable[index++]; + index = ((u16*)gAudioCtx.sequenceFontTable)[seqId]; + numFonts = gAudioCtx.sequenceFontTable[index++]; while (numFonts > 0) { - fontId = gAudioContext.sequenceFontTable[index++]; + fontId = gAudioCtx.sequenceFontTable[index++]; AudioLoad_SyncLoadFont(fontId); numFonts--; } @@ -576,7 +569,7 @@ u8* AudioLoad_SyncLoadSeq(s32 seqId) { s32 pad; s32 didAllocate; - if (gAudioContext.seqLoadStatus[AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId)] == LOAD_STATUS_IN_PROGRESS) { + if (gAudioCtx.seqLoadStatus[AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId)] == LOAD_STATUS_IN_PROGRESS) { return NULL; } @@ -596,7 +589,7 @@ u32 AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad sampleBankTable = AudioLoad_GetLoadTable(SAMPLE_TABLE); ramAddr = AudioLoad_SearchCaches(SAMPLE_TABLE, realTableId); if (ramAddr != NULL) { - if (gAudioContext.sampleFontLoadStatus[realTableId] != LOAD_STATUS_IN_PROGRESS) { + if (gAudioCtx.sampleFontLoadStatus[realTableId] != LOAD_STATUS_IN_PROGRESS) { AudioLoad_SetSampleFontLoadStatus(realTableId, LOAD_STATUS_COMPLETE); } *outMedium = MEDIUM_RAM; @@ -627,11 +620,11 @@ SoundFontData* AudioLoad_SyncLoadFont(u32 fontId) { SampleBankRelocInfo sampleBankReloc; s32 realFontId = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId); - if (gAudioContext.fontLoadStatus[realFontId] == LOAD_STATUS_IN_PROGRESS) { + if (gAudioCtx.fontLoadStatus[realFontId] == LOAD_STATUS_IN_PROGRESS) { return NULL; } - sampleBankId1 = gAudioContext.soundFontList[realFontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFontList[realFontId].sampleBankId2; + sampleBankId1 = gAudioCtx.soundFontList[realFontId].sampleBankId1; + sampleBankId2 = gAudioCtx.soundFontList[realFontId].sampleBankId2; sampleBankReloc.sampleBankId1 = sampleBankId1; sampleBankReloc.sampleBankId2 = sampleBankId2; @@ -773,11 +766,11 @@ AudioTable* AudioLoad_GetLoadTable(s32 tableType) { switch (tableType) { case SEQUENCE_TABLE: - table = gAudioContext.sequenceTable; + table = gAudioCtx.sequenceTable; break; case FONT_TABLE: - table = gAudioContext.soundFontTable; + table = gAudioCtx.soundFontTable; break; default: @@ -785,7 +778,7 @@ AudioTable* AudioLoad_GetLoadTable(s32 tableType) { break; case SAMPLE_TABLE: - table = gAudioContext.sampleBankTable; + table = gAudioCtx.sampleBankTable; break; } return table; @@ -806,9 +799,9 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample Drum* drum; SoundEffect* soundEffect; s32 i; - s32 numDrums = gAudioContext.soundFontList[fontId].numDrums; - s32 numInstruments = gAudioContext.soundFontList[fontId].numInstruments; - s32 numSfx = gAudioContext.soundFontList[fontId].numSfx; + s32 numDrums = gAudioCtx.soundFontList[fontId].numDrums; + s32 numInstruments = gAudioCtx.soundFontList[fontId].numInstruments; + s32 numSfx = gAudioCtx.soundFontList[fontId].numSfx; u32* fontData = (u32*)fontDataStartAddr; // Relocate an offset (relative to the start of the font data) to a pointer (a ram address) @@ -914,14 +907,14 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample #undef FONT_DATA_RELOC // Store the relocated pointers - gAudioContext.soundFontList[fontId].drums = (Drum**)fontData[0]; - gAudioContext.soundFontList[fontId].soundEffects = (SoundEffect*)fontData[1]; - gAudioContext.soundFontList[fontId].instruments = (Instrument**)(fontData + 2); + gAudioCtx.soundFontList[fontId].drums = (Drum**)fontData[0]; + gAudioCtx.soundFontList[fontId].soundEffects = (SoundEffect*)fontData[1]; + gAudioCtx.soundFontList[fontId].instruments = (Instrument**)(fontData + 2); } void AudioLoad_SyncDma(u32 devAddr, u8* ramAddr, u32 size, s32 medium) { - OSMesgQueue* msgQueue = &gAudioContext.syncDmaQueue; - OSIoMesg* ioMesg = &gAudioContext.syncDmaIoMesg; + OSMesgQueue* msgQueue = &gAudioCtx.syncDmaQueue; + OSIoMesg* ioMesg = &gAudioCtx.syncDmaIoMesg; size = ALIGN16(size); Audio_InvalDCache(ramAddr, size); @@ -950,19 +943,19 @@ s32 AudioLoad_Dma(OSIoMesg* mesg, u32 priority, s32 direction, u32 devAddr, void OSMesgQueue* reqQueue, s32 medium, const char* dmaFuncType) { OSPiHandle* handle; - if (gAudioContext.resetTimer > 16) { + if (gAudioCtx.resetTimer > 16) { return -1; } switch (medium) { case MEDIUM_CART: - handle = gAudioContext.cartHandle; + handle = gAudioCtx.cartHandle; break; case MEDIUM_DISK_DRIVE: // driveHandle is uninitialized and corresponds to stubbed-out disk drive support. // SM64 Shindou called osDriveRomInit here. - handle = gAudioContext.driveHandle; + handle = gAudioCtx.driveHandle; break; default: @@ -1005,19 +998,19 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData, switch (tableType) { case SEQUENCE_TABLE: - if (gAudioContext.seqLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) { + if (gAudioCtx.seqLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) { return NULL; } break; case FONT_TABLE: - if (gAudioContext.fontLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) { + if (gAudioCtx.fontLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) { return NULL; } break; case SAMPLE_TABLE: - if (gAudioContext.sampleFontLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) { + if (gAudioCtx.sampleFontLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) { return NULL; } break; @@ -1113,8 +1106,8 @@ void AudioLoad_SetUnusedHandler(void* callback) { } void AudioLoad_InitSoundFont(s32 fontId) { - SoundFont* font = &gAudioContext.soundFontList[fontId]; - AudioTableEntry* entry = &gAudioContext.soundFontTable->entries[fontId]; + SoundFont* font = &gAudioCtx.soundFontList[fontId]; + AudioTableEntry* entry = &gAudioCtx.soundFontTable->entries[fontId]; font->sampleBankId1 = (entry->shortData1 >> 8) & 0xFF; font->sampleBankId2 = (entry->shortData1) & 0xFF; @@ -1130,118 +1123,118 @@ void AudioLoad_Init(void* heap, u32 heapSize) { s32 i; D_801755D0 = NULL; - gAudioContext.resetTimer = 0; + gAudioCtx.resetTimer = 0; { s32 i; - u8* audioContextPtr = (u8*)&gAudioContext; + u8* audioContextPtr = (u8*)&gAudioCtx; - for (i = sizeof(gAudioContext); i >= 0; i--) { + for (i = sizeof(gAudioCtx); i >= 0; i--) { *audioContextPtr++ = 0; } } switch (osTvType) { case OS_TV_PAL: - gAudioContext.unk_2960 = 20.03042f; - gAudioContext.refreshRate = 50; + gAudioCtx.unk_2960 = 20.03042f; + gAudioCtx.refreshRate = 50; break; case OS_TV_MPAL: - gAudioContext.unk_2960 = 16.546f; - gAudioContext.refreshRate = 60; + gAudioCtx.unk_2960 = 16.546f; + gAudioCtx.refreshRate = 60; break; case OS_TV_NTSC: default: - gAudioContext.unk_2960 = 16.713f; - gAudioContext.refreshRate = 60; + gAudioCtx.unk_2960 = 16.713f; + gAudioCtx.refreshRate = 60; break; } Audio_InitMesgQueues(); for (i = 0; i < 3; i++) { - gAudioContext.aiBufLengths[i] = 0xA0; + gAudioCtx.aiBufLengths[i] = 0xA0; } - gAudioContext.totalTaskCount = 0; - gAudioContext.rspTaskIndex = 0; - gAudioContext.curAiBufIndex = 0; - gAudioContext.soundMode = SOUNDMODE_STEREO; - gAudioContext.curTask = NULL; - gAudioContext.rspTask[0].task.t.data_size = 0; - gAudioContext.rspTask[1].task.t.data_size = 0; - osCreateMesgQueue(&gAudioContext.syncDmaQueue, &gAudioContext.syncDmaMesg, 1); - osCreateMesgQueue(&gAudioContext.currAudioFrameDmaQueue, gAudioContext.currAudioFrameDmaMsgBuf, - ARRAY_COUNT(gAudioContext.currAudioFrameDmaMsgBuf)); - osCreateMesgQueue(&gAudioContext.externalLoadQueue, gAudioContext.externalLoadMsgBuf, - ARRAY_COUNT(gAudioContext.externalLoadMsgBuf)); - osCreateMesgQueue(&gAudioContext.preloadSampleQueue, gAudioContext.preloadSampleMsgBuf, - ARRAY_COUNT(gAudioContext.preloadSampleMsgBuf)); - gAudioContext.curAudioFrameDmaCount = 0; - gAudioContext.sampleDmaCount = 0; - gAudioContext.cartHandle = osCartRomInit(); + gAudioCtx.totalTaskCount = 0; + gAudioCtx.rspTaskIndex = 0; + gAudioCtx.curAiBufIndex = 0; + gAudioCtx.soundMode = SOUNDMODE_STEREO; + gAudioCtx.curTask = NULL; + gAudioCtx.rspTask[0].task.t.data_size = 0; + gAudioCtx.rspTask[1].task.t.data_size = 0; + osCreateMesgQueue(&gAudioCtx.syncDmaQueue, &gAudioCtx.syncDmaMesg, 1); + osCreateMesgQueue(&gAudioCtx.currAudioFrameDmaQueue, gAudioCtx.currAudioFrameDmaMsgBuf, + ARRAY_COUNT(gAudioCtx.currAudioFrameDmaMsgBuf)); + osCreateMesgQueue(&gAudioCtx.externalLoadQueue, gAudioCtx.externalLoadMsgBuf, + ARRAY_COUNT(gAudioCtx.externalLoadMsgBuf)); + osCreateMesgQueue(&gAudioCtx.preloadSampleQueue, gAudioCtx.preloadSampleMsgBuf, + ARRAY_COUNT(gAudioCtx.preloadSampleMsgBuf)); + gAudioCtx.curAudioFrameDmaCount = 0; + gAudioCtx.sampleDmaCount = 0; + gAudioCtx.cartHandle = osCartRomInit(); if (heap == NULL) { - gAudioContext.audioHeap = gAudioHeap; - gAudioContext.audioHeapSize = gAudioHeapInitSizes.heapSize; + gAudioCtx.audioHeap = gAudioHeap; + gAudioCtx.audioHeapSize = gAudioHeapInitSizes.heapSize; } else { void** hp = &heap; - gAudioContext.audioHeap = *hp; - gAudioContext.audioHeapSize = heapSize; + gAudioCtx.audioHeap = *hp; + gAudioCtx.audioHeapSize = heapSize; } - for (i = 0; i < (s32)gAudioContext.audioHeapSize / 8; i++) { - ((u64*)gAudioContext.audioHeap)[i] = 0; + for (i = 0; i < (s32)gAudioCtx.audioHeapSize / 8; i++) { + ((u64*)gAudioCtx.audioHeap)[i] = 0; } // Main Pool Split (split entirety of audio heap into initPool and sessionPool) AudioHeap_InitMainPools(gAudioHeapInitSizes.initPoolSize); // Initialize the audio interface buffers - for (i = 0; i < ARRAY_COUNT(gAudioContext.aiBuffers); i++) { - gAudioContext.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioContext.initPool, AIBUF_SIZE); + for (i = 0; i < ARRAY_COUNT(gAudioCtx.aiBuffers); i++) { + gAudioCtx.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioCtx.initPool, AIBUF_SIZE); } // Set audio tables pointers - gAudioContext.sequenceTable = (AudioTable*)gSequenceTable; - gAudioContext.soundFontTable = (AudioTable*)gSoundFontTable; - gAudioContext.sampleBankTable = (AudioTable*)gSampleBankTable; - gAudioContext.sequenceFontTable = gSequenceFontTable; + gAudioCtx.sequenceTable = (AudioTable*)gSequenceTable; + gAudioCtx.soundFontTable = (AudioTable*)gSoundFontTable; + gAudioCtx.sampleBankTable = (AudioTable*)gSampleBankTable; + gAudioCtx.sequenceFontTable = gSequenceFontTable; - gAudioContext.numSequences = gAudioContext.sequenceTable->numEntries; + gAudioCtx.numSequences = gAudioCtx.sequenceTable->numEntries; - gAudioContext.audioResetSpecIdToLoad = 0; - gAudioContext.resetStatus = 1; // Set reset to immediately initialize the audio heap + gAudioCtx.audioResetSpecIdToLoad = 0; + gAudioCtx.resetStatus = 1; // Set reset to immediately initialize the audio heap AudioHeap_ResetStep(); // Initialize audio tables - AudioLoad_InitTable(gAudioContext.sequenceTable, (u32)_AudioseqSegmentRomStart, 0); - AudioLoad_InitTable(gAudioContext.soundFontTable, (u32)_AudiobankSegmentRomStart, 0); - AudioLoad_InitTable(gAudioContext.sampleBankTable, (u32)_AudiotableSegmentRomStart, 0); - numFonts = gAudioContext.soundFontTable->numEntries; - gAudioContext.soundFontList = AudioHeap_Alloc(&gAudioContext.initPool, numFonts * sizeof(SoundFont)); + AudioLoad_InitTable(gAudioCtx.sequenceTable, (u32)_AudioseqSegmentRomStart, 0); + AudioLoad_InitTable(gAudioCtx.soundFontTable, (u32)_AudiobankSegmentRomStart, 0); + AudioLoad_InitTable(gAudioCtx.sampleBankTable, (u32)_AudiotableSegmentRomStart, 0); + numFonts = gAudioCtx.soundFontTable->numEntries; + gAudioCtx.soundFontList = AudioHeap_Alloc(&gAudioCtx.initPool, numFonts * sizeof(SoundFont)); for (i = 0; i < numFonts; i++) { AudioLoad_InitSoundFont(i); } - ramAddr = AudioHeap_Alloc(&gAudioContext.initPool, gAudioHeapInitSizes.permanentPoolSize); + ramAddr = AudioHeap_Alloc(&gAudioCtx.initPool, gAudioHeapInitSizes.permanentPoolSize); if (ramAddr == NULL) { // cast away const from gAudioHeapInitSizes *((u32*)&gAudioHeapInitSizes.permanentPoolSize) = 0; } - AudioHeap_InitPool(&gAudioContext.permanentPool, ramAddr, gAudioHeapInitSizes.permanentPoolSize); + AudioHeap_InitPool(&gAudioCtx.permanentPool, ramAddr, gAudioHeapInitSizes.permanentPoolSize); gAudioContextInitialized = true; - osSendMesg(gAudioContext.taskStartQueueP, (OSMesg)gAudioContext.totalTaskCount, OS_MESG_NOBLOCK); + osSendMesg(gAudioCtx.taskStartQueueP, (OSMesg)gAudioCtx.totalTaskCount, OS_MESG_NOBLOCK); } void AudioLoad_InitSlowLoads(void) { - gAudioContext.slowLoads[0].state = SLOW_LOAD_STATE_WAITING; - gAudioContext.slowLoads[1].state = SLOW_LOAD_STATE_WAITING; + gAudioCtx.slowLoads[0].state = SLOW_LOAD_STATE_WAITING; + gAudioCtx.slowLoads[1].state = SLOW_LOAD_STATE_WAITING; } s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* status) { @@ -1259,7 +1252,7 @@ s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* status) { return 0; } - slowLoad = &gAudioContext.slowLoads[gAudioContext.slowLoadPos]; + slowLoad = &gAudioCtx.slowLoads[gAudioCtx.slowLoadPos]; if (slowLoad->state == SLOW_LOAD_STATE_DONE) { slowLoad->state = SLOW_LOAD_STATE_WAITING; } @@ -1287,10 +1280,10 @@ s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* status) { slowLoad->seqOrFontId = fontId; slowLoad->instId = instId; if (slowLoad->medium == MEDIUM_UNK) { - slowLoad->unkMediumParam = gAudioContext.sampleBankTable->unkMediumParam; + slowLoad->unkMediumParam = gAudioCtx.sampleBankTable->unkMediumParam; } - gAudioContext.slowLoadPos ^= 1; + gAudioCtx.slowLoadPos ^= 1; return 0; } @@ -1346,9 +1339,9 @@ void AudioLoad_ProcessSlowLoads(s32 resetStatus) { AudioSlowLoad* slowLoad; s32 i; - for (i = 0; i < ARRAY_COUNT(gAudioContext.slowLoads); i++) { - slowLoad = &gAudioContext.slowLoads[i]; - switch (gAudioContext.slowLoads[i].state) { + for (i = 0; i < ARRAY_COUNT(gAudioCtx.slowLoads); i++) { + slowLoad = &gAudioCtx.slowLoads[i]; + switch (gAudioCtx.slowLoads[i].state) { case SLOW_LOAD_STATE_LOADING: if (slowLoad->medium != MEDIUM_UNK) { osRecvMesg(&slowLoad->msgQueue, NULL, OS_MESG_BLOCK); @@ -1406,14 +1399,14 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* status) { AudioTable* seqTable; u32 size; - if (seqId >= gAudioContext.numSequences) { + if (seqId >= gAudioCtx.numSequences) { *status = 0; return -1; } seqId = AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId); seqTable = AudioLoad_GetLoadTable(SEQUENCE_TABLE); - slowLoad = &gAudioContext.slowLoads[gAudioContext.slowLoadPos]; + slowLoad = &gAudioCtx.slowLoads[gAudioCtx.slowLoadPos]; if (slowLoad->state == SLOW_LOAD_STATE_DONE) { slowLoad->state = SLOW_LOAD_STATE_WAITING; } @@ -1434,15 +1427,15 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* status) { slowLoad->unkMediumParam = seqTable->unkMediumParam; } - gAudioContext.slowLoadPos ^= 1; + gAudioCtx.slowLoadPos ^= 1; return 0; } void AudioLoad_InitAsyncLoads(void) { s32 i; - for (i = 0; i < ARRAY_COUNT(gAudioContext.asyncLoads); i++) { - gAudioContext.asyncLoads[i].status = 0; + for (i = 0; i < ARRAY_COUNT(gAudioCtx.asyncLoads); i++) { + gAudioCtx.asyncLoads[i].status = 0; } } @@ -1456,7 +1449,7 @@ AudioAsyncLoad* AudioLoad_StartAsyncLoadUnkMedium(s32 unkMediumParam, u32 devAdd return NULL; } - osSendMesg(&gAudioContext.asyncLoadUnkMediumQueue, (OSMesg)asyncLoad, OS_MESG_NOBLOCK); + osSendMesg(&gAudioCtx.asyncLoadUnkMediumQueue, (OSMesg)asyncLoad, OS_MESG_NOBLOCK); asyncLoad->unkMediumParam = unkMediumParam; return asyncLoad; } @@ -1466,15 +1459,15 @@ AudioAsyncLoad* AudioLoad_StartAsyncLoad(u32 devAddr, void* ramAddr, u32 size, s AudioAsyncLoad* asyncLoad; s32 i; - for (i = 0; i < ARRAY_COUNT(gAudioContext.asyncLoads); i++) { - if (gAudioContext.asyncLoads[i].status == 0) { - asyncLoad = &gAudioContext.asyncLoads[i]; + for (i = 0; i < ARRAY_COUNT(gAudioCtx.asyncLoads); i++) { + if (gAudioCtx.asyncLoads[i].status == 0) { + asyncLoad = &gAudioCtx.asyncLoads[i]; break; } } // no more available async loads - if (i == ARRAY_COUNT(gAudioContext.asyncLoads)) { + if (i == ARRAY_COUNT(gAudioCtx.asyncLoads)) { return NULL; } @@ -1507,29 +1500,29 @@ void AudioLoad_ProcessAsyncLoads(s32 resetStatus) { AudioAsyncLoad* asyncLoad; s32 i; - if (gAudioContext.resetTimer == 1) { + if (gAudioCtx.resetTimer == 1) { return; } - if (gAudioContext.curUnkMediumLoad == NULL) { + if (gAudioCtx.curUnkMediumLoad == NULL) { if (resetStatus != 0) { // Clear and ignore queue if resetting. do { - } while (osRecvMesg(&gAudioContext.asyncLoadUnkMediumQueue, (OSMesg*)&asyncLoad, OS_MESG_NOBLOCK) != -1); - } else if (osRecvMesg(&gAudioContext.asyncLoadUnkMediumQueue, (OSMesg*)&asyncLoad, OS_MESG_NOBLOCK) == -1) { - gAudioContext.curUnkMediumLoad = NULL; + } while (osRecvMesg(&gAudioCtx.asyncLoadUnkMediumQueue, (OSMesg*)&asyncLoad, OS_MESG_NOBLOCK) != -1); + } else if (osRecvMesg(&gAudioCtx.asyncLoadUnkMediumQueue, (OSMesg*)&asyncLoad, OS_MESG_NOBLOCK) == -1) { + gAudioCtx.curUnkMediumLoad = NULL; } else { - gAudioContext.curUnkMediumLoad = asyncLoad; + gAudioCtx.curUnkMediumLoad = asyncLoad; } } - if (gAudioContext.curUnkMediumLoad != NULL) { - AudioLoad_ProcessAsyncLoadUnkMedium(gAudioContext.curUnkMediumLoad, resetStatus); + if (gAudioCtx.curUnkMediumLoad != NULL) { + AudioLoad_ProcessAsyncLoadUnkMedium(gAudioCtx.curUnkMediumLoad, resetStatus); } - for (i = 0; i < ARRAY_COUNT(gAudioContext.asyncLoads); i++) { - if (gAudioContext.asyncLoads[i].status == 1) { - asyncLoad = &gAudioContext.asyncLoads[i]; + for (i = 0; i < ARRAY_COUNT(gAudioCtx.asyncLoads); i++) { + if (gAudioCtx.asyncLoads[i].status == 1) { + asyncLoad = &gAudioCtx.asyncLoads[i]; if (asyncLoad->medium != MEDIUM_UNK) { AudioLoad_ProcessAsyncLoad(asyncLoad, resetStatus); } @@ -1561,8 +1554,8 @@ void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) { case FONT_TABLE: fontId = ASYNC_ID(retMsg); - sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1; + sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2; sampleBankReloc.sampleBankId1 = sampleBankId1; sampleBankReloc.sampleBankId2 = sampleBankId2; sampleBankReloc.baseAddr1 = @@ -1581,7 +1574,7 @@ void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) { } void AudioLoad_ProcessAsyncLoad(AudioAsyncLoad* asyncLoad, s32 resetStatus) { - AudioTable* sampleBankTable = gAudioContext.sampleBankTable; + AudioTable* sampleBankTable = gAudioCtx.sampleBankTable; if (asyncLoad->delay >= 2) { asyncLoad->delay--; @@ -1692,7 +1685,7 @@ void AudioLoad_RelocateSample(TunedSample* tunedSample, SoundFontData* fontData, sample->isRelocated = true; if (sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) { - gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; + gAudioCtx.usedSamples[gAudioCtx.numUsedSamples++] = sample; } } } @@ -1718,27 +1711,27 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData s32 i; preloadInProgress = false; - if (gAudioContext.preloadSampleStackTop != 0) { + if (gAudioCtx.preloadSampleStackTop != 0) { preloadInProgress = true; } else { D_8016B780 = 0; } - gAudioContext.numUsedSamples = 0; + gAudioCtx.numUsedSamples = 0; AudioLoad_RelocateFont(fontId, fontData, sampleBankReloc); size = 0; - for (i = 0; i < gAudioContext.numUsedSamples; i++) { - size += ALIGN16(gAudioContext.usedSamples[i]->size); + for (i = 0; i < gAudioCtx.numUsedSamples; i++) { + size += ALIGN16(gAudioCtx.usedSamples[i]->size); } if (size && size) {} - for (i = 0; i < gAudioContext.numUsedSamples; i++) { - if (gAudioContext.preloadSampleStackTop == 120) { + for (i = 0; i < gAudioCtx.numUsedSamples; i++) { + if (gAudioCtx.preloadSampleStackTop == 120) { break; } - sample = gAudioContext.usedSamples[i]; + sample = gAudioCtx.usedSamples[i]; sampleRamAddr = NULL; switch (isAsync) { case false: @@ -1775,7 +1768,7 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData case false: if (sample->medium == MEDIUM_UNK) { AudioLoad_SyncDmaUnkMedium((u32)sample->sampleAddr, sampleRamAddr, sample->size, - gAudioContext.sampleBankTable->unkMediumParam); + gAudioCtx.sampleBankTable->unkMediumParam); sample->sampleAddr = sampleRamAddr; sample->medium = MEDIUM_RAM; } else { @@ -1787,24 +1780,24 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData break; case true: - preload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop]; + preload = &gAudioCtx.preloadSampleStack[gAudioCtx.preloadSampleStackTop]; preload->sample = sample; preload->ramAddr = sampleRamAddr; - preload->encodedInfo = (gAudioContext.preloadSampleStackTop << 24) | 0xFFFFFF; + preload->encodedInfo = (gAudioCtx.preloadSampleStackTop << 24) | 0xFFFFFF; preload->isFree = false; preload->endAndMediumKey = (u32)sample->sampleAddr + sample->size + sample->medium; - gAudioContext.preloadSampleStackTop++; + gAudioCtx.preloadSampleStackTop++; break; } } - gAudioContext.numUsedSamples = 0; + gAudioCtx.numUsedSamples = 0; - if (gAudioContext.preloadSampleStackTop != 0 && !preloadInProgress) { - topPreload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop - 1]; + if (gAudioCtx.preloadSampleStackTop != 0 && !preloadInProgress) { + topPreload = &gAudioCtx.preloadSampleStack[gAudioCtx.preloadSampleStackTop - 1]; sample = topPreload->sample; nChunks = (sample->size >> 12) + 1; AudioLoad_StartAsyncLoad((u32)sample->sampleAddr, topPreload->ramAddr, sample->size, sample->medium, nChunks, - &gAudioContext.preloadSampleQueue, topPreload->encodedInfo); + &gAudioCtx.preloadSampleQueue, topPreload->encodedInfo); } } @@ -1816,20 +1809,20 @@ s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) { u32 nChunks; s32 pad; - if (gAudioContext.preloadSampleStackTop > 0) { + if (gAudioCtx.preloadSampleStackTop > 0) { if (resetStatus != 0) { // Clear result queue and preload stack and return. - osRecvMesg(&gAudioContext.preloadSampleQueue, (OSMesg*)&preloadIndex, OS_MESG_NOBLOCK); - gAudioContext.preloadSampleStackTop = 0; + osRecvMesg(&gAudioCtx.preloadSampleQueue, (OSMesg*)&preloadIndex, OS_MESG_NOBLOCK); + gAudioCtx.preloadSampleStackTop = 0; return false; } - if (osRecvMesg(&gAudioContext.preloadSampleQueue, (OSMesg*)&preloadIndex, OS_MESG_NOBLOCK) == -1) { + if (osRecvMesg(&gAudioCtx.preloadSampleQueue, (OSMesg*)&preloadIndex, OS_MESG_NOBLOCK) == -1) { // Previous preload is not done yet. return false; } preloadIndex >>= 24; - preload = &gAudioContext.preloadSampleStack[preloadIndex]; + preload = &gAudioCtx.preloadSampleStack[preloadIndex]; if (preload->isFree == false) { sample = preload->sample; @@ -1845,12 +1838,12 @@ s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) { // Pop requests with isFree = true off the stack, as far as possible, // and dispatch the next DMA. while (true) { - if (gAudioContext.preloadSampleStackTop <= 0) { + if (gAudioCtx.preloadSampleStackTop <= 0) { break; } - preload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop - 1]; + preload = &gAudioCtx.preloadSampleStack[gAudioCtx.preloadSampleStackTop - 1]; if (preload->isFree == true) { - gAudioContext.preloadSampleStackTop--; + gAudioCtx.preloadSampleStackTop--; continue; } @@ -1859,10 +1852,10 @@ s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) { key = (u32)sample->sampleAddr + sample->size + sample->medium; if (key != preload->endAndMediumKey) { preload->isFree = true; - gAudioContext.preloadSampleStackTop--; + gAudioCtx.preloadSampleStackTop--; } else { AudioLoad_StartAsyncLoad((u32)sample->sampleAddr, preload->ramAddr, sample->size, sample->medium, - nChunks, &gAudioContext.preloadSampleQueue, preload->encodedInfo); + nChunks, &gAudioCtx.preloadSampleQueue, preload->encodedInfo); break; } } @@ -1890,8 +1883,8 @@ s32 AudioLoad_AddToSampleSet(Sample* sample, s32 numSamples, Sample** sampleSet) s32 AudioLoad_GetSamplesForFont(s32 fontId, Sample** sampleSet) { s32 i; s32 numSamples = 0; - s32 numDrums = gAudioContext.soundFontList[fontId].numDrums; - s32 numInstruments = gAudioContext.soundFontList[fontId].numInstruments; + s32 numDrums = gAudioCtx.soundFontList[fontId].numDrums; + s32 numInstruments = gAudioCtx.soundFontList[fontId].numInstruments; for (i = 0; i < numDrums; i++) { Drum* drum = Audio_GetDrum(fontId, i); @@ -1924,7 +1917,7 @@ void AudioLoad_AddUsedSample(TunedSample* tunedSample) { Sample* sample = tunedSample->sample; if ((sample->size != 0) && sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) { - gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; + gAudioCtx.usedSamples[gAudioCtx.numUsedSamples++] = sample; } } @@ -1945,15 +1938,15 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, SampleBankRelocInfo* s32 nChunks; preloadInProgress = false; - if (gAudioContext.preloadSampleStackTop != 0) { + if (gAudioCtx.preloadSampleStackTop != 0) { preloadInProgress = true; } - gAudioContext.numUsedSamples = 0; + gAudioCtx.numUsedSamples = 0; - numDrums = gAudioContext.soundFontList[fontId].numDrums; - numInstruments = gAudioContext.soundFontList[fontId].numInstruments; - numSfx = gAudioContext.soundFontList[fontId].numSfx; + numDrums = gAudioCtx.soundFontList[fontId].numDrums; + numInstruments = gAudioCtx.soundFontList[fontId].numInstruments; + numSfx = gAudioCtx.soundFontList[fontId].numSfx; for (i = 0; i < numInstruments; i++) { instrument = Audio_GetInstrumentInner(fontId, i); @@ -1982,22 +1975,22 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, SampleBankRelocInfo* } } - if (gAudioContext.numUsedSamples == 0) { + if (gAudioCtx.numUsedSamples == 0) { return; } size = 0; - for (i = 0; i < gAudioContext.numUsedSamples; i++) { - size += ALIGN16(gAudioContext.usedSamples[i]->size); + for (i = 0; i < gAudioCtx.numUsedSamples; i++) { + size += ALIGN16(gAudioCtx.usedSamples[i]->size); } if (size) {} - for (i = 0; i < gAudioContext.numUsedSamples; i++) { - if (gAudioContext.preloadSampleStackTop == 120) { + for (i = 0; i < gAudioCtx.numUsedSamples; i++) { + if (gAudioCtx.preloadSampleStackTop == 120) { break; } - sample = gAudioContext.usedSamples[i]; + sample = gAudioCtx.usedSamples[i]; if (sample->medium == MEDIUM_RAM) { continue; } @@ -2031,7 +2024,7 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, SampleBankRelocInfo* case false: if (sample->medium == MEDIUM_UNK) { AudioLoad_SyncDmaUnkMedium((u32)sample->sampleAddr, addr, sample->size, - gAudioContext.sampleBankTable->unkMediumParam); + gAudioCtx.sampleBankTable->unkMediumParam); sample->sampleAddr = addr; sample->medium = MEDIUM_RAM; } else { @@ -2042,24 +2035,24 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, SampleBankRelocInfo* break; case true: - preload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop]; + preload = &gAudioCtx.preloadSampleStack[gAudioCtx.preloadSampleStackTop]; preload->sample = sample; preload->ramAddr = addr; - preload->encodedInfo = (gAudioContext.preloadSampleStackTop << 24) | 0xFFFFFF; + preload->encodedInfo = (gAudioCtx.preloadSampleStackTop << 24) | 0xFFFFFF; preload->isFree = false; preload->endAndMediumKey = (u32)sample->sampleAddr + sample->size + sample->medium; - gAudioContext.preloadSampleStackTop++; + gAudioCtx.preloadSampleStackTop++; break; } } - gAudioContext.numUsedSamples = 0; + gAudioCtx.numUsedSamples = 0; - if (gAudioContext.preloadSampleStackTop != 0 && !preloadInProgress) { - topPreload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop - 1]; + if (gAudioCtx.preloadSampleStackTop != 0 && !preloadInProgress) { + topPreload = &gAudioCtx.preloadSampleStack[gAudioCtx.preloadSampleStackTop - 1]; sample = topPreload->sample; nChunks = (sample->size >> 12) + 1; AudioLoad_StartAsyncLoad((u32)sample->sampleAddr, topPreload->ramAddr, sample->size, sample->medium, nChunks, - &gAudioContext.preloadSampleQueue, topPreload->encodedInfo); + &gAudioCtx.preloadSampleQueue, topPreload->encodedInfo); } } @@ -2071,13 +2064,13 @@ void AudioLoad_LoadPermanentSamples(void) { s32 i; sampleBankTable = AudioLoad_GetLoadTable(SAMPLE_TABLE); - for (i = 0; i < gAudioContext.permanentPool.numEntries; i++) { + for (i = 0; i < gAudioCtx.permanentPool.numEntries; i++) { SampleBankRelocInfo sampleBankReloc; - if (gAudioContext.permanentCache[i].tableType == FONT_TABLE) { - fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.permanentCache[i].id); - sampleBankReloc.sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; - sampleBankReloc.sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + if (gAudioCtx.permanentCache[i].tableType == FONT_TABLE) { + fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioCtx.permanentCache[i].id); + sampleBankReloc.sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1; + sampleBankReloc.sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2; if (sampleBankReloc.sampleBankId1 != 0xFF) { sampleBankReloc.sampleBankId1 = diff --git a/src/code/audio_playback.c b/src/code/audio_playback.c index 87ad945a65..87e2f792c2 100644 --- a/src/code/audio_playback.c +++ b/src/code/audio_playback.c @@ -31,7 +31,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) { sub->bitField0.stereoStrongLeft = false; sub->bitField0.stereoHeadsetEffects = stereoData.stereoHeadsetEffects; sub->bitField0.usesHeadsetPanEffects = stereoData.usesHeadsetPanEffects; - if (stereoHeadsetEffects && (gAudioContext.soundMode == SOUNDMODE_HEADSET)) { + if (stereoHeadsetEffects && (gAudioCtx.soundMode == SOUNDMODE_HEADSET)) { halfPanIndex = pan >> 1; if (halfPanIndex > 0x3F) { halfPanIndex = 0x3F; @@ -43,7 +43,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) { volLeft = gHeadsetPanVolume[pan]; volRight = gHeadsetPanVolume[0x7F - pan]; - } else if (stereoHeadsetEffects && (gAudioContext.soundMode == SOUNDMODE_STEREO)) { + } else if (stereoHeadsetEffects && (gAudioCtx.soundMode == SOUNDMODE_STEREO)) { strongLeft = strongRight = 0; sub->haasEffectLeftDelaySize = 0; sub->haasEffectRightDelaySize = 0; @@ -80,7 +80,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) { break; } - } else if (gAudioContext.soundMode == SOUNDMODE_MONO) { + } else if (gAudioCtx.soundMode == SOUNDMODE_MONO) { sub->bitField0.stereoHeadsetEffects = false; sub->bitField0.usesHeadsetPanEffects = false; volLeft = 0.707f; // approx 1/sqrt(2) @@ -163,9 +163,9 @@ void Audio_ProcessNotes(void) { f32 scale; s32 i; - for (i = 0; i < gAudioContext.numNotes; i++) { - note = &gAudioContext.notes[i]; - noteSubEu2 = &gAudioContext.noteSubsEu[gAudioContext.noteSubEuOffset + i]; + for (i = 0; i < gAudioCtx.numNotes; i++) { + note = &gAudioCtx.notes[i]; + noteSubEu2 = &gAudioCtx.noteSubsEu[gAudioCtx.noteSubEuOffset + i]; playbackState = ¬e->playbackState; if (playbackState->parentLayer != NO_LAYER) { if ((u32)playbackState->parentLayer < 0x7FFFFFFF) { @@ -174,7 +174,7 @@ void Audio_ProcessNotes(void) { if (note != playbackState->parentLayer->note && playbackState->unk_04 == 0) { playbackState->adsr.action.s.release = true; - playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv; playbackState->priority = 1; playbackState->unk_04 = 2; goto out; @@ -285,7 +285,7 @@ void Audio_ProcessNotes(void) { } subAttrs.frequency *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale; - subAttrs.frequency *= gAudioContext.audioBufferParameters.resampleRate; + subAttrs.frequency *= gAudioCtx.audioBufferParameters.resampleRate; subAttrs.velocity *= scale; Audio_InitNoteSub(note, noteSubEu2, &subAttrs); noteSubEu->bitField1.bookOffset = bookOffset; @@ -315,18 +315,18 @@ Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) { } if (!AudioLoad_IsFontLoadComplete(fontId)) { - gAudioContext.audioErrorFlags = fontId + 0x10000000; + gAudioCtx.audioErrorFlags = fontId + 0x10000000; return NULL; } - if (instId >= gAudioContext.soundFontList[fontId].numInstruments) { - gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000; + if (instId >= gAudioCtx.soundFontList[fontId].numInstruments) { + gAudioCtx.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000; return NULL; } - inst = gAudioContext.soundFontList[fontId].instruments[instId]; + inst = gAudioCtx.soundFontList[fontId].instruments[instId]; if (inst == NULL) { - gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000; + gAudioCtx.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000; return inst; } @@ -341,21 +341,21 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) { } if (!AudioLoad_IsFontLoadComplete(fontId)) { - gAudioContext.audioErrorFlags = fontId + 0x10000000; + gAudioCtx.audioErrorFlags = fontId + 0x10000000; return NULL; } - if (drumId >= gAudioContext.soundFontList[fontId].numDrums) { - gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000; + if (drumId >= gAudioCtx.soundFontList[fontId].numDrums) { + gAudioCtx.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000; return NULL; } - if ((u32)gAudioContext.soundFontList[fontId].drums < AUDIO_RELOCATED_ADDRESS_START) { + if ((u32)gAudioCtx.soundFontList[fontId].drums < AUDIO_RELOCATED_ADDRESS_START) { return NULL; } - drum = gAudioContext.soundFontList[fontId].drums[drumId]; + drum = gAudioCtx.soundFontList[fontId].drums[drumId]; if (drum == NULL) { - gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000; + gAudioCtx.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000; } return drum; @@ -369,23 +369,23 @@ SoundEffect* Audio_GetSoundEffect(s32 fontId, s32 sfxId) { } if (!AudioLoad_IsFontLoadComplete(fontId)) { - gAudioContext.audioErrorFlags = fontId + 0x10000000; + gAudioCtx.audioErrorFlags = fontId + 0x10000000; return NULL; } - if (sfxId >= gAudioContext.soundFontList[fontId].numSfx) { - gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000; + if (sfxId >= gAudioCtx.soundFontList[fontId].numSfx) { + gAudioCtx.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000; return NULL; } - if ((u32)gAudioContext.soundFontList[fontId].soundEffects < AUDIO_RELOCATED_ADDRESS_START) { + if ((u32)gAudioCtx.soundFontList[fontId].soundEffects < AUDIO_RELOCATED_ADDRESS_START) { return NULL; } - soundEffect = &gAudioContext.soundFontList[fontId].soundEffects[sfxId]; + soundEffect = &gAudioCtx.soundFontList[fontId].soundEffects[sfxId]; if (soundEffect == NULL) { - gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000; + gAudioCtx.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000; } if (soundEffect->tunedSample.sample == NULL) { @@ -406,24 +406,24 @@ s32 Audio_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* val switch (instrumentType) { case 0: - if (index >= gAudioContext.soundFontList[fontId].numDrums) { + if (index >= gAudioCtx.soundFontList[fontId].numDrums) { return -3; } - gAudioContext.soundFontList[fontId].drums[index] = value; + gAudioCtx.soundFontList[fontId].drums[index] = value; break; case 1: - if (index >= gAudioContext.soundFontList[fontId].numSfx) { + if (index >= gAudioCtx.soundFontList[fontId].numSfx) { return -3; } - gAudioContext.soundFontList[fontId].soundEffects[index] = *(SoundEffect*)value; + gAudioCtx.soundFontList[fontId].soundEffects[index] = *(SoundEffect*)value; break; default: - if (index >= gAudioContext.soundFontList[fontId].numInstruments) { + if (index >= gAudioCtx.soundFontList[fontId].numInstruments) { return -3; } - gAudioContext.soundFontList[fontId].instruments[index] = value; + gAudioCtx.soundFontList[fontId].instruments[index] = value; break; } @@ -456,7 +456,7 @@ void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) { if (note->playbackState.parentLayer != layer) { if (note->playbackState.parentLayer == NO_LAYER && note->playbackState.wantedParentLayer == NO_LAYER && note->playbackState.prevParentLayer == layer && target != ADSR_STATE_DECAY) { - note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.action.s.release = true; } return; @@ -500,16 +500,16 @@ void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) { note->playbackState.prevParentLayer = note->playbackState.parentLayer; note->playbackState.parentLayer = NO_LAYER; if (target == ADSR_STATE_RELEASE) { - note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.action.s.release = true; note->playbackState.unk_04 = 2; } else { note->playbackState.unk_04 = 1; note->playbackState.adsr.action.s.decay = true; if (layer->adsr.decayIndex == 0) { - note->playbackState.adsr.fadeOutVel = gAudioContext.adsrDecayTable[layer->channel->adsr.decayIndex]; + note->playbackState.adsr.fadeOutVel = gAudioCtx.adsrDecayTable[layer->channel->adsr.decayIndex]; } else { - note->playbackState.adsr.fadeOutVel = gAudioContext.adsrDecayTable[layer->adsr.decayIndex]; + note->playbackState.adsr.fadeOutVel = gAudioCtx.adsrDecayTable[layer->adsr.decayIndex]; } note->playbackState.adsr.sustain = ((f32)(s32)(layer->channel->adsr.sustain) * note->playbackState.adsr.current) / 256.0f; @@ -616,11 +616,11 @@ void Audio_InitNoteLists(NotePool* pool) { void Audio_InitNoteFreeList(void) { s32 i; - Audio_InitNoteLists(&gAudioContext.noteFreeLists); - for (i = 0; i < gAudioContext.numNotes; i++) { - gAudioContext.notes[i].listItem.u.value = &gAudioContext.notes[i]; - gAudioContext.notes[i].listItem.prev = NULL; - AudioSeq_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, &gAudioContext.notes[i].listItem); + Audio_InitNoteLists(&gAudioCtx.noteFreeLists); + for (i = 0; i < gAudioCtx.numNotes; i++) { + gAudioCtx.notes[i].listItem.u.value = &gAudioCtx.notes[i]; + gAudioCtx.notes[i].listItem.prev = NULL; + AudioSeq_AudioListPushBack(&gAudioCtx.noteFreeLists.disabled, &gAudioCtx.notes[i].listItem); } } @@ -634,22 +634,22 @@ void Audio_NotePoolClear(NotePool* pool) { switch (i) { case 0: source = &pool->disabled; - dest = &gAudioContext.noteFreeLists.disabled; + dest = &gAudioCtx.noteFreeLists.disabled; break; case 1: source = &pool->decaying; - dest = &gAudioContext.noteFreeLists.decaying; + dest = &gAudioCtx.noteFreeLists.decaying; break; case 2: source = &pool->releasing; - dest = &gAudioContext.noteFreeLists.releasing; + dest = &gAudioCtx.noteFreeLists.releasing; break; case 3: source = &pool->active; - dest = &gAudioContext.noteFreeLists.active; + dest = &gAudioCtx.noteFreeLists.active; break; } @@ -680,22 +680,22 @@ void Audio_NotePoolFill(NotePool* pool, s32 count) { switch (i) { case 0: - source = &gAudioContext.noteFreeLists.disabled; + source = &gAudioCtx.noteFreeLists.disabled; dest = &pool->disabled; break; case 1: - source = &gAudioContext.noteFreeLists.decaying; + source = &gAudioCtx.noteFreeLists.decaying; dest = &pool->decaying; break; case 2: - source = &gAudioContext.noteFreeLists.releasing; + source = &gAudioCtx.noteFreeLists.releasing; dest = &pool->releasing; break; case 3: - source = &gAudioContext.noteFreeLists.active; + source = &gAudioCtx.noteFreeLists.active; dest = &pool->active; break; } @@ -805,7 +805,7 @@ void Audio_NoteReleaseAndTakeOwnership(Note* note, SequenceLayer* layer) { note->playbackState.wantedParentLayer = layer; note->playbackState.priority = layer->channel->notePriority; - note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.action.s.release = true; } @@ -899,9 +899,9 @@ Note* Audio_AllocNote(SequenceLayer* layer) { } if (policy & 8) { - if (!(note = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) && - !(note = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) && - !(note = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) { + if (!(note = Audio_AllocNoteFromDisabled(&gAudioCtx.noteFreeLists, layer)) && + !(note = Audio_AllocNoteFromDecaying(&gAudioCtx.noteFreeLists, layer)) && + !(note = Audio_AllocNoteFromActive(&gAudioCtx.noteFreeLists, layer))) { goto null_return; } return note; @@ -909,13 +909,13 @@ Note* Audio_AllocNote(SequenceLayer* layer) { if (!(note = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) && !(note = Audio_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) && - !(note = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) && + !(note = Audio_AllocNoteFromDisabled(&gAudioCtx.noteFreeLists, layer)) && !(note = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) && !(note = Audio_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) && - !(note = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) && + !(note = Audio_AllocNoteFromDecaying(&gAudioCtx.noteFreeLists, layer)) && !(note = Audio_AllocNoteFromActive(&layer->channel->notePool, layer)) && !(note = Audio_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer)) && - !(note = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) { + !(note = Audio_AllocNoteFromActive(&gAudioCtx.noteFreeLists, layer))) { goto null_return; } return note; @@ -929,8 +929,8 @@ void Audio_NoteInitAll(void) { Note* note; s32 i; - for (i = 0; i < gAudioContext.numNotes; i++) { - note = &gAudioContext.notes[i]; + for (i = 0; i < gAudioCtx.numNotes; i++) { + note = &gAudioCtx.notes[i]; note->noteSubEu = gZeroNoteSub; note->playbackState.priority = 0; note->playbackState.unk_04 = 0; @@ -947,6 +947,6 @@ void Audio_NoteInitAll(void) { note->playbackState.stereoHeadsetEffects = false; note->startSamplePos = 0; note->synthesisState.synthesisBuffers = - AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, sizeof(NoteSynthesisBuffers)); + AudioHeap_AllocDmaMemory(&gAudioCtx.miscPool, sizeof(NoteSynthesisBuffers)); } } diff --git a/src/code/audio_seqplayer.c b/src/code/audio_seqplayer.c index 389a039fc6..89a9568c51 100644 --- a/src/code/audio_seqplayer.c +++ b/src/code/audio_seqplayer.c @@ -252,7 +252,7 @@ s32 AudioSeq_HandleScriptFlowControl(SequencePlayer* seqPlayer, SeqScriptState* void AudioSeq_InitSequenceChannel(SequenceChannel* channel) { s32 i; - if (channel == &gAudioContext.sequenceChannelNone) { + if (channel == &gAudioCtx.sequenceChannelNone) { return; } @@ -309,7 +309,7 @@ s32 AudioSeq_SeqChannelSetLayer(SequenceChannel* channel, s32 layerIndex) { s32 pad; if (channel->layers[layerIndex] == NULL) { - layer = AudioSeq_AudioListPopBack(&gAudioContext.layerFreeList); + layer = AudioSeq_AudioListPopBack(&gAudioCtx.layerFreeList); channel->layers[layerIndex] = layer; if (layer == NULL) { channel->layers[layerIndex] = NULL; @@ -353,7 +353,7 @@ s32 AudioSeq_SeqChannelSetLayer(SequenceChannel* channel, s32 layerIndex) { void AudioSeq_SeqLayerDisable(SequenceLayer* layer) { if (layer != NULL) { - if (layer->channel != &gAudioContext.sequenceChannelNone && layer->channel->seqPlayer->finished == 1) { + if (layer->channel != &gAudioCtx.sequenceChannelNone && layer->channel->seqPlayer->finished == 1) { Audio_SeqLayerNoteRelease(layer); } else { Audio_SeqLayerNoteDecay(layer); @@ -367,7 +367,7 @@ void AudioSeq_SeqLayerFree(SequenceChannel* channel, s32 layerIndex) { SequenceLayer* layer = channel->layers[layerIndex]; if (layer != NULL) { - AudioSeq_AudioListPushBack(&gAudioContext.layerFreeList, &layer->listItem); + AudioSeq_AudioListPushBack(&gAudioCtx.layerFreeList, &layer->listItem); AudioSeq_SeqLayerDisable(layer); channel->layers[layerIndex] = NULL; } @@ -452,10 +452,10 @@ void AudioSeq_SequencePlayerDisable(SequencePlayer* seqPlayer) { AudioLoad_SetFontLoadStatus(seqPlayer->defaultFont, LOAD_STATUS_MAYBE_DISCARDABLE); } - if (seqPlayer->defaultFont == gAudioContext.fontCache.temporary.entries[0].id) { - gAudioContext.fontCache.temporary.nextSide = 0; - } else if (seqPlayer->defaultFont == gAudioContext.fontCache.temporary.entries[1].id) { - gAudioContext.fontCache.temporary.nextSide = 1; + if (seqPlayer->defaultFont == gAudioCtx.fontCache.temporary.entries[0].id) { + gAudioCtx.fontCache.temporary.nextSide = 0; + } else if (seqPlayer->defaultFont == gAudioCtx.fontCache.temporary.entries[1].id) { + gAudioCtx.fontCache.temporary.nextSide = 1; } } @@ -488,15 +488,15 @@ void* AudioSeq_AudioListPopBack(AudioListItem* list) { void AudioSeq_InitLayerFreelist(void) { s32 i; - gAudioContext.layerFreeList.prev = &gAudioContext.layerFreeList; - gAudioContext.layerFreeList.next = &gAudioContext.layerFreeList; - gAudioContext.layerFreeList.u.count = 0; - gAudioContext.layerFreeList.pool = NULL; + gAudioCtx.layerFreeList.prev = &gAudioCtx.layerFreeList; + gAudioCtx.layerFreeList.next = &gAudioCtx.layerFreeList; + gAudioCtx.layerFreeList.u.count = 0; + gAudioCtx.layerFreeList.pool = NULL; - for (i = 0; i < ARRAY_COUNT(gAudioContext.sequenceLayers); i++) { - gAudioContext.sequenceLayers[i].listItem.u.value = &gAudioContext.sequenceLayers[i]; - gAudioContext.sequenceLayers[i].listItem.prev = NULL; - AudioSeq_AudioListPushBack(&gAudioContext.layerFreeList, &gAudioContext.sequenceLayers[i].listItem); + for (i = 0; i < ARRAY_COUNT(gAudioCtx.sequenceLayers); i++) { + gAudioCtx.sequenceLayers[i].listItem.u.value = &gAudioCtx.sequenceLayers[i]; + gAudioCtx.sequenceLayers[i].listItem.prev = NULL; + AudioSeq_AudioListPushBack(&gAudioCtx.layerFreeList, &gAudioCtx.sequenceLayers[i].listItem); } } @@ -873,7 +873,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { layer->tunedSample = NULL; tuning = 1.0f; if (instOrWave >= 0xC0) { - layer->tunedSample = &gAudioContext.synthesisReverbs[instOrWave - 0xC0].tunedSample; + layer->tunedSample = &gAudioCtx.synthesisReverbs[instOrWave - 0xC0].tunedSample; } } @@ -903,12 +903,12 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { portamento->extent = (freqScale2 / freqScale) - 1.0f; if (PORTAMENTO_IS_SPECIAL(*portamento)) { - speed = seqPlayer->tempo * 0x8000 / gAudioContext.tempoInternalToExternal; + speed = seqPlayer->tempo * 0x8000 / gAudioCtx.tempoInternalToExternal; if (layer->delay != 0) { speed = speed * 0x100 / (layer->delay * layer->portamentoTime); } } else { - speed = 0x20000 / (layer->portamentoTime * gAudioContext.audioBufferParameters.updatesPerFrame); + speed = 0x20000 / (layer->portamentoTime * gAudioCtx.audioBufferParameters.updatesPerFrame); } if (speed >= 0x7FFF) { @@ -935,7 +935,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { layer->tunedSample = NULL; layer->freqScale = gPitchFrequencies[semitone2]; if (instOrWave >= 0xC0) { - layer->tunedSample = &gAudioContext.synthesisReverbs[instOrWave - 0xC0].tunedSample; + layer->tunedSample = &gAudioCtx.synthesisReverbs[instOrWave - 0xC0].tunedSample; } } break; @@ -951,7 +951,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { time = 0.0f; } time *= seqPlayer->tempo; - time *= gAudioContext.unk_2870; + time *= gAudioCtx.unk_2870; time /= layer->freqScale; if (time > 0x7FFE) { time = 0x7FFE; @@ -964,7 +964,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { // (It's a bit unclear if 'portamento' has actually always been // set when this is reached...) if (PORTAMENTO_IS_SPECIAL(*portamento)) { - speed2 = seqPlayer->tempo * 0x8000 / gAudioContext.tempoInternalToExternal; + speed2 = seqPlayer->tempo * 0x8000 / gAudioCtx.tempoInternalToExternal; speed2 = speed2 * 0x100 / (layer->delay * layer->portamentoTime); if (speed2 >= 0x7FFF) { speed2 = 0x7FFF; @@ -1043,8 +1043,8 @@ s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd) { } if (channel->velocityRandomVariance != 0) { - floatDelta = layer->velocitySquare * (gAudioContext.audioRandom % channel->velocityRandomVariance) / 100.0f; - if ((gAudioContext.audioRandom & 0x8000) != 0) { + floatDelta = layer->velocitySquare * (gAudioCtx.audioRandom % channel->velocityRandomVariance) / 100.0f; + if ((gAudioCtx.audioRandom & 0x8000) != 0) { floatDelta = -floatDelta; } @@ -1064,8 +1064,8 @@ s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd) { if (channel->gateTimeRandomVariance != 0) { //! @bug should probably be gateTimeRandomVariance - intDelta = (layer->gateDelay * (gAudioContext.audioRandom % channel->velocityRandomVariance)) / 100; - if ((gAudioContext.audioRandom & 0x4000) != 0) { + intDelta = (layer->gateDelay * (gAudioCtx.audioRandom % channel->velocityRandomVariance)) / 100; + if ((gAudioCtx.audioRandom & 0x4000) != 0) { intDelta = -intDelta; } @@ -1244,9 +1244,9 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { cmd = (u8)cmdArgs[0]; if (seqPlayer->defaultFont != 0xFF) { - cmdArgU16 = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId]; - lowBits = gAudioContext.sequenceFontTable[cmdArgU16]; - cmd = gAudioContext.sequenceFontTable[cmdArgU16 + lowBits - cmd]; + cmdArgU16 = ((u16*)gAudioCtx.sequenceFontTable)[seqPlayer->seqId]; + lowBits = gAudioCtx.sequenceFontTable[cmdArgU16]; + cmd = gAudioCtx.sequenceFontTable[cmdArgU16 + lowBits - cmd]; } if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, cmd)) { @@ -1373,9 +1373,9 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { cmd = (u8)cmdArgs[0]; if (seqPlayer->defaultFont != 0xFF) { - cmdArgU16 = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId]; - lowBits = gAudioContext.sequenceFontTable[cmdArgU16]; - cmd = gAudioContext.sequenceFontTable[cmdArgU16 + lowBits - cmd]; + cmdArgU16 = ((u16*)gAudioCtx.sequenceFontTable)[seqPlayer->seqId]; + lowBits = gAudioCtx.sequenceFontTable[cmdArgU16]; + cmd = gAudioCtx.sequenceFontTable[cmdArgU16 + lowBits - cmd]; } if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, cmd)) { @@ -1569,12 +1569,12 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { case 0xB7: channel->unk_22 = - (cmdArgs[0] == 0) ? gAudioContext.audioRandom & 0xFFFF : gAudioContext.audioRandom % cmdArgs[0]; + (cmdArgs[0] == 0) ? gAudioCtx.audioRandom & 0xFFFF : gAudioCtx.audioRandom % cmdArgs[0]; break; case 0xB8: scriptState->value = - (cmdArgs[0] == 0) ? gAudioContext.audioRandom & 0xFFFF : gAudioContext.audioRandom % cmdArgs[0]; + (cmdArgs[0] == 0) ? gAudioCtx.audioRandom & 0xFFFF : gAudioCtx.audioRandom % cmdArgs[0]; break; case 0xBD: @@ -1746,11 +1746,11 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { seqPlayer->tempoAcc += seqPlayer->tempo; seqPlayer->tempoAcc += (s16)seqPlayer->unk_0C; - if (seqPlayer->tempoAcc < gAudioContext.tempoInternalToExternal) { + if (seqPlayer->tempoAcc < gAudioCtx.tempoInternalToExternal) { return; } - seqPlayer->tempoAcc -= (u16)gAudioContext.tempoInternalToExternal; + seqPlayer->tempoAcc -= (u16)gAudioCtx.tempoInternalToExternal; if (seqPlayer->stopScript == true) { return; @@ -1811,8 +1811,8 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { case 0xDD: seqPlayer->tempo = AudioSeq_ScriptReadU8(seqScript) * TATUMS_PER_BEAT; - if (seqPlayer->tempo > gAudioContext.tempoInternalToExternal) { - seqPlayer->tempo = (u16)gAudioContext.tempoInternalToExternal; + if (seqPlayer->tempo > gAudioCtx.tempoInternalToExternal) { + seqPlayer->tempo = (u16)gAudioCtx.tempoInternalToExternal; } if ((s16)seqPlayer->tempo <= 0) { @@ -1909,9 +1909,9 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { case 0xCE: cmd = AudioSeq_ScriptReadU8(seqScript); if (cmd == 0) { - seqScript->value = (gAudioContext.audioRandom >> 2) & 0xFF; + seqScript->value = (gAudioCtx.audioRandom >> 2) & 0xFF; } else { - seqScript->value = (gAudioContext.audioRandom >> 2) % cmd; + seqScript->value = (gAudioCtx.audioRandom >> 2) % cmd; } break; @@ -2038,11 +2038,10 @@ void AudioSeq_ProcessSequences(s32 arg0) { SequencePlayer* seqPlayer; u32 i; - gAudioContext.noteSubEuOffset = - (gAudioContext.audioBufferParameters.updatesPerFrame - arg0 - 1) * gAudioContext.numNotes; + gAudioCtx.noteSubEuOffset = (gAudioCtx.audioBufferParameters.updatesPerFrame - arg0 - 1) * gAudioCtx.numNotes; - for (i = 0; i < (u32)gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - seqPlayer = &gAudioContext.seqPlayers[i]; + for (i = 0; i < (u32)gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + seqPlayer = &gAudioCtx.seqPlayers[i]; if (seqPlayer->enabled == true) { AudioSeq_SequencePlayerProcessSequence(seqPlayer); Audio_SequencePlayerProcessSound(seqPlayer); @@ -2089,14 +2088,14 @@ void AudioSeq_ResetSequencePlayer(SequencePlayer* seqPlayer) { void AudioSeq_InitSequencePlayerChannels(s32 playerIdx) { SequenceChannel* channel; - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx]; s32 i; s32 j; for (i = 0; i < SEQ_NUM_CHANNELS; i++) { - seqPlayer->channels[i] = AudioHeap_AllocZeroed(&gAudioContext.miscPool, sizeof(SequenceChannel)); + seqPlayer->channels[i] = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(SequenceChannel)); if (seqPlayer->channels[i] == NULL) { - seqPlayer->channels[i] = &gAudioContext.sequenceChannelNone; + seqPlayer->channels[i] = &gAudioCtx.sequenceChannelNone; } else { channel = seqPlayer->channels[i]; channel->seqPlayer = seqPlayer; @@ -2114,7 +2113,7 @@ void AudioSeq_InitSequencePlayer(SequencePlayer* seqPlayer) { s32 j; for (i = 0; i < SEQ_NUM_CHANNELS; i++) { - seqPlayer->channels[i] = &gAudioContext.sequenceChannelNone; + seqPlayer->channels[i] = &gAudioCtx.sequenceChannelNone; } seqPlayer->enabled = false; @@ -2139,12 +2138,12 @@ void AudioSeq_InitSequencePlayers(void) { AudioSeq_InitLayerFreelist(); - for (i = 0; i < ARRAY_COUNT(gAudioContext.sequenceLayers); i++) { - gAudioContext.sequenceLayers[i].channel = NULL; - gAudioContext.sequenceLayers[i].enabled = false; + for (i = 0; i < ARRAY_COUNT(gAudioCtx.sequenceLayers); i++) { + gAudioCtx.sequenceLayers[i].channel = NULL; + gAudioCtx.sequenceLayers[i].enabled = false; } - for (i = 0; i < ARRAY_COUNT(gAudioContext.seqPlayers); i++) { - AudioSeq_InitSequencePlayer(&gAudioContext.seqPlayers[i]); + for (i = 0; i < ARRAY_COUNT(gAudioCtx.seqPlayers); i++) { + AudioSeq_InitSequencePlayer(&gAudioCtx.seqPlayers[i]); } } diff --git a/src/code/audio_synthesis.c b/src/code/audio_synthesis.c index 587b7e60e0..ca7467f91c 100644 --- a/src/code/audio_synthesis.c +++ b/src/code/audio_synthesis.c @@ -61,7 +61,7 @@ u8 sNumSamplesPerWavePeriod[] = { void AudioSynth_InitNextRingBuf(s32 chunkLen, s32 updateIndex, s32 reverbIndex) { ReverbRingBufferItem* bufItem; s32 pad[3]; - SynthesisReverb* reverb = &gAudioContext.synthesisReverbs[reverbIndex]; + SynthesisReverb* reverb = &gAudioCtx.synthesisReverbs[reverbIndex]; s32 temp_a0_2; s32 temp_a0_4; s32 numSamples; @@ -135,10 +135,10 @@ void func_800DB03C(s32 updateIndex) { s32 baseIndex; s32 i; - baseIndex = gAudioContext.numNotes * updateIndex; - for (i = 0; i < gAudioContext.numNotes; i++) { - subEu = &gAudioContext.notes[i].noteSubEu; - subEu2 = &gAudioContext.noteSubsEu[baseIndex + i]; + baseIndex = gAudioCtx.numNotes * updateIndex; + for (i = 0; i < gAudioCtx.numNotes; i++) { + subEu = &gAudioCtx.notes[i].noteSubEu; + subEu2 = &gAudioCtx.noteSubsEu[baseIndex + i]; if (subEu->bitField0.enabled) { subEu->bitField0.needsInit = false; } else { @@ -158,42 +158,41 @@ Acmd* AudioSynth_Update(Acmd* cmdStart, s32* cmdCnt, s16* aiStart, s32 aiBufLen) SynthesisReverb* reverb; cmdP = cmdStart; - for (i = gAudioContext.audioBufferParameters.updatesPerFrame; i > 0; i--) { + for (i = gAudioCtx.audioBufferParameters.updatesPerFrame; i > 0; i--) { AudioSeq_ProcessSequences(i - 1); - func_800DB03C(gAudioContext.audioBufferParameters.updatesPerFrame - i); + func_800DB03C(gAudioCtx.audioBufferParameters.updatesPerFrame - i); } aiBufP = aiStart; - gAudioContext.curLoadedBook = NULL; + gAudioCtx.curLoadedBook = NULL; - for (i = gAudioContext.audioBufferParameters.updatesPerFrame; i > 0; i--) { + for (i = gAudioCtx.audioBufferParameters.updatesPerFrame; i > 0; i--) { if (i == 1) { chunkLen = aiBufLen; - } else if ((aiBufLen / i) >= gAudioContext.audioBufferParameters.samplesPerUpdateMax) { - chunkLen = gAudioContext.audioBufferParameters.samplesPerUpdateMax; - } else if (gAudioContext.audioBufferParameters.samplesPerUpdateMin >= (aiBufLen / i)) { - chunkLen = gAudioContext.audioBufferParameters.samplesPerUpdateMin; + } else if ((aiBufLen / i) >= gAudioCtx.audioBufferParameters.samplesPerUpdateMax) { + chunkLen = gAudioCtx.audioBufferParameters.samplesPerUpdateMax; + } else if (gAudioCtx.audioBufferParameters.samplesPerUpdateMin >= (aiBufLen / i)) { + chunkLen = gAudioCtx.audioBufferParameters.samplesPerUpdateMin; } else { - chunkLen = gAudioContext.audioBufferParameters.samplesPerUpdate; + chunkLen = gAudioCtx.audioBufferParameters.samplesPerUpdate; } - for (j = 0; j < gAudioContext.numSynthesisReverbs; j++) { - if (gAudioContext.synthesisReverbs[j].useReverb) { - AudioSynth_InitNextRingBuf(chunkLen, gAudioContext.audioBufferParameters.updatesPerFrame - i, j); + for (j = 0; j < gAudioCtx.numSynthesisReverbs; j++) { + if (gAudioCtx.synthesisReverbs[j].useReverb) { + AudioSynth_InitNextRingBuf(chunkLen, gAudioCtx.audioBufferParameters.updatesPerFrame - i, j); } } - cmdP = AudioSynth_DoOneAudioUpdate(aiBufP, chunkLen, cmdP, - gAudioContext.audioBufferParameters.updatesPerFrame - i); + cmdP = AudioSynth_DoOneAudioUpdate(aiBufP, chunkLen, cmdP, gAudioCtx.audioBufferParameters.updatesPerFrame - i); aiBufLen -= chunkLen; aiBufP += 2 * chunkLen; } - for (j = 0; j < gAudioContext.numSynthesisReverbs; j++) { - if (gAudioContext.synthesisReverbs[j].framesToIgnore != 0) { - gAudioContext.synthesisReverbs[j].framesToIgnore--; + for (j = 0; j < gAudioCtx.numSynthesisReverbs; j++) { + if (gAudioCtx.synthesisReverbs[j].framesToIgnore != 0) { + gAudioCtx.synthesisReverbs[j].framesToIgnore--; } - gAudioContext.synthesisReverbs[j].curFrame ^= 1; + gAudioCtx.synthesisReverbs[j].curFrame ^= 1; } *cmdCnt = cmdP - cmdStart; @@ -204,8 +203,8 @@ void func_800DB2C0(s32 updateIndex, s32 noteIndex) { NoteSubEu* noteSubEu; s32 i; - for (i = updateIndex + 1; i < gAudioContext.audioBufferParameters.updatesPerFrame; i++) { - noteSubEu = &gAudioContext.noteSubsEu[(gAudioContext.numNotes * i) + noteIndex]; + for (i = updateIndex + 1; i < gAudioCtx.audioBufferParameters.updatesPerFrame; i++) { + noteSubEu = &gAudioCtx.noteSubsEu[(gAudioCtx.numNotes * i) + noteIndex]; if (!noteSubEu->bitField0.needsInit) { noteSubEu->bitField0.enabled = false; } else { @@ -332,7 +331,7 @@ Acmd* AudioSynth_FilterReverb(Acmd* cmd, s32 size, SynthesisReverb* reverb) { Acmd* AudioSynth_MaybeMixRingBuffer1(Acmd* cmd, SynthesisReverb* reverb, s32 updateIndex) { SynthesisReverb* temp_a3; - temp_a3 = &gAudioContext.synthesisReverbs[reverb->unk_05]; + temp_a3 = &gAudioCtx.synthesisReverbs[reverb->unk_05]; if (temp_a3->downsampleRate == 1) { cmd = AudioSynth_LoadRingBuffer1AtTemp(cmd, temp_a3, updateIndex); aMix(cmd++, DMEM_2CH_SIZE >> 4, reverb->unk_08, DMEM_WET_LEFT_CH, DMEM_WET_TEMP); @@ -593,27 +592,27 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat NoteSubEu* noteSubEu2; s32 unk14; - t = gAudioContext.numNotes * updateIndex; + t = gAudioCtx.numNotes * updateIndex; count = 0; - if (gAudioContext.numSynthesisReverbs == 0) { - for (i = 0; i < gAudioContext.numNotes; i++) { - if (gAudioContext.noteSubsEu[t + i].bitField0.enabled) { + if (gAudioCtx.numSynthesisReverbs == 0) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + if (gAudioCtx.noteSubsEu[t + i].bitField0.enabled) { noteIndices[count++] = i; } } } else { - for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) { - for (i = 0; i < gAudioContext.numNotes; i++) { - noteSubEu = &gAudioContext.noteSubsEu[t + i]; + for (reverbIndex = 0; reverbIndex < gAudioCtx.numSynthesisReverbs; reverbIndex++) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + noteSubEu = &gAudioCtx.noteSubsEu[t + i]; if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex == reverbIndex) { noteIndices[count++] = i; } } } - for (i = 0; i < gAudioContext.numNotes; i++) { - noteSubEu = &gAudioContext.noteSubsEu[t + i]; - if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex >= gAudioContext.numSynthesisReverbs) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + noteSubEu = &gAudioCtx.noteSubsEu[t + i]; + if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex >= gAudioCtx.numSynthesisReverbs) { noteIndices[count++] = i; } } @@ -622,8 +621,8 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat aClearBuffer(cmd++, DMEM_LEFT_CH, DMEM_2CH_SIZE); i = 0; - for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) { - reverb = &gAudioContext.synthesisReverbs[reverbIndex]; + for (reverbIndex = 0; reverbIndex < gAudioCtx.numSynthesisReverbs; reverbIndex++) { + reverb = &gAudioCtx.synthesisReverbs[reverbIndex]; useReverb = reverb->useReverb; if (useReverb) { @@ -660,11 +659,11 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat } while (i < count) { - noteSubEu2 = &gAudioContext.noteSubsEu[noteIndices[i] + t]; + noteSubEu2 = &gAudioCtx.noteSubsEu[noteIndices[i] + t]; if (noteSubEu2->bitField1.reverbIndex == reverbIndex) { - cmd = AudioSynth_ProcessNote(noteIndices[i], noteSubEu2, - &gAudioContext.notes[noteIndices[i]].synthesisState, aiBuf, aiBufLen, cmd, - updateIndex); + cmd = + AudioSynth_ProcessNote(noteIndices[i], noteSubEu2, &gAudioCtx.notes[noteIndices[i]].synthesisState, + aiBuf, aiBufLen, cmd, updateIndex); } else { break; } @@ -689,9 +688,9 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat } while (i < count) { - cmd = AudioSynth_ProcessNote(noteIndices[i], &gAudioContext.noteSubsEu[t + noteIndices[i]], - &gAudioContext.notes[noteIndices[i]].synthesisState, aiBuf, aiBufLen, cmd, - updateIndex); + cmd = + AudioSynth_ProcessNote(noteIndices[i], &gAudioCtx.noteSubsEu[t + noteIndices[i]], + &gAudioCtx.notes[noteIndices[i]].synthesisState, aiBuf, aiBufLen, cmd, updateIndex); i++; } @@ -756,7 +755,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS bookOffset = noteSubEu->bitField1.bookOffset; finished = noteSubEu->bitField0.finished; - note = &gAudioContext.notes[noteIndex]; + note = &gAudioCtx.notes[noteIndex]; flags = A_CONTINUE; if (noteSubEu->bitField0.needsInit == true) { @@ -814,24 +813,24 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS } if (sample->codec == CODEC_ADPCM || sample->codec == CODEC_SMALL_ADPCM) { - if (gAudioContext.curLoadedBook != sample->book->book) { + if (gAudioCtx.curLoadedBook != sample->book->book) { u32 nEntries; switch (bookOffset) { case 1: - gAudioContext.curLoadedBook = &D_8012FBA8[1]; + gAudioCtx.curLoadedBook = &D_8012FBA8[1]; break; case 2: case 3: default: - gAudioContext.curLoadedBook = sample->book->book; + gAudioCtx.curLoadedBook = sample->book->book; break; } if (1) {} if (1) {} if (1) {} nEntries = SAMPLES_PER_FRAME * sample->book->order * sample->book->numPredictors; - aLoadADPCM(cmd++, nEntries, gAudioContext.curLoadedBook); + aLoadADPCM(cmd++, nEntries, gAudioCtx.curLoadedBook); } } diff --git a/src/code/code_800E4FE0.c b/src/code/code_800E4FE0.c index 3b140b6cf7..7b575d025a 100644 --- a/src/code/code_800E4FE0.c +++ b/src/code/code_800E4FE0.c @@ -53,32 +53,32 @@ AudioTask* func_800E5000(void) { s32 sp48; s32 i; - gAudioContext.totalTaskCount++; - if (gAudioContext.totalTaskCount % (gAudioContext.audioBufferParameters.specUnk4) != 0) { + gAudioCtx.totalTaskCount++; + if (gAudioCtx.totalTaskCount % (gAudioCtx.audioBufferParameters.specUnk4) != 0) { if (D_801755D0 != NULL) { D_801755D0(); } - if ((gAudioContext.totalTaskCount % gAudioContext.audioBufferParameters.specUnk4) + 1 == - gAudioContext.audioBufferParameters.specUnk4) { + if ((gAudioCtx.totalTaskCount % gAudioCtx.audioBufferParameters.specUnk4) + 1 == + gAudioCtx.audioBufferParameters.specUnk4) { return sWaitingAudioTask; } else { return NULL; } } - osSendMesg(gAudioContext.taskStartQueueP, (OSMesg)gAudioContext.totalTaskCount, OS_MESG_NOBLOCK); - gAudioContext.rspTaskIndex ^= 1; - gAudioContext.curAiBufIndex++; - gAudioContext.curAiBufIndex %= 3; - index = (gAudioContext.curAiBufIndex - 2 + 3) % 3; + osSendMesg(gAudioCtx.taskStartQueueP, (OSMesg)gAudioCtx.totalTaskCount, OS_MESG_NOBLOCK); + gAudioCtx.rspTaskIndex ^= 1; + gAudioCtx.curAiBufIndex++; + gAudioCtx.curAiBufIndex %= 3; + index = (gAudioCtx.curAiBufIndex - 2 + 3) % 3; samplesRemainingInAi = osAiGetLength() / 4; - if (gAudioContext.resetTimer < 16) { - if (gAudioContext.aiBufLengths[index] != 0) { - osAiSetNextBuffer(gAudioContext.aiBuffers[index], gAudioContext.aiBufLengths[index] * 4); - if (gAudioContext.aiBuffers[index]) {} - if (gAudioContext.aiBufLengths[index]) {} + if (gAudioCtx.resetTimer < 16) { + if (gAudioCtx.aiBufLengths[index] != 0) { + osAiSetNextBuffer(gAudioCtx.aiBuffers[index], gAudioCtx.aiBufLengths[index] * 4); + if (gAudioCtx.aiBuffers[index]) {} + if (gAudioCtx.aiBufLengths[index]) {} } } @@ -86,36 +86,35 @@ AudioTask* func_800E5000(void) { D_801755D0(); } - sp5C = gAudioContext.curAudioFrameDmaCount; - for (i = 0; i < gAudioContext.curAudioFrameDmaCount; i++) { - if (osRecvMesg(&gAudioContext.currAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK) == 0) { + sp5C = gAudioCtx.curAudioFrameDmaCount; + for (i = 0; i < gAudioCtx.curAudioFrameDmaCount; i++) { + if (osRecvMesg(&gAudioCtx.currAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK) == 0) { sp5C--; } } if (sp5C != 0) { for (i = 0; i < sp5C; i++) { - osRecvMesg(&gAudioContext.currAudioFrameDmaQueue, NULL, OS_MESG_BLOCK); + osRecvMesg(&gAudioCtx.currAudioFrameDmaQueue, NULL, OS_MESG_BLOCK); } } - sp48 = MQ_GET_COUNT(&gAudioContext.currAudioFrameDmaQueue); + sp48 = MQ_GET_COUNT(&gAudioCtx.currAudioFrameDmaQueue); if (sp48 != 0) { for (i = 0; i < sp48; i++) { - osRecvMesg(&gAudioContext.currAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK); + osRecvMesg(&gAudioCtx.currAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK); } } - gAudioContext.curAudioFrameDmaCount = 0; + gAudioCtx.curAudioFrameDmaCount = 0; AudioLoad_DecreaseSampleDmaTtls(); - AudioLoad_ProcessLoads(gAudioContext.resetStatus); + AudioLoad_ProcessLoads(gAudioCtx.resetStatus); AudioLoad_ProcessScriptLoads(); - if (gAudioContext.resetStatus != 0) { + if (gAudioCtx.resetStatus != 0) { if (AudioHeap_ResetStep() == 0) { - if (gAudioContext.resetStatus == 0) { - osSendMesg(gAudioContext.audioResetQueueP, (OSMesg)(u32)gAudioContext.audioResetSpecIdToLoad, - OS_MESG_NOBLOCK); + if (gAudioCtx.resetStatus == 0) { + osSendMesg(gAudioCtx.audioResetQueueP, (OSMesg)(u32)gAudioCtx.audioResetSpecIdToLoad, OS_MESG_NOBLOCK); } sWaitingAudioTask = NULL; @@ -123,63 +122,62 @@ AudioTask* func_800E5000(void) { } } - if (gAudioContext.resetTimer > 16) { + if (gAudioCtx.resetTimer > 16) { return NULL; } - if (gAudioContext.resetTimer != 0) { - gAudioContext.resetTimer++; + if (gAudioCtx.resetTimer != 0) { + gAudioCtx.resetTimer++; } - gAudioContext.curTask = &gAudioContext.rspTask[gAudioContext.rspTaskIndex]; - gAudioContext.curAbiCmdBuf = gAudioContext.abiCmdBufs[gAudioContext.rspTaskIndex]; + gAudioCtx.curTask = &gAudioCtx.rspTask[gAudioCtx.rspTaskIndex]; + gAudioCtx.curAbiCmdBuf = gAudioCtx.abiCmdBufs[gAudioCtx.rspTaskIndex]; - index = gAudioContext.curAiBufIndex; - currAiBuffer = gAudioContext.aiBuffers[index]; + index = gAudioCtx.curAiBufIndex; + currAiBuffer = gAudioCtx.aiBuffers[index]; - gAudioContext.aiBufLengths[index] = - (s16)((((gAudioContext.audioBufferParameters.samplesPerFrameTarget - samplesRemainingInAi) + + gAudioCtx.aiBufLengths[index] = + (s16)((((gAudioCtx.audioBufferParameters.samplesPerFrameTarget - samplesRemainingInAi) + EXTRA_BUFFERED_AI_SAMPLES_TARGET) & ~0xF) + SAMPLES_TO_OVERPRODUCE); - if (gAudioContext.aiBufLengths[index] < gAudioContext.audioBufferParameters.minAiBufferLength) { - gAudioContext.aiBufLengths[index] = gAudioContext.audioBufferParameters.minAiBufferLength; + if (gAudioCtx.aiBufLengths[index] < gAudioCtx.audioBufferParameters.minAiBufferLength) { + gAudioCtx.aiBufLengths[index] = gAudioCtx.audioBufferParameters.minAiBufferLength; } - if (gAudioContext.aiBufLengths[index] > gAudioContext.audioBufferParameters.maxAiBufferLength) { - gAudioContext.aiBufLengths[index] = gAudioContext.audioBufferParameters.maxAiBufferLength; + if (gAudioCtx.aiBufLengths[index] > gAudioCtx.audioBufferParameters.maxAiBufferLength) { + gAudioCtx.aiBufLengths[index] = gAudioCtx.audioBufferParameters.maxAiBufferLength; } j = 0; - if (gAudioContext.resetStatus == 0) { + if (gAudioCtx.resetStatus == 0) { // msg = 0000RREE R = read pos, E = End Pos - while (osRecvMesg(gAudioContext.cmdProcQueueP, (OSMesg*)&sp4C, OS_MESG_NOBLOCK) != -1) { + while (osRecvMesg(gAudioCtx.cmdProcQueueP, (OSMesg*)&sp4C, OS_MESG_NOBLOCK) != -1) { if (1) {} Audio_ProcessCmds(sp4C); j++; } - if ((j == 0) && (gAudioContext.cmdQueueFinished)) { + if ((j == 0) && (gAudioCtx.cmdQueueFinished)) { Audio_ScheduleProcessCmds(); } } - gAudioContext.curAbiCmdBuf = - AudioSynth_Update(gAudioContext.curAbiCmdBuf, &abiCmdCnt, currAiBuffer, gAudioContext.aiBufLengths[index]); + gAudioCtx.curAbiCmdBuf = + AudioSynth_Update(gAudioCtx.curAbiCmdBuf, &abiCmdCnt, currAiBuffer, gAudioCtx.aiBufLengths[index]); // Update audioRandom to the next random number - gAudioContext.audioRandom = (gAudioContext.audioRandom + gAudioContext.totalTaskCount) * osGetCount(); - gAudioContext.audioRandom = - gAudioContext.audioRandom + gAudioContext.aiBuffers[index][gAudioContext.totalTaskCount & 0xFF]; + gAudioCtx.audioRandom = (gAudioCtx.audioRandom + gAudioCtx.totalTaskCount) * osGetCount(); + gAudioCtx.audioRandom = gAudioCtx.audioRandom + gAudioCtx.aiBuffers[index][gAudioCtx.totalTaskCount & 0xFF]; // gWaveSamples[8] interprets compiled assembly code as s16 samples as a way to generate sound with noise. // Start with the address of func_800E4FE0, and offset it by a random number between 0 - 0xFFF0 // Use the resulting address as the starting address to interpret an array of samples i.e. `s16 samples[]` - gWaveSamples[8] = (s16*)(((u8*)func_800E4FE0) + (gAudioContext.audioRandom & 0xFFF0)); + gWaveSamples[8] = (s16*)(((u8*)func_800E4FE0) + (gAudioCtx.audioRandom & 0xFFF0)); - index = gAudioContext.rspTaskIndex; - gAudioContext.curTask->msgQueue = NULL; - gAudioContext.curTask->unk_44 = NULL; + index = gAudioCtx.rspTaskIndex; + gAudioCtx.curTask->msgQueue = NULL; + gAudioCtx.curTask->unk_44 = NULL; - task = &gAudioContext.curTask->task.t; + task = &gAudioCtx.curTask->task.t; task->type = M_AUDTASK; task->flags = 0; task->ucode_boot = aspMainTextStart; @@ -193,7 +191,7 @@ AudioTask* func_800E5000(void) { task->output_buff = NULL; task->output_buff_size = NULL; if (1) {} - task->data_ptr = (u64*)gAudioContext.abiCmdBufs[index]; + task->data_ptr = (u64*)gAudioCtx.abiCmdBufs[index]; task->data_size = abiCmdCnt * sizeof(Acmd); task->yield_data_ptr = NULL; task->yield_data_size = 0; @@ -202,10 +200,10 @@ AudioTask* func_800E5000(void) { sMaxAbiCmdCnt = abiCmdCnt; } - if (gAudioContext.audioBufferParameters.specUnk4 == 1) { - return gAudioContext.curTask; + if (gAudioCtx.audioBufferParameters.specUnk4 == 1) { + return gAudioCtx.curTask; } else { - sWaitingAudioTask = gAudioContext.curTask; + sWaitingAudioTask = gAudioCtx.curTask; return NULL; } } @@ -235,9 +233,9 @@ void func_800E5584(AudioCmd* cmd) { break; case 0x83: - if (gAudioContext.seqPlayers[cmd->arg0].enabled) { + if (gAudioCtx.seqPlayers[cmd->arg0].enabled) { if (cmd->asInt == 0) { - AudioSeq_SequencePlayerDisableAsFinished(&gAudioContext.seqPlayers[cmd->arg0]); + AudioSeq_SequencePlayerDisableAsFinished(&gAudioCtx.seqPlayers[cmd->arg0]); } else { func_800E5958(cmd->arg0, cmd->asInt); } @@ -245,12 +243,12 @@ void func_800E5584(AudioCmd* cmd) { break; case 0xF0: - gAudioContext.soundMode = cmd->asUInt; + gAudioCtx.soundMode = cmd->asUInt; break; case 0xF1: - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[i]; seqPlayer->muted = 1; seqPlayer->recalculateVolume = 1; @@ -259,8 +257,8 @@ void func_800E5584(AudioCmd* cmd) { case 0xF2: if (cmd->asUInt == 1) { - for (i = 0; i < gAudioContext.numNotes; i++) { - Note* note = &gAudioContext.notes[i]; + for (i = 0; i < gAudioCtx.numNotes; i++) { + Note* note = &gAudioCtx.notes[i]; NoteSubEu* subEu = ¬e->noteSubEu; if (subEu->bitField0.enabled && note->playbackState.unk_04 == 0) { @@ -271,8 +269,8 @@ void func_800E5584(AudioCmd* cmd) { } } - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[i]; seqPlayer->muted = 0; seqPlayer->recalculateVolume = 1; @@ -284,15 +282,15 @@ void func_800E5584(AudioCmd* cmd) { break; case 0xF4: - AudioLoad_AsyncLoadSampleBank(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue); + AudioLoad_AsyncLoadSampleBank(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue); break; case 0xF5: - AudioLoad_AsyncLoadFont(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue); + AudioLoad_AsyncLoadFont(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue); break; case 0xFC: - AudioLoad_AsyncLoadSeq(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue); + AudioLoad_AsyncLoadSeq(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue); break; case 0xF6: @@ -300,12 +298,12 @@ void func_800E5584(AudioCmd* cmd) { break; case 0x90: - gAudioContext.unk_5BDC[cmd->arg0] = cmd->asUShort; + gAudioCtx.unk_5BDC[cmd->arg0] = cmd->asUShort; break; case 0xF9: - gAudioContext.resetStatus = 5; - gAudioContext.audioResetSpecIdToLoad = cmd->asUInt; + gAudioCtx.resetStatus = 5; + gAudioCtx.audioResetSpecIdToLoad = cmd->asUInt; break; case 0xFB: @@ -321,8 +319,8 @@ void func_800E5584(AudioCmd* cmd) { case 0xFE: temp_t7 = cmd->asUInt; if (temp_t7 == 1) { - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[i]; if (seqPlayer->enabled) { AudioSeq_SequencePlayerDisableAsFinished(seqPlayer); @@ -343,7 +341,7 @@ void func_800E5584(AudioCmd* cmd) { // SetFadeOutTimer void func_800E5958(s32 playerIdx, s32 fadeTimer) { - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx]; if (fadeTimer == 0) { fadeTimer = 1; @@ -359,7 +357,7 @@ void func_800E59AC(s32 playerIdx, s32 fadeTimer) { SequencePlayer* seqPlayer; if (fadeTimer != 0) { - seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + seqPlayer = &gAudioCtx.seqPlayers[playerIdx]; seqPlayer->state = 1; seqPlayer->fadeTimerUnkEu = fadeTimer; seqPlayer->fadeTimer = fadeTimer; @@ -369,30 +367,27 @@ void func_800E59AC(s32 playerIdx, s32 fadeTimer) { } void Audio_InitMesgQueuesInternal(void) { - gAudioContext.cmdWrPos = 0; - gAudioContext.cmdRdPos = 0; - gAudioContext.cmdQueueFinished = 0; - gAudioContext.taskStartQueueP = &gAudioContext.taskStartQueue; - gAudioContext.cmdProcQueueP = &gAudioContext.cmdProcQueue; - gAudioContext.audioResetQueueP = &gAudioContext.audioResetQueue; - osCreateMesgQueue(gAudioContext.taskStartQueueP, gAudioContext.taskStartMsgBuf, - ARRAY_COUNT(gAudioContext.taskStartMsgBuf)); - osCreateMesgQueue(gAudioContext.cmdProcQueueP, gAudioContext.cmdProcMsgBuf, - ARRAY_COUNT(gAudioContext.cmdProcMsgBuf)); - osCreateMesgQueue(gAudioContext.audioResetQueueP, gAudioContext.audioResetMsgBuf, - ARRAY_COUNT(gAudioContext.audioResetMsgBuf)); + gAudioCtx.cmdWrPos = 0; + gAudioCtx.cmdRdPos = 0; + gAudioCtx.cmdQueueFinished = 0; + gAudioCtx.taskStartQueueP = &gAudioCtx.taskStartQueue; + gAudioCtx.cmdProcQueueP = &gAudioCtx.cmdProcQueue; + gAudioCtx.audioResetQueueP = &gAudioCtx.audioResetQueue; + osCreateMesgQueue(gAudioCtx.taskStartQueueP, gAudioCtx.taskStartMsgBuf, ARRAY_COUNT(gAudioCtx.taskStartMsgBuf)); + osCreateMesgQueue(gAudioCtx.cmdProcQueueP, gAudioCtx.cmdProcMsgBuf, ARRAY_COUNT(gAudioCtx.cmdProcMsgBuf)); + osCreateMesgQueue(gAudioCtx.audioResetQueueP, gAudioCtx.audioResetMsgBuf, ARRAY_COUNT(gAudioCtx.audioResetMsgBuf)); } void Audio_QueueCmd(u32 opArgs, void** data) { - AudioCmd* cmd = &gAudioContext.cmdBuf[gAudioContext.cmdWrPos & 0xFF]; + AudioCmd* cmd = &gAudioCtx.cmdBuf[gAudioCtx.cmdWrPos & 0xFF]; cmd->opArgs = opArgs; cmd->data = *data; - gAudioContext.cmdWrPos++; + gAudioCtx.cmdWrPos++; - if (gAudioContext.cmdWrPos == gAudioContext.cmdRdPos) { - gAudioContext.cmdWrPos--; + if (gAudioCtx.cmdWrPos == gAudioCtx.cmdRdPos) { + gAudioCtx.cmdWrPos--; } } @@ -420,15 +415,14 @@ s32 Audio_ScheduleProcessCmds(void) { static s32 D_801304E8 = 0; s32 ret; - if (D_801304E8 < (u8)((gAudioContext.cmdWrPos - gAudioContext.cmdRdPos) + 0x100)) { - D_801304E8 = (u8)((gAudioContext.cmdWrPos - gAudioContext.cmdRdPos) + 0x100); + if (D_801304E8 < (u8)((gAudioCtx.cmdWrPos - gAudioCtx.cmdRdPos) + 0x100)) { + D_801304E8 = (u8)((gAudioCtx.cmdWrPos - gAudioCtx.cmdRdPos) + 0x100); } - ret = - osSendMesg(gAudioContext.cmdProcQueueP, - (OSMesg)(((gAudioContext.cmdRdPos & 0xFF) << 8) | (gAudioContext.cmdWrPos & 0xFF)), OS_MESG_NOBLOCK); + ret = osSendMesg(gAudioCtx.cmdProcQueueP, + (OSMesg)(((gAudioCtx.cmdRdPos & 0xFF) << 8) | (gAudioCtx.cmdWrPos & 0xFF)), OS_MESG_NOBLOCK); if (ret != -1) { - gAudioContext.cmdRdPos = gAudioContext.cmdWrPos; + gAudioCtx.cmdRdPos = gAudioCtx.cmdWrPos; ret = 0; } else { return -1; @@ -438,8 +432,8 @@ s32 Audio_ScheduleProcessCmds(void) { } void Audio_ResetCmdQueue(void) { - gAudioContext.cmdQueueFinished = 0; - gAudioContext.cmdRdPos = gAudioContext.cmdWrPos; + gAudioCtx.cmdQueueFinished = 0; + gAudioCtx.cmdRdPos = gAudioCtx.cmdWrPos; } void Audio_ProcessCmd(AudioCmd* cmd) { @@ -452,8 +446,8 @@ void Audio_ProcessCmd(AudioCmd* cmd) { return; } - if (cmd->arg0 < gAudioContext.audioBufferParameters.numSequencePlayers) { - seqPlayer = &gAudioContext.seqPlayers[cmd->arg0]; + if (cmd->arg0 < gAudioCtx.audioBufferParameters.numSequencePlayers) { + seqPlayer = &gAudioCtx.seqPlayers[cmd->arg0]; if (cmd->op & 0x80) { func_800E5584(cmd); return; @@ -468,7 +462,7 @@ void Audio_ProcessCmd(AudioCmd* cmd) { return; } if (cmd->arg1 == 0xFF) { - phi_v0 = gAudioContext.unk_5BDC[cmd->arg0]; + phi_v0 = gAudioCtx.unk_5BDC[cmd->arg0]; for (i = 0; i < 16; i++) { if (phi_v0 & 1) { func_800E6300(seqPlayer->channels[i], cmd); @@ -484,20 +478,20 @@ void Audio_ProcessCmds(u32 msg) { AudioCmd* cmd; u8 endPos; - if (!gAudioContext.cmdQueueFinished) { + if (!gAudioCtx.cmdQueueFinished) { curCmdRdPos = msg >> 8; } while (true) { endPos = msg & 0xFF; if (curCmdRdPos == endPos) { - gAudioContext.cmdQueueFinished = 0; + gAudioCtx.cmdQueueFinished = 0; return; } - cmd = &gAudioContext.cmdBuf[curCmdRdPos++ & 0xFF]; + cmd = &gAudioCtx.cmdBuf[curCmdRdPos++ & 0xFF]; if (cmd->op == 0xF8) { - gAudioContext.cmdQueueFinished = 1; + gAudioCtx.cmdQueueFinished = 1; return; } @@ -509,7 +503,7 @@ void Audio_ProcessCmds(u32 msg) { u32 func_800E5E20(u32* out) { u32 sp1C; - if (osRecvMesg(&gAudioContext.externalLoadQueue, (OSMesg*)&sp1C, OS_MESG_NOBLOCK) == -1) { + if (osRecvMesg(&gAudioCtx.externalLoadQueue, (OSMesg*)&sp1C, OS_MESG_NOBLOCK) == -1) { *out = 0; return 0; } @@ -522,17 +516,17 @@ u8* func_800E5E84(s32 arg0, u32* arg1) { } void Audio_GetSampleBankIdsOfFont(s32 fontId, u32* sampleBankId1, u32* sampleBankId2) { - *sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; - *sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + *sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1; + *sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2; } s32 func_800E5EDC(void) { s32 pad; s32 sp18; - if (osRecvMesg(gAudioContext.audioResetQueueP, (OSMesg*)&sp18, OS_MESG_NOBLOCK) == -1) { + if (osRecvMesg(gAudioCtx.audioResetQueueP, (OSMesg*)&sp18, OS_MESG_NOBLOCK) == -1) { return 0; - } else if (gAudioContext.audioResetSpecIdToLoad != sp18) { + } else if (gAudioCtx.audioResetSpecIdToLoad != sp18) { return -1; } else { return 1; @@ -542,7 +536,7 @@ s32 func_800E5EDC(void) { void func_800E5F34(void) { // macro? // clang-format off - s32 chk = -1; OSMesg msg; do {} while (osRecvMesg(gAudioContext.audioResetQueueP, &msg, OS_MESG_NOBLOCK) != chk); + s32 chk = -1; OSMesg msg; do {} while (osRecvMesg(gAudioCtx.audioResetQueueP, &msg, OS_MESG_NOBLOCK) != chk); // clang-format on } @@ -552,16 +546,16 @@ s32 func_800E5F88(s32 resetPreloadID) { s32 pad; func_800E5F34(); - resetStatus = gAudioContext.resetStatus; + resetStatus = gAudioCtx.resetStatus; if (resetStatus != 0) { Audio_ResetCmdQueue(); - if (gAudioContext.audioResetSpecIdToLoad == resetPreloadID) { + if (gAudioCtx.audioResetSpecIdToLoad == resetPreloadID) { return -2; } else if (resetStatus > 2) { - gAudioContext.audioResetSpecIdToLoad = resetPreloadID; + gAudioCtx.audioResetSpecIdToLoad = resetPreloadID; return -3; } else { - osRecvMesg(gAudioContext.audioResetQueueP, &msg, OS_MESG_BLOCK); + osRecvMesg(gAudioCtx.audioResetQueueP, &msg, OS_MESG_BLOCK); } } @@ -572,15 +566,15 @@ s32 func_800E5F88(s32 resetPreloadID) { } void Audio_PreNMIInternal(void) { - gAudioContext.resetTimer = 1; + gAudioCtx.resetTimer = 1; if (gAudioContextInitialized) { func_800E5F88(0); - gAudioContext.resetStatus = 0; + gAudioCtx.resetStatus = 0; } } s8 func_800E6070(s32 playerIdx, s32 channelIdx, s32 scriptIdx) { - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx]; SequenceChannel* channel; if (seqPlayer->enabled) { @@ -592,15 +586,15 @@ s8 func_800E6070(s32 playerIdx, s32 channelIdx, s32 scriptIdx) { } s8 func_800E60C4(s32 playerIdx, s32 port) { - return gAudioContext.seqPlayers[playerIdx].soundScriptIO[port]; + return gAudioCtx.seqPlayers[playerIdx].soundScriptIO[port]; } void Audio_InitExternalPool(void* ramAddr, u32 size) { - AudioHeap_InitPool(&gAudioContext.externalPool, ramAddr, size); + AudioHeap_InitPool(&gAudioCtx.externalPool, ramAddr, size); } void Audio_DestroyExternalPool(void) { - gAudioContext.externalPool.startRamAddr = NULL; + gAudioCtx.externalPool.startRamAddr = NULL; } void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) { @@ -780,8 +774,8 @@ void func_800E651C(u32 arg0, s32 arg1) { } void Audio_WaitForAudioTask(void) { - osRecvMesg(gAudioContext.taskStartQueueP, NULL, OS_MESG_NOBLOCK); - osRecvMesg(gAudioContext.taskStartQueueP, NULL, OS_MESG_BLOCK); + osRecvMesg(gAudioCtx.taskStartQueueP, NULL, OS_MESG_NOBLOCK); + osRecvMesg(gAudioCtx.taskStartQueueP, NULL, OS_MESG_BLOCK); } s32 func_800E6590(s32 playerIdx, s32 arg1, s32 arg2) { @@ -792,7 +786,7 @@ s32 func_800E6590(s32 playerIdx, s32 arg1, s32 arg2) { s32 loopEnd; s32 samplePos; - seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + seqPlayer = &gAudioCtx.seqPlayers[playerIdx]; if (seqPlayer->enabled && seqPlayer->channels[arg1]->enabled) { layer = seqPlayer->channels[arg1]->layers[arg2]; if (layer == NULL) { @@ -841,8 +835,8 @@ s32 func_800E66C0(s32 arg0) { TunedSample* tunedSample; phi_v1 = 0; - for (i = 0; i < gAudioContext.numNotes; i++) { - note = &gAudioContext.notes[i]; + for (i = 0; i < gAudioCtx.numNotes; i++) { + note = &gAudioCtx.notes[i]; playbackState = ¬e->playbackState; if (note->noteSubEu.bitField0.enabled) { noteSubEu = ¬e->noteSubEu; @@ -859,7 +853,7 @@ s32 func_800E66C0(s32 arg0) { phi_v1++; if ((arg0 & 1) == 1) { - playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv; playbackState->adsr.action.s.release = 1; } } @@ -871,8 +865,8 @@ s32 func_800E66C0(s32 arg0) { u32 Audio_NextRandom(void) { static u32 audRand = 0x12345678; - audRand = ((osGetCount() + 0x1234567) * (audRand + gAudioContext.totalTaskCount)); - audRand += gAudioContext.audioRandom; + audRand = ((osGetCount() + 0x1234567) * (audRand + gAudioCtx.totalTaskCount)); + audRand += gAudioCtx.audioRandom; return audRand; } diff --git a/src/code/code_800EC960.c b/src/code/code_800EC960.c index c34d00a6bb..f729319af3 100644 --- a/src/code/code_800EC960.c +++ b/src/code/code_800EC960.c @@ -2200,7 +2200,7 @@ s32 AudioOcarina_MemoryGameNextNote(void) { } void AudioOcarina_Update(void) { - sOcarinaUpdateTaskStart = gAudioContext.totalTaskCount; + sOcarinaUpdateTaskStart = gAudioCtx.totalTaskCount; if (sOcarinaInstrumentId != OCARINA_INSTRUMENT_OFF) { if (sIsOcarinaInputEnabled == true) { AudioOcarina_ReadControllerInput(); @@ -2404,7 +2404,7 @@ void AudioDebug_Draw(GfxPrint* printer) { GfxPrint_Printf(printer, "- %s -", sAudioDebugPageNames[sAudioDebugPage]); for (i = 0; i < gAudioSpecs[gAudioSpecId].numNotes; i++) { - if (gAudioContext.notes[i].noteSubEu.bitField0.enabled == 1) { + if (gAudioCtx.notes[i].noteSubEu.bitField0.enabled == 1) { numEnabledNotes++; } } @@ -2529,7 +2529,7 @@ void AudioDebug_Draw(GfxPrint* printer) { for (k2 = 0; k2 < gChannelsPerBank[gSfxChannelLayout][k]; k2++) { #define entryIndex (gActiveSfx[k][k2].entryIndex) #define entry (&gSfxBanks[k][entryIndex]) -#define chan (gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[entry->channelIdx]) +#define chan (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[entry->channelIdx]) GfxPrint_SetPos(printer, 2 + sAudioIntInfoX, 5 + ind + sAudioIntInfoY); if (sAudioIntInfoBankPage[k] == 1) { if ((entryIndex != 0xFF) && @@ -2692,14 +2692,14 @@ void AudioDebug_Draw(GfxPrint* printer) { GfxPrint_Printf(printer, "%1X", i); GfxPrint_SetPos(printer, 15 + i, 7); - if (gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->enabled) { + if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->enabled) { GfxPrint_Printf(printer, "O"); } else { GfxPrint_Printf(printer, "X"); } GfxPrint_SetPos(printer, 15 + i, 8); - if (gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->stopSomething2) { + if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->stopSomething2) { GfxPrint_Printf(printer, "O"); } else { GfxPrint_Printf(printer, "X"); @@ -2708,7 +2708,7 @@ void AudioDebug_Draw(GfxPrint* printer) { GfxPrint_SetPos(printer, 15 + i, 9); ctr = 0; for (j = 0; j < 4; j++) { - if (gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->layers[j] != NULL) { + if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->layers[j] != NULL) { ctr++; } } @@ -2763,33 +2763,32 @@ void AudioDebug_Draw(GfxPrint* printer) { for (i = 0; i < 8; i++) { GfxPrint_SetPos(printer, 15 + 3 * i, 22); GfxPrint_Printf(printer, "%02X ", - (u8)gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + (u8)gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->soundScriptIO[i]); } - if (gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->enabled) { + if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->enabled) { GfxPrint_SetPos(printer, 15, 11); GfxPrint_Printf(printer, "%d", - (u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->volume * 127.1)); GfxPrint_SetPos(printer, 15, 12); GfxPrint_Printf(printer, "%d", - (u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->volumeScale * 127.1)); GfxPrint_SetPos(printer, 15, 13); - GfxPrint_Printf(printer, "%X", - gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] - .channels[sAudioSubTrackInfoChannelSel] - ->fontId); + GfxPrint_Printf( + printer, "%X", + gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->fontId); - ctr = (u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + ctr = (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->instOrWave); @@ -2805,46 +2804,44 @@ void AudioDebug_Draw(GfxPrint* printer) { GfxPrint_Printf(printer, "%d", ctr2); GfxPrint_SetPos(printer, 15, 15); - GfxPrint_Printf(printer, "%d", - gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] - .channels[sAudioSubTrackInfoChannelSel] - ->newPan); + GfxPrint_Printf( + printer, "%d", + gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->newPan); GfxPrint_SetPos(printer, 15, 16); GfxPrint_Printf(printer, "%d", - gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->panChannelWeight); GfxPrint_SetPos(printer, 15, 17); - GfxPrint_Printf(printer, "%d", - gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] - .channels[sAudioSubTrackInfoChannelSel] - ->reverb); + GfxPrint_Printf( + printer, "%d", + gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->reverb); GfxPrint_SetPos(printer, 15, 18); GfxPrint_Printf(printer, "%d", - gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->notePriority); GfxPrint_SetPos(printer, 15, 19); GfxPrint_Printf(printer, "%d", - (u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->vibratoRateTarget / 32)); GfxPrint_SetPos(printer, 15, 20); GfxPrint_Printf(printer, "%d", - (u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->vibratoExtentTarget / 8)); GfxPrint_SetPos(printer, 15, 21); GfxPrint_Printf(printer, "%d", - (u16)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + (u16)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->freqScale * 100)); @@ -2858,47 +2855,46 @@ void AudioDebug_Draw(GfxPrint* printer) { GfxPrint_SetPos(printer, 3, 5); GfxPrint_Printf(printer, "DRIVER %05X / %05X", - gAudioContext.miscPool.curRamAddr - gAudioContext.miscPool.startRamAddr, - gAudioContext.miscPool.size); + gAudioCtx.miscPool.curRamAddr - gAudioCtx.miscPool.startRamAddr, gAudioCtx.miscPool.size); GfxPrint_SetPos(printer, 3, 6); GfxPrint_Printf( - printer, "AT-SEQ %02X-%02X (%05X-%05X / %05X)", (u8)gAudioContext.seqCache.temporary.entries[0].id, - (u8)gAudioContext.seqCache.temporary.entries[1].id, gAudioContext.seqCache.temporary.entries[0].size, - gAudioContext.seqCache.temporary.entries[1].size, gAudioContext.seqCache.temporary.pool.size); + printer, "AT-SEQ %02X-%02X (%05X-%05X / %05X)", (u8)gAudioCtx.seqCache.temporary.entries[0].id, + (u8)gAudioCtx.seqCache.temporary.entries[1].id, gAudioCtx.seqCache.temporary.entries[0].size, + gAudioCtx.seqCache.temporary.entries[1].size, gAudioCtx.seqCache.temporary.pool.size); GfxPrint_SetPos(printer, 3, 7); GfxPrint_Printf( - printer, "AT-BNK %02X-%02X (%05X-%05X / %05X)", (u8)gAudioContext.fontCache.temporary.entries[0].id, - (u8)gAudioContext.fontCache.temporary.entries[1].id, gAudioContext.fontCache.temporary.entries[0].size, - gAudioContext.fontCache.temporary.entries[1].size, gAudioContext.fontCache.temporary.pool.size); + printer, "AT-BNK %02X-%02X (%05X-%05X / %05X)", (u8)gAudioCtx.fontCache.temporary.entries[0].id, + (u8)gAudioCtx.fontCache.temporary.entries[1].id, gAudioCtx.fontCache.temporary.entries[0].size, + gAudioCtx.fontCache.temporary.entries[1].size, gAudioCtx.fontCache.temporary.pool.size); GfxPrint_SetPos(printer, 3, 8); - GfxPrint_Printf(printer, "ST-SEQ %02Xseqs (%05X / %06X)", gAudioContext.seqCache.persistent.numEntries, - gAudioContext.seqCache.persistent.pool.curRamAddr - - gAudioContext.seqCache.persistent.pool.startRamAddr, - gAudioContext.seqCache.persistent.pool.size); + GfxPrint_Printf(printer, "ST-SEQ %02Xseqs (%05X / %06X)", gAudioCtx.seqCache.persistent.numEntries, + gAudioCtx.seqCache.persistent.pool.curRamAddr - + gAudioCtx.seqCache.persistent.pool.startRamAddr, + gAudioCtx.seqCache.persistent.pool.size); - for (k = 0; (u32)k < gAudioContext.seqCache.persistent.numEntries; k++) { + for (k = 0; (u32)k < gAudioCtx.seqCache.persistent.numEntries; k++) { GfxPrint_SetPos(printer, 3 + 3 * k, 9); - GfxPrint_Printf(printer, "%02x", gAudioContext.seqCache.persistent.entries[k].id); + GfxPrint_Printf(printer, "%02x", gAudioCtx.seqCache.persistent.entries[k].id); } GfxPrint_SetPos(printer, 3, 10); - GfxPrint_Printf(printer, "ST-BNK %02Xbanks (%05X / %06X)", gAudioContext.fontCache.persistent.numEntries, - gAudioContext.fontCache.persistent.pool.curRamAddr - - gAudioContext.fontCache.persistent.pool.startRamAddr, - gAudioContext.fontCache.persistent.pool.size); + GfxPrint_Printf(printer, "ST-BNK %02Xbanks (%05X / %06X)", gAudioCtx.fontCache.persistent.numEntries, + gAudioCtx.fontCache.persistent.pool.curRamAddr - + gAudioCtx.fontCache.persistent.pool.startRamAddr, + gAudioCtx.fontCache.persistent.pool.size); - for (k = 0; (u32)k < gAudioContext.fontCache.persistent.numEntries; k++) { + for (k = 0; (u32)k < gAudioCtx.fontCache.persistent.numEntries; k++) { GfxPrint_SetPos(printer, 3 + 3 * k, 11); - GfxPrint_Printf(printer, "%02x", gAudioContext.fontCache.persistent.entries[k].id); + GfxPrint_Printf(printer, "%02x", gAudioCtx.fontCache.persistent.entries[k].id); } GfxPrint_SetPos(printer, 3, 12); GfxPrint_Printf(printer, "E-MEM %05X / %05X", - gAudioContext.permanentPool.curRamAddr - gAudioContext.permanentPool.startRamAddr, - gAudioContext.permanentPool.size); + gAudioCtx.permanentPool.curRamAddr - gAudioCtx.permanentPool.startRamAddr, + gAudioCtx.permanentPool.size); break; case PAGE_BLOCK_CHANGE_BGM: @@ -2917,34 +2913,34 @@ void AudioDebug_Draw(GfxPrint* printer) { SETCOL(255, 255, 255); GfxPrint_SetPos(printer, 3, 7); GfxPrint_Printf(printer, "NEXT SCENE %02X %s", - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2], - sAudioSceneNames[(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2]]); + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2], + sAudioSceneNames[(u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2]]); GfxPrint_SetPos(printer, 3, 8); GfxPrint_Printf(printer, "NOW SCENE %02X %s", - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4], - sAudioSceneNames[(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4]]); + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4], + sAudioSceneNames[(u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4]]); GfxPrint_SetPos(printer, 3, 9); GfxPrint_Printf(printer, "NOW BLOCK %02X", - (gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5] + 1) & 0xFF); + (gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5] + 1) & 0xFF); GfxPrint_SetPos(printer, 3, 11); GfxPrint_Printf(printer, "PORT"); GfxPrint_SetPos(printer, 3, 12); GfxPrint_Printf(printer, "%02X %02X %02X %02X", - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[0], - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[1], - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2], - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]); + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[0], + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[1], + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2], + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]); GfxPrint_SetPos(printer, 3, 13); GfxPrint_Printf(printer, "%02X %02X %02X %02X", - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4], - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5], - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[6], - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[7]); + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4], + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5], + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[6], + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[7]); break; case PAGE_OCARINA_TEST: @@ -3682,7 +3678,7 @@ void func_800F5CF8(void); */ void func_800F3054(void) { if (func_800FAD34() == 0) { - sAudioUpdateTaskStart = gAudioContext.totalTaskCount; + sAudioUpdateTaskStart = gAudioCtx.totalTaskCount; sAudioUpdateStartTime = osGetTime(); AudioOcarina_Update(); Audio_StepFreqLerp(&sRiverFreqScaleLerp); @@ -3700,7 +3696,7 @@ void func_800F3054(void) { AudioDebug_SetInput(); AudioDebug_ProcessInput(); Audio_ScheduleProcessCmds(); - sAudioUpdateTaskEnd = gAudioContext.totalTaskCount; + sAudioUpdateTaskEnd = gAudioCtx.totalTaskCount; sAudioUpdateEndTime = osGetTime(); } } @@ -3774,9 +3770,9 @@ s8 Audio_ComputeSfxReverb(u8 bankId, u8 entryIdx, u8 channelIdx) { } } - if (IS_SEQUENCE_CHANNEL_VALID(gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx])) { - scriptAdd = gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1]; - if (gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1] < 0) { + if (IS_SEQUENCE_CHANNEL_VALID(gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx])) { + scriptAdd = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1]; + if (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1] < 0) { scriptAdd = 0; } } @@ -3843,7 +3839,7 @@ f32 Audio_ComputeSfxFreqScale(u8 bankId, u8 entryIdx) { f32 freq = 1.0f; if (entry->sfxParams & SFX_FLAG_14) { - freq = 1.0f - ((gAudioContext.audioRandom & 0xF) / 192.0f); + freq = 1.0f - ((gAudioCtx.audioRandom & 0xF) / 192.0f); } switch (bankId) { @@ -3867,7 +3863,7 @@ f32 Audio_ComputeSfxFreqScale(u8 bankId, u8 entryIdx) { if (phi_v0 == 1) { if (!(entry->sfxParams & SFX_FLAG_11)) { - freq *= (1.0293 - ((gAudioContext.audioRandom & 0xF) / 144.0f)); + freq *= (1.0293 - ((gAudioCtx.audioRandom & 0xF) / 144.0f)); } } @@ -4109,7 +4105,7 @@ void func_800F4010(Vec3f* pos, u16 sfxId, f32 arg2) { sp24 = 1.0f; } else { phi_f0 = 1.1f; - phi_v0 = gAudioContext.audioRandom % 2; + phi_v0 = gAudioCtx.audioRandom % 2; } if ((phi_f0 < arg2) && (phi_v0 != 0)) { @@ -4311,15 +4307,13 @@ s32 Audio_SetGanonsTowerBgmVolume(u8 targetVol) { // Sets the reverb for (channelIdx = 0; channelIdx < 16; channelIdx++) { - if (gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx] != - &gAudioContext.sequenceChannelNone) { + if (gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx] != &gAudioCtx.sequenceChannelNone) { // soundScriptIO[5] is set to 0x40 in channels 0, 1, and 4 - if ((u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] != 0xFF) { + if ((u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] != 0xFF) { // Higher volume leads to lower reverb - reverb = - ((u16)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] - - targetVol) + - 0x7F; + reverb = ((u16)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] - + targetVol) + + 0x7F; if (reverb > 0x7F) { reverb = 0x7F; } @@ -4495,7 +4489,7 @@ void Audio_SplitBgmChannels(s8 volSplit) { channelBits = 0; for (channelIdx = 0; channelIdx < 16; channelIdx++) { - if (notePriority > gAudioContext.seqPlayers[bgmPlayers[i]].channels[channelIdx]->notePriority) { + if (notePriority > gAudioCtx.seqPlayers[bgmPlayers[i]].channels[channelIdx]->notePriority) { // If the note currently playing in the channel is a high enough priority, // then keep the channel on by setting a channelBit // If this condition fails, then the channel will be shut off @@ -4601,7 +4595,7 @@ void func_800F56A8(void) { bvar = temp_v0 & 0xFF; if ((temp_v0 != NA_BGM_DISABLED) && (sSeqFlags[bvar] & SEQ_FLAG_4)) { if (D_8013062C != 0xC0) { - D_8013062C = gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]; + D_8013062C = gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]; } else { D_8013062C = 0; } diff --git a/src/code/code_800F7260.c b/src/code/code_800F7260.c index 1f8e2b891e..c73992f177 100644 --- a/src/code/code_800F7260.c +++ b/src/code/code_800F7260.c @@ -441,7 +441,7 @@ void Audio_PlayActiveSfx(u8 bankId) { entryIndex = gActiveSfx[bankId][i].entryIndex; if (entryIndex != 0xFF) { entry = &gSfxBanks[bankId][entryIndex]; - channel = gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIdx]; + channel = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIdx]; if (entry->state == SFX_STATE_READY) { entry->channelIdx = sCurSfxPlayerChannelIdx; if (entry->sfxParams & SFX_FLAG_3) { @@ -661,7 +661,7 @@ void Audio_StepUnusedBankLerp(u8 bankId) { void func_800F8F88(void) { u8 bankId; - if (IS_SEQUENCE_CHANNEL_VALID(gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[0])) { + if (IS_SEQUENCE_CHANNEL_VALID(gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[0])) { sCurSfxPlayerChannelIdx = 0; for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) { Audio_ChooseActiveSfx(bankId); diff --git a/src/code/code_800F9280.c b/src/code/code_800F9280.c index 00df77801b..115789fe5f 100644 --- a/src/code/code_800F9280.c +++ b/src/code/code_800F9280.c @@ -45,12 +45,12 @@ void Audio_StartSequence(u8 seqPlayerIndex, u8 seqId, u8 seqArgs, u16 fadeInDura seqArgs &= 0x7F; if (seqArgs == 0x7F) { // `fadeInDuration` is interpreted as skip ticks - duration = (fadeInDuration >> 3) * 60 * gAudioContext.audioBufferParameters.updatesPerFrame; + duration = (fadeInDuration >> 3) * 60 * gAudioCtx.audioBufferParameters.updatesPerFrame; Audio_QueueCmdS32(0x85000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(seqId, 8, 8), duration); } else { // `fadeInDuration` is interpreted as number of frames at 30 fps Audio_QueueCmdS32(0x82000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(seqId, 8, 8), - (fadeInDuration * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4); + (fadeInDuration * (u16)gAudioCtx.audioBufferParameters.updatesPerFrame) / 4); } gActiveSeqs[seqPlayerIndex].seqId = seqId | (seqArgs << 8); @@ -78,7 +78,7 @@ void Audio_StartSequence(u8 seqPlayerIndex, u8 seqId, u8 seqArgs, u16 fadeInDura void Audio_StopSequence(u8 seqPlayerIndex, u16 fadeOutDuration) { Audio_QueueCmdS32(0x83000000 | ((u8)seqPlayerIndex << 16), - (fadeOutDuration * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4); + (fadeOutDuration * (u16)gAudioCtx.audioBufferParameters.updatesPerFrame) / 4); gActiveSeqs[seqPlayerIndex].seqId = NA_BGM_DISABLED; } @@ -408,7 +408,7 @@ void Audio_ProcessSeqCmds(void) { } u16 Audio_GetActiveSeqId(u8 seqPlayerIndex) { - if (!gAudioContext.seqPlayers[seqPlayerIndex].enabled) { + if (!gAudioCtx.seqPlayers[seqPlayerIndex].enabled) { return NA_BGM_DISABLED; } return gActiveSeqs[seqPlayerIndex].seqId; @@ -541,8 +541,8 @@ void Audio_UpdateActiveSequences(void) { } // Process tempo commands - if (gAudioContext.seqPlayers[seqPlayerIndex].enabled) { - tempoPrev = gAudioContext.seqPlayers[seqPlayerIndex].tempo / TATUMS_PER_BEAT; + if (gAudioCtx.seqPlayers[seqPlayerIndex].enabled) { + tempoPrev = gAudioCtx.seqPlayers[seqPlayerIndex].tempo / TATUMS_PER_BEAT; tempoOp = (tempoCmd & 0xF000) >> 12; switch (tempoOp) { case SEQCMD_SUB_OP_TEMPO_SPEED_UP: @@ -583,7 +583,7 @@ void Audio_UpdateActiveSequences(void) { } gActiveSeqs[seqPlayerIndex].tempoTarget = tempoTarget; - gActiveSeqs[seqPlayerIndex].tempoCur = gAudioContext.seqPlayers[seqPlayerIndex].tempo / TATUMS_PER_BEAT; + gActiveSeqs[seqPlayerIndex].tempoCur = gAudioCtx.seqPlayers[seqPlayerIndex].tempo / TATUMS_PER_BEAT; gActiveSeqs[seqPlayerIndex].tempoStep = (gActiveSeqs[seqPlayerIndex].tempoCur - gActiveSeqs[seqPlayerIndex].tempoTarget) / tempoTimer; gActiveSeqs[seqPlayerIndex].tempoTimer = tempoTimer; @@ -659,7 +659,7 @@ void Audio_UpdateActiveSequences(void) { // Only process setup commands if `seqPlayerIndex` if no longer playing // i.e. the `seqPlayer` is no longer enabled - if (gAudioContext.seqPlayers[seqPlayerIndex].enabled) { + if (gAudioCtx.seqPlayers[seqPlayerIndex].enabled) { continue; }