diff options
| author | krimtonz <33664508+krimtonz@users.noreply.github.com> | 2021-07-27 18:44:58 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-27 19:44:58 -0400 |
| commit | d1a5ea5110ee3a8e7d2f0ed54921570fdccee65c (patch) | |
| tree | ad0a67c7adeb2df31be0476891ee5191ed30df7f /src/code | |
| parent | cc9a04feb43cb5481e5a503259276af12a824dc1 (diff) | |
Audio WIP (#836)
* being code_800EC960
* wip
* wip
* more audio progress
* migrate data in code_800E11F0
* wip
* make ok
* remove asm
* wip
* move some variables outside of gAudioContext to the AudioContext structure due to the size used in func_800E3094
* more progress
* wip
* wip
* split code_800E11F0
* migrate rodata in code_800E11F0
* match functions that couldn't because of data issues
* move code_800E4FE0 asm files
* wip
* more wip
* fix global functions, and forward declarations
* wip
* wip
* wip
* ocarina wip
* match a couple functions
* some progress
* separate some bss
* match func_800EDA3C
* some matching
* more matches
* migrate audio rodata
* some matches
* more matchess
* start on synthesis
* work on synthesis
* fix function declaration
* Merge branch 'master' into audio
* match a few more functions
* wip
* wip
* more matching, rename Audio_SetBGM to Audio_QueueSeqCmd
* name several audio functions, and audiocontext members
* more naming, rename code_800E11F0 to audio_load, code_800DAAC0 to audio_synthesis
* audio wip
* match a few more functions.
* wip
* add missing NON_MATCHING directive
* wip
* some matching, data reogranization
* match cursed function
* wip
* wip
* formatting
* remove prefix from struct memebers
* missed function rename
* review
Co-authored-by: fig02 <fig02srl@gmail.com>
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/audioMgr.c | 40 | ||||
| -rw-r--r-- | src/code/audio_effects.c | 2 | ||||
| -rw-r--r-- | src/code/audio_heap.c | 515 | ||||
| -rw-r--r-- | src/code/audio_load.c | 1652 | ||||
| -rw-r--r-- | src/code/audio_playback.c | 112 | ||||
| -rw-r--r-- | src/code/audio_rodata.c | 7 | ||||
| -rw-r--r-- | src/code/audio_seqplayer.c | 92 | ||||
| -rw-r--r-- | src/code/audio_synthesis.c | 1199 | ||||
| -rw-r--r-- | src/code/code_800DACC0.c | 136 | ||||
| -rw-r--r-- | src/code/code_800E11F0.c | 234 | ||||
| -rw-r--r-- | src/code/code_800E4FE0.c | 844 | ||||
| -rw-r--r-- | src/code/code_800EC960.c | 3598 | ||||
| -rw-r--r-- | src/code/code_800F7260.c | 61 | ||||
| -rw-r--r-- | src/code/code_800F9280.c | 466 | ||||
| -rw-r--r-- | src/code/game.c | 10 | ||||
| -rw-r--r-- | src/code/graph.c | 2 | ||||
| -rw-r--r-- | src/code/sched.c | 2 | ||||
| -rw-r--r-- | src/code/z_demo.c | 4 | ||||
| -rw-r--r-- | src/code/z_scene.c | 2 |
19 files changed, 7912 insertions, 1066 deletions
diff --git a/src/code/audioMgr.c b/src/code/audioMgr.c index ebe5307e9..f64f4ba91 100644 --- a/src/code/audioMgr.c +++ b/src/code/audioMgr.c @@ -1,52 +1,52 @@ #include "global.h" void func_800C3C80(AudioMgr* audioMgr) { - Sub_AudioMgr_18* sub = audioMgr->unk_70; + AudioTask* task; - if (audioMgr->unk_70->unk_40 != NULL) { - osSendMesg(sub->unk_40, NULL, OS_MESG_BLOCK); + task = audioMgr->rspTask; + if (audioMgr->rspTask->taskQueue != NULL) { + osSendMesg(task->taskQueue, NULL, OS_MESG_BLOCK); } } void AudioMgr_HandleRetrace(AudioMgr* audioMgr) { - Sub_AudioMgr_18* sub; + AudioTask* rspTask; if (SREG(20) > 0) { - audioMgr->unk_70 = NULL; + audioMgr->rspTask = NULL; } - if (audioMgr->unk_70 != NULL) { - audioMgr->unk_8 = NULL; - audioMgr->unk_10 = 2; - audioMgr->unk_14 = 0; + if (audioMgr->rspTask != NULL) { + audioMgr->audioTask.next = NULL; + audioMgr->audioTask.flags = 2; + audioMgr->audioTask.framebuffer = NULL; - audioMgr->unk_18.unk_0 = audioMgr->unk_70->unk_0; - audioMgr->unk_18.unk_40 = &audioMgr->unk_AC; + audioMgr->audioTask.list = audioMgr->rspTask->task; + audioMgr->audioTask.msgQ = &audioMgr->unk_AC; - audioMgr->unk_5C = NULL; - osSendMesg(&audioMgr->sched->cmdQ, &audioMgr->unk_8, OS_MESG_BLOCK); + audioMgr->audioTask.msg = NULL; + osSendMesg(&audioMgr->sched->cmdQ, &audioMgr->audioTask, OS_MESG_BLOCK); Sched_SendEntryMsg(audioMgr->sched); } D_8016A550 = osGetTime(); if (SREG(20) >= 2) { - sub = NULL; + rspTask = NULL; } else { - sub = func_800E4FE0(); + rspTask = func_800E4FE0(); } D_8016A558 += osGetTime() - D_8016A550; D_8016A550 = 0; - - if (audioMgr->unk_70 != NULL) { + if (audioMgr->rspTask != NULL) { osRecvMesg(&audioMgr->unk_AC, NULL, OS_MESG_BLOCK); func_800C3C80(audioMgr); } - audioMgr->unk_70 = sub; + audioMgr->rspTask = rspTask; } void AudioMgr_HandlePRENMI(AudioMgr* audioMgr) { // Audio manager received OS_SC_PRE_NMI_MSG osSyncPrintf("オーディオマネージャが OS_SC_PRE_NMI_MSG を受け取りました\n"); - func_800F6C14(); + Audio_PreNMI(); } void AudioMgr_ThreadEntry(void* arg0) { @@ -94,7 +94,7 @@ void AudioMgr_Init(AudioMgr* audioMgr, void* stack, OSPri pri, OSId id, SchedCon audioMgr->sched = sched; audioMgr->irqMgr = irqMgr; - audioMgr->unk_70 = NULL; + audioMgr->rspTask = NULL; osCreateMesgQueue(&audioMgr->unk_AC, &audioMgr->unk_C4, 1); osCreateMesgQueue(&audioMgr->unk_74, &audioMgr->unk_8C, 8); diff --git a/src/code/audio_effects.c b/src/code/audio_effects.c index 45d267fb0..73b5c9d1a 100644 --- a/src/code/audio_effects.c +++ b/src/code/audio_effects.c @@ -258,7 +258,7 @@ f32 Audio_AdsrUpdate(AdsrState* adsr) { break; default: - adsr->delay *= gAudioContext.gAudioBufferParameters.unk_24; + adsr->delay *= gAudioContext.audioBufferParameters.unk_24; if (adsr->delay == 0) { adsr->delay = 1; } diff --git a/src/code/audio_heap.c b/src/code/audio_heap.c index ff221da46..f7874ed38 100644 --- a/src/code/audio_heap.c +++ b/src/code/audio_heap.c @@ -2,7 +2,7 @@ #include "global.h" f32 func_800DDE20(f32 arg0) { - return 256.0f * gAudioContext.gAudioBufferParameters.unkUpdatesPerFrameScaled / arg0; + return 256.0f * gAudioContext.audioBufferParameters.unkUpdatesPerFrameScaled / arg0; } void func_800DDE3C(void) { @@ -33,20 +33,20 @@ void Audio_ResetLoadStatus(void) { s32 i; for (i = 0; i < 0x30; i++) { - if (gAudioContext.gBankLoadStatus[i] != 5) { - gAudioContext.gBankLoadStatus[i] = 0; + if (gAudioContext.bankLoadStatus[i] != 5) { + gAudioContext.bankLoadStatus[i] = 0; } } for (i = 0; i < 0x30; i++) { - if (gAudioContext.gUnusedLoadStatus[i] != 5) { - gAudioContext.gUnusedLoadStatus[i] = 0; + if (gAudioContext.audioTableLoadStatus[i] != 5) { + gAudioContext.audioTableLoadStatus[i] = 0; } } for (i = 0; i < 0x80; i++) { - if (gAudioContext.gSeqLoadStatus[i] != 5) { - gAudioContext.gSeqLoadStatus[i] = 0; + if (gAudioContext.seqLoadstatus[i] != 5) { + gAudioContext.seqLoadstatus[i] = 0; } } } @@ -54,8 +54,8 @@ void Audio_ResetLoadStatus(void) { void Audio_DiscardBank(s32 bankId) { s32 i; - for (i = 0; i < gAudioContext.gMaxSimultaneousNotes; i++) { - Note* note = &gAudioContext.gNotes[i]; + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + Note* note = &gAudioContext.notes[i]; if (note->playbackState.bankId == bankId) { if (note->playbackState.unk_04 == 0 && note->playbackState.priority != 0) { @@ -64,7 +64,7 @@ void Audio_DiscardBank(s32 bankId) { } Audio_NoteDisable(note); Audio_AudioListRemove(¬e->listItem); - Audio_AudioListPushBack(&gNoteFreeLists.disabled, ¬e->listItem); + Audio_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, ¬e->listItem); } } } @@ -72,14 +72,14 @@ void Audio_DiscardBank(s32 bankId) { void func_800DE12C(s32 bankId) { s32 i; - for (i = 0; i < gAudioContext.gMaxSimultaneousNotes; i++) { - Note* note = &gAudioContext.gNotes[i]; + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + Note* note = &gAudioContext.notes[i]; NotePlaybackState* state = ¬e->playbackState; 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.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; state->adsr.action.s.release = true; } } @@ -89,22 +89,22 @@ void func_800DE12C(s32 bankId) { void Audio_DiscardSequence(s32 seqId) { s32 i; - for (i = 0; i < gAudioContext.gAudioBufferParameters.numSequencePlayers; i++) { - if (gAudioContext.gSequencePlayers[i].enabled && gAudioContext.gSequencePlayers[i].seqId == seqId) { - Audio_SequencePlayerDisable(&gAudioContext.gSequencePlayers[i]); + for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { + if (gAudioContext.seqPlayers[i].enabled && gAudioContext.seqPlayers[i].seqId == seqId) { + Audio_SequencePlayerDisable(&gAudioContext.seqPlayers[i]); } } } void func_800DE238(void* mem, u32 size) { - func_800E6880(mem, size); + Audio_osWritebackDCache(mem, size); } void* func_800DE258(SoundAllocPool* pool, u32 size) { void* ret = NULL; - if (gAudioContext.gUnkPool.start != 0) { - ret = Audio_AllocZeroed(&gAudioContext.gUnkPool, size); + if (gAudioContext.unkPool.start != 0) { + ret = Audio_AllocZeroed(&gAudioContext.unkPool, size); } if (ret == NULL) { ret = Audio_AllocZeroed(pool, size); @@ -115,8 +115,8 @@ void* func_800DE258(SoundAllocPool* pool, u32 size) { void* func_800DE2B0(SoundAllocPool* pool, u32 size) { void* ret = NULL; - if (gAudioContext.gUnkPool.start != NULL) { - ret = Audio_Alloc(&gAudioContext.gUnkPool, size); + if (gAudioContext.unkPool.start != NULL) { + ret = Audio_Alloc(&gAudioContext.unkPool, size); } if (ret == NULL) { ret = Audio_Alloc(pool, size); @@ -206,16 +206,16 @@ void func_800DE4B0(s32 poolIdx) { switch (poolIdx) { case 0: - loadedPool = &gAudioContext.gSeqLoadedPool; - table = gAudioContext.gSeqLoadStatus; + loadedPool = &gAudioContext.seqLoadedPool; + table = gAudioContext.seqLoadstatus; break; case 1: - loadedPool = &gAudioContext.gBankLoadedPool; - table = gAudioContext.gBankLoadStatus; + loadedPool = &gAudioContext.bankLoadedPool; + table = gAudioContext.bankLoadStatus; break; case 2: - loadedPool = &gAudioContext.gUnusedLoadedPool; - table = gAudioContext.gUnusedLoadStatus; + loadedPool = &gAudioContext.unusedLoadedPool; + table = gAudioContext.audioTableLoadStatus; break; } @@ -241,52 +241,52 @@ void func_800DE4B0(s32 poolIdx) { } 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; + Audio_SoundAllocPoolInit(&gAudioContext.audioInitPool, gAudioContext.audioHeap, sizeForAudioInitPool); + Audio_SoundAllocPoolInit(&gAudioContext.audioSessionPool, gAudioContext.audioHeap + sizeForAudioInitPool, + gAudioContext.audioHeapSize - sizeForAudioInitPool); + gAudioContext.unkPool.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); + gAudioContext.audioSessionPool.cur = gAudioContext.audioSessionPool.start; + Audio_SoundAllocPoolInit(&gAudioContext.notesAndBuffersPool, + Audio_Alloc(&gAudioContext.audioSessionPool, split->wantSeq), split->wantSeq); + Audio_SoundAllocPoolInit(&gAudioContext.seqAndBankPool, + Audio_Alloc(&gAudioContext.audioSessionPool, 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); + gAudioContext.seqAndBankPool.cur = gAudioContext.seqAndBankPool.start; + Audio_SoundAllocPoolInit(&gAudioContext.persistentCommonPool, + Audio_Alloc(&gAudioContext.seqAndBankPool, split->wantPersistent), split->wantPersistent); + Audio_SoundAllocPoolInit(&gAudioContext.temporaryCommonPool, + Audio_Alloc(&gAudioContext.seqAndBankPool, 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); + gAudioContext.persistentCommonPool.cur = gAudioContext.persistentCommonPool.start; + Audio_SoundAllocPoolInit(&gAudioContext.seqLoadedPool.persistent.pool, + Audio_Alloc(&gAudioContext.persistentCommonPool, split->wantSeq), split->wantSeq); + Audio_SoundAllocPoolInit(&gAudioContext.bankLoadedPool.persistent.pool, + Audio_Alloc(&gAudioContext.persistentCommonPool, split->wantBank), split->wantBank); + Audio_SoundAllocPoolInit(&gAudioContext.unusedLoadedPool.persistent.pool, + Audio_Alloc(&gAudioContext.persistentCommonPool, split->wantUnused), split->wantUnused); + Audio_PersistentPoolClear(&gAudioContext.seqLoadedPool.persistent); + Audio_PersistentPoolClear(&gAudioContext.bankLoadedPool.persistent); + Audio_PersistentPoolClear(&gAudioContext.unusedLoadedPool.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); + gAudioContext.temporaryCommonPool.cur = gAudioContext.temporaryCommonPool.start; + Audio_SoundAllocPoolInit(&gAudioContext.seqLoadedPool.temporary.pool, + Audio_Alloc(&gAudioContext.temporaryCommonPool, split->wantSeq), split->wantSeq); + Audio_SoundAllocPoolInit(&gAudioContext.bankLoadedPool.temporary.pool, + Audio_Alloc(&gAudioContext.temporaryCommonPool, split->wantBank), split->wantBank); + Audio_SoundAllocPoolInit(&gAudioContext.unusedLoadedPool.temporary.pool, + Audio_Alloc(&gAudioContext.temporaryCommonPool, split->wantUnused), split->wantUnused); + Audio_TemporaryPoolClear(&gAudioContext.seqLoadedPool.temporary); + Audio_TemporaryPoolClear(&gAudioContext.bankLoadedPool.temporary); + Audio_TemporaryPoolClear(&gAudioContext.unusedLoadedPool.temporary); } void* Audio_AllocBankOrSeq(s32 poolIdx, s32 size, s32 arg2, s32 id) { @@ -303,16 +303,16 @@ void* Audio_AllocBankOrSeq(s32 poolIdx, s32 size, s32 arg2, s32 id) { switch (poolIdx) { case 0: - loadedPool = &gAudioContext.gSeqLoadedPool; - table = gAudioContext.gSeqLoadStatus; + loadedPool = &gAudioContext.seqLoadedPool; + table = gAudioContext.seqLoadstatus; break; case 1: - loadedPool = &gAudioContext.gBankLoadedPool; - table = gAudioContext.gBankLoadStatus; + loadedPool = &gAudioContext.bankLoadedPool; + table = gAudioContext.bankLoadStatus; break; case 2: - loadedPool = &gAudioContext.gUnusedLoadedPool; - table = gAudioContext.gUnusedLoadStatus; + loadedPool = &gAudioContext.unusedLoadedPool; + table = gAudioContext.audioTableLoadStatus; break; } @@ -329,28 +329,28 @@ void* Audio_AllocBankOrSeq(s32 poolIdx, s32 size, s32 arg2, s32 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) { + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + if (gAudioContext.notes[i].playbackState.bankId == tp->entries[0].id && + gAudioContext.notes[i].noteSubEu.bitField0.s.enabled != 0) { break; } } - if (i == gAudioContext.gMaxSimultaneousNotes) { + if (i == gAudioContext.maxSimultaneousNotes) { 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) { + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + if (gAudioContext.notes[i].playbackState.bankId == tp->entries[1].id && + gAudioContext.notes[i].noteSubEu.bitField0.s.enabled != 0) { break; } } - if (i == gAudioContext.gMaxSimultaneousNotes) { + if (i == gAudioContext.maxSimultaneousNotes) { Audio_SetBankLoadStatus(tp->entries[1].id, 3); secondVal = 3; } @@ -371,54 +371,54 @@ void* Audio_AllocBankOrSeq(s32 poolIdx, s32 size, s32 arg2, s32 id) { // 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) { + for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { + if (gAudioContext.seqPlayers[i].enabled != 0 && + gAudioContext.seqPlayers[i].seqId == tp->entries[0].id) { break; } } - if (i == gAudioContext.gAudioBufferParameters.numSequencePlayers) { + if (i == gAudioContext.audioBufferParameters.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) { + for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { + if (gAudioContext.seqPlayers[i].enabled != 0 && + gAudioContext.seqPlayers[i].seqId == tp->entries[1].id) { break; } } - if (i == gAudioContext.gAudioBufferParameters.numSequencePlayers) { + if (i == gAudioContext.audioBufferParameters.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) { + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + if (gAudioContext.notes[i].playbackState.bankId == tp->entries[0].id && + gAudioContext.notes[i].noteSubEu.bitField0.s.enabled != 0) { break; } } - if (i == gAudioContext.gMaxSimultaneousNotes) { + if (i == gAudioContext.maxSimultaneousNotes) { 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) { + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + if (gAudioContext.notes[i].playbackState.bankId == tp->entries[1].id && + gAudioContext.notes[i].noteSubEu.bitField0.s.enabled != 0) { break; } } - if (i == gAudioContext.gMaxSimultaneousNotes) { + if (i == gAudioContext.maxSimultaneousNotes) { tp->nextSide = 1; goto done; } @@ -565,13 +565,13 @@ void* func_800DF0CC(s32 poolIdx, s32 arg1, s32 bankId) { switch (poolIdx) { case 0: - loadedPool = &gAudioContext.gSeqLoadedPool; + loadedPool = &gAudioContext.seqLoadedPool; break; case 1: - loadedPool = &gAudioContext.gBankLoadedPool; + loadedPool = &gAudioContext.bankLoadedPool; break; case 2: - loadedPool = &gAudioContext.gUnusedLoadedPool; + loadedPool = &gAudioContext.unusedLoadedPool; break; } @@ -673,15 +673,15 @@ void func_800DF7C4(void) { s32 i; s32 j; - if (gAudioContext.gAudioBufferParameters.presetUnk4 == 2) { + if (gAudioContext.audioBufferParameters.presetUnk4 == 2) { count = 2; } else { count = 1; } - for (i = 0; i < gAudioContext.gNumSynthesisReverbs; i++) { + for (i = 0; i < gAudioContext.numSynthesisReverbs; i++) { for (j = 0; j < count; j++) { - func_800DF7BC(&gAudioContext.gSynthesisReverbs[i]); + func_800DF7BC(&gAudioContext.synthesisReverbs[i]); } } } @@ -690,11 +690,11 @@ void func_800DF888(void) { s32 ind; s32 i; - ind = gAudioContext.unk_28A8; - gAudioContext.unk_2974[ind] = gAudioContext.gAudioBufferParameters.minAiBufferLength; + ind = gAudioContext.curAIBufIdx; + gAudioContext.aiBufLengths[ind] = gAudioContext.audioBufferParameters.minAiBufferLength; for (i = 0; i < 0x580; i++) { - gAudioContext.unk_2968[ind][i] = 0; + gAudioContext.aiBuffers[ind][i] = 0; } } @@ -703,80 +703,80 @@ s32 Audio_ResetStep(void) { s32 j; s32 sp24; - if (gAudioContext.gAudioBufferParameters.presetUnk4 == 2) { + if (gAudioContext.audioBufferParameters.presetUnk4 == 2) { sp24 = 2; } else { sp24 = 1; } - switch (gAudioContext.gAudioResetStatus) { + switch (gAudioContext.resetStatus) { case 5: - for (i = 0; i < gAudioContext.gAudioBufferParameters.numSequencePlayers; i++) { - Audio_SequencePlayerDisableAsFinished(&gAudioContext.gSequencePlayers[i]); + for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { + Audio_SequencePlayerDisableAsFinished(&gAudioContext.seqPlayers[i]); } - gAudioContext.gAudioResetFadeOutFramesLeft = 2 / sp24; - gAudioContext.gAudioResetStatus--; + gAudioContext.audioResetFadeOutFramesLeft = 2 / sp24; + gAudioContext.resetStatus--; break; case 4: - if (gAudioContext.gAudioResetFadeOutFramesLeft != 0) { - gAudioContext.gAudioResetFadeOutFramesLeft--; + if (gAudioContext.audioResetFadeOutFramesLeft != 0) { + gAudioContext.audioResetFadeOutFramesLeft--; 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; + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + if (gAudioContext.notes[i].noteSubEu.bitField0.s.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; } } - gAudioContext.gAudioResetFadeOutFramesLeft = 8 / sp24; - gAudioContext.gAudioResetStatus--; + gAudioContext.audioResetFadeOutFramesLeft = 8 / sp24; + gAudioContext.resetStatus--; } break; case 3: - if (gAudioContext.gAudioResetFadeOutFramesLeft != 0) { - gAudioContext.gAudioResetFadeOutFramesLeft--; + if (gAudioContext.audioResetFadeOutFramesLeft != 0) { + gAudioContext.audioResetFadeOutFramesLeft--; func_800DF7C4(); } else { - gAudioContext.gAudioResetFadeOutFramesLeft = 2 / sp24; - gAudioContext.gAudioResetStatus--; + gAudioContext.audioResetFadeOutFramesLeft = 2 / sp24; + gAudioContext.resetStatus--; } break; case 2: func_800DF888(); - if (gAudioContext.gAudioResetFadeOutFramesLeft != 0) { - gAudioContext.gAudioResetFadeOutFramesLeft--; + if (gAudioContext.audioResetFadeOutFramesLeft != 0) { + gAudioContext.audioResetFadeOutFramesLeft--; } else { - gAudioContext.gAudioResetStatus--; + gAudioContext.resetStatus--; func_800E0CBC(); func_800E1148(); } break; case 1: - func_800DFBF8(); - gAudioContext.gAudioResetStatus = 0; + Audio_InitHeap(); + gAudioContext.resetStatus = 0; for (i = 0; i < 3; i++) { - gAudioContext.unk_2974[i] = gAudioContext.gAudioBufferParameters.maxAiBufferLength; + gAudioContext.aiBufLengths[i] = gAudioContext.audioBufferParameters.maxAiBufferLength; for (j = 0; j < 0x580; j++) { - gAudioContext.unk_2968[i][j] = 0; + gAudioContext.aiBuffers[i][j] = 0; } } break; } - if (gAudioContext.gAudioResetStatus < 3) { + if (gAudioContext.resetStatus < 3) { return 0; } return 1; } -void func_800DFBF8(void) { +void Audio_InitHeap(void) { s32 pad1[4]; s16* mem; s32 persistentMem; @@ -787,112 +787,113 @@ void func_800DFBF8(void) { s32 i; s32 j; s32 pad2; - AudioSessionSettings* 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) & + AudioSessionSettings* preset = &gAudioSessionPresets[gAudioContext.audioResetPresetIdToLoad]; + + preset = &gAudioSessionPresets[gAudioContext.audioResetPresetIdToLoad]; + gAudioContext.sampleDmaReqCnt = 0; + gAudioContext.audioBufferParameters.frequency = preset->frequency; + gAudioContext.audioBufferParameters.aiFrequency = osAiSetFrequency(gAudioContext.audioBufferParameters.frequency); + gAudioContext.audioBufferParameters.samplesPerFrameTarget = + ((gAudioContext.audioBufferParameters.frequency / gAudioContext.refreshRate) + 0xF) & 0xFFF0; + 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.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.audioBufferParameters.samplesPerUpdateMax = + gAudioContext.audioBufferParameters.samplesPerUpdate + 8; + gAudioContext.audioBufferParameters.samplesPerUpdateMin = + gAudioContext.audioBufferParameters.samplesPerUpdate - 8; + gAudioContext.audioBufferParameters.resampleRate = 32000.0f / (s32)gAudioContext.audioBufferParameters.frequency; + gAudioContext.audioBufferParameters.unkUpdatesPerFrameScaled = + (1.0f / 256.0f) / gAudioContext.audioBufferParameters.updatesPerFrame; + gAudioContext.audioBufferParameters.unk_24 = gAudioContext.audioBufferParameters.updatesPerFrame * 0.25f; + gAudioContext.audioBufferParameters.updatesPerFrameInv = + 1.0f / gAudioContext.audioBufferParameters.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.maxSimultaneousNotes = preset->maxSimultaneousNotes; + gAudioContext.audioBufferParameters.numSequencePlayers = preset->numSequencePlayers; + if (gAudioContext.audioBufferParameters.numSequencePlayers > 4) { + gAudioContext.audioBufferParameters.numSequencePlayers = 4; } gAudioContext.unk_2 = preset->unk_14; - gAudioContext.gTempoInternalToExternal = (u32)(gAudioContext.gAudioBufferParameters.updatesPerFrame * 2880000.0f / + gAudioContext.tempoInternalToExternal = (u32)(gAudioContext.audioBufferParameters.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.unk_2870 = gAudioContext.refreshRate; + gAudioContext.unk_2870 *= gAudioContext.audioBufferParameters.updatesPerFrame; + gAudioContext.unk_2870 /= gAudioContext.audioBufferParameters.aiFrequency; + gAudioContext.unk_2870 /= gAudioContext.tempoInternalToExternal; - 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; + gAudioContext.audioBufferParameters.presetUnk4 = preset->unk_04; + gAudioContext.audioBufferParameters.samplesPerFrameTarget *= gAudioContext.audioBufferParameters.presetUnk4; + gAudioContext.audioBufferParameters.maxAiBufferLength *= gAudioContext.audioBufferParameters.presetUnk4; + gAudioContext.audioBufferParameters.minAiBufferLength *= gAudioContext.audioBufferParameters.presetUnk4; + gAudioContext.audioBufferParameters.updatesPerFrame *= gAudioContext.audioBufferParameters.presetUnk4; - if (gAudioContext.gAudioBufferParameters.presetUnk4 >= 2) { - gAudioContext.gAudioBufferParameters.maxAiBufferLength -= 0x10; + if (gAudioContext.audioBufferParameters.presetUnk4 >= 2) { + gAudioContext.audioBufferParameters.maxAiBufferLength -= 0x10; } - gAudioContext.gMaxAudioCmds = - gAudioContext.gMaxSimultaneousNotes * 0x10 * gAudioContext.gAudioBufferParameters.updatesPerFrame + + gAudioContext.maxAudioCmds = + gAudioContext.maxSimultaneousNotes * 0x10 * gAudioContext.audioBufferParameters.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); + wantMisc = gAudioContext.audioSessionPool.size - totalMem - 0x100; + + if (gAudioContext.unkPool.start != NULL) { + gAudioContext.unkPool.cur = gAudioContext.unkPool.start; + } + + gAudioContext.sessionPoolSplit.wantSeq = wantMisc; + gAudioContext.sessionPoolSplit.wantCustom = totalMem; + Audio_SessionPoolsInit(&gAudioContext.sessionPoolSplit); + gAudioContext.seqAndBankPoolSplit.wantPersistent = persistentMem; + gAudioContext.seqAndBankPoolSplit.wantTemporary = temporaryMem; + Audio_SeqAndBankPoolInit(&gAudioContext.seqAndBankPoolSplit); + gAudioContext.persistentCommonPoolSplit.wantSeq = preset->persistentSeqMem; + gAudioContext.persistentCommonPoolSplit.wantBank = preset->persistentBankMem; + gAudioContext.persistentCommonPoolSplit.wantUnused = preset->persistentUnusedMem; + Audio_PersistentPoolsInit(&gAudioContext.persistentCommonPoolSplit); + gAudioContext.temporaryCommonPoolSplit.wantSeq = preset->temporarySeqMem; + gAudioContext.temporaryCommonPoolSplit.wantBank = preset->temporaryBankMem; + gAudioContext.temporaryCommonPoolSplit.wantUnused = preset->temporaryUnusedMem; + Audio_TemporaryPoolsInit(&gAudioContext.temporaryCommonPoolSplit); Audio_ResetLoadStatus(); - gAudioContext.gNotes = - Audio_AllocZeroed(&gAudioContext.gNotesAndBuffersPool, gAudioContext.gMaxSimultaneousNotes * sizeof(Note)); + gAudioContext.notes = + Audio_AllocZeroed(&gAudioContext.notesAndBuffersPool, gAudioContext.maxSimultaneousNotes * sizeof(Note)); Audio_NoteInitAll(); Audio_InitNoteFreeList(); - gAudioContext.gNoteSubsEu = Audio_AllocZeroed(&gAudioContext.gNotesAndBuffersPool, - gAudioContext.gAudioBufferParameters.updatesPerFrame * - gAudioContext.gMaxSimultaneousNotes * sizeof(NoteSubEu)); + gAudioContext.noteSubsEu = Audio_AllocZeroed(&gAudioContext.notesAndBuffersPool, + gAudioContext.audioBufferParameters.updatesPerFrame * + gAudioContext.maxSimultaneousNotes * sizeof(NoteSubEu)); for (i = 0; i != 2; i++) { - gAudioContext.gAudioCmdBuffers[i] = - Audio_AllocDmaMemoryZeroed(&gAudioContext.gNotesAndBuffersPool, gAudioContext.gMaxAudioCmds * sizeof(u64)); + gAudioContext.abiCmdBufs[i] = + Audio_AllocDmaMemoryZeroed(&gAudioContext.notesAndBuffersPool, gAudioContext.maxAudioCmds * sizeof(u64)); } - gAudioContext.unk_3520 = Audio_Alloc(&gAudioContext.gNotesAndBuffersPool, 0x100 * sizeof(f32)); + gAudioContext.unk_3520 = Audio_Alloc(&gAudioContext.notesAndBuffersPool, 0x100 * sizeof(f32)); func_800DDE3C(); for (i = 0; i < 4; i++) { - gAudioContext.gSynthesisReverbs[i].useReverb = 0; + gAudioContext.synthesisReverbs[i].useReverb = 0; } - gAudioContext.gNumSynthesisReverbs = preset->numReverbs; - for (i = 0; i < gAudioContext.gNumSynthesisReverbs; i++) { + gAudioContext.numSynthesisReverbs = preset->numReverbs; + for (i = 0; i < gAudioContext.numSynthesisReverbs; i++) { ReverbSettings* settings = &preset->reverbSettings[i]; - SynthesisReverb* reverb = &gAudioContext.gSynthesisReverbs[i]; + SynthesisReverb* reverb = &gAudioContext.synthesisReverbs[i]; reverb->downsampleRate = settings->downsampleRate; reverb->windowSize = settings->windowSize * 64; reverb->windowSize /= reverb->downsampleRate; @@ -906,52 +907,52 @@ void func_800DFBF8(void) { 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->leftRingBuf = func_800DE258(&gAudioContext.notesAndBuffersPool, reverb->windowSize * sizeof(s16)); + reverb->rightRingBuf = func_800DE258(&gAudioContext.notesAndBuffersPool, reverb->windowSize * sizeof(s16)); + reverb->nextRingBufPos = 0; reverb->unk_20 = 0; - reverb->unk_03 = 0; - reverb->unk_24 = reverb->windowSize; - reverb->unk_02 = 2; - reverb->unk_00 = 1; + reverb->curFrame = 0; + reverb->bufSizePerChan = reverb->windowSize; + reverb->framesToIgnore = 2; + reverb->resampleFlags = 1; reverb->sound.sample = &reverb->sample; reverb->sample.loop = &reverb->loop; reverb->sound.tuning = 1.0f; reverb->sample.bits4 = 4; reverb->sample.bits2 = 0; - reverb->sample.bits24 = reverb->windowSize * 2; - reverb->sample.sampleAddr = (u8*)reverb->unk_28; + reverb->sample.size = reverb->windowSize * 2; + reverb->sample.sampleAddr = (u8*)reverb->leftRingBuf; reverb->loop.start = 0; reverb->loop.count = 1; reverb->loop.end = reverb->windowSize; 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); - for (j = 0; j < gAudioContext.gAudioBufferParameters.updatesPerFrame; j++) { - mem = func_800DE258(&gAudioContext.gNotesAndBuffersPool, 0x340); + reverb->unk_30 = Audio_AllocZeroed(&gAudioContext.notesAndBuffersPool, 0x20); + reverb->unk_34 = Audio_AllocZeroed(&gAudioContext.notesAndBuffersPool, 0x20); + reverb->unk_38 = Audio_AllocZeroed(&gAudioContext.notesAndBuffersPool, 0x20); + reverb->unk_3C = Audio_AllocZeroed(&gAudioContext.notesAndBuffersPool, 0x20); + for (j = 0; j < gAudioContext.audioBufferParameters.updatesPerFrame; j++) { + mem = func_800DE258(&gAudioContext.notesAndBuffersPool, 0x340); reverb->items[0][j].toDownsampleLeft = mem; reverb->items[0][j].toDownsampleRight = mem + 0x1A0 / sizeof(s16); - mem = func_800DE258(&gAudioContext.gNotesAndBuffersPool, 0x340); + mem = func_800DE258(&gAudioContext.notesAndBuffersPool, 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)); + reverb->unk_278 = Audio_AllocDmaMemoryZeroed(&gAudioContext.notesAndBuffersPool, 0x40); + reverb->unk_270 = Audio_AllocDmaMemory(&gAudioContext.notesAndBuffersPool, 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)); + reverb->unk_27C = Audio_AllocDmaMemoryZeroed(&gAudioContext.notesAndBuffersPool, 0x40); + reverb->unk_274 = Audio_AllocDmaMemory(&gAudioContext.notesAndBuffersPool, 8 * sizeof(s16)); func_800DF5DC(reverb->unk_274, settings->unk_16); } else { reverb->unk_274 = NULL; @@ -959,17 +960,17 @@ void func_800DFBF8(void) { } Audio_InitSequencePlayers(); - for (j = 0; j < gAudioContext.gAudioBufferParameters.numSequencePlayers; j++) { + for (j = 0; j < gAudioContext.audioBufferParameters.numSequencePlayers; j++) { func_800EC734(j); - Audio_ResetSequencePlayer(&gAudioContext.gSequencePlayers[j]); + Audio_ResetSequencePlayer(&gAudioContext.seqPlayers[j]); } func_800E0634(preset->unk_30, preset->unk_34); - func_800E1618(gAudioContext.gMaxSimultaneousNotes); + func_800E1618(gAudioContext.maxSimultaneousNotes); gAudioContext.unk_176C = 0; - func_800E3400(); + Audio_SyncLoadsInit(); func_800E4FB0(); - func_800E3A14(); + Audio_AsyncLoadReqInit(); gAudioContext.unk_4 = 0x1000; func_800E4D94(); intMask = osSetIntMask(1); @@ -1027,13 +1028,13 @@ void* func_800E05C4(u32 size, s32 arg1, void* arg2, s8 arg3, s32 arg4) { void func_800E0634(u32 arg0, u32 arg1) { void* mem; - mem = func_800DE2B0(&gAudioContext.gNotesAndBuffersPool, arg0); + mem = func_800DE2B0(&gAudioContext.notesAndBuffersPool, 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); + mem = func_800DE2B0(&gAudioContext.notesAndBuffersPool, arg1); if (mem == NULL) { gAudioContext.unk_3174.pool.size = 0; } else { @@ -1073,10 +1074,10 @@ UnkHeapEntry* func_800E06CC(u32 size) { index = -1; for (i = 0; i < gAudioContext.unk_176C; i++) { - thing = &gAudioContext.unk_0D68[i]; + thing = &gAudioContext.unk_0D54[i + 1]; if (thing->unk_10 == 0) { start = thing->unk_08; - end = thing->unk_08 + thing->sample->bits24 - 1; + end = thing->unk_08 + thing->sample->size - 1; if (end < allocBefore && start < allocBefore) { continue; @@ -1131,7 +1132,7 @@ void func_800E0964(UnkHeapEntry* entry, s32 bankId) { s32 drumId; s32 sfxId; - for (instId = 0; instId < gAudioContext.gCtlEntries[bankId].numInstruments; instId++) { + for (instId = 0; instId < gAudioContext.ctlEntries[bankId].numInstruments; instId++) { inst = Audio_GetInstrumentInner(bankId, instId); if (inst != NULL) { if (inst->normalRangeLo != 0) { @@ -1144,14 +1145,14 @@ void func_800E0964(UnkHeapEntry* entry, s32 bankId) { } } - for (drumId = 0; drumId < gAudioContext.gCtlEntries[bankId].numDrums; drumId++) { + for (drumId = 0; drumId < gAudioContext.ctlEntries[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++) { + for (sfxId = 0; sfxId < gAudioContext.ctlEntries[bankId].numSfx; sfxId++) { sfx = Audio_GetSfx(bankId, sfxId); if (sfx != NULL) { func_800E0BB4(entry, sfx->sample); @@ -1165,10 +1166,10 @@ void func_800E0AD8(UnkHeapEntry* entry) { s32 unk3; s32 bankId; - numBanks = *gAudioContext.unk_2834; + numBanks = gAudioContext.audioBankTable->header.entryCnt; for (bankId = 0; bankId < numBanks; bankId++) { - unk2 = gAudioContext.gCtlEntries[bankId].unk_02; - unk3 = gAudioContext.gCtlEntries[bankId].unk_03; + unk2 = gAudioContext.ctlEntries[bankId].unk_02; + unk3 = gAudioContext.ctlEntries[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) { @@ -1220,10 +1221,10 @@ void func_800E0CBC(void) { s32 bankId; s32 j; - numBanks = *gAudioContext.unk_2834; + numBanks = gAudioContext.audioBankTable->header.entryCnt; for (bankId = 0; bankId < numBanks; bankId++) { - unk2 = gAudioContext.gCtlEntries[bankId].unk_02; - unk3 = gAudioContext.gCtlEntries[bankId].unk_03; + unk2 = gAudioContext.ctlEntries[bankId].unk_02; + unk3 = gAudioContext.ctlEntries[bankId].unk_03; if ((unk2 == 0xFF) && (unk3 == 0xFF)) { continue; } @@ -1268,8 +1269,8 @@ void func_800E0E90(s32 id) { } void func_800E0EB4(s32 arg0, s32 id) { - ManyStruct_800E0E0C_2* manyThing; - Struct_800E0E0C_2* thing; + AudioTable* audioTable; + AudioTableEntry* thing; s32 numBanks; s32 instId; s32 drumId; @@ -1284,19 +1285,19 @@ void func_800E0EB4(s32 arg0, s32 id) { u8** fakematch; s32 pad[4]; - manyThing = gAudioContext.unk_2838; - numBanks = *gAudioContext.unk_2834; + audioTable = gAudioContext.audioTable; + numBanks = gAudioContext.audioBankTable->header.entryCnt; sp78.unk_0 = func_800DF074(2, 2, id); if (sp78.unk_0 == NULL) { return; } - thing = &manyThing->unk_C[id]; - sp78.unk_8 = thing->unk_8; - sp78.unk_C = thing->unk_C; + thing = &audioTable->entries[id]; + sp78.unk_8 = thing->size; + sp78.unk_C = thing->unk_08; if ((sp78.unk_C == 2) || (sp78.unk_C == 3)) { - sp78.unk_4 = thing->unk_4; + sp78.unk_4 = thing->romAddr; } else { sp78.unk_4 = NULL; } @@ -1310,8 +1311,8 @@ void func_800E0EB4(s32 arg0, s32 id) { } for (bankId = 0; bankId < numBanks; bankId++) { - unk2 = gAudioContext.gCtlEntries[bankId].unk_02; - unk3 = gAudioContext.gCtlEntries[bankId].unk_03; + unk2 = gAudioContext.ctlEntries[bankId].unk_02; + unk3 = gAudioContext.ctlEntries[bankId].unk_03; if ((unk2 != 0xFF) || (unk3 != 0xFF)) { if (!Audio_IsBankLoadComplete(bankId) || func_800DF074(1, 2, bankId) == NULL) { continue; @@ -1323,7 +1324,7 @@ void func_800E0EB4(s32 arg0, s32 id) { continue; } - for (instId = 0; instId < gAudioContext.gCtlEntries[bankId].numInstruments; instId++) { + for (instId = 0; instId < gAudioContext.ctlEntries[bankId].numInstruments; instId++) { inst = Audio_GetInstrumentInner(bankId, instId); if (inst != NULL) { if (inst->normalRangeLo != 0) { @@ -1336,14 +1337,14 @@ void func_800E0EB4(s32 arg0, s32 id) { } } - for (drumId = 0; drumId < gAudioContext.gCtlEntries[bankId].numDrums; drumId++) { + for (drumId = 0; drumId < gAudioContext.ctlEntries[bankId].numDrums; drumId++) { drum = Audio_GetDrum(bankId, drumId); if (drum != NULL) { func_800E0E0C(&sp78, drum->sound.sample); } } - for (sfxId = 0; sfxId < gAudioContext.gCtlEntries[bankId].numSfx; sfxId++) { + for (sfxId = 0; sfxId < gAudioContext.ctlEntries[bankId].numSfx; sfxId++) { sfx = Audio_GetSfx(bankId, sfxId); if (sfx != NULL) { func_800E0E0C(&sp78, sfx->sample); @@ -1359,7 +1360,7 @@ void func_800E1148(void) { TemporaryPool* temporary; u32 i; - pool = &gAudioContext.gUnusedLoadedPool; + pool = &gAudioContext.unusedLoadedPool; temporary = &pool->temporary; if (temporary->entries[0].id != -1) { diff --git a/src/code/audio_load.c b/src/code/audio_load.c new file mode 100644 index 000000000..3d6da12c9 --- /dev/null +++ b/src/code/audio_load.c @@ -0,0 +1,1652 @@ +#include "ultra64.h" +#include "global.h" + +typedef enum { LOAD_STATUS_WAITING, LOAD_STATUS_START, LOAD_STATUS_LOADING, LOAD_STATUS_DONE } SyncLoadStatus; + +#define RELOC(v, base) (reloc = (void*)((u32)v + (u32)base)) + +/* forward declarations */ +s32 func_800E217C(s32 playerIdx, s32, s32); +unk_ldr* func_800E2454(u32 arg0); +AudioBankSample* Audio_GetBankSample(s32 bankId, s32 sfxId); +void Audio_ProcessAsyncLoads(s32 arg0); +void Audio_HandleAsyncMsg(AsyncLoadReq* arg0, s32 arg1); +void Audio_UpdateAsyncReq(AsyncLoadReq* arg0, s32 arg1); +void func_800E4198(s32, unk_ldr*, RelocInfo*, s32); +void Audio_SampleReloc(AudioBankSound* sound, u32, RelocInfo*); +void func_800E202C(s32 arg0); +u32 func_800E2338(u32 arg0, u32* arg1, s32 arg2); +u8* func_800E2558(u32 tableType, u32 bankId, s32* didAllocate); +u32 Audio_GetTableIndex(s32 tableType, u32 tableIdx); +void* func_800E27A4(s32 tableType, s32 id); +void* Audio_GetLoadTable(s32 tableType); +void Audio_DMAFastCopy(u32 devAddr, u8* addr, u32 size, s32 handleType); +void func_800E2BCC(u32 devAddr, u8* addr, u32 size, s32 handleType); +s32 Audio_DMA(OSIoMesg* mesg, u32 priority, s32 direction, u32 devAddr, void* ramAddr, u32 size, OSMesgQueue* reqQueue, + s32 handleType, const char* dmaFuncType); +void* Audio_AsyncLoadInner(s32 tableType, s32 arg1, s32 arg2, s32 arg3, OSMesgQueue* retQueue); +AsyncLoadReq* func_800E3A44(s32 arg0, s32 devAddr, void* ramAddr, s32 size, s32 arg4, s32 nChunks, + OSMesgQueue* retQueue, s32 retMsg); +AsyncLoadReq* Audio_InitAsyncReq(s32 devAddr, void* ramAddr, s32 size, s32 arg3, s32 nChunks, OSMesgQueue* retQueue, + s32 retMsg); +void func_800E3FB4(AsyncLoadReq* req, u32 size); +void func_800E4044(u32 devAddr, void* ramAddr, u32 size, s16 arg3); +u8* func_800E22C4(s32 seqId); +s32 func_800E4590(s32 resetStatus); +void func_800E3874(AudioSyncLoad* arg0, s32 size); +void Audio_ProcessSyncLoads(s32 resetStatus); +void func_800E38F8(s32 arg0, s32 arg1, s32 arg2, s32 arg3); + +OSMesgQueue D_8016B6E0; +u8 D_8016B6F8[0x40]; +u8* D_8016B738[0x12]; +u32 D_8016B780[8]; + +void func_800E11F0(void) { + s32 i; + + for (i = 0; i < gAudioContext.unk_2624; i++) { + SampleDmaReq* req = &gAudioContext.sampleDmaReqs[i]; + if (req->unk_0E != 0) { + req->unk_0E--; + if ((req->unk_0E) == 0) { + req->unk_0D = gAudioContext.unk_282E; + gAudioContext.unk_262C[gAudioContext.unk_282E] = i; + gAudioContext.unk_282E++; + } + } + } + + for (i = gAudioContext.unk_2624; i < gAudioContext.sampleDmaReqCnt; i++) { + SampleDmaReq* req = &gAudioContext.sampleDmaReqs[i]; + if (req->unk_0E != 0) { + req->unk_0E--; + if (req->unk_0E == 0) { + req->unk_0D = gAudioContext.unk_282F; + gAudioContext.unk_272C[gAudioContext.unk_282F] = i; + gAudioContext.unk_282F++; + } + } + } + + gAudioContext.unk_2628 = 0; +} + +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/func_800E12DC.s") + +#ifdef NON_MATCHING +void func_800E1618(s32 arg0) { + SampleDmaReq* temp_s0; + s32 i; + s32 t2; + + gAudioContext.unk_288C = gAudioContext.unk_2874; + gAudioContext.sampleDmaReqs = + Audio_Alloc(&gAudioContext.notesAndBuffersPool, + (gAudioContext.maxSimultaneousNotes * 0x40) * gAudioContext.audioBufferParameters.presetUnk4); + t2 = gAudioContext.maxSimultaneousNotes * 3 * gAudioContext.audioBufferParameters.presetUnk4; + for (i = 0; i < t2; i++) { + SampleDmaReq* temp_s0 = &gAudioContext.sampleDmaReqs[gAudioContext.sampleDmaReqCnt]; + temp_s0->ramAddr = func_800DE2B0(&gAudioContext.notesAndBuffersPool, gAudioContext.unk_288C); + if (temp_s0->ramAddr == NULL) { + break; + } else { + func_800DE238(temp_s0->ramAddr, gAudioContext.unk_288C); + temp_s0->size = gAudioContext.unk_288C; + temp_s0->devAddr = 0; + temp_s0->unk_08 = 0; + temp_s0->unk_0C = 0; + temp_s0->unk_0E = 0; + gAudioContext.sampleDmaReqCnt++; + } + } + + for (i = 0; i < gAudioContext.sampleDmaReqCnt; i++) { + gAudioContext.unk_262C[i] = i; + gAudioContext.sampleDmaReqs[i].unk_0D = i; + } + + for (i = gAudioContext.sampleDmaReqCnt; i < 0x100; i++) { + gAudioContext.unk_262C[i] = 0; + } + + gAudioContext.unk_282C = 0; + gAudioContext.unk_282E = gAudioContext.sampleDmaReqCnt; + gAudioContext.unk_2624 = gAudioContext.sampleDmaReqCnt; + gAudioContext.unk_288C = gAudioContext.unk_2878; + + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + SampleDmaReq* temp_s0 = &gAudioContext.sampleDmaReqs[gAudioContext.sampleDmaReqCnt]; + temp_s0->ramAddr = func_800DE2B0(&gAudioContext.notesAndBuffersPool, gAudioContext.unk_288C); + if (temp_s0->ramAddr == NULL) { + break; + } else { + func_800DE238(temp_s0->ramAddr, gAudioContext.unk_288C); + temp_s0->size = gAudioContext.unk_288C; + temp_s0->devAddr = 0U; + temp_s0->unk_08 = 0; + temp_s0->unk_0C = 0; + temp_s0->unk_0E = 0; + gAudioContext.sampleDmaReqCnt++; + } + } + + for (i = gAudioContext.unk_2624; i < gAudioContext.sampleDmaReqCnt; i++) { + SampleDmaReq* temp_s0 = &gAudioContext.sampleDmaReqs[i + gAudioContext.unk_2624]; + gAudioContext.unk_272C[i - gAudioContext.unk_2624] = gAudioContext.unk_2624; + temp_s0->unk_0D = i - gAudioContext.unk_2624; + } + + for (i = gAudioContext.sampleDmaReqCnt; i < 0x100; i++) { + gAudioContext.unk_272C[i] = gAudioContext.unk_2624; + } + + gAudioContext.unk_282D = 0; + gAudioContext.unk_282F = gAudioContext.sampleDmaReqCnt - gAudioContext.unk_2624; +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/func_800E1618.s") +#endif + +s32 Audio_IsBankLoadComplete(s32 bankId) { + if (bankId == 0xFF) { + return true; + } else if (gAudioContext.bankLoadStatus[bankId] >= 2) { + return true; + } else if (gAudioContext.bankLoadStatus[Audio_GetTableIndex(BANK_TABLE, bankId)] >= 2) { + return true; + } else { + return false; + } +} + +s32 Audio_IsSeqLoadComplete(s32 seqId) { + if (seqId == 0xFF) { + return 1; + } else if (gAudioContext.seqLoadstatus[seqId] >= 2) { + return 1; + } else if (gAudioContext.seqLoadstatus[Audio_GetTableIndex(SEQUENCE_TABLE, seqId)] >= 2) { + return true; + } else { + return false; + } +} + +s32 Audio_IsAudTabLoadComplete(s32 tabId) { + if (tabId == 0xFF) { + return true; + } else if (gAudioContext.audioTableLoadStatus[tabId] >= 2) { + return true; + } else if (gAudioContext.audioTableLoadStatus[Audio_GetTableIndex(AUDIO_TABLE, tabId)] >= 2) { + return true; + } else { + return false; + } +} + +void Audio_SetBankLoadStatus(s32 bankId, s32 status) { + if ((bankId != 0xFF) && (gAudioContext.bankLoadStatus[bankId] != 5)) { + gAudioContext.bankLoadStatus[bankId] = status; + } +} + +void Audio_SetSeqLoadStatus(s32 seqId, s32 status) { + if ((seqId != 0xFF) && (gAudioContext.seqLoadstatus[seqId] != 5)) { + gAudioContext.seqLoadstatus[seqId] = status; + } +} + +void func_800E1A78(s32 arg0, s32 arg1) { + if (arg0 != 0xFF) { + if (gAudioContext.audioTableLoadStatus[arg0] != 5) { + gAudioContext.audioTableLoadStatus[arg0] = arg1; + } + + if ((gAudioContext.audioTableLoadStatus[arg0] == 5) || (gAudioContext.audioTableLoadStatus[arg0] == 2)) { + func_800E0E90(arg0); + } + } +} + +void Aduio_SetAudtabLoadstatus(s32 tabId, s32 status) { + if ((tabId != 0xFF) && (gAudioContext.audioTableLoadStatus[tabId] != 5)) { + gAudioContext.audioTableLoadStatus[tabId] = status; + } +} + +void Audio_InitAudioTable(AudioTable* table, u32 romAddr, u16 arg2) { + s32 i; + + table->header.unk_02 = arg2; + table->header.romAddr = romAddr; + + for (i = 0; i < table->header.entryCnt; i++) { + if ((table->entries[i].size != 0) && (table->entries[i].unk_08 == 2)) { + table->entries[i].romAddr += romAddr; + } + } +} + +unk_ldr* func_800E1B68(s32 arg0, u32* arg1) { + char pad[0x8]; + s32 phi_s0; + unk_ldr* sp28; + s32 phi_s1; + s32 phi_s2; + s32 i; + + if (arg0 >= gAudioContext.seqTabEntCnt) { + return 0; + } + + phi_s2 = 0xFF; + phi_s0 = gAudioContext.unk_283C[arg0]; // ofset into unk_283C for cnt? + phi_s1 = *(phi_s0 + gAudioContext.unk_283Cb); + phi_s0++; + + while (phi_s1 > 0) { + phi_s2 = gAudioContext.unk_283Cb[phi_s0++]; + sp28 = func_800E2454(phi_s2); + phi_s1--; + } + + *arg1 = phi_s2; + return sp28; +} + +void func_800E1C18(s32 channelIdx, s32 arg1) { + s32 pad; + u32 sp18; + + if (channelIdx < gAudioContext.seqTabEntCnt) { + if (arg1 & 2) { + func_800E1B68(channelIdx, &sp18); + } + if (arg1 & 1) { + func_800E22C4(channelIdx); + } + } +} + +s32 func_800E1C78(AudioBankSample* sample, s32 arg1) { + void* sampleAddr; + + if (sample->unk_bits25 == 1) { + if (sample->bits2 != 0) { + sampleAddr = func_800E05C4(sample->size, arg1, (void*)sample->sampleAddr, sample->bits2, 1); + if (sampleAddr == NULL) { + return -1; + } + + if (sample->bits2 == 1) { + func_800E2BCC(sample->sampleAddr, sampleAddr, sample->size, gAudioContext.audioTable->header.unk_02); + } else { + Audio_DMAFastCopy(sample->sampleAddr, sampleAddr, sample->size, sample->bits2); + } + sample->bits2 = 0; + sample->sampleAddr = sampleAddr; + } + } +} + +s32 func_800E1D64(s32 arg0, s32 arg1, s32 arg2) { + if (arg1 < 0x7F) { + Instrument* instrument = Audio_GetInstrumentInner(arg0, arg1); + + if (instrument == NULL) { + return -1; + } + if (instrument->normalRangeLo != 0) { + func_800E1C78(instrument->lowNotesSound.sample, arg0); + } + func_800E1C78(instrument->normalNotesSound.sample, arg0); + if (instrument->normalRangeHi != 0x7F) { + func_800E1C78(instrument->highNotesSound.sample, arg0); + return; + } + } else if (arg1 == 0x7F) { + Drum* drum = Audio_GetDrum(arg0, arg2); + + if (drum == 0) { + return -1; + } + func_800E1C78(drum->sound.sample, arg0); + return 0; + } +} + +void Audio_AsyncLoad(s32 arg0, s32 arg1, s32 arg2, s32 arg3, OSMesgQueue* queue) { + if (Audio_AsyncLoadInner(arg0, arg1, arg2, arg3, queue) == NULL) { + osSendMesg(queue, -1, OS_MESG_NOBLOCK); + } +} + +void Audio_AudioSeqAsyncLoad(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue* queue) { + Audio_AsyncLoad(SEQUENCE_TABLE, arg0, 0, arg2, queue); +} + +void Audio_AudioTableAsyncLoad(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue* queue) { + Audio_AsyncLoad(AUDIO_TABLE, arg0, 0, arg2, queue); +} + +void Audio_AudioBankAsyncLoad(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue* queue) { + Audio_AsyncLoad(BANK_TABLE, arg0, 0, arg2, queue); +} + +u8* func_800E1F38(s32 arg0, u32* arg1) { + s32 temp_v1; + + temp_v1 = gAudioContext.unk_283C[arg0]; + + *arg1 = *(temp_v1 + gAudioContext.unk_283Cb); + temp_v1++; + if (*arg1 == 0) { + return NULL; + } + return &gAudioContext.unk_283Cb[temp_v1]; +} + +void func_800E1F7C(s32 arg0) { + s32 temp_s0; + s32 phi_s1; + s32 phi_s2; + + phi_s1 = gAudioContext.unk_283C[arg0]; + phi_s2 = *(phi_s1 + gAudioContext.unk_283Cb); + phi_s1++; + + while (phi_s2 > 0) { + phi_s2--; + temp_s0 = Audio_GetTableIndex(1, gAudioContext.unk_283Cb[phi_s1++]); + if (func_800E04E8(1, temp_s0) == NULL) { + func_800E202C(temp_s0); + Audio_SetBankLoadStatus(temp_s0, 0); + } + } +} + +void func_800E202C(s32 arg0) { + s32 i; + SoundMultiPool* pool = &gAudioContext.bankLoadedPool; + PersistentPool* persistent; + + if (arg0 == pool->temporary.entries[0].id) { + pool->temporary.entries[0].id = -1; + } else if (arg0 == pool->temporary.entries[1].id) { + pool->temporary.entries[1].id = -1; + } + + persistent = &pool->persistent; + for (i = 0; i < persistent->numEntries; i++) { + if (arg0 == persistent->entries[i].id) { + persistent->entries[i].id = -1; + } + } + + Audio_DiscardBank(arg0); +} + +s32 func_800E20D4(s32 playerIdx, s32 seqId, s32 arg2) { + if (gAudioContext.resetTimer != 0) { + return 0; + } else { + gAudioContext.seqPlayers[playerIdx].unk_DC = 0; + return func_800E217C(playerIdx, seqId, arg2); + } +} + +s32 func_800E2124(s32 playerIdx, s32 seqId, s32 arg2) { + if (gAudioContext.resetTimer != 0) { + return 0; + } + + gAudioContext.seqPlayers[playerIdx].unk_DC = arg2; + return func_800E217C(playerIdx, seqId, 0); +} + +// InitSeqPlayer +s32 func_800E217C(s32 playerIdx, s32 seqId, s32 arg2) { + SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + u8* seqData; + s32 phi_s0; + s32 phi_s1; + s32 phi_s2; + + if (seqId >= gAudioContext.seqTabEntCnt) { + return 0; + } + + Audio_SequencePlayerDisable(seqPlayer); + + phi_s2 = 0xFF; + phi_s0 = gAudioContext.unk_283C[seqId]; + phi_s1 = gAudioContext.unk_283Cb[phi_s0++]; + + while (phi_s1 > 0) { + phi_s2 = gAudioContext.unk_283Cb[phi_s0++]; + func_800E2454(phi_s2); + phi_s1--; + } + + seqData = func_800E22C4(seqId); + if (seqData == NULL) { + return 0; + } + + Audio_ResetSequencePlayer(seqPlayer); + seqPlayer->seqId = seqId; + seqPlayer->defaultBank = Audio_GetTableIndex(1, phi_s2); + seqPlayer->seqData = seqData; + seqPlayer->enabled = 1; + seqPlayer->scriptState.pc = seqData; + seqPlayer->scriptState.depth = 0; + seqPlayer->delay = 0; + seqPlayer->finished = 0; + seqPlayer->seqVariationEu = playerIdx; + Audio_ProcessSequence(seqPlayer); +} + +// LoadSequence +u8* func_800E22C4(s32 seqId) { + s32 pad; + s32 sp20; + + if (gAudioContext.seqLoadstatus[Audio_GetTableIndex(0, seqId)] == 1) { + return NULL; + } + + return func_800E2558(0, seqId, &sp20); +} + +u32 func_800E2318(u32 arg0, u32* arg1) { + return func_800E2338(arg0, arg1, 1); +} + +u32 func_800E2338(u32 arg0, u32* arg1, s32 arg2) { + void* temp_v0; + AudioTable* audioTable; + u32 temp_s0; + s8 tmp; + + temp_s0 = Audio_GetTableIndex(2, arg0); + audioTable = Audio_GetLoadTable(2); + if (temp_v0 = func_800E27A4(2, temp_s0), temp_v0 != NULL) { + if (gAudioContext.audioTableLoadStatus[temp_s0] != 1) { + Aduio_SetAudtabLoadstatus(temp_s0, 2); + } + *arg1 = 0; + return temp_v0; + } else if (tmp = audioTable->entries[arg0].unk_09, tmp == 4 || arg2 == 1) { + *arg1 = audioTable->entries[arg0].unk_08; + return audioTable->entries[temp_s0].romAddr; + } else if (temp_v0 = func_800E2558(2, arg0, &arg2), temp_v0 != NULL) { + *arg1 = 0; + return temp_v0; + } else { + *arg1 = audioTable->entries[arg0].unk_08; + return audioTable->entries[temp_s0].romAddr; + } +} + +unk_ldr* func_800E2454(u32 arg0) { + u8* temp_ret; + s32 unk02; + s32 unk03; + s32 sp38; + RelocInfo relocInfo; + s32 idx; + + idx = Audio_GetTableIndex(BANK_TABLE, arg0); + if (gAudioContext.bankLoadStatus[idx] == 1) { + return NULL; + } + unk02 = gAudioContext.ctlEntries[idx].unk_02; + unk03 = gAudioContext.ctlEntries[idx].unk_03; + + relocInfo.unk_00 = unk02; + relocInfo.unk_04 = unk03; + if (relocInfo.unk_00 != 0xFF) { + relocInfo.unk_08 = func_800E2338(relocInfo.unk_00, &relocInfo.unk_10, 0); + } else { + relocInfo.unk_08 = 0; + } + + if (unk03 != 0xFF) { + relocInfo.unk_0C = func_800E2338(unk03, &relocInfo.unk_14, 0); + } else { + relocInfo.unk_0C = 0; + } + + temp_ret = func_800E2558(1, arg0, &sp38); + if (temp_ret == 0) { + return NULL; + } + if (sp38 == 1) { + func_800E4198(idx, temp_ret, &relocInfo, 0); + } + + return temp_ret; +} + +u8* func_800E2558(u32 tableType, u32 bankId, s32* didAllocate) { + u32 size; + AudioTable* table; + s32 pad; + u32 sp40; + s32 status; + u32 romAddr; + s32 sp24; + u8* ret; + u32 id; + + id = Audio_GetTableIndex(tableType, bankId); + ret = func_800E27A4(tableType, id); + if (ret != NULL) { + *didAllocate = false; + status = 2; + } else { + table = Audio_GetLoadTable(tableType); + size = table->entries[id].size; + size = ALIGN16(size); + sp40 = table->entries[bankId].unk_08; + sp24 = table->entries[bankId].unk_09; + romAddr = table->entries[id].romAddr; + switch (sp24) { + case 0: + ret = func_800E0540(tableType, id, size); + if (ret == NULL) { + return ret; + } + break; + case 1: + ret = Audio_AllocBankOrSeq(tableType, size, 1, id); + if (ret == NULL) { + return ret; + } + break; + case 2: + ret = Audio_AllocBankOrSeq(tableType, size, 0, id); + if (ret == NULL) { + return ret; + } + break; + case 3: + case 4: + ret = Audio_AllocBankOrSeq(tableType, size, 2, id); + if (ret == NULL) { + return ret; + } + break; + } + + *didAllocate = true; + if (sp40 == 1) { + func_800E2BCC(romAddr, ret, size, (s16)table->header.unk_02); + } else { + Audio_DMAFastCopy(romAddr, ret, size, sp40); + } + + status = sp24 == 0 ? 5 : 2; + } + + switch (tableType) { + case SEQUENCE_TABLE: + Audio_SetSeqLoadStatus(id, status); + break; + case BANK_TABLE: + Audio_SetBankLoadStatus(id, status); + break; + case AUDIO_TABLE: + func_800E1A78(id, status); + break; + default: + break; + } + + return ret; +} + +u32 Audio_GetTableIndex(s32 tableType, u32 tableIdx) { + AudioTable* table = Audio_GetLoadTable(tableType); + + if (table->entries[tableIdx].size == 0) { + tableIdx = table->entries[tableIdx].romAddr; + } + + return tableIdx; +} + +void* func_800E27A4(s32 tableType, s32 id) { + void* ret; + + ret = func_800E04E8(tableType, id); + if (ret != NULL) { + return ret; + } + + ret = func_800DF074(tableType, 2, id); + if (ret != NULL) { + return ret; + } + + return NULL; +} + +void* Audio_GetLoadTable(s32 tableType) { + void* ret; + + switch (tableType) { + case SEQUENCE_TABLE: + ret = gAudioContext.sequenceTable; + break; + case BANK_TABLE: + ret = gAudioContext.audioBankTable; + break; + default: + ret = NULL; + break; + case AUDIO_TABLE: + ret = gAudioContext.audioTable; + break; + } + return ret; +} + +#define BASE_OFFSET(x, off) (void*)((u32)(x) + (u32)(off)) + +#ifdef NON_MATCHING +void func_800E283C(s32 arg0, unk_ldr* arg1, RelocInfo* arg2) { + s32 sp50; + s32 temp_v1_3; + s32 temp_s5; + s32 temp_a3; + void* reloc; + s32 i; + Drum* drum; + AudioBankSound* sfx; + Instrument* inst; + Instrument** end; + Instrument** instIt; + Drum** drums; + + temp_a3 = gAudioContext.ctlEntries[arg0].numDrums; + sp50 = gAudioContext.ctlEntries[arg0].numInstruments; + temp_s5 = gAudioContext.ctlEntries[arg0].numSfx; + + drums = arg1->drums; + if ((drums != NULL) && (temp_a3 != 0)) { + if (1) { + arg1->drums = RELOC(drums, arg1); + } + for (i = 0; i < temp_a3; i++) { + reloc = arg1->drums[i]; + if (reloc != NULL) { + arg1->drums[i] = drum = RELOC(reloc, arg1); + if (!drum->loaded) { + Audio_SampleReloc(&drum->sound, arg1, arg2); + reloc = drum->envelope; + drum->envelope = BASE_OFFSET(reloc, arg1); + drum->loaded = 1; + } + } + } + } + + if ((arg1->sfx != NULL) && (temp_s5 != 0)) { + if (1) { + arg1->sfx = RELOC(arg1->sfx, arg1); + } + for (i = 0; i < temp_s5; i++) { + sfx = &arg1->sfx[i]; + if ((sfx != NULL) && (sfx->sample != NULL)) { + Audio_SampleReloc(sfx, arg1, arg2); + } + } + } + + if (sp50 >= 0x7F) { + sp50 = 0x7E; + } + + temp_v1_3 = sp50 + 1; + if (temp_v1_3 > 1) { + instIt = arg1->instruments; + end = instIt + temp_v1_3 - 2; + do { + if (*instIt != NULL) { + inst = *instIt; + *instIt = RELOC(inst, arg1); + if (0) {} + inst = *instIt; + if (!inst->loaded) { + if (inst->normalRangeLo != 0) { + Audio_SampleReloc(&inst->lowNotesSound, arg1, arg2); + } + Audio_SampleReloc(&inst->normalNotesSound, arg1, arg2); + if (inst->normalRangeHi != 0x7F) { + Audio_SampleReloc(&inst->highNotesSound, arg1, arg2); + } + + inst->loaded = 1; + inst->envelope = RELOC(inst->envelope, arg1); + } + } + instIt++; + } while (instIt <= end); + } + + gAudioContext.ctlEntries[arg0].drums = arg1->drums; + gAudioContext.ctlEntries[arg0].soundEffects = arg1->sfx; + gAudioContext.ctlEntries[arg0].instruments = arg1->instruments; +} +#else +void func_800E283C(s32 arg0, unk_ldr* arg1, RelocInfo* arg2); +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/func_800E283C.s") +#endif + +void Audio_DMAFastCopy(u32 devAddr, u8* addr, u32 size, s32 handleType) { + OSMesgQueue* msgQueue = &gAudioContext.unk_25E8; + OSIoMesg* ioMesg = &gAudioContext.unk_2604; + size = ALIGN16(size); + + Audio_osInvalDCache(addr, size); + + while (true) { + if (size < 0x400) { + break; + } + Audio_DMA(ioMesg, OS_MESG_PRI_HIGH, OS_READ, devAddr, addr, 0x400, msgQueue, handleType, "FastCopy"); + osRecvMesg(msgQueue, NULL, OS_MESG_BLOCK); + size -= 0x400; + devAddr += 0x400; + addr += 0x400; + } + + if (size != 0) { + Audio_DMA(ioMesg, OS_MESG_PRI_HIGH, OS_READ, devAddr, addr, size, msgQueue, handleType, "FastCopy"); + osRecvMesg(msgQueue, NULL, OS_MESG_BLOCK); + } +} + +void func_800E2BCC(u32 devAddr, u8* addr, u32 size, s32 handleType) { +} + +s32 (*sDmaHandler)(OSPiHandle* handle, OSIoMesg* mb, s32 direction) = osEPiStartDma; + +s32 Audio_DMA(OSIoMesg* mesg, u32 priority, s32 direction, u32 devAddr, void* ramAddr, u32 size, OSMesgQueue* reqQueue, + s32 handleType, const char* dmaFuncType) { + OSPiHandle* handle; + + if (gAudioContext.resetTimer > 0x10) { + return -1; + } + + switch (handleType) { + case 2: + handle = gAudioContext.cartHandle; + break; + case 3: + handle = gAudioContext.unk_1E1C; + break; + default: + return 0; + } + + if ((size % 0x10) != 0) { + size = ALIGN16(size); + } + + mesg->hdr.pri = priority; + mesg->hdr.retQueue = reqQueue; + mesg->dramAddr = ramAddr; + mesg->devAddr = devAddr; + mesg->size = size; + handle->transferInfo.cmdType = 2; + sDmaHandler(handle, mesg, direction); + return 0; +} + +void func_800E2CB8(void) { +} + +void func_800E2CC0(u32 arg0, u32 arg1) { + s32 sp1C; + + func_800E2558(arg0, arg1, &sp1C); +} + +void* Audio_AsyncLoadInner(s32 tableType, s32 arg1, s32 arg2, s32 arg3, OSMesgQueue* retQueue) { + u32 sp54; + AudioTable* sp50; + void* sp4C; + s32 sp48; + s8 temp_a1; + u32 sp40; + s32 sp3C; + u32 temp_v0; + u32 sp34; + + sp34 = Audio_GetTableIndex(tableType, arg1); + switch (tableType) { + case SEQUENCE_TABLE: + if (gAudioContext.seqLoadstatus[sp34] == 1) { + return NULL; + } + break; + case BANK_TABLE: + if (gAudioContext.bankLoadStatus[sp34] == 1) { + return NULL; + } + break; + case AUDIO_TABLE: + if (gAudioContext.audioTableLoadStatus[sp34] == 1) { + return NULL; + } + break; + } + + sp4C = func_800E27A4(tableType, sp34); + if (sp4C != NULL) { + sp3C = 2; + osSendMesg(retQueue, arg3 << 0x18, 0); + } else { + sp50 = Audio_GetLoadTable(tableType); + sp54 = sp50->entries[sp34].size; + sp54 = ALIGN16(sp54); + sp48 = sp50->entries[arg1].unk_08; + temp_a1 = sp50->entries[arg1].unk_09; + sp40 = sp50->entries[sp34].romAddr; + sp3C = 2; + switch (temp_a1) { + case 0: + sp4C = func_800E0540(tableType, sp34, sp54); + if (sp4C == NULL) { + return sp4C; + } + sp3C = 5; + break; + case 1: + sp4C = Audio_AllocBankOrSeq(tableType, sp54, 1, sp34); + if (sp4C == NULL) { + return sp4C; + } + break; + case 2: + sp4C = Audio_AllocBankOrSeq(tableType, sp54, 0, sp34); + if (sp4C == NULL) { + return sp4C; + } + break; + case 3: + case 4: + sp4C = Audio_AllocBankOrSeq(tableType, sp54, 2, sp34); + if (sp4C == NULL) { + return sp4C; + } + break; + } + + if (sp48 == 1) { + func_800E3A44((s16)sp50->header.unk_02, sp40, sp4C, sp54, sp48, arg2, retQueue, + (arg3 << 0x18) | (tableType << 0x10) | (arg1 << 8) | sp3C); + } else { + Audio_InitAsyncReq(sp40, sp4C, sp54, sp48, arg2, retQueue, MK_ASYNC_MSG(arg3, tableType, sp34, sp3C)); + } + sp3C = 1; + } + + switch (tableType) { + case 0: + Audio_SetSeqLoadStatus(sp34, sp3C); + break; + case 1: + Audio_SetBankLoadStatus(sp34, sp3C); + break; + case 2: + func_800E1A78(sp34, sp3C); + break; + default: + break; + } + + return sp4C; +} + +void Audio_ProcessLoads(s32 resetStatus) { + Audio_ProcessSyncLoads(resetStatus); + func_800E4590(resetStatus); + Audio_ProcessAsyncLoads(resetStatus); +} + +// SetDmaCallback +void func_800E301C(void* callback) { + sDmaHandler = callback; +} + +u32 D_801304D4 = 0; +void func_800E3028(u32 arg0) { + D_801304D4 = arg0; +} + +// InitCtlTable +void func_800E3034(s32 arg0) { + CtlEntry* ctlEnt = &gAudioContext.ctlEntries[arg0]; + AudioBankTableEntry* tableEnt = &gAudioContext.audioBankTable->entries[arg0]; + + ctlEnt->unk_02 = (tableEnt->unk_0A >> 8) & 0xFF; + ctlEnt->unk_03 = (tableEnt->unk_0A) & 0xFF; + ctlEnt->numInstruments = (tableEnt->unk_0C >> 8) & 0xFF; + ctlEnt->numDrums = tableEnt->unk_0C & 0xFF; + ctlEnt->numSfx = tableEnt->unk_0E; +} + +s32 gAudioContextInitalized = 0; + +void Audio_ContextInit(void* heap, u32 heapSize) { + char pad[0x48]; + s32 sp24; + void* temp_v0_3; + s32 i; + u64* heapP; + u8* ctxP; + s16* u2974p; + + D_801755D0 = NULL; + gAudioContext.resetTimer = 0; + + { + s32 i; + u8* ctxP = &gAudioContext; + for (i = sizeof(gAudioContext); i >= 0; i--) { + *ctxP++ = 0; + } + } + + switch (osTvType) { + case OS_TV_PAL: + gAudioContext.unk_2960 = 20.03042f; + gAudioContext.refreshRate = 50; + break; + case OS_TV_MPAL: + gAudioContext.unk_2960 = 16.546f; + gAudioContext.refreshRate = 60; + break; + case OS_TV_NTSC: + default: + gAudioContext.unk_2960 = 16.713f; + gAudioContext.refreshRate = 60; + } + + Audio_InitMesgQueues(); + + for (i = 0; i < 3; i++) { + gAudioContext.aiBufLengths[i] = 0xA0; + } + + gAudioContext.totalTaskCnt = 0; + gAudioContext.rspTaskIdx = 0; + gAudioContext.curAIBufIdx = 0; + gAudioContext.soundMode = 0; + gAudioContext.currTask = NULL; + gAudioContext.rspTask[0].task.t.data_size = 0; + gAudioContext.rspTask[1].task.t.data_size = 0; + osCreateMesgQueue(&gAudioContext.unk_25E8, &gAudioContext.unk_2600, 1); + osCreateMesgQueue(&gAudioContext.unk_1ED0, &gAudioContext.unk_1EE8, 0x40); + osCreateMesgQueue(&gAudioContext.unk_1E20, &gAudioContext.unk_1E38, 0x10); + osCreateMesgQueue(&gAudioContext.unk_1E78, &gAudioContext.unk_1E90, 0x10); + gAudioContext.sampleIoReqIdx = 0; + gAudioContext.sampleDmaReqCnt = 0; + gAudioContext.cartHandle = osCartRomInit(); + + if (heap == NULL) { + gAudioContext.audioHeap = gAudioHeap; + gAudioContext.audioHeapSize = D_8014A6C4.heap; + } else { + void** hp = &heap; + gAudioContext.audioHeap = *hp; + gAudioContext.audioHeapSize = heapSize; + } + + for (i = 0; i < (s32)gAudioContext.audioHeapSize / 8; i++) { + ((u64*)gAudioContext.audioHeap)[i] = 0; + } + + Audio_InitMainPools(D_8014A6C4.mainPool); + + for (i = 0; i < 3; i++) { + gAudioContext.aiBuffers[i] = Audio_AllocZeroed(&gAudioContext.audioInitPool, AIBUF_LEN); + } + + gAudioContext.sequenceTable = &gSequenceTable; + gAudioContext.audioBankTable = &gAudioBankTable; + gAudioContext.audioTable = &gAudioTable; + gAudioContext.unk_283C = &D_80155340; + gAudioContext.seqTabEntCnt = gAudioContext.sequenceTable->header.entryCnt; + + gAudioContext.audioResetPresetIdToLoad = 0; + gAudioContext.resetStatus = 1; + + Audio_ResetStep(); + Audio_InitAudioTable(gAudioContext.sequenceTable, _AudioseqSegmentRomStart, 0); + Audio_InitAudioTable(gAudioContext.audioBankTable, _AudiobankSegmentRomStart, 0); + Audio_InitAudioTable(gAudioContext.audioTable, _AudiotableSegmentRomStart, 0); + sp24 = gAudioContext.audioBankTable->header.entryCnt; + gAudioContext.ctlEntries = Audio_Alloc(&gAudioContext.audioInitPool, sp24 * sizeof(CtlEntry)); + + for (i = 0; i < sp24; i++) { + func_800E3034(i); + } + + if (temp_v0_3 = Audio_Alloc(&gAudioContext.audioInitPool, D_8014A6C4.initPool), temp_v0_3 == NULL) { + + *((u32*)&D_8014A6C4.initPool) = 0; + } + + Audio_SoundAllocPoolInit(&gAudioContext.unk_2D50, temp_v0_3, D_8014A6C4.initPool); + gAudioContextInitalized = 1; + osSendMesg(gAudioContext.taskStartQueueP, (void*)gAudioContext.totalTaskCnt, 0); +} + +void Audio_SyncLoadsInit(void) { + gAudioContext.syncLoads[0].status = 0; + gAudioContext.syncLoads[1].status = 0; +} + +s32 Audio_SyncLoadSample(s32 arg0, s32 arg1, u8* isDone) { + AudioBankSample* sample; + AudioSyncLoad* syncLoad; + + sample = Audio_GetBankSample(arg0, arg1); + if (sample == NULL) { + *isDone = 0; + return -1; + } + + if (sample->bits2 == 0) { + *isDone = 2; + return 0; + } + + syncLoad = &gAudioContext.syncLoads[gAudioContext.syncLoadPos]; + if (syncLoad->status == LOAD_STATUS_DONE) { + syncLoad->status = LOAD_STATUS_WAITING; + } + + syncLoad->sample = *sample; + syncLoad->isDone = isDone; + syncLoad->ramAddr = func_800E05C4(sample->size, arg0, sample->sampleAddr, sample->bits2, 0); + + if (syncLoad->ramAddr == NULL) { + if (sample->bits2 == 1 || sample->bits4 == 2) { + *isDone = 0; + return -1; + } else { + *isDone = 3; + return -1; + } + } + + syncLoad->status = LOAD_STATUS_START; + syncLoad->size = ALIGN16(sample->size); + syncLoad->unk_10 = syncLoad->ramAddr; + syncLoad->devAddr = sample->sampleAddr; + syncLoad->unk_00 = sample->bits2; + syncLoad->unk_01 = arg0; + syncLoad->unk_02 = arg1; + if (syncLoad->unk_00 == 1) { + syncLoad->unk_04 = gAudioContext.audioTable->header.unk_02; + } + + gAudioContext.syncLoadPos ^= 1; + return 0; +} + +AudioBankSample* Audio_GetBankSample(s32 bankId, s32 sfxId) { + AudioBankSample* ret; + + if (sfxId < 0x80) { + Instrument* instrument = Audio_GetInstrumentInner(bankId, sfxId); + if (instrument == NULL) { + return NULL; + } + ret = instrument->normalNotesSound.sample; + } else if (sfxId < 0x100) { + Drum* drum = Audio_GetDrum(bankId, sfxId - 0x80); + if (drum == NULL) { + return NULL; + } + ret = drum->sound.sample; + } else { + AudioBankSound* bankSound = Audio_GetSfx(bankId, sfxId - 0x100); + if (bankSound == NULL) { + return NULL; + } + ret = bankSound->sample; + } + return ret; +} + +void func_800E3670(void) { +} + +void func_800E3678(AudioSyncLoad* syncLoad) { + AudioBankSample* sample; + + if (syncLoad->sample.sampleAddr == NULL) { + return; + } + + sample = Audio_GetBankSample(syncLoad->unk_01, syncLoad->unk_02); + if (sample == NULL) { + return; + } + + syncLoad->sample = *sample; + sample->sampleAddr = syncLoad->unk_10; + sample->bits2 = 0; +} + +void Audio_ProcessSyncLoads(s32 resetStatus) { + AudioSyncLoad* syncLoad; + s32 i; + + for (i = 0; i < ARRAY_COUNT(gAudioContext.syncLoads); i++) { + syncLoad = &gAudioContext.syncLoads[i]; + switch (gAudioContext.syncLoads[i].status) { + case LOAD_STATUS_LOADING: + if (syncLoad->unk_00 != 1) { + osRecvMesg(&syncLoad->msgqueue, NULL, OS_MESG_BLOCK); + } + + if (resetStatus != 0) { + syncLoad->status = LOAD_STATUS_DONE; + continue; + } + case LOAD_STATUS_START: + syncLoad->status = LOAD_STATUS_LOADING; + if (syncLoad->size == 0) { + func_800E3678(syncLoad); + syncLoad->status = LOAD_STATUS_DONE; + *syncLoad->isDone = 1; + } else if (syncLoad->size < 0x400) { + if (syncLoad->unk_00 == 1) { + u32 size = syncLoad->size; + func_800E38F8(syncLoad->devAddr, syncLoad->ramAddr, size, syncLoad->unk_04); + } else { + func_800E3874(syncLoad, syncLoad->size); + } + syncLoad->size = 0; + } else { + if (syncLoad->unk_00 == 1) { + func_800E38F8(syncLoad->devAddr, syncLoad->ramAddr, 0x400, syncLoad->unk_04); + } else { + func_800E3874(syncLoad, 0x400); + } + syncLoad->size -= 0x400; + syncLoad->ramAddr += 0x400; + syncLoad->devAddr += 0x400; + } + break; + } + } +} + +void func_800E3874(AudioSyncLoad* arg0, s32 size) { + Audio_osInvalDCache(arg0->ramAddr, size); + osCreateMesgQueue(&arg0->msgqueue, &arg0->msg, 1); + Audio_DMA(&arg0->ioMesg, 0U, 0, arg0->devAddr, arg0->ramAddr, size, &arg0->msgqueue, arg0->unk_00, "SLOWCOPY"); +} + +void func_800E38F8(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { +} + +s32 Audio_SyncLoadSeq(s32 seqIdx, u8* ramAddr, u8* isDone) { + AudioSyncLoad* syncLoad; + SequenceTable* seqTable; + u32 size; + + if (seqIdx >= gAudioContext.seqTabEntCnt) { + *isDone = 0; + return -1; + } + + seqIdx = Audio_GetTableIndex(0, seqIdx); + seqTable = Audio_GetLoadTable(0); + syncLoad = &gAudioContext.syncLoads[gAudioContext.syncLoadPos]; + if (syncLoad->status == LOAD_STATUS_DONE) { + syncLoad->status = LOAD_STATUS_WAITING; + } + + syncLoad->sample.sampleAddr = NULL; + syncLoad->isDone = isDone; + size = seqTable->entries[seqIdx].size; + size = ALIGN16(size); + syncLoad->ramAddr = ramAddr; + syncLoad->status = LOAD_STATUS_START; + syncLoad->size = size; + syncLoad->unk_10 = ramAddr; + syncLoad->devAddr = seqTable->entries[seqIdx].romAddr; + syncLoad->unk_00 = seqTable->entries[seqIdx].unk_08; + syncLoad->unk_01 = seqIdx; + + if (syncLoad->unk_00 == 1) { + syncLoad->unk_04 = seqTable->header.unk_02; + } + + gAudioContext.syncLoadPos ^= 1; + return 0; +} + +void Audio_AsyncLoadReqInit(void) { + s32 i; + + for (i = 0; i < ARRAY_COUNT(gAudioContext.asyncReqs); i++) { + gAudioContext.asyncReqs[i].status = 0; + } +} + +AsyncLoadReq* func_800E3A44(s32 arg0, s32 devAddr, void* ramAddr, s32 size, s32 arg4, s32 nChunks, + OSMesgQueue* retQueue, s32 retMsg) { + AsyncLoadReq* loadReq; + + loadReq = Audio_InitAsyncReq(devAddr, ramAddr, size, arg4, nChunks, retQueue, retMsg); + + if (loadReq == NULL) { + return NULL; + } + + osSendMesg(&gAudioContext.asyncLoadQueue, loadReq, 0); + loadReq->unk_18 = arg0; + return loadReq; +} + +AsyncLoadReq* Audio_InitAsyncReq(s32 devAddr, void* ramAddr, s32 size, s32 arg3, s32 nChunks, OSMesgQueue* retQueue, + s32 retMsg) { + AsyncLoadReq* loadReq; + s32 i; + + for (i = 0; i < ARRAY_COUNT(gAudioContext.asyncReqs); i++) { + if (gAudioContext.asyncReqs[i].status == 0) { + loadReq = &gAudioContext.asyncReqs[i]; + break; + } + } + + // no more available async reqs + if (i == ARRAY_COUNT(gAudioContext.asyncReqs)) { + return NULL; + } + + loadReq->status = LOAD_STATUS_START; + loadReq->devAddr = devAddr; + loadReq->unk_04 = ramAddr; + loadReq->ramAddr = ramAddr; + loadReq->bytesRemaining = size; + + if (nChunks == 0) { + loadReq->chunkSize = 0x1000; + } else if (nChunks == 1) { + loadReq->chunkSize = size; + } else { + loadReq->chunkSize = ((size / nChunks) + 0xFF) & ~0xFF; + if (loadReq->chunkSize < 0x100) { + loadReq->chunkSize = 0x100; + } + } + + loadReq->retQueue = retQueue; + loadReq->unk_01 = 3; + loadReq->unk_02 = arg3; + loadReq->retMsg = retMsg; + osCreateMesgQueue(&loadReq->msgQueue, loadReq->msg, ARRAY_COUNT(loadReq->msg)); + return loadReq; +} + +void Audio_ProcessAsyncLoads(s32 resetStatus) { + AsyncLoadReq* loadReq; + s32 i; + + if (gAudioContext.resetTimer == 1) { + return; + } + + if (gAudioContext.curAsyncReq == NULL) { + if (resetStatus != 0) { + do { + } while (osRecvMesg(&gAudioContext.asyncLoadQueue, &loadReq, OS_MESG_NOBLOCK) != -1); + } else if (osRecvMesg(&gAudioContext.asyncLoadQueue, &loadReq, OS_MESG_NOBLOCK) == -1) { + gAudioContext.curAsyncReq = NULL; + } else { + gAudioContext.curAsyncReq = loadReq; + } + } + + if (gAudioContext.curAsyncReq != NULL) { + Audio_HandleAsyncMsg(gAudioContext.curAsyncReq, resetStatus); + } + + for (i = 0; i < ARRAY_COUNT(gAudioContext.asyncReqs); i++) { + if (gAudioContext.asyncReqs[i].status == 1) { + loadReq = &gAudioContext.asyncReqs[i]; + if (loadReq->unk_02 != 1) { + Audio_UpdateAsyncReq(loadReq, resetStatus); + } + } + } +} + +void Audio_HandleAsyncMsg(AsyncLoadReq* arg0, s32 arg1) { +} + +void Audio_AsyncReqDone(AsyncLoadReq* loadReq) { + u32 retMsg = loadReq->retMsg; + u32 b2; + u32 pad; + u32 t1; + OSMesg doneMsg; + u32 t2; + RelocInfo sp30; + + if (1) {} + switch (ASYNC_TBLTYPE(retMsg)) { + case SEQUENCE_TABLE: + Audio_SetSeqLoadStatus(ASYNC_B2(retMsg), ASYNC_B3(retMsg)); + break; + case AUDIO_TABLE: + func_800E1A78(ASYNC_B2(retMsg), ASYNC_B3(retMsg)); + break; + case BANK_TABLE: + b2 = ASYNC_B2(retMsg); + t1 = gAudioContext.ctlEntries[b2].unk_02; + t2 = gAudioContext.ctlEntries[b2].unk_03; + sp30.unk_00 = t1; + sp30.unk_04 = t2; + sp30.unk_08 = t1 != 0xFF ? func_800E2318(t1, &sp30.unk_10) : 0; + sp30.unk_0C = t2 != 0xFF ? func_800E2318(t2, &sp30.unk_14) : 0; + Audio_SetBankLoadStatus(b2, ASYNC_B3(retMsg)); + func_800E4198(b2, loadReq->unk_04, &sp30, 1); + break; + } + + doneMsg = loadReq->retMsg; + if (1) {} + loadReq->status = LOAD_STATUS_WAITING; + osSendMesg(loadReq->retQueue, doneMsg, OS_MESG_NOBLOCK); +} + +void Audio_UpdateAsyncReq(AsyncLoadReq* req, s32 resetStatus) { + AudioTable* audioTable = gAudioContext.audioTable; + + if (req->unk_01 >= 2) { + req->unk_01--; + return; + } + + if (req->unk_01 == 1) { + req->unk_01 = 0; + } else if (resetStatus != 0) { + osRecvMesg(&req->msgQueue, NULL, OS_MESG_BLOCK); + req->status = LOAD_STATUS_WAITING; + return; + } else if (osRecvMesg(&req->msgQueue, NULL, OS_MESG_NOBLOCK) == -1) { + return; + } + + if (req->bytesRemaining == 0) { + Audio_AsyncReqDone(req); + return; + } + + if (req->bytesRemaining < req->chunkSize) { + if (req->unk_02 == 1) { + func_800E4044(req->devAddr, req->ramAddr, req->bytesRemaining, audioTable->header.unk_02); + } else { + func_800E3FB4(req, req->bytesRemaining); + } + req->bytesRemaining = 0; + return; + } + + if (req->unk_02 == 1) { + func_800E4044(req->devAddr, req->ramAddr, req->chunkSize, audioTable->header.unk_02); + } else { + func_800E3FB4(req, req->chunkSize); + } + + req->bytesRemaining -= req->chunkSize; + req->devAddr += req->chunkSize; + req->ramAddr = req->ramAddr + req->chunkSize; +} + +void func_800E3FB4(AsyncLoadReq* req, u32 size) { + size = ALIGN16(size); + Audio_osInvalDCache(req->ramAddr, size); + osCreateMesgQueue(&req->msgQueue, &req->msg, 1); + Audio_DMA(&req->ioMesg, 0, 0, req->devAddr, req->ramAddr, size, &req->msgQueue, req->unk_02, "BGCOPY"); +} + +void func_800E4044(u32 devAddr, void* ramAddr, u32 size, s16 arg3) { +} + +void Audio_SampleReloc(AudioBankSound* sound, u32 arg1, RelocInfo* arg2) { + AudioBankSample* sample; + void* reloc; + + if ((u32)sound->sample <= 0x80000000) { + sample = sound->sample = RELOC(sound->sample, arg1); + if (sample->size != 0 && sample->unk_bits25 != 1) { + sample->loop = RELOC(sample->loop, arg1); + sample->book = RELOC(sample->book, arg1); + switch (sample->bits2) { + case 0: + sample->sampleAddr = RELOC(sample->sampleAddr, arg2->unk_08); + sample->bits2 = arg2->unk_10; + break; + case 1: + sample->sampleAddr = RELOC(sample->sampleAddr, arg2->unk_0C); + sample->bits2 = arg2->unk_14; + break; + case 2: + case 3: + break; + } + + sample->unk_bits25 = 1; + if (sample->unk_bits26 && (sample->bits2 != 0)) { + gAudioContext.unk_B68[gAudioContext.unk_1768++] = sample; + } + } + } +} + +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/func_800E4198.s") + +#ifdef NON_MATCHING +s32 func_800E4590(s32 resetStatus) { + u32 sp4C; + AudioBankSample* temp_v0_3; + AudioStruct0D68* temp_v1_2; + s32 temp_a0_2; + s32 temp_v0_2; + u32 temp_a0; + u32 temp_a0_3; + u32 temp_a2_2; + u32 temp_t0; + u8* temp_s0; + AudioStruct0D68* temp_a2; + AudioBankSample* temp_v0; + AudioStruct0D68* temp_v1; + + if (gAudioContext.unk_176C > 0) { + if (resetStatus != 0) { + osRecvMesg(&gAudioContext.unk_1E78, &sp4C, 0); + gAudioContext.unk_176C = 0; + return 0; + } + if (osRecvMesg(&gAudioContext.unk_1E78, &sp4C, 0) == -1) { + return 0; + } + + sp4C >>= 0x18; + + if (gAudioContext.unk_0D54[sp4C + 1].unk_10 == 0) { + if ((temp_v0_3->sampleAddr + temp_v0_3->size + temp_v0_3->bits2) == + gAudioContext.unk_0D54[sp4C + 1].unk_00) { + temp_v0_3->bits2 = 0; + temp_v0_3->sampleAddr = temp_v0_3->loop; + } + gAudioContext.unk_0D54[sp4C + 1].unk_10 = 1; + } + + while (gAudioContext.unk_176C > 0) { + if (gAudioContext.unk_0D54[gAudioContext.unk_176C].unk_10 == 1) { + gAudioContext.unk_176C--; + continue; + } else { + temp_v0_3 = gAudioContext.unk_0D54[gAudioContext.unk_176C].sample; + if (&temp_v0_3->sampleAddr[temp_v0_3->size + temp_v0_3->bits2] != + gAudioContext.unk_0D54[gAudioContext.unk_176C].unk_00) { + gAudioContext.unk_0D54[gAudioContext.unk_176C].unk_10 = 1; + gAudioContext.unk_176C--; + continue; + } else { + Audio_InitAsyncReq(temp_v0_3->sampleAddr, gAudioContext.unk_0D54[gAudioContext.unk_176C].unk_08, + temp_v0_3->size, temp_v0_3->bits2, (temp_a2_2 >> 0xC) + 1, + &gAudioContext.unk_1E78, gAudioContext.unk_0D54[gAudioContext.unk_176C].pad); + break; + } + } + } + } + return 1; +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/func_800E4590.s") +#endif + +s32 func_800E4744(AudioBankSample* sample, s32 sampleCnt, AudioBankSample** sampleList) { + s32 i; + + for (i = 0; i < sampleCnt; i++) { + if (sample->sampleAddr == sampleList[i]->sampleAddr) { + break; + } + } + + if (i == sampleCnt) { + sampleList[sampleCnt] = sample; + sampleCnt++; + } + + return sampleCnt; +} + +s32 func_800E478C(s32 bankId, AudioBankSample** sampleList) { + s32 i; + s32 drumCnt; + s32 instrumentCnt; + s32 sampleCnt = 0; + + drumCnt = gAudioContext.ctlEntries[bankId].numDrums; + instrumentCnt = gAudioContext.ctlEntries[bankId].numInstruments; + + for (i = 0; i < drumCnt; i++) { + Drum* drum = Audio_GetDrum(bankId, i); + if (1) {} + if (drum != NULL) { + sampleCnt = func_800E4744(drum->sound.sample, sampleCnt, sampleList); + } + } + + for (i = 0; i < instrumentCnt; i++) { + Instrument* instrument = Audio_GetInstrumentInner(bankId, i); + if (instrument != NULL) { + if (instrument->normalRangeLo != 0) { + sampleCnt = func_800E4744(instrument->lowNotesSound.sample, sampleCnt, sampleList); + } + if (instrument->normalRangeHi != 0x7F) { + sampleCnt = func_800E4744(instrument->highNotesSound.sample, sampleCnt, sampleList); + } + sampleCnt = func_800E4744(instrument->normalNotesSound.sample, sampleCnt, sampleList); + } + } + return sampleCnt; +} + +void func_800E48C0(AudioBankSound* sound) { + AudioBankSample* sample = sound->sample; + + if ((sample->size != 0) && (sample->unk_bits26) && (sample->bits2)) { + gAudioContext.unk_B68[gAudioContext.unk_1768++] = sample; + } +} + +// large +void func_800E4918(s32, s32, RelocInfo*); +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_load/func_800E4918.s") + +void func_800E4D94(void) { + s32 pad; + u32 temp_s2; + AudioTable* audioTable; + s32 pad2; + s32 i; + + audioTable = Audio_GetLoadTable(AUDIO_TABLE); + for (i = 0; i < gAudioContext.unk_2D50.unused; i++) { + RelocInfo sp4C; + if (gAudioContext.unk_2D60[i].poolIndex == 1) { + temp_s2 = Audio_GetTableIndex(BANK_TABLE, gAudioContext.unk_2D60[i].id); + sp4C.unk_00 = gAudioContext.ctlEntries[temp_s2].unk_02; + sp4C.unk_04 = gAudioContext.ctlEntries[temp_s2].unk_03; + + if (sp4C.unk_00 != 0xFF) { + sp4C.unk_00 = Audio_GetTableIndex(AUDIO_TABLE, sp4C.unk_00); + sp4C.unk_10 = audioTable->entries[sp4C.unk_00].unk_08; + } + + if (sp4C.unk_04 != 0xFF) { + sp4C.unk_04 = Audio_GetTableIndex(AUDIO_TABLE, sp4C.unk_04); + sp4C.unk_14 = audioTable->entries[sp4C.unk_04].unk_08; + } + func_800E4918(temp_s2, 0, &sp4C); + } + } +} + +void func_800E4ED4(void) { +} + +void func_800E4EDC(void) { +} + +void func_800E4EE4(void) { +} + +void func_800E4EEC(s32 arg0, s32 arg1, u8* arg2) { + static u32 D_801304DC = 0; + D_8016B738[D_801304DC] = arg2; + Audio_AsyncLoad(arg0, arg1, 0, D_801304DC, &D_8016B6E0); + D_801304DC++; + if (D_801304DC == 0x10) { + D_801304DC = 0; + } +} + +void func_800E4F58(void) { + u32 pad; + u32 sp20; + u8* temp_v0; + + if (osRecvMesg(&D_8016B6E0, &sp20, OS_MESG_NOBLOCK) != -1) { + pad = sp20 >> 0x18; + temp_v0 = D_8016B738[pad]; + if (temp_v0 != NULL) { + *temp_v0 = 0; + } + } +} + +void func_800E4FB0(void) { + osCreateMesgQueue(&D_8016B6E0, &D_8016B6F8, 0x10); +} diff --git a/src/code/audio_playback.c b/src/code/audio_playback.c index 03cbd6099..a9ce8e9c2 100644 --- a/src/code/audio_playback.c +++ b/src/code/audio_playback.c @@ -30,7 +30,7 @@ void Audio_NoteSetVelPanReverb(Note* note, NoteSubEu* sub, Reverb* reverb) { sub->bitField0.s.stereoStrongLeft = false; sub->bitField0.s.stereoHeadsetEffects = sp24.stereoHeadsetEffects; sub->bitField0.s.usesHeadsetPanEffects = sp24.usesHeadsetPanEffects; - if (stereoHeadsetEffects && gAudioContext.gSoundMode == 1) { + if (stereoHeadsetEffects && gAudioContext.soundMode == 1) { smallPanIndex = pan >> 1; if (smallPanIndex > 0x3f) { smallPanIndex = 0x3f; @@ -42,7 +42,7 @@ void Audio_NoteSetVelPanReverb(Note* note, NoteSubEu* sub, Reverb* reverb) { volLeft = gHeadsetPanVolume[pan]; volRight = gHeadsetPanVolume[0x7f - pan]; - } else if (stereoHeadsetEffects && gAudioContext.gSoundMode == 0) { + } else if (stereoHeadsetEffects && gAudioContext.soundMode == 0) { strongLeft = strongRight = 0; sub->headsetPanRight = 0; sub->headsetPanLeft = 0; @@ -76,7 +76,7 @@ void Audio_NoteSetVelPanReverb(Note* note, NoteSubEu* sub, Reverb* reverb) { break; } - } else if (gAudioContext.gSoundMode == 3) { + } else if (gAudioContext.soundMode == 3) { sub->bitField0.s.stereoHeadsetEffects = false; sub->bitField0.s.usesHeadsetPanEffects = false; volLeft = 0.707f; @@ -164,9 +164,9 @@ void Audio_ProcessNotes(void) { f32 scale; s32 i; - for (i = 0; i < gAudioContext.gMaxSimultaneousNotes; i++) { - note = &gAudioContext.gNotes[i]; - noteSubEu2 = &gAudioContext.gNoteSubsEu[gAudioContext.gNoteSubEuOffset + i]; + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + note = &gAudioContext.notes[i]; + noteSubEu2 = &gAudioContext.noteSubsEu[gAudioContext.noteSubEuOffset + i]; playbackState = ¬e->playbackState; if (playbackState->parentLayer != NO_LAYER) { if ((u32)playbackState->parentLayer < 0x7FFFFFFFU) { @@ -175,7 +175,7 @@ void Audio_ProcessNotes(void) { if (note != playbackState->parentLayer->note && playbackState->unk_04 == 0) { playbackState->adsr.action.s.release = true; - playbackState->adsr.fadeOutVel = gAudioContext.gAudioBufferParameters.updatesPerFrameInv; + playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; playbackState->priority = 1; playbackState->unk_04 = 2; goto out; @@ -286,7 +286,7 @@ void Audio_ProcessNotes(void) { } reverb.frequency *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale; - reverb.frequency *= gAudioContext.gAudioBufferParameters.resampleRate; + reverb.frequency *= gAudioContext.audioBufferParameters.resampleRate; reverb.velocity *= scale; Audio_NoteSetVelPanReverb(note, noteSubEu2, &reverb); noteSubEu->bitField1.s.bookOffset = bookOffset; @@ -315,18 +315,18 @@ Instrument* Audio_GetInstrumentInner(s32 bankId, s32 instId) { } if (!Audio_IsBankLoadComplete(bankId)) { - gAudioContext.gAudioErrorFlags = bankId + 0x10000000; + gAudioContext.audioErrorFlags = bankId + 0x10000000; return NULL; } - if (instId >= gAudioContext.gCtlEntries[bankId].numInstruments) { - gAudioContext.gAudioErrorFlags = ((bankId << 8) + instId) + 0x3000000; + if (instId >= gAudioContext.ctlEntries[bankId].numInstruments) { + gAudioContext.audioErrorFlags = ((bankId << 8) + instId) + 0x3000000; return NULL; } - inst = gAudioContext.gCtlEntries[bankId].instruments[instId]; + inst = gAudioContext.ctlEntries[bankId].instruments[instId]; if (inst == NULL) { - gAudioContext.gAudioErrorFlags = ((bankId << 8) + instId) + 0x1000000; + gAudioContext.audioErrorFlags = ((bankId << 8) + instId) + 0x1000000; return inst; } @@ -341,21 +341,21 @@ Drum* Audio_GetDrum(s32 bankId, s32 drumId) { } if (!Audio_IsBankLoadComplete(bankId)) { - gAudioContext.gAudioErrorFlags = bankId + 0x10000000; + gAudioContext.audioErrorFlags = bankId + 0x10000000; return NULL; } - if (drumId >= gAudioContext.gCtlEntries[bankId].numDrums) { - gAudioContext.gAudioErrorFlags = ((bankId << 8) + drumId) + 0x4000000; + if (drumId >= gAudioContext.ctlEntries[bankId].numDrums) { + gAudioContext.audioErrorFlags = ((bankId << 8) + drumId) + 0x4000000; return NULL; } - if ((u32)gAudioContext.gCtlEntries[bankId].drums < 0x80000000U) { + if ((u32)gAudioContext.ctlEntries[bankId].drums < 0x80000000U) { return NULL; } - drum = gAudioContext.gCtlEntries[bankId].drums[drumId]; + drum = gAudioContext.ctlEntries[bankId].drums[drumId]; if (drum == NULL) { - gAudioContext.gAudioErrorFlags = ((bankId << 8) + drumId) + 0x5000000; + gAudioContext.audioErrorFlags = ((bankId << 8) + drumId) + 0x5000000; } return drum; @@ -369,23 +369,23 @@ AudioBankSound* Audio_GetSfx(s32 bankId, s32 sfxId) { } if (!Audio_IsBankLoadComplete(bankId)) { - gAudioContext.gAudioErrorFlags = bankId + 0x10000000; + gAudioContext.audioErrorFlags = bankId + 0x10000000; return NULL; } - if (sfxId >= gAudioContext.gCtlEntries[bankId].numSfx) { - gAudioContext.gAudioErrorFlags = ((bankId << 8) + sfxId) + 0x4000000; + if (sfxId >= gAudioContext.ctlEntries[bankId].numSfx) { + gAudioContext.audioErrorFlags = ((bankId << 8) + sfxId) + 0x4000000; return NULL; } - if ((u32)gAudioContext.gCtlEntries[bankId].soundEffects < 0x80000000U) { + if ((u32)gAudioContext.ctlEntries[bankId].soundEffects < 0x80000000U) { return NULL; } - sfx = &gAudioContext.gCtlEntries[bankId].soundEffects[sfxId]; + sfx = &gAudioContext.ctlEntries[bankId].soundEffects[sfxId]; if (sfx == NULL) { - gAudioContext.gAudioErrorFlags = ((bankId << 8) + sfxId) + 0x5000000; + gAudioContext.audioErrorFlags = ((bankId << 8) + sfxId) + 0x5000000; } if (sfx->sample == NULL) { @@ -406,24 +406,24 @@ s32 func_800E7744(s32 instrument, s32 bankId, s32 instId, void* arg3) { switch (instrument) { case 0: - if (instId >= gAudioContext.gCtlEntries[bankId].numDrums) { + if (instId >= gAudioContext.ctlEntries[bankId].numDrums) { return -3; } - gAudioContext.gCtlEntries[bankId].drums[instId] = arg3; + gAudioContext.ctlEntries[bankId].drums[instId] = arg3; break; case 1: - if (instId >= gAudioContext.gCtlEntries[bankId].numSfx) { + if (instId >= gAudioContext.ctlEntries[bankId].numSfx) { return -3; } - gAudioContext.gCtlEntries[bankId].soundEffects[instId] = *(AudioBankSound*)arg3; + gAudioContext.ctlEntries[bankId].soundEffects[instId] = *(AudioBankSound*)arg3; break; default: - if (instId >= gAudioContext.gCtlEntries[bankId].numInstruments) { + if (instId >= gAudioContext.ctlEntries[bankId].numInstruments) { return -3; } - gAudioContext.gCtlEntries[bankId].instruments[instId] = arg3; + gAudioContext.ctlEntries[bankId].instruments[instId] = arg3; break; } @@ -456,7 +456,7 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target) if (note->playbackState.parentLayer != seqLayer) { 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.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.action.s.release = true; } return; @@ -500,7 +500,7 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target) note->playbackState.prevParentLayer = note->playbackState.parentLayer; note->playbackState.parentLayer = NO_LAYER; if (target == ADSR_STATE_RELEASE) { - note->playbackState.adsr.fadeOutVel = gAudioContext.gAudioBufferParameters.updatesPerFrameInv; + note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.action.s.release = true; note->playbackState.unk_04 = 2; } else { @@ -602,11 +602,11 @@ void Audio_InitNoteLists(NotePool* pool) { void Audio_InitNoteFreeList(void) { s32 i; - Audio_InitNoteLists(&gNoteFreeLists); - for (i = 0; i < gAudioContext.gMaxSimultaneousNotes; i++) { - gAudioContext.gNotes[i].listItem.u.value = &gAudioContext.gNotes[i]; - gAudioContext.gNotes[i].listItem.prev = NULL; - Audio_AudioListPushBack(&gNoteFreeLists.disabled, &gAudioContext.gNotes[i].listItem); + Audio_InitNoteLists(&gAudioContext.noteFreeLists); + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + gAudioContext.notes[i].listItem.u.value = &gAudioContext.notes[i]; + gAudioContext.notes[i].listItem.prev = NULL; + Audio_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, &gAudioContext.notes[i].listItem); } } @@ -620,22 +620,22 @@ void Audio_NotePoolClear(NotePool* pool) { switch (i) { case 0: source = &pool->disabled; - dest = &gNoteFreeLists.disabled; + dest = &gAudioContext.noteFreeLists.disabled; break; case 1: source = &pool->decaying; - dest = &gNoteFreeLists.decaying; + dest = &gAudioContext.noteFreeLists.decaying; break; case 2: source = &pool->releasing; - dest = &gNoteFreeLists.releasing; + dest = &gAudioContext.noteFreeLists.releasing; break; case 3: source = &pool->active; - dest = &gNoteFreeLists.active; + dest = &gAudioContext.noteFreeLists.active; break; } @@ -666,22 +666,22 @@ void Audio_NotePoolFill(NotePool* pool, s32 count) { switch (i) { case 0: - source = &gNoteFreeLists.disabled; + source = &gAudioContext.noteFreeLists.disabled; dest = &pool->disabled; break; case 1: - source = &gNoteFreeLists.decaying; + source = &gAudioContext.noteFreeLists.decaying; dest = &pool->decaying; break; case 2: - source = &gNoteFreeLists.releasing; + source = &gAudioContext.noteFreeLists.releasing; dest = &pool->releasing; break; case 3: - source = &gNoteFreeLists.active; + source = &gAudioContext.noteFreeLists.active; dest = &pool->active; break; } @@ -790,7 +790,7 @@ void Audio_NoteReleaseAndTakeOwnership(Note* note, SequenceChannelLayer* seqLaye note->playbackState.wantedParentLayer = seqLayer; note->playbackState.priority = seqLayer->seqChannel->notePriority; - note->playbackState.adsr.fadeOutVel = gAudioContext.gAudioBufferParameters.updatesPerFrameInv; + note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.action.s.release = true; } @@ -884,9 +884,9 @@ Note* Audio_AllocNote(SequenceChannelLayer* seqLayer) { } if (policy & 8) { - if (!(ret = Audio_AllocNoteFromDisabled(&gNoteFreeLists, seqLayer)) && - !(ret = Audio_AllocNoteFromDecaying(&gNoteFreeLists, seqLayer)) && - !(ret = Audio_AllocNoteFromActive(&gNoteFreeLists, seqLayer))) { + if (!(ret = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, seqLayer)) && + !(ret = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, seqLayer)) && + !(ret = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, seqLayer))) { goto null_return; } return ret; @@ -894,13 +894,13 @@ Note* Audio_AllocNote(SequenceChannelLayer* seqLayer) { if (!(ret = Audio_AllocNoteFromDisabled(&seqLayer->seqChannel->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromDisabled(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) && - !(ret = Audio_AllocNoteFromDisabled(&gNoteFreeLists, seqLayer)) && + !(ret = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, seqLayer)) && !(ret = Audio_AllocNoteFromDecaying(&seqLayer->seqChannel->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromDecaying(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) && - !(ret = Audio_AllocNoteFromDecaying(&gNoteFreeLists, seqLayer)) && + !(ret = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, seqLayer)) && !(ret = Audio_AllocNoteFromActive(&seqLayer->seqChannel->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromActive(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) && - !(ret = Audio_AllocNoteFromActive(&gNoteFreeLists, seqLayer))) { + !(ret = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, seqLayer))) { goto null_return; } return ret; @@ -914,8 +914,8 @@ void Audio_NoteInitAll(void) { Note* note; s32 i; - for (i = 0; i < gAudioContext.gMaxSimultaneousNotes; i++) { - note = &gAudioContext.gNotes[i]; + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + note = &gAudioContext.notes[i]; note->noteSubEu = gZeroNoteSub; note->playbackState.priority = 0; note->playbackState.unk_04 = 0; @@ -931,6 +931,6 @@ void Audio_NoteInitAll(void) { note->portamento.speed = 0; note->playbackState.stereoHeadsetEffects = false; note->unk_BC = 0; - note->synthesisState.synthesisBuffers = Audio_AllocDmaMemory(&gAudioContext.gNotesAndBuffersPool, 0x1E0); + note->synthesisState.synthesisBuffers = Audio_AllocDmaMemory(&gAudioContext.notesAndBuffersPool, 0x1E0); } } diff --git a/src/code/audio_rodata.c b/src/code/audio_rodata.c new file mode 100644 index 000000000..469c5fc35 --- /dev/null +++ b/src/code/audio_rodata.c @@ -0,0 +1,7 @@ +#include "global.h" + +const s16 D_8014A6C0[] = { + 0x1C00, + 0x0030, +}; +const AudioContextInitSizes D_8014A6C4 = { 0x37F00, 0xE0E0, 0xBCE0 }; diff --git a/src/code/audio_seqplayer.c b/src/code/audio_seqplayer.c index 297d72546..5998ae702 100644 --- a/src/code/audio_seqplayer.c +++ b/src/code/audio_seqplayer.c @@ -107,7 +107,7 @@ s32 Audio_HandleScriptFlowControl(SequencePlayer* seqPlayer, M64ScriptState* sta void Audio_SequenceChannelInit(SequenceChannel* seqChannel) { s32 i; - if (seqChannel == &gAudioContext.gSequenceChannelNone) { + if (seqChannel == &gAudioContext.sequenceChannelNone) { return; } @@ -164,7 +164,7 @@ s32 Audio_SeqChannelSetLayer(SequenceChannel* seqChannel, s32 layerIdx) { if (seqChannel->layers[layerIdx] == NULL) { SequenceChannelLayer* layer; - layer = Audio_AudioListPopBack(&gAudioContext.gLayerFreeList); + layer = Audio_AudioListPopBack(&gAudioContext.layerFreeList); seqChannel->layers[layerIdx] = layer; if (layer == NULL) { seqChannel->layers[layerIdx] = NULL; @@ -206,7 +206,7 @@ s32 Audio_SeqChannelSetLayer(SequenceChannel* seqChannel, s32 layerIdx) { void Audio_SeqChannelLayerDisable(SequenceChannelLayer* layer) { if (layer != NULL) { - if (layer->seqChannel != &gAudioContext.gSequenceChannelNone && layer->seqChannel->seqPlayer->finished == 1) { + if (layer->seqChannel != &gAudioContext.sequenceChannelNone && layer->seqChannel->seqPlayer->finished == 1) { Audio_SeqChanLayerNoteRelease(layer); } else { Audio_SeqChanLayerNoteDecay(layer); @@ -220,7 +220,7 @@ void Audio_SeqChannelLayerFree(SequenceChannel* seqChannel, s32 layerIdx) { SequenceChannelLayer* layer = seqChannel->layers[layerIdx]; if (layer != NULL) { - Audio_AudioListPushBack(&gAudioContext.gLayerFreeList, &layer->listItem); + Audio_AudioListPushBack(&gAudioContext.layerFreeList, &layer->listItem); Audio_SeqChannelLayerDisable(layer); seqChannel->layers[layerIdx] = NULL; } @@ -303,10 +303,10 @@ void Audio_SequencePlayerDisable(SequencePlayer* seqPlayer) { Audio_SetBankLoadStatus(seqPlayer->defaultBank, 4); } - if (seqPlayer->defaultBank == gAudioContext.gBankLoadedPool.temporary.entries[0].id) { - gAudioContext.gBankLoadedPool.temporary.nextSide = 0; - } else if (seqPlayer->defaultBank == gAudioContext.gBankLoadedPool.temporary.entries[1].id) { - gAudioContext.gBankLoadedPool.temporary.nextSide = 1; + if (seqPlayer->defaultBank == gAudioContext.bankLoadedPool.temporary.entries[0].id) { + gAudioContext.bankLoadedPool.temporary.nextSide = 0; + } else if (seqPlayer->defaultBank == gAudioContext.bankLoadedPool.temporary.entries[1].id) { + gAudioContext.bankLoadedPool.temporary.nextSide = 1; } } @@ -338,15 +338,15 @@ void* Audio_AudioListPopBack(AudioListItem* list) { void Audio_InitLayerFreelist(void) { s32 i; - gAudioContext.gLayerFreeList.prev = &gAudioContext.gLayerFreeList; - gAudioContext.gLayerFreeList.next = &gAudioContext.gLayerFreeList; - gAudioContext.gLayerFreeList.u.count = 0; - gAudioContext.gLayerFreeList.pool = NULL; + gAudioContext.layerFreeList.prev = &gAudioContext.layerFreeList; + gAudioContext.layerFreeList.next = &gAudioContext.layerFreeList; + gAudioContext.layerFreeList.u.count = 0; + gAudioContext.layerFreeList.pool = NULL; - for (i = 0; i < ARRAY_COUNT(gAudioContext.gSequenceLayers); i++) { - gAudioContext.gSequenceLayers[i].listItem.u.value = &gAudioContext.gSequenceLayers[i]; - gAudioContext.gSequenceLayers[i].listItem.prev = NULL; - Audio_AudioListPushBack(&gAudioContext.gLayerFreeList, &gAudioContext.gSequenceLayers[i].listItem); + for (i = 0; i < ARRAY_COUNT(gAudioContext.sequenceLayers); i++) { + gAudioContext.sequenceLayers[i].listItem.u.value = &gAudioContext.sequenceLayers[i]; + gAudioContext.sequenceLayers[i].listItem.prev = NULL; + Audio_AudioListPushBack(&gAudioContext.layerFreeList, &gAudioContext.sequenceLayers[i].listItem); } } @@ -704,7 +704,7 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) { layer->sound = NULL; tuning = 1.0f; if (instOrWave >= 0xC0) { - layer->sound = &gAudioContext.gSynthesisReverbs[instOrWave - 0xC0].sound; + layer->sound = &gAudioContext.synthesisReverbs[instOrWave - 0xC0].sound; } } @@ -732,12 +732,12 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) { portamento->extent = (freqScale2 / freqScale) - 1.0f; if (PORTAMENTO_IS_SPECIAL(*portamento)) { - speed = seqPlayer->tempo * 0x8000 / gAudioContext.gTempoInternalToExternal; + speed = seqPlayer->tempo * 0x8000 / gAudioContext.tempoInternalToExternal; if (layer->delay != 0) { speed = speed * 0x100 / (layer->delay * layer->portamentoTime); } } else { - speed = 0x20000 / (layer->portamentoTime * gAudioContext.gAudioBufferParameters.updatesPerFrame); + speed = 0x20000 / (layer->portamentoTime * gAudioContext.audioBufferParameters.updatesPerFrame); } if (speed >= 0x7FFF) { @@ -764,7 +764,7 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) { layer->sound = NULL; layer->freqScale = gNoteFrequencies[cmd2]; if (instOrWave >= 0xC0) { - layer->sound = &gAudioContext.gSynthesisReverbs[instOrWave - 0xC0].sound; + layer->sound = &gAudioContext.synthesisReverbs[instOrWave - 0xC0].sound; } } break; @@ -791,7 +791,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.gTempoInternalToExternal; + speed2 = seqPlayer->tempo * 0x8000 / gAudioContext.tempoInternalToExternal; speed2 = speed2 * 0x100 / (layer->delay * layer->portamentoTime); if (speed2 >= 0x7FFF) { speed2 = 0x7FFF; @@ -870,8 +870,8 @@ s32 func_800EAAE0(SequenceChannelLayer* layer, s32 arg1) { if (seqChannel->velocityRandomVariance != 0) { floatDelta = - layer->velocitySquare * (f32)(gAudioContext.gAudioRandom % seqChannel->velocityRandomVariance) / 100.0f; - if ((gAudioContext.gAudioRandom & 0x8000) != 0) { + layer->velocitySquare * (f32)(gAudioContext.audioRandom % seqChannel->velocityRandomVariance) / 100.0f; + if ((gAudioContext.audioRandom & 0x8000) != 0) { floatDelta = -floatDelta; } layer->velocitySquare2 = layer->velocitySquare + floatDelta; @@ -888,8 +888,8 @@ s32 func_800EAAE0(SequenceChannelLayer* layer, s32 arg1) { layer->duration = (layer->noteDuration * playPercentage) >> 8; if (seqChannel->durationRandomVariance != 0) { //! @bug should probably be durationRandomVariance - intDelta = (layer->duration * (gAudioContext.gAudioRandom % seqChannel->velocityRandomVariance)) / 100; - if ((gAudioContext.gAudioRandom & 0x4000) != 0) { + intDelta = (layer->duration * (gAudioContext.audioRandom % seqChannel->velocityRandomVariance)) / 100; + if ((gAudioContext.audioRandom & 0x4000) != 0) { intDelta = -intDelta; } layer->duration += intDelta; @@ -1327,12 +1327,12 @@ void Audio_SequenceChannelProcessScript(SequenceChannel* channel) { scriptState->value = (*channel->dynTable)[0][scriptState->value]; break; case 0xB7: - channel->unk_22 = (parameters[0] == 0) ? gAudioContext.gAudioRandom // odd load here - : gAudioContext.gAudioRandom % parameters[0]; + channel->unk_22 = (parameters[0] == 0) ? gAudioContext.audioRandom // odd load here + : gAudioContext.audioRandom % parameters[0]; break; case 0xB8: - scriptState->value = (parameters[0] == 0) ? gAudioContext.gAudioRandom - : gAudioContext.gAudioRandom % parameters[0]; + scriptState->value = (parameters[0] == 0) ? gAudioContext.audioRandom + : gAudioContext.audioRandom % parameters[0]; break; case 0xBD: { result = Audio_NextRandom(); @@ -1498,11 +1498,11 @@ void Audio_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { seqPlayer->tempoAcc += seqPlayer->tempo; seqPlayer->tempoAcc += (s16)seqPlayer->unk_0C; - if (seqPlayer->tempoAcc < gAudioContext.gTempoInternalToExternal) { + if (seqPlayer->tempoAcc < gAudioContext.tempoInternalToExternal) { return; } - seqPlayer->tempoAcc -= (u16)gAudioContext.gTempoInternalToExternal; + seqPlayer->tempoAcc -= (u16)gAudioContext.tempoInternalToExternal; if (seqPlayer->unk_0b2 == true) { return; @@ -1558,8 +1558,8 @@ void Audio_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { break; case 0xDD: seqPlayer->tempo = Audio_M64ReadU8(seqScript) * 48; - if (seqPlayer->tempo > gAudioContext.gTempoInternalToExternal) { - seqPlayer->tempo = (u16)gAudioContext.gTempoInternalToExternal; + if (seqPlayer->tempo > gAudioContext.tempoInternalToExternal) { + seqPlayer->tempo = (u16)gAudioContext.tempoInternalToExternal; } if ((s16)seqPlayer->tempo <= 0) { seqPlayer->tempo = 1; @@ -1641,9 +1641,9 @@ void Audio_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { case 0xCE: command = Audio_M64ReadU8(seqScript); if (command == 0) { - seqScript->value = (gAudioContext.gAudioRandom >> 2) & 0xff; + seqScript->value = gAudioContext.audioRandom / 4; } else { - seqScript->value = (gAudioContext.gAudioRandom >> 2) % command; + seqScript->value = (gAudioContext.audioRandom / 4) % command; } break; case 0xCD: { @@ -1760,10 +1760,10 @@ void Audio_ProcessSequences(s32 arg0) { SequencePlayer* seqPlayer; u32 i; - gAudioContext.gNoteSubEuOffset = - (gAudioContext.gAudioBufferParameters.updatesPerFrame - arg0 - 1) * gAudioContext.gMaxSimultaneousNotes; - for (i = 0; i < (u32)gAudioContext.gAudioBufferParameters.numSequencePlayers; i++) { - seqPlayer = &gAudioContext.gSequencePlayers[i]; + gAudioContext.noteSubEuOffset = + (gAudioContext.audioBufferParameters.updatesPerFrame - arg0 - 1) * gAudioContext.maxSimultaneousNotes; + for (i = 0; i < (u32)gAudioContext.audioBufferParameters.numSequencePlayers; i++) { + seqPlayer = &gAudioContext.seqPlayers[i]; if (seqPlayer->enabled == 1) { Audio_SequencePlayerProcessSequence(seqPlayer); Audio_SequencePlayerProcessSound(seqPlayer); @@ -1809,13 +1809,13 @@ void Audio_ResetSequencePlayer(SequencePlayer* seqPlayer) { void func_800EC734(s32 seqPlayerIdx) { SequenceChannel* seqChannel; - SequencePlayer* seqPlayer = &gAudioContext.gSequencePlayers[seqPlayerIdx]; + SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[seqPlayerIdx]; s32 i, j; for (i = 0; i < 0x10; i++) { - seqPlayer->channels[i] = Audio_AllocZeroed(&gAudioContext.gNotesAndBuffersPool, sizeof(SequenceChannel)); + seqPlayer->channels[i] = Audio_AllocZeroed(&gAudioContext.notesAndBuffersPool, sizeof(SequenceChannel)); if (seqPlayer->channels[i] == NULL) { - seqPlayer->channels[i] = &gAudioContext.gSequenceChannelNone; + seqPlayer->channels[i] = &gAudioContext.sequenceChannelNone; } else { seqChannel = seqPlayer->channels[i]; seqChannel->seqPlayer = seqPlayer; @@ -1832,7 +1832,7 @@ void Audio_InitSequencePlayer(SequencePlayer* seqPlayer) { s32 i, j; for (i = 0; i < 0x10; i++) { - seqPlayer->channels[i] = &gAudioContext.gSequenceChannelNone; + seqPlayer->channels[i] = &gAudioContext.sequenceChannelNone; } seqPlayer->enabled = false; @@ -1856,11 +1856,11 @@ void Audio_InitSequencePlayers(void) { Audio_InitLayerFreelist(); for (i = 0; i < 64; i++) { - gAudioContext.gSequenceLayers[i].seqChannel = NULL; - gAudioContext.gSequenceLayers[i].enabled = false; + gAudioContext.sequenceLayers[i].seqChannel = NULL; + gAudioContext.sequenceLayers[i].enabled = false; } for (i = 0; i < 4; i++) { - Audio_InitSequencePlayer(&gAudioContext.gSequencePlayers[i]); + Audio_InitSequencePlayer(&gAudioContext.seqPlayers[i]); } } diff --git a/src/code/audio_synthesis.c b/src/code/audio_synthesis.c new file mode 100644 index 000000000..1c86f4212 --- /dev/null +++ b/src/code/audio_synthesis.c @@ -0,0 +1,1199 @@ +#include "ultra64.h" +#include "global.h" + +Acmd* AudioSynth_LoadRingBuffer(Acmd* arg0, u16 arg1, u16 arg2, s32 arg3, SynthesisReverb* arg4); +Acmd* AudioSynth_SaveBuffer(Acmd* arg0, u16 arg1, u16 arg2, s32 arg3, s16* arg4); +Acmd* AudioSynth_SaveRingBuffer(Acmd* arg0, u16 arg1, u16 arg2, s32 arg3, SynthesisReverb* arg4); +Acmd* func_800DC384(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updateIdx); +Acmd* func_800DC910(s32 noteIdx, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s16* aiBuf, s32 aiBufLen, + Acmd* cmd, s32 updateIdx); +Acmd* func_800DD9F4(Acmd* arg0, NoteSubEu* arg1, NoteSynthesisState* arg2, s32 arg3); +Acmd* func_800DDB64(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s32 arg3, s32 arg4, s32 arg5); +Acmd* func_800DD6CC(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s32 aiBufLen, u16, s32, s32); +Acmd* func_800DD62C(Acmd* cmd, NoteSynthesisState* synthState, s32 count, u16 pitch, u16 inpDmem, s32 resampleFlags); +extern s16 D_8012FBAA[]; +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_synthesis/pad_800DACB0.s") + +void AudioSynth_InitNextRingBuf(s32 chunkSize, s32 bufIdx, s32 reverbIdx) { + ReverbRingBufferItem* bufItem; + s32 pad[3]; + SynthesisReverb* reverb = &gAudioContext.synthesisReverbs[reverbIdx]; + s32 temp_a0_2; + s32 temp_a0_4; + s32 sampleCnt; + s32 extraSamples; + s32 i; + s32 j; + + if (reverb->downsampleRate >= 2) { + if (reverb->framesToIgnore == 0) { + bufItem = &reverb->items[reverb->curFrame][bufIdx]; + // inval dcache + Audio_osInvalDCache(bufItem->toDownsampleLeft, 0x340); + + for (j = 0, i = 0; i < bufItem->lengthA / 2; j += reverb->downsampleRate, i++) { + reverb->leftRingBuf[bufItem->startPos + i] = bufItem->toDownsampleLeft[j]; + reverb->rightRingBuf[bufItem->startPos + i] = bufItem->toDownsampleRight[j]; + } + + for (i = 0; i < bufItem->lengthB / 2; j += reverb->downsampleRate, i++) { + reverb->leftRingBuf[i] = bufItem->toDownsampleLeft[j]; + reverb->rightRingBuf[i] = bufItem->toDownsampleRight[j]; + } + } + } + + bufItem = &reverb->items[reverb->curFrame][bufIdx]; + sampleCnt = chunkSize / reverb->downsampleRate; + extraSamples = (sampleCnt + reverb->nextRingBufPos) - reverb->bufSizePerChan; + temp_a0_2 = reverb->nextRingBufPos; + if (extraSamples < 0) { + bufItem->lengthA = sampleCnt * 2; + bufItem->lengthB = 0; + bufItem->startPos = reverb->nextRingBufPos; + reverb->nextRingBufPos += sampleCnt; + } else { + bufItem->lengthA = (sampleCnt - extraSamples) * 2; + bufItem->lengthB = extraSamples * 2; + bufItem->startPos = reverb->nextRingBufPos; + reverb->nextRingBufPos = extraSamples; + } + + bufItem->numSamplesAfterDownsampling = sampleCnt; + bufItem->chunkLen = chunkSize; + + if (reverb->unk_14 != 0) { + temp_a0_4 = reverb->unk_14 + temp_a0_2; + if (temp_a0_4 >= reverb->bufSizePerChan) { + temp_a0_4 -= reverb->bufSizePerChan; + } + bufItem = &reverb->items2[reverb->curFrame][bufIdx]; + sampleCnt = chunkSize / reverb->downsampleRate; + extraSamples = (temp_a0_4 + sampleCnt) - reverb->bufSizePerChan; + if (extraSamples < 0) { + bufItem->lengthA = sampleCnt * 2; + bufItem->lengthB = 0; + bufItem->startPos = temp_a0_4; + } else { + bufItem->lengthA = (sampleCnt - extraSamples) * 2; + bufItem->lengthB = extraSamples * 2; + bufItem->startPos = temp_a0_4; + } + bufItem->numSamplesAfterDownsampling = sampleCnt; + bufItem->chunkLen = chunkSize; + } +} + +void func_800DB03C(s32 arg0) { + NoteSubEu* temp_v0_2; + NoteSubEu* subEu; + s32 t; + s32 i; + + t = gAudioContext.maxSimultaneousNotes * arg0; + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + subEu = &gAudioContext.notes[i].noteSubEu; + temp_v0_2 = &gAudioContext.noteSubsEu[t + i]; + if (subEu->bitField0.s.enabled) { + subEu->bitField0.s.needsInit = 0; + } else { + temp_v0_2->bitField0.s.enabled = 0; + } + + subEu->unk_06 = 0; + } +} + +Acmd* AudioSynth_Update(Acmd* cmdStart, s32* cmdCnt, s16* aiStart, s32 aiBufLen) { + s32 chunkSize; + s16* aiBufP; + Acmd* cmdP; + s32 i; + s32 j; + SynthesisReverb* reverb; + + cmdP = cmdStart; + for (i = gAudioContext.audioBufferParameters.updatesPerFrame; i > 0; i--) { + Audio_ProcessSequences(i - 1); + func_800DB03C(gAudioContext.audioBufferParameters.updatesPerFrame - i); + } + + aiBufP = aiStart; + gAudioContext.unk_0x10 = 0; + for (i = gAudioContext.audioBufferParameters.updatesPerFrame; i > 0; i--) { + if (i == 1) { + chunkSize = aiBufLen; + } else if ((aiBufLen / i) >= gAudioContext.audioBufferParameters.samplesPerUpdateMax) { + chunkSize = gAudioContext.audioBufferParameters.samplesPerUpdateMax; + } else if (gAudioContext.audioBufferParameters.samplesPerUpdateMin >= (aiBufLen / i)) { + chunkSize = gAudioContext.audioBufferParameters.samplesPerUpdateMin; + } else { + chunkSize = gAudioContext.audioBufferParameters.samplesPerUpdate; + } + + for (j = 0; j < gAudioContext.numSynthesisReverbs; j++) { + if (gAudioContext.synthesisReverbs[j].useReverb) { + AudioSynth_InitNextRingBuf(chunkSize, gAudioContext.audioBufferParameters.updatesPerFrame - i, j); + } + } + + cmdP = func_800DC384(aiBufP, chunkSize, cmdP, gAudioContext.audioBufferParameters.updatesPerFrame - i); + aiBufLen -= chunkSize; + aiBufP += chunkSize * 2; + } + + for (j = 0; j < gAudioContext.numSynthesisReverbs; j++) { + if (gAudioContext.synthesisReverbs[j].framesToIgnore != 0) { + gAudioContext.synthesisReverbs[j].framesToIgnore--; + } + gAudioContext.synthesisReverbs[j].curFrame ^= 1; + } + + *cmdCnt = cmdP - cmdStart; + return cmdP; +} + +void func_800DB2C0(s32 arg0, s32 arg1) { + NoteSubEu* temp_v1; + s32 i; + + for (i = arg0 + 1; i < gAudioContext.audioBufferParameters.updatesPerFrame; i++) { + temp_v1 = &gAudioContext.noteSubsEu[(gAudioContext.maxSimultaneousNotes * i) + arg1]; + if (!temp_v1->bitField0.s.needsInit) { + temp_v1->bitField0.s.enabled = 0; + } else { + break; + } + } +} + +Acmd* func_800DB330(Acmd* arg0, SynthesisReverb* reverb, s16 arg2) { + ReverbRingBufferItem* bufItem = &reverb->items[reverb->curFrame][arg2]; + + arg0 = AudioSynth_LoadRingBuffer(arg0, 0x3E0, bufItem->startPos, bufItem->lengthA, reverb); + if (bufItem->lengthB != 0) { + arg0 = AudioSynth_LoadRingBuffer(arg0, bufItem->lengthA + 0x3E0, 0, bufItem->lengthB, reverb); + } + return arg0; +} + +Acmd* func_800DB3D8(Acmd* arg0, SynthesisReverb* arg1, s16 arg2) { + ReverbRingBufferItem* temp_v1; + + temp_v1 = &arg1->items[arg1->curFrame][arg2]; + arg0 = AudioSynth_SaveRingBuffer(arg0, 0x3E0, temp_v1->startPos, temp_v1->lengthA, arg1); + if (temp_v1->lengthB != 0) { + arg0 = AudioSynth_SaveRingBuffer(arg0, temp_v1->lengthA + 0x3E0, 0, temp_v1->lengthB, arg1); + } + return arg0; +} + +Acmd* func_800DB480(Acmd* arg0, SynthesisReverb* arg1) { + void* temp_a2; + void* temp_a3; + + aDMEMMove(arg0++, 0xC80, 0x720, 0x1A0); + aMix(arg0++, 0x1A, arg1->unk_10, 0xE20, 0xC80); + aMix(arg0++, 0x1A, arg1->unk_12, 0x720, 0xE20); + return arg0; +} + +Acmd* func_800DB4E4(Acmd* arg0, s32 arg1, SynthesisReverb* arg2, s16 arg3) { + ReverbRingBufferItem* temp_v1; + s16 temp_t0_2; + s16 temp_t1_2; + + temp_v1 = &arg2->items[arg2->curFrame][arg3]; + temp_t0_2 = (temp_v1->startPos & 7) * 2; + temp_t1_2 = ALIGN16(temp_t0_2 + temp_v1->lengthA); + arg0 = AudioSynth_LoadRingBuffer(arg0, 0x3E0, temp_v1->startPos - (temp_t0_2 / 2), 0x1A0, arg2); + if (temp_v1->lengthB != 0) { + arg0 = AudioSynth_LoadRingBuffer(arg0, temp_t1_2 + 0x3E0, 0, 0x1A0 - temp_t1_2, arg2); + } + aSetBuffer(arg0++, 0, temp_t0_2 + 0x3E0, 0xC80, arg1 * 2); + aResample(arg0++, arg2->resampleFlags, arg2->unk_0E, arg2->unk_30); + aSetBuffer(arg0++, 0, temp_t0_2 + 0x580, 0xE20, arg1 * 2); + aResample(arg0++, arg2->resampleFlags, arg2->unk_0E, arg2->unk_34); + return arg0; +} + +Acmd* func_800DB680(Acmd* cmd, SynthesisReverb* reverb, s16 bufIdx) { + ReverbRingBufferItem* bufItem = &reverb->items[reverb->curFrame][bufIdx]; + + aSetBuffer(cmd++, 0, 0xC80, 0x720, bufItem->unk_18 * 2); + aResample(cmd++, reverb->resampleFlags, bufItem->unk_16, reverb->unk_38); + + cmd = AudioSynth_SaveBuffer(cmd, 0x720, bufItem->startPos, bufItem->lengthA, reverb->leftRingBuf); + if (bufItem->lengthB != 0) { + cmd = AudioSynth_SaveBuffer(cmd, bufItem->lengthA + 0x720, 0, bufItem->lengthB, reverb->leftRingBuf); + } + aSetBuffer(cmd++, 0, 0xE20, 0x720, bufItem->unk_18 * 2); + aResample(cmd++, reverb->resampleFlags, bufItem->unk_16, reverb->unk_3C); + cmd = AudioSynth_SaveBuffer(cmd, 0x720, bufItem->startPos, bufItem->lengthA, reverb->rightRingBuf); + + if (bufItem->lengthB != 0) { + cmd = AudioSynth_SaveBuffer(cmd, bufItem->lengthA + 0x720, 0, bufItem->lengthB, reverb->rightRingBuf); + } + + return cmd; +} + +Acmd* func_800DB828(Acmd* arg0, s32 arg1, SynthesisReverb* arg2, s16 arg3) { + ReverbRingBufferItem* temp_v1; + s16 temp_t1; + s16 temp_t2_2; + + temp_v1 = &arg2->items[arg2->curFrame][arg3]; + temp_v1->unk_14 = (temp_v1->unk_18 << 0xF) / arg1; + temp_t1 = (temp_v1->startPos & 7) * 2; + temp_v1->unk_16 = (arg1 << 0xF) / temp_v1->unk_18; + temp_t2_2 = ALIGN16(temp_t1 + temp_v1->lengthA); + arg0 = AudioSynth_LoadRingBuffer(arg0, 0x3E0, temp_v1->startPos - (temp_t1 / 2), 0x1A0, arg2); + if (temp_v1->lengthB != 0) { + arg0 = AudioSynth_LoadRingBuffer(arg0, temp_t2_2 + 0x3E0, 0, 0x1A0 - temp_t2_2, arg2); + } + aSetBuffer(arg0++, 0, temp_t1 + 0x3E0, 0xC80, arg1 * 2); + aResample(arg0++, arg2->resampleFlags, temp_v1->unk_14, arg2->unk_30); + aSetBuffer(arg0++, 0, temp_t1 + 0x580, 0xE20, arg1 * 2); + aResample(arg0++, arg2->resampleFlags, temp_v1->unk_14, arg2->unk_34); + return arg0; +} + +Acmd* func_800DBA40(Acmd* arg0, s32 arg1, SynthesisReverb* arg2) { + if (arg2->unk_270 != NULL) { + aFilter(arg0++, 2, arg1, arg2->unk_270); + aFilter(arg0++, arg2->resampleFlags, 0xC80, arg2->unk_278); + } + + if (arg2->unk_274 != NULL) { + aFilter(arg0++, 2, arg1, arg2->unk_274); + aFilter(arg0++, arg2->resampleFlags, 0xE20, arg2->unk_27C); + } + return arg0; +} + +Acmd* func_800DBAE8(Acmd* arg0, SynthesisReverb* arg1, s32 arg2) { + SynthesisReverb* temp_a3; + + temp_a3 = &gAudioContext.synthesisReverbs[arg1->unk_05]; + if (temp_a3->downsampleRate == 1) { + arg0 = func_800DB330(arg0, temp_a3, arg2); + aMix(arg0++, 0x34, arg1->unk_08, 0xC80, 0x3E0); + arg0 = func_800DB3D8(arg0, temp_a3, arg2); + } + return arg0; +} + +void func_800DBB94(void) { +} + +void func_800DBB9C(Acmd* arg0, s32 arg1, s32 arg2) { + aClearBuffer(arg0, arg1, arg2); +} + +void func_800DBBBC(void) { +} + +void func_800DBBC4(void) { +} + +void func_800DBBCC(void) { +} + +void func_800DBBD4(Acmd* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { + aMix(arg0, arg1, arg2, arg3, arg4); +} + +void func_800DBC08(void) { +} + +void func_800DBC10(void) { +} + +void func_800DBC18(void) { +} + +void AudioSynth_SetBuffer(Acmd* cmd, s32 flag, s32 dmemIn, s32 dmemOut, s32 count) { + aSetBuffer(cmd, flag, dmemIn, dmemOut, count); +} + +void func_800DBC54(void) { +} + +void func_800DBC5C(void) { +} + +// possible fake match? +void AudioSynth_DMemMove(Acmd* cmd, s32 dmemIn, s32 dmemOut, s32 count) { + cmd->words.w0 = _SHIFTL(A_DMEMMOVE, 24, 8) | _SHIFTL(dmemIn, 0, 24); + cmd->words.w1 = _SHIFTL(dmemOut, 16, 16) | _SHIFTL(count, 0, 16); +} + +void func_800DBC90(void) { +} + +void func_800DBC98(void) { +} + +void func_800DBCA0(void) { +} + +void func_800DBCA8(void) { +} + +void AudioSynth_InterL(Acmd* cmd, s32 dmemIn, s32 dmemOut, s32 count) { + cmd->words.w0 = _SHIFTL(A_INTERL, 24, 8) | _SHIFTL(count, 0, 16); + cmd->words.w1 = _SHIFTL(dmemIn, 16, 16) | _SHIFTL(dmemOut, 0, 16); +} + +void func_800DBCD4(Acmd* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { + aEnvSetup1(arg0, arg1, arg2, arg3, arg4); +} + +void func_800DBD08(void) { +} + +void func_800DBD10(Acmd* arg0, s32 arg1, s32 arg2, s32 arg3) { + aLoadBuffer(arg0, arg3, arg1, arg2); +} + +void func_800DBD38(Acmd* arg0, s32 arg1, s32 arg2, s32 arg3) { + aSaveBuffer(arg0, arg1, arg3, arg2); +} + +void AudioSynth_EnvSetup2(Acmd* cmd, s32 volLeft, s32 volRight) { + cmd->words.w0 = _SHIFTL(A_ENVSETUP2, 24, 8); + cmd->words.w1 = _SHIFTL(volLeft, 16, 16) | _SHIFTL(volRight, 0, 16); +} + +void func_800DBD7C(void) { +} + +void func_800DBD84(void) { +} + +void func_800DBD8C(void) { +} + +void AudioSynth_UnkCmd17(Acmd* arg0, s32 arg1, s32 arg2) { + aUnkCmd17(arg0, arg1, arg2); +} + +void AudioSynth_HiLoGain(Acmd* cmd, s32 gain, s32 dmemIn, s32 dmemOut, s32 count) { + cmd->words.w0 = _SHIFTL(A_HILOGAIN, 24, 8) | _SHIFTL(gain, 16, 8) | _SHIFTL(count, 0, 16); + cmd->words.w1 = _SHIFTL(dmemIn, 16, 16) | _SHIFTL(dmemOut, 0, 16); +} + +void AudioSynth_UnkCmd19(Acmd* cmd, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { + cmd->words.w0 = _SHIFTL(A_UNK19, 24, 8) | _SHIFTL(arg4, 16, 8) | _SHIFTL(arg3, 0, 16); + cmd->words.w1 = _SHIFTL(arg1, 16, 16) | _SHIFTL(arg2, 0, 16); +} + +void func_800DBE18(void) { +} + +void func_800DBE20(void) { +} + +void func_800DBE28(void) { +} + +void func_800DBE30(void) { +} + +void AudioSynth_UnkCmd3(Acmd* cmd, s32 arg1, s32 arg2, s32 arg3) { + cmd->words.w0 = _SHIFTL(A_UNK3, 24, 8) | _SHIFTL(arg3, 0, 16); + cmd->words.w1 = _SHIFTL(arg1, 16, 16) | _SHIFTL(arg2, 0, 16); +} + +void func_800DBE5C(void) { +} + +void func_800DBE64(void) { +} + +void func_800DBE6C(void) { +} + +void AudioSynth_SetFilter(Acmd* cmd, s32 flags, s32 countOrBuf, s32 addr) { + aFilter(cmd, flags, countOrBuf, addr); +} + +void AudioSynth_SetFilterCount(Acmd* cmd, s32 count, s32 addr) { + aFilter(cmd, 2, count, addr); +} + +Acmd* func_800DBEB0(Acmd* cmd, s32 arg1, SynthesisReverb* reverb, s16 arg3) { + ReverbRingBufferItem* ringBufferItem = &reverb->items[reverb->curFrame][arg3]; + + cmd = AudioSynth_LoadRingBuffer(cmd, 0xC80, ringBufferItem->startPos, ringBufferItem->lengthA, reverb); + if (ringBufferItem->lengthB != 0) { + cmd = AudioSynth_LoadRingBuffer(cmd, ringBufferItem->lengthA + 0xC80, 0, ringBufferItem->lengthB, reverb); + } + + return cmd; +} + +Acmd* func_800DBF5C(Acmd* cmd, s32 arg1, SynthesisReverb* reverb, s16 bufIdx) { + ReverbRingBufferItem* bufItem = &reverb->items2[reverb->curFrame][bufIdx]; + + cmd = AudioSynth_LoadRingBuffer(cmd, 0xC80, bufItem->startPos, bufItem->lengthA, reverb); + if (bufItem->lengthB != 0) { + cmd = AudioSynth_LoadRingBuffer(cmd, bufItem->lengthA + 0xC80, 0, bufItem->lengthB, reverb); + } + return cmd; +} + +Acmd* AudioSynth_LoadRingBuffer(Acmd* cmd, u16 dmem, u16 startPos, s32 length, SynthesisReverb* reverb) { + aLoadBuffer(cmd++, &reverb->leftRingBuf[startPos], dmem, length); + aLoadBuffer(cmd++, &reverb->rightRingBuf[startPos], dmem + 0x1A0, length); + return cmd; +} + +Acmd* AudioSynth_SaveRingBuffer(Acmd* cmd, u16 dmem, u16 startPos, s32 length, SynthesisReverb* reverb) { + aSaveBuffer(cmd++, dmem, &reverb->leftRingBuf[startPos], length); + aSaveBuffer(cmd++, dmem + 0x1A0, &reverb->rightRingBuf[startPos], length); + return cmd; +} + +Acmd* AudioSynth_SaveBuffer(Acmd* cmd, u16 dmem, u16 offset, s32 length, s16* buf) { + aSaveBuffer(cmd++, dmem, &buf[offset], length); + return cmd; +} + +Acmd* func_800DC124(Acmd* cmd, s32 arg1, SynthesisReverb* reverb, s16 arg3) { + if (reverb->downsampleRate == 1) { + cmd = func_800DBF5C(cmd, arg1, reverb, arg3); + } + + return cmd; +} + +Acmd* func_800DC164(Acmd* cmd, s32 arg1, SynthesisReverb* reverb, s16 arg3) { + if (reverb->downsampleRate == 1) { + if (reverb->unk_18 != 0) { + cmd = func_800DB828(cmd, arg1, reverb, arg3); + } else { + cmd = func_800DBEB0(cmd, arg1, reverb, arg3); + } + } else { + cmd = func_800DB4E4(cmd, arg1, reverb, arg3); + } + return cmd; +} + +Acmd* func_800DC1D8(Acmd* cmd, SynthesisReverb* reverb, s16 bufIdx) { + ReverbRingBufferItem* bufItem = &reverb->items[reverb->curFrame][bufIdx]; + + if (reverb->downsampleRate == 1) { + if (reverb->unk_18 != 0) { + cmd = func_800DB680(cmd, reverb, bufIdx); + } else { + cmd = AudioSynth_SaveRingBuffer(cmd, 0xC80, bufItem->startPos, bufItem->lengthA, reverb); + if (bufItem->lengthB != 0) { + cmd = AudioSynth_SaveRingBuffer(cmd, bufItem->lengthA + 0xC80, 0, bufItem->lengthB, reverb); + } + } + } else { + func_800DBD38(cmd++, 0xC80, 0x340, reverb->items[reverb->curFrame][bufIdx].toDownsampleLeft); + } + + reverb->resampleFlags = 0; + return cmd; +} + +Acmd* func_800DC2DC(Acmd* cmd, SynthesisReverb* reverb, s16 bufIdx) { + ReverbRingBufferItem* bufItem = &reverb->items2[reverb->curFrame][bufIdx]; + + cmd = AudioSynth_SaveRingBuffer(cmd, 0xC80, bufItem->startPos, bufItem->lengthA, reverb); + if (bufItem->lengthB != 0) { + cmd = AudioSynth_SaveRingBuffer(cmd, bufItem->lengthA + 0xC80, 0, bufItem->lengthB, reverb); + } + return cmd; +} + +#ifdef NON_MATCHING +Acmd* func_800DC384(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updateIdx) { + NoteSubEu* phi_v0; + u8 sp9C[88]; + s16 phi_s2; + s16 phi_s4; + s32 t; + s32 useReverb; + SynthesisReverb* temp_t8; + u8 t2; + s32 i; + s32 unk14; + + t = gAudioContext.maxSimultaneousNotes * updateIdx; + phi_s2 = 0; + if (gAudioContext.numSynthesisReverbs == 0) { + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + phi_v0 = &gAudioContext.noteSubsEu[t + i]; + if (phi_v0->bitField0.s.enabled) { + sp9C[phi_s2++] = i; + } + } + i = 0; + } else { + for (phi_s4 = 0; phi_s4 < gAudioContext.numSynthesisReverbs; phi_s4++) { + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + phi_v0 = &gAudioContext.noteSubsEu[t + i]; + if (phi_v0->bitField0.s.enabled && phi_v0->bitField1.s.reverbIndex == phi_s4) { + sp9C[phi_s2++] = i; + } + } + } + + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + phi_v0 = &gAudioContext.noteSubsEu[t + i]; + if (phi_v0->bitField0.s.enabled && phi_v0->bitField1.s.reverbIndex >= gAudioContext.numSynthesisReverbs) { + sp9C[phi_s2++] = i; + } + } + i = 0; + } + + aClearBuffer(cmd++, 0x940, 0x340); + for (phi_s4 = 0; phi_s4 < gAudioContext.numSynthesisReverbs; phi_s4++) { + temp_t8 = &gAudioContext.synthesisReverbs[phi_s4]; + useReverb = temp_t8->useReverb; + if (useReverb) { + cmd = func_800DC164(cmd, aiBufLen, temp_t8, updateIdx); + aMix(cmd++, 0x34, temp_t8->unk_0A, 0xC80, 0x940); + unk14 = temp_t8->unk_14; + if (unk14) { + aDMEMMove(cmd++, 0xC80, 0x3E0, 0x340); + } + + aMix(cmd++, 0x34, temp_t8->unk_0C + 0x8000, 0xC80, 0xC80); + if ((temp_t8->unk_10 != 0) || (temp_t8->unk_12 != 0)) { + cmd = func_800DB480(cmd, temp_t8); + } + + if (unk14) { + cmd = func_800DC1D8(cmd, temp_t8, updateIdx); + if (temp_t8->unk_05 != -1) { + cmd = func_800DBAE8(cmd, temp_t8, updateIdx); + } + cmd = func_800DC124(cmd, aiBufLen, temp_t8, updateIdx); + aMix(cmd++, 0x34, temp_t8->unk_16, 0x3E0, 0xC80); + } + } + + while (i < phi_s2) { + phi_v0 = &gAudioContext.noteSubsEu[sp9C[i] + t]; + if (phi_v0->bitField1.s.reverbIndex == phi_s4) { + cmd = func_800DC910(sp9C[i], phi_v0, &gAudioContext.notes[sp9C[i]].synthesisState, aiBuf, aiBufLen, + cmd, updateIdx); + } else { + break; + } + i++; + } + + if (useReverb) { + if ((temp_t8->unk_270 != NULL) || (temp_t8->unk_274 != NULL)) { + cmd = func_800DBA40(cmd, aiBufLen * 2, temp_t8); + } + if (unk14) { + cmd = func_800DC2DC(cmd, temp_t8, updateIdx); + } else { + cmd = func_800DC1D8(cmd, temp_t8, updateIdx); + if (temp_t8->unk_05 != -1) { + cmd = func_800DBAE8(cmd, temp_t8, updateIdx); + } + } + } + } + + while (i < phi_s2) { + cmd = func_800DC910(sp9C[i], &gAudioContext.noteSubsEu[t + sp9C[i]], + &gAudioContext.notes[sp9C[i]].synthesisState, aiBuf, aiBufLen, cmd, updateIdx); + i++; + } + + updateIdx = aiBufLen * 2; + aInterleave(cmd++, updateIdx, 0x3C0, 0x940, 0xAE0); + aSaveBuffer(cmd++, 0x3C0, aiBuf, updateIdx * 2); + + return cmd; +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_synthesis/func_800DC384.s") +#endif + +#ifdef NON_MATCHING +Acmd* func_800DC910(s32 noteIdx, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s16* aiBuf, s32 aiBufLen, + Acmd* cmd, s32 updateIdx) { + AudioBankSample* sp150; + AdpcmLoop* sp14C; + s32 sp140; + s32 sp13C; + s32 sp138; + u16 sp136; + s32 sp120; + s32 sp110; + s32 sp104; + s32 sp100; + s32 spFC; + s32 spD4; + s32 spCC; + s32 spC8; + s32 spC0; + s32 spBC; + s32 spB0; + u16 spAE; + Note* sp9C; + u32 sp8C; + u32 sp88; + u32 sp50; + Acmd* temp_a0_3; + Acmd* temp_v0; + Acmd* temp_v0_10; + Acmd* temp_v0_11; + Acmd* temp_v0_12; + Acmd* temp_v0_13; + Acmd* temp_v0_8; + Acmd* temp_v0_9; + Acmd* temp_v1_3; + NoteSubEu* temp_a1; + NoteSynthesisState* temp_a2; + s32 temp_a1_3; + s32 temp_a2_2; + s32 temp_a2_3; + s32 temp_a2_4; + s32 temp_s1; + s32 temp_s1_2; + s32 temp_s1_3; + s32 temp_s4; + s32 temp_t0_3; + s32 temp_t1; + s32 temp_t9; + s32 temp_v0_3; + s32 temp_v0_5; + s32 temp_v0_7; + s32 temp_v1; + s32 temp_v1_4; + s32 temp_v1_5; + s32 temp_v1_6; + s32 temp_t0; + u16 temp_t6; + u16 temp_v1_7; + u32 temp_a3; + u32 temp_a3_3; + u32 temp_a3_4; + u32 temp_a3_5; + u32 temp_t0_2; + u32 temp_v0_6; + u8 temp_a1_4; + AdpcmLoop* temp_a1_2; + AudioBankSample* temp_v0_2; + AdpcmBook* temp_v0_4; + s32 phi_t1; + u8 phi_v1; + s32 phi_fp; + s32 phi_t1_2; + s32 phi_s3; + s32 phi_s1; + s32 phi_a1; + s32 phi_t1_3; + s32 phi_t0; + s32 phi_s4; + s32 phi_s0; + s32 phi_s5; + s32 phi_s6; + s32 phi_s7; + s32 phi_t1_4; + s32 phi_v1_2; + u8 phi_v1_3; + s32 phi_v1_4; + s32 phi_t1_5; + s32 phi_a1_2; + NoteSubEu* phi_s6_2; + s32 phi_s1_2; + NoteSubEu* phi_s6_3; + + sp8C = noteSubEu->bitField1.s.bookOffset; + sp88 = noteSubEu->bitField0.s.finished; + sp9C = &gAudioContext.notes[noteIdx]; + sp138 = 0; + + if (noteSubEu->bitField0.s.needsInit == 1) { + synthState->restart = 0; + synthState->unk_06 = 0; + synthState->curVolLeft = 0; + synthState->curVolRight = 0; + synthState->samplePosInt = sp9C->unk_BC; + synthState->samplePosFrac = noteSubEu->reverbVol; + synthState->unk_05 = 0; + synthState->prevHeadsetPanRight = 0; + synthState->prevHeadsetPanLeft = 0; + synthState->unk_1A = 1; + sp9C->noteSubEu.bitField0.s.finished = 0; + sp88 = 0; + sp138 = 1; + } + + sp136 = noteSubEu->resamplingRateFixedPoint; + spC0 = noteSubEu->bitField1.s.isSyntheticWave + 1; + temp_t0 = (sp136 * aiBufLen * 2) + synthState->unk_06; + synthState->unk_06 = temp_t0; + if (1 != synthState->unk_05) {} + synthState->unk_05 = spC0; + if (noteSubEu->bitField1.s.bit2) { + sp50 = temp_t0 >> 0x10; + cmd = func_800DD9F4(cmd, noteSubEu, synthState, sp50); + spAE = (synthState->samplePosInt * 2) + 0x580; + synthState->samplePosInt += sp50; + + // OLD BLOCK 94 + + } else { + sp50 = temp_t0 >> 0x10; + sp150 = noteSubEu->sound.audioBankSound->sample; + sp14C = sp150->loop; + sp100 = sp14C->end; + spB0 = 0; + spBC = 0; + sp110 = sp150->sampleAddr; + for (spBC = 0; !sp88 && spBC < spC0; spBC++) { + if (spC0 == 1) { + phi_fp = sp50; + } else if (sp50 & 1) { + phi_fp = (sp50 & ~1) + (spBC * 2); + } else { + phi_fp = sp50; + } + + if (sp150->bits4 == 0 || sp150->bits4 == 3) { + if (gAudioContext.unk_0x10 != sp150->bits4 + 8) { + switch (sp8C) { + case 1: + gAudioContext.unk_0x10 = D_8012FBAA; + ; + break; + case 2: + gAudioContext.unk_0x10 = sp150->bits4 + 8; + break; + case 3: + default: + break; + } + + aLoadADPCM(cmd++, sp150->book->order * 0x10 * sp150->book->npredictors, gAudioContext.unk_0x10); + } + } + sp104 = 0; + phi_s5 = 0; + while (sp104 != phi_fp) { + sp140 = 0; + sp13C = 0; + spFC = phi_fp - sp104; + phi_s3 = synthState->samplePosInt & 0xF; + if (phi_s3 == 0 && synthState->restart == 0) { + phi_s3 = 0x10; + } + if (spFC < (sp14C->end - synthState->samplePosInt)) { + phi_s1 = (s32)((spFC - (0x10 - phi_s3)) + 0xF) / 0x10; + phi_s0 = phi_s1 * 0x10; + phi_s6 = (0x10 - phi_s3); + phi_s7 = ((0x10 - phi_s3) + phi_s0) - spFC; + } else { + phi_s0 = (sp14C->end - synthState->samplePosInt) - (0x10 - phi_s3); + phi_s6 = (0x10 - phi_s3); + if (phi_s0 <= 0) { + phi_s0 = 0; + phi_s6 = (sp14C->end - synthState->samplePosInt); + } + phi_s1 = (s32)(phi_s0 + 0xF) / 0x10; + if (sp14C->count != 0) { + sp13C = 1; + phi_s7 = 0; + } else { + sp140 = 1; + phi_s7 = 0; + } + } + switch (sp150->bits4) { + case 0: + spCC = 0x10; + spC8 = 0; + spD4 = 9; + goto block_39; + case 3: + spCC = 0x10; + spC8 = 0; + spD4 = 5; + goto block_39; + case 1: + spCC = 0x10; + spC8 = 0; + spD4 = 0x10; + goto block_39; + case 2: + sp138 = 0; + sp120 = 0; + sp104 = phi_fp; + func_800DBB9C(cmd++, 0x580, (phi_fp * 2) + 0x20); + phi_s5 = phi_fp; + break; + case 5: + sp138 = 0; + sp120 = 0; + sp104 = phi_fp; + func_800DBB9C(cmd++, 0x580, (phi_fp * 2) + 0x20); + phi_s5 = phi_fp; + break; + // OLD BLOCK 71 + // OLD BLOCK 78 + + case 4: + block_39: + if (phi_s1 != 0) { + temp_v1_5 = (s32)((synthState->samplePosInt + spCC) - phi_s3) / 0x10; + if (sp150->bits2 == 0) { + phi_a1 = spC8 + (temp_v1_5 * spD4) + sp110; + } else if (sp150->bits2 != 1) { + phi_a1 = + func_800E12DC(spC8 + (temp_v1_5 * spD4) + sp110, ((phi_s1 * spD4) + 0x1F) & ~0xF, + sp138, &synthState->sampleDmaIndex, sp150->bits2); + } else { + return cmd; + } + + if (phi_a1 != 0) { + phi_t0 = phi_a1 & 0xF; + temp_v0_7 = ((phi_s1 * spD4) + 0x1F) & 0xFFF0; + aLoadBuffer(cmd++, phi_a1 - phi_t0, 0x940 - temp_v0_7, temp_v0_7); + } else { + phi_t0 = 0; + phi_s0 = 0; + } + + if (synthState->restart) { + aSetLoop(cmd++, sp150->loop); + sp138 = 2; + synthState->restart = 0; + } + + if (sp104 == 0) { + sp120 = phi_s3 * 2; + phi_s4 = 0; + } else { + phi_s4 = (phi_s5 + 0x1F) & ~0xF; + } + switch (sp150->bits4) { + case 0: + aSetBuffer(cmd++, 0, ((0x940 - (((phi_s1 * spD4) + 0x1F) & 0xFFF0)) + phi_t0), + phi_s4 + 0x580, phi_s0 * 2); + aADPCMdec(cmd++, sp138, synthState->synthesisBuffers); + break; + case 3: + aSetBuffer(cmd++, 0, ((0x940 - (((phi_s1 * spD4) + 0x1F) & 0xFFF0)) + phi_t0), + phi_s4 + 0x580, phi_s0 * 2); + aADPCMdec(cmd++, sp138 | 4, synthState->synthesisBuffers); + break; + case 1: + AudioSynth_SetBuffer(cmd++, 0, 0x940 - (((phi_s1 * spD4) + 0x1F) & 0xFFF0) + phi_t0, + phi_s4 + 0x580, phi_s0 * 2); + AudioSynth_UnkCmd17(cmd++, sp138, (s32)synthState->synthesisBuffers); + break; + } + + if (sp104 != 0) { + aDMEMMove(cmd++, phi_s4 + (phi_s3 * 2) + 0x580, phi_s5 + 0x580, + (((phi_s0 + phi_s6) - phi_s7) * 2)); + } + + temp_v1_6 = (phi_s0 + phi_s6) - phi_s7; + temp_t1 = sp104 + temp_v1_6; + + switch (sp138) { + case 1: + sp120 = 0x20; + phi_s5 = (phi_s0 * 2) + 0x20; + break; + case 2: + phi_s5 += (temp_v1_6 * 2); + break; + default: + if (phi_s5 != 0) { + phi_s5 += (temp_v1_6 * 2); + } else { + phi_s5 = (phi_s3 + temp_v1_6) * 2; + } + break; + } + + sp138 = 0; + break; + } + } + + if (sp140 != 0) { + sp88 = 1; + func_800DBB9C(cmd++, phi_s5 + 0x580, (phi_fp - sp104) * 2); + sp9C->noteSubEu.bitField0.s.finished = 1; + func_800DB2C0(updateIdx, noteIdx); + } else { + if (sp13C != 0) { + synthState->restart = 1; + synthState->samplePosInt = sp14C->start; + } else { + synthState->samplePosInt += spFC; + } + } + phi_v1_2 = spC0; + } + + switch (spC0) { + case 1: + spAE = sp120 + 0x580; + break; + case 2: + break; + default: + switch (spBC) { + case 0: + spAE = 0x3E0; + AudioSynth_InterL(cmd++, sp120 + 0x580, 0x3E0, ((phi_fp / 2) + 7) & ~7); + spB0 = phi_fp; + if (sp88 != 0) { + func_800DBB9C(cmd++, phi_fp + 0x3E0, phi_fp + 0x10); + } + break; + case 1: + AudioSynth_InterL(cmd++, sp120 + 0x580, spB0 + 0x3E0, ((phi_fp / 2) + 7) & ~7); + break; + } + } + } + } + + sp138 = 0; + if (noteSubEu->bitField0.s.needsInit == 1) { + noteSubEu->bitField0.s.needsInit = 0; + sp138 = 1; + } + + cmd = func_800DD62C(cmd++, synthState, aiBufLen * 2, sp136, spAE, sp138); + if (sp8C == 3) { + AudioSynth_UnkCmd19(cmd++, 0x3C0, 0x3C0, aiBufLen * 2, 0); + } + + if (sp8C == 2) { + AudioSynth_UnkCmd3(cmd++, 0x3C0, 0x3C0, aiBufLen * 2); + } + + phi_a1_2 = noteSubEu->unk_2; + if (phi_a1_2 != 0) { + if (phi_a1_2 < 0x10) { + phi_a1_2 = 0x10; + } + AudioSynth_HiLoGain(cmd++, phi_a1_2, 0x3C0, 0, (aiBufLen * 2) + 0x20); + } + + if (noteSubEu->unk_14 != 0) { + AudioSynth_SetFilterCount(cmd++, aiBufLen * 2, noteSubEu->unk_14); + AudioSynth_SetFilter(cmd++, sp138, 0x3C0, synthState->synthesisBuffers->mixEnvelopeState); + } + + if (noteSubEu->unk_07 != 0 && noteSubEu->unk_10 != 0) { + AudioSynth_DMemMove(cmd++, 0x3C0, 0x760, aiBufLen * 2); + if (synthState->unk_1A != 0) { + func_800DBB9C(cmd++, 0x760 - noteSubEu->unk_07, noteSubEu->unk_07); + synthState->unk_1A = 0; + } else { + func_800DBD10(cmd++, 0x760 - noteSubEu->unk_07, noteSubEu->unk_07, + &synthState->synthesisBuffers->panSamplesBuffer[0x18]); + } + AudioSynth_SaveBuffer(cmd++, ((aiBufLen * 2) - noteSubEu->unk_07) + 0x3C0, noteSubEu->unk_07, + &synthState->synthesisBuffers->panSamplesBuffer[0x18], NULL); + func_800DBBD4(cmd++, (aiBufLen * 2) >> 4, noteSubEu->unk_10, 0x760, 0x760 - noteSubEu->unk_07); + AudioSynth_DMemMove(cmd++, 0x760 - noteSubEu->unk_07, 0x3C0, aiBufLen * 2); + } else { + synthState->unk_1A = 1; + } + + if ((noteSubEu->headsetPanRight != 0) || (synthState->prevHeadsetPanRight != 0)) { + phi_s0 = 1; + } else if ((noteSubEu->headsetPanLeft != 0) || synthState->prevHeadsetPanLeft != 0) { + phi_s0 = 2; + } else { + phi_s0 = 0; + } + cmd = func_800DD6CC(cmd, noteSubEu, synthState, aiBufLen, 0x3C0, phi_s0, sp138); + if (noteSubEu->bitField0.s.usesHeadsetPanEffects) { + if (!(sp138 & 1)) { + sp138 = 0; + } + cmd = func_800DDB64(cmd, noteSubEu, synthState, aiBufLen * 2, sp138, phi_s0); + } + return cmd; +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_synthesis/func_800DC910.s") +#endif + +Acmd* func_800DD62C(Acmd* cmd, NoteSynthesisState* synthState, s32 count, u16 pitch, u16 inpDmem, s32 resampleFlags) { + if (pitch == 0) { + func_800DBB9C(cmd++, 0x3C0, count); + } else { + aSetBuffer(cmd++, 0, inpDmem, 0x3C0, count); + aResample(cmd++, resampleFlags, pitch, synthState->synthesisBuffers->finalResampleState); + } + return cmd; +} + +extern u32 D_801304A4; +extern u32 D_801304A8; +extern u32 D_801304AC; + +Acmd* func_800DD6CC(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s32 aiBufLen, u16 arg4, s32 arg5, + s32 arg6) { + u32 phi_a1; + u16 curVolLeft; + u16 targetVolLeft; + s32 phi_t1; + s16 reverVol; + u16 curVolRight; + s16 phi_a3; + s16 phi_t0; + s16 sp52; + s16 sp50; + u16 targetVolRight; + s32 pad; + + curVolLeft = synthState->curVolLeft; + targetVolLeft = noteSubEu->targetVolLeft; + targetVolLeft *= 0x10; + reverVol = noteSubEu->reverbVol; + curVolRight = synthState->curVolRight; + targetVolRight = noteSubEu->targetVolRight; + targetVolRight *= 0x10; + + phi_a3 = targetVolLeft != curVolLeft ? (targetVolLeft - curVolLeft) / (aiBufLen >> 3) : 0; + phi_t0 = targetVolRight != curVolRight ? (targetVolRight - curVolRight) / (aiBufLen >> 3) : 0; + + sp50 = synthState->samplePosFrac; + phi_t1 = sp50 & 0x7F; + + if (sp50 != reverVol) { + sp52 = (((reverVol & 0x7F) - phi_t1) << 9) / (aiBufLen >> 3); + synthState->samplePosFrac = reverVol; + } else { + sp52 = 0; + } + + synthState->curVolLeft = curVolLeft + (phi_a3 * (aiBufLen >> 3)); + synthState->curVolRight = curVolRight + (phi_t0 * (aiBufLen >> 3)); + + if (noteSubEu->bitField1.s.hasTwoAdpcmParts) { + func_800DBB9C(cmd++, 0x5C0, 0x1A0); + func_800DBCD4(cmd++, phi_t1 * 2, sp52, phi_a3, phi_t0); + AudioSynth_EnvSetup2(cmd++, curVolLeft, curVolRight); + switch (arg5) { + case 1: + phi_a1 = D_801304A4; + break; + case 2: + phi_a1 = D_801304A8; + break; + default: + phi_a1 = D_801304AC; + break; + } + } else { + aEnvSetup1(cmd++, phi_t1 * 2, sp52, phi_a3, phi_t0); + aEnvSetup2(cmd++, curVolLeft, curVolRight); + phi_a1 = D_801304AC; + } + + aEnvMixer(cmd++, arg4, aiBufLen, (sp50 & 0x80) >> 7, noteSubEu->bitField0.s.stereoHeadsetEffects, + noteSubEu->bitField0.s.usesHeadsetPanEffects, noteSubEu->bitField0.s.stereoStrongRight, + noteSubEu->bitField0.s.stereoStrongLeft, phi_a1); + return cmd; +} + +extern u8 D_801304C0[]; +Acmd* func_800DD9F4(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s32 arg3) { + s32 temp_v0; + s32 temp_t0; + s32 samplePosInt; + + temp_t0 = noteSubEu->unk_06; + samplePosInt = synthState->samplePosInt; + if (noteSubEu->bitField1.s.bookOffset != 0) { + func_800DBD10(cmd++, 0x580, ALIGN16(arg3 * 2), gWaveSamples[8]); + gWaveSamples[8] += arg3 * 2; + return cmd; + } else { + aLoadBuffer(cmd++, noteSubEu->sound.samples, 0x580, 0x80); + if (temp_t0 != 0) { + samplePosInt = (samplePosInt * D_801304C0[temp_t0 >> 2]) / D_801304C0[temp_t0 & 3]; + } + samplePosInt &= 0x3F; + temp_v0 = 0x40 - samplePosInt; + if (temp_v0 < arg3 && ((arg3 - temp_v0 + 0x3F) / 0x40) != 0) { + aDuplicate(cmd++, ((arg3 - temp_v0 + 0x3F) / 0x40), 0x580, 0x600, 0x80); + } + synthState->samplePosInt = samplePosInt; + } + return cmd; +} + +#ifdef NON_MATCHING +Acmd* func_800DDB64(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s32 arg3, s32 arg4, s32 arg5) { + s32 phi_v0; + s32 phi_v1; + s32 phi_t0; + + switch (arg5) { + case 1: + phi_v1 = noteSubEu->headsetPanRight; + phi_v0 = synthState->prevHeadsetPanRight; + synthState->prevHeadsetPanLeft = 0; + synthState->prevHeadsetPanRight = noteSubEu->headsetPanRight; + phi_t0 = 0x940; + break; + case 2: + phi_v1 = noteSubEu->headsetPanLeft; + phi_v0 = synthState->prevHeadsetPanLeft; + synthState->prevHeadsetPanLeft = noteSubEu->headsetPanLeft; + synthState->prevHeadsetPanRight = 0; + phi_t0 = 0xAE0; + break; + default: + return cmd; + } + + if (arg4 != 1) { + if (phi_v0 != phi_v1) { + aSetBuffer(cmd++, 0, 0x5C0, 0x3C0, (arg3 + phi_v1) - phi_v0); + aResampleZOH(cmd++, (u16)((((arg3 << 0xF) / 2) - 1) / ((((arg3 + phi_v1) - phi_v0) - 2) / 2)), 0); + } else { + aDMEMMove(cmd++, 0x5C0, 0x3C0, arg3); + } + + if (phi_v0 != 0) { + aLoadBuffer(cmd++, &synthState->synthesisBuffers->panResampleState[0x8], 0x5C0, ALIGN16(phi_v0)); + aDMEMMove(cmd++, 0x3C0, phi_v0 + 0x5C0, (arg3 + phi_v1) - phi_v0); + } else { + aDMEMMove(cmd++, 0x3C0, 0x5C0, (arg3 + phi_v1)); + } + } else { + aDMEMMove(cmd++, 0x5C0, 0x3C0, arg3); + aClearBuffer(cmd++, 0x5C0, phi_v1); + aDMEMMove(cmd++, 0x3C0, phi_v1 + 0x5C0, arg3); + } + + if (phi_v1 != 0) { + aSaveBuffer(cmd++, arg3 + 0x5C0, &synthState->synthesisBuffers->panResampleState[0x8], ALIGN16(phi_v1)); + } + aAddMixer(cmd++, ((arg3 + 0x3F) & ~0x3F), 0x5C0, phi_t0, 0x7FFF); + return cmd; +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/audio_synthesis/func_800DDB64.s") +#endif diff --git a/src/code/code_800DACC0.c b/src/code/code_800DACC0.c deleted file mode 100644 index 10ebbce75..000000000 --- a/src/code/code_800DACC0.c +++ /dev/null @@ -1,136 +0,0 @@ -#include "ultra64.h" -#include "global.h" - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/pad_800DACB0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DACC0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DB03C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DB0C4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DB2C0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DB330.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DB3D8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DB480.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DB4E4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DB680.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DB828.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBA40.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBAE8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBB94.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBB9C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBBBC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBBC4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBBCC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBBD4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBC08.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBC10.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBC18.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBC20.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBC54.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBC5C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBC64.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBC90.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBC98.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBCA0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBCA8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBCB0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBCD4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBD08.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBD10.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBD38.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBD60.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBD7C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBD84.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBD8C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBD94.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBDB0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBDE4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBE18.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBE20.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBE28.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBE30.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBE38.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBE5C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBE64.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBE6C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBE74.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBE98.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBEB0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DBF5C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DC008.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DC074.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DC0E0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DC124.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DC164.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DC1D8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DC2DC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DC384.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DC910.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DD62C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DD6CC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DD9F4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800DACC0/func_800DDB64.s") diff --git a/src/code/code_800E11F0.c b/src/code/code_800E11F0.c deleted file mode 100644 index 43d3ac105..000000000 --- a/src/code/code_800E11F0.c +++ /dev/null @@ -1,234 +0,0 @@ -#include "ultra64.h" -#include "global.h" - -// like audio_load in sm64, but completely rewritten - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E11F0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E12DC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1618.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/Audio_IsBankLoadComplete.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/Audio_IsSeqLoadComplete.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E19A0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/Audio_SetBankLoadStatus.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/Audio_SetSeqLoadStatus.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1A78.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1AD8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1B08.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1B68.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1C18.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1C78.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1D64.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1E34.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1E6C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1EB0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1EF4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1F38.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E1F7C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E202C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E20D4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2124.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E217C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E22C4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2318.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2338.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2454.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2558.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2768.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E27A4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E27F8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E283C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2AA8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2BCC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2BE0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2CB8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2CC0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2CE0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E2FEC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E301C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3028.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3034.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3094.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3400.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3414.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E35E0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3670.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3678.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E36EC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3874.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E38F8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E390C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3A14.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3A44.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3AC8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3BEC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3D10.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3D1C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3E58.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E3FB4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4044.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4058.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4198.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4590.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4744.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E478C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E48C0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4918.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4D94.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4ED4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4EDC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4EE4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4EEC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4F58.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4FB0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E4FE0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5000.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5584.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5958.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E59AC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E59F4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5A8C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5AD8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5AFC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5B20.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5B50.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5B80.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5C10.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5C28.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5D6C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5E20.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5E84.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5EA4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5EDC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5F34.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E5F88.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E6024.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E6070.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E60C4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E60EC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E611C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E6128.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E6300.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E64B0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E64F8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E651C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E6550.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E6590.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E6680.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E66A0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E66C0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/Audio_NextRandom.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E11F0/func_800E6818.s") diff --git a/src/code/code_800E4FE0.c b/src/code/code_800E4FE0.c new file mode 100644 index 000000000..6be070381 --- /dev/null +++ b/src/code/code_800E4FE0.c @@ -0,0 +1,844 @@ +#include "global.h" + +typedef enum { + CHAN_UPD_UNK_0, // 0 + CHAN_UPD_VOL_SCALE, // 1 + CHAN_UPD_VOL, // 2 + CHAN_UPD_PAN_SIGNED, // 3 + CHAN_UPD_FREQ_SCALE, // 4 + CHAN_UPD_REVERB, // 5 + CHAN_UPD_SCRIPT_IO, // 6 + CHAN_UPD_PAN_UNSIGNED, // 7 + CHAN_UPD_STOP_SOMETHING2, // 8 + CHAN_UPD_MUTE_BEHAVE, // 9 + CHAN_UPD_VIBE_X8, // 10 + CHAN_UPD_VIBE_X32, // 11 + CHAN_UPD_UNK_0F, // 12 + CHAN_UPD_UNK_20, // 13 + CHAN_UPD_REVERB_FLG // 14 +} ChannelUpdateType; + +void func_800E6300(SequenceChannel* channel, AudioCmd* arg1); +void func_800E59AC(s32 playerIdx, s32 fadeTimer); +void Audio_InitMesgQueues(void); +AudioTask* func_800E5000(void); +void Audio_ProcessCmds(u32); +void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* arg1); +void func_800E5958(s32 playerIdx, s32 fadeTimer); +s32 func_800E66C0(s32 arg0); + +// AudioMgr_Retrace +AudioTask* func_800E4FE0(void) { + return func_800E5000(); +} + +u32 D_801304E0 = 0x80; +AudioTask* D_801304E4 = NULL; + +extern u8 D_80155C70[]; +#ifdef NON_EQUIVALENT +// haven't verified Equivalency yet. +AudioTask* func_800E5000(void) { + u32 sp6C; + s32 abiCmdCnt; + s32 sp5C; + s16* sp58; + u32 sp4C; + s32 sp48; + void* sp3C; + void* sp34; + OSTask_t* temp_v1_10; + OSMesgQueue* temp_s1; + s16 temp_a0_2; + s16 temp_v0_2; + s16 temp_v1; + s16 temp_v1_2; + s16 temp_v1_9; + s32 temp_a0; + s32 temp_a3; + s32 temp_a3_2; + s32 temp_hi; + s32 temp_s0; + s32 temp_s0_2; + s32 temp_s0_3; + s32 temp_s0_4; + s32 temp_s0_5; + s32 temp_t4; + s32 temp_t6; + s32 temp_t7; + s32 temp_v1_6; + s32 temp_v1_7; + s32 temp_v1_8; + u32 temp_t3; + u32 temp_t4_2; + void* temp_t0; + void* temp_v1_3; + void* temp_v1_4; + void* temp_v1_5; + s16 phi_v1; + s32 phi_a0; + void* phi_v1_2; + s32 phi_s0; + s32 phi_v1_3; + void* phi_v1_4; + s32 phi_s0_2; + s32 phi_v1_5; + s32 phi_s0_3; + s32 phi_s0_4; + void* phi_v1_6; + s32 phi_s0_5; + s32 i; + + gAudioContext.totalTaskCnt++; + if (gAudioContext.totalTaskCnt % (gAudioContext.audioBufferParameters.presetUnk4) != 0) { + if (D_801755D0 != 0) { + D_801755D0(); + } + + if (gAudioContext.audioBufferParameters.presetUnk4 == + ((gAudioContext.totalTaskCnt % (gAudioContext.audioBufferParameters.presetUnk4)) + 1)) { + return D_801304E4; + } else { + return NULL; + } + } + + osSendMesg(gAudioContext.taskStartQueueP, gAudioContext.totalTaskCnt, 0); + temp_t4 = gAudioContext.curAIBufIdx + 1; + temp_t6 = (gAudioContext.curAIBufIdx + 1) % 3; + gAudioContext.rspTaskIdx ^= 1; + gAudioContext.curAIBufIdx++; + gAudioContext.curAIBufIdx %= 3; + temp_hi = (gAudioContext.curAIBufIdx - 2 + 3) % 3; + sp6C = osAiGetLength() / 4; + if (gAudioContext.resetTimer < 16) { + if (gAudioContext.aiBufLengths[temp_hi] != 0) { + sp34 = &gAudioContext + (temp_hi * 4); + sp3C = &gAudioContext + (temp_hi * 2); + osAiSetNextBuffer(gAudioContext.aiBuffers[temp_hi], gAudioContext.aiBufLengths[temp_hi] * 4); + } + } + + if (D_801755D0 != NULL) { + D_801755D0(); + } + + sp5C = gAudioContext.sampleIoReqIdx; + for (i = 0; i < gAudioContext.sampleIoReqIdx; i++) { + if (osRecvMesg(&gAudioContext.unk_1ED0, NULL, 0) == 0) { + sp5C--; + } + } + + if (sp5C != 0) { + for (i = 0; i < sp5C; i++) { + osRecvMesg(&gAudioContext.unk_1ED0, NULL, 1); + } + } + + sp48 = gAudioContext.unk_1ED0.validCount; + if (gAudioContext.unk_1ED0.validCount != 0) { + for (i = 0; i < sp48; i++) { + osRecvMesg(&gAudioContext.unk_1ED0, NULL, 0); + } + } + gAudioContext.sampleIoReqIdx = 0; + func_800E11F0(); + Audio_ProcessLoads(gAudioContext.resetStatus); + func_800E4F58(); + if ((gAudioContext.resetStatus != 0) && (Audio_ResetStep() == 0)) { + if (gAudioContext.resetStatus == 0) { + osSendMesg(gAudioContext.audioResetQueueP, gAudioContext.audioResetPresetIdToLoad, 0); + } + + D_801304E4 = NULL; + return NULL; + } + + if (gAudioContext.resetTimer > 16) { + return NULL; + } else if (gAudioContext.resetTimer != 0) { + gAudioContext.resetTimer++; + } + + gAudioContext.currTask = &gAudioContext.rspTask[gAudioContext.rspTaskIdx]; + gAudioContext.curAbiCmdBuf = gAudioContext.abiCmdBufs[gAudioContext.rspTaskIdx]; + gAudioContext.aiBufLengths[gAudioContext.curAIBufIdx] = + (s16)((((gAudioContext.audioBufferParameters.samplesPerFrameTarget - sp6C) + 0x80) & 0xFFF0) + 0x10); + if (gAudioContext.aiBufLengths[gAudioContext.curAIBufIdx] < + gAudioContext.audioBufferParameters.minAiBufferLength) { + gAudioContext.aiBufLengths[gAudioContext.curAIBufIdx] = gAudioContext.audioBufferParameters.minAiBufferLength; + } + + if (gAudioContext.audioBufferParameters.maxAiBufferLength < + gAudioContext.aiBufLengths[gAudioContext.curAIBufIdx]) { + gAudioContext.aiBufLengths[gAudioContext.curAIBufIdx] = gAudioContext.audioBufferParameters.maxAiBufferLength; + } + + if (gAudioContext.resetStatus == 0) { + i = 0; + // msg = 0000RREE R = read pos, E = End Pos + while (osRecvMesg(gAudioContext.cmdProcQueueP, &sp4C, 0) != -1) { + Audio_ProcessCmds(sp4C); + i++; + } + if ((i == 0) && (gAudioContext.cmdQueueFinished)) { + Audio_ScheduleProcessCmds(); + } + } + + gAudioContext.curAbiCmdBuf = + AudioSynth_Update(gAudioContext.curAbiCmdBuf, &abiCmdCnt, gAudioContext.aiBuffers[gAudioContext.curAIBufIdx], + gAudioContext.aiBufLengths[gAudioContext.curAIBufIdx]); + gAudioContext.audioRandom = osGetCount() * (gAudioContext.audioRandom + gAudioContext.totalTaskCnt); + gAudioContext.audioRandom = gAudioContext.aiBuffers[gAudioContext.curAIBufIdx][gAudioContext.totalTaskCnt & 0xFF] + + gAudioContext.audioRandom; + ; + gWaveSamples[8] = (s16*)((((u8*)func_800E4FE0)) + (gAudioContext.audioRandom & 0xFFF0)); + gAudioContext.currTask->taskQueue = NULL; + gAudioContext.currTask->unk_44 = NULL; + temp_v1_10 = &gAudioContext.currTask->task.t; + temp_v1_10->type = 2U; + temp_v1_10->flags = 0U; + temp_v1_10->ucode_boot = D_801120C0; + temp_v1_10->ucode_boot_size = 0x1000; + temp_v1_10->ucode_data_size = (((s32)(D_80155F50 - D_80155C70) >> 3) * 8) - 1; + temp_v1_10->ucode = D_801120C0; + temp_v1_10->ucode_data = D_80155C70; + temp_v1_10->ucode_size = 0x1000; + temp_v1_10->dram_stack = NULL; + temp_v1_10->dram_stack_size = 0; + temp_v1_10->output_buff = NULL; + temp_v1_10->output_buff_size = NULL; + temp_v1_10->data_ptr = gAudioContext.abiCmdBufs[gAudioContext.rspTaskIdx]; + temp_v1_10->yield_data_ptr = NULL; + temp_v1_10->yield_data_size = 0; + temp_v1_10->data_size = abiCmdCnt * sizeof(ACmd); + + if (D_801304E0 < abiCmdCnt) { + D_801304E0 = abiCmdCnt; + } + + if (gAudioContext.audioBufferParameters.presetUnk4 == 1) { + return gAudioContext.currTask; + } + D_801304E4 = gAudioContext.currTask; + return NULL; +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E4FE0/func_800E5000.s") +#endif + +#define ACMD_SND_MDE ((u32)0xF0000000) +#define ACMD_MUTE ((u32)0xF1000000) + +void func_800E5584(AudioCmd* cmd) { + s32 i; + s32 pad; + s32 pad2; + u32 temp_a1_5; + u32 temp_t7; + + switch (cmd->op) { + case 0x81: + func_800E1C18(cmd->arg1, cmd->arg2); + return; + case 0x82: + func_800E20D4(cmd->arg0, cmd->arg1, cmd->arg2); + func_800E59AC(cmd->arg0, cmd->data); + return; + case 0x85: + func_800E2124(cmd->arg0, cmd->arg1, cmd->data); + return; + case 0x83: + if (gAudioContext.seqPlayers[cmd->arg0].enabled) { + if (cmd->asInt == 0) { + Audio_SequencePlayerDisableAsFinished(&gAudioContext.seqPlayers[cmd->arg0]); + } else { + func_800E5958(cmd->arg0, cmd->asInt); + } + } + return; + case 0xF0: + gAudioContext.soundMode = cmd->asUInt; + return; + case 0xF1: + for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { + SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; + seqPlayer->muted = 1; + seqPlayer->recalculateVolume = 1; + } + return; + case 0xF2: + if (cmd->asUInt == 1) { + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + Note* note = &gAudioContext.notes[i]; + NoteSubEu* subEu = ¬e->noteSubEu.bitField0; + if (subEu->bitField0.s.enabled && note->playbackState.unk_04 == 0) { + if (note->playbackState.parentLayer->seqChannel->muteBehavior & 8) { + subEu->bitField0.s.finished = 1; + } + } + } + } + + for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { + SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; + seqPlayer->muted = 0; + seqPlayer->recalculateVolume = 1; + } + + return; + case 0xF3: + func_800E1D64(cmd->arg0, cmd->arg1, cmd->arg2); + return; + case 0xF4: + Audio_AudioTableAsyncLoad(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.unk_1E20); + return; + case 0xF5: + Audio_AudioBankAsyncLoad(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.unk_1E20); + return; + case 0xFC: + Audio_AudioSeqAsyncLoad(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.unk_1E20); + return; + case 0xF6: + func_800E1F7C(cmd->arg1); + return; + case 0x90: + gAudioContext.unk_5BDC[cmd->arg0] = cmd->asUShort; + return; + case 0xF9: + gAudioContext.resetStatus = 5; + gAudioContext.audioResetPresetIdToLoad = cmd->asUInt; + return; + case 0xFB: + D_801755D0 = cmd->asUInt; + return; + case 0xE0: + case 0xE1: + case 0xE2: + func_800E7744(cmd->op - 0xE0, cmd->arg0, cmd->arg1, cmd->data); + return; + case 0xFE: + temp_t7 = cmd->asUInt; + if (temp_t7 == 1) { + for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { + SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; + if (seqPlayer->enabled) { + Audio_SequencePlayerDisableAsFinished(seqPlayer); + } + } + } + func_800E66C0(temp_t7); + return; + case 0xE3: + func_800DE4B0(cmd->asInt); + return; + default: + return; + } +} + +// SetFadeOutTimer +void func_800E5958(s32 playerIdx, s32 fadeTimer) { + SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + + if (fadeTimer == 0) { + fadeTimer = 1; + } + + seqPlayer->fadeVelocity = -(seqPlayer->fadeVolume / fadeTimer); + seqPlayer->state = 2; + seqPlayer->fadeTimer = fadeTimer; +} + +// SetFadeInTimer +void func_800E59AC(s32 playerIdx, s32 fadeTimer) { + SequencePlayer* seqPlayer; + if (fadeTimer != 0) { + seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + seqPlayer->state = 1; + seqPlayer->fadeTimerUnkEu = fadeTimer; + seqPlayer->fadeTimer = fadeTimer; + seqPlayer->fadeVolume = 0.0f; + seqPlayer->fadeVelocity = 0.0f; + } +} + +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.taskStartMsgs, + ARRAY_COUNT(gAudioContext.taskStartMsgs)); + osCreateMesgQueue(gAudioContext.cmdProcQueueP, gAudioContext.cmdProcMsgs, ARRAY_COUNT(gAudioContext.cmdProcMsgs)); + osCreateMesgQueue(gAudioContext.audioResetQueueP, gAudioContext.audioResetMesgs, + ARRAY_COUNT(gAudioContext.audioResetMesgs)); +} + +void Audio_QueueCmd(u32 opArgs, void** data) { + AudioCmd* cmd = &gAudioContext.cmdBuf[gAudioContext.cmdWrPos & 0xFF]; + + cmd->opArgs = opArgs; + cmd->data = *data; + + gAudioContext.cmdWrPos++; + + if (gAudioContext.cmdWrPos == gAudioContext.cmdRdPos) { + gAudioContext.cmdWrPos--; + } +} + +void Audio_QueueCmdF32(u32 opArgs, f32 data) { + Audio_QueueCmd(opArgs, &data); +} + +void Audio_QueueCmdS32(u32 opArgs, s32 data) { + Audio_QueueCmd(opArgs, &data); +} + +void Audio_QueueCmdS8(u32 opArgs, s8 data) { + u32 uData = data << 0x18; + + Audio_QueueCmd(opArgs, &uData); +} + +void Audio_QueueCmdU16(u32 opArgs, u16 data) { + u32 uData = data << 0x10; + + Audio_QueueCmd(opArgs, &uData); +} + +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); + } + + ret = + osSendMesg(gAudioContext.cmdProcQueueP, + (void*)(((gAudioContext.cmdRdPos & 0xFF) << 8) | (gAudioContext.cmdWrPos & 0xFF)), OS_MESG_NOBLOCK); + if (ret != -1) { + gAudioContext.cmdRdPos = gAudioContext.cmdWrPos; + ret = 0; + } else { + return -1; + } + + return ret; +} + +void Audio_ResetCmdQueue(void) { + gAudioContext.cmdQueueFinished = 0; + gAudioContext.cmdRdPos = gAudioContext.cmdWrPos; +} + +void Audio_ProcessCmd(AudioCmd* cmd) { + SequencePlayer* seqPlayer; + u16 phi_v0; + s32 i; + + if ((cmd->op & 0xF0) == 0xF0) { + func_800E5584(cmd); + return; + } + + if (cmd->arg0 < gAudioContext.audioBufferParameters.numSequencePlayers) { + seqPlayer = &gAudioContext.seqPlayers[cmd->arg0]; + if (cmd->op & 0x80) { + func_800E5584(cmd); + return; + } + if (cmd->op & 0x40) { + func_800E6128(seqPlayer, cmd); + return; + } + + if (cmd->arg1 < 0x10) { + func_800E6300(seqPlayer->channels[cmd->arg1], cmd); + return; + } + if (cmd->arg1 == 0xFF) { + phi_v0 = gAudioContext.unk_5BDC[cmd->arg0]; + for (i = 0; i < 0x10; i++) { + if (phi_v0 & 1) { + func_800E6300(seqPlayer->channels[i], cmd); + } + phi_v0 = phi_v0 >> 1; + } + } + } +} + +void Audio_ProcessCmds(u32 msg) { + static u8 curCmdRdPos = 0; + AudioCmd* cmd; + u8 endPos; + + if (!gAudioContext.cmdQueueFinished) { + curCmdRdPos = msg >> 8; + } + + while (true) { + endPos = msg & 0xFF; + if (curCmdRdPos == endPos) { + gAudioContext.cmdQueueFinished = 0; + return; + } + + cmd = &gAudioContext.cmdBuf[curCmdRdPos++ & 0xFF]; + if (cmd->op == 0xF8) { + gAudioContext.cmdQueueFinished = 1; + return; + } + + Audio_ProcessCmd(cmd); + cmd->op = 0; + } +} + +u32 func_800E5E20(u32* arg0) { + u32 sp1C; + + if (osRecvMesg(&gAudioContext.unk_1E20, &sp1C, 0) == -1) { + *arg0 = 0; + return 0; + } + *arg0 = sp1C & 0xFFFFFF; + return sp1C >> 0x18; +} + +u8* func_800E5E84(s32 arg0, u32* arg1) { + return func_800E1F38(arg0, arg1); +} + +void func_800E5EA4(s32 arg0, u32* arg1, u32* arg2) { + *arg1 = gAudioContext.ctlEntries[arg0].unk_02; + *arg2 = gAudioContext.ctlEntries[arg0].unk_03; +} + +s32 func_800E5EDC(void) { + s32 pad; + s32 sp18; + + if (osRecvMesg(gAudioContext.audioResetQueueP, &sp18, OS_MESG_NOBLOCK) == -1) { + return 0; + } else if (gAudioContext.audioResetPresetIdToLoad != sp18) { + return -1; + } else { + return 1; + } +} + +void func_800E5F34(void) { + // probably a macro of some type? + s32 chk = -1;s32 sp28;do { } while (osRecvMesg(gAudioContext.audioResetQueueP, &sp28, 0) != chk); +} + +s32 func_800E5F88(u32 resetPreloadID) { + s32 resetStatus; + OSMesg msg; + s32 pad; + + func_800E5F34(); + resetStatus = gAudioContext.resetStatus; + if (resetStatus != 0) { + Audio_ResetCmdQueue(); + if (gAudioContext.audioResetPresetIdToLoad == resetPreloadID) { + return -2; + } else if (resetStatus > 2) { + gAudioContext.audioResetPresetIdToLoad = resetPreloadID; + return -3; + } else { + osRecvMesg(gAudioContext.audioResetQueueP, &msg, OS_MESG_BLOCK); + } + } + + func_800E5F34(); + Audio_QueueCmdS32(0xF9000000, resetPreloadID); + + return Audio_ScheduleProcessCmds(); +} + +void Audio_PreNMIInternal(void) { + gAudioContext.resetTimer = 1; + if (gAudioContextInitalized) { + func_800E5F88(0); + gAudioContext.resetStatus = 0; + } +} + +s8 func_800E6070(s32 playerIdx, s32 channelIdx, s32 scriptIdx) { + SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + SequenceChannel* channel; + if (seqPlayer->enabled) { + channel = seqPlayer->channels[channelIdx]; + return channel->soundScriptIO[scriptIdx]; + } else { + return -1; + } +} + +s8 func_800E60C4(s32 arg0, s32 arg1) { + return gAudioContext.seqPlayers[arg0].unk_158[arg1]; +} + +void func_800E60EC(void* memAddr, u32 size) { + Audio_SoundAllocPoolInit(&gAudioContext.unkPool, memAddr, size); +} + +void func_800E611C(void) { + gAudioContext.unkPool.start = NULL; +} + +void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) { + f32 fadeVolume; + switch (cmd->op) { + case 0x41: + if (seqPlayer->fadeVolumeScale != cmd->asFloat) { + seqPlayer->fadeVolumeScale = cmd->asFloat; + seqPlayer->recalculateVolume = 1; + } + return; + case 0x47: + seqPlayer->tempo = cmd->asInt * 0x30; + return; + case 0x49: + seqPlayer->unk_0C = cmd->asInt * 0x30; + return; + case 0x4E: + seqPlayer->unk_0C = cmd->asInt; + return; + case 0x48: + seqPlayer->transposition = cmd->asSbyte; + return; + case 0x46: + seqPlayer->unk_158[cmd->arg2] = cmd->asSbyte; + return; + case 0x4A: + fadeVolume = (s32)cmd->arg1 / 127.0f; + goto block_11; + case 0x4B: + fadeVolume = ((s32)cmd->arg1 / 100.0f) * seqPlayer->fadeVolume; + block_11: + if (seqPlayer->state != 2) { + seqPlayer->volume = seqPlayer->fadeVolume; + if (cmd->asInt == 0) { + seqPlayer->fadeVolume = fadeVolume; + } else { + s32 tmp = cmd->asInt; + seqPlayer->state = 0; + seqPlayer->fadeTimer = tmp; + seqPlayer->fadeVelocity = (fadeVolume - seqPlayer->fadeVolume) / tmp; + } + } + return; + case 0x4C: + if (seqPlayer->state != 2) { + if (cmd->asInt == 0) { + seqPlayer->fadeVolume = seqPlayer->volume; + } else { + s32 tmp = cmd->asInt; + seqPlayer->state = 0; + seqPlayer->fadeTimer = tmp; + seqPlayer->fadeVelocity = (seqPlayer->volume - seqPlayer->fadeVolume) / tmp; + } + } + return; + case 0x4D: + seqPlayer->unk_34 = cmd->asFloat; + if (seqPlayer->unk_34 == 1.0f) { + seqPlayer->unk_0b1 = 0; + } else { + seqPlayer->unk_0b1 = 1; + } + } +} + +void func_800E6300(SequenceChannel* channel, AudioCmd* cmd) { + switch (cmd->op) { + case CHAN_UPD_VOL_SCALE: + if (channel->volumeScale != cmd->asFloat) { + channel->volumeScale = cmd->asFloat; + channel->changes.s.volume = 1; + } + return; + case CHAN_UPD_VOL: + if (channel->volume != cmd->asFloat) { + channel->volume = cmd->asFloat; + channel->changes.s.volume = 1; + } + return; + case CHAN_UPD_PAN_SIGNED: + if (channel->newPan != cmd->asSbyte) { + channel->newPan = cmd->asSbyte; + channel->changes.s.pan = 1; + } + return; + case CHAN_UPD_PAN_UNSIGNED: + if (channel->newPan != cmd->asSbyte) { + channel->panChannelWeight = cmd->asSbyte; + channel->changes.s.pan = 1; + } + return; + case CHAN_UPD_FREQ_SCALE: + if (channel->freqScale != cmd->asFloat) { + channel->freqScale = cmd->asFloat; + channel->changes.s.freqScale = 1; + } + return; + case CHAN_UPD_REVERB: + if (channel->reverb != cmd->asSbyte) { + channel->reverb = cmd->asSbyte; + } + return; + case CHAN_UPD_SCRIPT_IO: + if (cmd->arg2 < 8) { + channel->soundScriptIO[cmd->arg2] = cmd->asSbyte; + } + return; + case CHAN_UPD_STOP_SOMETHING2: + channel->stopSomething2 = cmd->asSbyte; + return; + case CHAN_UPD_MUTE_BEHAVE: + channel->muteBehavior = cmd->asSbyte; + return; + case CHAN_UPD_VIBE_X8: + channel->vibratoExtentTarget = cmd->asUbyte * 8; + channel->vibratoExtentChangeDelay = 1; + return; + case CHAN_UPD_VIBE_X32: + channel->vibratoRateTarget = cmd->asUbyte * 32; + channel->vibratoRateChangeDelay = 1; + return; + case CHAN_UPD_UNK_0F: + channel->unk_0F = cmd->asUbyte; + return; + case CHAN_UPD_UNK_20: + channel->unk_20 = cmd->asUShort; + return; + case CHAN_UPD_REVERB_FLG: + channel->reverbBits.asByte = cmd->asUbyte; + return; + } +} + +void func_800E64B0(s32 arg0, s32 arg1, s32 arg2) { + Audio_QueueCmdS32(((arg0 & 0xFF) << 0x10) | 0xFA000000 | ((arg1 & 0xFF) << 8) | (arg2 & 0xFF), 1); +} + +void func_800E64F8(void) { + Audio_QueueCmdS32(0xFA000000, 0); +} + +void func_800E651C(u32 arg0, s32 arg1) { + Audio_QueueCmdS32((arg1 & 0xFF) | 0xFD000000, arg0); +} + +void Audio_WaitForAudioTask(void) { + osRecvMesg(gAudioContext.taskStartQueueP, NULL, OS_MESG_NOBLOCK); + osRecvMesg(gAudioContext.taskStartQueueP, NULL, OS_MESG_BLOCK); +} + +#ifdef NON_MATCHING +s32 func_800E6590(s32 arg0, s32 arg1, s32 arg2) { + u32 temp_v1_2; + AudioBankSound* temp_a0; + Note* temp_a0_2; + SequenceChannelLayer* temp_v0; + SequenceChannel* temp_v1; + SequencePlayer* seqPlayer; + + seqPlayer = &gAudioContext.seqPlayers[arg0]; + if (seqPlayer->enabled && seqPlayer->channels[arg1]->enabled) { + temp_v0 = seqPlayer->channels[arg1]->layers[arg2]; + if (temp_v0 == NULL) { + return 0; + } + + if (temp_v0->enabled) { + temp_a0_2 = temp_v0->note; + if (temp_a0_2 == NULL) { + return 0; + } + + if (!temp_v0->bit3) { + return 0; + } + + if (temp_v0 == temp_a0_2->playbackState.parentLayer) { + temp_a0 = temp_a0_2->noteSubEu.sound.audioBankSound; + if (temp_a0 == 0) { + return 0; + } + return temp_a0->sample->loop->end - temp_a0_2->synthesisState.samplePosInt; + } + return 0; + } + } + return 0; +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/code_800E4FE0/func_800E6590.s") +#endif + +s32 func_800E6680(void) { + return func_800E66C0(0); +} + +void func_800E66A0(void) { + func_800E66C0(2); +} + +s32 func_800E66C0(s32 arg0) { + s32 phi_v1; + NotePlaybackState* temp_a2; + NoteSubEu* temp_a3; + s32 i; + Note* note; + AudioBankSound* sound; + + phi_v1 = 0; + for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { + note = &gAudioContext.notes[i]; + temp_a2 = ¬e->playbackState; + if (note->noteSubEu.bitField0.s.enabled) { + temp_a3 = ¬e->noteSubEu; + if (temp_a2->adsr.action.s.state != 0) { + if (arg0 >= 2) { + sound = temp_a3->sound.audioBankSound; + if (sound == NULL || temp_a3->bitField1.s.bit2) { + continue; + } + if (sound->sample->bits2 == 0) { + continue; + } + } + + phi_v1++; + if ((arg0 & 1) == 1) { + temp_a2->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + temp_a2->adsr.action.s.release = 1; + } + } + } + } + return phi_v1; +} + +u32 Audio_NextRandom(void) { + static u32 audRand = 0x12345678; + + audRand = ((osGetCount() + 0x1234567) * (audRand + gAudioContext.totalTaskCnt)); + audRand += gAudioContext.audioRandom; + return audRand; +} + +void Audio_InitMesgQueues(void) { + Audio_InitMesgQueuesInternal(); +} diff --git a/src/code/code_800EC960.c b/src/code/code_800EC960.c index 962e73557..f6cd65611 100644 --- a/src/code/code_800EC960.c +++ b/src/code/code_800EC960.c @@ -1,268 +1,3350 @@ #include "ultra64.h" #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EC960.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ECA00.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ECA60.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ECAF0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ECB34.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ECB7C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ECC04.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ECDBC.s") - +typedef struct { + f32 unk_00; + f32 unk_04; + s8 unk_08; + s8 unk_09; + s8 unk_0A; + u8 unk_0B; + u8 unk_0C; +} unk_s1; + +typedef struct { + f32 unk_00; + f32 unk_04; + f32 unk_08; + s32 unk_0C; +} unk_s2; + +void Audio_SetVolScale(u8, u8, u8, u8); +void func_800F5550(u16); +void func_800F5E18(u8 arg0, u16 arg1, u8 arg2, s8 arg3, s8 arg4); +void func_800F4784(unk_s2* arg0); +void func_800F56A8(void); +void func_800F6FB4(u8); +s32 func_800F491C(u8 arg0); + +// stick float vals +extern f32 D_8012F6B4[]; +extern u32 sOcarinaAllowedBtnMask; // 80130EFC +extern s32 sOcarinaABtnMap; // 80130F00 +extern s32 sOcarinaCUPBtnMap; // 80130F04 +extern s32 sOcarinaCDownBtnMap; // 80130F08 +extern u8 D_80131F64; +extern u8 D_80133408; +extern s8 D_8013060C; +extern s8 D_80130604; +extern s8 D_80130614; +extern f32 D_80130620; +extern s8 D_80130624; +extern u8 D_80131878; +extern u32 D_80130F3C; +extern u8 sCurOcarinaBtnVal; // 80130F14 +extern u8 sPrevOcarinaNoteVal; // 80130F18 +extern u8 sCurOcarinaBtnIdx; // note index? +extern u8 sLearnSongLastBtn; +extern u8 sOcarinaInpEnabled; // D_80130F0C +extern u8 sPlaybackState; +extern u16 sStaffPlaybackPos; +extern s8 D_80130F10; // ocarina active? +extern u8 sNoteValueIndexMap[]; +extern s8 D_80130618; +extern u8 D_8013061C; +extern u8 D_8013063C; +extern u8 D_80130640; +extern u8 D_80130644; +extern u8 D_80130648; +extern s8 D_801306C8[]; +extern u8 D_80133414; +extern s8 D_80130610; +extern u8 D_80130600; +extern u8 D_801305F8[]; +extern s8 D_80130608; +extern u8 D_801305FF; +extern Vec3f* D_8013064C; +extern u8 D_801305CC; +extern u8 D_8013062C; +extern u8 D_80130630; +extern u8 D_80130658[]; +extern u8 D_80133418; +extern u16 D_80130628; +extern s8 D_80130F2C; // pitch? +extern f32 D_80130650; +extern s8 D_801305B8; +extern s8 D_801305BC; +extern s8 D_801305C0; +extern f32 D_801305E4[]; +extern u8 sPrevChargeLevel; +extern f32 D_801305F4; +extern u32 D_801305B0; +extern u32 D_801305B4; +extern f32 D_80131C8C; +extern u8 D_80131C98; +extern u8 D_80131C9C; +extern u8 D_80131CA0; +extern u8 D_80131CA8; +extern u16 D_80131E08[]; +extern u8 D_8013340C; +extern u8 D_80131EEE; +extern s8 D_80131EBC; +extern s8 D_80131EC0; +extern s8 D_80131EC4; +extern s8 D_80131EC8[]; +extern u16 D_80131E20[]; +extern u8 D_80131CA4; +extern u8 sOcaMinigameEndPos; +extern u8 sOcaMinigameApndPos; +extern u8 sOcaMinigameNoteCnts[]; +extern u16 D_80130F3E; +extern u8 sOcarinaNoteValues[5]; +extern u8 D_8013170C; +/** bit field of songs that can be played + * 0x0800 storms + * 0x0400 song of time + * 0x0200 suns + * 0x0100 lullaby + * 0x0080 epona + * 0x0040 sarias + * 0x0020 prelude + * 0x0010 nocturne + * 0x0008 requiem + * 0x0004 serenade + * 0x0002 bolero + * 0x0001 minuet + */ +extern u8 D_8013187C; +extern u16 D_80130F4C; +extern u8 D_80131880; +extern u8 D_80131858; +extern f32 D_80130F24; +extern s8 D_80130F34; +extern u32 D_80130F28; +extern u8 D_80131F4C[]; +extern u8 D_80131F50; +extern OcarinaSong sOcarinaSongs[]; // 80130F80 +extern u32 sNotePlaybackTimer; +extern u16 sPlaybackNotePos; +extern u32 D_80131860; +extern u8 D_8013186; +extern u8 D_80131868; +extern u8 D_8013186C; +extern s8 D_80131870; +extern u8 D_80131874; +extern u8 sRecordSongPos; +extern u8 D_80131864; +extern s8 D_80130F30; +extern OcarinaSong* sPlaybackSong; +extern OcarinaSong sPierresSong; +extern u8 sDisplayedNoteValue; // Note to display on screen? +extern s32 D_80130F68; +extern OcarinaNote* D_80131BE4; +extern OcarinaSong* D_80131BEC; + +typedef struct { + u8 unk_00; + char unk_01[0x37]; +} unk_dstruct; + +extern u8 D_80131EFC; +extern unk_dstruct D_801337CE[]; +extern u8 D_80131F28; +extern u8 D_80131F2C; +extern u8 D_80131F30[]; + +/** + * BSS + */ +u32 sAudioUpdateStartTime; // 8016B7A0 +u32 sAudioUpdateEndTime; +f32 D_8016B7A8; +f32 D_8016B7AC; // maybe padding? +f32 D_8016B7B0; +f32 D_8016B7B4; +unk_s2 D_8016B7B8; +unk_s2 D_8016B7C8; +f32 D_8016B7D8; +s8 D_8016B7DC; +f32 D_8016B7E0; +u16 D_8016B7E4; +typedef struct { + char unk_00[6]; + s16 unk_06; +} unk_D_8016B7E8; +unk_D_8016B7E8 D_8016B7E8[0x19]; +u8 D_8016B8B0; +u8 D_8016B8B1; +u8 D_8016B8B2; +u8 D_8016B8B3; +u8 D_8016B8B4; +unk_s1 D_8016B8B8[0x10]; + +// maybe a struct? +u8 D_8016B9B8[0x20]; +u8 D_8016B9D8[0x8]; // probably array. +u8 D_8016B9E0[0x12]; +u8 D_8016B9F2; +u8 D_8016B9F3; +u8 D_8016B9F4; +u16 D_8016B9F6; + +OcarinaStaff D_8016B9F8; // playing along staff? +OcarinaStaff sDisplayedStaff; // displayed staff? +OcarinaStaff D_8016BA00; // ?? note and status not updated, pos updated as you play +u32 D_8016BA04; +typedef struct { + s8 x; + s8 y; +} OcarinaStick; +OcarinaStick sCurOcaStick; +u32 sCurOcarinaBtnPress; +u32 D_8016BA10; +u32 sPrevOcarinaBtnPress; +s32 D_8016BA18; +s32 D_8016BA1C; +u8 sCurOcarinaSong[8]; +u8 sOcarinaSongAppendPos; +u8 sOcarinaHasStartedSong; +u8 gOcarinaSongNotestartIdx; +u8 sOcarinaSongCnt; +u16 sOcarinaAvailSongs; +u8 D_8016BA2E; +u16 sLearnSongPos[0x10]; +u16 D_8016BA50[0x10]; +u16 D_8016BA70[0x10]; +u8 sLearnSongExpectedNote[0x10]; +OcarinaNote D_8016BAA0; +u8 D_8016BAA8; +f32 D_8016BAAC; +u32 D_8016BAB0; +u32 sDebugPadPressRaw; +u32 sDebugPadPress; +s32 sAudioUpdateTaskStart; +s32 sAudioUpdateTaskEnd; + +void func_800EC960(u8 custom) { + if (!custom) { + osSyncPrintf("AUDIO : Ocarina Control Assign Normal\n"); + sOcarinaAllowedBtnMask = (BTN_A | BTN_CUP | BTN_CDOWN | BTN_CLEFT | BTN_CRIGHT); + sOcarinaABtnMap = BTN_A; + sOcarinaCUPBtnMap = BTN_CUP; + sOcarinaCDownBtnMap = BTN_CDOWN; + } else { + osSyncPrintf("AUDIO : Ocarina Control Assign Custom\n"); + sOcarinaAllowedBtnMask = (BTN_A | BTN_B | BTN_CDOWN | BTN_CLEFT | BTN_CRIGHT); + sOcarinaABtnMap = BTN_B; + sOcarinaCUPBtnMap = BTN_CDOWN; + sOcarinaCDownBtnMap = BTN_A; + } +} + +void PadMgr_RequestPadData(PadMgr* padmgr, Input* inputs, s32 mode); +void Audio_GetOcaInput(void) { + Input input[4]; + Input* inputP = &input[0]; + u32 sp18; + + sp18 = sCurOcarinaBtnPress; + inputP = input; + PadMgr_RequestPadData(&gPadMgr, input, 0); + sCurOcarinaBtnPress = inputP->cur.button; + sPrevOcarinaBtnPress = sp18; + sCurOcaStick.x = inputP->rel.stick_x; + sCurOcaStick.y = inputP->rel.stick_y; +} + +f32 Audio_OcaAdjStick(s8 inp) { + s8 inpAdj; + f32 ret; + + if (inp > 0x40) { + inpAdj = 127; + } else if (inp < -0x40) { + inpAdj = -128; + } else if (inp >= 0) { + inpAdj = (inp * 127) / 64; + } else { + inpAdj = (inp * 128) / 64; + } + ret = D_8012F6B4[inpAdj]; + return ret; +} + +u8 func_800ECAF0(void) { + u8 ret; + + if (D_80131878 != 0) { + ret = D_80131878 - 1; + D_80131878 = 0; + } else if (D_80130F3C != 0) { + ret = 0xFE; + } else { + ret = 0xFF; + } + + return ret; +} + +u8 Audio_OcaMapNoteValue(u8 arg0) { + u8 temp_v1; + + temp_v1 = sNoteValueIndexMap[arg0 & 0x3F]; + if (temp_v1 == 5) { + if (arg0 & 0x80) { + return 2; + } + return 3; + } + return temp_v1; +} + +void func_800ECB7C(u8 songIdx) { + u8 savedSongIdx; + u8 scarecrowSongIdx; + u8 noteIdx; + + savedSongIdx = 0; + scarecrowSongIdx = 0; + while (savedSongIdx < 8 && scarecrowSongIdx < 0x10) { + noteIdx = sOcarinaSongs[songIdx].notes[scarecrowSongIdx++].noteIdx; + if (noteIdx != 0xFF) { + gOcarinaSongNotes[0xC].notesIdx[savedSongIdx++] = sNoteValueIndexMap[noteIdx]; + } + } +} + +// start ocarina. +void func_800ECC04(u16 flg) { + u8 i; + + if ((sOcarinaSongs[0xC].notes[1].volume != 0xFF) && ((flg & 0xFFF) == 0xFFF)) { + flg |= 0x1000; + } + + if ((flg == 0xCFFF) && (sOcarinaSongs[0xC].notes[1].volume != 0xFF)) { + flg = 0xDFFF; + } + + if ((flg == 0xFFF) && (sOcarinaSongs[0xC].notes[1].volume != 0xFF)) { + flg = 0x1FFF; + } + + if (flg != 0xFFFF) { + D_80130F3C = 0x80000000 + (u32)flg; + gOcarinaSongNotestartIdx = 0; + sOcarinaSongCnt = 0xE; + if (flg != 0xA000) { + sOcarinaSongCnt--; + } + sOcarinaAvailSongs = flg & 0x3FFF; + D_8013187C = 8; + sOcarinaHasStartedSong = 0; + D_80131878 = 0; + D_8016BA2E = 0; + D_8016B9F8.state = func_800ECAF0(); + sOcarinaInpEnabled = 1; + D_80130F4C = 0; + for (i = 0; i < 0xE; i++) { + sLearnSongPos[i] = 0; + D_8016BA50[i] = 0; + D_8016BA70[i] = 0; + sLearnSongExpectedNote[i] = 0; + } + + if (flg & 0x8000) { + D_8013187C = 0; + } + + if (flg & 0x4000) { + sOcarinaSongAppendPos = 0; + } + + if (flg & 0xD000) { + func_800ECB7C(0xC); + return; + } + } else { + D_80130F3C = 0; + sOcarinaInpEnabled = 0; + } +} + +void func_800ECDBC(void) { + if (sCurOcarinaBtnVal != 0xFF && sOcarinaHasStartedSong == 0) { + sOcarinaHasStartedSong = 1; + sLearnSongLastBtn = 0xFF; + } +} + +#ifdef NON_MATCHING +void func_800ECDF8(void) { + u16 sh; + u16 pad; + u8 inputChanged = 0; + u16 pad2; + s8 sp57 = 0; + u8 i; + OcarinaNote* prevNote; + OcarinaNote* note; + + func_800ECDBC(); + + if (sOcarinaHasStartedSong) { + if ((D_80130F2C < 0 ? -D_80130F2C : D_80130F2C) >= 0x15) { + D_80130F3C = 0; + return; + } + + if (sPrevOcarinaNoteVal == sCurOcarinaBtnVal || sCurOcarinaBtnVal == 0xFF) { + inputChanged = 1; + } + + for (i = gOcarinaSongNotestartIdx; i < sOcarinaSongCnt; i++) { + sh = 1 << i; + if (sOcarinaAvailSongs & sh) { + D_8016BA50[i] = D_8016BA70[i] + 0x12; + if (inputChanged) { + if ((D_8016BA50[i] >= D_8016BA70[i] - 0x12) && (D_8016BA50[i] >= D_8016BA70[i]) && + (sOcarinaSongs[i].notes[sLearnSongPos[i]].unk_02 == 0) && + (sLearnSongLastBtn == sLearnSongExpectedNote[i])) { + D_80131878 = i + 1; + sOcarinaInpEnabled = 0; + D_80130F3C = 0; + } + } else if (D_8016BA50[i] >= (D_8016BA70[i] - 0x12)) { + if (sLearnSongLastBtn != 0xFF) { + if (sLearnSongLastBtn == sLearnSongExpectedNote[i]) { + if (i == 0xC) { + D_8016BA50[i] = 0; + } + } else { + sOcarinaAvailSongs ^= sh; + } + } + + prevNote = &sOcarinaSongs[i].notes[sLearnSongPos[i]]; + note = &sOcarinaSongs[i].notes[++sLearnSongPos[i]]; + D_8016BA70[i] = prevNote->unk_02; + sLearnSongExpectedNote[i] = prevNote->noteIdx; + + if (sCurOcarinaBtnVal != sLearnSongExpectedNote[i]) { + sOcarinaAvailSongs ^= sh; + } + for (; prevNote->noteIdx == note->noteIdx || (note->noteIdx == 0xFF && note->unk_02 != 0); + sLearnSongPos[i]++) { + D_8016BA70[i] += note->unk_02; + note = &sOcarinaSongs[i].notes[sLearnSongPos[i] + 1]; + prevNote = &sOcarinaSongs[i].notes[sLearnSongPos[i]]; + } + } else if (D_8016BA50[i] < 0xA) { + sp57 = -1; + D_8016BA50[i] = 0; + sLearnSongLastBtn = sCurOcarinaBtnVal; + } else { + sOcarinaAvailSongs ^= sh; + } + } + + if (sOcarinaAvailSongs == 0 && D_8016BA2E >= D_8013187C) { + sOcarinaInpEnabled = 0; + if (CHECK_BTN_ANY(D_80130F3C, BTN_B) && sCurOcarinaBtnVal == sOcarinaSongs[i].notes[0].noteIdx) { + D_80130F4C = D_80130F3C; + } + D_80130F3C = 0; + return; + } + } + + if (!inputChanged) { + sLearnSongLastBtn = sCurOcarinaBtnVal; + D_8016BA2E += sp57 + 1; + } + } +} +#else +void func_800ECDF8(void); #pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ECDF8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ED200.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ED458.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ED848.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ED858.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800ED93C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EDA3C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EDD68.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE170.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE29C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE2D4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE318.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE3C8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE3D4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE3F8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE404.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE57C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE5EC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE6F4.s") - +#endif + +void func_800ED200(void) { + u32 temp_v0; + u8 i; + u8 j; + u8 k; + + if (CHECK_BTN_ANY(sCurOcarinaBtnPress, BTN_L) && CHECK_BTN_ANY(sCurOcarinaBtnPress, sOcarinaAllowedBtnMask)) { + func_800ECC04(D_80130F3E); + return; + } + + func_800ECDBC(); + + if (sOcarinaHasStartedSong) { + if ((sPrevOcarinaNoteVal != sCurOcarinaBtnVal) && (sCurOcarinaBtnVal != 0xFF)) { + D_8016BA2E++; + if (D_8016BA2E >= 9) { + D_8016BA2E = 1; + } + + if (sOcarinaSongAppendPos == 8) { + for (i = 0; i < 7; i++) { + sCurOcarinaSong[i] = sCurOcarinaSong[i + 1]; + } + } else { + sOcarinaSongAppendPos++; + } + + if ((D_80130F2C < 0 ? -D_80130F2C : D_80130F2C) >= 0x15) { + sCurOcarinaSong[sOcarinaSongAppendPos - 1] = 0xFF; + } else { + sCurOcarinaSong[sOcarinaSongAppendPos - 1] = sCurOcarinaBtnVal; + } + + for (i = gOcarinaSongNotestartIdx; i < sOcarinaSongCnt; i++) { + if (sOcarinaAvailSongs & (u16)(1 << i)) { + for (j = 0, k = 0; + j < gOcarinaSongNotes[i].len && k == 0 && sOcarinaSongAppendPos >= gOcarinaSongNotes[i].len;) { + temp_v0 = sCurOcarinaSong[(sOcarinaSongAppendPos - gOcarinaSongNotes[i].len) + j]; + if (temp_v0 == sOcarinaNoteValues[gOcarinaSongNotes[i].notesIdx[j]]) { + j++; + } else { + k++; + } + } + + if (j == gOcarinaSongNotes[i].len) { + D_80131878 = i + 1; + sOcarinaInpEnabled = 0; + D_80130F3C = 0; + } + } + } + } + } +} + +void func_800ED458(s32 arg0) { + u32 phi_v1_2; + + if (D_80130F3C != 0 && D_80131880 != 0) { + D_80131880--; + return; + } + + if ((D_8016BA10 == 0) || + ((sCurOcarinaBtnPress & sOcarinaAllowedBtnMask) != (0, D_8016BA10 & sOcarinaAllowedBtnMask))) { + D_8016BA10 = 0; + if (1) {} + sCurOcarinaBtnVal = 0xFF; + sCurOcarinaBtnIdx = 0xFF; + phi_v1_2 = (sCurOcarinaBtnPress & sOcarinaAllowedBtnMask) & (sPrevOcarinaBtnPress & sOcarinaAllowedBtnMask); + if (!(D_8016BA18 & phi_v1_2) && (sCurOcarinaBtnPress != 0)) { + D_8016BA18 = sCurOcarinaBtnPress; + } else { + D_8016BA18 &= phi_v1_2; + } + + if (D_8016BA18 & sOcarinaABtnMap) { + osSyncPrintf("Presss NA_KEY_D4 %08x\n", sOcarinaABtnMap); + sCurOcarinaBtnVal = 2; + sCurOcarinaBtnIdx = 0; + } else if (D_8016BA18 & sOcarinaCDownBtnMap) { + osSyncPrintf("Presss NA_KEY_F4 %08x\n", sOcarinaCDownBtnMap); + sCurOcarinaBtnVal = 5; + sCurOcarinaBtnIdx = 1; + } else if (D_8016BA18 & 1) { + osSyncPrintf("Presss NA_KEY_A4 %08x\n", 1); + sCurOcarinaBtnVal = 9; + sCurOcarinaBtnIdx = 2; + } else if (D_8016BA18 & 2) { + osSyncPrintf("Presss NA_KEY_B4 %08x\n", 2); + sCurOcarinaBtnVal = 0xB; + sCurOcarinaBtnIdx = 3; + } else if (D_8016BA18 & sOcarinaCUPBtnMap) { + osSyncPrintf("Presss NA_KEY_D5 %08x\n", sOcarinaCUPBtnMap); + sCurOcarinaBtnVal = 0xE; + sCurOcarinaBtnIdx = 4; + } + + if (sCurOcarinaBtnVal != 0xFF && sCurOcarinaBtnPress & 0x10 && D_80131858 != 2) { + sCurOcarinaBtnIdx += 0x80; + sCurOcarinaBtnVal++; + } + + if ((sCurOcarinaBtnVal != 0xFF) && (sCurOcarinaBtnPress & 0x2000) && (D_80131858 != 2)) { + sCurOcarinaBtnIdx += 0x40; + sCurOcarinaBtnVal--; + } + + if (D_80131858 != 2) { + D_80130F2C = sCurOcaStick.y; + D_80130F24 = Audio_OcaAdjStick(D_80130F2C); + + D_80130F34 = (sCurOcaStick.x < 0 ? -sCurOcaStick.x : sCurOcaStick.x) >> 2; + Audio_QueueCmdS8(0x6020D06, D_80130F34); + } else { + D_80130F2C = 0; + D_80130F24 = 1.0f; + } + + if ((sCurOcarinaBtnVal != 0xFF) && (sPrevOcarinaNoteVal != sCurOcarinaBtnVal)) { + Audio_QueueCmdS8(0x6020D07, D_80130F10 - 1); + Audio_QueueCmdS8(0x6020D05, sCurOcarinaBtnVal); + Audio_PlaySoundGeneral(NA_SE_OC_OCARINA, &D_801333D4, 4, &D_80130F24, &D_80130F28, &D_801333E8); + } else if ((sPrevOcarinaNoteVal != 0xFF) && (sCurOcarinaBtnVal == 0xFF)) { + Audio_StopSfx(NA_SE_OC_OCARINA); + } + } +} + +void func_800ED848(u8 inputEnabled) { + sOcarinaInpEnabled = inputEnabled; +} + +void func_800ED858(u8 arg0) { + if (D_80130F10 == arg0) { + return; + } + + Audio_SeqCmd8(2, 1, 0xD, arg0); + D_80130F10 = arg0; + if (arg0 == 0) { + sCurOcarinaBtnPress = 0; + sPrevOcarinaBtnPress = 0; + D_8016BA18 = 0; + D_8016BA10 = 0xFFFF; + func_800ED458(0); + Audio_StopSfx(NA_SE_OC_OCARINA); + func_800F7260(0); + sPlaybackState = 0; + sStaffPlaybackPos = 0; + sOcarinaInpEnabled = 0; + D_80130F3C = 0; + Audio_ClearBGMMute(0xD); + } else { + sCurOcarinaBtnPress = 0; + Audio_GetOcaInput(); + D_8016BA10 = sCurOcarinaBtnPress; + Audio_QueueSeqCmdMute(0xD); + } +} + +void func_800ED93C(s8 songIdx, s8 arg1) { + s32 temp_a0; + s32 temp_a0_2; + u16 temp_t5; + u16 temp_v0; + u16 temp_v0_2; + u16 phi_v0; + + if (songIdx == 0) { + sPlaybackState = 0; + Audio_StopSfx(NA_SE_OC_OCARINA); + return; + } + + if (songIdx < 0xF) { + sPlaybackSong = &sOcarinaSongs[songIdx - 1]; + } else { + sPlaybackSong = &sPierresSong; + } + + sPlaybackState = arg1; + sNotePlaybackTimer = 0; + sDisplayedNoteValue = 0xFF; + sPlaybackNotePos = 0; + sStaffPlaybackPos = 0; + while (sPlaybackSong->notes[sPlaybackNotePos].noteIdx == 0xFF) { + sPlaybackNotePos++; + } +} + +extern u8 sNotePlaybackVolume; +extern f32 sNormalizedNotePlaybackVolume; +extern u8 sNotePlaybackVibrato; +extern s8 sNotePlaybackTone; +extern f32 sNormalizedNotePlaybackTone; + +void Audio_OcaPlayback(void) { + s32 noteTimerStep; + s32 nextNoteTimerStep; + + if (sPlaybackState != 0) { + if (sStaffPlaybackPos == 0) { + noteTimerStep = 3; + } else { + noteTimerStep = D_8016BA04 - D_80130F68; + } + + if (noteTimerStep < sNotePlaybackTimer) { + sNotePlaybackTimer -= noteTimerStep; + } else { + nextNoteTimerStep = noteTimerStep - sNotePlaybackTimer; + sNotePlaybackTimer = 0; + } + + if (sNotePlaybackTimer == 0) { + + sNotePlaybackTimer = sPlaybackSong->notes[sPlaybackNotePos].unk_02; + + if (sPlaybackNotePos == 1) { + sNotePlaybackTimer++; + } + + if (sNotePlaybackTimer == 0) { + sPlaybackState--; + if (sPlaybackState != 0) { + sPlaybackNotePos = 0; + sStaffPlaybackPos = 0; + sDisplayedNoteValue = 0xFF; + } else { + Audio_StopSfx(NA_SE_OC_OCARINA); + } + return; + } else { + sNotePlaybackTimer -= nextNoteTimerStep; + } + + if (sNotePlaybackVolume != sPlaybackSong->notes[sPlaybackNotePos].volume) { + sNotePlaybackVolume = sPlaybackSong->notes[sPlaybackNotePos].volume; + sNormalizedNotePlaybackVolume = sNotePlaybackVolume / 127.0f; + } + + if (sNotePlaybackVibrato != sPlaybackSong->notes[sPlaybackNotePos].vibrato) { + sNotePlaybackVibrato = sPlaybackSong->notes[sPlaybackNotePos].vibrato; + Audio_QueueCmdS8(0x06020D06, sNotePlaybackVibrato); + } + + if (sNotePlaybackTone != sPlaybackSong->notes[sPlaybackNotePos].tone) { + sNotePlaybackTone = sPlaybackSong->notes[sPlaybackNotePos].tone; + sNormalizedNotePlaybackTone = Audio_OcaAdjStick(sNotePlaybackTone); + } + + if ((sPlaybackSong->notes[sPlaybackNotePos].volume == sPlaybackSong->notes[sPlaybackNotePos - 1].volume && + (sPlaybackSong->notes[sPlaybackNotePos].vibrato == + sPlaybackSong->notes[sPlaybackNotePos - 1].vibrato) && + (sPlaybackSong->notes[sPlaybackNotePos].tone == sPlaybackSong->notes[sPlaybackNotePos - 1].tone))) { + sDisplayedNoteValue = 0xFE; + } + + if (sDisplayedNoteValue != sPlaybackSong->notes[sPlaybackNotePos].noteIdx) { + u8 tmp = sPlaybackSong->notes[sPlaybackNotePos].noteIdx; + if (tmp == 0xA) { + sDisplayedNoteValue = tmp + sPlaybackSong->notes[sPlaybackNotePos].semitone; + } else { + sDisplayedNoteValue = tmp; + } + + if (sDisplayedNoteValue != 0xFF) { + sStaffPlaybackPos++; + Audio_QueueCmdS8(0x6020D07, D_80130F10 - 1); + Audio_QueueCmdS8(0x6020D05, sDisplayedNoteValue & 0x3F); + Audio_PlaySoundGeneral(NA_SE_OC_OCARINA, &D_801333D4, 4, &sNormalizedNotePlaybackTone, + &sNormalizedNotePlaybackVolume, &D_801333E8); + } else { + Audio_StopSfx(NA_SE_OC_OCARINA); + } + } + sPlaybackNotePos++; + } + } +} + +void func_800EDD68(u8 arg0) { + u16 i; + u16 i2; + u16 mad2; + u8 mad; + OcarinaNote* note; + u8 j; + u8 k; + s32 t; + OcarinaSong* song; + + if (D_80131858 == 1) { + song = gScarecrowCustomSongPtr; + } else { + song = D_80131BEC; + } + song->notes[sRecordSongPos].noteIdx = D_80131864; + song->notes[sRecordSongPos].unk_02 = D_8016BA04 - D_80131860; + song->notes[sRecordSongPos].volume = D_80131868; + song->notes[sRecordSongPos].vibrato = D_8013186C; + song->notes[sRecordSongPos].tone = D_80131870; + song->notes[sRecordSongPos].semitone = D_80131874 & 0xC0; + D_80131864 = sCurOcarinaBtnVal; + D_80131868 = D_80130F30; + D_8013186C = D_80130F34; + D_80131870 = D_80130F2C; + D_80131874 = sCurOcarinaBtnIdx; + sRecordSongPos++; + + if ((sRecordSongPos != 107) && (arg0 == 0)) { + return; + } + + i = sRecordSongPos; + mad = 0xFF; + while (i != 0 && mad == 0xFF) { + i--; + mad = song->notes[i].noteIdx; + } + + if (1) {} + + if (sRecordSongPos != (i + 1)) { + sRecordSongPos = i + 2; + song->notes[sRecordSongPos - 1].unk_02 = 0; + } + + song->notes[sRecordSongPos].unk_02 = 0; + + if (D_80131858 == 2) { + if (D_8016BA2E >= 8) { + for (i = 0; i < sRecordSongPos; i++) { + song->notes[i] = song->notes[i + 1]; + } + + func_800ECB7C(0xD); + + for (i = 0; i < 0xC; i++) { + for (j = 0; j < 9 - gOcarinaSongNotes[i].len; j++) { + for (k = 0; k < gOcarinaSongNotes[i].len && k + j < 8 && + gOcarinaSongNotes[i].notesIdx[k] == gOcarinaSongNotes[0xC].notesIdx[k + j]; + k++) + ; + + if (k == gOcarinaSongNotes[i].len) { + D_80131858 = 0xFF; + sOcarinaSongs[0xC].notes[1].volume = 0xFF; + return; + } + } + } + + i = 1; + while (i < 8) { + if (gOcarinaSongNotes[0xC].notesIdx[0] != gOcarinaSongNotes[0xC].notesIdx[i]) { + i = 9; + } else { + i++; + } + } + + if (i == 8) { + D_80131858 = 0xFF; + sOcarinaSongs[0xC].notes[1].volume = 0xFF; + return; + } + + for (i = 0; i < sRecordSongPos; i++) { + sOcarinaSongs[0xC].notes[i] = sOcarinaSongs[0xD].notes[i]; + } + + sOcarinaInpEnabled = 0; + } else { + sOcarinaSongs[0xC].notes[1].volume = 0xFF; + } + } + D_80131858 = 0; +} + +// start custom song? +/** + * arg0 = 1, start + * arg0 = 0, finish + * arg0 = 2, also start? + */ +void func_800EE170(u8 arg0) { + if ((u32)arg0 == D_80131858) { + return; + } + + if (arg0 != 0) { + D_80131860 = D_8016BA04; + D_80131864 = 0xFF; + D_80131868 = 0x57; + D_8013186C = 0; + D_80131870 = 0; + D_80131874 = 0; + sRecordSongPos = 0; + sOcarinaInpEnabled = 1; + D_8016BA2E = 0; + D_8016BAA0 = sPierresSong.notes[1]; + } else { + if (sRecordSongPos == 0) { + sPierresSong.notes[1] = D_8016BAA0; + } else { + if (D_80131858 == 2) { + D_8016BA2E = 1; + } + + func_800EDD68(1); + } + + sOcarinaInpEnabled = 0; + D_8016BA2E = 0; + } + + D_80131858 = arg0; +} + +void func_800EE29C(void) { + D_8016BA00.state = D_80131858; + D_8016BA00.pos = D_8016BA2E; + if (D_80131858 == 0xFF) { + D_80131858 = 0; + } +} + +void func_800EE2D4(void) { + D_8016B9F8.noteIdx = sCurOcarinaBtnIdx & 0x3F; + D_8016B9F8.state = func_800ECAF0(); + D_8016B9F8.pos = D_8016BA2E; +} + +void func_800EE318(void) { + if ((sDisplayedNoteValue & 0x3F) < 0x10) { + sDisplayedStaff.noteIdx = Audio_OcaMapNoteValue(sDisplayedNoteValue); + } + + sDisplayedStaff.state = sPlaybackState; + + if (sPlaybackSong != &sPierresSong) { + sDisplayedStaff.pos = sStaffPlaybackPos; + } else if (sStaffPlaybackPos == 0) { + sDisplayedStaff.pos = 0; + } else { + sDisplayedStaff.pos = ((sStaffPlaybackPos - 1) % 8) + 1; + } +} + +OcarinaStaff* func_800EE3C8(void) { + return &D_8016BA00; +} + +OcarinaStaff* func_800EE3D4(void) { + if (D_8016B9F8.state < 0xFE) { + D_80130F3C = 0; + } + return &D_8016B9F8; +} + +OcarinaStaff* Audio_OcaGetDisplayStaff(void) { + return &sDisplayedStaff; +} + +void func_800EE404(void) { + s32 noteChanged; + + if ((D_80131858 != 0) && ((D_8016BA04 - D_80131860) >= 3)) { + noteChanged = false; + if (D_80131864 != sCurOcarinaBtnVal) { + if (sCurOcarinaBtnVal != 0xFF) { + D_8016BA00.noteIdx = sCurOcarinaBtnIdx & 0x3F; + D_8016BA2E++; + } else if ((D_80131858 == 2) && (D_8016BA2E == 8)) { + func_800EDD68(1); + return; + } + + if (D_8016BA2E > 8) { + if (D_80131858 == 2) { + // notes played are over 8 and in recording mode. + func_800EDD68(1); + return; + } + D_8016BA2E = true; + } + + noteChanged = true; + } else if (D_80131868 != D_80130F30) { + noteChanged = true; + } else if (D_8013186C != D_80130F34) { + noteChanged = true; + } else if (D_80131870 != D_80130F2C) { + noteChanged = true; + } + + if (noteChanged) { + func_800EDD68(0); + D_80131860 = D_8016BA04; + } + } +} + +s32 func_800EE5EC(void); + +void func_800EE57C(u8 minigameIdx) { + u8 i; + + if (minigameIdx > 2) { + minigameIdx = 2; + } + + sOcaMinigameApndPos = 0; + sOcaMinigameEndPos = sOcaMinigameNoteCnts[minigameIdx]; + + for (i = 0; i < 3; i++) { + func_800EE5EC(); + } +} + +#define OCA_MEMORYGAME_IDX 0xD +s32 func_800EE5EC(void) { + u32 rnd; + u8 rndNote; + + if (sOcaMinigameApndPos == sOcaMinigameEndPos) { + return 1; + } + + rnd = Audio_NextRandom(); + rndNote = sOcarinaNoteValues[rnd % 5]; + + if (sOcarinaSongs[OCA_MEMORYGAME_IDX].notes[sOcaMinigameApndPos - 1].noteIdx == rndNote) { + rndNote = sOcarinaNoteValues[(rnd + 1) % 5]; + } + + sOcarinaSongs[OCA_MEMORYGAME_IDX].notes[sOcaMinigameApndPos].noteIdx = rndNote; + sOcarinaSongs[OCA_MEMORYGAME_IDX].notes[sOcaMinigameApndPos].unk_02 = 0x2D; + sOcarinaSongs[OCA_MEMORYGAME_IDX].notes[sOcaMinigameApndPos].volume = 0x50; + sOcarinaSongs[OCA_MEMORYGAME_IDX].notes[sOcaMinigameApndPos].vibrato = 0; + sOcarinaSongs[OCA_MEMORYGAME_IDX].notes[sOcaMinigameApndPos].tone = 0; + + sOcaMinigameApndPos++; + + sOcarinaSongs[OCA_MEMORYGAME_IDX].notes[sOcaMinigameApndPos].noteIdx = 0xFF; + sOcarinaSongs[OCA_MEMORYGAME_IDX].notes[sOcaMinigameApndPos].unk_02 = 0; + sOcarinaSongs[OCA_MEMORYGAME_IDX].notes[sOcaMinigameApndPos + 1].noteIdx = 0xFF; + sOcarinaSongs[OCA_MEMORYGAME_IDX].notes[sOcaMinigameApndPos + 1].unk_02 = 0; + if (1) {} + return 0; +} + +// input update? +void func_800EE6F4(void) { + D_8016BA04 = gAudioContext.totalTaskCnt; + if (D_80130F10 != 0) { + if (sOcarinaInpEnabled == 1) { + Audio_GetOcaInput(); + } + if ((sPlaybackState == 0) && (sOcarinaInpEnabled == 1)) { + func_800ED458(0); + } + if (D_80130F3C != 0) { + if (D_80130F3C & 0x4000) { + func_800ED200(); + } else { + func_800ECDF8(); + } + } + + Audio_OcaPlayback(); + D_80130F68 = D_8016BA04; + + if (sPlaybackState == 0) { + func_800EE404(); + } + + if ((D_80130F3C != 0) && (sPrevOcarinaNoteVal != sCurOcarinaBtnVal)) { + D_80131880 = 1; + } + + sPrevOcarinaNoteVal = sCurOcarinaBtnVal; + } + + func_800EE2D4(); + func_800EE318(); + func_800EE29C(); +} + +#ifdef NON_MATCHING +// matches, but data needs to be migrated. +void func_800EE824(void) { + static u8 D_80131C80 = 0; + static u8 D_80131C84 = 1; + static u16 D_80131C88 = 0x4B0; + + switch (D_80131C80) { + case 0: + if (D_80131C88-- == 0) { + if (D_80131C84 < 7) { + D_80131C80++; + } else { + D_80131C80 = 3; + func_800ED858(0); + } + D_80131C88 = 0x4B0; + } + break; + case 1: + func_800F7260(0); + func_800ED858(D_80131C84); + func_800ED93C(0xF, 1); + D_80131C84++; + D_80131C80++; + break; + case 2: + if (Audio_OcaGetDisplayStaff()->state == 0) { + D_80131C80 = 0; + } + break; + } +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE824.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE930.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE97C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EE9D0.s") - +#endif + +void func_800EE930(void) { + D_8016B9F8.noteIdx = 0xFF; + D_8016B9F8.state = 0xFF; + D_8016B9F8.pos = 0; + sDisplayedStaff.noteIdx = 0xFF; + sDisplayedStaff.state = 0; + sDisplayedStaff.pos = 0; + D_8016BA00.noteIdx = 0xFF; + D_8016BA00.state = 0xFF; + D_8016BA00.pos = 0; + D_80131880 = 0; +} + +// DebugAudio_GetOcaInput +void func_800EE97C(void) { + Input inputs[4]; + u32 btn; + + PadMgr_RequestPadData(&gPadMgr, &inputs, 0); + btn = inputs[3].cur.button; + D_8016BAB0 = btn & 0xFFFF; + sDebugPadPress = (btn ^ sDebugPadPressRaw) & btn; + sDebugPadPressRaw = btn; +} + +u8* func_800EE9D0(s32 arg0, u8 arg1) { + s32 temp_a1; + s32 temp_v1; + u8* temp_a3; + s32 phi_v0; + s32 phi_t0; + s32 phi_v1; + u8 i; + u32 flg = 1; + + for (i = 0; i < arg1; flg *= 2, i++) { + if (arg0 & flg) { + D_8016B9B8[arg1 - i - 1] = 0x31; + } else { + D_8016B9B8[arg1 - i - 1] = 0x30; + } + } + + D_8016B9B8[arg1] = 0; + return D_8016B9B8; +} + +extern char D_80131CAC[][0x17]; +extern char D_80131F54[][5]; +extern char D_80131E38[7][0xB]; +extern char D_80131E88[][0xA]; +extern u8 D_80131F68; + +// Debug Print #pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800EEA50.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F1BDC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F2150.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F227C.s") - +extern u16 D_80131E14; +void func_800F1BDC(void) { + u16 phi_t1 = 1; + + if (D_8016BAB0 & 4) { + if (D_80131E20[D_80131CA4] >= 0x10) { + phi_t1 = 0x10; + } + } else if (D_8016BAB0 & 2) { + if (D_80131E20[D_80131CA4] >= 0x10) { + phi_t1 = 8; + } + } else { + if (D_8016BAB0 & 8) { + D_80131E08[D_80131CA4] = 0; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DUP)) { + if (D_80131CA4 > 0) { + D_80131CA4--; + } else { + D_80131CA4 = 0xA; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DDOWN)) { + if (D_80131CA4 < 0xA) { + D_80131CA4++; + } else { + D_80131CA4 = 0; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DLEFT)) { + if (D_80131E08[D_80131CA4] >= phi_t1) { + if (1) { + D_80131E08[D_80131CA4] -= phi_t1; + } + } else { + D_80131E08[D_80131CA4] += D_80131E20[D_80131CA4] - phi_t1; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DRIGHT)) { + if (D_80131E08[D_80131CA4] + phi_t1 < D_80131E20[D_80131CA4]) { + D_80131E08[D_80131CA4] += phi_t1; + } else { + D_80131E08[D_80131CA4] += phi_t1 - D_80131E20[D_80131CA4]; + } + } + + if (D_80131CA4 == 8) { + if (D_80131E08[D_80131CA4] != 0) { + func_800F6828(0x20); + } else { + func_800F6828(0); + } + } + + if (D_80131CA4 == 9) { + if (D_80131E08[D_80131CA4] != 0) { + func_800F67A0(0x20); + } else { + func_800F67A0(0); + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_A)) { + switch (D_80131CA4) { + case 0: + case 1: + Audio_StartSeq(D_80131CA4, 0, D_80131E08[D_80131CA4]); + break; + case 2: + case 3: + Audio_PlaySoundGeneral(((D_80131E08[2] << 0xC) & 0xFFFF) + D_80131E08[3] + SFX_FLAG, &D_801333D4, 4, + &D_801333E0, &D_801333E0, &D_801333E8); + break; + case 4: + func_800F6700(D_80131E08[D_80131CA4]); + break; + case 5: + Audio_SeqCmdE01(0, D_80131E08[D_80131CA4]); + break; + case 6: + Audio_SeqCmdF(0, D_80131E08[D_80131CA4]); + D_80131EFC = D_80131E14; + if (gAudioSessionPresets[D_80131EFC].numSequencePlayers - 1 < D_80131F28) { + D_80131F28 = gAudioSessionPresets[D_80131EFC].numSequencePlayers - 1; + } + break; + case 7: + func_800F6FB4(D_80131E08[D_80131CA4]); + break; + case 8: + case 9: + break; + case 10: + func_800F7260(D_80131E08[D_80131CA4] * 127); + break; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_B)) { + switch (D_80131CA4) { + case 0: + case 1: + Audio_SeqCmd1(D_80131CA4, 0); + break; + case 7: + Audio_SeqCmd1(0, 0); + break; + case 2: + case 3: + func_800F87A0(D_80131E08[2]); + break; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_CDOWN)) { + if (D_80131CA4 == 0) { + if (1) {} + func_800F595C(D_80131E08[D_80131CA4]); + } + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_CRIGHT)) { + if (D_80131CA4 == 0) { + if (1) {} + func_800F5ACC(D_80131E08[D_80131CA4]); + } + } +} + +void func_800F2150(void) { + if (CHECK_BTN_ANY(sDebugPadPress, BTN_CUP)) { + D_80131EC0--; + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_CDOWN)) { + D_80131EC0++; + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_CLEFT)) { + D_80131EBC--; + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_CRIGHT)) { + D_80131EBC++; + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_B)) { + D_80131EBC = 0; + D_80131EC0 = 0; + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DUP) && D_80131EC4 > 0) { + D_80131EC4--; + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DDOWN) && D_80131EC4 < 6) { + D_80131EC4++; + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DLEFT) && D_80131EC8[D_80131EC4] > 0) { + D_80131EC8[D_80131EC4]--; + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DRIGHT) && D_80131EC8[D_80131EC4] < 4) { + D_80131EC8[D_80131EC4]++; + } +} + +extern u8 D_80131ED0; +extern u8 D_80131ED4; +extern u8 D_80131ED8; +extern s8 D_80131EDC; +extern s8 D_80131EE0; +extern u8 D_80131EE4[]; +extern u8 D_80131EF0[]; +extern u8 D_801333F0; + +void func_800F227C(void) { + + if (D_80131EE4[0] != 0) { + if (CHECK_BTN_ANY(sDebugPadPress, BTN_CUP)) { + D_80131EE0--; + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_CDOWN)) { + D_80131EE0++; + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_CLEFT)) { + D_80131EDC--; + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_CRIGHT)) { + D_80131EDC++; + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_A)) { + D_80131EDC = 0x1A; + D_80131EE0 = 1; + D_80131EE4[2] = 6; + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_B)) { + D_80131ED4 = 0; + D_80131ED8 = 0; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DUP)) { + if (D_80131ED0 > 0) { + D_80131ED0--; + } else { + D_80131ED0 = 10; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DDOWN)) { + if (D_80131ED0 < 0xA) { + D_80131ED0++; + } else { + D_80131ED0 = 0; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DLEFT)) { + if (D_80131EE4[D_80131ED0] > 0) { + D_80131EE4[D_80131ED0]--; + } else { + D_80131EE4[D_80131ED0] = D_80131EF0[D_80131ED0] - 1; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DRIGHT)) { + if (D_80131EE4[D_80131ED0] < D_80131EF0[D_80131ED0] - 1) { + D_80131EE4[D_80131ED0]++; + } else { + D_80131EE4[D_80131ED0] = 0; + } + } + + D_801333F0 = D_80131EE4[3] + (D_80131EE4[4] * 2) + (D_80131EE4[5] * 4) + (D_80131EE4[6] * 8) + + (D_80131EE4[7] * 0x10) + (D_80131EE4[8] * 32); +} + +extern u8 D_80131F00; +extern u8 D_80131F04; +extern u8 D_80131F08; +extern u16 D_8016E2E0[]; +extern u16 D_8016E2F8[]; +extern u8 D_801333F4; +extern u8 D_8016E310[]; +#ifdef NON_MATCHING +void func_800F2464(void) { + s16 phi_t1; + u16 new_var; + u8 phi_v1; + + if (D_80131F00 == 0) { + if ((sDebugPadPress & 0x800) != 0) { + if (D_80131F04 > 0) { + D_80131F04--; + } else { + D_80131F04 = 9; + } + } + if ((sDebugPadPress & 0x400) != 0) { + if (D_80131F04 < 9) { + D_80131F04++; + } else { + D_80131F04 = 0; + } + } + + phi_v1 = 9; + phi_t1 = phi_t1; + if ((sDebugPadPress & 0x8000) != 0) { + D_80131F00 = 1; + } + + if ((sDebugPadPress & 0x4000) != 0) { + D_8016E2E0[D_80131F04] = 0; + D_8016E2F8[D_80131F04] = 0; + } + if ((sDebugPadPress & 0x1000) != 0) { + phi_v1 = D_80131F04; + if (phi_v1 != 0) { + phi_v1--; + } else { + phi_v1 = 9; + } + D_8016E2E0[D_80131F04] = D_8016E2E0[phi_v1]; + if (!D_80131F08) + ; + D_8016E2F8[D_80131F04] = D_8016E2F8[phi_v1]; + } + } else { + if ((sDebugPadPress & 0x200) != 0) { + if (D_80131F08 > 0) { + D_80131F08--; + } else { + D_80131F08 = 7; + } + } + if ((sDebugPadPress & 0x100) != 0) { + if (D_80131F08 < 7) { + D_80131F08++; + } else { + D_80131F08 = 0; + } + } + + if (((sDebugPadPress & 0x800) != 0) || ((sDebugPadPress & 0x400) != 0)) { + if ((sDebugPadPress & 0x800) != 0) { + phi_t1 = (D_8016BAB0 & 8) != 0 ? 8 : 1; + } + + if ((sDebugPadPress & 0x400) != 0) { + phi_t1 = (D_8016BAB0 & 8) != 0 ? -8 : -1; + } + + if (D_80131F08 < 4) { + new_var = (u16)(((D_8016E2E0[D_80131F04] >> (((-D_80131F08) * 4) + 0xC)) + phi_t1) & 0xF); + D_8016E2E0[D_80131F04] = + (u16)((D_8016E2E0[D_80131F04] & ((0xF << (((-D_80131F08) * 4) + 0xC)) ^ 0xFFFF)) + + (new_var << (((-D_80131F08) * 4) + 0xC))); + } else { + new_var = (u16)(((D_8016E2F8[D_80131F04] >> (((-D_80131F08) * 4) + 0x1C)) + phi_t1) & 0xF); + D_8016E2F8[D_80131F04] = + (u16)((D_8016E2F8[D_80131F04] & ((0xF << (((-D_80131F08) * 4) + 0x1C)) ^ 0xFFFF)) + + (new_var << (((-D_80131F08) * 4) + 0x1C))); + } + } + + if ((sDebugPadPress & 0x8000) != 0) { + D_80131F00 = 0; + } + + if ((sDebugPadPress & 0x4000) != 0) { + if (D_80131F08 < 4) { + D_8016E2E0[D_80131F04] = 0; + } else { + D_8016E2F8[D_80131F04] = 0; + } + } + } + if ((sDebugPadPress & 2) != 0) { + D_801333F4 ^= 1; + } + if ((sDebugPadPress & 4) != 0) { + D_8016E310[D_80131F04] ^= 1; + } +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F2464.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F27A0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F28AC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F28B4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F29FC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F2A04.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F2D6C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F2E28.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F3054.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F3138.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F3140.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F314C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F3188.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F32F0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F3468.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F35EC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F37B8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F3990.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F3A08.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F3ED4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F3F3C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F3F84.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4010.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4138.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4190.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F41E0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4254.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F436C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4414.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F44EC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4524.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4578.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F45D0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4634.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F46E0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4784.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F47BC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F47FC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F483C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4870.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F491C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4A54.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4A70.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4B58.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4BE8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4BF4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4C58.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F4E30.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F50CC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F50EC.s") - +#endif + +void func_800F27A0(void) { + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DDOWN)) { + if (D_80131F28 != 0) { + D_80131F28--; + } else { + D_80131F28 = gAudioSessionPresets[D_80131EFC].numSequencePlayers - 1; + } + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DUP)) { + if (D_80131F28 < gAudioSessionPresets[D_80131EFC].numSequencePlayers - 1) { + D_80131F28++; + } else { + D_80131F28 = 0; + } + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DLEFT)) { + D_80131F2C = (D_80131F2C - 1) & 0xF; + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DRIGHT)) { + D_80131F2C = (D_80131F2C + 1) & 0xF; + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_START)) { + D_80131F30[D_80131F28] = 0; + } +} + +void func_800F28AC(void) { +} + +void func_800F28B4(void) { + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DUP)) { + if (D_80131F50 > 0) { + D_80131F50--; + } else { + D_80131F50 = 1; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DDOWN)) { + if (D_80131F50 <= 0) { + D_80131F50++; + } else { + D_80131F50 = 0; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DLEFT)) { + D_80131F4C[D_80131F50]--; + if (D_80131F50 == 1) { + func_800F5E90(D_80131F4C[1]); + ; // might be a fake match? + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DRIGHT)) { + D_80131F4C[D_80131F50]++; + if (D_80131F50 == 1) { + func_800F5E90(D_80131F4C[1]); + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_A)) { + Audio_QueueCmdS8(MK_CMD(0x46, 0x00, 0x00, 0x00), D_80131F4C[1]); + Audio_QueueSeqCmd(D_80131F4C[0] | 0x10000); + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_B)) { + Audio_QueueSeqCmd(0x100100FF); + } +} + +void func_800F29FC(void) { +} + +extern u8 D_80131F18; +extern u16 D_80131F20[]; + +extern u16 D_80131E24; +extern u8 D_80131F1C; + +void func_800F2A04(void) { + s32 phi_a2; + u16 sfx; + + if (D_8016BAB0 & 2) { + phi_a2 = 8; + } else { + phi_a2 = 1; + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DUP)) { + if (D_80131F18 > 0) { + D_80131F18--; + } else { + D_80131F18 = 3; + } + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DDOWN)) { + if (D_80131F18 < 3) { + D_80131F18++; + } else { + D_80131F18 = 0; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DLEFT)) { + if (D_80131F18 < 2) { + if (D_80131F18 == 0) { + if (D_80131F20[D_80131F18] > 0) { + D_80131F20[D_80131F18]--; + } else { + D_80131F20[D_80131F18] = D_80131E24 - 1; + } + } else { + D_80131F20[D_80131F18] -= phi_a2; + D_80131F20[D_80131F18] &= 0x1FF; + } + } else if (D_80131F18 == 3) { + D_8013331C[D_80131F20[0]][D_80131F20[1]].unk_0 -= phi_a2; + } else { + D_80131F1C = (D_80131F1C - 1) & 0xF; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_DRIGHT)) { + if (D_80131F18 < 2) { + if (D_80131F18 == 0) { + if (D_80131F20[D_80131F18] < (D_80131E24 - 1)) { + D_80131F20[D_80131F18]++; + } else { + D_80131F20[D_80131F18] = 0; + } + } else { + D_80131F20[D_80131F18] += phi_a2; + D_80131F20[D_80131F18] &= 0x1FF; + } + } else if (D_80131F18 == 3) { + D_8013331C[D_80131F20[0]][D_80131F20[1]].unk_0 += phi_a2; + } else { + D_80131F1C = (D_80131F1C + 1) & 0xF; + } + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_A)) { + sfx = (u16)(D_80131F20[0] << 0xC) + D_80131F20[1] + SFX_FLAG; + Audio_PlaySoundGeneral(sfx, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_B)) { + func_800F87A0(D_80131F20[0]); + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_CDOWN)) { + if (D_80131F18 == 2) { + D_8013331C[D_80131F20[0]][D_80131F20[1]].unk_2 ^= (1 << (0xF - D_80131F1C)); + } + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_CUP)) { + if (D_80131F18 < 2) { + D_80131F20[D_80131F18] = 0; + } + } +} + +void func_800F2D6C(s8* arg0, u16 arg1) { + u8 i = 0; + + D_8016B7E8[D_80131ED4].unk_06 = arg1; + + while (arg0[i] != 0) { + D_8016B7E8[D_80131ED4].unk_00[i] = arg0[i]; + i++; + } + + while (i < 5) { + D_8016B7E8[D_80131ED4].unk_00[i] = 0; + i++; + } + + if (D_80131ED4 < 0x18) { + D_80131ED4++; + } else { + D_80131ED4 = 0; + D_80131ED8 = 1; + } +} + +void func_800F1BDC(void); +void func_800F2150(void); +void func_800F227C(void); +void func_800F2464(void); +void func_800F27A0(void); +void func_800F28AC(void); +void func_800F2A04(void); + +void func_800F2E28(void) { + if (D_80131C98 != 0) { + if (D_80131C9C != 0) { + func_800F7260(0x6F); + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_L)) { + // goto next page. + if (D_80131CA0 < 0xE) { + D_80131CA0++; + } else { + D_80131CA0 = 0; + } + } + if (CHECK_BTN_ANY(sDebugPadPress, BTN_R)) { + // goto previous page + if (D_80131CA0 > 0) { + D_80131CA0--; + } else { + D_80131CA0 = 0xE; + } + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_Z)) { + // change text color + D_80131CA8 = (u32)(++D_80131CA8) % 8; + } + + switch (D_80131CA0) { + case 0: + if (CHECK_BTN_ANY(sDebugPadPress, BTN_A)) { + D_80131E08[5] ^= 0x1; + Audio_SeqCmdE01(0, D_80131E08[5]); + if (func_800FA0B4(0) != 1) { + Audio_SeqCmd1(0, 0); + } + Audio_SeqCmd1(1, 0); + Audio_SeqCmd1(3, 0); + } + + if (CHECK_BTN_ANY(sDebugPadPress, BTN_B)) { + D_80131C9C ^= 0x1; + if (D_80131C9C == 0) { + func_800F7260(0); + } + } + break; + case 1: + func_800F1BDC(); + break; + case 7: + func_800F2150(); + break; + case 13: + func_800F227C(); + break; + case 8: + func_800F2464(); + break; + case 5: + func_800F27A0(); + break; + case 3: + func_800F28AC(); + break; + case 9: + func_800F28B4(); + break; + case 11: + func_800F29FC(); + break; + case 12: + func_800F2A04(); + break; + case 14: + default: + break; + } + + D_8013340C = D_80131EEE; + } +} + +void func_800F50CC(void); +void func_800F4A70(void); +void func_800F5CF8(void); + +void func_800F30534(void) { + if (func_800FAD34() == 0) { + sAudioUpdateTaskStart = gAudioContext.totalTaskCnt; + sAudioUpdateStartTime = osGetTime(); + func_800EE6F4(); + func_800F4784(&D_8016B7B8); + func_800F4784(&D_8016B7C8); + func_800F4A70(); + func_800F56A8(); + func_800F5CF8(); + if (D_80133414 == 7) { + func_800F50CC(); + } + func_800F8E3C(); + Audio_ProcessSeqCmds(); + func_800F8F88(); + func_800FA3DC(); + func_800EE97C(); + func_800F2E28(); + Audio_ScheduleProcessCmds(); + sAudioUpdateTaskEnd = gAudioContext.totalTaskCnt; + sAudioUpdateEndTime = osGetTime(); + } +} + +void func_800F3138(UNK_TYPE arg0) { +} + +void func_800F3140(UNK_TYPE arg0, UNK_TYPE arg1) { +} + +void func_800F314C(s8 arg0) { + Audio_QueueCmdS32(0x82000000 | (((u8)arg0 & 0xFF) << 8), 1); +} + +f32 func_800F3188(u8 bankIdx, u8 entryIdx) { + SoundBankEntry* bankEntry; + f32 temp_f14; + f32 temp_f2; + f32 phi_f0; + f32 ret; + + bankEntry = &gSoundBanks[bankIdx][entryIdx]; + if (bankEntry->unk_26 & 0x2000) { + return 1.0f; + } + + if (bankEntry->unk_1C > 10000.0f) { + ret = 0.0f; + } else { + switch (bankEntry->unk_26 & 3) { + case 1: + phi_f0 = 666.6667f; + break; + case 2: + phi_f0 = 952.381f; + break; + case 3: + phi_f0 = 3846.154f; + break; + default: + phi_f0 = 500.0f; + break; + } + + temp_f14 = phi_f0 / 5.0f; + + if (bankEntry->unk_1C < temp_f14) { + ret = 1.0f; + } else if (bankEntry->unk_1C < phi_f0) { + ret = ((((phi_f0 - temp_f14) - (bankEntry->unk_1C - temp_f14)) / (phi_f0 - temp_f14)) * 0.19f) + 0.81f; + } else { + ret = (1.0f - ((bankEntry->unk_1C - phi_f0) / (10000.0f - phi_f0))) * 0.81f; + } + ret = SQ(ret); + } + + return ret; +} + +s8 func_800F32F0(u8 arg0, u8 arg1, u8 arg2) { + SoundBankEntry* temp_a3; + SequenceChannel* temp_a1; + s32 phi_a1; + s8 phi_v0 = 0; + s32 phi_v1 = 0; + SequenceChannel* none = &gAudioContext.sequenceChannelNone; + + temp_a3 = &gSoundBanks[arg0][arg1]; + if (!(temp_a3->unk_26 & 0x1000)) { + if (temp_a3->unk_1C < 2500.0f) { + phi_v0 = *temp_a3->posZ > 0.0f ? (temp_a3->unk_1C / 2500.0f) * 70.0f : (temp_a3->unk_1C / 2500.0f) * 91.0f; + } else { + phi_v0 = 0x46; + } + } + + temp_a1 = gAudioContext.seqPlayers[2].channels[arg2]; + if (none != temp_a1) { + phi_v1 = temp_a1->soundScriptIO[1]; + if (temp_a1->soundScriptIO[1] < 0) { + phi_v1 = 0; + } + } + + phi_a1 = *temp_a3->unk_18 + phi_v0 + phi_v1; + if ((arg0 != 5) || !((temp_a3->unk_28 & 0x1FF) < 2)) { + phi_a1 += D_80130614 + D_80130618 + D_80130610; + } + + if (phi_a1 >= 0x80) { + phi_a1 = 0x7F; + } + + return phi_a1; +} + +s8 func_800F3468(f32 arg0, f32 arg1, u8 arg2) { + f32 temp_f14; + f32 temp_f2; + f32 phi_f12; + f32 phi_f2; + f32 phi_f2_2; + f32 phi_f12_2; + f32 phi_f0; + f32 phi_f0_2; + + if (arg0 < 0) { + phi_f12 = -arg0; + } else { + phi_f12 = arg0; + } + if (arg1 < 0) { + phi_f2 = -arg1; + } else { + phi_f2 = arg1; + } + + if (phi_f12 > 8000.0f) { + phi_f12 = 8000.0f; + } + + if (phi_f2 > 8000.0f) { + phi_f2 = 8000.0f; + } + + if ((arg0 == 0.0f) && (arg1 == 0.0f)) { + phi_f0 = 0.5f; + } else if (phi_f2 <= phi_f12) { + phi_f0 = (16000.0f - phi_f12) / (3.3f * (16000.0f - phi_f2)); + if (arg0 >= 0.0f) { + phi_f0 = 1.0f - phi_f0; + } + } else { + phi_f0 = (arg0 / (5.0769234f * phi_f2)) + 0.5f; + } + + if (phi_f2 < 50.0f) { + if (phi_f12 < 50.0f) { + phi_f0 = ((phi_f0 - 0.5f) * SQ(phi_f12 / 50.0f)) + 0.5f; + } + } + return (phi_f0 * 127.0f) + 0.5f; +} + +f32 func_800F35EC(u8 bankIdx, u8 entryIdx) { + s32 phi_v0 = 0; + SoundBankEntry* entry = &gSoundBanks[bankIdx][entryIdx]; + f32 unk1C; + f32 freq = 1.0f; + + if (entry->unk_26 & 0x4000) { + freq = 1.0f - ((gAudioContext.audioRandom & 0xF) / 192.0f); + } + + switch (bankIdx) { + case BANK_PLAYER: + case BANK_ITEM: + case BANK_VOICE: + if (D_80130644 != 0) { + phi_v0 = 1; + } + break; + case BANK_ENV: + case BANK_ENEMY: + if (D_80130648 != 0) { + phi_v0 = 1; + } + break; + case BANK_SYSTEM: + case BANK_OCARINA: + break; + } + + if (phi_v0 == 1) { + if (!(entry->unk_26 & 0x800)) { + freq *= (1.0293 - ((gAudioContext.audioRandom & 0xF) / 144.0f)); + } + } + + unk1C = entry->unk_1C; + if (!(entry->unk_26 & 0x2000)) { + if (!(entry->unk_26 & 0x8000)) { + if (unk1C >= 10000.0f) { + freq += 0.2f; + } else { + freq += (0.2f * (unk1C / 10000.0f)); + } + } + } + + if (entry->unk_26 & 0xC0) { + freq += (entry->unk_2F / 192.0f); + } + + return freq; +} + +u8 func_800F37B8(f32 arg0, SoundBankEntry* arg1, s8 arg2) { + s8 phi_v0; + u8 phi_v1; + f32 phi_f0; + f32 phi_f12; + + if (*arg1->posZ < arg0) { + phi_v0 = arg2 < 0x41 ? arg2 : 0x7F - arg2; + + if (phi_v0 < 0x1E) { + phi_v1 = 0; + } else { + phi_v1 = (((phi_v0 & 0xFFFF) * 0xA) - 0x12C) / 0x22; + if (phi_v1 != 0) { + phi_v1 = 0x10 - phi_v1; + } + } + } else { + phi_v1 = 0; + } + + if (phi_v1 == 0) { + if (arg1->unk_26 & 0x200) { + phi_v1 = 0xF; + } + } + + switch (arg1->unk_26 & 3) { + case 1: + phi_f0 = 12.0f; + break; + case 2: + phi_f0 = 9.0f; + break; + case 3: + phi_f0 = 6.0f; + break; + default: + phi_f0 = 15.0f; + break; + } + + if (arg1->unk_1C > 1923.077f) { + phi_f12 = 1923.077f; + } else { + phi_f12 = arg1->unk_1C; + } + + return (phi_v1 * 0x10) + (u8)((phi_f0 * phi_f12) / 1923.077f); +} + +s8 func_800F3990(f32 arg0, u16 arg1) { + s8 ret = 0; + + if (arg0 >= 0.0f) { + if (arg0 > 625.0f) { + ret = 0x7F; + } else { + ret = (arg0 / 625.0f) * 126.0f; + } + } + return ret | 1; +} + +extern f32 D_801305C4[]; +void func_800F3A08(u8 bankIdx, u8 entryIdx, u8 channelIdx) { + f32 sp44; + s8 phi_a1; + s8 sp42; + f32 sp3C; + s8 sp3B; + u8 sp3A; + u8 sp39; + s8 sp38; + f32 sp34; + u8 sp33; + SoundBankEntry* temp_a3; + + sp42 = 0; + sp3B = 0x40; + sp3A = 0; + sp39 = 0; + sp38 = 0; + sp33 = 0; + sp3C = 1.0f; + sp44 = 1.0f; + temp_a3 = &gSoundBanks[bankIdx][entryIdx]; + switch (bankIdx) { + case BANK_PLAYER: + case BANK_ITEM: + case BANK_ENV: + case BANK_ENEMY: + case BANK_VOICE: + if (D_80130604 == 2) { + sp38 = func_800F3990(*temp_a3->posY, temp_a3->unk_26); + } + case BANK_OCARINA: + temp_a3->unk_1C = sqrtf(temp_a3->unk_1C); + sp44 = func_800F3188(bankIdx, entryIdx) * *temp_a3->unk_14; + sp42 = func_800F32F0(bankIdx, entryIdx, channelIdx); + sp3B = func_800F3468(*temp_a3->posX, *temp_a3->posZ, temp_a3->unk_C); + sp3C = func_800F35EC(bankIdx, entryIdx) * *temp_a3->unk_10; + if (D_80130604 == 2) { + sp34 = D_801305C4[(temp_a3->unk_26 & 0x400) >> 0xA]; + if (!(temp_a3->unk_26 & 0x800)) { + if (*temp_a3->posZ < sp34) { + sp3A = 0x10; + } + + if ((D_8016B8B8[channelIdx].unk_0A ^ sp3A) & 0x10) { + if (sp3B < 0x40) { + sp3A = D_8016B8B8[channelIdx].unk_0A ^ 0x14; + } else { + sp3A = D_8016B8B8[channelIdx].unk_0A ^ 0x18; + } + } else { + sp3A = D_8016B8B8[channelIdx].unk_0A; + } + } + } + if (D_8013063C != 0) { + if ((bankIdx == 1) || (bankIdx == 0) || (bankIdx == 6)) { + sp33 = D_8013063C; + } + } + + if ((sp33 | D_80130640) != 0) { + sp39 = (sp33 | D_80130640); + } else if (D_80130604 != 2) { + } else if (temp_a3->unk_26 & 0x2000) { + } else { + sp39 = func_800F37B8(sp34, temp_a3, sp3B); + } + break; + case BANK_SYSTEM: + break; + } + + if (D_8016B8B8[channelIdx].unk_00 != sp44) { + phi_a1 = (u8)(sp44 * 127.0f); + D_8016B8B8[channelIdx].unk_00 = sp44; + } else { + phi_a1 = -1; + } + + Audio_QueueCmdS8(0x6020000 | (channelIdx << 8) | 2, phi_a1); + if (sp42 != D_8016B8B8[channelIdx].unk_08) { + Audio_QueueCmdS8(0x5020000 | (channelIdx << 8), sp42); + D_8016B8B8[channelIdx].unk_08 = sp42; + } + if (sp3C != D_8016B8B8[channelIdx].unk_04) { + Audio_QueueCmdF32(0x4020000 | (channelIdx << 8), sp3C); + D_8016B8B8[channelIdx].unk_04 = sp3C; + } + if (sp3A != D_8016B8B8[channelIdx].unk_0A) { + Audio_QueueCmdS8(0xE020000 | (channelIdx << 8), sp3A | 0x10); + D_8016B8B8[channelIdx].unk_0A = sp3A; + } + if (sp39 != D_8016B8B8[channelIdx].unk_0B) { + Audio_QueueCmdS8(0x6020000 | (channelIdx << 8) | 3, sp39); + D_8016B8B8[channelIdx].unk_0B = sp39; + } + if (sp38 != D_8016B8B8[channelIdx].unk_0C) { + Audio_QueueCmdS8(0xC020000 | (channelIdx << 8), 0x10); + Audio_QueueCmdU16(0xD020000 | (channelIdx << 8), ((u16)(sp38) << 8) + 0xFF); + D_8016B8B8[channelIdx].unk_0C = sp38; + } + if (sp3B != D_8016B8B8[channelIdx].unk_09) { + Audio_QueueCmdS8(0x3020000 | (channelIdx << 8), sp3B); + D_8016B8B8[channelIdx].unk_09 = sp3B; + } +} + +void func_800F3ED4(void) { + u8 i; + unk_s1* t; + + for (i = 0; i < 16; i++) { + t = &D_8016B8B8[i]; + t->unk_00 = 1.0f; + t->unk_04 = 1.0f; + t->unk_08 = 0; + t->unk_09 = 0x40; + t->unk_0A = 0; + t->unk_0B = 0xFF; + t->unk_0C = 0xFF; + } + + D_8016B8B8[0xD].unk_0C = 0; + D_8013061C = 0; + D_80130618 = 0; +} + +void func_800F3F3C(u8 arg0) { + if (D_8016E264[0] != 1) { + Audio_StartSeq(3, 0, 0x6D); + Audio_SeqCmd8(3, 0, 0, arg0); + } +} + +f32 func_800F3F84(f32 arg0) { + f32 ret = 1.0f; + + if (arg0 > 6.0f) { + D_8016B7A8 = 1.0f; + D_8016B7B0 = 1.1f; + } else { + ret = arg0 / 6.0f; + D_8016B7A8 = (ret * 0.22500002f) + 0.775f; + D_8016B7B0 = (ret * 0.2f) + 0.9f; + } + return ret; +} + +void func_800F4010(Vec3f* arg0, u16 arg1, f32 arg2) { + f32 sp24; + f32 phi_f0; + u8 phi_v0; + u16 phi_a0; + + D_80131C8C = arg2; + sp24 = func_800F3F84(arg2); + Audio_PlaySoundGeneral(arg1, arg0, 4, &D_8016B7B0, &D_8016B7A8, &D_801333E8); + + if ((arg1 & 0xF0) == 0xB0) { + phi_f0 = 0.3f; + phi_v0 = 1; + sp24 = 1.0f; + } else { + phi_f0 = 1.1f; + phi_v0 = gAudioContext.audioRandom % 2; + } + + if ((phi_f0 < arg2) && (phi_v0 != 0)) { + if ((arg1 & 0x80) != 0) { + phi_a0 = 0x867; + } else { + phi_a0 = 0x866; + } + D_8016B7AC = (sp24 * 0.7) + 0.3; + Audio_PlaySoundGeneral(phi_a0, arg0, 4U, &D_8016B7B0, &D_8016B7AC, &D_801333E8); + } +} + +void func_800F4138(Vec3f* pos, u16 sfxId, f32 arg2) { + func_800F3F84(arg2); + Audio_PlaySoundGeneral(sfxId, pos, 4U, &D_8016B7B0, &D_8016B7A8, &D_801333E8); +} + +void func_800F4190(Vec3f* pos, u16 sfxId) { + Audio_PlaySoundGeneral(sfxId, pos, 4, &D_801305B0, &D_801333E0, &D_801305B4); +} +void func_800F41E0(Vec3f* pos, u16 baseSfx, u8 arg2) { + u8 offset = Audio_NextRandom() % arg2; + Audio_PlaySoundGeneral(baseSfx + offset, pos, 4, &D_801333E0, &D_801333E0, &D_801333E8); +} + +void func_800F4254(Vec3f* pos, u8 level) { + level &= 3; + if (level != sPrevChargeLevel) { + D_801305F4 = D_801305E4[level]; + switch (level) { + case 1: + Audio_PlaySoundGeneral(NA_SE_PL_SWORD_CHARGE, pos, 4, &D_801305F4, &D_801333E0, &D_801333E8); + break; + case 2: + Audio_PlaySoundGeneral(NA_SE_PL_SWORD_CHARGE, pos, 4, &D_801305F4, &D_801333E0, &D_801333E8); + break; + } + + sPrevChargeLevel = level; + } + + if (level != 0) { + Audio_PlaySoundGeneral(NA_SE_IT_SWORD_CHARGE - SFX_FLAG, pos, 4, &D_801305F4, &D_801333E0, &D_801333E8); + } +} + +void func_800F436C(Vec3f* pos, u16 sfxId, f32 arg2) { + if (arg2 < 0.75f) { + D_8016B7D8 = ((arg2 / 0.75f) * 0.25f) + 0.5f; + } else { + D_8016B7D8 = arg2; + } + + if (D_8016B7D8 > 0.5f) { + Audio_PlaySoundGeneral(sfxId, pos, 4, &D_8016B7D8, &D_801333E0, &D_801333E8); + } +} + +void func_800F4414(Vec3f* pos, u16 sfxId, f32 arg2) { + D_801305B8--; + if (D_801305B8 == 0) { + Audio_PlaySoundGeneral(sfxId, pos, 4, &D_8016B7D8, &D_801333E0, &D_801333E8); + + if (arg2 > 2.0f) { + arg2 = 2.0f; + } + D_801305B8 = (s8)((D_801305C0 - D_801305BC) * (1.0f - arg2)) + D_801305C0; + } +} + +void func_800F44EC(s8 arg0, s8 arg1) { + D_801305B8 = 1; + D_801305BC = arg1; + D_801305C0 = arg0; +} + +void func_800F4524(Vec3f* arg0, u16 arg1, s8 arg2) { + D_8016B7DC = arg2; + Audio_PlaySoundGeneral(arg1, arg0, 4, &D_801333E0, &D_801333E0, &D_8016B7DC); +} + +void func_800F4578(Vec3f* arg0, u16 arg1, f32 arg2) { + D_8016B7E0 = arg2; + Audio_PlaySoundGeneral(arg1, arg0, 4, &D_801333E0, &D_8016B7E0, &D_801333E8); +} + +void func_800F45D0(f32 arg0) { + func_800F4414(&D_801333D4, NA_SE_IT_FISHING_REEL_SLOW - SFX_FLAG, arg0); + func_800F436C(&D_801333D4, 0, (0.15f * arg0) + 1.4f); +} + +void func_800F4634(Vec3f* pos, f32 arg1) { + if (func_800F8FF4(0x2006) == 0) { + D_8016B7B8.unk_00 = arg1; + } else if (arg1 != D_8016B7B8.unk_00) { + D_8016B7B8.unk_04 = arg1; + D_8016B7B8.unk_0C = 0x28; + D_8016B7B8.unk_08 = (D_8016B7B8.unk_04 - D_8016B7B8.unk_00) / 40.0f; + } + Audio_PlaySoundGeneral(0x2006, pos, 4, &D_8016B7B8, &D_801333E0, &D_801333E8); +} + +void func_800F46E0(Vec3f* pos, f32 arg0) { + if (func_800F8FF4(0x2007) == 0) { + D_8016B7C8.unk_00 = arg0; + } else if (arg0 != D_8016B7C8.unk_00) { + D_8016B7C8.unk_04 = arg0; + D_8016B7C8.unk_0C = 0x28; + D_8016B7C8.unk_08 = (D_8016B7C8.unk_04 - D_8016B7C8.unk_00) / 40.0f; + } + Audio_PlaySoundGeneral(0x2007, pos, 4, &D_8016B7C8, &D_8016B7C8, &D_801333E8); +} + +void func_800F4784(unk_s2* arg0) { + if (arg0->unk_0C != 0) { + arg0->unk_0C--; + if (arg0->unk_0C != 0) { + arg0->unk_00 = arg0->unk_00 + arg0->unk_08; + } else { + arg0->unk_00 = arg0->unk_04; + } + } +} + +void func_800F47BC(void) { + Audio_SetVolScale(0, 1, 0, 0xA); + Audio_SetVolScale(3, 1, 0, 0xA); +} + +void func_800F47FC(void) { + Audio_SetVolScale(0, 1, 0x7F, 3); + Audio_SetVolScale(3, 1, 0x7F, 3); +} + +void func_800F483C(u8 arg0, u8 arg1) { + Audio_SetVolScale(0, 0, arg0, arg1); +} + +void func_800F4870(u8 arg0) { + s8 phi_s1; + u8 i; + + phi_s1 = 0; + if (arg0 == 0) { + phi_s1 = 0x7F; + } + + for (i = 0; i < 16; i++) { + Audio_QueueCmdS8(_SHIFTL(0x07, 24, 8) | _SHIFTL(0x00, 16, 8) | _SHIFTL(i, 8, 8) | _SHIFTL(0, 0, 8), phi_s1); + } + + if (arg0 == 7) { + D_80130600 = 2; + } else { + func_800F491C(D_801305F8[arg0 & 7]); + } +} + +s32 func_800F491C(u8 arg0) { + u8 phi_v0; + u16 phi_v0_2; + + SequenceChannel* none = &gAudioContext.sequenceChannelNone; + u8 i; + + if (D_8016B8B4 != arg0) { + Audio_SetVolScale(0, 0, arg0, 2); + if (arg0 < 0x40) { + phi_v0 = 0x10; + } else { + phi_v0 = ((((arg0 - 0x40) >> 2) + 1) << 4); + } + + Audio_SeqCmd8(0, 4, 15, phi_v0); + for (i = 0; i < 0x10; i++) { + if (none != gAudioContext.seqPlayers[0].channels[i]) { + if ((u8)gAudioContext.seqPlayers[0].channels[i]->soundScriptIO[5] != 0xFF) { + // this looks like some kind of macro? + phi_v0_2 = ((u16)gAudioContext.seqPlayers[0].channels[i]->soundScriptIO[5] - arg0) + 0x7F; + if (phi_v0_2 >= 0x80) { + phi_v0_2 = 0x7F; + } + Audio_QueueCmdS8(_SHIFTL(5, 24, 8) | _SHIFTL(0, 16, 8) | _SHIFTL(i, 8, 8) | _SHIFTL(0, 0, 8), + (u8)phi_v0_2); + } + } + } + D_8016B8B4 = arg0; + } + return -1; +} + +void func_800F4A54(u8 arg0) { + D_8016B8B0 = arg0; + D_8016B8B2 = 1; +} + +void func_800F4A70(void) { + if (D_8016B8B2 == 1) { + if (D_8016B8B1 != D_8016B8B0) { + Audio_SetVolScale(0, 0, D_8016B8B0, 0xA); + D_8016B8B1 = D_8016B8B0; + D_8016B8B3 = 1; + } + D_8016B8B2 = 0; + } else if (D_8016B8B3 == 1 && D_80130608 == 0) { + Audio_SetVolScale(0, 0, 0x7F, 0xA); + D_8016B8B1 = 0x7F; + D_8016B8B3 = 0; + } + + if (D_80130600 != 0) { + D_80130600--; + if (D_80130600 == 0) { + func_800F491C(D_801305FF); + } + } +} + +void func_800F4B58(Vec3f* arg0, u16 arg1, u8* arg2) { + Audio_PlaySoundGeneral(arg1, arg0, 4, &gNoteFrequencies[arg2[D_801305CC] + 39], &D_801333E0, &D_801333E8); + + if (D_801305CC < 15) { + D_801305CC++; + } +} + +void func_800F4BE8(void) { + D_801305CC = 0; +} + +void func_800F4BF4(Vec3f* arg0, u16 arg1, s8 arg2) { + Audio_PlaySoundGeneral(arg1, arg0, 4, &gNoteFrequencies[arg2 + 39], &D_801333E0, &D_801333E8); +} + +void func_800F4C58(Vec3f* arg0, u16 sfxId, u8 arg2) { + u8 phi_s1 = 0; + u8 i; + u8 bank; + + bank = SFX_BANK_SHIFT(sfxId); + for (i = 0; i < bank; i++) { + phi_s1 += D_80130578[D_801333CC][i]; + } + + for (i = 0; i < D_80130578[D_801333CC][bank]; i++) { + if ((D_8016E1B8[bank][i].unk_4 != 0xFF) && (sfxId == gSoundBanks[bank][D_8016E1B8[bank][i].unk_4].unk_28)) { + Audio_QueueCmdS8(_SHIFTL(6, 24, 8) | _SHIFTL(2, 16, 8) | _SHIFTL(phi_s1, 8, 8) | _SHIFTL(6, 0, 8), arg2); + } + phi_s1++; + } + Audio_PlaySoundGeneral(sfxId, arg0, 4, &D_801333E0, &D_801333E0, &D_801333E8); +} + +void func_800F4E30(Vec3f* arg0, f32 arg1) { + Vec3f* temp_v0; + f32 temp_f0; + f32 temp_f2; + s32 temp_s0; + Vec3f* phi_v0; + f32 phi_f0; + s32 phi_v0_2; + f32 phi_f22; + s32 phi_s0; + s8 phi_s4; + u8 i; + + if (D_8013064C == NULL) { + D_8013064C = arg0; + D_80130650 = arg1; + } else if (arg0 != D_8013064C) { + if (arg1 < D_80130650) { + D_8013064C = arg0; + D_80130650 = arg1; + } + } else { + D_80130650 = arg1; + } + + if (D_8013064C->x > 100.0f) { + phi_s4 = 0x7F; + } else if (D_8013064C->x < -100.0f) { + phi_s4 = 0; + } else { + phi_s4 = ((D_8013064C->x / 100.0f) * 64.0f) + 64.0f; + } + + if (D_80130650 > 400.0f) { + phi_f22 = 0.1f; + } else if (D_80130650 < 120.0f) { + phi_f22 = 1.0f; + } else { + phi_f22 = ((1.0f - ((D_80130650 - 120.0f) / 280.0f)) * 0.9f) + 0.1f; + } + + for (i = 0; i < 0x10; i++) { + if (i != 9) { + Audio_SeqCmd6(0, 2, i, (127.0f * phi_f22)); + Audio_QueueCmdS8(0x03000000 | ((u8)((u32)i) << 8), phi_s4); + } + } +} + +void func_800F50CC(void) { + if (D_8013064C != NULL) { + D_8013064C = NULL; + } +} + +void* func_800F50EC(Vec3f* arg0) { + if (D_8013064C == arg0) { + D_8013064C = NULL; + } +} + +#ifdef NON_MATCHING +// matches, but need to migrate data. +void func_800F510C(s8 arg0) { + u8 phi_v1; + u8 phi_a2; + u16 phi_a1; + u8 sp40[2] = { 0, 3 }; + u8 i; + u8 j; + + if ((func_800FA0B4(1) == 0xFFFF) && (func_800FA0B4(3) != 0x2F)) { + for (i = 0; i < 2; i++) { + if (i == 0) { + phi_v1 = arg0; + } else { + phi_v1 = 0x7F - arg0; + } + + if (phi_v1 >= 0x65) { + phi_a2 = 0xB; + } else if (phi_v1 < 0x14) { + phi_a2 = 2; + } else { + phi_a2 = ((phi_v1 - 0x14) / 0xA) + 2; + } + + phi_a1 = 0; + for (j = 0; j < 0x10; j++) { + if (gAudioContext.seqPlayers[sp40[i]].channels[j]->notePriority < phi_a2) { + phi_a1 += (1 << j); + } + } + + Audio_SeqCmdA(sp40[i], phi_a1); + } + } +} +#else +void func_800F510C(s8); #pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F510C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F52A0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5504.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5510.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5550.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F56A8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5718.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F574C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5918.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F595C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F59E8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5A58.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5ACC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5B58.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5BF0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5C2C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5C64.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5CF8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5E18.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F5E90.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6114.s") - +#endif + +void func_800F52A0(Vec3f* arg0, u16 arg1, u16 arg2) { + f32 phi_f2; + f32 phi_f14; + u8 phi_a2; + f32 temp_f0; + + if (D_8016B9F3 != 0) { + D_8016B9F3--; + return; + } + + phi_f14 = sqrtf(SQ(arg0->z) + SQ(arg0->x)); + if (D_8013064C == NULL) { + D_8013064C = arg0; + func_800F5E18(3, arg1, 0, 7, 2); + } else { + temp_f0 = sqrtf(SQ(D_8013064C->z) + SQ(D_8013064C->x)); + if (phi_f14 < temp_f0) { + D_8013064C = arg0; + } else { + phi_f14 = temp_f0; + } + } + + if (arg0->y < 0.0f) { + phi_f2 = -arg0->y; + } else { + phi_f2 = arg0->y; + } + + if ((arg2 / 15.0f) < phi_f2) { + phi_a2 = 0; + } else if (phi_f14 < arg2) { + phi_a2 = (1.0f - (phi_f14 / arg2)) * 127.0f; + } else { + phi_a2 = 0; + } + + if (arg1 != 0x28) { + func_800F510C(phi_a2); + } + + Audio_SetVolScale(3, 3, phi_a2, 0); + Audio_SetVolScale(0, 3, (0x7F - phi_a2), 0); +} + +void func_800F5504(void) { + D_8013064C = NULL; +} + +void func_800F5510(u16 arg0) { + func_800F5550(arg0); + func_800F5E18(0, arg0, 0, 0, 1); +} + +void func_800F5550(u16 arg0) { + u8 sp27 = 0; + u16 nv; + + if (func_800FA0B4(0) != 0x4C) { + if (func_800FA0B4(3) == 0x2F) { + func_800F9474(3, 0); + Audio_QueueCmdS32(0xF8000000, 0); + } + + if ((D_80130658[D_80130630] & 0x20) && D_80130658[(arg0 & 0xFF) & 0xFF] & 0x10) { + + if ((D_8013062C & 0x3F) != 0) { + sp27 = 0x1E; + } + + func_800F5E18(0, arg0, sp27, 7, D_8013062C); + + D_8013062C = 0; + } else { + nv = (D_80130658[(arg0 & 0xFF) & 0xFF] & 0x40) ? 1 : 0xFF; + func_800F5E18(0, arg0, 0, 7, nv); + if (!(D_80130658[arg0] & 0x20)) { + D_8013062C = 0xC0; + } + } + D_80130630 = arg0 & 0xFF; + } +} + +void func_800F56A8(void) { + u16 temp_v0; + u8 bvar; + + temp_v0 = func_800FA0B4(0); + bvar = temp_v0 & 0xFF; + if ((temp_v0 != 0xFFFF) && ((D_80130658[bvar] & 0x10) != 0)) { + if (D_8013062C != 0xC0) { + D_8013062C = gAudioContext.seqPlayers->unk_158[3]; + } else { + D_8013062C = 0; + } + } +} + +void func_800F5718(void) { + if (func_800FA0B4(0) != 0x4C) { + Audio_StartSeq(0, 0, 0x4C); + } +} + +void func_800F574C(f32 arg0, u8 arg2) { + if (arg0 == 1.0f) { + Audio_SeqCmdB40(0, arg2, 0); + } else { + Audio_SeqCmdC(1, 0x30, arg2, arg0 * 100.0f); + } + Audio_SeqCmdC(1, 0xA0, arg2, arg0 * 100.0f); +} + +void func_800F5918(void) { + if (func_800FA0B4(0) == 0x6C && func_800FA11C(0, 0xF0000000)) { + Audio_SeqCmdB(0, 5, 0, 0xD2); + } +} + +void func_800F595C(u16 arg0) { + u8 arg0b = arg0 & 0xFF; + + if (D_80130658[arg0b] & 2) { + func_800F5C64(arg0); + } else if (D_80130658[arg0b] & 4) { + Audio_StartSeq(1, 0, arg0); + + } else { + func_800F5E18(0, arg0, 0, 7, -1); + Audio_SeqCmd1(1, 0); + } +} + +void func_800F59E8(u16 arg0) { + u8 arg0b = arg0 & 0xFF; + + if (D_80130658[arg0b] & 2) { + Audio_SeqCmd1(1, 0); + } else if (D_80130658[arg0b] & 4) { + Audio_SeqCmd1(1, 0); + } else { + Audio_SeqCmd1(0, 0); + } +} + +s32 func_800F5A58(u8 arg0) { + u8 phi_a1 = 0; + + if (D_80130658[arg0 & 0xFF] & 2) { + phi_a1 = 1; + } else if (D_80130658[arg0 & 0xFF] & 4) { + phi_a1 = 1; + } + + if (arg0 == (u8)func_800FA0B4(phi_a1)) { + return 1; + } else { + return 0; + } +} + +void func_800F5ACC(u16 arg0) { + u16 temp_v0; + + temp_v0 = func_800FA0B4(0); + if ((temp_v0 & 0xFF) != 0x2E && (temp_v0 & 0xFF) != 0x62 && temp_v0 != arg0) { + func_800F5E90(3); + if (temp_v0 != 0xFFFF) { + D_80130628 = temp_v0; + } else { + osSyncPrintf("Middle Boss BGM Start not stack \n"); + } + Audio_StartSeq(0, 0, arg0); + } +} + +void func_800F5B58(void) { + if ((func_800FA0B4(0) != 0xFFFF) && (D_80130628 != 0xFFFF) && (D_80130658[func_800FA0B4(0) & 0xFF] & 8)) { + if (D_80130628 == 0xFFFF) { + Audio_SeqCmd1(0, 0); + } else { + Audio_StartSeq(0, 0, D_80130628); + } + D_80130628 = 0xFFFF; + } +} + +void func_800F5BF0(u8 arg0) { + u16 temp_v0; + + temp_v0 = func_800FA0B4(0); + if (temp_v0 != 1) { + D_80130628 = temp_v0; + } + func_800F6FB4(arg0); +} + +void func_800F5C2C(void) { + if (D_80130628 != 0xFFFF) { + Audio_StartSeq(0, 0, D_80130628); + } + D_80130628 = 0xFFFF; +} + +void func_800F5C64(u16 arg0) { + u16 sp26; + s32 sp20; + u8* sp1C; + u8* sp18; + + sp26 = func_800FA0B4(1); + sp1C = func_800E5E84(sp26 & 0xFF, &sp20); + sp18 = func_800E5E84(arg0 & 0xFF, &sp20); + if ((sp26 == 0xFFFF) || (*sp1C == *sp18)) { + D_8016B9F4 = 1; + } else { + D_8016B9F4 = 5; + Audio_SeqCmd1(1, 0); + } + D_8016B9F6 = arg0; +} + +void func_800F5CF8(void) { + u16 sp26; + u16 sp24; + u16 sp22; + + if (D_8016B9F4 != 0) { + D_8016B9F4--; + if (D_8016B9F4 == 0) { + Audio_QueueCmdS32(0xE3000000, 0); + Audio_QueueCmdS32(0xE3000000, 1); + func_800FA0B4(0); + sp26 = func_800FA0B4(1); + sp22 = func_800FA0B4(3); + if (sp26 == 0xFFFF) { + Audio_SetVolScale(0, 1, 0, 5); + Audio_SetVolScale(3, 1, 0, 5); + Audio_SeqCmdC(1, 0x80, 1, 0xA); + Audio_SeqCmdC(1, 0x83, 1, 0xA); + Audio_SeqCmdC(1, 0x90, 0, 0); + if (sp22 != 0x2F) { + Audio_SeqCmdC(1, 0x93, 0, 0); + } + } + Audio_StartSeq(1, 1, D_8016B9F6); + Audio_SeqCmdA(0, 0xFFFF); + if (sp22 != 0x2F) { + Audio_SeqCmdA(3, 0xFFFF); + } + } + } +} + +void func_800F5E18(u8 seqIdx, u16 seqId, u8 fadeTimer, s8 arg3, s8 arg4) { + Audio_SeqCmd7(seqIdx, arg3, arg4); + Audio_StartSeq(seqIdx, fadeTimer, seqId); +} + +extern u8 D_80130654; +extern u32 D_80130634; +extern u32 D_80130638; +void func_800F5E90(u8 arg0) { + s32 phi_t0; + u16 phi_t1; + u8 phi_a3; + + D_80130654 = arg0; + if (D_80130628 == 0xFFFF) { + if (D_8013060C != 0) { + arg0 = 3; + } + phi_t1 = D_8016E750[0].unk_254; + if (phi_t1 == 2 && func_800FA0B4(3) == 0x81A) { + arg0 = 3; + } + + phi_a3 = phi_t1 & 0xFF; + if ((phi_t1 == 0xFFFF) || ((D_80130658[phi_a3] & 1) != 0) || ((D_8013061C & 0x7F) == 1)) { + if (arg0 != (D_8013061C & 0x7F)) { + if (arg0 == 1) { + if (D_8016E750[3].volScales[1] - D_80130624 < 0) { + phi_t0 = -(D_8016E750[3].volScales[1] - D_80130624); + } else { + phi_t0 = D_8016E750[3].volScales[1] - D_80130624; + } + Audio_SetVolScale(3, 3, D_80130624, phi_t0); + Audio_StartSeq(3, 10, 0x81A); + if (phi_t1 != 1) { + Audio_SetVolScale(0, 3, (0x7F - D_80130624) & 0xFF, 0xA); + func_800F510C(D_80130624); + } + } else { + if ((D_8013061C & 0x7F) == 1) { + Audio_SeqCmd1(3, 10); + if (arg0 == 3) { + phi_a3 = 0; + } else { + phi_a3 = 10; + } + + Audio_SetVolScale(0, 3, 0x7F, phi_a3); + func_800F510C(0); + } + } + + D_8013061C = arg0 + 0x80; + } + } else { + if (arg0 == 0) { + if (D_8013061C == 2) { + D_80130638 = 0; + } + D_80130634 = 0; + D_80130638++; + } else { + D_80130634++; + } + + if (arg0 == 2 && D_80130634 < 0x1E && D_80130638 >= 0x15) { + arg0 = 0; + } + + D_8013061C = arg0; + Audio_SeqCmd7(0, 2, arg0); + } + } +} + +void func_800F6114(f32 arg0) { + f32 phi_f0; + + if (D_8013061C == 0x81) { + if (arg0 != D_80130620) { + if (arg0 < 150.0f) { + phi_f0 = 0.0f; + } else if (arg0 > 500.0f) { + phi_f0 = 350.0f; + } else { + phi_f0 = arg0 - 150.0f; + } + + D_80130624 = ((350.0f - phi_f0) * 127.0f) / 350.0f; + Audio_SetVolScale(3, 3, D_80130624, 0xA); + if (D_8016E750[0].unk_254 != 1) { + Audio_SetVolScale(0, 3, (0x7F - D_80130624), 0xA); + } + } + if (D_8016E750[0].unk_254 != 1) { + func_800F510C(D_80130624); + } + } + D_80130620 = arg0; +} + +#ifdef NON_MATCHING +void func_800F6268(f32 arg0, u16 arg1) { + s8 temp_a0; + s8 phi_v1; + + D_8016BAA8 = 1; + D_8016BAAC = arg0; + if (D_8016B9F2 == 0) { + temp_a0 = func_800FA0B4(0); + if (temp_a0 == (arg1 & 0xFF)) { + if ((arg1 & 0xFF) == 0x2F) { + + if (arg0 > 2000.0f) { + phi_v1 = 0x7F; + } else if (arg0 < 200.0f) { + phi_v1 = 0; + } else { + phi_v1 = ((arg0 - 200.0f) * 127.0f) / 1800.0f; + } + Audio_SeqCmd6(0, 3, 0, 0x7F - phi_v1); + Audio_SeqCmd6(0, 3, 1, 0x7F - phi_v1); + Audio_SeqCmd6(0, 3, 13, phi_v1); + if (D_8016B9D8[0] == 0) { + D_8016B9D8[0]++; + } + } + } else if ((temp_a0 == 1) && ((arg1 & 0xFF) == 0x2F)) { + temp_a0 = func_800FA0B4(3); + if ((temp_a0 != (arg1 & 0xFF)) && (D_8016B9D8[0] < 0xA)) { + func_800F5E18(3, 0x2F, 0, 0, 0); + Audio_SeqCmdA(3, 0xFFFC); + D_8016B9D8[0] = 0xA; + } + + if (arg0 > 2000.0f) { + phi_v1 = 127; + } else if (arg0 < 200.0f) { + phi_v1 = 0; + } else { + phi_v1 = ((arg0 - 200.0f) * 127.0f) / 1800.0f; + } + Audio_SeqCmd6(3, 3, 0, 127 - phi_v1); + Audio_SeqCmd6(3, 3, 1, 127 - phi_v1); + } + + if (D_8016B9D8[0] < 0xA) { + D_8016B9D8[0]++; + } + } +} +#else +void func_800F6268(f32 arg0, u16 arg1); #pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6268.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F64E0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6584.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F66C0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F66DC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6700.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F67A0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6828.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F68BC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F68D4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F691C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6964.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6AB0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6B3C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6B68.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6BB8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6BDC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6C14.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6C34.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6D58.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6E7C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F6FB4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F70F8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F711C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F7170.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F71BC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800EC960/func_800F7208.s") +#endif + +void func_800F64E0(u8 arg0) { + D_80130608 = arg0; + if (arg0 != 0) { + Audio_PlaySoundGeneral(0x4800, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + Audio_QueueCmdS32(0xF1000000, 0); + } else { + Audio_PlaySoundGeneral(0x4801, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + Audio_QueueCmdS32(0xF2000000, 0); + } +} + +void func_800F6584(u8 arg0) { + u8 seqIdx; + u16 sp34; + + D_8016B9F2 = arg0; + if ((func_800FA0B4(0) & 0xFF) == 0x2F) { + seqIdx = 0; + sp34 = 0; + } else if ((func_800FA0B4(3) & 0xFF) == 0x2F) { + seqIdx = 3; + sp34 = 0xFFFC; + } else { + return; + } + + if (arg0 != 0) { + Audio_SeqCmd6(seqIdx, 1, 0, 0); + Audio_SeqCmd6(seqIdx, 1, 1, 0); + if (seqIdx == 3) { + Audio_SeqCmdA(seqIdx, sp34 | 3); + } + } else { + if (seqIdx == 3) { + func_800F5E18(3, 0x2F, 0, 0, 0); + } + Audio_SeqCmd6(seqIdx, 1, 0, 0x7F); + Audio_SeqCmd6(seqIdx, 1, 1, 0x7F); + if (seqIdx == 3) { + Audio_SeqCmdA(seqIdx, sp34); + } + } +} + +void func_800F66C0(s8 arg0) { + D_80130614 = arg0 & 0x7F; +} + +void func_800F66DC(s8 arg0) { + if (arg0 != 0) { + D_80130618 = arg0 & 0x7F; + } +} + +void func_800F6700(s8 arg0) { + s8 sp1F; + + switch (arg0) { + case 0: + sp1F = 0; + D_80130604 = 0; + break; + case 1: + sp1F = 3; + D_80130604 = 3; + break; + case 2: + sp1F = 1; + D_80130604 = 1; + break; + case 3: + sp1F = 0; + D_80130604 = 2; + break; + } + + Audio_SeqCmdE0(0, sp1F); +} + +void func_800F67A0(u8 arg0) { + if (D_8013063C != arg0) { + if (arg0 == 0) { + Audio_StopSfx(0x86B); + } else if (D_8013063C == 0) { + Audio_PlaySoundGeneral(0x86B, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + } + D_8013063C = arg0; + D_80130644 = arg0; +} + +void func_800F6828(u8 arg0) { + u32 t; + u8 i; + + D_80130648 = arg0; + D_80130640 = arg0; + if (D_8016E750[0].unk_254 == 1) { + for (i = 0; i < 16; i++) { + t = i; + Audio_QueueCmdS8(((t & 0xFF) << 8) | 0x6000000 | 6, arg0); + } + } +} + +void func_800F68BC(s8 arg0) { + D_8013060C = arg0; +} + +void func_800F68D4(u16 arg0, Vec3f* arg1, u8 arg2, u32* arg3, u32* arg4, u32* arg5) { + if (D_8013060C == 0) { + Audio_PlaySoundGeneral(arg0, arg1, arg2, arg3, arg4, arg5); + } +} + +void func_800F691C(u16 arg0) { + func_800F68D4(arg0, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); +} + +void func_800F6964(u16 arg0) { + s32 phi_v1; + u8 i; + + Audio_SeqCmd1(0, (arg0 * 3) / 2); + Audio_SeqCmd1(1, (arg0 * 3) / 2); + for (i = 0; i < 0x10; i++) { + phi_v1 = 0; + switch (i) { + case 0xB: + case 0xC: + if (D_80133414 == 0xA) { + phi_v1 = 1; + } + break; + case 0xD: + phi_v1 = 1; + break; + } + + if (!phi_v1) { + Audio_SeqCmd6(2, arg0 >> 1, i, 0); + } + } + + Audio_SeqCmd1(3, (arg0 * 3) / 2); +} + +void func_800F6AB0(u16 arg0) { + Audio_SeqCmd1(0, arg0); + Audio_SeqCmd1(1, arg0); + Audio_SeqCmd1(3, arg0); + Audio_SetVolScale(0, 3, 0x7F, 0); + Audio_SetVolScale(0, 1, 0x7F, 0); +} + +void func_800F6B3C(void) { + func_800F9280(2, 0, 0xFF, 5); +} + +void Audio_DisableAllSeq(void) { + Audio_DisableSeq(0, 0); + Audio_DisableSeq(1, 0); + Audio_DisableSeq(2, 0); + Audio_DisableSeq(3, 0); + Audio_ScheduleProcessCmds(); +} + +s8 func_800F6BB8(void) { + return func_800E6680(); +} + +void func_800F6BDC(void) { + Audio_DisableAllSeq(); + Audio_ScheduleProcessCmds(); + while (true) { + if (!func_800F6BB8()) { + return; + } + } +} + +void Audio_PreNMI(void) { + Audio_PreNMIInternal(); +} + +void func_800F6C34(void) { + D_8013061C = 0; + D_8016B7A8 = 1.0f; + D_8016B7B0 = 1.0f; + D_8013063C = 0; + D_80130640 = 0; + D_80130644 = 0; + D_80130648 = 0; + func_800ED858(0); + D_8016B7B8.unk_0C = 0; + D_8016B7C8.unk_0C = 0; + D_8016B7B8.unk_00 = 1.0f; + D_8016B7C8.unk_00 = 1.0f; + D_8016B7D8 = 1.0f; + D_8016B8B0 = 0x7F; + D_8016B8B1 = 0x7F; + D_8016B8B2 = 0; + D_8016B8B3 = 0; + D_8016B8B4 = 0xFF; + D_8016B9D8[0] = 0; + D_80130610 = D_801306C8[D_80133414]; + D_80130608 = 0; + D_80130628 = 0xFFFF; + Audio_QueueCmdS8(0x46000000, -1); + D_8013064C = NULL; + D_8016B9F4 = 0; + D_8016B9F3 = 1; + D_8016B9F2 = 0; +} + +typedef struct { + u16 unk_00; + u16 unk_02; + u8 unk_04[0x64]; +} D_801306DC_s; + +extern D_801306DC_s D_801306DC[]; + +void func_800F6D58(u8 arg0, u8 arg1, u8 arg2) { + u8 t; + u8 temp_a0; + u8 i; + + if ((D_8016E750[0].unk_254 != 1) && func_800FA11C(1, 0xF00000FF)) { + D_80131F64 = 1; + return; + } + + if (((arg0 << 8) + arg1) == 0x101) { + if (func_800FA0B4(3) != 0x2F) { + *D_8016B9D8 = 0; + } + } + + t = arg0 >> 4; + temp_a0 = arg0 & 0xF; + if (t == 0) { + t = arg0 & 0xF; + } + + for (i = t; i <= temp_a0; i++) { + Audio_SeqCmd8(0, arg1, i, arg2); + } +} + +void func_800F6E7C(u16 arg0, u16 arg1) { + u8 i; + u32 t; + + if (func_800FA0B4(0) == 0x4C) { + func_800F3F3C(0xF); + return; + } + Audio_SeqCmd7(0, 0, 1); + Audio_SeqCmd7(0, 4, arg0 >> 8); + Audio_SeqCmd7(0, 5, arg0 & 0xFF); + Audio_SetVolScale(0, 0, 0x7F, 1); + + i = 0; + if (D_80133408 != 0) { + i = 1; + Audio_SeqCmdE01(0, 0); + } + + Audio_StartSeq(0, 0, 1); + + if (i != 0) { + Audio_SeqCmdE01(0, 1); + } + + for (i = 0; i < 0x10; i++) { + if (!(arg1 & (1 << i)) && (arg0 & (1 << i))) { + Audio_SeqCmd8(0, 1, i, 1); + } + } +} + +void func_800F6FB4(u8 arg0) { + u8 i = 0; + u8 b0; + u8 b1; + u8 b2; + + if ((D_8016E750[0].unk_254 == 0xFFFF) || ((D_80130658[((u8)D_8016E750[0].unk_254) & 0xFFFF] & 0x80) == 0)) { + func_800F6E7C(D_801306DC[arg0].unk_00, D_801306DC[arg0].unk_02); + while ((D_801306DC[arg0].unk_04[i] != 0xFF) && (i < 0x64)) { + // Probably a fake match, using Audio_SeqCmd8 deosn't work. + b0 = D_801306DC[arg0].unk_04[i++]; + b1 = D_801306DC[arg0].unk_04[i++]; + b2 = D_801306DC[arg0].unk_04[i++]; + Audio_QueueSeqCmd(0x80000000 | (b1 << 0x10) | (b0 << 8) | b2); + } + + Audio_SeqCmd8(0, 0x07, 0xD, D_80130604); + } +} + +void func_800F70F8(void) { + Audio_ContextInit(0, 0); +} + +void func_800F711C(void) { + func_800F6C34(); + func_800EE930(); + func_800F3ED4(); + func_800FAEB4(); + func_800F905C(); + func_800F9280(2, 0, 0x70, 0xA); +} + +void func_800F7170(void) { + func_800F9280(2, 0, 0x70, 1); + Audio_QueueCmdS32(0xF2000000, 1); + Audio_ScheduleProcessCmds(); + Audio_QueueCmdS32(0xF8000000, 0); +} + +void func_800F71BC(s32 arg0) { + D_80133418 = 1; + func_800F6C34(); + func_800EE930(); + func_800F3ED4(); + func_800FADF8(); + func_800F905C(); +} + +void func_800F7208(void) { + func_800FADF8(); + Audio_QueueCmdS32(0xF2000000, 1); + func_800F6C34(); + func_800F3ED4(); + func_800F9280(2, 0, 0x70, 1); +} diff --git a/src/code/code_800F7260.c b/src/code/code_800F7260.c index 92689791e..aed3f4cb8 100644 --- a/src/code/code_800F7260.c +++ b/src/code/code_800F7260.c @@ -8,7 +8,7 @@ typedef struct { /* 0x08 */ u8 unk_8; /* 0x0C */ f32* unk_C; /* 0x10 */ f32* unk_10; - /* 0x14 */ f32* unk_14; + /* 0x14 */ s8* unk_14; } Struct_800F738C; // size = 0x18 typedef struct { @@ -18,16 +18,6 @@ typedef struct { /* 0x0C */ u16 unk_C; } Struct_800F8EA0; // size = 0x10 -typedef struct { - u32 unk_0; - u8 unk_4; -} Struct_800F7CEC; - -typedef struct { - u8 unk_0; - u16 unk_2; -} Struct_8013331C; - u8 D_80133340[4] = { 0x53, 0x45, @@ -83,7 +73,7 @@ f32 D_801333E0 = 1.0f; UNK_TYPE D_801333E4 = 0; -f32 D_801333E8 = 0.0f; +s8 D_801333E8 = 0; UNK_TYPE D_801333EC = 0; @@ -94,7 +84,6 @@ u8 D_801333F4 = 0; u8 D_801333F8 = 0; extern Struct_800F738C D_8016C9A0[]; -extern Struct_800F7CEC D_8016E1B8[7][3]; // total size = 0xA8 extern Struct_800F8EA0 D_8016E270[]; extern Struct_8013331C* D_8013331C[9]; @@ -111,21 +100,21 @@ void func_800F7260(u16 arg0) { } } -void func_800F72B8(u8 arg0) { +void Audio_QueueSeqCmdMute(u8 arg0) { D_801333D0 |= (1 << arg0); - func_800FA240(0, 2, 0x40, 0xF); - func_800FA240(3, 2, 0x40, 0xF); + Audio_SetVolScale(0, 2, 0x40, 0xF); + Audio_SetVolScale(3, 2, 0x40, 0xF); } -void func_800F731C(u8 arg0) { +void Audio_ClearBGMMute(u8 arg0) { D_801333D0 &= ((1 << arg0) ^ 0xFFFF); if (D_801333D0 == 0) { - func_800FA240(0, 2, 0x7F, 0xF); - func_800FA240(3, 2, 0x7F, 0xF); + Audio_SetVolScale(0, 2, 0x7F, 0xF); + Audio_SetVolScale(3, 2, 0x7F, 0xF); } } -void Audio_PlaySoundGeneral(u16 sfxId, Vec3f* a1, u8 a2, f32* a3, f32* a4, f32* a5) { +void Audio_PlaySoundGeneral(u16 sfxId, Vec3f* a1, u8 a2, f32* a3, f32* a4, s8* a5) { u8 i; Struct_800F738C* phi_v0; @@ -264,7 +253,7 @@ void func_800F7680(void) { if ((flag2) || (D_8013331C[SFX_BANK_SHIFT(sp50->sfxId)][SFX_INDEX(sp50->sfxId)].unk_2 & 4) || (phi_a1 == phi_s1)) { if ((gSoundBanks[phi_s5][phi_a1].unk_26 & 8) && gSoundBanks[phi_s5][phi_a1].unk_2A != 1) { - func_800F731C(gSoundBanks[phi_s5][phi_a1].unk_2E); + Audio_ClearBGMMute(gSoundBanks[phi_s5][phi_a1].unk_2E); } gSoundBanks[phi_s5][phi_a1].unk_C = sp50->unk_8; gSoundBanks[phi_s5][phi_a1].unk_28 = sp50->sfxId; @@ -320,7 +309,7 @@ void func_800F7B54(u8 bankId, u8 bankIndex) { u8 i; if (entry->unk_26 & 8) { - func_800F731C(entry->unk_2E); + Audio_ClearBGMMute(entry->unk_2E); } if (bankIndex == D_8016E1A0[bankId]) { D_8016E1A0[bankId] = entry->prev; @@ -371,7 +360,7 @@ void func_800F7CEC(u8 arg0) { if ((1 == gSoundBanks[arg0][phi_s4].unk_2A) && (gSoundBanks[arg0][phi_s4].unk_28 & 0xC00)) { gSoundBanks[arg0][phi_s4].unk_2B--; } else if (!(gSoundBanks[arg0][phi_s4].unk_28 & 0xC00) && (gSoundBanks[arg0][phi_s4].unk_2A == 5)) { - func_800E5B20((gSoundBanks[arg0][phi_s4].unk_2E << 8) | 0x6020000, 0); + Audio_QueueCmdS8((gSoundBanks[arg0][phi_s4].unk_2E << 8) | 0x6020000, 0); func_800F7B54(arg0, phi_s4); } if (gSoundBanks[arg0][phi_s4].unk_2B == 0) { @@ -402,7 +391,7 @@ void func_800F7CEC(u8 arg0) { } if (temp_s2->unk_1C > 1.0e10f) { if (temp_s2->unk_2A == 4) { - func_800E5B20((temp_s2->unk_2E << 8) | 0x6020000, 0); + Audio_QueueCmdS8((temp_s2->unk_2E << 8) | 0x6020000, 0); if (temp_s2->unk_28 & 0xC00) { func_800F7B54(arg0, phi_s4); phi_s4 = phi_s0; @@ -506,11 +495,11 @@ void func_800F8480(u8 bankId) { bankIndex = D_8016E1B8[bankId][i].unk_4; if (bankIndex != 0xFF) { entry = &gSoundBanks[bankId][bankIndex]; - seqChannel = gAudioContext.gSequencePlayers[2].channels[D_8016E260]; + seqChannel = gAudioContext.seqPlayers[2].channels[D_8016E260]; if (entry->unk_2A == 2) { entry->unk_2E = D_8016E260; if (entry->unk_26 & 8) { - func_800F72B8(D_8016E260); + Audio_QueueSeqCmdMute(D_8016E260); } if (entry->unk_26 & 0xC0) { switch (entry->unk_26 & 0xC0) { @@ -529,10 +518,10 @@ void func_800F8480(u8 bankId) { } } func_800F3A08(bankId, bankIndex, D_8016E260); - func_800E5B20(0x06020000 | ((D_8016E260 & 0xFF) << 8), 1); - func_800E5B20(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 4, entry->unk_28 & 0xFF); + Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8), 1); + Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 4, entry->unk_28 & 0xFF); if (D_80130570[bankId] != 0) { - func_800E5B20(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 5, (entry->unk_28 & 0x100) >> 8); + Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 5, (entry->unk_28 & 0x100) >> 8); } if (entry->unk_28 & 0xC00) { entry->unk_2A = 4; @@ -563,7 +552,7 @@ void func_800F87A0(u8 bankId) { while (bankIndex != 0xFF) { entry = &gSoundBanks[bankId][bankIndex]; if (entry->unk_2A >= 3) { - func_800E5B20(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); + Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); } if (entry->unk_2A != 0) { func_800F7B54(bankId, bankIndex); @@ -583,7 +572,7 @@ void func_800F8884(u8 bankId, Vec3f* pos) { entry = &gSoundBanks[bankId][bankIndex]; if (entry->posX == &pos->x) { if (entry->unk_2A >= 3) { - func_800E5B20(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); + Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); } if (entry->unk_2A != 0) { func_800F7B54(bankId, bankIndex); @@ -625,7 +614,7 @@ void func_800F8A44(Vec3f* pos, u16 sfxId) { entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex]; if (entry->posX == &pos->x && entry->unk_28 == sfxId) { if (entry->unk_2A >= 3) { - func_800E5B20(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); + Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); } if (entry->unk_2A != 0) { func_800F7B54(SFX_BANK(sfxId), bankIndex); @@ -653,7 +642,7 @@ void func_800F8BA0(u8 arg0, u16 sfxId) { entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex]; if (entry->unk_C == arg0 && entry->unk_28 == sfxId) { if (entry->unk_2A >= 3) { - func_800E5B20(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); + Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); } if (entry->unk_2A != 0) { func_800F7B54(SFX_BANK(sfxId), bankIndex); @@ -670,7 +659,7 @@ void func_800F8BA0(u8 arg0, u16 sfxId) { func_800F74E0(4, &sp58); } -void func_800F8D04(u32 sfxId) { +void Audio_StopSfx(u32 sfxId) { SoundBankEntry* entry; u8 bankIndex = gSoundBanks[SFX_BANK(sfxId)][0].next; u8 bankIndex2 = 0; @@ -680,7 +669,7 @@ void func_800F8D04(u32 sfxId) { entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex]; if (entry->unk_28 == sfxId) { if (entry->unk_2A >= 3) { - func_800E5B20(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); + Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); } if (entry->unk_2A != 0) { func_800F7B54(SFX_BANK(sfxId), bankIndex); @@ -724,7 +713,7 @@ void func_800F8F34(u8 arg0) { void func_800F8F88(void) { u8 i; - if (IS_SEQUENCE_CHANNEL_VALID(gAudioContext.gSequencePlayers[2].channels[0])) { + if (IS_SEQUENCE_CHANNEL_VALID(gAudioContext.seqPlayers[2].channels[0])) { D_8016E260 = 0; for (i = 0; i < ARRAY_COUNT(gSoundBanks); i++) { func_800F7CEC(i); diff --git a/src/code/code_800F9280.c b/src/code/code_800F9280.c index 347d8270d..1b3d0fe25 100644 --- a/src/code/code_800F9280.c +++ b/src/code/code_800F9280.c @@ -1,30 +1,472 @@ #include "ultra64.h" #include "global.h" +#include "ultra64/abi.h" +extern unk_D_8016E750 D_8016E750[4]; +extern u8 D_8016E348[4]; +extern u32 sAudioSeqCmds[0x100]; +extern u8 sSeqCmdRdPos; +extern u8 sSeqCmdWrPos; +extern u8 D_80133408; +void Audio_ProcessSeqCmd(u32 cmd); + +#ifdef NON_MATCHING +void func_800F9280(u8 seqIdx, u8 seqId, u8 arg2, u16 fadeTimer) { + u8 temp_s0; + u8 i; + + temp_s0 = seqIdx; + if (D_80133408 == 0 || temp_s0 == 2) { + arg2 &= 0x7F; + if (arg2 == 0x7F) { + Audio_QueueCmdS32(0x85000000 | ((u8)seqIdx << 16) | (seqId << 8), + ((fadeTimer >> 3) * 0x3C * gAudioContext.audioBufferParameters.updatesPerFrame) & + 0xFFFF); + } else { + Audio_QueueCmdS32(0x82000000 | ((u8)seqIdx << 16) | (seqId << 8), + (fadeTimer * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4); + } + + D_8016E750[temp_s0].unk_256 = D_8016E750[temp_s0].unk_254 = (arg2 << 8) | seqId; + + if (D_8016E750[temp_s0].volCur != 1.0f) { + Audio_QueueCmdF32(0x41000000 | ((u8)seqIdx << 16), D_8016E750[temp_s0].volCur); + } + + D_8016E750[temp_s0].unk_28 = 0; + D_8016E750[temp_s0].unk_18 = 0; + D_8016E750[temp_s0].unk_14 = 0; + + for (i = 0; i < 0x10; i++) { + D_8016E750[temp_s0].unk_50[i].unk_00 = 1.0f; + D_8016E750[temp_s0].unk_50[i].unk_0C = 0; + D_8016E750[temp_s0].unk_50[i].unk_10 = 1.0f; + D_8016E750[temp_s0].unk_50[i].unk_1C = 0; + } + + D_8016E750[temp_s0].unk_250 = 0; + D_8016E750[temp_s0].unk_252 = 0; + } +} +#else +void func_800F9280(u8 seqIdx, u8 seqId, u8 arg2, u16 fadeTimer); #pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800F9280.s") +#endif + +void func_800F9474(u8 arg0, u16 arg1) { + Audio_QueueCmdS32(0x83000000 | ((u8)arg0 << 16), + (arg1 * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4); + D_8016E750[arg0].unk_254 = 0xFFFF; +} + +typedef enum { + SEQ_START, + CMD1, + CMD2, + CMD3, + SEQ_VOL_UPD, + CMD5, + CMD6, + CMD7, + CMD8, + CMD9, + CMDA, + CMDB, + CMDC, + CMDD, + CMDE, + CMDF +} SeqCmdType; + +extern u32 D_8013340C; +#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/Audio_ProcessSeqCmd.s") + +void Audio_QueueSeqCmd(u32 cmd) { + sAudioSeqCmds[sSeqCmdWrPos++] = cmd; +} + +void Audio_ProcessSeqCmds(void) { + while (sSeqCmdWrPos != sSeqCmdRdPos) { + Audio_ProcessSeqCmd(sAudioSeqCmds[sSeqCmdRdPos++]); + } +} + +u16 func_800FA0B4(u8 playerIdx) { + if (!gAudioContext.seqPlayers[playerIdx].enabled) { + return 0xFFFF; + } + return D_8016E750[playerIdx].unk_254; +} + +s32 func_800FA11C(u32 arg0, u32 arg1) { + u8 i; + + for (i = sSeqCmdRdPos; i != sSeqCmdWrPos; i++) { + if (arg0 == (sAudioSeqCmds[i] & arg1)) { + return false; + } + } + + return true; +} + +void func_800FA174(u8 arg0) { + D_8016E348[arg0] = 0; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800F9474.s") +void func_800FA18C(u8 arg0, u8 arg1) { + u8 i; -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800F94FC.s") + for (i = 0; i < D_8016E750[arg0].unk_4D; i++) { + u8 unkb = (D_8016E750[arg0].unk_2C[i] & 0xF00000) >> 0x14; -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/Audio_SetBGM.s") + if (unkb == arg1) { + D_8016E750[arg0].unk_2C[i] = 0xFF000000; + } + } +} +#define Audio_SetVolScaleNow(seqIdx, volFadeTimer, volScale) \ + Audio_ProcessSeqCmd(0x40000000 | ((u8)seqIdx << 0x18) | ((u8)volFadeTimer << 0x10) | ((u8)(volScale * 127.0f))); -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA034.s") +void Audio_SetVolScale(u8 seqIdx, u8 scaleIdx, u8 targetVol, u8 volFadeTimer) { + f32 volScale; + u8 i; -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA0B4.s") + D_8016E750[seqIdx].volScales[scaleIdx] = targetVol & 0x7F; -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA11C.s") + if (volFadeTimer != 0) { + D_8016E750[seqIdx].fadeVolUpdate = 1; + D_8016E750[seqIdx].volFadeTimer = volFadeTimer; + } else { + for (i = 0, volScale = 1.0f; i < 4; i++) { + volScale *= D_8016E750[seqIdx].volScales[i] / 127.0f; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA174.s") + Audio_SetVolScaleNow(seqIdx, volFadeTimer, volScale); + } +} -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA18C.s") +#ifdef NON_MATCHING +void func_800FA3DC(void) { + u32 sp70; + f32 temp_f0; + f32 temp_f0_2; + f32 temp_f16; + f32 temp_f2; + f32 temp_f6; + f32 temp_f8; + s32 temp_a0_2; + s32 temp_a2; + s32 temp_a3; + u16 temp_lo; + s32 temp_s0; + s32 temp_s0_2; + u8 temp_s1; + s32 temp_s3; + s32 temp_s3_2; + s32 temp_s5; + s32 temp_v0_10; + u8 temp_v0_4; + s32 temp_v1; + u16 temp_t4; + u16 temp_t5; + u16 temp_t5_2; + u16 temp_t8; + u16 temp_v0_2; + u16 temp_v0_5; + u16 temp_v0_6; + u16 temp_v1_2; + u16 temp_v1_3; + u8 temp_a0; + u32 temp_v0; + u8 temp_a3_3; + u8 temp_s0_3; + u8 temp_t3; + u8 temp_v0_9; + u8 temp_v1_4; + unk_D_8016E750* temp_s0_4; + unk_D_8016E750* temp_s0_5; + unk_D_8016E750* temp_s2; + void* temp_v0_7; + void* temp_v0_8; + s32 phi_s3; + f32 phi_f0; + f32 phi_f6; + u16 phi_a2; + s32 phi_a2_2; + f32 phi_f0_2; + u8 phi_t0; + f32 phi_f8; + s32 phi_s0; + s32 phi_s0_2; + s32 phi_s3_2; + s32 phi_v1; + f32 phi_f16; + u8 i; + u8 j; + u8 k; -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA240.s") + for (i = 0; i < 4; i++) { + temp_s2 = &D_8016E750[i]; + if (temp_s2->unk_260 != 0) { + switch (func_800E5E20(&sp70)) { + case 1: + case 2: + case 3: + case 4: + temp_s2->unk_260 = 0; + Audio_ProcessSeqCmd(temp_s2->unk_25C); + break; + } + } + if (temp_s2->fadeVolUpdate) { + for (j = 0, phi_f0 = 1.0f; j < 4; j++) { + phi_f0 *= (D_8016E750[i].volScales[j] / 127.0f); + } + + Audio_SeqCmd4(i, temp_s2->volFadeTimer, phi_f0 * 127.0f); + temp_s2->fadeVolUpdate = 0; + } + + if (temp_s2->unk_0C != 0) { + temp_s2->unk_0C--; + + if (temp_s2->unk_0C != 0) { + temp_s2->volCur = temp_s2->volCur - temp_s2->unk_08; + } else { + temp_s2->volCur = temp_s2->volTarget; + } + + Audio_QueueCmdF32(0x41000000 | _SHIFTL(i, 16, 8), temp_s2->volCur); + } + + if (temp_s2->unk_14 != 0) { + phi_a2 = temp_s2->unk_14 & 0xFFF; + phi_t0 = (temp_s2->unk_14 & 0xFF0000) >> 0xF; + if (phi_t0 == 0) { + phi_t0++; + } + + if (gAudioContext.seqPlayers[i].enabled) { + temp_v0_4 = (temp_s2->unk_14 & 0xF000) >> 0xC; + temp_lo = gAudioContext.seqPlayers[i].tempo / 0x30; + switch (temp_v0_4) { + case 1: + phi_a2 += temp_lo; + break; + case 2: + phi_a2 = temp_a2; + if (temp_v1 < temp_lo) { + phi_a2 = temp_lo - temp_v1; + } + break; + case 3: + phi_a2 = temp_lo * (phi_a2 / 100.0f); + break; + case 4: + temp_v0_5 = temp_s2->unk_18; + phi_a2 = temp_lo; + if (temp_v0_5 != 0) { + phi_a2 = temp_v0_5 & 0xFFFF; + } + break; + } + + if (phi_a2 >= 0x12D) { + phi_a2 = 0x12C; + } + + if (temp_s2->unk_18 == 0) { + temp_s2->unk_18 = temp_lo; + } + + temp_s2->unk_20 = phi_a2; + temp_s2->unk_1C = temp_lo; + temp_s2->unk_28 = phi_t0; + temp_s2->unk_14 = 0; + temp_s2->unk_24 = (temp_s2->unk_1C - temp_s2->unk_20) / temp_s2->unk_28; + } + } + + if (temp_s2->unk_28 != 0) { + temp_s2->unk_28--; + if (temp_s2->unk_28 != 0) { + temp_s2->unk_1C = temp_s2->unk_1C - temp_s2->unk_24; + } else { + temp_s2->unk_1C = temp_s2->unk_20; + } + Audio_QueueCmdS32(0x47000000 | _SHIFTL(i, 16, 8), temp_s2->unk_1C); + } + + if (temp_s2->unk_252 != 0) { + for (k = 0; k < 0x10; k++) { + if (D_8016E750[i].unk_50[k].unk_0C != 0) { + D_8016E750[i].unk_50[k].unk_0C--; + if (D_8016E750[i].unk_50[k].unk_0C != 0) { + D_8016E750[i].unk_50[k].unk_00 -= D_8016E750[i].unk_50[k].unk_08; + } else { + D_8016E750[i].unk_50[k].unk_00 = D_8016E750[i].unk_50[k].unk_04; + temp_s2->unk_252 ^= (1 << k); + } + Audio_QueueCmdF32(0x01000000 | _SHIFTL(i, 16, 8) | (k, 8, 8), D_8016E750[i].unk_50[k].unk_00); + } + } + } + if (temp_s2->unk_250 != 0) { + for (k = 0; k < 0x10; k++) { + if (D_8016E750[i].unk_50[k].unk_1C != 0) { + D_8016E750[i].unk_50[k].unk_1C--; + if (D_8016E750[i].unk_50[k].unk_1C != 0) { + D_8016E750[i].unk_50[k].unk_10 -= D_8016E750[i].unk_50[k].unk_18; + } else { + D_8016E750[i].unk_50[k].unk_10 = D_8016E750[i].unk_50[k].unk_14; + temp_s2->unk_250 ^= (1 << k); + } + Audio_QueueCmdF32(0x04000000 | _SHIFTL(i, 16, 8) | _SHIFTL(k, 8, 8), + D_8016E750[i].unk_50[k].unk_10); + } + } + } + + if (temp_s2->unk_4D != 0) { + if (func_800FA11C(0xF0000000, 0xF0000000) == 0) { + temp_s2->unk_4D = 0; + return; + } + + if (temp_s2->unk_4C != 0) { + temp_s2->unk_4C--; + } else if (!gAudioContext.seqPlayers[i].enabled) { + for (j = 0; j < temp_s2->unk_4D; j++) { + // temp_a0 = (temp_v0_10 & 0x00F00000) >> 20; + // temp_s1 = (temp_v0_10 & 0x000F0000) >> 16; + // temp_s0_3 = (temp_v0_10 & 0xFF00) >> 8; + // temp_a3_3 = (temp_v0_10 & 0xFF) >> 0; + temp_v0_10 = D_8016E750[i].unk_2C[j]; + temp_a0 = Unk2C_B8(temp_v0_10); + temp_s1 = Unk2C_B12(temp_v0_10); + temp_s0_3 = Unk2C_B16(temp_v0_10); + temp_a3_3 = Unk2C_B24(temp_v0_10); + switch (temp_a0) { + case 0: + Audio_SetVolScale(temp_s1, 1, 0x7F, temp_a3_3); + break; + case 7: + if (temp_a3_3 == D_8016E348[i]) { + Audio_SetVolScale(temp_s1, 1, 0x7F, temp_s0_3); + } + break; + case 1: + Audio_SeqCmd3(i, temp_s2->unk_254); + break; + case 2: + Audio_StartSeq(temp_s1, 0, D_8016E750[temp_s1].unk_254); + D_8016E750[temp_s1].fadeVolUpdate = 1; + D_8016E750[temp_s1].volScales[1] = 0x7F; + break; + case 3: + Audio_SeqCmdB30(temp_s1, temp_s0_3, temp_a3_3); + break; + case 4: + Audio_SeqCmdB40(temp_s1, temp_a3_3, 0); + break; + case 5: + Audio_StartSeq(temp_s1, D_8016E750[temp_s1].unk_4E, temp_v0_10); + Audio_SetVolScale(temp_s1, 1, 0x7F, 0); + D_8016E750[temp_s1].unk_4E = 0; + break; + case 6: + temp_s2->unk_4E = temp_s0_3; + break; + case 8: + Audio_SetVolScale(temp_s1, temp_s0_3, 0x7F, temp_a3_3); + break; + case 14: + if (temp_a3_3 & 1) { + Audio_QueueCmdS32(0xE3000000, 0); + } + if (temp_a3_3 & 2) { + Audio_QueueCmdS32(0xE3000000U, 1); + } + if (temp_a3_3 & 4) { + Audio_QueueCmdS32(0xE3000000U, 2); + } + break; + case 9: + Audio_SeqCmdA(temp_s1, temp_v0_10); + break; + case 10: + Audio_SeqCmd5(temp_s1, temp_s0_3, (temp_a3_3 * 0xA)); + break; + } + } + + temp_s2->unk_4D = 0; + } + } + } +} +#else +void func_800FA3DC(void); #pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA3DC.s") +#endif + +extern u8 D_80133418; +extern u8 D_801333CC; +#define CMD46(a) (_SHIFTL(0x46, 24, 8) | _SHIFTL(a, 16, 8)) +u8 func_800FAD34(void) { + if (D_80133418 != 0) { + if (D_80133418 == 1) { + if (func_800E5EDC() == 1) { + D_80133418 = 0; + Audio_QueueCmdS8(CMD46(2), D_801333CC); + func_800F7170(); + } + } else if (D_80133418 == 2) { + while (func_800E5EDC() != 1) {} + D_80133418 = 0; + Audio_QueueCmdS8(CMD46(2), D_801333CC); + func_800F7170(); + } + } + + return D_80133418; +} + +void func_800FADF8(void) { + u8 i, j; -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FAD34.s") + for (i = 0; i < 4; i++) { + D_8016E348[i] = 0; + D_8016E750[i].unk_254 = 0xFFFF; + D_8016E750[i].unk_256 = 0xFFFF; + D_8016E750[i].unk_28 = 0; + D_8016E750[i].unk_18 = 0; + D_8016E750[i].unk_14 = 0; + D_8016E750[i].unk_258 = 0; + D_8016E750[i].unk_4D = 0; + D_8016E750[i].unk_4E = 0; + D_8016E750[i].unk_250 = 0; + D_8016E750[i].unk_252 = 0; + for (j = 0; j < 4; j++) { + D_8016E750[i].volScales[j] = 0x7F; + } + D_8016E750[i].volFadeTimer = 1; + D_8016E750[i].fadeVolUpdate = 1; + } +} -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FADF8.s") +void func_800FAEB4(void) { + u8 i, j; -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FAEB4.s") + for (i = 0; i < 4; i++) { + D_8016E750[i].volCur = 1.0f; + D_8016E750[i].unk_0C = 0; + D_8016E750[i].fadeVolUpdate = 0; + for (j = 0; j < 4; j++) { + D_8016E750[i].volScales[j] = 0x7F; + } + } + func_800FADF8(); +} diff --git a/src/code/game.c b/src/code/game.c index ce71375f1..3f4f063f7 100644 --- a/src/code/game.c +++ b/src/code/game.c @@ -262,22 +262,22 @@ void GameState_Update(GameState* gameState) { gfxCtx->viFeatures = gViConfigFeatures; gfxCtx->xScale = gViConfigXScale; gfxCtx->yScale = gViConfigYScale; - if (SREG(63) == 6 || (SREG(63) == 2u && osTvType == 1)) { + if (SREG(63) == 6 || (SREG(63) == 2u && osTvType == OS_TV_NTSC)) { gfxCtx->viMode = &osViModeNtscLan1; gfxCtx->yScale = 1.0f; } - if (SREG(63) == 5 || (SREG(63) == 2u && osTvType == 2)) { + if (SREG(63) == 5 || (SREG(63) == 2u && osTvType == OS_TV_MPAL)) { gfxCtx->viMode = &osViModeMpalLan1; gfxCtx->yScale = 1.0f; } - if (SREG(63) == 4 || (SREG(63) == 2u && osTvType == 0)) { + if (SREG(63) == 4 || (SREG(63) == 2u && osTvType == OS_TV_PAL)) { gfxCtx->viMode = &osViModePalLan1; gfxCtx->yScale = 1.0f; } - if (SREG(63) == 3 || (SREG(63) == 2u && osTvType == 0)) { + if (SREG(63) == 3 || (SREG(63) == 2u && osTvType == OS_TV_PAL)) { gfxCtx->viMode = &osViModeFpalLan1; gfxCtx->yScale = 0.833f; } @@ -436,7 +436,7 @@ void GameState_Destroy(GameState* gameState) { // game destructor start osSyncPrintf("game デストラクタ開始\n"); func_800C3C20(); - func_800F3054(); + func_800F30534(); osRecvMesg(&gameState->gfxCtx->queue, NULL, OS_MESG_BLOCK); LogUtils_CheckNullPointer("this->cleanup", gameState->destroy, "../game.c", 1139); if (gameState->destroy != NULL) { diff --git a/src/code/graph.c b/src/code/graph.c index 2ad106782..725cbaaa7 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -362,7 +362,7 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) { gfxCtx->fbIdx++; } - func_800F3054(); + func_800F30534(); { OSTime time = osGetTime(); diff --git a/src/code/sched.c b/src/code/sched.c index a28e78a2f..cce050822 100644 --- a/src/code/sched.c +++ b/src/code/sched.c @@ -249,7 +249,7 @@ u32 Sched_IsComplete(SchedContext* sc, OSScTask* task) { void Sched_RunTask(SchedContext* sc, OSScTask* spTask, OSScTask* dpTask) { ASSERT(sc->curRSPTask == NULL, "sc->curRSPTask == NULL", "../sched.c", 663); if (spTask != NULL) { - if (spTask->list.t.type == 0) { + if (spTask->list.t.type == M_NULTASK) { if (spTask->flags & OS_SC_NEEDS_RSP) { spTask->state &= ~OS_SC_SP; sc->curRSPTask = NULL; diff --git a/src/code/z_demo.c b/src/code/z_demo.c index 2a2229f27..71bc52ea5 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -410,9 +410,9 @@ void Cutscene_Command_FadeBGM(GlobalContext* globalCtx, CutsceneContext* csCtx, var1 = cmd->endFrame - cmd->startFrame; if (cmd->type == 3) { - Audio_SetBGM(var1 << 0x10 | 0x110000FF); + Audio_QueueSeqCmd(var1 << 0x10 | 0x110000FF); } else { - Audio_SetBGM(var1 << 0x10 | 0x100000FF); + Audio_QueueSeqCmd(var1 << 0x10 | 0x100000FF); } } } diff --git a/src/code/z_scene.c b/src/code/z_scene.c index 8e3ab67a2..64135c47b 100644 --- a/src/code/z_scene.c +++ b/src/code/z_scene.c @@ -422,7 +422,7 @@ void func_80099140(GlobalContext* globalCtx, SceneCmd* cmd) { globalCtx->soundCtx.nightSeqIndex = cmd->soundSettings.nightSeqIndex; if (gSaveContext.seqIndex == 0xFF) { - Audio_SetBGM(cmd->soundSettings.bgmId | 0xF0000000); + Audio_QueueSeqCmd(cmd->soundSettings.bgmId | 0xF0000000); } } |
