1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-08-28 01:41:20 +00:00

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>
This commit is contained in:
krimtonz 2021-07-27 18:44:58 -05:00 committed by GitHub
parent cc9a04feb4
commit d1a5ea5110
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
429 changed files with 9047 additions and 17038 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -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(&note->listItem);
Audio_AudioListPushBack(&gNoteFreeLists.disabled, &note->listItem);
Audio_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, &note->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 = &note->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];
AudioSessionSettings* preset = &gAudioSessionPresets[gAudioContext.audioResetPresetIdToLoad];
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) &
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;
wantMisc = gAudioContext.audioSessionPool.size - totalMem - 0x100;
if (gAudioContext.gUnkPool.start != NULL) {
gAudioContext.gUnkPool.cur = gAudioContext.gUnkPool.start;
if (gAudioContext.unkPool.start != NULL) {
gAudioContext.unkPool.cur = gAudioContext.unkPool.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);
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) {

1652
src/code/audio_load.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -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 = &note->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);
}
}

7
src/code/audio_rodata.c Normal file
View file

@ -0,0 +1,7 @@
#include "global.h"
const s16 D_8014A6C0[] = {
0x1C00,
0x0030,
};
const AudioContextInitSizes D_8014A6C4 = { 0x37F00, 0xE0E0, 0xBCE0 };

View file

@ -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]);
}
}

1199
src/code/audio_synthesis.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -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")

View file

@ -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")

844
src/code/code_800E4FE0.c Normal file
View file

@ -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 = &note->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 = &note->playbackState;
if (note->noteSubEu.bitField0.s.enabled) {
temp_a3 = &note->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();
}

File diff suppressed because it is too large Load diff

View file

@ -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);

View file

@ -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
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800F9474.s")
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;
}
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800F94FC.s")
typedef enum {
SEQ_START,
CMD1,
CMD2,
CMD3,
SEQ_VOL_UPD,
CMD5,
CMD6,
CMD7,
CMD8,
CMD9,
CMDA,
CMDB,
CMDC,
CMDD,
CMDE,
CMDF
} SeqCmdType;
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/Audio_SetBGM.s")
extern u32 D_8013340C;
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/Audio_ProcessSeqCmd.s")
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA034.s")
void Audio_QueueSeqCmd(u32 cmd) {
sAudioSeqCmds[sSeqCmdWrPos++] = cmd;
}
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA0B4.s")
void Audio_ProcessSeqCmds(void) {
while (sSeqCmdWrPos != sSeqCmdRdPos) {
Audio_ProcessSeqCmd(sAudioSeqCmds[sSeqCmdRdPos++]);
}
}
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA11C.s")
u16 func_800FA0B4(u8 playerIdx) {
if (!gAudioContext.seqPlayers[playerIdx].enabled) {
return 0xFFFF;
}
return D_8016E750[playerIdx].unk_254;
}
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA174.s")
s32 func_800FA11C(u32 arg0, u32 arg1) {
u8 i;
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA18C.s")
for (i = sSeqCmdRdPos; i != sSeqCmdWrPos; i++) {
if (arg0 == (sAudioSeqCmds[i] & arg1)) {
return false;
}
}
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FA240.s")
return true;
}
void func_800FA174(u8 arg0) {
D_8016E348[arg0] = 0;
}
void func_800FA18C(u8 arg0, u8 arg1) {
u8 i;
for (i = 0; i < D_8016E750[arg0].unk_4D; i++) {
u8 unkb = (D_8016E750[arg0].unk_2C[i] & 0xF00000) >> 0x14;
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)));
void Audio_SetVolScale(u8 seqIdx, u8 scaleIdx, u8 targetVol, u8 volFadeTimer) {
f32 volScale;
u8 i;
D_8016E750[seqIdx].volScales[scaleIdx] = targetVol & 0x7F;
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;
}
Audio_SetVolScaleNow(seqIdx, volFadeTimer, volScale);
}
}
#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;
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
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FAD34.s")
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();
}
}
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FADF8.s")
return D_80133418;
}
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F9280/func_800FAEB4.s")
void func_800FADF8(void) {
u8 i, j;
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;
}
}
void func_800FAEB4(void) {
u8 i, j;
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();
}

View file

@ -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) {

View file

@ -362,7 +362,7 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
gfxCtx->fbIdx++;
}
func_800F3054();
func_800F30534();
{
OSTime time = osGetTime();

View file

@ -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;

View file

@ -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);
}
}
}

View file

@ -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);
}
}