1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-08-11 17:30:25 +00:00

Document Audio Thread Commands (#1399)

* begin docs

* cleanup

* copy over progress

* cleanup

* small cleanup

* more docs, fill out cmds

* small touchup

* pan weight ganon comment

* fix specId

* seqcmd cleanup

* format

* small cleanup

* one more thing

* small feedback from MM

* partial PR

* some PR Suggestions

* small adjustments

* ticks, seqticks, frames, updates: term cleanup

* small fix

* PR Review

* PR Review

* PR Review

* rm param

* adjust comment

* update renamed functions

* format

---------

Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>
This commit is contained in:
engineer124 2024-02-01 10:25:23 +11:00 committed by GitHub
parent d65fb6ed28
commit a0d31dba68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 1393 additions and 842 deletions

View file

@ -30,7 +30,7 @@ u8 sSfxBankListEnd[7];
u8 sSfxBankFreeListStart[7];
u8 sSfxBankUnused[7];
ActiveSfx gActiveSfx[7][3];
u8 sCurSfxPlayerChannelIdx;
u8 sCurSfxPlayerChannelIndex;
u8 gSfxBankMuted[7];
UnusedBankLerp sUnusedBankLerp[7];
u16 gAudioSfxSwapSource[10];
@ -50,14 +50,14 @@ void Audio_SetSfxBanksMute(u16 muteMask) {
}
}
void Audio_QueueSeqCmdMute(u8 channelIdx) {
D_801333D0 |= (1 << channelIdx);
void Audio_QueueSeqCmdMute(u8 channelIndex) {
D_801333D0 |= (1 << channelIndex);
Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_SFX, 0x40, 0xF);
Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, VOL_SCALE_INDEX_SFX, 0x40, 0xF);
}
void Audio_ClearBGMMute(u8 channelIdx) {
D_801333D0 &= ((1 << channelIdx) ^ 0xFFFF);
void Audio_ClearBGMMute(u8 channelIndex) {
D_801333D0 &= ((1 << channelIndex) ^ 0xFFFF);
if (D_801333D0 == 0) {
Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_SFX, 0x7F, 0xF);
Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, VOL_SCALE_INDEX_SFX, 0x7F, 0xF);
@ -211,7 +211,7 @@ void Audio_ProcessSfxRequest(void) {
if ((req->sfxId & 0xC00) || (sfxParams->params & SFX_FLAG_2) || (index == evictIndex)) {
if ((gSfxBanks[bankId][index].sfxParams & SFX_FLAG_3) &&
gSfxBanks[bankId][index].state != SFX_STATE_QUEUED) {
Audio_ClearBGMMute(gSfxBanks[bankId][index].channelIdx);
Audio_ClearBGMMute(gSfxBanks[bankId][index].channelIndex);
}
gSfxBanks[bankId][index].token = req->token;
gSfxBanks[bankId][index].sfxId = req->sfxId;
@ -262,7 +262,7 @@ void Audio_RemoveSfxBankEntry(u8 bankId, u8 entryIndex) {
u8 i;
if (entry->sfxParams & SFX_FLAG_3) {
Audio_ClearBGMMute(entry->channelIdx);
Audio_ClearBGMMute(entry->channelIndex);
}
if (entryIndex == sSfxBankListEnd[bankId]) {
sSfxBankListEnd[bankId] = entry->prev;
@ -314,7 +314,7 @@ void Audio_ChooseActiveSfx(u8 bankId) {
gSfxBanks[bankId][entryIndex].freshness--;
} else if (!(gSfxBanks[bankId][entryIndex].sfxId & 0xC00) &&
(gSfxBanks[bankId][entryIndex].state == SFX_STATE_PLAYING_2)) {
Audio_QueueCmdS8((gSfxBanks[bankId][entryIndex].channelIdx << 8) | 0x6020000, 0);
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, gSfxBanks[bankId][entryIndex].channelIndex, 0, 0);
Audio_RemoveSfxBankEntry(bankId, entryIndex);
}
if (gSfxBanks[bankId][entryIndex].freshness == 0) {
@ -346,7 +346,7 @@ void Audio_ChooseActiveSfx(u8 bankId) {
}
if (entry->dist > SQ(1e5f)) {
if (entry->state == SFX_STATE_PLAYING_1) {
Audio_QueueCmdS8((entry->channelIdx << 8) | 0x6020000, 0);
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
if (entry->sfxId & 0xC00) {
Audio_RemoveSfxBankEntry(bankId, entryIndex);
entryIndex = k;
@ -451,45 +451,51 @@ void Audio_PlayActiveSfx(u8 bankId) {
entryIndex = gActiveSfx[bankId][i].entryIndex;
if (entryIndex != 0xFF) {
entry = &gSfxBanks[bankId][entryIndex];
channel = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIdx];
channel = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIndex];
if (entry->state == SFX_STATE_READY) {
entry->channelIdx = sCurSfxPlayerChannelIdx;
entry->channelIndex = sCurSfxPlayerChannelIndex;
if (entry->sfxParams & SFX_FLAG_3) {
Audio_QueueSeqCmdMute(sCurSfxPlayerChannelIdx);
Audio_QueueSeqCmdMute(sCurSfxPlayerChannelIndex);
}
if ((entry->sfxParams & SFX_PARAM_67_MASK) != (0 << SFX_PARAM_67_SHIFT)) {
switch (entry->sfxParams & SFX_PARAM_67_MASK) {
case (1 << SFX_PARAM_67_SHIFT):
entry->unk_2F = Audio_NextRandom() & 0xF;
entry->unk_2F = AudioThread_NextRandom() & 0xF;
break;
case (2 << SFX_PARAM_67_SHIFT):
entry->unk_2F = Audio_NextRandom() & 0x1F;
entry->unk_2F = AudioThread_NextRandom() & 0x1F;
break;
case (3 << SFX_PARAM_67_SHIFT):
entry->unk_2F = Audio_NextRandom() & 0x3F;
entry->unk_2F = AudioThread_NextRandom() & 0x3F;
break;
default:
entry->unk_2F = 0;
break;
}
}
Audio_SetSfxProperties(bankId, entryIndex, sCurSfxPlayerChannelIdx);
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((sCurSfxPlayerChannelIdx & 0xFF) << 8), 1);
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((sCurSfxPlayerChannelIdx & 0xFF) << 8) | 4,
entry->sfxId & 0xFF);
Audio_SetSfxProperties(bankId, entryIndex, sCurSfxPlayerChannelIndex);
// ioPort 0, enable the sfx to play in `NA_BGM_GENERAL_SFX`
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, sCurSfxPlayerChannelIndex, 0, 1);
// ioPort 4, write the lower bits sfx index for `NA_BGM_GENERAL_SFX` to find the right code to execute
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, sCurSfxPlayerChannelIndex, 4, entry->sfxId & 0xFF);
// If the sfx bank has more than 255 entries (greater than a u8 can store),
// then store the Id in upper and lower bits
if (gIsLargeSfxBank[bankId]) {
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((sCurSfxPlayerChannelIdx & 0xFF) << 8) | 5,
(entry->sfxId & 0x100) >> 8);
// ioPort 5, write the upper bits sfx index for `NA_BGM_GENERAL_SFX`, for banks with > 0xFF entries
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, sCurSfxPlayerChannelIndex, 5, (entry->sfxId & 0x100) >> 8);
}
if (entry->sfxId & 0xC00) {
entry->state = SFX_STATE_PLAYING_1;
} else {
entry->state = SFX_STATE_PLAYING_2;
}
} else if ((u8)channel->soundScriptIO[1] == (u8)SEQ_IO_VAL_NONE) {
} else if ((u8)channel->seqScriptIO[1] == (u8)SEQ_IO_VAL_NONE) {
Audio_RemoveSfxBankEntry(bankId, entryIndex);
} else if (entry->state == SFX_STATE_PLAYING_REFRESH) {
Audio_SetSfxProperties(bankId, entryIndex, sCurSfxPlayerChannelIdx);
Audio_SetSfxProperties(bankId, entryIndex, sCurSfxPlayerChannelIndex);
if (entry->sfxId & 0xC00) {
entry->state = SFX_STATE_PLAYING_1;
} else {
@ -497,7 +503,7 @@ void Audio_PlayActiveSfx(u8 bankId) {
}
}
}
sCurSfxPlayerChannelIdx++;
sCurSfxPlayerChannelIndex++;
}
}
@ -510,7 +516,7 @@ void Audio_StopSfxByBank(u8 bankId) {
while (entryIndex != 0xFF) {
entry = &gSfxBanks[bankId][entryIndex];
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((entry->channelIdx & 0xFF) << 8), 0);
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
}
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSfxBankEntry(bankId, entryIndex);
@ -530,7 +536,7 @@ void func_800F8884(u8 bankId, Vec3f* pos) {
entry = &gSfxBanks[bankId][entryIndex];
if (entry->posX == &pos->x) {
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((entry->channelIdx & 0xFF) << 8), 0);
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
}
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSfxBankEntry(bankId, entryIndex);
@ -572,7 +578,7 @@ void Audio_StopSfxByPosAndId(Vec3f* pos, u16 sfxId) {
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->posX == &pos->x && entry->sfxId == sfxId) {
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((entry->channelIdx & 0xFF) << 8), 0);
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
}
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSfxBankEntry(SFX_BANK(sfxId), entryIndex);
@ -600,7 +606,7 @@ void Audio_StopSfxByTokenAndId(u8 token, u16 sfxId) {
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->token == token && entry->sfxId == sfxId) {
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((entry->channelIdx & 0xFF) << 8), 0);
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
}
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSfxBankEntry(SFX_BANK(sfxId), entryIndex);
@ -627,7 +633,7 @@ void Audio_StopSfxById(u32 sfxId) {
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->sfxId == sfxId) {
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((entry->channelIdx & 0xFF) << 8), 0);
AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
}
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSfxBankEntry(SFX_BANK(sfxId), entryIndex);
@ -672,7 +678,7 @@ void func_800F8F88(void) {
u8 bankId;
if (IS_SEQUENCE_CHANNEL_VALID(gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[0])) {
sCurSfxPlayerChannelIdx = 0;
sCurSfxPlayerChannelIndex = 0;
for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) {
Audio_ChooseActiveSfx(bankId);
Audio_PlayActiveSfx(bankId);