mirror of
https://github.com/HarbourMasters/Starship
synced 2026-08-08 10:53:24 -04:00
In my nightmares, I see audio_synthesis (#146)
* heapsort * suff * load init * split * split data * begone asm * names * names and cleanup * let's try this * woo macros * general * bgm macro * names * audio_thread * Update Torch * I think it's time to move on * Merge remote-tracking branch 'upstream/master' into play --------- Co-authored-by: Alejandro Javier Asenjo Nitti <alejandro.asenjo88@gmail.com>
This commit is contained in:
@@ -90,14 +90,14 @@ volatile s32 gAudioTaskCountQ;
|
||||
s32 gCurAudioFrameDmaCount;
|
||||
s32 gAudioTaskIndexQ;
|
||||
s32 gCurAiBuffIndex;
|
||||
void* gAbiCmdBuffs[2];
|
||||
Acmd* gCurAiCmdBuffer;
|
||||
AudioTask* gAudioCurTask;
|
||||
AudioTask gAudioRspTasks[2];
|
||||
Acmd* gAbiCmdBuffs[2];
|
||||
Acmd* gCurAbiCmdBuffer;
|
||||
SPTask* gAudioCurTask;
|
||||
SPTask gAudioRspTasks[2];
|
||||
f32 gMaxTempoTvTypeFactors;
|
||||
s32 gRefreshRate;
|
||||
u16* gAiBuffers[3];
|
||||
u16 gAiBuffLengths[3];
|
||||
s16* gAiBuffers[3];
|
||||
s16 gAiBuffLengths[3];
|
||||
u32 gAudioRandom;
|
||||
UNK_TYPE D_80155D88;
|
||||
volatile u32 gResetTimer;
|
||||
|
||||
+16
-16
@@ -870,7 +870,7 @@ void Audio_StartSequence(u8 seqPlayId, u8 seqId, u8 seqArgs, u16 fadeInTime) {
|
||||
s32 pad;
|
||||
|
||||
if (!gStartSeqDisabled || (seqPlayId == SEQ_PLAYER_SFX)) {
|
||||
AUDIOCMD_GLOBAL_INIT_SEQPLAYER((u32) seqPlayId, (u32) seqId, fadeInTime);
|
||||
AUDIOCMD_GLOBAL_INIT_SEQPLAYER((u32) seqPlayId, (u32) seqId, 0, fadeInTime);
|
||||
gActiveSequences[seqPlayId].prevSeqId = gActiveSequences[seqPlayId].seqId = seqId | ((seqArgs) << 8);
|
||||
if (gActiveSequences[seqPlayId].mainVolume.mod != 1.0f) {
|
||||
AUDIOCMD_SEQPLAYER_FADE_VOLUME_SCALE((u32) seqPlayId, gActiveSequences[seqPlayId].mainVolume.mod);
|
||||
@@ -930,8 +930,8 @@ void Audio_ProcessSeqCmd(u32 seqCmd) {
|
||||
gActiveSequences[seqPlayId].isWaitingForFonts = 1;
|
||||
Audio_StopSequence(seqPlayId, 1);
|
||||
if (gActiveSequences[seqPlayId].prevSeqId != 0xFFFF) {
|
||||
tempptr = func_8001ED14(seqNumber, &sp4C);
|
||||
tempPtr2 = func_8001ED14(gActiveSequences[seqPlayId].prevSeqId & 0xFF, &sp4C);
|
||||
tempptr = AudioThread_GetFontsForSequence(seqNumber, &sp4C);
|
||||
tempPtr2 = AudioThread_GetFontsForSequence(gActiveSequences[seqPlayId].prevSeqId & 0xFF, &sp4C);
|
||||
if (tempptr[0] != tempPtr2[0]) {
|
||||
AUDIOCMD_GLOBAL_DISCARD_SEQ_FONTS(seqNumber);
|
||||
}
|
||||
@@ -1061,8 +1061,8 @@ void Audio_ProcessSeqCmd(u32 seqCmd) {
|
||||
break;
|
||||
case 7:
|
||||
val = seqCmd & 0xFF;
|
||||
ioPort = ((seqCmd & 0xFF0000) >> 0x10);
|
||||
AUDIOCMD_SEQPLAYER_SET_IO(seqPlayId, ioPort, 0, val);
|
||||
ioPort = ((seqCmd & 0xFF0000) >> 0x10); // may be misnamed
|
||||
AUDIOCMD_SEQPLAYER_SET_IO(seqPlayId, ioPort, val);
|
||||
// AudioThread_QueueCmdS8(((seqPlayId & 0xFF) << 0x10) | 0x46000000 | (temp3 << 8), temp4);
|
||||
break;
|
||||
case 8:
|
||||
@@ -1127,7 +1127,7 @@ void Audio_ProcessSeqCmd(u32 seqCmd) {
|
||||
sp61 = sNewAudioSpecId;
|
||||
sNewAudioSpecId = specId;
|
||||
if (sp61 != sNewAudioSpecId) {
|
||||
func_8001ED8C((OSMesg) (u32) sNewAudioSpecId);
|
||||
AudioThread_ResetAudioHeap(sNewAudioSpecId);
|
||||
func_8001DE1C(sp61);
|
||||
AUDIOCMD_GLOBAL_STOP_AUDIOCMDS();
|
||||
} else {
|
||||
@@ -1224,17 +1224,17 @@ void Audio_UpdateActiveSequences(void) {
|
||||
s32 temp;
|
||||
u32 cmd;
|
||||
f32 fadeMod;
|
||||
s32 sp70;
|
||||
u32 sp70;
|
||||
s32 pad1;
|
||||
s32 pad2;
|
||||
|
||||
for (seqPlayId = 0; seqPlayId < 4; seqPlayId++) {
|
||||
if ((gActiveSequences[seqPlayId].isWaitingForFonts != 0)) {
|
||||
switch ((s32) func_8001ECAC(&sp70)) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
switch ((s32) AudioThread_GetAsyncLoadStatus(&sp70)) {
|
||||
case SEQ_PLAYER_BGM + 1:
|
||||
case SEQ_PLAYER_FANFARE + 1:
|
||||
case SEQ_PLAYER_SFX + 1:
|
||||
case SEQ_PLAYER_VOICE + 1:
|
||||
gActiveSequences[seqPlayId].isWaitingForFonts = 0;
|
||||
Audio_ProcessSeqCmd(gActiveSequences[seqPlayId].startSeqCmd);
|
||||
break;
|
||||
@@ -1433,7 +1433,7 @@ u8 func_80018FA4(void) {
|
||||
if (D_800C5D58 == 1) {
|
||||
if (func_8001ED34() == 1) {
|
||||
D_800C5D58 = 0;
|
||||
AUDIOCMD_SEQPLAYER_SET_IO(SEQ_PLAYER_SFX, 0, 0, gSfxChannelLayout);
|
||||
AUDIOCMD_SEQPLAYER_SET_IO(SEQ_PLAYER_SFX, 0, gSfxChannelLayout);
|
||||
func_8001DD40();
|
||||
}
|
||||
} else if (D_800C5D58 == 2) {
|
||||
@@ -1441,7 +1441,7 @@ u8 func_80018FA4(void) {
|
||||
;
|
||||
}
|
||||
D_800C5D58 = 0;
|
||||
AUDIOCMD_SEQPLAYER_SET_IO(SEQ_PLAYER_SFX, 0, 0, gSfxChannelLayout);
|
||||
AUDIOCMD_SEQPLAYER_SET_IO(SEQ_PLAYER_SFX, 0, gSfxChannelLayout);
|
||||
func_8001DD40();
|
||||
}
|
||||
}
|
||||
@@ -2953,7 +2953,7 @@ void func_8001DD40(void) {
|
||||
func_80017550();
|
||||
SEQCMD_SET_SEQPLAYER_VOLUME(SEQ_PLAYER_SFX, 0, 127);
|
||||
SEQCMD_SET_SEQPLAYER_VOLUME(SEQ_PLAYER_VOICE, 0, 127);
|
||||
func_8001E920();
|
||||
AudioThread_ScheduleProcessCmds();
|
||||
AUDIOCMD_GLOBAL_STOP_AUDIOCMDS();
|
||||
AUDIOCMD_GLOBAL_STOP_AUDIOCMDS();
|
||||
AUDIOCMD_GLOBAL_STOP_AUDIOCMDS();
|
||||
@@ -2989,7 +2989,7 @@ void Audio_Update(void) {
|
||||
func_8001AF50();
|
||||
Audio_UpdateActiveSequences();
|
||||
Audio_UpdateDelayedSeqCmds();
|
||||
func_8001E920();
|
||||
AudioThread_ScheduleProcessCmds();
|
||||
}
|
||||
gAudioFrameCounter++;
|
||||
}
|
||||
|
||||
@@ -590,7 +590,7 @@ s32 AudioHeap_ResetStep(void) {
|
||||
}
|
||||
}
|
||||
|
||||
gResetFadeoutFramesLeft = 0x10 / sp24;
|
||||
gResetFadeoutFramesLeft = 16 / sp24;
|
||||
gResetStatus--;
|
||||
}
|
||||
break;
|
||||
|
||||
+15
-15
@@ -252,15 +252,15 @@ void* AudioLoad_SyncLoadSeqFonts(s32 seqId, u32* outFontId) {
|
||||
return soundFontData;
|
||||
}
|
||||
|
||||
void AudioLoad_SyncLoadSeqParts(s32 seqId, s32 arg1) {
|
||||
void AudioLoad_SyncLoadSeqParts(s32 seqId, s32 flags) {
|
||||
s32 pad;
|
||||
u32 fontId;
|
||||
|
||||
seqId = AudioLoad_GetLoadTableIndex(0, seqId);
|
||||
if (arg1 & 2) {
|
||||
if (flags & 2) {
|
||||
AudioLoad_SyncLoadSeqFonts(seqId, &fontId);
|
||||
}
|
||||
if (arg1 & 1) {
|
||||
if (flags & 1) {
|
||||
AudioLoad_SyncLoadSeq(seqId);
|
||||
}
|
||||
}
|
||||
@@ -309,22 +309,22 @@ s32 AudioLoad_SyncLoadInstrument(s32 fontId, s32 instId, s32 drumId) {
|
||||
}
|
||||
}
|
||||
|
||||
void AudioLoad_AsyncLoadSampleBank(s32 sampleBankId, s32 arg1, s32 retData, OSMesgQueue* retQueue) {
|
||||
if (AudioLoad_AsyncLoadInner(2, AudioLoad_GetLoadTableIndex(2, sampleBankId), arg1, retData, retQueue) == NULL) {
|
||||
void AudioLoad_AsyncLoadSampleBank(s32 sampleBankId, s32 nChunks, s32 retData, OSMesgQueue* retQueue) {
|
||||
if (AudioLoad_AsyncLoadInner(2, AudioLoad_GetLoadTableIndex(2, sampleBankId), nChunks, retData, retQueue) == NULL) {
|
||||
osSendMesg(retQueue, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioLoad_AsyncLoadSeq(s32 seqId, s32 arg1, s32 retData, OSMesgQueue* retQueue) {
|
||||
void AudioLoad_AsyncLoadSeq(s32 seqId, s32 nChunks, s32 retData, OSMesgQueue* retQueue) {
|
||||
s32 index = ((u16*) gSeqFontTable)[AudioLoad_GetLoadTableIndex(0, seqId)];
|
||||
s32 fontsLeft = gSeqFontTable[index++];
|
||||
|
||||
for (fontsLeft; fontsLeft > 0; fontsLeft--) {
|
||||
AudioLoad_AsyncLoadInner(1, AudioLoad_GetLoadTableIndex(1, gSeqFontTable[index++]), arg1, retData, retQueue);
|
||||
AudioLoad_AsyncLoadInner(1, AudioLoad_GetLoadTableIndex(1, gSeqFontTable[index++]), nChunks, retData, retQueue);
|
||||
}
|
||||
}
|
||||
|
||||
void* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) {
|
||||
u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) {
|
||||
s32 index = ((u16*) gSeqFontTable)[AudioLoad_GetLoadTableIndex(0, seqId)];
|
||||
|
||||
*outNumFonts = gSeqFontTable[index++];
|
||||
@@ -838,21 +838,21 @@ void AudioLoad_Init(void) {
|
||||
*clearContext++ = 0;
|
||||
}
|
||||
switch (osTvType) {
|
||||
case 0:
|
||||
case OS_TV_PAL:
|
||||
gMaxTempoTvTypeFactors = 20.03042f;
|
||||
gRefreshRate = 0x32;
|
||||
gRefreshRate = 50;
|
||||
break;
|
||||
case 2:
|
||||
case OS_TV_MPAL:
|
||||
gMaxTempoTvTypeFactors = 16.546f;
|
||||
gRefreshRate = 0x3C;
|
||||
gRefreshRate = 60;
|
||||
break;
|
||||
default:
|
||||
case 1:
|
||||
case OS_TV_NTSC:
|
||||
gMaxTempoTvTypeFactors = 16.713f;
|
||||
gRefreshRate = 0x3C;
|
||||
gRefreshRate = 60;
|
||||
break;
|
||||
}
|
||||
func_8001EE3C();
|
||||
AudioThread_Init();
|
||||
for (i = 0; i < 3; i++) {
|
||||
gAiBuffLengths[i] = 0xA0;
|
||||
}
|
||||
|
||||
+1230
-16
File diff suppressed because it is too large
Load Diff
+393
-26
@@ -1,5 +1,12 @@
|
||||
#include "sys.h"
|
||||
#include "sf64audio_provisional.h"
|
||||
#include "audiothread_cmd.h"
|
||||
|
||||
void AudioThread_ProcessCmds(u32 msg);
|
||||
void AudioThread_SetFadeOutTimer(s32 seqPlayId, s32 fadeTime);
|
||||
void AudioThread_SetFadeInTimer(s32 seqPlayId, s32 fadeTime);
|
||||
|
||||
extern AudioTable gSampleBankTableInit;
|
||||
|
||||
OSMesgQueue sAudioTaskStartQueue;
|
||||
OSMesgQueue sThreadCmdProcQueue;
|
||||
@@ -11,27 +18,230 @@ OSMesg sThreadCmdProcMsg[4];
|
||||
OSMesg sAudioUnkMsg[1];
|
||||
OSMesg sAudioResetMsg[1];
|
||||
|
||||
s8 gThreadCmdWritePos = 0;
|
||||
s8 gThreadCmdReadPos = 0;
|
||||
u8 gThreadCmdWritePos = 0;
|
||||
u8 gThreadCmdReadPos = 0;
|
||||
OSMesgQueue* gAudioTaskStartQueue = &sAudioTaskStartQueue;
|
||||
OSMesgQueue* gThreadCmdProcQueue = &sThreadCmdProcQueue;
|
||||
OSMesgQueue* gAudioUnkQueue = &sAudioUnkQueue;
|
||||
OSMesgQueue* gAudioResetQueue = &sAudioResetQueue;
|
||||
s32 gMaxAbiCmdCnt = 128;
|
||||
AudioTask* gWaitingAudioTask = NULL;
|
||||
s32 D_800C7C70 = 0;
|
||||
u8 gCurCmdReadPos = 0;
|
||||
u8 gThreadCmdQueueFinished = 0;
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001DF50.s")
|
||||
static const char devstr0[] = "DAC:Lost 1 Frame.\n";
|
||||
static const char devstr1[] = "DMA: Request queue over.( %d )\n";
|
||||
static const char devstr2[] = "Spec Change Override. %d -> %d\n";
|
||||
static const char devstr3[] = "Audio:now-max tasklen is %d / %d\n";
|
||||
static const char devstr4[] = "Audio:Warning:ABI Tasklist length over (%d)\n";
|
||||
static const char devstr5[] = "BGLOAD Start %d\n";
|
||||
static const char devstr6[] = "Error: OverFlow Your Request\n";
|
||||
static const char devstr7[] = "---AudioSending (%d->%d) \n";
|
||||
static const char devstr8[] = "AudioSend: %d -> %d (%d)\n";
|
||||
static const char devstr9[] = "Continue Port\n";
|
||||
static const char devstr10[] = "%d -> %d\n";
|
||||
static const char devstr11[] = "Sync-Frame Break. (Remain %d)\n";
|
||||
static const char devstr12[] = "Undefined Port Command %d\n";
|
||||
static const char devstr13[] = "specchg conjunction error (Msg:%d Cur:%d)\n";
|
||||
static const char devstr14[] = "Error : Queue is not empty ( %x ) \n";
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001E444.s")
|
||||
SPTask* AudioThread_CreateTask(void) {
|
||||
static s32 gMaxAbiCmdCnt = 128;
|
||||
static SPTask* gWaitingAudioTask = NULL;
|
||||
u32 sp54;
|
||||
s32 sp50;
|
||||
s32 sp4C;
|
||||
s32 pad48;
|
||||
OSTask_t* task;
|
||||
u16* sp40;
|
||||
s32 pad3C;
|
||||
u32 sp38;
|
||||
u32 sp34;
|
||||
s32 pad30;
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001E720.s")
|
||||
gAudioTaskCountQ++;
|
||||
if ((gAudioTaskCountQ % gAudioBufferParams.specUnk4) != 0) {
|
||||
return gWaitingAudioTask;
|
||||
}
|
||||
osSendMesg(gAudioTaskStartQueue, (OSMesg) gAudioTaskCountQ, 0);
|
||||
gAudioTaskIndexQ ^= 1;
|
||||
gCurAiBuffIndex++;
|
||||
gCurAiBuffIndex %= 3;
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001E778.s")
|
||||
sp4C = (gCurAiBuffIndex + 1) % 3;
|
||||
sp54 = osAiGetLength() >> 2;
|
||||
if ((gResetTimer < 16) && (gAiBuffLengths[sp4C] != 0)) {
|
||||
osAiSetNextBuffer(gAiBuffers[sp4C], gAiBuffLengths[sp4C] * 4);
|
||||
}
|
||||
if (gCurAudioFrameDmaCount && gCurAudioFrameDmaCount) {}
|
||||
gCurAudioFrameDmaCount = 0;
|
||||
AudioLoad_DecreaseSampleDmaTtls();
|
||||
AudioLoad_ProcessLoads(gResetStatus);
|
||||
if (osRecvMesg(gAudioUnkQueue, (OSMesg) &sp38, 0) != -1) {
|
||||
if (gResetStatus == 0) {
|
||||
gResetStatus = 5;
|
||||
}
|
||||
gAudioSpecId = sp38;
|
||||
}
|
||||
if ((gResetStatus != 0) && (AudioHeap_ResetStep() == 0)) {
|
||||
if (gResetStatus == 0) {
|
||||
osSendMesg(gAudioResetQueue, (OSMesg) (s32) gAudioSpecId, 0);
|
||||
}
|
||||
gWaitingAudioTask = NULL;
|
||||
return NULL;
|
||||
}
|
||||
if (gResetTimer > 16) {
|
||||
return NULL;
|
||||
}
|
||||
if (gResetTimer != 0) {
|
||||
gResetTimer++;
|
||||
}
|
||||
gAudioCurTask = &gAudioRspTasks[gAudioTaskIndexQ];
|
||||
gCurAbiCmdBuffer = gAbiCmdBuffs[gAudioTaskIndexQ];
|
||||
sp4C = gCurAiBuffIndex;
|
||||
sp40 = gAiBuffers[sp4C];
|
||||
gAiBuffLengths[sp4C] = ((gAudioBufferParams.samplesPerFrameTarget - sp54 + 0x80) & ~0xF) + 0x10;
|
||||
|
||||
void func_8001E7C8(void) {
|
||||
if (gAiBuffLengths[sp4C] < gAudioBufferParams.minAiBufferLength) {
|
||||
gAiBuffLengths[sp4C] = gAudioBufferParams.minAiBufferLength;
|
||||
}
|
||||
if (gAiBuffLengths[sp4C] > gAudioBufferParams.maxAiBufferLength) {
|
||||
gAiBuffLengths[sp4C] = gAudioBufferParams.maxAiBufferLength;
|
||||
}
|
||||
while (osRecvMesg(gThreadCmdProcQueue, (OSMesg) &sp34, 0) != -1) {
|
||||
AudioThread_ProcessCmds(sp34);
|
||||
}
|
||||
gCurAbiCmdBuffer = func_80009B64(gCurAbiCmdBuffer, &sp50, sp40, gAiBuffLengths[sp4C]);
|
||||
gAudioRandom = osGetCount() * (gAudioRandom + gAudioTaskCountQ);
|
||||
gAudioRandom = gAiBuffers[sp4C][gAudioTaskCountQ & 0xFF] + gAudioRandom;
|
||||
|
||||
sp4C = gAudioTaskIndexQ;
|
||||
|
||||
gAudioCurTask->msgQueue = NULL;
|
||||
gAudioCurTask->msg = NULL;
|
||||
|
||||
task = &gAudioCurTask->task.t;
|
||||
|
||||
task->type = 2;
|
||||
task->flags = 0;
|
||||
task->ucode_boot = rspbootTextStart;
|
||||
task->ucode_boot_size = (uintptr_t) rspbootTextEnd - (uintptr_t) rspbootTextStart;
|
||||
|
||||
task->ucode = aspMainTextStart;
|
||||
task->ucode_data = aspMainDataStart;
|
||||
task->ucode_size = SP_UCODE_SIZE;
|
||||
task->ucode_data_size = (aspMainDataEnd - aspMainDataStart) * 8;
|
||||
|
||||
task->dram_stack = NULL;
|
||||
task->dram_stack_size = 0;
|
||||
|
||||
task->output_buff = NULL;
|
||||
task->output_buff_size = NULL;
|
||||
if (1) {}
|
||||
task->data_ptr = (u64*) gAbiCmdBuffs[sp4C];
|
||||
task->data_size = sp50 * sizeof(Acmd);
|
||||
|
||||
task->yield_data_ptr = NULL;
|
||||
task->yield_data_size = 0;
|
||||
|
||||
if (gMaxAbiCmdCnt < sp50) {
|
||||
gMaxAbiCmdCnt = sp50;
|
||||
}
|
||||
|
||||
if (gAudioBufferParams.specUnk4 == 1) {
|
||||
return gAudioCurTask;
|
||||
} else {
|
||||
gWaitingAudioTask = gAudioCurTask;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioThread_ProcessGlobalCmd(AudioCmd* cmd) {
|
||||
s32 i;
|
||||
|
||||
switch (cmd->op) {
|
||||
case AUDIOCMD_OP_GLOBAL_SYNC_LOAD_SEQ_PARTS:
|
||||
AudioLoad_SyncLoadSeqParts(cmd->arg1, 3);
|
||||
break;
|
||||
case AUDIOCMD_OP_GLOBAL_INIT_SEQPLAYER:
|
||||
case 0x88:
|
||||
AudioLoad_SyncInitSeqPlayer(cmd->arg0, cmd->arg1, cmd->arg2);
|
||||
AudioThread_SetFadeInTimer(cmd->arg0, cmd->data);
|
||||
break;
|
||||
case AUDIOCMD_OP_GLOBAL_DISABLE_SEQPLAYER:
|
||||
if (gSeqPlayers[cmd->arg0].enabled) {
|
||||
if (cmd->asInt == 0) {
|
||||
func_800144E4(&gSeqPlayers[cmd->arg0]);
|
||||
} else {
|
||||
AudioThread_SetFadeOutTimer(cmd->arg0, cmd->asInt);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0x84:
|
||||
break;
|
||||
case AUDIOCMD_OP_GLOBAL_SET_SOUND_MODE:
|
||||
gAudioSoundMode = cmd->asUInt;
|
||||
break;
|
||||
case AUDIOCMD_OP_GLOBAL_MUTE:
|
||||
for (i = 0; i < 4; i++) {
|
||||
SequencePlayer* seqplayer = &gSeqPlayers[i];
|
||||
|
||||
seqplayer->muted = true;
|
||||
seqplayer->recalculateVolume = true;
|
||||
}
|
||||
break;
|
||||
case AUDIOCMD_OP_GLOBAL_UNMUTE:
|
||||
if (cmd->asUInt == 1) {
|
||||
for (i = 0; i < gNumNotes; i++) {
|
||||
Note* note = &gNotes[i];
|
||||
NoteSubEu* noteSub = ¬e->noteSubEu;
|
||||
|
||||
if ((noteSub->bitField0.enabled) && (note->playbackState.unk_04 == 0) &&
|
||||
(note->playbackState.parentLayer != NO_LAYER) &&
|
||||
(note->playbackState.parentLayer->channel->muteBehavior & 8)) {
|
||||
noteSub->bitField0.finished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < 4; i++) {
|
||||
SequencePlayer* seqplayer = &gSeqPlayers[i];
|
||||
|
||||
seqplayer->muted = false;
|
||||
seqplayer->recalculateVolume = true;
|
||||
}
|
||||
break;
|
||||
case AUDIOCMD_OP_GLOBAL_SYNC_LOAD_INSTRUMENT:
|
||||
AudioLoad_SyncLoadInstrument(cmd->arg0, cmd->arg1, cmd->arg2);
|
||||
break;
|
||||
case AUDIOCMD_OP_GLOBAL_ASYNC_LOAD_SAMPLE_BANK:
|
||||
AudioLoad_AsyncLoadSampleBank(cmd->arg0, cmd->arg1, cmd->arg2, &gExternalLoadQueue);
|
||||
break;
|
||||
case AUDIOCMD_OP_GLOBAL_ASYNC_LOAD_FONT:
|
||||
AudioLoad_AsyncLoadSeq(cmd->arg0, cmd->arg1, cmd->arg2, &gExternalLoadQueue);
|
||||
break;
|
||||
case AUDIOCMD_OP_GLOBAL_DISCARD_SEQ_FONTS:
|
||||
AudioLoad_DiscardSeqFonts(cmd->arg1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioThread_SetFadeOutTimer(s32 seqPlayId, s32 fadeTime) {
|
||||
if (fadeTime == 0) {
|
||||
fadeTime = 1;
|
||||
}
|
||||
|
||||
gSeqPlayers[seqPlayId].state = 2;
|
||||
gSeqPlayers[seqPlayId].fadeTimer = fadeTime;
|
||||
gSeqPlayers[seqPlayId].fadeVelocity = -(gSeqPlayers[seqPlayId].fadeVolume / fadeTime);
|
||||
}
|
||||
|
||||
void AudioThread_SetFadeInTimer(s32 seqPlayId, s32 fadeTime) {
|
||||
if (fadeTime != 0) {
|
||||
gSeqPlayers[seqPlayId].state = 1;
|
||||
gSeqPlayers[seqPlayId].fadeTimerUnkEu = fadeTime;
|
||||
gSeqPlayers[seqPlayId].fadeTimer = fadeTime;
|
||||
gSeqPlayers[seqPlayId].fadeVolume = 0.0f;
|
||||
gSeqPlayers[seqPlayId].fadeVelocity = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioThread_InitQueues(void) {
|
||||
gThreadCmdWritePos = 0;
|
||||
gThreadCmdReadPos = 0;
|
||||
osCreateMesgQueue(gAudioTaskStartQueue, sAudioTaskStartMsg, 1);
|
||||
@@ -40,30 +250,187 @@ void func_8001E7C8(void) {
|
||||
osCreateMesgQueue(gAudioResetQueue, sAudioResetMsg, 1);
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/AudioThread_QueueCmd.s")
|
||||
void AudioThread_QueueCmd(u32 opArgs, void** data) {
|
||||
AudioCmd* audioCmd = &gThreadCmdBuffer[gThreadCmdWritePos & 0xFF];
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/AudioThread_QueueCmdF32.s")
|
||||
audioCmd->opArgs = opArgs;
|
||||
audioCmd->data = *data;
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/AudioThread_QueueCmdS32.s")
|
||||
gThreadCmdWritePos++;
|
||||
if (gThreadCmdWritePos == gThreadCmdReadPos) {
|
||||
gThreadCmdWritePos--;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/AudioThread_QueueCmdS8.s")
|
||||
void AudioThread_QueueCmdF32(u32 opArgs, f32 val) {
|
||||
AudioThread_QueueCmd(opArgs, (void**) &val);
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001E920.s")
|
||||
void AudioThread_QueueCmdS32(u32 opArgs, u32 val) {
|
||||
AudioThread_QueueCmd(opArgs, (void**) &val);
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001E998.s")
|
||||
void AudioThread_QueueCmdS8(u32 opArgs, s8 val) {
|
||||
s32 data = val << 0x18;
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001E9AC.s")
|
||||
AudioThread_QueueCmd(opArgs, (void**) &data);
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001ECAC.s")
|
||||
void AudioThread_ScheduleProcessCmds(void) {
|
||||
static s32 D_800C7C70 = 0;
|
||||
s32 msg;
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001ED14.s")
|
||||
if (D_800C7C70 < (u8) (gThreadCmdWritePos - gThreadCmdReadPos + 0x100)) {
|
||||
D_800C7C70 = (u8) (gThreadCmdWritePos - gThreadCmdReadPos + 0x100);
|
||||
}
|
||||
msg = (((gThreadCmdReadPos & 0xFF) << 8) | (gThreadCmdWritePos & 0xFF));
|
||||
osSendMesg(gThreadCmdProcQueue, (OSMesg) msg, 0);
|
||||
gThreadCmdReadPos = gThreadCmdWritePos;
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001ED34.s")
|
||||
void AudioThread_ResetCmdQueue(void) {
|
||||
gThreadCmdReadPos = gThreadCmdWritePos;
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001ED8C.s")
|
||||
void AudioThread_ProcessCmds(u32 msg) {
|
||||
static u8 gCurCmdReadPos = 0;
|
||||
static u8 gThreadCmdQueueFinished = false;
|
||||
AudioCmd* cmd;
|
||||
SequenceChannel* channel;
|
||||
SequencePlayer* player;
|
||||
u8 writePos;
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001EE00.s")
|
||||
if (!gThreadCmdQueueFinished) {
|
||||
gCurCmdReadPos = (msg >> 8) & 0xFF;
|
||||
}
|
||||
writePos = msg & 0xFF;
|
||||
while (true) {
|
||||
if (gCurCmdReadPos == writePos) {
|
||||
gThreadCmdQueueFinished = 0;
|
||||
break;
|
||||
}
|
||||
cmd = &gThreadCmdBuffer[gCurCmdReadPos & 0xFF];
|
||||
gCurCmdReadPos++;
|
||||
if (cmd->op == AUDIOCMD_OP_GLOBAL_STOP_AUDIOCMDS) {
|
||||
gThreadCmdQueueFinished = true;
|
||||
break;
|
||||
}
|
||||
if ((cmd->op & 0xF0) == 0xF0) {
|
||||
AudioThread_ProcessGlobalCmd(cmd);
|
||||
} else if (cmd->arg0 < 4) {
|
||||
player = &gSeqPlayers[cmd->arg0];
|
||||
if (cmd->op & 0x80) {
|
||||
AudioThread_ProcessGlobalCmd(cmd);
|
||||
} else if (cmd->op & 0x40) {
|
||||
switch (cmd->op) {
|
||||
case AUDIOCMD_OP_SEQPLAYER_FADE_VOLUME_SCALE:
|
||||
if (player->fadeVolumeMod != cmd->asFloat) {
|
||||
player->fadeVolumeMod = cmd->asFloat;
|
||||
player->recalculateVolume = true;
|
||||
}
|
||||
break;
|
||||
case AUDIOCMD_OP_SEQPLAYER_SET_TEMPO: /* switch 1 */
|
||||
player->tempo = cmd->asInt * 48;
|
||||
break;
|
||||
case AUDIOCMD_OP_SEQPLAYER_SET_TRANSPOSITION: /* switch 1 */
|
||||
player->transposition = cmd->asSbyte;
|
||||
break;
|
||||
case 0x46: // AUDIOCMD_OP_SEQPLAYER_SET_IO?
|
||||
player->unk_07[cmd->arg2] = cmd->asSbyte;
|
||||
break;
|
||||
}
|
||||
} else if ((player->enabled) && (cmd->arg1 < 16)) {
|
||||
channel = player->channels[cmd->arg1];
|
||||
if (channel != &gSeqChannelNone) {
|
||||
switch (cmd->op) {
|
||||
case AUDIOCMD_OP_CHANNEL_SET_VOL_SCALE:
|
||||
if (channel->volumeMod != cmd->asFloat) {
|
||||
channel->volumeMod = cmd->asFloat;
|
||||
channel->changes.s.volume = true;
|
||||
}
|
||||
break;
|
||||
case AUDIOCMD_OP_CHANNEL_SET_VOL:
|
||||
if (channel->volume != cmd->asFloat) {
|
||||
channel->volume = cmd->asFloat;
|
||||
channel->changes.s.volume = true;
|
||||
}
|
||||
break;
|
||||
case AUDIOCMD_OP_CHANNEL_SET_PAN:
|
||||
if (channel->newPan != cmd->asSbyte) {
|
||||
channel->newPan = cmd->asSbyte;
|
||||
channel->changes.s.pan = true;
|
||||
}
|
||||
break;
|
||||
case AUDIOCMD_OP_CHANNEL_SET_FREQ_SCALE:
|
||||
if (channel->freqMod != cmd->asFloat) {
|
||||
channel->freqMod = cmd->asFloat;
|
||||
channel->changes.s.freqMod = true;
|
||||
}
|
||||
break;
|
||||
case AUDIOCMD_OP_CHANNEL_SET_REVERB_VOLUME:
|
||||
if (channel->targetReverbVol != cmd->asSbyte) {
|
||||
channel->targetReverbVol = cmd->asSbyte;
|
||||
}
|
||||
break;
|
||||
case AUDIOCMD_OP_CHANNEL_SET_IO:
|
||||
if (cmd->arg2 < 8) {
|
||||
channel->seqScriptIO[cmd->arg2] = cmd->asSbyte;
|
||||
}
|
||||
break;
|
||||
case AUDIOCMD_OP_CHANNEL_SET_MUTE:
|
||||
channel->muted = cmd->asSbyte;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cmd->op = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/func_8001EE3C.s")
|
||||
u32 AudioThread_GetAsyncLoadStatus(u32* outData) {
|
||||
u32 sp1C;
|
||||
|
||||
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/audio_thread/D_800C90F0.s")
|
||||
if (osRecvMesg(&gExternalLoadQueue, (OSMesg*) &sp1C, 0) == -1) {
|
||||
*outData = 0;
|
||||
return 0;
|
||||
}
|
||||
*outData = sp1C & 0xFFFFFF;
|
||||
return sp1C >> 0x18;
|
||||
}
|
||||
|
||||
u8* AudioThread_GetFontsForSequence(s32 seqId, u32* outNumFonts) {
|
||||
return AudioLoad_GetFontsForSequence(seqId, outNumFonts);
|
||||
}
|
||||
|
||||
s32 func_8001ED34(void) {
|
||||
s32 pad;
|
||||
s32 sp18;
|
||||
|
||||
if (osRecvMesg(gAudioResetQueue, (OSMesg*) &sp18, 0) == -1) {
|
||||
return 0;
|
||||
}
|
||||
if (sp18 != gAudioSpecId) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void AudioThread_ResetAudioHeap(s32 specId) {
|
||||
// clang-format off
|
||||
s32 m1 = -1;OSMesg sp28;do {} while (osRecvMesg(gAudioResetQueue, &sp28, 0) != m1);
|
||||
// clang-format on
|
||||
|
||||
AudioThread_ResetCmdQueue();
|
||||
osSendMesg(gAudioUnkQueue, (OSMesg) specId, 0);
|
||||
}
|
||||
|
||||
void AudioThread_PreNMIReset(void) {
|
||||
gResetTimer = 1;
|
||||
AudioThread_ResetAudioHeap(0);
|
||||
gResetStatus = 0;
|
||||
}
|
||||
|
||||
void AudioThread_Init(void) {
|
||||
AudioThread_InitQueues();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ void Graphics_NMIWipe(void) {
|
||||
Graphics_FillRectangle(&gMasterDisp, SCREEN_WIDTH - 8 - MIN(304, D_800D4A80), 176, SCREEN_WIDTH - 8, 232, 0, 0, 0,
|
||||
255);
|
||||
if (D_800D4A80 == 0) {
|
||||
func_8001EE00();
|
||||
AudioThread_PreNMIReset();
|
||||
}
|
||||
D_800D4A80 += 45;
|
||||
if (D_800D4A80 >= 485) {
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
#include "sys.h"
|
||||
|
||||
void AudioLoad_Init(void);
|
||||
SPTask* func_8001DF50(void);
|
||||
SPTask* AudioThread_CreateTask(void);
|
||||
void Audio_InitSounds(void);
|
||||
void Audio_Update(void);
|
||||
|
||||
@@ -109,7 +109,7 @@ void Audio_ThreadEntry(void* arg0) {
|
||||
|
||||
AudioLoad_Init();
|
||||
Audio_InitSounds();
|
||||
task = func_8001DF50();
|
||||
task = AudioThread_CreateTask();
|
||||
if (task != NULL) {
|
||||
task->msgQueue = &gAudioTaskMsgQueue;
|
||||
task->msg = (OSMesg) TASK_MESG_1;
|
||||
@@ -117,7 +117,7 @@ void Audio_ThreadEntry(void* arg0) {
|
||||
osSendMesg(&gTaskMsgQueue, task, OS_MESG_PRI_NORMAL);
|
||||
}
|
||||
while (1) {
|
||||
task = func_8001DF50();
|
||||
task = AudioThread_CreateTask();
|
||||
if (task != NULL) {
|
||||
task->msgQueue = &gAudioTaskMsgQueue;
|
||||
task->msg = (OSMesg) TASK_MESG_1;
|
||||
|
||||
Reference in New Issue
Block a user