summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorzelda2774 <69368340+zelda2774@users.noreply.github.com>2020-09-20 19:22:09 +0200
committerGitHub <noreply@github.com>2020-09-20 13:22:09 -0400
commit055d1d2baeef17f1f9c3fbe5bfb643cc38fc3873 (patch)
tree56dbf627325d337dd1b7ae214f1422df602b6f0c /src/code
parent90188416602be3691f4381a0fad40c3850a6e213 (diff)
audio_heap: 1 non-matching (#381)
* Audio_AllocDmaMemory * Audio_AllocDmaMemoryZeroed * func_800DE238 * Audio_SessionPoolsInit * func_800DE2B0 * func_800DE258 * Audio_DiscardSequence * Audio_DiscardBank * func_800DE12C * Audio_ResetLoadStatus * func_800DDE3C * func_800DDE20 * Audio_InitMainPools * Audio_SoundAllocPoolInit * Audio_PersistentPoolClear * Audio_TemporaryPoolClear * func_800DE4A0 * Audio_PersistentPoolsInit * Audio_TemporaryPoolsInit * Formatting * Audio_SeqAndBankPoolInit * Audio_Alloc * Audio_AllocZeroed * func_800DE4B0 * func_800DF0CC * func_800DF074 * func_800DF1D8 * func_800DF688 * func_800DF5DC, func_800DF630 * func_800DF7BC * func_800DF7C4 * func_800DF888 * Fix AudioBufferParameters * Audio_ResetStep * Struct work * oops * structsss * wip on func_800DFBF8 * func_800E04E8 * func_800E0540 * func_800E0964 * func_800E1148 * func_800DF5AC * func_800E0E6C * func_800E0E90 * func_800E0BF8 * func_800E0634 * func_800E05C4 * func_800E0CBC * func_800E0C80 * naming * func_800E0BB4 * func_800E0AD8 * func_800E0E0C * func_800E0EB4 * func_800E06CC * Audio_AllocBankOrSeq * Use true/false macros * fixup * Format * comments * review * unk instrument -> sfx * Reword comment * Change AVOID_UB to a comment Co-authored-by: zelda2774 <zelda2774@invalid>
Diffstat (limited to 'src/code')
-rw-r--r--src/code/audio_effects.c14
-rw-r--r--src/code/audio_heap.c1380
-rw-r--r--src/code/audio_playback.c84
-rw-r--r--src/code/audio_seqplayer.c122
4 files changed, 1439 insertions, 161 deletions
diff --git a/src/code/audio_effects.c b/src/code/audio_effects.c
index 180f80aba..41f727771 100644
--- a/src/code/audio_effects.c
+++ b/src/code/audio_effects.c
@@ -21,7 +21,7 @@ void Audio_SequenceChannelProcessSound(SequenceChannel* seqChannel, s32 recalcul
chanFreqScale = seqChannel->freqScale;
if (b != 0) {
chanFreqScale *= seqChannel->seqPlayer->unk_34;
- seqChannel->changes.s.freqScale = 1;
+ seqChannel->changes.s.freqScale = true;
}
for (i = 0; i < 4; i++) {
@@ -31,7 +31,7 @@ void Audio_SequenceChannelProcessSound(SequenceChannel* seqChannel, s32 recalcul
layer->noteFreqScale = layer->freqScale * chanFreqScale;
layer->noteVelocity = layer->velocitySquare2 * seqChannel->appliedVolume;
layer->notePan = (seqChannel->pan + layer->pan * (0x80 - seqChannel->panChannelWeight)) >> 7;
- layer->notePropertiesNeedInit = 0;
+ layer->notePropertiesNeedInit = false;
} else {
if (seqChannel->changes.s.freqScale) {
layer->noteFreqScale = layer->freqScale * chanFreqScale;
@@ -53,7 +53,7 @@ void Audio_SequencePlayerProcessSound(SequencePlayer* seqPlayer) {
if (seqPlayer->fadeTimer != 0) {
seqPlayer->fadeVolume += seqPlayer->fadeVelocity;
- seqPlayer->recalculateVolume = 1;
+ seqPlayer->recalculateVolume = true;
if (seqPlayer->fadeVolume > 1.0f) {
seqPlayer->fadeVolume = 1.0f;
@@ -78,7 +78,7 @@ void Audio_SequencePlayerProcessSound(SequencePlayer* seqPlayer) {
}
}
- seqPlayer->recalculateVolume = 0;
+ seqPlayer->recalculateVolume = false;
}
f32 Audio_GetPortamentoFreqScale(Portamento* p) {
@@ -258,7 +258,7 @@ f32 Audio_AdsrUpdate(AdsrState* adsr) {
break;
default:
- adsr->delay *= gAudioContext.unk_286C;
+ adsr->delay *= gAudioContext.gAudioBufferParameters.unk_24;
if (adsr->delay == 0) {
adsr->delay = 1;
}
@@ -313,12 +313,12 @@ f32 Audio_AdsrUpdate(AdsrState* adsr) {
if (adsr->action.s.decay) {
adsr->action.s.state = ADSR_STATE_DECAY;
- adsr->action.s.decay = 0;
+ adsr->action.s.decay = false;
}
if (adsr->action.s.release) {
adsr->action.s.state = ADSR_STATE_RELEASE;
- adsr->action.s.release = 0;
+ adsr->action.s.release = false;
}
if (adsr->current < 0.0f) {
diff --git a/src/code/audio_heap.c b/src/code/audio_heap.c
index 04d4ae7f6..974f5eb56 100644
--- a/src/code/audio_heap.c
+++ b/src/code/audio_heap.c
@@ -1,106 +1,1384 @@
#include <ultra64.h>
#include <global.h>
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DDE20.s")
+f32 func_800DDE20(f32 arg0) {
+ return 256.0f * gAudioContext.gAudioBufferParameters.unkUpdatesPerFrameScaled / arg0;
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DDE3C.s")
+void func_800DDE3C(void) {
+ s32 i;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DDF80.s")
+ gAudioContext.unk_3520[255] = func_800DDE20(0.25f);
+ gAudioContext.unk_3520[254] = func_800DDE20(0.33f);
+ gAudioContext.unk_3520[253] = func_800DDE20(0.5f);
+ gAudioContext.unk_3520[252] = func_800DDE20(0.66f);
+ gAudioContext.unk_3520[251] = func_800DDE20(0.75f);
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DE048.s")
+ for (i = 128; i < 251; i++) {
+ gAudioContext.unk_3520[i] = func_800DDE20(251 - i);
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DE12C.s")
+ for (i = 16; i < 128; i++) {
+ gAudioContext.unk_3520[i] = func_800DDE20(4 * (143 - i));
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DE1B4.s")
+ for (i = 1; i < 16; i++) {
+ gAudioContext.unk_3520[i] = func_800DDE20(60 * (23 - i));
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DE238.s")
+ gAudioContext.unk_3520[0] = 0.0f;
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DE258.s")
+void Audio_ResetLoadStatus(void) {
+ s32 i;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DE2B0.s")
+ for (i = 0; i < 0x30; i++) {
+ if (gAudioContext.gBankLoadStatus[i] != 5) {
+ gAudioContext.gBankLoadStatus[i] = 0;
+ }
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/Audio_AllocDmaMemory.s")
+ for (i = 0; i < 0x30; i++) {
+ if (gAudioContext.gUnusedLoadStatus[i] != 5) {
+ gAudioContext.gUnusedLoadStatus[i] = 0;
+ }
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DE344.s")
+ for (i = 0; i < 0x80; i++) {
+ if (gAudioContext.gSeqLoadStatus[i] != 5) {
+ gAudioContext.gSeqLoadStatus[i] = 0;
+ }
+ }
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/Audio_AllocZeroed.s")
+void Audio_DiscardBank(s32 bankId) {
+ s32 i;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/Audio_Alloc.s")
+ for (i = 0; i < gAudioContext.gMaxSimultaneousNotes; i++) {
+ Note* note = &gAudioContext.gNotes[i];
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/Audio_SoundAllocPoolInit.s")
+ if (note->playbackState.bankId == bankId) {
+ if (note->playbackState.unk_04 == 0 && note->playbackState.priority != 0) {
+ note->playbackState.parentLayer->enabled = false;
+ note->playbackState.parentLayer->finished = true;
+ }
+ Audio_NoteDisable(note);
+ Audio_AudioListRemove(&note->listItem);
+ Audio_AudioListPushBack(&gNoteFreeLists.disabled, &note->listItem);
+ }
+ }
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/Audio_PersistentPoolClear.s")
+void func_800DE12C(s32 bankId) {
+ s32 i;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/Audio_TemporaryPoolClear.s")
+ for (i = 0; i < gAudioContext.gMaxSimultaneousNotes; i++) {
+ Note* note = &gAudioContext.gNotes[i];
+ NotePlaybackState* state = &note->playbackState;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DE4A0.s")
+ if (state->bankId == bankId) {
+ if (state->priority != 0 && state->adsr.action.s.state == ADSR_STATE_DECAY) {
+ state->priority = 1;
+ state->adsr.fadeOutVel = gAudioContext.gAudioBufferParameters.updatesPerFrameInv;
+ state->adsr.action.s.release = true;
+ }
+ }
+ }
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DE4B0.s")
+void Audio_DiscardSequence(s32 seqId) {
+ s32 i;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/Audio_InitMainPools.s")
+ for (i = 0; i < gAudioContext.gAudioBufferParameters.numSequencePlayers; i++) {
+ if (gAudioContext.gSequencePlayers[i].enabled && gAudioContext.gSequencePlayers[i].seqId == seqId) {
+ Audio_SequencePlayerDisable(&gAudioContext.gSequencePlayers[i]);
+ }
+ }
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/Audio_SessionPoolsInit.s")
+void func_800DE238(void* mem, u32 size) {
+ func_800E6880(mem, size);
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/Audio_SeqAndBankPoolInit.s")
+void* func_800DE258(SoundAllocPool* pool, u32 size) {
+ void* ret = NULL;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/Audio_PersistentPoolsInit.s")
+ if (gAudioContext.gUnkPool.start != 0) {
+ ret = Audio_AllocZeroed(&gAudioContext.gUnkPool, size);
+ }
+ if (ret == NULL) {
+ ret = Audio_AllocZeroed(pool, size);
+ }
+ return ret;
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/Audio_TemporaryPoolsInit.s")
+void* func_800DE2B0(SoundAllocPool* pool, u32 size) {
+ void* ret = NULL;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/Audio_AllocBankOrSeq.s")
+ if (gAudioContext.gUnkPool.start != NULL) {
+ ret = Audio_Alloc(&gAudioContext.gUnkPool, size);
+ }
+ if (ret == NULL) {
+ ret = Audio_Alloc(pool, size);
+ }
+ return ret;
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DF074.s")
+void* Audio_AllocDmaMemory(SoundAllocPool* pool, u32 size) {
+ void* ret;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DF0CC.s")
+ ret = Audio_Alloc(pool, size);
+ if (ret != NULL) {
+ func_800DE238(ret, size);
+ }
+ return ret;
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DF1D8.s")
+void* Audio_AllocDmaMemoryZeroed(SoundAllocPool* pool, u32 size) {
+ void* ret;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DF5AC.s")
+ ret = Audio_AllocZeroed(pool, size);
+ if (ret != NULL) {
+ func_800DE238(ret, size);
+ }
+ return ret;
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DF5DC.s")
+void* Audio_AllocZeroed(SoundAllocPool* pool, u32 size) {
+ u8* ret = Audio_Alloc(pool, size);
+ u8* ptr;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DF630.s")
+ if (ret != NULL) {
+ for (ptr = ret; ptr < pool->cur; ptr++) {
+ *ptr = 0;
+ }
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DF688.s")
+ return ret;
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DF7BC.s")
+void* Audio_Alloc(SoundAllocPool* pool, u32 size) {
+ u32 aligned = ALIGN16(size);
+ u8* ret = pool->cur;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DF7C4.s")
+ if (pool->start + pool->size >= pool->cur + aligned) {
+ pool->cur += aligned;
+ } else {
+ return NULL;
+ }
+ pool->unused++;
+ return ret;
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DF888.s")
+void Audio_SoundAllocPoolInit(SoundAllocPool* pool, void* memAddr, u32 size) {
+ pool->cur = pool->start = (u8*)ALIGN16((u32)memAddr);
+ pool->size = size - ((u32)memAddr & 0xF);
+ pool->unused = 0;
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DF8F4.s")
+void Audio_PersistentPoolClear(PersistentPool* persistent) {
+ persistent->pool.unused = 0;
+ persistent->numEntries = 0;
+ persistent->pool.cur = persistent->pool.start;
+}
+void Audio_TemporaryPoolClear(TemporaryPool* temporary) {
+ temporary->pool.unused = 0;
+ temporary->pool.cur = temporary->pool.start;
+ temporary->nextSide = 0;
+ temporary->entries[0].ptr = temporary->pool.start;
+ temporary->entries[1].ptr = temporary->pool.start + temporary->pool.size;
+ temporary->entries[0].id = -1;
+ temporary->entries[1].id = -1;
+}
+
+void func_800DE4A0(SoundAllocPool* pool) {
+ pool->unused = 0;
+ pool->cur = pool->start;
+}
+
+void func_800DE4B0(s32 poolIdx) {
+ SoundMultiPool* loadedPool;
+ SoundAllocPool* persistentPool;
+ PersistentPool* persistent;
+ void* entryPtr;
+ u8* table;
+
+ switch (poolIdx) {
+ case 0:
+ loadedPool = &gAudioContext.gSeqLoadedPool;
+ table = gAudioContext.gSeqLoadStatus;
+ break;
+ case 1:
+ loadedPool = &gAudioContext.gBankLoadedPool;
+ table = gAudioContext.gBankLoadStatus;
+ break;
+ case 2:
+ loadedPool = &gAudioContext.gUnusedLoadedPool;
+ table = gAudioContext.gUnusedLoadStatus;
+ break;
+ }
+
+ persistent = &loadedPool->persistent;
+ persistentPool = &persistent->pool;
+
+ if (persistent->numEntries == 0) {
+ return;
+ }
+
+ entryPtr = persistent->entries[persistent->numEntries - 1].ptr;
+ persistentPool->cur = entryPtr;
+ persistentPool->unused--;
+
+ if (poolIdx == 2) {
+ func_800E0E6C(persistent->entries[persistent->numEntries - 1].id);
+ }
+ if (poolIdx == 1) {
+ Audio_DiscardBank(persistent->entries[persistent->numEntries - 1].id);
+ }
+ table[persistent->entries[persistent->numEntries - 1].id] = 0;
+ persistent->numEntries--;
+}
+
+void Audio_InitMainPools(s32 sizeForAudioInitPool) {
+ Audio_SoundAllocPoolInit(&gAudioContext.gAudioInitPool, gAudioContext.gAudioHeap, sizeForAudioInitPool);
+ Audio_SoundAllocPoolInit(&gAudioContext.gAudioSessionPool, gAudioContext.gAudioHeap + sizeForAudioInitPool,
+ gAudioContext.gAudioHeapSize - sizeForAudioInitPool);
+ gAudioContext.gUnkPool.start = NULL;
+}
+
+void Audio_SessionPoolsInit(AudioPoolSplit4* split) {
+ gAudioContext.gAudioSessionPool.cur = gAudioContext.gAudioSessionPool.start;
+ Audio_SoundAllocPoolInit(&gAudioContext.gNotesAndBuffersPool,
+ Audio_Alloc(&gAudioContext.gAudioSessionPool, split->wantSeq), split->wantSeq);
+ Audio_SoundAllocPoolInit(&gAudioContext.gSeqAndBankPool,
+ Audio_Alloc(&gAudioContext.gAudioSessionPool, split->wantCustom), split->wantCustom);
+}
+
+void Audio_SeqAndBankPoolInit(AudioPoolSplit2* split) {
+ gAudioContext.gSeqAndBankPool.cur = gAudioContext.gSeqAndBankPool.start;
+ Audio_SoundAllocPoolInit(&gAudioContext.gPersistentCommonPool,
+ Audio_Alloc(&gAudioContext.gSeqAndBankPool, split->wantPersistent), split->wantPersistent);
+ Audio_SoundAllocPoolInit(&gAudioContext.gTemporaryCommonPool,
+ Audio_Alloc(&gAudioContext.gSeqAndBankPool, split->wantTemporary), split->wantTemporary);
+}
+
+void Audio_PersistentPoolsInit(AudioPoolSplit3* split) {
+ gAudioContext.gPersistentCommonPool.cur = gAudioContext.gPersistentCommonPool.start;
+ Audio_SoundAllocPoolInit(&gAudioContext.gSeqLoadedPool.persistent.pool,
+ Audio_Alloc(&gAudioContext.gPersistentCommonPool, split->wantSeq), split->wantSeq);
+ Audio_SoundAllocPoolInit(&gAudioContext.gBankLoadedPool.persistent.pool,
+ Audio_Alloc(&gAudioContext.gPersistentCommonPool, split->wantBank), split->wantBank);
+ Audio_SoundAllocPoolInit(&gAudioContext.gUnusedLoadedPool.persistent.pool,
+ Audio_Alloc(&gAudioContext.gPersistentCommonPool, split->wantUnused), split->wantUnused);
+ Audio_PersistentPoolClear(&gAudioContext.gSeqLoadedPool.persistent);
+ Audio_PersistentPoolClear(&gAudioContext.gBankLoadedPool.persistent);
+ Audio_PersistentPoolClear(&gAudioContext.gUnusedLoadedPool.persistent);
+}
+
+void Audio_TemporaryPoolsInit(AudioPoolSplit3* split) {
+ gAudioContext.gTemporaryCommonPool.cur = gAudioContext.gTemporaryCommonPool.start;
+ Audio_SoundAllocPoolInit(&gAudioContext.gSeqLoadedPool.temporary.pool,
+ Audio_Alloc(&gAudioContext.gTemporaryCommonPool, split->wantSeq), split->wantSeq);
+ Audio_SoundAllocPoolInit(&gAudioContext.gBankLoadedPool.temporary.pool,
+ Audio_Alloc(&gAudioContext.gTemporaryCommonPool, split->wantBank), split->wantBank);
+ Audio_SoundAllocPoolInit(&gAudioContext.gUnusedLoadedPool.temporary.pool,
+ Audio_Alloc(&gAudioContext.gTemporaryCommonPool, split->wantUnused), split->wantUnused);
+ Audio_TemporaryPoolClear(&gAudioContext.gSeqLoadedPool.temporary);
+ Audio_TemporaryPoolClear(&gAudioContext.gBankLoadedPool.temporary);
+ Audio_TemporaryPoolClear(&gAudioContext.gUnusedLoadedPool.temporary);
+}
+
+void* Audio_AllocBankOrSeq(s32 poolIdx, s32 size, s32 arg2, s32 id) {
+ SoundMultiPool* loadedPool;
+ TemporaryPool* tp;
+ SoundAllocPool* pool;
+ void* mem;
+ void* ret;
+ u8 firstVal;
+ u8 secondVal;
+ s32 i;
+ u8* table;
+ s32 side;
+
+ switch (poolIdx) {
+ case 0:
+ loadedPool = &gAudioContext.gSeqLoadedPool;
+ table = gAudioContext.gSeqLoadStatus;
+ break;
+ case 1:
+ loadedPool = &gAudioContext.gBankLoadedPool;
+ table = gAudioContext.gBankLoadStatus;
+ break;
+ case 2:
+ loadedPool = &gAudioContext.gUnusedLoadedPool;
+ table = gAudioContext.gUnusedLoadStatus;
+ break;
+ }
+
+ if (arg2 == 0) {
+ tp = &loadedPool->temporary;
+ pool = &tp->pool;
+
+ if (pool->size < size) {
+ return NULL;
+ }
+
+ firstVal = (tp->entries[0].id == -1) ? 0 : table[tp->entries[0].id];
+ secondVal = (tp->entries[1].id == -1) ? 0 : table[tp->entries[1].id];
+
+ if (poolIdx == 1) {
+ if (firstVal == 4) {
+ for (i = 0; i < gAudioContext.gMaxSimultaneousNotes; i++) {
+ if (gAudioContext.gNotes[i].playbackState.bankId == tp->entries[0].id &&
+ gAudioContext.gNotes[i].noteSubEu.bitField0.s.enabled != 0) {
+ break;
+ }
+ }
+
+ if (i == gAudioContext.gMaxSimultaneousNotes) {
+ Audio_SetBankLoadStatus(tp->entries[0].id, 3);
+ firstVal = 3;
+ }
+ }
+
+ if (secondVal == 4) {
+ for (i = 0; i < gAudioContext.gMaxSimultaneousNotes; i++) {
+ if (gAudioContext.gNotes[i].playbackState.bankId == tp->entries[1].id &&
+ gAudioContext.gNotes[i].noteSubEu.bitField0.s.enabled != 0) {
+ break;
+ }
+ }
+
+ if (i == gAudioContext.gMaxSimultaneousNotes) {
+ Audio_SetBankLoadStatus(tp->entries[1].id, 3);
+ secondVal = 3;
+ }
+ }
+ }
+
+ if (firstVal == 0) {
+ tp->nextSide = 0;
+ } else if (secondVal == 0) {
+ tp->nextSide = 1;
+ } else if (firstVal == 3 && secondVal == 3) {
+ // Use the opposite side from last time.
+ } else if (firstVal == 3) {
+ tp->nextSide = 0;
+ } else if (secondVal == 3) {
+ tp->nextSide = 1;
+ } else {
+ // Check if there is a side which isn't in active use, if so, evict that one.
+ if (poolIdx == 0) {
+ if (firstVal == 2) {
+ for (i = 0; i < gAudioContext.gAudioBufferParameters.numSequencePlayers; i++) {
+ if (gAudioContext.gSequencePlayers[i].enabled != 0 &&
+ gAudioContext.gSequencePlayers[i].seqId == tp->entries[0].id) {
+ break;
+ }
+ }
+
+ if (i == gAudioContext.gAudioBufferParameters.numSequencePlayers) {
+ tp->nextSide = 0;
+ goto done;
+ }
+ }
+
+ if (secondVal == 2) {
+ for (i = 0; i < gAudioContext.gAudioBufferParameters.numSequencePlayers; i++) {
+ if (gAudioContext.gSequencePlayers[i].enabled != 0 &&
+ gAudioContext.gSequencePlayers[i].seqId == tp->entries[1].id) {
+ break;
+ }
+ }
+
+ if (i == gAudioContext.gAudioBufferParameters.numSequencePlayers) {
+ tp->nextSide = 1;
+ goto done;
+ }
+ }
+ } else if (poolIdx == 1) {
+ if (firstVal == 2) {
+ for (i = 0; i < gAudioContext.gMaxSimultaneousNotes; i++) {
+ if (gAudioContext.gNotes[i].playbackState.bankId == tp->entries[0].id &&
+ gAudioContext.gNotes[i].noteSubEu.bitField0.s.enabled != 0) {
+ break;
+ }
+ }
+ if (i == gAudioContext.gMaxSimultaneousNotes) {
+ tp->nextSide = 0;
+ goto done;
+ }
+ }
+
+ if (secondVal == 2) {
+ for (i = 0; i < gAudioContext.gMaxSimultaneousNotes; i++) {
+ if (gAudioContext.gNotes[i].playbackState.bankId == tp->entries[1].id &&
+ gAudioContext.gNotes[i].noteSubEu.bitField0.s.enabled != 0) {
+ break;
+ }
+ }
+ if (i == gAudioContext.gMaxSimultaneousNotes) {
+ tp->nextSide = 1;
+ goto done;
+ }
+ }
+ }
+
+ // No such luck. Evict the side that wasn't chosen last time, except
+ // if it is being loaded into.
+ if (tp->nextSide == 0) {
+ if (firstVal == 1) {
+ if (secondVal == 1) {
+ goto fail;
+ }
+ tp->nextSide = 1;
+ }
+ } else {
+ if (secondVal == 1) {
+ if (firstVal == 1) {
+ goto fail;
+ }
+ tp->nextSide = 0;
+ }
+ }
+
+ if (0) {
+ fail:
+ // Both sides are being loaded into.
+ return NULL;
+ }
+ }
+ done:
+
+ side = tp->nextSide;
+
+ if (tp->entries[side].id != -1) {
+ if (poolIdx == 2) {
+ func_800E0E6C(tp->entries[side].id);
+ }
+ table[tp->entries[side].id] = 0;
+ if (poolIdx == 1) {
+ Audio_DiscardBank(tp->entries[side].id);
+ }
+ }
+
+ switch (side) {
+ case 0:
+ tp->entries[0].ptr = pool->start;
+ tp->entries[0].id = id;
+ tp->entries[0].size = size;
+ pool->cur = pool->start + size;
+
+ if (tp->entries[1].id != -1 && tp->entries[1].ptr < pool->cur) {
+ if (poolIdx == 2) {
+ func_800E0E6C(tp->entries[1].id);
+ }
+
+ table[tp->entries[1].id] = 0;
+ switch (poolIdx) {
+ case 0:
+ Audio_DiscardSequence((s32)tp->entries[1].id);
+ break;
+ case 1:
+ Audio_DiscardBank((s32)tp->entries[1].id);
+ break;
+ }
+
+ tp->entries[1].id = -1;
+ tp->entries[1].ptr = pool->start + pool->size;
+ }
+
+ ret = tp->entries[0].ptr;
+ break;
+
+ case 1:
+ tp->entries[1].ptr = (u8*)((u32)(pool->start + pool->size - size) & ~0xF);
+ tp->entries[1].id = id;
+ tp->entries[1].size = size;
+ if (tp->entries[0].id != -1 && tp->entries[1].ptr < pool->cur) {
+ if (poolIdx == 2) {
+ func_800E0E6C(tp->entries[0].id);
+ }
+
+ table[tp->entries[0].id] = 0;
+ switch (poolIdx) {
+ case 0:
+ Audio_DiscardSequence(tp->entries[0].id);
+ break;
+ case 1:
+ Audio_DiscardBank(tp->entries[0].id);
+ break;
+ }
+
+ tp->entries[0].id = -1;
+ pool->cur = pool->start;
+ }
+ ret = tp->entries[1].ptr;
+ break;
+
+ default:
+ return NULL;
+ }
+
+ tp->nextSide ^= 1;
+ return ret;
+ }
+
+ mem = Audio_Alloc(&loadedPool->persistent.pool, size);
+ loadedPool->persistent.entries[loadedPool->persistent.numEntries].ptr = mem;
+
+ if (mem == NULL) {
+ switch (arg2) {
+ case 2:
+ return Audio_AllocBankOrSeq(poolIdx, size, 0, id);
+
+ case 0:
+ case 1:
+ return NULL;
+ }
+ }
+
+ loadedPool->persistent.entries[loadedPool->persistent.numEntries].id = id;
+ loadedPool->persistent.entries[loadedPool->persistent.numEntries].size = size;
+ return loadedPool->persistent.entries[loadedPool->persistent.numEntries++].ptr;
+}
+
+void* func_800DF074(s32 poolIdx, s32 arg1, s32 id) {
+ void* ret;
+
+ ret = func_800E04E8(poolIdx, id);
+ if (ret != NULL) {
+ return ret;
+ }
+ if (arg1 == 3) {
+ return NULL;
+ }
+ return func_800DF0CC(poolIdx, arg1, id);
+}
+
+void* func_800DF0CC(s32 poolIdx, s32 arg1, s32 bankId) {
+ u32 i;
+ SoundMultiPool* loadedPool;
+ TemporaryPool* temporary;
+ PersistentPool* persistent;
+
+ switch (poolIdx) {
+ case 0:
+ loadedPool = &gAudioContext.gSeqLoadedPool;
+ break;
+ case 1:
+ loadedPool = &gAudioContext.gBankLoadedPool;
+ break;
+ case 2:
+ loadedPool = &gAudioContext.gUnusedLoadedPool;
+ break;
+ }
+
+ temporary = &loadedPool->temporary;
+ if (arg1 == 0) {
+ if (temporary->entries[0].id == bankId) {
+ temporary->nextSide = 1;
+ return temporary->entries[0].ptr;
+ } else if (temporary->entries[1].id == bankId) {
+ temporary->nextSide = 0;
+ return temporary->entries[1].ptr;
+ } else {
+ return NULL;
+ }
+ }
+
+ persistent = &loadedPool->persistent;
+ for (i = 0; i < persistent->numEntries; i++) {
+ if (persistent->entries[i].id == bankId) {
+ return persistent->entries[i].ptr;
+ }
+ }
+
+ if (arg1 == 2) {
+ return func_800DF074(poolIdx, 0, bankId);
+ }
+ return NULL;
+}
+
+void func_800DF1D8(f32 arg0, f32 arg1, u16* arg2) {
+ s32 i;
+ f32 tmp[16];
+
+ tmp[0] = (f32)(arg1 * 262159.0f);
+ tmp[8] = (f32)(arg0 * 262159.0f);
+ tmp[1] = (f32)((arg1 * arg0) * 262159.0f);
+ tmp[9] = (f32)(((arg0 * arg0) + arg1) * 262159.0f);
+
+ for (i = 2; i < 8; i++) {
+ //! @bug value was probably meant to be stored to tmp[i] and tmp[8 + i]
+ arg2[i] = arg1 * tmp[i - 2] + arg0 * tmp[i - 1];
+ arg2[8 + i] = arg1 * tmp[6 + i] + arg0 * tmp[7 + i];
+ }
+
+ for (i = 0; i < 16; i++) {
+ arg2[i] = tmp[i];
+ }
+}
+
+void func_800DF5AC(s16* arg0) {
+ s32 i;
+
+ for (i = 0; i < 8; i++) {
+ arg0[i] = 0;
+ }
+}
+
+void func_800DF5DC(s16* arg0, s32 arg1) {
+ s32 i;
+ s16* ptr = &D_80130228[8 * arg1];
+
+ for (i = 0; i < 8; i++) {
+ arg0[i] = ptr[i];
+ }
+}
+
+void func_800DF630(s16* arg0, s32 arg1) {
+ s32 i;
+ s16* ptr = &D_80130328[8 * (arg1 - 1)];
+
+ for (i = 0; i < 8; i++) {
+ arg0[i] = ptr[i];
+ }
+}
+
+void func_800DF688(s16* arg0, s32 arg1, s32 arg2) {
+ s32 i;
+
+ if (arg1 == 0 && arg2 == 0) {
+ func_800DF5DC(arg0, 0);
+ } else if (arg2 == 0) {
+ func_800DF5DC(arg0, arg1);
+ } else if (arg1 == 0) {
+ func_800DF630(arg0, arg2);
+ } else {
+ s16* ptr1 = &D_80130228[8 * arg1];
+ s16* ptr2 = &D_80130328[8 * (arg2 - 1)];
+ for (i = 0; i < 8; i++) {
+ arg0[i] = (ptr1[i] + ptr2[i]) / 2;
+ }
+ }
+}
+
+void func_800DF7BC(SynthesisReverb* reverb) {
+}
+
+void func_800DF7C4(void) {
+ s32 count;
+ s32 i;
+ s32 j;
+
+ if (gAudioContext.gAudioBufferParameters.presetUnk4 == 2) {
+ count = 2;
+ } else {
+ count = 1;
+ }
+
+ for (i = 0; i < gAudioContext.gNumSynthesisReverbs; i++) {
+ for (j = 0; j < count; j++) {
+ func_800DF7BC(&gAudioContext.gSynthesisReverbs[i]);
+ }
+ }
+}
+
+void func_800DF888(void) {
+ s32 ind;
+ s32 i;
+
+ ind = gAudioContext.unk_28A8;
+ gAudioContext.unk_2974[ind] = gAudioContext.gAudioBufferParameters.minAiBufferLength;
+
+ for (i = 0; i < 0x580; i++) {
+ gAudioContext.unk_2968[ind][i] = 0;
+ }
+}
+
+s32 Audio_ResetStep(void) {
+ s32 i;
+ s32 j;
+ s32 sp24;
+
+ if (gAudioContext.gAudioBufferParameters.presetUnk4 == 2) {
+ sp24 = 2;
+ } else {
+ sp24 = 1;
+ }
+
+ switch (gAudioContext.gAudioResetStatus) {
+ case 5:
+ for (i = 0; i < gAudioContext.gAudioBufferParameters.numSequencePlayers; i++) {
+ Audio_SequencePlayerDisableAsFinished(&gAudioContext.gSequencePlayers[i]);
+ }
+ gAudioContext.gAudioResetFadeOutFramesLeft = 2 / sp24;
+ gAudioContext.gAudioResetStatus--;
+ break;
+
+ case 4:
+ if (gAudioContext.gAudioResetFadeOutFramesLeft != 0) {
+ gAudioContext.gAudioResetFadeOutFramesLeft--;
+ func_800DF7C4();
+ } else {
+ for (i = 0; i < gAudioContext.gMaxSimultaneousNotes; i++) {
+ if (gAudioContext.gNotes[i].noteSubEu.bitField0.s.enabled &&
+ gAudioContext.gNotes[i].playbackState.adsr.action.s.state != ADSR_STATE_DISABLED) {
+ gAudioContext.gNotes[i].playbackState.adsr.fadeOutVel =
+ gAudioContext.gAudioBufferParameters.updatesPerFrameInv;
+ gAudioContext.gNotes[i].playbackState.adsr.action.s.release = true;
+ }
+ }
+ gAudioContext.gAudioResetFadeOutFramesLeft = 8 / sp24;
+ gAudioContext.gAudioResetStatus--;
+ }
+ break;
+
+ case 3:
+ if (gAudioContext.gAudioResetFadeOutFramesLeft != 0) {
+ gAudioContext.gAudioResetFadeOutFramesLeft--;
+ func_800DF7C4();
+ } else {
+ gAudioContext.gAudioResetFadeOutFramesLeft = 2 / sp24;
+ gAudioContext.gAudioResetStatus--;
+ }
+ break;
+
+ case 2:
+ func_800DF888();
+ if (gAudioContext.gAudioResetFadeOutFramesLeft != 0) {
+ gAudioContext.gAudioResetFadeOutFramesLeft--;
+ } else {
+ gAudioContext.gAudioResetStatus--;
+ func_800E0CBC();
+ func_800E1148();
+ }
+ break;
+
+ case 1:
+ func_800DFBF8();
+ gAudioContext.gAudioResetStatus = 0;
+ for (i = 0; i < 3; i++) {
+ gAudioContext.unk_2974[i] = gAudioContext.gAudioBufferParameters.maxAiBufferLength;
+ for (j = 0; j < 0x580; j++) {
+ gAudioContext.unk_2968[i][j] = 0;
+ }
+ }
+ break;
+ }
+
+ if (gAudioContext.gAudioResetStatus < 3) {
+ return 0;
+ }
+
+ return 1;
+}
+
+#ifdef NON_EQUIVALENT
+// first half matches, reorderings and regalloc in second half
+void func_800DFBF8(void) {
+ s32 pad[6];
+ s32 i;
+ s32 j;
+ s16* mem;
+ u16 windowSize;
+ s32 persistentMem;
+ s32 temporaryMem;
+ s32 totalMem;
+ AudioSessionSettings* preset;
+ s32 wantMisc;
+ u32 intMask;
+
+ preset = &gAudioSessionPresets[gAudioContext.gAudioResetPresetIdToLoad];
+ gAudioContext.gSampleDmaNumListItems = 0;
+ gAudioContext.gAudioBufferParameters.frequency = preset->frequency;
+ gAudioContext.gAudioBufferParameters.aiFrequency = osAiSetFrequency(gAudioContext.gAudioBufferParameters.frequency);
+ gAudioContext.gAudioBufferParameters.samplesPerFrameTarget =
+ ((gAudioContext.gAudioBufferParameters.frequency / gAudioContext.gRefreshRate) + 0xF) & 0xFFF0;
+ gAudioContext.gAudioBufferParameters.minAiBufferLength =
+ gAudioContext.gAudioBufferParameters.samplesPerFrameTarget - 0x10;
+ gAudioContext.gAudioBufferParameters.maxAiBufferLength =
+ gAudioContext.gAudioBufferParameters.samplesPerFrameTarget + 0x10;
+ gAudioContext.gAudioBufferParameters.updatesPerFrame =
+ ((gAudioContext.gAudioBufferParameters.samplesPerFrameTarget + 0x10) / 0xD0) + 1;
+ gAudioContext.gAudioBufferParameters.samplesPerUpdate =
+ (gAudioContext.gAudioBufferParameters.samplesPerFrameTarget /
+ gAudioContext.gAudioBufferParameters.updatesPerFrame) &
+ ~7;
+ gAudioContext.gAudioBufferParameters.samplesPerUpdateMax =
+ gAudioContext.gAudioBufferParameters.samplesPerUpdate + 8;
+ gAudioContext.gAudioBufferParameters.samplesPerUpdateMin =
+ gAudioContext.gAudioBufferParameters.samplesPerUpdate - 8;
+ gAudioContext.gAudioBufferParameters.resampleRate = 32000.0f / (s32)gAudioContext.gAudioBufferParameters.frequency;
+ gAudioContext.gAudioBufferParameters.unkUpdatesPerFrameScaled =
+ (1.0f / 256.0f) / gAudioContext.gAudioBufferParameters.updatesPerFrame;
+ gAudioContext.gAudioBufferParameters.unk_24 = gAudioContext.gAudioBufferParameters.updatesPerFrame * 0.25f;
+ gAudioContext.gAudioBufferParameters.updatesPerFrameInv =
+ 1.0f / gAudioContext.gAudioBufferParameters.updatesPerFrame;
+ gAudioContext.unk_2874 = preset->unk_10;
+ gAudioContext.unk_2878 = preset->unk_12;
+
+ gAudioContext.gMaxSimultaneousNotes = preset->maxSimultaneousNotes;
+ gAudioContext.gAudioBufferParameters.numSequencePlayers = preset->numSequencePlayers;
+ if (gAudioContext.gAudioBufferParameters.numSequencePlayers > 4) {
+ gAudioContext.gAudioBufferParameters.numSequencePlayers = 4;
+ }
+ gAudioContext.unk_2 = preset->unk_14;
+ gAudioContext.gTempoInternalToExternal = (u32)(gAudioContext.gAudioBufferParameters.updatesPerFrame * 2880000.0f /
+ gTatumsPerBeat / gAudioContext.unk_2960);
+
+ gAudioContext.unk_2870 = gAudioContext.gRefreshRate;
+ gAudioContext.unk_2870 *= gAudioContext.gAudioBufferParameters.updatesPerFrame;
+ gAudioContext.unk_2870 /= gAudioContext.gAudioBufferParameters.aiFrequency;
+ gAudioContext.unk_2870 /= gAudioContext.gTempoInternalToExternal;
+
+ gAudioContext.gAudioBufferParameters.presetUnk4 = preset->unk_04;
+ gAudioContext.gAudioBufferParameters.samplesPerFrameTarget *= gAudioContext.gAudioBufferParameters.presetUnk4;
+ gAudioContext.gAudioBufferParameters.maxAiBufferLength *= gAudioContext.gAudioBufferParameters.presetUnk4;
+ gAudioContext.gAudioBufferParameters.minAiBufferLength *= gAudioContext.gAudioBufferParameters.presetUnk4;
+ gAudioContext.gAudioBufferParameters.updatesPerFrame *= gAudioContext.gAudioBufferParameters.presetUnk4;
+
+ if (gAudioContext.gAudioBufferParameters.presetUnk4 >= 2) {
+ gAudioContext.gAudioBufferParameters.maxAiBufferLength -= 0x10;
+ }
+
+ gAudioContext.gMaxAudioCmds =
+ gAudioContext.gMaxSimultaneousNotes * 0x10 * gAudioContext.gAudioBufferParameters.updatesPerFrame +
+ preset->numReverbs * 0x18 + 0x140;
+
+ persistentMem = preset->persistentSeqMem + preset->persistentBankMem + preset->persistentUnusedMem + 0x10;
+ temporaryMem = preset->temporarySeqMem + preset->temporaryBankMem + preset->temporaryUnusedMem + 0x10;
+ totalMem = persistentMem + temporaryMem;
+ wantMisc = gAudioContext.gAudioSessionPool.size - totalMem - 0x100;
+
+ if (gAudioContext.gUnkPool.start != NULL) {
+ gAudioContext.gUnkPool.cur = gAudioContext.gUnkPool.start;
+ }
+
+ gAudioContext.sSessionPoolSplit.wantSeq = wantMisc;
+ gAudioContext.sSessionPoolSplit.wantCustom = totalMem;
+ Audio_SessionPoolsInit(&gAudioContext.sSessionPoolSplit);
+ gAudioContext.sSeqAndBankPoolSplit.wantPersistent = persistentMem;
+ gAudioContext.sSeqAndBankPoolSplit.wantTemporary = temporaryMem;
+ Audio_SeqAndBankPoolInit(&gAudioContext.sSeqAndBankPoolSplit);
+ gAudioContext.sPersistentCommonPoolSplit.wantSeq = preset->persistentSeqMem;
+ gAudioContext.sPersistentCommonPoolSplit.wantBank = preset->persistentBankMem;
+ gAudioContext.sPersistentCommonPoolSplit.wantUnused = preset->persistentUnusedMem;
+ Audio_PersistentPoolsInit(&gAudioContext.sPersistentCommonPoolSplit);
+ gAudioContext.sTemporaryCommonPoolSplit.wantSeq = preset->temporarySeqMem;
+ gAudioContext.sTemporaryCommonPoolSplit.wantBank = preset->temporaryBankMem;
+ gAudioContext.sTemporaryCommonPoolSplit.wantUnused = preset->temporaryUnusedMem;
+ Audio_TemporaryPoolsInit(&gAudioContext.sTemporaryCommonPoolSplit);
+
+ Audio_ResetLoadStatus();
+ gAudioContext.gNotes =
+ Audio_AllocZeroed(&gAudioContext.gNotesAndBuffersPool, gAudioContext.gMaxSimultaneousNotes * sizeof(Note));
+ Audio_NoteInitAll();
+ Audio_InitNoteFreeList();
+ gAudioContext.gNoteSubsEu = Audio_AllocZeroed(&gAudioContext.gNotesAndBuffersPool,
+ gAudioContext.gAudioBufferParameters.updatesPerFrame *
+ gAudioContext.gMaxSimultaneousNotes * sizeof(NoteSubEu));
+
+ for (i = 0; i != 2; i++) {
+ gAudioContext.gAudioCmdBuffers[i] =
+ Audio_AllocDmaMemoryZeroed(&gAudioContext.gNotesAndBuffersPool, gAudioContext.gMaxAudioCmds * sizeof(u64));
+ }
+
+ gAudioContext.unk_3520 = Audio_Alloc(&gAudioContext.gNotesAndBuffersPool, 0x100 * sizeof(f32));
+ func_800DDE3C();
+ for (i = 0; i < 4; i++) {
+ gAudioContext.gSynthesisReverbs[i].useReverb = 0;
+ }
+
+ gAudioContext.gNumSynthesisReverbs = preset->numReverbs;
+ for (i = 0; i < gAudioContext.gNumSynthesisReverbs; i++) {
+ SynthesisReverb* reverb = &gAudioContext.gSynthesisReverbs[i];
+ ReverbSettings* settings = &preset->reverbSettings[i];
+ reverb->downsampleRate = settings->downsampleRate;
+ reverb->windowSize = settings->windowSize * 64;
+ reverb->windowSize /= reverb->downsampleRate;
+ reverb->unk_0C = settings->unk_4;
+ reverb->unk_0A = settings->unk_A;
+ reverb->unk_14 = settings->unk_6 * 64;
+ reverb->unk_16 = settings->unk_8;
+ reverb->unk_18 = 0;
+ reverb->unk_10 = settings->unk_C;
+ reverb->unk_12 = settings->unk_E;
+ reverb->unk_05 = settings->unk_10;
+ reverb->unk_08 = settings->unk_12;
+ reverb->useReverb = 8;
+ reverb->unk_28 = func_800DE258(&gAudioContext.gNotesAndBuffersPool, reverb->windowSize * sizeof(s16));
+ reverb->unk_2C = func_800DE258(&gAudioContext.gNotesAndBuffersPool, reverb->windowSize * sizeof(s16));
+ reverb->unk_1C = 0;
+ reverb->unk_20 = 0;
+ reverb->unk_03 = 0;
+ reverb->unk_02 = 2;
+ reverb->unk_00 = 1;
+ reverb->unk_24 = reverb->windowSize;
+ reverb->sound.sample = &reverb->sample;
+ reverb->sample.loop = &reverb->loop;
+ reverb->sample.bits4 = 4;
+ reverb->sample.bits2 = 0;
+ reverb->sample.bits24 = reverb->windowSize * 2;
+ reverb->loop.start = 0;
+ reverb->loop.count = 1;
+ reverb->loop.end = reverb->windowSize;
+ reverb->sound.tuning = 1.0f;
+ reverb->sample.sampleAddr = (u8*)reverb->unk_28;
+
+ if (reverb->downsampleRate != 1) {
+ reverb->unk_0E = 0x8000 / reverb->downsampleRate;
+ reverb->unk_30 = Audio_AllocZeroed(&gAudioContext.gNotesAndBuffersPool, 0x20);
+ reverb->unk_34 = Audio_AllocZeroed(&gAudioContext.gNotesAndBuffersPool, 0x20);
+ reverb->unk_38 = Audio_AllocZeroed(&gAudioContext.gNotesAndBuffersPool, 0x20);
+ reverb->unk_3C = Audio_AllocZeroed(&gAudioContext.gNotesAndBuffersPool, 0x20);
+ reverb = reverb;
+ for (j = 0; j < gAudioContext.gAudioBufferParameters.updatesPerFrame; j++) {
+ mem = func_800DE258(&gAudioContext.gNotesAndBuffersPool, 0x340);
+ reverb->items[0][j].toDownsampleLeft = mem;
+ reverb->items[0][j].toDownsampleRight = mem + 0x1A0 / sizeof(s16);
+ mem = func_800DE258(&gAudioContext.gNotesAndBuffersPool, 0x340);
+ reverb->items[1][j].toDownsampleLeft = mem;
+ reverb->items[1][j].toDownsampleRight = mem + 0x1A0 / sizeof(s16);
+ }
+ }
+
+ if (settings->unk_14 != 0) {
+ reverb->unk_278 = Audio_AllocDmaMemoryZeroed(&gAudioContext.gNotesAndBuffersPool, 0x40);
+ reverb->unk_270 = Audio_AllocDmaMemory(&gAudioContext.gNotesAndBuffersPool, 8 * sizeof(s16));
+ func_800DF5DC(reverb->unk_270, settings->unk_14);
+ } else {
+ reverb->unk_270 = NULL;
+ }
+
+ if (settings->unk_16 != 0) {
+ reverb->unk_27C = Audio_AllocDmaMemoryZeroed(&gAudioContext.gNotesAndBuffersPool, 0x40);
+ reverb->unk_274 = Audio_AllocDmaMemory(&gAudioContext.gNotesAndBuffersPool, 8 * sizeof(s16));
+ func_800DF5DC(reverb->unk_274, settings->unk_16);
+ } else {
+ reverb->unk_274 = NULL;
+ }
+ }
+
+ Audio_InitSequencePlayers();
+ for (i = 0; i < gAudioContext.gAudioBufferParameters.numSequencePlayers; i++) {
+ func_800EC734(i);
+ Audio_ResetSequencePlayer(&gAudioContext.gSequencePlayers[i]);
+ }
+
+ func_800E0634(preset->unk_30, preset->unk_34);
+ func_800E1618(gAudioContext.gMaxSimultaneousNotes);
+ gAudioContext.unk_176C = 0;
+ func_800E3400();
+ func_800E4FB0();
+ func_800E3A14();
+ gAudioContext.unk_4 = 0x1000;
+ func_800E4D94();
+ intMask = osSetIntMask(1);
+ osWritebackDCacheAll();
+ osSetIntMask(intMask);
+}
+#else
#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800DFBF8.s")
+#endif
+
+void* func_800E04E8(s32 poolIdx, s32 id) {
+ s32 i;
+
+ for (i = 0; i < gAudioContext.unk_2D50.unused; i++) {
+ if (gAudioContext.unk_2D60[i].poolIndex == poolIdx && gAudioContext.unk_2D60[i].id == id) {
+ return gAudioContext.unk_2D60[i].ptr;
+ }
+ }
+ return NULL;
+}
+
+void* func_800E0540(s32 poolIdx, s32 id, u32 size) {
+ void* ret;
+ s32 sp18;
+
+ sp18 = gAudioContext.unk_2D50.unused;
+
+ ret = Audio_Alloc(&gAudioContext.unk_2D50, size);
+ gAudioContext.unk_2D60[sp18].ptr = ret;
+ if (ret == NULL) {
+ return NULL;
+ }
+ gAudioContext.unk_2D60[sp18].poolIndex = poolIdx;
+ gAudioContext.unk_2D60[sp18].id = id;
+ gAudioContext.unk_2D60[sp18].size = size;
+ // @bug UB: missing return. "ret" is in v0 at this point, but doing an
+ // explicit return uses an additional register.
+ // return ret;
+}
+
+void* func_800E05C4(u32 size, s32 arg1, void* arg2, s8 arg3, s32 arg4) {
+ UnkHeapEntry* entry;
+
+ if (arg4 == 0) {
+ entry = func_800E06CC(size);
+ } else {
+ entry = func_800E0BF8(size);
+ }
+ if (entry != NULL) {
+ entry->unk_02 = arg1;
+ entry->unk_0C = arg2;
+ entry->unk_01 = arg3;
+ return entry->unk_08;
+ }
+ return NULL;
+}
+
+void func_800E0634(u32 arg0, u32 arg1) {
+ void* mem;
+
+ mem = func_800DE2B0(&gAudioContext.gNotesAndBuffersPool, arg0);
+ if (mem == NULL) {
+ gAudioContext.unk_2EE0.pool.size = 0;
+ } else {
+ Audio_SoundAllocPoolInit(&gAudioContext.unk_2EE0.pool, mem, arg0);
+ }
+ mem = func_800DE2B0(&gAudioContext.gNotesAndBuffersPool, arg1);
+ if (mem == NULL) {
+ gAudioContext.unk_3174.pool.size = 0;
+ } else {
+ Audio_SoundAllocPoolInit(&gAudioContext.unk_3174.pool, mem, arg1);
+ }
+ gAudioContext.unk_2EE0.size = 0;
+ gAudioContext.unk_3174.size = 0;
+}
+
+UnkHeapEntry* func_800E06CC(u32 size) {
+ u8* allocAfter;
+ u8* allocBefore;
+ void* mem;
+ s32 index;
+ s32 i;
+ UnkHeapEntry* ret;
+ AudioStruct0D68* thing;
+ UnkPool* unkPool;
+ u8* start;
+ u8* end;
+
+ unkPool = &gAudioContext.unk_3174;
+ allocBefore = unkPool->pool.cur;
+ mem = Audio_Alloc(&unkPool->pool, size);
+ if (mem == NULL) {
+ u8* old = unkPool->pool.cur;
+ unkPool->pool.cur = unkPool->pool.start;
+ mem = Audio_Alloc(&unkPool->pool, size);
+ if (mem == NULL) {
+ unkPool->pool.cur = old;
+ return NULL;
+ }
+ allocBefore = unkPool->pool.start;
+ }
+
+ allocAfter = unkPool->pool.cur;
+
+ index = -1;
+ for (i = 0; i < gAudioContext.unk_176C; i++) {
+ thing = &gAudioContext.unk_0D68[i];
+ if (thing->unk_10 == 0) {
+ start = thing->unk_08;
+ end = thing->unk_08 + thing->sample->bits24 - 1;
+
+ if (end < allocBefore && start < allocBefore) {
+ continue;
+ }
+ if (end >= allocAfter && start >= allocAfter) {
+ continue;
+ }
+
+ // Overlap
+ thing->unk_10 = 1;
+ }
+ }
+
+ for (i = 0; i < unkPool->size; i++) {
+ if (unkPool->entries[i].unk_00 == 0) {
+ continue;
+ }
+
+ start = unkPool->entries[i].unk_08;
+ end = start + unkPool->entries[i].size - 1;
+
+ if (end < allocBefore && start < allocBefore) {
+ continue;
+ }
+ if (end >= allocAfter && start >= allocAfter) {
+ continue;
+ }
+
+ // Overlap. Discard existing entry?
+ func_800E0AD8(&unkPool->entries[i]);
+ if (index == -1) {
+ index = i;
+ }
+ }
+
+ if (index == -1) {
+ index = unkPool->size++;
+ }
+
+ ret = &unkPool->entries[index];
+ ret->unk_00 = 1;
+ ret->unk_08 = mem;
+ ret->size = size;
+ return ret;
+}
+
+void func_800E0964(UnkHeapEntry* entry, s32 bankId) {
+ Drum* drum;
+ Instrument* inst;
+ AudioBankSound* sfx;
+ s32 instId;
+ s32 drumId;
+ s32 sfxId;
+
+ for (instId = 0; instId < gAudioContext.gCtlEntries[bankId].numInstruments; instId++) {
+ inst = Audio_GetInstrumentInner(bankId, instId);
+ if (inst != NULL) {
+ if (inst->normalRangeLo != 0) {
+ func_800E0BB4(entry, inst->lowNotesSound.sample);
+ }
+ if (inst->normalRangeHi != 0x7F) {
+ func_800E0BB4(entry, inst->highNotesSound.sample);
+ }
+ func_800E0BB4(entry, inst->normalNotesSound.sample);
+ }
+ }
+
+ for (drumId = 0; drumId < gAudioContext.gCtlEntries[bankId].numDrums; drumId++) {
+ drum = Audio_GetDrum(bankId, drumId);
+ if (drum != NULL) {
+ func_800E0BB4(entry, drum->sound.sample);
+ }
+ }
+
+ for (sfxId = 0; sfxId < gAudioContext.gCtlEntries[bankId].numSfx; sfxId++) {
+ sfx = Audio_GetSfx(bankId, sfxId);
+ if (sfx != NULL) {
+ func_800E0BB4(entry, sfx->sample);
+ }
+ }
+}
+
+void func_800E0AD8(UnkHeapEntry* entry) {
+ s32 numBanks;
+ s32 unk2;
+ s32 unk3;
+ s32 bankId;
+
+ numBanks = *gAudioContext.unk_2834;
+ for (bankId = 0; bankId < numBanks; bankId++) {
+ unk2 = gAudioContext.gCtlEntries[bankId].unk_02;
+ unk3 = gAudioContext.gCtlEntries[bankId].unk_03;
+ if (((unk2 != 0xFF) && (entry->unk_02 == unk2)) || ((unk3 != 0xFF) && (entry->unk_02 == unk3)) ||
+ entry->unk_02 == 0) {
+ if (func_800DF074(1, 2, bankId) != NULL) {
+ if (Audio_IsBankLoadComplete(bankId) != 0) {
+ func_800E0964(entry, bankId);
+ }
+ }
+ }
+ }
+}
+
+void func_800E0BB4(UnkHeapEntry* entry, AudioBankSample* sample) {
+ if (sample != NULL) {
+ if (sample->sampleAddr == entry->unk_08) {
+ sample->sampleAddr = entry->unk_0C;
+ sample->bits2 = entry->unk_01;
+ }
+ }
+}
+
+UnkHeapEntry* func_800E0BF8(u32 size) {
+ UnkPool* pool;
+ UnkHeapEntry* entry;
+ void* mem;
+
+ pool = &gAudioContext.unk_2EE0;
+ mem = Audio_Alloc(&pool->pool, size);
+ if (mem == NULL) {
+ return NULL;
+ }
+ entry = &pool->entries[pool->size];
+ entry->unk_00 = 1;
+ entry->unk_08 = mem;
+ entry->size = size;
+ pool->size++;
+ return entry;
+}
+
+void func_800E0C80(UnkHeapEntry* entry, s32 arg1, s32 arg2, s32 bankId) {
+ if ((entry->unk_02 == arg1) || (entry->unk_02 == arg2) || (entry->unk_02 == 0)) {
+ func_800E0964(entry, bankId);
+ }
+}
+
+void func_800E0CBC(void) {
+ s32 numBanks;
+ s32 unk2;
+ s32 unk3;
+ s32 bankId;
+ s32 j;
+
+ numBanks = *gAudioContext.unk_2834;
+ for (bankId = 0; bankId < numBanks; bankId++) {
+ unk2 = gAudioContext.gCtlEntries[bankId].unk_02;
+ unk3 = gAudioContext.gCtlEntries[bankId].unk_03;
+ if ((unk2 == 0xFF) && (unk3 == 0xFF)) {
+ continue;
+ }
+ if (func_800DF074(1, 3, bankId) == NULL || !Audio_IsBankLoadComplete(bankId)) {
+ continue;
+ }
+
+ for (j = 0; j < gAudioContext.unk_2EE0.size; j++) {
+ func_800E0C80(&gAudioContext.unk_2EE0.entries[j], unk2, unk3, bankId);
+ }
+ for (j = 0; j < gAudioContext.unk_3174.size; j++) {
+ func_800E0C80(&gAudioContext.unk_3174.entries[j], unk2, unk3, bankId);
+ }
+ }
+}
+
+typedef struct {
+ u8* unk_0;
+ u8* unk_4;
+ u32 unk_8;
+ u8 unk_C;
+} Struct_800E0E0C;
+
+void func_800E0E0C(Struct_800E0E0C* arg0, AudioBankSample* sample) {
+ if (sample != NULL) {
+ u8* start = arg0->unk_0;
+ u8* end = arg0->unk_0 + arg0->unk_8;
+ u8* sampleAddr = sample->sampleAddr;
+ if (start <= sampleAddr && sampleAddr < end) {
+ sample->sampleAddr = sampleAddr - start + arg0->unk_4;
+ sample->bits2 = arg0->unk_C & 0xFF;
+ }
+ }
+}
+
+void func_800E0E6C(s32 id) {
+ func_800E0EB4(0, id);
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E04E8.s")
+void func_800E0E90(s32 id) {
+ func_800E0EB4(1, id);
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E0540.s")
+void func_800E0EB4(s32 arg0, s32 id) {
+ ManyStruct_800E0E0C_2* manyThing;
+ Struct_800E0E0C_2* thing;
+ s32 numBanks;
+ s32 instId;
+ s32 drumId;
+ s32 sfxId;
+ Struct_800E0E0C sp78;
+ s32 unk2;
+ s32 unk3;
+ s32 bankId;
+ Drum* drum;
+ Instrument* inst;
+ AudioBankSound* sfx;
+ u8** fakematch;
+ s32 pad[4];
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E05C4.s")
+ manyThing = gAudioContext.unk_2838;
+ numBanks = *gAudioContext.unk_2834;
+ sp78.unk_0 = func_800DF074(2, 2, id);
+ if (sp78.unk_0 == NULL) {
+ return;
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E0634.s")
+ thing = &manyThing->unk_C[id];
+ sp78.unk_8 = thing->unk_8;
+ sp78.unk_C = thing->unk_C;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E06CC.s")
+ if ((sp78.unk_C == 2) || (sp78.unk_C == 3)) {
+ sp78.unk_4 = thing->unk_4;
+ } else {
+ sp78.unk_4 = NULL;
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E0964.s")
+ fakematch = &sp78.unk_0;
+ if ((arg0 != 0) && (arg0 == 1)) {
+ u8* temp = sp78.unk_4;
+ sp78.unk_4 = *fakematch;
+ sp78.unk_0 = temp;
+ sp78.unk_C = 0;
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E0AD8.s")
+ for (bankId = 0; bankId < numBanks; bankId++) {
+ unk2 = gAudioContext.gCtlEntries[bankId].unk_02;
+ unk3 = gAudioContext.gCtlEntries[bankId].unk_03;
+ if ((unk2 != 0xFF) || (unk3 != 0xFF)) {
+ if (!Audio_IsBankLoadComplete(bankId) || func_800DF074(1, 2, bankId) == NULL) {
+ continue;
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E0BB4.s")
+ if (unk2 == id) {
+ } else if (unk3 == id) {
+ } else {
+ continue;
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E0BF8.s")
+ for (instId = 0; instId < gAudioContext.gCtlEntries[bankId].numInstruments; instId++) {
+ inst = Audio_GetInstrumentInner(bankId, instId);
+ if (inst != NULL) {
+ if (inst->normalRangeLo != 0) {
+ func_800E0E0C(&sp78, inst->lowNotesSound.sample);
+ }
+ if (inst->normalRangeHi != 0x7F) {
+ func_800E0E0C(&sp78, inst->highNotesSound.sample);
+ }
+ func_800E0E0C(&sp78, inst->normalNotesSound.sample);
+ }
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E0C80.s")
+ for (drumId = 0; drumId < gAudioContext.gCtlEntries[bankId].numDrums; drumId++) {
+ drum = Audio_GetDrum(bankId, drumId);
+ if (drum != NULL) {
+ func_800E0E0C(&sp78, drum->sound.sample);
+ }
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E0CBC.s")
+ for (sfxId = 0; sfxId < gAudioContext.gCtlEntries[bankId].numSfx; sfxId++) {
+ sfx = Audio_GetSfx(bankId, sfxId);
+ if (sfx != NULL) {
+ func_800E0E0C(&sp78, sfx->sample);
+ }
+ }
+ }
+ }
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E0E0C.s")
+void func_800E1148(void) {
+ SoundMultiPool* pool;
+ PersistentPool* persistent;
+ TemporaryPool* temporary;
+ u32 i;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E0E6C.s")
+ pool = &gAudioContext.gUnusedLoadedPool;
+ temporary = &pool->temporary;
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E0E90.s")
+ if (temporary->entries[0].id != -1) {
+ func_800E0E6C(temporary->entries[0].id);
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E0EB4.s")
+ if (temporary->entries[1].id != -1) {
+ func_800E0E6C(temporary->entries[1].id);
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_heap/func_800E1148.s")
+ persistent = &pool->persistent;
+ for (i = 0; i < persistent->numEntries; i++) {
+ func_800E0E6C(persistent->entries[i].id);
+ }
+}
diff --git a/src/code/audio_playback.c b/src/code/audio_playback.c
index 08e3b2ca7..d5e71ff9c 100644
--- a/src/code/audio_playback.c
+++ b/src/code/audio_playback.c
@@ -27,8 +27,8 @@ void Audio_NoteSetVelPanReverb(Note* note, NoteSubEu* sub, Reverb* reverb) {
pan &= 0x7F;
- sub->bitField0.s.stereoStrongRight = 0;
- sub->bitField0.s.stereoStrongLeft = 0;
+ sub->bitField0.s.stereoStrongRight = false;
+ sub->bitField0.s.stereoStrongLeft = false;
sub->bitField0.s.stereoHeadsetEffects = sp24.stereoHeadsetEffects;
sub->bitField0.s.usesHeadsetPanEffects = sp24.usesHeadsetPanEffects;
if (stereoHeadsetEffects && gAudioContext.gSoundMode == 1) {
@@ -39,7 +39,7 @@ void Audio_NoteSetVelPanReverb(Note* note, NoteSubEu* sub, Reverb* reverb) {
sub->headsetPanLeft = gHeadsetPanQuantization[smallPanIndex];
sub->headsetPanRight = gHeadsetPanQuantization[0x3f - smallPanIndex];
- sub->bitField1.s.hasTwoAdpcmParts = 1;
+ sub->bitField1.s.hasTwoAdpcmParts = true;
volLeft = gHeadsetPanVolume[pan];
volRight = gHeadsetPanVolume[0x7f - pan];
@@ -47,7 +47,7 @@ void Audio_NoteSetVelPanReverb(Note* note, NoteSubEu* sub, Reverb* reverb) {
strongLeft = strongRight = 0;
sub->headsetPanRight = 0;
sub->headsetPanLeft = 0;
- sub->bitField1.s.hasTwoAdpcmParts = 0;
+ sub->bitField1.s.hasTwoAdpcmParts = false;
volLeft = gStereoPanVolume[pan];
volRight = gStereoPanVolume[0x7f - pan];
@@ -78,8 +78,8 @@ void Audio_NoteSetVelPanReverb(Note* note, NoteSubEu* sub, Reverb* reverb) {
}
} else if (gAudioContext.gSoundMode == 3) {
- sub->bitField0.s.stereoHeadsetEffects = 0;
- sub->bitField0.s.usesHeadsetPanEffects = 0;
+ sub->bitField0.s.stereoHeadsetEffects = false;
+ sub->bitField0.s.usesHeadsetPanEffects = false;
volLeft = 0.707f;
volRight = 0.707f;
} else {
@@ -106,7 +106,7 @@ void Audio_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput)
f32 resamplingRate = 0.0f;
if (resamplingRateInput < 2.0f) {
- noteSubEu->bitField1.s.isSyntheticWave = 0;
+ noteSubEu->bitField1.s.isSyntheticWave = false;
if (1.99998f < resamplingRateInput) {
resamplingRate = 1.99998f;
@@ -115,7 +115,7 @@ void Audio_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput)
}
} else {
- noteSubEu->bitField1.s.isSyntheticWave = 1;
+ noteSubEu->bitField1.s.isSyntheticWave = true;
if (3.99996f < resamplingRateInput) {
resamplingRate = 1.99998f;
} else {
@@ -140,13 +140,13 @@ void Audio_NoteInit(Note* note) {
}
void Audio_NoteDisable(Note* note) {
- if (note->noteSubEu.bitField0.s.needsInit == 1) {
- note->noteSubEu.bitField0.s.needsInit = 0;
+ if (note->noteSubEu.bitField0.s.needsInit == true) {
+ note->noteSubEu.bitField0.s.needsInit = false;
}
note->playbackState.priority = 0;
- note->noteSubEu.bitField0.s.enabled = 0;
+ note->noteSubEu.bitField0.s.enabled = false;
note->playbackState.unk_04 = 0;
- note->noteSubEu.bitField0.s.finished = 0;
+ note->noteSubEu.bitField0.s.finished = false;
note->playbackState.parentLayer = NO_LAYER;
note->playbackState.prevParentLayer = NO_LAYER;
note->playbackState.adsr.action.s.state = ADSR_STATE_DISABLED;
@@ -175,7 +175,7 @@ void Audio_ProcessNotes(void) {
}
if (note != playbackState->parentLayer->note && playbackState->unk_04 == 0) {
- playbackState->adsr.action.s.release = 1;
+ playbackState->adsr.action.s.release = true;
playbackState->adsr.fadeOutVel = gAudioContext.gAudioBufferParameters.updatesPerFrameInv;
playbackState->priority = 1;
playbackState->unk_04 = 2;
@@ -229,7 +229,7 @@ void Audio_ProcessNotes(void) {
}
} else {
if (playbackState->parentLayer != NO_LAYER) {
- playbackState->parentLayer->bit1 = 1;
+ playbackState->parentLayer->bit1 = true;
}
Audio_NoteDisable(note);
Audio_AudioListRemove(&note->listItem);
@@ -239,7 +239,7 @@ void Audio_ProcessNotes(void) {
}
} else if (playbackState->adsr.action.s.state == ADSR_STATE_DISABLED) {
if (playbackState->parentLayer != NO_LAYER) {
- playbackState->parentLayer->bit1 = 1;
+ playbackState->parentLayer->bit1 = true;
}
Audio_NoteDisable(note);
Audio_AudioListRemove(&note->listItem);
@@ -362,8 +362,8 @@ Drum* Audio_GetDrum(s32 bankId, s32 drumId) {
return drum;
}
-UnkInstrument* Audio_GetUnkInstrument(s32 bankId, s32 unkInstrumentId) {
- UnkInstrument* unkInstrument;
+AudioBankSound* Audio_GetSfx(s32 bankId, s32 sfxId) {
+ AudioBankSound* sfx;
if (bankId == 0xFF) {
return NULL;
@@ -374,29 +374,29 @@ UnkInstrument* Audio_GetUnkInstrument(s32 bankId, s32 unkInstrumentId) {
return NULL;
}
- if (unkInstrumentId >= gAudioContext.gCtlEntries[bankId].numUnkInstruments) {
- gAudioContext.gAudioErrorFlags = ((bankId << 8) + unkInstrumentId) + 0x4000000;
+ if (sfxId >= gAudioContext.gCtlEntries[bankId].numSfx) {
+ gAudioContext.gAudioErrorFlags = ((bankId << 8) + sfxId) + 0x4000000;
return NULL;
}
- if ((u32)gAudioContext.gCtlEntries[bankId].unkInstruments < 0x80000000U) {
+ if ((u32)gAudioContext.gCtlEntries[bankId].soundEffects < 0x80000000U) {
return NULL;
}
- unkInstrument = &gAudioContext.gCtlEntries[bankId].unkInstruments[unkInstrumentId];
+ sfx = &gAudioContext.gCtlEntries[bankId].soundEffects[sfxId];
- if (unkInstrument == NULL) {
- gAudioContext.gAudioErrorFlags = ((bankId << 8) + unkInstrumentId) + 0x5000000;
+ if (sfx == NULL) {
+ gAudioContext.gAudioErrorFlags = ((bankId << 8) + sfxId) + 0x5000000;
}
- if (unkInstrument->unk_0 == 0) {
+ if (sfx->sample == NULL) {
return NULL;
}
- return unkInstrument;
+ return sfx;
}
-s32 func_800E7744(s32 instrument, s32 bankId, s32 instId, UnkInstrument* arg3) {
+s32 func_800E7744(s32 instrument, s32 bankId, s32 instId, void* arg3) {
if (bankId == 0xFF) {
return -1;
}
@@ -410,21 +410,21 @@ s32 func_800E7744(s32 instrument, s32 bankId, s32 instId, UnkInstrument* arg3) {
if (instId >= gAudioContext.gCtlEntries[bankId].numDrums) {
return -3;
}
- gAudioContext.gCtlEntries[bankId].drums[instId] = (void*)arg3;
+ gAudioContext.gCtlEntries[bankId].drums[instId] = arg3;
break;
case 1:
- if (instId >= gAudioContext.gCtlEntries[bankId].numUnkInstruments) {
+ if (instId >= gAudioContext.gCtlEntries[bankId].numSfx) {
return -3;
}
- gAudioContext.gCtlEntries[bankId].unkInstruments[instId] = *arg3;
+ gAudioContext.gCtlEntries[bankId].soundEffects[instId] = *(AudioBankSound*)arg3;
break;
default:
if (instId >= gAudioContext.gCtlEntries[bankId].numInstruments) {
return -3;
}
- gAudioContext.gCtlEntries[bankId].instruments[instId] = (void*)arg3;
+ gAudioContext.gCtlEntries[bankId].instruments[instId] = arg3;
break;
}
@@ -441,7 +441,7 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target)
return;
}
- seqLayer->bit3 = 0;
+ seqLayer->bit3 = false;
if (seqLayer->note == NULL) {
return;
@@ -458,7 +458,7 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target)
if (note->playbackState.parentLayer == NO_LAYER && note->playbackState.wantedParentLayer == NO_LAYER &&
note->playbackState.prevParentLayer == seqLayer && target != ADSR_STATE_DECAY) {
note->playbackState.adsr.fadeOutVel = gAudioContext.gAudioBufferParameters.updatesPerFrameInv;
- note->playbackState.adsr.action.s.release = 1;
+ note->playbackState.adsr.action.s.release = true;
}
return;
}
@@ -484,7 +484,7 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target)
attributes->unk_6 = chan->unk_20;
attributes->unk_4 = chan->unk_0F;
if (chan->seqPlayer->muted && (chan->muteBehavior & 8)) {
- note->noteSubEu.bitField0.s.finished = 1;
+ note->noteSubEu.bitField0.s.finished = true;
}
if (seqLayer->reverbBits.asByte == 0) {
@@ -502,11 +502,11 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target)
note->playbackState.parentLayer = NO_LAYER;
if (target == ADSR_STATE_RELEASE) {
note->playbackState.adsr.fadeOutVel = gAudioContext.gAudioBufferParameters.updatesPerFrameInv;
- note->playbackState.adsr.action.s.release = 1;
+ note->playbackState.adsr.action.s.release = true;
note->playbackState.unk_04 = 2;
} else {
note->playbackState.unk_04 = 1;
- note->playbackState.adsr.action.s.decay = 1;
+ note->playbackState.adsr.action.s.decay = true;
if (seqLayer->adsr.releaseRate == 0) {
note->playbackState.adsr.fadeOutVel = gAudioContext.unk_3520[seqLayer->seqChannel->adsr.releaseRate];
} else {
@@ -753,8 +753,8 @@ void Audio_NoteInitForLayer(Note* note, SequenceChannelLayer* seqLayer) {
note->playbackState.prevParentLayer = NO_LAYER;
note->playbackState.parentLayer = seqLayer;
playback->priority = seqLayer->seqChannel->notePriority;
- seqLayer->notePropertiesNeedInit = 1;
- seqLayer->bit3 = 1;
+ seqLayer->notePropertiesNeedInit = true;
+ seqLayer->bit3 = true;
seqLayer->note = note;
seqLayer->seqChannel->noteUnused = note;
seqLayer->seqChannel->layerUnused = seqLayer;
@@ -768,9 +768,9 @@ void Audio_NoteInitForLayer(Note* note, SequenceChannelLayer* seqLayer) {
sub->sound.audioBankSound = seqLayer->sound;
if (instId >= 0x80 && instId < 0xC0) {
- sub->bitField1.s.bit2 = 1;
+ sub->bitField1.s.bit2 = true;
} else {
- sub->bitField1.s.bit2 = 0;
+ sub->bitField1.s.bit2 = false;
}
if (sub->bitField1.s.bit2) {
@@ -792,7 +792,7 @@ void Audio_NoteReleaseAndTakeOwnership(Note* note, SequenceChannelLayer* seqLaye
note->playbackState.priority = seqLayer->seqChannel->notePriority;
note->playbackState.adsr.fadeOutVel = gAudioContext.gAudioBufferParameters.updatesPerFrameInv;
- note->playbackState.adsr.action.s.release = 1;
+ note->playbackState.adsr.action.s.release = true;
}
Note* Audio_AllocNoteFromDisabled(NotePool* pool, SequenceChannelLayer* seqLayer) {
@@ -906,7 +906,7 @@ Note* Audio_AllocNote(SequenceChannelLayer* seqLayer) {
return ret;
null_return:
- seqLayer->bit3 = 1;
+ seqLayer->bit3 = true;
return NULL;
}
@@ -929,7 +929,7 @@ void Audio_NoteInitAll(void) {
note->vibratoState.active = 0;
note->portamento.cur = 0;
note->portamento.speed = 0;
- note->playbackState.stereoHeadsetEffects = 0;
+ note->playbackState.stereoHeadsetEffects = false;
note->unk_BC = 0;
note->synthesisState.synthesisBuffers = Audio_AllocDmaMemory(&gAudioContext.gNotesAndBuffersPool, 0x1E0);
}
diff --git a/src/code/audio_seqplayer.c b/src/code/audio_seqplayer.c
index da5a2ff5c..0092249b2 100644
--- a/src/code/audio_seqplayer.c
+++ b/src/code/audio_seqplayer.c
@@ -110,14 +110,14 @@ void Audio_SequenceChannelInit(SequenceChannel* seqChannel) {
return;
}
- seqChannel->enabled = 0;
- seqChannel->finished = 0;
- seqChannel->stopScript = 0;
- seqChannel->stopSomething2 = 0;
- seqChannel->hasInstrument = 0;
- seqChannel->stereoHeadsetEffects = 0;
+ seqChannel->enabled = false;
+ seqChannel->finished = false;
+ seqChannel->stopScript = false;
+ seqChannel->stopSomething2 = false;
+ seqChannel->hasInstrument = false;
+ seqChannel->stereoHeadsetEffects = false;
seqChannel->transposition = 0;
- seqChannel->largeNotes = 0;
+ seqChannel->largeNotes = false;
seqChannel->bookOffset = 0;
seqChannel->reverbBits.asByte = 0;
seqChannel->changes.asByte = 0xff;
@@ -154,7 +154,7 @@ void Audio_SequenceChannelInit(SequenceChannel* seqChannel) {
seqChannel->soundScriptIO[i] = -1;
}
- seqChannel->unused = 0;
+ seqChannel->unused = false;
Audio_InitNoteLists(&seqChannel->notePool);
}
@@ -177,14 +177,14 @@ s32 Audio_SeqChannelSetLayer(SequenceChannel* seqChannel, s32 layerIdx) {
layer->seqChannel = seqChannel;
layer->adsr = seqChannel->adsr;
layer->adsr.releaseRate = 0;
- layer->enabled = 1;
- layer->finished = 0;
- layer->stopSomething = 0;
- layer->continuousNotes = 0;
- layer->bit3 = 0;
- layer->ignoreDrumPan = 0;
- layer->bit1 = 0;
- layer->notePropertiesNeedInit = 0;
+ layer->enabled = true;
+ layer->finished = false;
+ layer->stopSomething = false;
+ layer->continuousNotes = false;
+ layer->bit3 = false;
+ layer->ignoreDrumPan = false;
+ layer->bit1 = false;
+ layer->notePropertiesNeedInit = false;
layer->reverbBits.asByte = 0;
layer->portamento.mode = 0;
layer->scriptState.depth = 0;
@@ -210,8 +210,8 @@ void Audio_SeqChannelLayerDisable(SequenceChannelLayer* layer) {
} else {
Audio_SeqChanLayerNoteDecay(layer);
}
- layer->enabled = 0;
- layer->finished = 1;
+ layer->enabled = false;
+ layer->finished = true;
}
}
@@ -232,8 +232,8 @@ void Audio_SequenceChannelDisable(SequenceChannel* seqChannel) {
}
Audio_NotePoolClear(&seqChannel->notePool);
- seqChannel->enabled = 0;
- seqChannel->finished = 1;
+ seqChannel->enabled = false;
+ seqChannel->finished = true;
}
void Audio_SequencePlayerInitChannels(SequencePlayer* seqPlayer, u16 channelBits) {
@@ -267,8 +267,8 @@ void Audio_SequenceChannelEnable(SequencePlayer* seqPlayer, u8 channelIdx, void*
SequenceChannel* seqChannel = seqPlayer->channels[channelIdx];
s32 i;
- seqChannel->enabled = 1;
- seqChannel->finished = 0;
+ seqChannel->enabled = true;
+ seqChannel->finished = false;
seqChannel->scriptState.depth = 0;
seqChannel->scriptState.pc = script;
seqChannel->delay = 0;
@@ -280,7 +280,7 @@ void Audio_SequenceChannelEnable(SequencePlayer* seqPlayer, u8 channelIdx, void*
}
void Audio_SequencePlayerDisableAsFinished(SequencePlayer* seqPlayer) {
- seqPlayer->finished = 1;
+ seqPlayer->finished = true;
Audio_SequencePlayerDisable(seqPlayer);
}
@@ -290,8 +290,8 @@ void Audio_SequencePlayerDisable(SequencePlayer* seqPlayer) {
if (!seqPlayer->enabled) {
return;
}
- seqPlayer->enabled = 0;
- seqPlayer->finished = 1;
+ seqPlayer->enabled = false;
+ seqPlayer->finished = true;
if (Audio_IsSeqLoadComplete(seqPlayer->seqId)) {
Audio_SetSeqLoadStatus(seqPlayer->seqId, 3);
@@ -381,7 +381,7 @@ void Audio_SeqChannelLayerProcessScript(SequenceChannelLayer* layer) {
layer->delay--;
if (!layer->stopSomething && layer->delay <= layer->duration) {
Audio_SeqChanLayerNoteDecay(layer);
- layer->stopSomething = 1;
+ layer->stopSomething = true;
}
return;
}
@@ -418,13 +418,13 @@ void func_800E9ED8(SequenceChannelLayer* layer) {
PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_2) {
layer->portamento.mode = 0;
}
- layer->notePropertiesNeedInit = 1;
+ layer->notePropertiesNeedInit = true;
}
s32 func_800E9F64(SequenceChannelLayer* layer, s32 arg1) {
if (!layer->stopSomething && layer->sound != NULL && layer->sound->sample->bits4 == 2 &&
layer->sound->sample->bits2 != 0) {
- layer->stopSomething = 1;
+ layer->stopSomething = true;
return -1;
}
@@ -503,11 +503,11 @@ s32 func_800EA0C0(SequenceChannelLayer* layer) {
case 0xC4: // layer_continuousnoteson
case 0xC5: // layer_continuousnotesoff
if (cmd == 0xC4) {
- layer->continuousNotes = 1;
+ layer->continuousNotes = true;
} else {
- layer->continuousNotes = 0;
+ layer->continuousNotes = false;
}
- layer->bit1 = 0;
+ layer->bit1 = false;
Audio_SeqChanLayerNoteDecay(layer);
break;
@@ -578,7 +578,7 @@ s32 func_800EA0C0(SequenceChannelLayer* layer) {
break;
case 0xCC:
- layer->ignoreDrumPan = 1;
+ layer->ignoreDrumPan = true;
break;
case 0xCD:
@@ -617,11 +617,11 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) {
AudioBankSound* sound;
Instrument* instrument;
Drum* drum;
- AudioBankSound* unkInstrument;
+ s32 pad;
SequenceChannel* seqChannel;
SequencePlayer* seqPlayer;
u8 cmd;
- u16 unkInstrumentId;
+ u16 sfxId;
s32 cmd2;
s32 vel;
f32 time;
@@ -647,7 +647,7 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) {
layer->semitone = cmd;
drum = Audio_GetDrum(seqChannel->bankId, cmd);
if (drum == NULL) {
- layer->stopSomething = 1;
+ layer->stopSomething = true;
layer->delay2 = layer->delay;
return -1;
}
@@ -663,10 +663,10 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) {
case 1:
layer->semitone = cmd;
- unkInstrumentId = (layer->transposition << 6) + cmd;
- sound = (AudioBankSound*)Audio_GetUnkInstrument(seqChannel->bankId, unkInstrumentId);
+ sfxId = (layer->transposition << 6) + cmd;
+ sound = Audio_GetSfx(seqChannel->bankId, sfxId);
if (sound == NULL) {
- layer->stopSomething = 1;
+ layer->stopSomething = true;
layer->delay2 = layer->delay + 1;
return -1;
}
@@ -679,7 +679,7 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) {
cmd2 = cmd;
layer->semitone = cmd;
if (cmd >= 0x80) {
- layer->stopSomething = 1;
+ layer->stopSomething = true;
return -1;
}
if (layer->instOrWave == 0xFF) {
@@ -701,7 +701,7 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) {
layer->sound = NULL;
tuning = 1.0f;
if (instOrWave >= 0xC0) {
- layer->sound = &gAudioContext.largeSounds[instOrWave - 0xC0].sound;
+ layer->sound = &gAudioContext.gSynthesisReverbs[instOrWave - 0xC0].sound;
}
}
@@ -729,12 +729,12 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) {
portamento->extent = (freqScale2 / freqScale) - 1.0f;
if (PORTAMENTO_IS_SPECIAL(*portamento)) {
- speed = seqPlayer->tempo * 0x8000 / gAudioContext.unk_2898;
+ speed = seqPlayer->tempo * 0x8000 / gAudioContext.gTempoInternalToExternal;
if (layer->delay != 0) {
speed = speed * 0x100 / (layer->delay * layer->portamentoTime);
}
} else {
- speed = 0x20000 / (layer->portamentoTime * gAudioContext.gAudioBufferParameters.unk_08);
+ speed = 0x20000 / (layer->portamentoTime * gAudioContext.gAudioBufferParameters.updatesPerFrame);
}
if (speed >= 0x7FFF) {
@@ -761,7 +761,7 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) {
layer->sound = NULL;
layer->freqScale = gNoteFrequencies[cmd2];
if (instOrWave >= 0xC0) {
- layer->sound = &gAudioContext.largeSounds[instOrWave - 0xC0].sound;
+ layer->sound = &gAudioContext.gSynthesisReverbs[instOrWave - 0xC0].sound;
}
}
break;
@@ -788,7 +788,7 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) {
// set when this is reached...)
if (PORTAMENTO_IS_SPECIAL(*portamento)) {
s32 speed2;
- speed2 = seqPlayer->tempo * 0x8000 / gAudioContext.unk_2898;
+ speed2 = seqPlayer->tempo * 0x8000 / gAudioContext.gTempoInternalToExternal;
speed2 = speed2 * 0x100 / (layer->delay * layer->portamentoTime);
if (speed2 >= 0x7FFF) {
speed2 = 0x7FFF;
@@ -817,12 +817,12 @@ s32 func_800EAAE0(SequenceChannelLayer* layer, s32 arg1) {
if (arg1 == 0xC0) {
layer->delay = Audio_M64ReadCompressedU16(state);
- layer->stopSomething = 1;
- layer->bit1 = 0;
+ layer->stopSomething = true;
+ layer->bit1 = false;
return -1;
}
- layer->stopSomething = 0;
+ layer->stopSomething = false;
if (seqChannel->largeNotes == 1) {
switch (arg1 & 0xC0) {
case 0:
@@ -902,11 +902,11 @@ s32 func_800EAAE0(SequenceChannelLayer* layer, s32 arg1) {
}
if ((seqPlayer->muted && (seqChannel->muteBehavior & (0x40 | 0x10)) != 0) || seqChannel->stopSomething2) {
- layer->stopSomething = 1;
+ layer->stopSomething = true;
return -1;
}
if (seqPlayer->unk_DC != 0) {
- layer->stopSomething = 1;
+ layer->stopSomething = true;
return -1;
}
return arg1;
@@ -947,10 +947,10 @@ void Audio_SetInstrument(SequenceChannel* seqChannel, u8 instId) {
seqChannel->instrument = (Instrument*)2;
} else if ((seqChannel->instOrWave =
Audio_GetInstrument(seqChannel, instId, &seqChannel->instrument, &seqChannel->adsr)) == 0) {
- seqChannel->hasInstrument = 0;
+ seqChannel->hasInstrument = false;
return;
}
- seqChannel->hasInstrument = 1;
+ seqChannel->hasInstrument = true;
}
void Audio_SequenceChannelSetVolume(SequenceChannel* seqChannel, u8 volume) {
@@ -970,8 +970,8 @@ void Audio_ProcessSequences(s32 arg0) {
u32 i;
gAudioContext.gNoteSubEuOffset =
- (gAudioContext.gAudioBufferParameters.unk_08 - arg0 - 1) * gAudioContext.gMaxSimultaneousNotes;
- for (i = 0; i < (u32)gAudioContext.gAudioBufferParameters.unk_10; i++) {
+ (gAudioContext.gAudioBufferParameters.updatesPerFrame - arg0 - 1) * gAudioContext.gMaxSimultaneousNotes;
+ for (i = 0; i < (u32)gAudioContext.gAudioBufferParameters.numSequencePlayers; i++) {
seqPlayer = &gAudioContext.gSequencePlayers[i];
if (seqPlayer->enabled == 1) {
Audio_SequencePlayerProcessSequence(seqPlayer);
@@ -993,7 +993,7 @@ void Audio_ResetSequencePlayer(SequencePlayer* seqPlayer) {
s32 i;
Audio_SequencePlayerDisable(seqPlayer);
- seqPlayer->unk_0b2 = 0;
+ seqPlayer->unk_0b2 = false;
seqPlayer->delay = 0;
seqPlayer->state = 1;
seqPlayer->fadeTimer = 0;
@@ -1029,7 +1029,7 @@ void func_800EC734(s32 seqPlayerIdx) {
} else {
seqChannel = seqPlayer->channels[i];
seqChannel->seqPlayer = seqPlayer;
- seqChannel->enabled = 0;
+ seqChannel->enabled = false;
for (j = 0; j < 4; j++) {
seqChannel->layers[j] = NULL;
}
@@ -1045,11 +1045,11 @@ void Audio_InitSequencePlayer(SequencePlayer* seqPlayer) {
seqPlayer->channels[i] = &gAudioContext.gSequenceChannelNone;
}
- seqPlayer->enabled = 0;
- seqPlayer->muted = 0;
- seqPlayer->bankDmaInProgress = 0;
- seqPlayer->seqDmaInProgress = 0;
- seqPlayer->unk_0b1 = 0;
+ seqPlayer->enabled = false;
+ seqPlayer->muted = false;
+ seqPlayer->bankDmaInProgress = false;
+ seqPlayer->seqDmaInProgress = false;
+ seqPlayer->unk_0b1 = false;
for (j = 0; j < 8; j++) {
seqPlayer->unk_158[j] = -1;
@@ -1067,7 +1067,7 @@ void Audio_InitSequencePlayers(void) {
Audio_InitLayerFreelist();
for (i = 0; i < 64; i++) {
gAudioContext.gSequenceLayers[i].seqChannel = NULL;
- gAudioContext.gSequenceLayers[i].enabled = 0;
+ gAudioContext.gSequenceLayers[i].enabled = false;
}
for (i = 0; i < 4; i++) {