summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorengineer124 <47598039+engineer124@users.noreply.github.com>2022-10-07 07:29:33 -0400
committerGitHub <noreply@github.com>2022-10-07 13:29:33 +0200
commit062f4d8e158a5f497efad26910d1c799fed3184e (patch)
treecf363b6fc08fe61c7ee9158ed21a9d759b2f018e /src/code
parenta99d41bf35d560996e252dd7db18bd488e98f70c (diff)
Document code_800F9280.c -> audio_seqcmd.c i.e. (Audio_QueueSeqCmd) (#1234)
* Document SoundSources * PR Suggestions * Duration timers to dec * `PlaySfxByPosAndId` -> `PlaySoundByPosition` * Begin importing docs from MM * Finish cleanup using code from MM * Start documenting commands * First attempt at thorough AudioSeqCmd wrappers * Improve names * Merge branch 'master' into audio_seqCmd fix name to minimize conflicts * Combine macros, implement them through repo * Improve docs * More progress, begin sequence command docs * seqcmd.h * More documentation of seqcmd.h * More docs * cleanup * More cleanup * More docs * VOL_SCALE_INDEX enum * missed enums * More Cleanup * docs * More docs * Add comments about sfxChannelLayout * More cleanup * Even better docs * Add a file description * small touchups * More cleanup of comments * more * More cleanup * More cleanup * Missing space * typos * Audio_SetVolumeScaleNow * More cleanup * Fill in enum * one more cleanup * Capitalize macros * remove AUDIO_ * cleanup * more cleanup * Small Fix * Add a lot of backticks for docs * Restructuring docs * More cleanup * swap channel args, cleanup * Typos * Many suggestions, revert filename * pr suggestions * even more PR * more pr suggestions * pr suggestion
Diffstat (limited to 'src/code')
-rw-r--r--src/code/audio_external_data.c8
-rw-r--r--src/code/code_800EC960.c357
-rw-r--r--src/code/code_800F7260.c8
-rw-r--r--src/code/code_800F9280.c910
-rw-r--r--src/code/z_demo.c8
-rw-r--r--src/code/z_kankyo.c6
-rw-r--r--src/code/z_scene.c2
7 files changed, 707 insertions, 592 deletions
diff --git a/src/code/audio_external_data.c b/src/code/audio_external_data.c
index 3dcf0fd1d..6a4c29eda 100644
--- a/src/code/audio_external_data.c
+++ b/src/code/audio_external_data.c
@@ -52,10 +52,10 @@ u8 D_801333F8 = 0;
s32 D_801333FC = 0; // unused
-u8 gSeqCmdWrPos = 0;
-u8 gSeqCmdRdPos = 0;
-u8 D_80133408 = 0;
-u8 D_8013340C = 1;
+u8 gSeqCmdWritePos = 0;
+u8 gSeqCmdReadPos = 0;
+u8 gStartSeqDisabled = false;
+u8 gAudioDebugPrintSeqCmd = true;
u8 gSoundModeList[] = {
SOUNDMODE_STEREO,
diff --git a/src/code/code_800EC960.c b/src/code/code_800EC960.c
index db828c39a..c34d00a6b 100644
--- a/src/code/code_800EC960.c
+++ b/src/code/code_800EC960.c
@@ -1,27 +1,7 @@
#include "ultra64.h"
#include "global.h"
-// TODO: can these macros be shared between files? code_800F9280 seems to use
-// versions without any casts...
-#define Audio_DisableSeq(playerIdx, fadeOut) Audio_QueueCmdS32(0x83000000 | ((u8)playerIdx << 16), fadeOut)
-#define Audio_StartSeq(playerIdx, fadeTimer, seqId) \
- Audio_QueueSeqCmd(0x00000000 | ((u8)playerIdx << 24) | ((u8)(fadeTimer) << 0x10) | (u16)seqId)
-#define Audio_SeqCmd7(playerIdx, a, b) \
- Audio_QueueSeqCmd(0x70000000 | ((u8)playerIdx << 0x18) | ((u8)a << 0x10) | (u8)(b))
-#define Audio_SeqCmdC(playerIdx, a, b, c) \
- Audio_QueueSeqCmd(0xC0000000 | ((u8)playerIdx << 24) | ((u8)a << 16) | ((u8)b << 8) | ((u8)(c)))
-#define Audio_SeqCmdA(playerIdx, a) Audio_QueueSeqCmd(0xA0000000 | ((u8)playerIdx << 24) | ((u16)(a)))
-#define Audio_SeqCmd1(playerIdx, a) Audio_QueueSeqCmd(0x100000FF | ((u8)playerIdx << 24) | ((u8)(a) << 16))
-#define Audio_SeqCmdB(playerIdx, a, b, c) \
- Audio_QueueSeqCmd(0xB0000000 | ((u8)playerIdx << 24) | ((u8)a << 16) | ((u8)b << 8) | ((u8)c))
-#define Audio_SeqCmdB40(playerIdx, a, b) Audio_QueueSeqCmd(0xB0004000 | ((u8)playerIdx << 24) | ((u8)a << 16) | ((u8)b))
-#define Audio_SeqCmd6(playerIdx, a, b, c) \
- Audio_QueueSeqCmd(0x60000000 | ((u8)playerIdx << 24) | ((u8)(a) << 16) | ((u8)b << 8) | ((u8)c))
-#define Audio_SeqCmdE0(playerIdx, a) Audio_QueueSeqCmd(0xE0000000 | ((u8)playerIdx << 24) | ((u8)a))
-#define Audio_SeqCmdE01(playerIdx, a) Audio_QueueSeqCmd(0xE0000100 | ((u8)playerIdx << 24) | ((u16)a))
-#define Audio_SeqCmd8(playerIdx, a, b, c) \
- Audio_QueueSeqCmd(0x80000000 | ((u8)playerIdx << 24) | ((u8)a << 16) | ((u8)b << 8) | ((u8)c))
-#define Audio_SeqCmdF(playerIdx, a) Audio_QueueSeqCmd(0xF0000000 | ((u8)playerIdx << 24) | ((u8)a))
+#define Audio_DisableSeq(seqPlayerIndex, fadeOut) Audio_QueueCmdS32(0x83000000 | ((u8)seqPlayerIndex << 16), fadeOut)
#define ABS_ALT(x) ((x) < 0 ? -(x) : (x))
@@ -1768,7 +1748,7 @@ void AudioOcarina_SetInstrument(u8 ocarinaInstrumentId) {
return;
}
- Audio_SeqCmd8(SEQ_PLAYER_SFX, 1, SFX_CHANNEL_OCARINA, ocarinaInstrumentId);
+ SEQCMD_SET_CHANNEL_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 1, ocarinaInstrumentId);
sOcarinaInstrumentId = ocarinaInstrumentId;
if (ocarinaInstrumentId == OCARINA_INSTRUMENT_OFF) {
sOcarinaInputButtonCur = 0;
@@ -3158,7 +3138,7 @@ void AudioDebug_ProcessInput_SndCont(void) {
switch (sAudioSndContSel) {
case 0:
case 1:
- Audio_StartSeq(sAudioSndContSel, 0, sAudioSndContWork[sAudioSndContSel]);
+ SEQCMD_PLAY_SEQUENCE(sAudioSndContSel, 0, 0, sAudioSndContWork[sAudioSndContSel]);
break;
case 2:
case 3:
@@ -3170,10 +3150,10 @@ void AudioDebug_ProcessInput_SndCont(void) {
func_800F6700(sAudioSndContWork[sAudioSndContSel]);
break;
case 5:
- Audio_SeqCmdE01(SEQ_PLAYER_BGM_MAIN, sAudioSndContWork[sAudioSndContSel]);
+ SEQCMD_DISABLE_PLAY_SEQUENCES(sAudioSndContWork[sAudioSndContSel]);
break;
case 6:
- Audio_SeqCmdF(SEQ_PLAYER_BGM_MAIN, sAudioSndContWork[sAudioSndContSel]);
+ SEQCMD_RESET_AUDIO_HEAP(0, sAudioSndContWork[sAudioSndContSel]);
sAudioSubTrackInfoSpec = sAudioSndContWork[6];
if (sAudioSubTrackInfoPlayerSel > gAudioSpecs[sAudioSubTrackInfoSpec].numSequencePlayers - 1) {
sAudioSubTrackInfoPlayerSel = gAudioSpecs[sAudioSubTrackInfoSpec].numSequencePlayers - 1;
@@ -3195,10 +3175,10 @@ void AudioDebug_ProcessInput_SndCont(void) {
switch (sAudioSndContSel) {
case 0:
case 1:
- Audio_SeqCmd1(sAudioSndContSel, 0);
+ SEQCMD_STOP_SEQUENCE(sAudioSndContSel, 0);
break;
case 7:
- Audio_SeqCmd1(SEQ_PLAYER_BGM_MAIN, 0);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0);
break;
case 2:
case 3:
@@ -3488,11 +3468,11 @@ void AudioDebug_ProcessInput_BlkChgBgm(void) {
if (CHECK_BTN_ANY(sDebugPadPress, BTN_A)) {
Audio_QueueCmdS8(MK_CMD(0x46, SEQ_PLAYER_BGM_MAIN, 0x00, 0x00), sAudioBlkChgBgmWork[1]);
- Audio_QueueSeqCmd(sAudioBlkChgBgmWork[0] | 0x10000);
+ SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1, 0, sAudioBlkChgBgmWork[0]);
}
if (CHECK_BTN_ANY(sDebugPadPress, BTN_B)) {
- Audio_QueueSeqCmd(0x100100FF);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1);
}
}
@@ -3644,12 +3624,12 @@ void AudioDebug_ProcessInput(void) {
case PAGE_NON:
if (CHECK_BTN_ANY(sDebugPadPress, BTN_A)) {
sAudioSndContWork[5] ^= 1;
- Audio_SeqCmdE01(SEQ_PLAYER_BGM_MAIN, sAudioSndContWork[5]);
- if (func_800FA0B4(SEQ_PLAYER_BGM_MAIN) != NA_BGM_NATURE_AMBIENCE) {
- Audio_SeqCmd1(SEQ_PLAYER_BGM_MAIN, 0);
+ SEQCMD_DISABLE_PLAY_SEQUENCES(sAudioSndContWork[5]);
+ if (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) != NA_BGM_NATURE_AMBIENCE) {
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0);
}
- Audio_SeqCmd1(SEQ_PLAYER_FANFARE, 0);
- Audio_SeqCmd1(SEQ_PLAYER_BGM_SUB, 0);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 0);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_SUB, 0);
}
if (CHECK_BTN_ANY(sDebugPadPress, BTN_B)) {
@@ -3691,7 +3671,7 @@ void AudioDebug_ProcessInput(void) {
break;
}
- D_8013340C = sAudioScrPrtWork[10];
+ gAudioDebugPrintSeqCmd = sAudioScrPrtWork[10];
}
void Audio_UpdateRiverSoundVolumes(void);
@@ -3716,7 +3696,7 @@ void func_800F3054(void) {
Audio_ProcessSfxRequests();
Audio_ProcessSeqCmds();
func_800F8F88();
- func_800FA3DC();
+ Audio_UpdateActiveSequences();
AudioDebug_SetInput();
AudioDebug_ProcessInput();
Audio_ScheduleProcessCmds();
@@ -4094,8 +4074,8 @@ void Audio_ResetSfxChannelState(void) {
void Audio_PlayCutsceneEffectsSequence(u8 csEffectType) {
if (gSfxBankMuted[0] != 1) {
- Audio_StartSeq(SEQ_PLAYER_BGM_SUB, 0, NA_BGM_CUTSCENE_EFFECTS);
- Audio_SeqCmd8(SEQ_PLAYER_BGM_SUB, 0, 0, csEffectType);
+ SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_SUB, 0, 0, NA_BGM_CUTSCENE_EFFECTS);
+ SEQCMD_SET_CHANNEL_IO(SEQ_PLAYER_BGM_SUB, 0, 0, csEffectType);
}
}
@@ -4263,17 +4243,17 @@ void Audio_StepFreqLerp(FreqLerp* lerp) {
}
void func_800F47BC(void) {
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 1, 0, 10);
- Audio_SetVolScale(SEQ_PLAYER_BGM_SUB, 1, 0, 10);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_FANFARE, 0, 10);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, VOL_SCALE_INDEX_FANFARE, 0, 10);
}
void func_800F47FC(void) {
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 1, 0x7F, 3);
- Audio_SetVolScale(SEQ_PLAYER_BGM_SUB, 1, 0x7F, 3);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_FANFARE, 0x7F, 3);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, VOL_SCALE_INDEX_FANFARE, 0x7F, 3);
}
void func_800F483C(u8 targetVol, u8 volFadeTimer) {
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 0, targetVol, volFadeTimer);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_BGM_MAIN, targetVol, volFadeTimer);
}
/**
@@ -4315,7 +4295,7 @@ s32 Audio_SetGanonsTowerBgmVolume(u8 targetVol) {
if (sGanonsTowerVol != targetVol) {
// Sets the volume
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 0, targetVol, 2);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_BGM_MAIN, targetVol, 2);
// Sets the filter cutoff of the form (lowPassFilterCutoff << 4) | (highPassFilter & 0xF). highPassFilter is
// always set to 0
@@ -4327,7 +4307,7 @@ s32 Audio_SetGanonsTowerBgmVolume(u8 targetVol) {
lowPassFilterCutoff = (((targetVol - 0x40) >> 2) + 1) << 4;
}
// Set lowPassFilterCutoff to io port 4 from channel 15
- Audio_SeqCmd8(SEQ_PLAYER_BGM_MAIN, 4, 15, lowPassFilterCutoff);
+ SEQCMD_SET_CHANNEL_IO(SEQ_PLAYER_BGM_MAIN, 15, 4, lowPassFilterCutoff);
// Sets the reverb
for (channelIdx = 0; channelIdx < 16; channelIdx++) {
@@ -4369,14 +4349,14 @@ void Audio_UpdateRiverSoundVolumes(void) {
if (sRiverSoundMainBgmLower == true) {
if (sRiverSoundMainBgmCurrentVol != sRiverSoundMainBgmVol) {
// lowers the volume for 1 frame
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 0, sRiverSoundMainBgmVol, 0xA);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_BGM_MAIN, sRiverSoundMainBgmVol, 10);
sRiverSoundMainBgmCurrentVol = sRiverSoundMainBgmVol;
sRiverSoundMainBgmRestore = true;
}
sRiverSoundMainBgmLower = false;
} else if (sRiverSoundMainBgmRestore == true && D_80130608 == 0) {
// restores the volume every frame
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 0, 0x7F, 0xA);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_BGM_MAIN, 0x7F, 10);
sRiverSoundMainBgmCurrentVol = 0x7F;
sRiverSoundMainBgmRestore = false;
}
@@ -4464,7 +4444,7 @@ void func_800F4E30(Vec3f* pos, f32 arg1) {
for (i = 0; i < 0x10; i++) {
if (i != 9) {
- Audio_SeqCmd6(SEQ_PLAYER_BGM_MAIN, 2, i, (127.0f * phi_f22));
+ SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_MAIN, i, 2, (127.0f * phi_f22));
Audio_QueueCmdS8(0x3 << 24 | SEQ_PLAYER_BGM_MAIN << 16 | ((u8)((u32)i) << 8), phi_s4);
}
}
@@ -4494,8 +4474,8 @@ void Audio_SplitBgmChannels(s8 volSplit) {
u8 channelIdx;
u8 i;
- if ((func_800FA0B4(SEQ_PLAYER_FANFARE) == NA_BGM_DISABLED) &&
- (func_800FA0B4(SEQ_PLAYER_BGM_SUB) != NA_BGM_LONLON)) {
+ if ((Audio_GetActiveSeqId(SEQ_PLAYER_FANFARE) == NA_BGM_DISABLED) &&
+ (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB) != NA_BGM_LONLON)) {
for (i = 0; i < ARRAY_COUNT(bgmPlayers); i++) {
if (i == 0) {
// Main Bgm SeqPlayer
@@ -4523,7 +4503,7 @@ void Audio_SplitBgmChannels(s8 volSplit) {
}
}
- Audio_SeqCmdA(bgmPlayers[i], channelBits);
+ SEQCMD_SET_CHANNEL_DISABLE_MASK(bgmPlayers[i], channelBits);
}
}
}
@@ -4570,8 +4550,8 @@ void Audio_PlaySariaBgm(Vec3f* pos, u16 seqId, u16 distMax) {
Audio_SplitBgmChannels(vol);
}
- Audio_SetVolScale(SEQ_PLAYER_BGM_SUB, 3, vol, 0);
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 3, 0x7F - vol, 0);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, VOL_SCALE_INDEX_BGM_SUB, vol, 0);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_BGM_SUB, 0x7F - vol, 0);
}
void Audio_ClearSariaBgm2(void) {
@@ -4587,9 +4567,9 @@ void func_800F5550(u16 seqId) {
u8 sp27 = 0;
u16 nv;
- if (func_800FA0B4(SEQ_PLAYER_BGM_MAIN) != NA_BGM_WINDMILL) {
- if (func_800FA0B4(SEQ_PLAYER_BGM_SUB) == NA_BGM_LONLON) {
- func_800F9474(SEQ_PLAYER_BGM_SUB, 0);
+ if (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) != NA_BGM_WINDMILL) {
+ if (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB) == NA_BGM_LONLON) {
+ Audio_StopSequence(SEQ_PLAYER_BGM_SUB, 0);
Audio_QueueCmdS32(0xF8000000, 0);
}
@@ -4617,7 +4597,7 @@ void func_800F56A8(void) {
u16 temp_v0;
u8 bvar;
- temp_v0 = func_800FA0B4(SEQ_PLAYER_BGM_MAIN);
+ temp_v0 = Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN);
bvar = temp_v0 & 0xFF;
if ((temp_v0 != NA_BGM_DISABLED) && (sSeqFlags[bvar] & SEQ_FLAG_4)) {
if (D_8013062C != 0xC0) {
@@ -4629,23 +4609,25 @@ void func_800F56A8(void) {
}
void func_800F5718(void) {
- if (func_800FA0B4(SEQ_PLAYER_BGM_MAIN) != NA_BGM_WINDMILL) {
- Audio_StartSeq(SEQ_PLAYER_BGM_MAIN, 0, NA_BGM_WINDMILL);
+ if (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) != NA_BGM_WINDMILL) {
+ SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_WINDMILL);
}
}
-void func_800F574C(f32 arg0, u8 arg2) {
- if (arg0 == 1.0f) {
- Audio_SeqCmdB40(SEQ_PLAYER_BGM_MAIN, arg2, 0);
+void func_800F574C(f32 scaleTempoAndFreq, u8 duration) {
+ if (scaleTempoAndFreq == 1.0f) {
+ SEQCMD_RESET_TEMPO(SEQ_PLAYER_BGM_MAIN, duration);
} else {
- Audio_SeqCmdC(SEQ_PLAYER_FANFARE, 0x30, arg2, arg0 * 100.0f);
+ SEQCMD_SETUP_SCALE_TEMPO(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_MAIN, duration, scaleTempoAndFreq * 100.0f);
}
- Audio_SeqCmdC(SEQ_PLAYER_FANFARE, 0xA0, arg2, arg0 * 100.0f);
+
+ SEQCMD_SETUP_SET_PLAYER_FREQ(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_MAIN, duration, scaleTempoAndFreq * 100.0f);
}
void func_800F5918(void) {
- if (func_800FA0B4(SEQ_PLAYER_BGM_MAIN) == NA_BGM_TIMED_MINI_GAME && func_800FA11C(0, 0xF0000000)) {
- Audio_SeqCmdB(SEQ_PLAYER_BGM_MAIN, 5, 0, 0xD2);
+ if (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) == NA_BGM_TIMED_MINI_GAME &&
+ Audio_IsSeqCmdNotQueued(SEQCMD_OP_PLAY_SEQUENCE << 28, SEQCMD_OP_MASK)) {
+ SEQCMD_SET_TEMPO(SEQ_PLAYER_BGM_MAIN, 5, 210);
}
}
@@ -4655,11 +4637,11 @@ void func_800F595C(u16 arg0) {
if (sSeqFlags[arg0b] & SEQ_FLAG_FANFARE) {
Audio_PlayFanfare(arg0);
} else if (sSeqFlags[arg0b] & SEQ_FLAG_FANFARE_GANON) {
- Audio_StartSeq(SEQ_PLAYER_FANFARE, 0, arg0);
+ SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_FANFARE, 0, 0, arg0);
} else {
func_800F5E18(SEQ_PLAYER_BGM_MAIN, arg0, 0, 7, -1);
- Audio_SeqCmd1(SEQ_PLAYER_FANFARE, 0);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 0);
}
}
@@ -4667,11 +4649,11 @@ void func_800F59E8(u16 arg0) {
u8 arg0b = arg0 & 0xFF;
if (sSeqFlags[arg0b] & SEQ_FLAG_FANFARE) {
- Audio_SeqCmd1(SEQ_PLAYER_FANFARE, 0);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 0);
} else if (sSeqFlags[arg0b] & SEQ_FLAG_FANFARE_GANON) {
- Audio_SeqCmd1(SEQ_PLAYER_FANFARE, 0);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 0);
} else {
- Audio_SeqCmd1(SEQ_PLAYER_BGM_MAIN, 0);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0);
}
}
@@ -4684,7 +4666,7 @@ s32 func_800F5A58(u8 arg0) {
phi_a1 = 1;
}
- if (arg0 == (u8)func_800FA0B4(phi_a1)) {
+ if (arg0 == (u8)Audio_GetActiveSeqId(phi_a1)) {
return 1;
} else {
return 0;
@@ -4696,7 +4678,7 @@ s32 func_800F5A58(u8 arg0) {
* Designed for the mini-boss sequence, but also used by mini-game 2 sequence
*/
void func_800F5ACC(u16 seqId) {
- u16 curSeqId = func_800FA0B4(SEQ_PLAYER_BGM_MAIN);
+ u16 curSeqId = Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN);
if ((curSeqId & 0xFF) != NA_BGM_GANON_TOWER && (curSeqId & 0xFF) != NA_BGM_ESCAPE && curSeqId != seqId) {
Audio_SetSequenceMode(SEQ_MODE_IGNORE);
@@ -4706,7 +4688,7 @@ void func_800F5ACC(u16 seqId) {
osSyncPrintf("Middle Boss BGM Start not stack \n");
}
- Audio_StartSeq(SEQ_PLAYER_BGM_MAIN, 0, seqId);
+ SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, seqId);
}
}
@@ -4714,12 +4696,12 @@ void func_800F5ACC(u16 seqId) {
* Restores the previous sequence to the main bgm player before func_800F5ACC was called
*/
void func_800F5B58(void) {
- if ((func_800FA0B4(SEQ_PLAYER_BGM_MAIN) != NA_BGM_DISABLED) && (sPrevMainBgmSeqId != NA_BGM_DISABLED) &&
- (sSeqFlags[func_800FA0B4(SEQ_PLAYER_BGM_MAIN) & 0xFF] & SEQ_FLAG_RESTORE)) {
+ if ((Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) != NA_BGM_DISABLED) && (sPrevMainBgmSeqId != NA_BGM_DISABLED) &&
+ (sSeqFlags[Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) & 0xFF] & SEQ_FLAG_RESTORE)) {
if (sPrevMainBgmSeqId == NA_BGM_DISABLED) {
- Audio_SeqCmd1(SEQ_PLAYER_BGM_MAIN, 0);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0);
} else {
- Audio_StartSeq(SEQ_PLAYER_BGM_MAIN, 0, sPrevMainBgmSeqId);
+ SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, sPrevMainBgmSeqId);
}
sPrevMainBgmSeqId = NA_BGM_DISABLED;
@@ -4730,7 +4712,7 @@ void func_800F5B58(void) {
* Plays the nature ambience sequence on the main bgm player, but stores the previous sequence to return to later
*/
void func_800F5BF0(u8 natureAmbienceId) {
- u16 curSeqId = func_800FA0B4(SEQ_PLAYER_BGM_MAIN);
+ u16 curSeqId = Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN);
if (curSeqId != NA_BGM_NATURE_AMBIENCE) {
sPrevMainBgmSeqId = curSeqId;
@@ -4744,7 +4726,7 @@ void func_800F5BF0(u8 natureAmbienceId) {
*/
void func_800F5C2C(void) {
if (sPrevMainBgmSeqId != NA_BGM_DISABLED) {
- Audio_StartSeq(SEQ_PLAYER_BGM_MAIN, 0, sPrevMainBgmSeqId);
+ SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, sPrevMainBgmSeqId);
}
sPrevMainBgmSeqId = NA_BGM_DISABLED;
}
@@ -4755,53 +4737,58 @@ void Audio_PlayFanfare(u16 seqId) {
u8* sp1C;
u8* sp18;
- sp26 = func_800FA0B4(SEQ_PLAYER_FANFARE);
+ sp26 = Audio_GetActiveSeqId(SEQ_PLAYER_FANFARE);
sp1C = func_800E5E84(sp26 & 0xFF, &sp20);
sp18 = func_800E5E84(seqId & 0xFF, &sp20);
if ((sp26 == NA_BGM_DISABLED) || (*sp1C == *sp18)) {
D_8016B9F4 = 1;
} else {
D_8016B9F4 = 5;
- Audio_SeqCmd1(SEQ_PLAYER_FANFARE, 0);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 0);
}
D_8016B9F6 = seqId;
}
void func_800F5CF8(void) {
- u16 sp26;
- u16 pad;
- u16 sp22;
+ u16 seqIdFanfare;
+ u16 seqIdBgmMain;
+ u16 seqIdBgmSub;
if (D_8016B9F4 != 0) {
D_8016B9F4--;
if (D_8016B9F4 == 0) {
Audio_QueueCmdS32(0xE3000000, SEQUENCE_TABLE);
Audio_QueueCmdS32(0xE3000000, FONT_TABLE);
- func_800FA0B4(SEQ_PLAYER_BGM_MAIN);
- sp26 = func_800FA0B4(SEQ_PLAYER_FANFARE);
- sp22 = func_800FA0B4(SEQ_PLAYER_BGM_SUB);
- if (sp26 == NA_BGM_DISABLED) {
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 1, 0, 5);
- Audio_SetVolScale(SEQ_PLAYER_BGM_SUB, 1, 0, 5);
- Audio_SeqCmdC(SEQ_PLAYER_FANFARE, 0x80, 1, 0xA);
- Audio_SeqCmdC(SEQ_PLAYER_FANFARE, 0x83, 1, 0xA);
- Audio_SeqCmdC(SEQ_PLAYER_FANFARE, 0x90, 0, 0);
- if (sp22 != NA_BGM_LONLON) {
- Audio_SeqCmdC(SEQ_PLAYER_FANFARE, 0x93, 0, 0);
+
+ seqIdBgmMain = Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN);
+ seqIdFanfare = Audio_GetActiveSeqId(SEQ_PLAYER_FANFARE);
+ seqIdBgmSub = Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB);
+
+ (void)seqIdBgmMain; // suppresses set but unused warning
+ if (seqIdFanfare == NA_BGM_DISABLED) {
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_FANFARE, 0, 5);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, VOL_SCALE_INDEX_FANFARE, 0, 5);
+ SEQCMD_SETUP_RESTORE_PLAYER_VOLUME_WITH_SCALE_INDEX(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_MAIN,
+ VOL_SCALE_INDEX_FANFARE, 10);
+ SEQCMD_SETUP_RESTORE_PLAYER_VOLUME_WITH_SCALE_INDEX(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_SUB,
+ VOL_SCALE_INDEX_FANFARE, 10);
+ SEQCMD_SETUP_SET_CHANNEL_DISABLE_MASK(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_MAIN, 0);
+ if (seqIdBgmSub != NA_BGM_LONLON) {
+ SEQCMD_SETUP_SET_CHANNEL_DISABLE_MASK(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_SUB, 0);
}
}
- Audio_StartSeq(SEQ_PLAYER_FANFARE, 1, D_8016B9F6);
- Audio_SeqCmdA(0, 0xFFFF);
- if (sp22 != NA_BGM_LONLON) {
- Audio_SeqCmdA(SEQ_PLAYER_BGM_SUB, 0xFFFF);
+ SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_FANFARE, 1, 0, D_8016B9F6);
+ SEQCMD_SET_CHANNEL_DISABLE_MASK(SEQ_PLAYER_BGM_MAIN, 0xFFFF);
+ if (seqIdBgmSub != NA_BGM_LONLON) {
+ SEQCMD_SET_CHANNEL_DISABLE_MASK(SEQ_PLAYER_BGM_SUB, 0xFFFF);
}
}
}
}
-void func_800F5E18(u8 playerIdx, u16 seqId, u8 fadeTimer, s8 arg3, s8 arg4) {
- Audio_SeqCmd7(playerIdx, arg3, arg4);
- Audio_StartSeq(playerIdx, fadeTimer, seqId);
+void func_800F5E18(u8 seqPlayerIndex, u16 seqId, u8 fadeTimer, s8 ioPort, s8 ioData) {
+ SEQCMD_SET_PLAYER_IO(seqPlayerIndex, ioPort, ioData);
+ SEQCMD_PLAY_SEQUENCE(seqPlayerIndex, fadeTimer, 0, seqId);
}
void Audio_SetSequenceMode(u8 seqMode) {
@@ -4815,9 +4802,9 @@ void Audio_SetSequenceMode(u8 seqMode) {
seqMode = SEQ_MODE_IGNORE;
}
- seqId = D_8016E750[SEQ_PLAYER_BGM_MAIN].unk_254;
+ seqId = gActiveSeqs[SEQ_PLAYER_BGM_MAIN].seqId;
- if (seqId == NA_BGM_FIELD_LOGIC && func_800FA0B4(SEQ_PLAYER_BGM_SUB) == (NA_BGM_ENEMY | 0x800)) {
+ if (seqId == NA_BGM_FIELD_LOGIC && Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB) == (NA_BGM_ENEMY | 0x800)) {
seqMode = SEQ_MODE_IGNORE;
}
@@ -4826,29 +4813,33 @@ void Audio_SetSequenceMode(u8 seqMode) {
if (seqMode != (sPrevSeqMode & 0x7F)) {
if (seqMode == SEQ_MODE_ENEMY) {
// Start playing enemy bgm
- if (D_8016E750[SEQ_PLAYER_BGM_SUB].volScales[1] - sAudioEnemyVol < 0) {
- volumeFadeInTimer = -(D_8016E750[SEQ_PLAYER_BGM_SUB].volScales[1] - sAudioEnemyVol);
+ if (gActiveSeqs[SEQ_PLAYER_BGM_SUB].volScales[VOL_SCALE_INDEX_FANFARE] - sAudioEnemyVol < 0) {
+ volumeFadeInTimer =
+ -(gActiveSeqs[SEQ_PLAYER_BGM_SUB].volScales[VOL_SCALE_INDEX_FANFARE] - sAudioEnemyVol);
} else {
- volumeFadeInTimer = D_8016E750[SEQ_PLAYER_BGM_SUB].volScales[1] - sAudioEnemyVol;
+ volumeFadeInTimer =
+ gActiveSeqs[SEQ_PLAYER_BGM_SUB].volScales[VOL_SCALE_INDEX_FANFARE] - sAudioEnemyVol;
}
- Audio_SetVolScale(SEQ_PLAYER_BGM_SUB, 3, sAudioEnemyVol, volumeFadeInTimer);
- Audio_StartSeq(SEQ_PLAYER_BGM_SUB, 10, NA_BGM_ENEMY | 0x800);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, VOL_SCALE_INDEX_BGM_SUB, sAudioEnemyVol,
+ volumeFadeInTimer);
+ SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_SUB, 10, 8, NA_BGM_ENEMY);
if (seqId != NA_BGM_NATURE_AMBIENCE) {
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 3, (0x7F - sAudioEnemyVol) & 0xFF, 0xA);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_BGM_SUB,
+ (0x7F - sAudioEnemyVol) & 0xFF, 0xA);
Audio_SplitBgmChannels(sAudioEnemyVol);
}
} else if ((sPrevSeqMode & 0x7F) == SEQ_MODE_ENEMY) {
// Stop playing enemy bgm
- Audio_SeqCmd1(SEQ_PLAYER_BGM_SUB, 10);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_SUB, 10);
if (seqMode == SEQ_MODE_IGNORE) {
volumeFadeOutTimer = 0;
} else {
volumeFadeOutTimer = 10;
}
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 3, 0x7F, volumeFadeOutTimer);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_BGM_SUB, 0x7F, volumeFadeOutTimer);
Audio_SplitBgmChannels(0);
}
@@ -4872,7 +4863,7 @@ void Audio_SetSequenceMode(u8 seqMode) {
}
sPrevSeqMode = seqMode;
- Audio_SeqCmd7(SEQ_PLAYER_BGM_MAIN, 2, seqMode);
+ SEQCMD_SET_PLAYER_IO(SEQ_PLAYER_BGM_MAIN, 2, seqMode);
}
}
}
@@ -4891,12 +4882,12 @@ void Audio_SetBgmEnemyVolume(f32 dist) {
}
sAudioEnemyVol = ((350.0f - adjDist) * 127.0f) / 350.0f;
- Audio_SetVolScale(SEQ_PLAYER_BGM_SUB, 3, sAudioEnemyVol, 10);
- if (D_8016E750[SEQ_PLAYER_BGM_MAIN].unk_254 != NA_BGM_NATURE_AMBIENCE) {
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 3, (0x7F - sAudioEnemyVol), 10);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, VOL_SCALE_INDEX_BGM_SUB, sAudioEnemyVol, 10);
+ if (gActiveSeqs[SEQ_PLAYER_BGM_MAIN].seqId != NA_BGM_NATURE_AMBIENCE) {
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_BGM_SUB, (0x7F - sAudioEnemyVol), 10);
}
}
- if (D_8016E750[SEQ_PLAYER_BGM_MAIN].unk_254 != NA_BGM_NATURE_AMBIENCE) {
+ if (gActiveSeqs[SEQ_PLAYER_BGM_MAIN].seqId != NA_BGM_NATURE_AMBIENCE) {
Audio_SplitBgmChannels(sAudioEnemyVol);
}
}
@@ -4911,7 +4902,7 @@ void func_800F6268(f32 dist, u16 arg1) {
sAudioHasMalonBgm = true;
sAudioMalonBgmDist = dist;
if (D_8016B9F2 == 0) {
- temp_a0 = (s8)(func_800FA0B4(SEQ_PLAYER_BGM_MAIN) & 0xFF);
+ temp_a0 = (s8)(Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) & 0xFF);
if (temp_a0 == (arg1 & 0xFF)) {
if ((arg1 & 0xFF) == NA_BGM_LONLON) {
@@ -4923,18 +4914,18 @@ void func_800F6268(f32 dist, u16 arg1) {
phi_v1 = (s8)(((dist - 200.0f) * 127.0f) / 1800.0f);
}
// Transition volume of channels 0, 1 and 13 on seq player 0 over 3 frames
- Audio_SeqCmd6(SEQ_PLAYER_BGM_MAIN, 3, 0, 127 - phi_v1);
- Audio_SeqCmd6(SEQ_PLAYER_BGM_MAIN, 3, 1, 127 - phi_v1);
- Audio_SeqCmd6(SEQ_PLAYER_BGM_MAIN, 3, 13, phi_v1);
+ SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_MAIN, 0, 3, 127 - phi_v1);
+ SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_MAIN, 1, 3, 127 - phi_v1);
+ SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_MAIN, 13, 3, phi_v1);
if (D_8016B9D8 == 0) {
D_8016B9D8++;
}
}
} else if ((temp_a0 == NA_BGM_NATURE_AMBIENCE) && ((arg1 & 0xFF) == NA_BGM_LONLON)) {
- temp_a0 = (s8)(func_800FA0B4(SEQ_PLAYER_BGM_SUB) & 0xFF);
+ temp_a0 = (s8)(Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB) & 0xFF);
if ((temp_a0 != (arg1 & 0xFF)) && (D_8016B9D8 < 10)) {
func_800F5E18(SEQ_PLAYER_BGM_SUB, NA_BGM_LONLON, 0, 0, 0);
- Audio_SeqCmdA(SEQ_PLAYER_BGM_SUB, 0xFFFC);
+ SEQCMD_SET_CHANNEL_DISABLE_MASK(SEQ_PLAYER_BGM_SUB, 0xFFFC);
D_8016B9D8 = 10;
}
@@ -4946,8 +4937,8 @@ void func_800F6268(f32 dist, u16 arg1) {
phi_v1 = (s8)(((dist - 200.0f) * 127.0f) / 1800.0f);
}
// Transition volume of channels 0 and 1 on seq player 0 over 3 frames
- Audio_SeqCmd6(SEQ_PLAYER_BGM_SUB, 3, 0, 127 - phi_v1);
- Audio_SeqCmd6(SEQ_PLAYER_BGM_SUB, 3, 1, 127 - phi_v1);
+ SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_SUB, 0, 3, 127 - phi_v1);
+ SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_SUB, 1, 3, 127 - phi_v1);
}
if (D_8016B9D8 < 10) {
@@ -4970,34 +4961,34 @@ void func_800F64E0(u8 arg0) {
}
void func_800F6584(u8 arg0) {
- u8 playerIdx;
+ u8 seqPlayerIndex;
u16 sp34;
D_8016B9F2 = arg0;
- if ((func_800FA0B4(SEQ_PLAYER_BGM_MAIN) & 0xFF) == NA_BGM_LONLON) {
- playerIdx = SEQ_PLAYER_BGM_MAIN;
+ if ((Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) & 0xFF) == NA_BGM_LONLON) {
+ seqPlayerIndex = SEQ_PLAYER_BGM_MAIN;
sp34 = 0;
- } else if ((func_800FA0B4(SEQ_PLAYER_BGM_SUB) & 0xFF) == NA_BGM_LONLON) {
- playerIdx = SEQ_PLAYER_BGM_SUB;
+ } else if ((Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB) & 0xFF) == NA_BGM_LONLON) {
+ seqPlayerIndex = SEQ_PLAYER_BGM_SUB;
sp34 = 0xFFFC;
} else {
return;
}
if (arg0 != 0) {
- Audio_SeqCmd6(playerIdx, 1, 0, 0);
- Audio_SeqCmd6(playerIdx, 1, 1, 0);
- if (playerIdx == SEQ_PLAYER_BGM_SUB) {
- Audio_SeqCmdA(playerIdx, sp34 | 3);
+ SEQCMD_SET_CHANNEL_VOLUME(seqPlayerIndex, 0, 1, 0);
+ SEQCMD_SET_CHANNEL_VOLUME(seqPlayerIndex, 1, 1, 0);
+ if (seqPlayerIndex == SEQ_PLAYER_BGM_SUB) {
+ SEQCMD_SET_CHANNEL_DISABLE_MASK(seqPlayerIndex, sp34 | 3);
}
} else {
- if (playerIdx == SEQ_PLAYER_BGM_SUB) {
+ if (seqPlayerIndex == SEQ_PLAYER_BGM_SUB) {
func_800F5E18(SEQ_PLAYER_BGM_SUB, NA_BGM_LONLON, 0, 0, 0);
}
- Audio_SeqCmd6(playerIdx, 1, 0, 0x7F);
- Audio_SeqCmd6(playerIdx, 1, 1, 0x7F);
- if (playerIdx == SEQ_PLAYER_BGM_SUB) {
- Audio_SeqCmdA(playerIdx, sp34);
+ SEQCMD_SET_CHANNEL_VOLUME(seqPlayerIndex, 0, 1, 0x7F);
+ SEQCMD_SET_CHANNEL_VOLUME(seqPlayerIndex, 1, 1, 0x7F);
+ if (seqPlayerIndex == SEQ_PLAYER_BGM_SUB) {
+ SEQCMD_SET_CHANNEL_DISABLE_MASK(seqPlayerIndex, sp34);
}
}
}
@@ -5037,7 +5028,7 @@ void func_800F6700(s8 audioSetting) {
break;
}
- Audio_SeqCmdE0(SEQ_PLAYER_BGM_MAIN, soundModeIndex);
+ SEQCMD_SET_SOUND_MODE(soundModeIndex);
}
void Audio_SetBaseFilter(u8 filter) {
@@ -5059,7 +5050,7 @@ void Audio_SetExtraFilter(u8 filter) {
sAudioExtraFilter2 = filter;
sAudioExtraFilter = filter;
- if (D_8016E750[SEQ_PLAYER_BGM_MAIN].unk_254 == NA_BGM_NATURE_AMBIENCE) {
+ if (gActiveSeqs[SEQ_PLAYER_BGM_MAIN].seqId == NA_BGM_NATURE_AMBIENCE) {
for (i = 0; i < 16; i++) {
t = i;
// CHAN_UPD_SCRIPT_IO (seq player 0, all channels, slot 6)
@@ -5087,8 +5078,8 @@ void func_800F6964(u16 arg0) {
s32 skip;
u8 channelIdx;
- Audio_SeqCmd1(SEQ_PLAYER_BGM_MAIN, (arg0 * 3) / 2);
- Audio_SeqCmd1(SEQ_PLAYER_FANFARE, (arg0 * 3) / 2);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, (arg0 * 3) / 2);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, (arg0 * 3) / 2);
for (channelIdx = 0; channelIdx < 16; channelIdx++) {
skip = false;
switch (channelIdx) {
@@ -5104,23 +5095,23 @@ void func_800F6964(u16 arg0) {
}
if (!skip) {
- Audio_SeqCmd6(SEQ_PLAYER_SFX, arg0 >> 1, channelIdx, 0);
+ SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_SFX, channelIdx, arg0 >> 1, 0);
}
}
- Audio_SeqCmd1(SEQ_PLAYER_BGM_SUB, (arg0 * 3) / 2);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_SUB, (arg0 * 3) / 2);
}
void func_800F6AB0(u16 arg0) {
- Audio_SeqCmd1(SEQ_PLAYER_BGM_MAIN, arg0);
- Audio_SeqCmd1(SEQ_PLAYER_FANFARE, arg0);
- Audio_SeqCmd1(SEQ_PLAYER_BGM_SUB, arg0);
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 3, 0x7F, 0);
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 1, 0x7F, 0);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, arg0);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, arg0);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_SUB, arg0);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_BGM_SUB, 0x7F, 0);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_FANFARE, 0x7F, 0);
}
void func_800F6B3C(void) {
- func_800F9280(SEQ_PLAYER_SFX, 0, 0xFF, 5);
+ Audio_StartSequence(SEQ_PLAYER_SFX, 0, 0xFF, 5);
}
void Audio_DisableAllSeq(void) {
@@ -5179,19 +5170,20 @@ void func_800F6C34(void) {
D_8016B9F2 = 0;
}
-void Audio_SetNatureAmbienceChannelIO(u8 channelIdxRange, u8 port, u8 val) {
+void Audio_SetNatureAmbienceChannelIO(u8 channelIdxRange, u8 ioPort, u8 ioData) {
u8 firstChannelIdx;
u8 lastChannelIdx;
u8 channelIdx;
- if ((D_8016E750[SEQ_PLAYER_BGM_MAIN].unk_254 != NA_BGM_NATURE_AMBIENCE) && func_800FA11C(1, 0xF00000FF)) {
+ if ((gActiveSeqs[SEQ_PLAYER_BGM_MAIN].seqId != NA_BGM_NATURE_AMBIENCE) &&
+ Audio_IsSeqCmdNotQueued(SEQCMD_OP_PLAY_SEQUENCE << 28 | NA_BGM_NATURE_AMBIENCE, SEQCMD_OP_MASK | 0xFF)) {
sAudioNatureFailed = true;
return;
}
- // channelIdxRange = 01 on port 1
- if (((channelIdxRange << 8) + port) == ((NATURE_CHANNEL_CRITTER_0 << 8) + CHANNEL_IO_PORT_1)) {
- if (func_800FA0B4(SEQ_PLAYER_BGM_SUB) != NA_BGM_LONLON) {
+ // channelIdxRange = 01 on ioPort 1
+ if (((channelIdxRange << 8) + ioPort) == ((NATURE_CHANNEL_CRITTER_0 << 8) + CHANNEL_IO_PORT_1)) {
+ if (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB) != NA_BGM_LONLON) {
D_8016B9D8 = 0;
}
}
@@ -5204,38 +5196,38 @@ void Audio_SetNatureAmbienceChannelIO(u8 channelIdxRange, u8 port, u8 val) {
}
for (channelIdx = firstChannelIdx; channelIdx <= lastChannelIdx; channelIdx++) {
- Audio_SeqCmd8(SEQ_PLAYER_BGM_MAIN, port, channelIdx, val);
+ SEQCMD_SET_CHANNEL_IO(SEQ_PLAYER_BGM_MAIN, channelIdx, ioPort, ioData);
}
}
void Audio_StartNatureAmbienceSequence(u16 playerIO, u16 channelMask) {
u8 channelIdx;
- if (func_800FA0B4(SEQ_PLAYER_BGM_MAIN) == NA_BGM_WINDMILL) {
+ if (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) == NA_BGM_WINDMILL) {
Audio_PlayCutsceneEffectsSequence(SEQ_CS_EFFECTS_RAINFALL);
return;
}
- Audio_SeqCmd7(SEQ_PLAYER_BGM_MAIN, 0, 1);
- Audio_SeqCmd7(SEQ_PLAYER_BGM_MAIN, 4, playerIO >> 8);
- Audio_SeqCmd7(SEQ_PLAYER_BGM_MAIN, 5, playerIO & 0xFF);
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 0, 0x7F, 1);
+ SEQCMD_SET_PLAYER_IO(SEQ_PLAYER_BGM_MAIN, 0, 1);
+ SEQCMD_SET_PLAYER_IO(SEQ_PLAYER_BGM_MAIN, 4, playerIO >> 8);
+ SEQCMD_SET_PLAYER_IO(SEQ_PLAYER_BGM_MAIN, 5, playerIO & 0xFF);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_BGM_MAIN, 0x7F, 1);
channelIdx = false;
- if (D_80133408 != 0) {
+ if (gStartSeqDisabled) {
channelIdx = true;
- Audio_SeqCmdE01(SEQ_PLAYER_BGM_MAIN, 0);
+ SEQCMD_DISABLE_PLAY_SEQUENCES(false);
}
- Audio_StartSeq(SEQ_PLAYER_BGM_MAIN, 0, NA_BGM_NATURE_AMBIENCE);
+ SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_NATURE_AMBIENCE);
if (channelIdx) {
- Audio_SeqCmdE01(SEQ_PLAYER_BGM_MAIN, 1);
+ SEQCMD_DISABLE_PLAY_SEQUENCES(true);
}
for (channelIdx = 0; channelIdx < 16; channelIdx++) {
if (!(channelMask & (1 << channelIdx)) && (playerIO & (1 << channelIdx))) {
- Audio_SeqCmd8(SEQ_PLAYER_BGM_MAIN, CHANNEL_IO_PORT_1, channelIdx, 1);
+ SEQCMD_SET_CHANNEL_IO(SEQ_PLAYER_BGM_MAIN, channelIdx, CHANNEL_IO_PORT_1, 1);
}
}
}
@@ -5243,24 +5235,23 @@ void Audio_StartNatureAmbienceSequence(u16 playerIO, u16 channelMask) {
void Audio_PlayNatureAmbienceSequence(u8 natureAmbienceId) {
u8 i = 0;
u8 channelIdx;
- u8 port;
- u8 val;
+ u8 ioPort;
+ u8 ioData;
- if (!((D_8016E750[SEQ_PLAYER_BGM_MAIN].unk_254 != NA_BGM_DISABLED) &&
- (sSeqFlags[((u8)D_8016E750[SEQ_PLAYER_BGM_MAIN].unk_254) & 0xFF] & SEQ_FLAG_NO_AMBIENCE))) {
+ if ((gActiveSeqs[SEQ_PLAYER_BGM_MAIN].seqId == NA_BGM_DISABLED) ||
+ !(sSeqFlags[((u8)gActiveSeqs[SEQ_PLAYER_BGM_MAIN].seqId) & 0xFF] & SEQ_FLAG_NO_AMBIENCE)) {
Audio_StartNatureAmbienceSequence(sNatureAmbienceDataIO[natureAmbienceId].playerIO,
sNatureAmbienceDataIO[natureAmbienceId].channelMask);
while ((sNatureAmbienceDataIO[natureAmbienceId].channelIO[i] != 0xFF) && (i < 100)) {
- // Probably a fake match, using Audio_SeqCmd8 doesn't work.
channelIdx = sNatureAmbienceDataIO[natureAmbienceId].channelIO[i++];
- port = sNatureAmbienceDataIO[natureAmbienceId].channelIO[i++];
- val = sNatureAmbienceDataIO[natureAmbienceId].channelIO[i++];
- Audio_QueueSeqCmd(0x80000000 | (SEQ_PLAYER_BGM_MAIN << 24) | (port << 0x10) | (channelIdx << 8) | val);
+ ioPort = sNatureAmbienceDataIO[natureAmbienceId].channelIO[i++];
+ ioData = sNatureAmbienceDataIO[natureAmbienceId].channelIO[i++];
+ SEQCMD_SET_CHANNEL_IO(SEQ_PLAYER_BGM_MAIN, channelIdx, ioPort, ioData);
}
- Audio_SeqCmd8(SEQ_PLAYER_BGM_MAIN, CHANNEL_IO_PORT_7, NATURE_CHANNEL_UNK, sSoundMode);
+ SEQCMD_SET_CHANNEL_IO(SEQ_PLAYER_BGM_MAIN, NATURE_CHANNEL_UNK, CHANNEL_IO_PORT_7, sSoundMode);
}
}
@@ -5272,13 +5263,13 @@ void Audio_InitSound(void) {
func_800F6C34();
AudioOcarina_ResetStaffs();
Audio_ResetSfxChannelState();
- func_800FAEB4();
+ Audio_ResetActiveSequencesAndVolume();
Audio_ResetSfx();
- func_800F9280(SEQ_PLAYER_SFX, 0, 0x70, 10);
+ Audio_StartSequence(SEQ_PLAYER_SFX, 0, 0x70, 10);
}
void func_800F7170(void) {
- func_800F9280(SEQ_PLAYER_SFX, 0, 0x70, 1);
+ Audio_StartSequence(SEQ_PLAYER_SFX, 0, 0x70, 1);
Audio_QueueCmdS32(0xF2000000, 1);
Audio_ScheduleProcessCmds();
Audio_QueueCmdS32(0xF8000000, 0);
@@ -5289,14 +5280,14 @@ void func_800F71BC(s32 arg0) {
func_800F6C34();
AudioOcarina_ResetStaffs();
Audio_ResetSfxChannelState();
- func_800FADF8();
+ Audio_ResetActiveSequences();
Audio_ResetSfx();
}
void func_800F7208(void) {
- func_800FADF8();
+ Audio_ResetActiveSequences();
Audio_QueueCmdS32(0xF2000000, 1);
func_800F6C34();
Audio_ResetSfxChannelState();
- func_800F9280(SEQ_PLAYER_SFX, 0, 0x70, 1);
+ Audio_StartSequence(SEQ_PLAYER_SFX, 0, 0x70, 1);
}
diff --git a/src/code/code_800F7260.c b/src/code/code_800F7260.c
index c8f24736f..1f8e2b891 100644
--- a/src/code/code_800F7260.c
+++ b/src/code/code_800F7260.c
@@ -52,15 +52,15 @@ void Audio_SetSfxBanksMute(u16 muteMask) {
void Audio_QueueSeqCmdMute(u8 channelIdx) {
D_801333D0 |= (1 << channelIdx);
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 2, 0x40, 0xF);
- Audio_SetVolScale(SEQ_PLAYER_BGM_SUB, 2, 0x40, 0xF);
+ 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);
if (D_801333D0 == 0) {
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 2, 0x7F, 0xF);
- Audio_SetVolScale(SEQ_PLAYER_BGM_SUB, 2, 0x7F, 0xF);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_SFX, 0x7F, 0xF);
+ Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, VOL_SCALE_INDEX_SFX, 0x7F, 0xF);
}
}
diff --git a/src/code/code_800F9280.c b/src/code/code_800F9280.c
index 86ca22831..00df77801 100644
--- a/src/code/code_800F9280.c
+++ b/src/code/code_800F9280.c
@@ -1,350 +1,388 @@
+/**
+ * @file code_800F9280.c
+ *
+ * This file implements a set of high-level audio sequence commands that allow sequences to be modified in real-time.
+ * These commands are intended to interface external to the audio library.
+ *
+ * These commands are generated using `Audio_QueueSeqCmd`, and a user-friendly interface for this function
+ * can be found in `seqcmd.h`
+ *
+ * These commands change sequences by generating internal audio commands `Audio_QueueCmd` which allows these
+ * sequence requests to be passed onto the audio thread. It is worth noting all functions in this file are
+ * called from the graph thread.
+ *
+ * These commands are not to be confused with the sequence instructions used by the sequences themselves
+ * which are a midi-based scripting language.
+ *
+ * Nor are these commands to be confused with the internal audio commands used to transfer requests from
+ * the graph thread to the audio thread.
+ */
#include "ultra64.h"
#include "global.h"
#include "ultra64/abi.h"
+// Direct audio command (skips the queueing system)
+#define SEQCMD_SET_PLAYER_VOLUME_NOW(seqPlayerIndex, duration, volume) \
+ Audio_ProcessSeqCmd((SEQCMD_OP_SET_PLAYER_VOLUME << 28) | ((u8)(seqPlayerIndex) << 24) | ((u8)(duration) << 16) | \
+ ((u8)((volume)*127.0f)));
+
typedef struct {
- u8 unk_0;
- u8 unk_1; // importance?
-} Struct_8016E320;
+ u8 seqId;
+ u8 priority; // higher values have higher priority
+} SeqRequest;
-Struct_8016E320 D_8016E320[4][5];
-u8 D_8016E348[4];
+SeqRequest sSeqRequests[4][5];
+u8 sNumSeqRequests[4];
u32 sAudioSeqCmds[0x100];
-unk_D_8016E750 D_8016E750[4];
-
-// TODO: clean up these macros. They are similar to ones in code_800EC960.c but without casts.
-#define Audio_StartSeq(playerIdx, fadeTimer, seqId) \
- Audio_QueueSeqCmd(0x00000000 | ((playerIdx) << 24) | ((fadeTimer) << 16) | (seqId))
-#define Audio_SeqCmdA(playerIdx, a) Audio_QueueSeqCmd(0xA0000000 | ((playerIdx) << 24) | (a))
-#define Audio_SeqCmdB30(playerIdx, a, b) Audio_QueueSeqCmd(0xB0003000 | ((playerIdx) << 24) | ((a) << 16) | (b))
-#define Audio_SeqCmdB40(playerIdx, a, b) Audio_QueueSeqCmd(0xB0004000 | ((playerIdx) << 24) | ((a) << 16) | (b))
-#define Audio_SeqCmd3(playerIdx, a) Audio_QueueSeqCmd(0x30000000 | ((playerIdx) << 24) | (a))
-#define Audio_SeqCmd5(playerIdx, a, b) Audio_QueueSeqCmd(0x50000000 | ((playerIdx) << 24) | ((a) << 16) | (b))
-#define Audio_SeqCmd4(playerIdx, a, b) Audio_QueueSeqCmd(0x40000000 | ((playerIdx) << 24) | ((a) << 16) | (b))
-#define Audio_SetVolScaleNow(playerIdx, volFadeTimer, volScale) \
- Audio_ProcessSeqCmd(0x40000000 | ((u8)playerIdx << 24) | ((u8)volFadeTimer << 16) | ((u8)(volScale * 127.0f)));
-
-void func_800F9280(u8 playerIdx, u8 seqId, u8 arg2, u16 fadeTimer) {
- u8 i;
- u16 dur;
+ActiveSequence gActiveSeqs[4];
+
+void Audio_StartSequence(u8 seqPlayerIndex, u8 seqId, u8 seqArgs, u16 fadeInDuration) {
+ u8 channelIndex;
+ u16 duration;
s32 pad;
- if (D_80133408 == 0 || playerIdx == SEQ_PLAYER_SFX) {
- arg2 &= 0x7F;
- if (arg2 == 0x7F) {
- dur = (fadeTimer >> 3) * 60 * gAudioContext.audioBufferParameters.updatesPerFrame;
- Audio_QueueCmdS32(0x85000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(seqId, 8, 8), dur);
+ if (!gStartSeqDisabled || (seqPlayerIndex == SEQ_PLAYER_SFX)) {
+ seqArgs &= 0x7F;
+ if (seqArgs == 0x7F) {
+ // `fadeInDuration` is interpreted as skip ticks
+ duration = (fadeInDuration >> 3) * 60 * gAudioContext.audioBufferParameters.updatesPerFrame;
+ Audio_QueueCmdS32(0x85000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(seqId, 8, 8), duration);
} else {
- Audio_QueueCmdS32(0x82000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(seqId, 8, 8),
- (fadeTimer * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4);
+ // `fadeInDuration` is interpreted as number of frames at 30 fps
+ Audio_QueueCmdS32(0x82000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(seqId, 8, 8),
+ (fadeInDuration * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4);
}
- D_8016E750[playerIdx].unk_254 = seqId | (arg2 << 8);
- D_8016E750[playerIdx].unk_256 = seqId | (arg2 << 8);
+ gActiveSeqs[seqPlayerIndex].seqId = seqId | (seqArgs << 8);
+ gActiveSeqs[seqPlayerIndex].prevSeqId = seqId | (seqArgs << 8);
- if (D_8016E750[playerIdx].volCur != 1.0f) {
- Audio_QueueCmdF32(0x41000000 | _SHIFTL(playerIdx, 16, 8), D_8016E750[playerIdx].volCur);
+ if (gActiveSeqs[seqPlayerIndex].volCur != 1.0f) {
+ Audio_QueueCmdF32(0x41000000 | _SHIFTL(seqPlayerIndex, 16, 8), gActiveSeqs[seqPlayerIndex].volCur);
}
- D_8016E750[playerIdx].unk_28 = 0;
- D_8016E750[playerIdx].unk_18 = 0;
- D_8016E750[playerIdx].unk_14 = 0;
+ gActiveSeqs[seqPlayerIndex].tempoTimer = 0;
+ gActiveSeqs[seqPlayerIndex].tempoOriginal = 0;
+ gActiveSeqs[seqPlayerIndex].tempoCmd = 0;
- for (i = 0; i < 0x10; i++) {
- D_8016E750[playerIdx].unk_50[i].unk_00 = 1.0f;
- D_8016E750[playerIdx].unk_50[i].unk_0C = 0;
- D_8016E750[playerIdx].unk_50[i].unk_10 = 1.0f;
- D_8016E750[playerIdx].unk_50[i].unk_1C = 0;
+ for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volCur = 1.0f;
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volTimer = 0;
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleCur = 1.0f;
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleTimer = 0;
}
- D_8016E750[playerIdx].unk_250 = 0;
- D_8016E750[playerIdx].unk_252 = 0;
+ gActiveSeqs[seqPlayerIndex].freqScaleChannelFlags = 0;
+ gActiveSeqs[seqPlayerIndex].volChannelFlags = 0;
}
}
-void func_800F9474(u8 playerIdx, u16 arg1) {
- Audio_QueueCmdS32(0x83000000 | ((u8)playerIdx << 16),
- (arg1 * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4);
- D_8016E750[playerIdx].unk_254 = NA_BGM_DISABLED;
+void Audio_StopSequence(u8 seqPlayerIndex, u16 fadeOutDuration) {
+ Audio_QueueCmdS32(0x83000000 | ((u8)seqPlayerIndex << 16),
+ (fadeOutDuration * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4);
+ gActiveSeqs[seqPlayerIndex].seqId = NA_BGM_DISABLED;
}
-typedef enum {
- SEQ_START,
- CMD1,
- CMD2,
- CMD3,
- SEQ_VOL_UPD,
- CMD5,
- CMD6,
- CMD7,
- CMD8,
- CMD9,
- CMDA,
- CMDB,
- CMDC,
- CMDD,
- CMDE,
- CMDF
-} SeqCmdType;
-
void Audio_ProcessSeqCmd(u32 cmd) {
- s32 pad;
+ s32 priority;
+ s32 channelMaskEnable;
+ u16 channelMaskDisable;
u16 fadeTimer;
- u16 channelMask;
- u32 channelMaskReversed;
u16 val;
u8 oldSpec;
u8 spec;
u8 op;
u8 subOp;
- u8 playerIdx;
+ u8 seqPlayerIndex;
u8 seqId;
u8 seqArgs;
u8 found;
u8 port;
u8 duration;
- u8 chanIdx;
+ u8 channelIndex;
u8 i;
- s32 new_var;
- f32 freqScale;
+ f32 freqScaleTarget;
+ s32 pad;
- if (D_8013340C && (cmd & 0xF0000000) != 0x70000000) {
+ if (gAudioDebugPrintSeqCmd && (cmd & SEQCMD_OP_MASK) != (SEQCMD_OP_SET_PLAYER_IO << 28)) {
AudioDebug_ScrPrt("SEQ H", (cmd >> 16) & 0xFFFF);
AudioDebug_ScrPrt(" L", cmd & 0xFFFF);
}
op = cmd >> 28;
- playerIdx = (cmd & 0xF000000) >> 24;
+ seqPlayerIndex = (cmd & 0xF000000) >> 24;
switch (op) {
- case 0x0:
- // play sequence immediately
+ case SEQCMD_OP_PLAY_SEQUENCE:
+ // Play a new sequence
seqId = cmd & 0xFF;
seqArgs = (cmd & 0xFF00) >> 8;
+ // `fadeTimer` is only shifted 13 bits instead of 16 bits.
+ // `fadeTimer` continues to be scaled in `Audio_StartSequence`
fadeTimer = (cmd & 0xFF0000) >> 13;
- if ((D_8016E750[playerIdx].unk_260 == 0) && (seqArgs < 0x80)) {
- func_800F9280(playerIdx, seqId, seqArgs, fadeTimer);
+ if (!gActiveSeqs[seqPlayerIndex].isWaitingForFonts && (seqArgs < 0x80)) {
+ Audio_StartSequence(seqPlayerIndex, seqId, seqArgs, fadeTimer);
}
break;
- case 0x1:
- // disable seq player
+ case SEQCMD_OP_STOP_SEQUENCE:
+ // Stop a sequence and disable the sequence player
fadeTimer = (cmd & 0xFF0000) >> 13;
- func_800F9474(playerIdx, fadeTimer);
+ Audio_StopSequence(seqPlayerIndex, fadeTimer);
break;
- case 0x2:
- // queue sequence
+ case SEQCMD_OP_QUEUE_SEQUENCE:
+ // Queue a sequence into `sSeqRequests`
seqId = cmd & 0xFF;
seqArgs = (cmd & 0xFF00) >> 8;
fadeTimer = (cmd & 0xFF0000) >> 13;
- new_var = seqArgs;
- for (i = 0; i < D_8016E348[playerIdx]; i++) {
- if (D_8016E320[playerIdx][i].unk_0 == seqId) {
+ priority = seqArgs;
+
+ // Checks if the requested sequence is first in the list of requests
+ // If it is already queued and first in the list, then play the sequence immediately
+ for (i = 0; i < sNumSeqRequests[seqPlayerIndex]; i++) {
+ if (sSeqRequests[seqPlayerIndex][i].seqId == seqId) {
if (i == 0) {
- func_800F9280(playerIdx, seqId, seqArgs, fadeTimer);
+ Audio_StartSequence(seqPlayerIndex, seqId, seqArgs, fadeTimer);
}
return;
}
}
- found = D_8016E348[playerIdx];
- for (i = 0; i < D_8016E348[playerIdx]; i++) {
- if (D_8016E320[playerIdx][i].unk_1 <= new_var) {
+ // Searches the sequence requests for the first request that does not have a higher priority
+ // than the current incoming request
+ found = sNumSeqRequests[seqPlayerIndex];
+ for (i = 0; i < sNumSeqRequests[seqPlayerIndex]; i++) {
+ if (priority >= sSeqRequests[seqPlayerIndex][i].priority) {
found = i;
- i = D_8016E348[playerIdx]; // "break;"
+ i = sNumSeqRequests[seqPlayerIndex]; // "break;"
}
}
- if (D_8016E348[playerIdx] < 5) {
- D_8016E348[playerIdx]++;
+ // Check if the queue is full
+ if (sNumSeqRequests[seqPlayerIndex] < ARRAY_COUNT(sSeqRequests[seqPlayerIndex])) {
+ sNumSeqRequests[seqPlayerIndex]++;
}
- for (i = D_8016E348[playerIdx] - 1; i != found; i--) {
- D_8016E320[playerIdx][i].unk_1 = D_8016E320[playerIdx][i - 1].unk_1;
- D_8016E320[playerIdx][i].unk_0 = D_8016E320[playerIdx][i - 1].unk_0;
+
+ for (i = sNumSeqRequests[seqPlayerIndex] - 1; i != found; i--) {
+ // Move all requests of lower priority backwards 1 place in the queue
+ // If the queue is full, overwrite the entry with the lowest priority
+ sSeqRequests[seqPlayerIndex][i].priority = sSeqRequests[seqPlayerIndex][i - 1].priority;
+ sSeqRequests[seqPlayerIndex][i].seqId = sSeqRequests[seqPlayerIndex][i - 1].seqId;
}
- D_8016E320[playerIdx][found].unk_1 = seqArgs;
- D_8016E320[playerIdx][found].unk_0 = seqId;
+ // Fill the newly freed space in the queue with the new request
+ sSeqRequests[seqPlayerIndex][found].priority = seqArgs;
+ sSeqRequests[seqPlayerIndex][found].seqId = seqId;
+
+ // The sequence is first in queue, so start playing.
if (found == 0) {
- func_800F9280(playerIdx, seqId, seqArgs, fadeTimer);
+ Audio_StartSequence(seqPlayerIndex, seqId, seqArgs, fadeTimer);
}
break;
- case 0x3:
- // unqueue/stop sequence
- seqId = cmd & 0xFF;
+ case SEQCMD_OP_UNQUEUE_SEQUENCE:
+ // Unqueue sequence
fadeTimer = (cmd & 0xFF0000) >> 13;
- found = D_8016E348[playerIdx];
- for (i = 0; i < D_8016E348[playerIdx]; i++) {
- if (D_8016E320[playerIdx][i].unk_0 == seqId) {
+ found = sNumSeqRequests[seqPlayerIndex];
+ for (i = 0; i < sNumSeqRequests[seqPlayerIndex]; i++) {
+ seqId = cmd & 0xFF;
+ if (sSeqRequests[seqPlayerIndex][i].seqId == seqId) {
found = i;
- i = D_8016E348[playerIdx]; // "break;"
+ i = sNumSeqRequests[seqPlayerIndex]; // "break;"
}
}
- if (found != D_8016E348[playerIdx]) {
- for (i = found; i < D_8016E348[playerIdx] - 1; i++) {
- D_8016E320[playerIdx][i].unk_1 = D_8016E320[playerIdx][i + 1].unk_1;
- D_8016E320[playerIdx][i].unk_0 = D_8016E320[playerIdx][i + 1].unk_0;
+ if (found != sNumSeqRequests[seqPlayerIndex]) {
+ // Move all requests of lower priority forward 1 place in the queue
+ for (i = found; i < sNumSeqRequests[seqPlayerIndex] - 1; i++) {
+ sSeqRequests[seqPlayerIndex][i].priority = sSeqRequests[seqPlayerIndex][i + 1].priority;
+ sSeqRequests[seqPlayerIndex][i].seqId = sSeqRequests[seqPlayerIndex][i + 1].seqId;
}
- D_8016E348[playerIdx]--;
+ sNumSeqRequests[seqPlayerIndex]--;
}
+ // If the sequence was first in queue (it is currently playing),
+ // Then stop the sequence and play the next sequence in the queue.
if (found == 0) {
- func_800F9474(playerIdx, fadeTimer);
- if (D_8016E348[playerIdx] != 0) {
- func_800F9280(playerIdx, D_8016E320[playerIdx][0].unk_0, D_8016E320[playerIdx][0].unk_1, fadeTimer);
+ Audio_StopSequence(seqPlayerIndex, fadeTimer);
+ if (sNumSeqRequests[seqPlayerIndex] != 0) {
+ Audio_StartSequence(seqPlayerIndex, sSeqRequests[seqPlayerIndex][0].seqId,
+ sSeqRequests[seqPlayerIndex][0].priority, fadeTimer);
}
}
break;
- case 0x4:
- // transition seq volume
+ case SEQCMD_OP_SET_PLAYER_VOLUME:
+ // Transition volume to a target volume for an entire player
duration = (cmd & 0xFF0000) >> 15;
val = cmd & 0xFF;
if (duration == 0) {
duration++;
}
- D_8016E750[playerIdx].volTarget = (f32)val / 127.0f;
- if (D_8016E750[playerIdx].volCur != D_8016E750[playerIdx].volTarget) {
- D_8016E750[playerIdx].unk_08 =
- (D_8016E750[playerIdx].volCur - D_8016E750[playerIdx].volTarget) / (f32)duration;
- D_8016E750[playerIdx].unk_0C = duration;
+ // Volume is scaled relative to 127
+ gActiveSeqs[seqPlayerIndex].volTarget = (f32)val / 127.0f;
+ if (gActiveSeqs[seqPlayerIndex].volCur != gActiveSeqs[seqPlayerIndex].volTarget) {
+ gActiveSeqs[seqPlayerIndex].volStep =
+ (gActiveSeqs[seqPlayerIndex].volCur - gActiveSeqs[seqPlayerIndex].volTarget) / (f32)duration;
+ gActiveSeqs[seqPlayerIndex].volTimer = duration;
}
break;
- case 0x5:
- // transition freq scale for all channels
+ case SEQCMD_OP_SET_PLAYER_FREQ:
+ // Transition freq scale to a target freq for all channels
duration = (cmd & 0xFF0000) >> 15;
val = cmd & 0xFFFF;
if (duration == 0) {
duration++;
}
- freqScale = (f32)val / 1000.0f;
- for (i = 0; i < 16; i++) {
- D_8016E750[playerIdx].unk_50[i].unk_14 = freqScale;
- D_8016E750[playerIdx].unk_50[i].unk_1C = duration;
- D_8016E750[playerIdx].unk_50[i].unk_18 =
- (D_8016E750[playerIdx].unk_50[i].unk_10 - freqScale) / (f32)duration;
+ // Frequency is scaled relative to 1000
+ freqScaleTarget = (f32)val / 1000.0f;
+ for (i = 0; i < SEQ_NUM_CHANNELS; i++) {
+ gActiveSeqs[seqPlayerIndex].channelData[i].freqScaleTarget = freqScaleTarget;
+ gActiveSeqs[seqPlayerIndex].channelData[i].freqScaleTimer = duration;
+ gActiveSeqs[seqPlayerIndex].channelData[i].freqScaleStep =
+ (gActiveSeqs[seqPlayerIndex].channelData[i].freqScaleCur - freqScaleTarget) / (f32)duration;
}
- D_8016E750[playerIdx].unk_250 = 0xFFFF;
+ gActiveSeqs[seqPlayerIndex].freqScaleChannelFlags = 0xFFFF;
break;
- case 0xD:
- // transition freq scale
+ case SEQCMD_OP_SET_CHANNEL_FREQ:
+ // Transition freq scale to a target for a specific channel
duration = (cmd & 0xFF0000) >> 15;
- chanIdx = (cmd & 0xF000) >> 12;
+ channelIndex = (cmd & 0xF000) >> 12;
val = cmd & 0xFFF;
if (duration == 0) {
duration++;
}
- freqScale = (f32)val / 1000.0f;
- D_8016E750[playerIdx].unk_50[chanIdx].unk_14 = freqScale;
- D_8016E750[playerIdx].unk_50[chanIdx].unk_18 =
- (D_8016E750[playerIdx].unk_50[chanIdx].unk_10 - freqScale) / (f32)duration;
- D_8016E750[playerIdx].unk_50[chanIdx].unk_1C = duration;
- D_8016E750[playerIdx].unk_250 |= 1 << chanIdx;
+ // Frequency is scaled relative to 1000
+ freqScaleTarget = (f32)val / 1000.0f;
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleTarget = freqScaleTarget;
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleStep =
+ (gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleCur - freqScaleTarget) / (f32)duration;
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleTimer = duration;
+ gActiveSeqs[seqPlayerIndex].freqScaleChannelFlags |= 1 << channelIndex;
break;
- case 0x6:
- // transition vol scale
+ case SEQCMD_OP_SET_CHANNEL_VOLUME:
+ // Transition volume to a target volume for a specific channel
duration = (cmd & 0xFF0000) >> 15;
- chanIdx = (cmd & 0xF00) >> 8;
+ channelIndex = (cmd & 0xF00) >> 8;
val = cmd & 0xFF;
if (duration == 0) {
duration++;
}
- D_8016E750[playerIdx].unk_50[chanIdx].unk_04 = (f32)val / 127.0f;
- if (D_8016E750[playerIdx].unk_50[chanIdx].unk_00 != D_8016E750[playerIdx].unk_50[chanIdx].unk_04) {
- D_8016E750[playerIdx].unk_50[chanIdx].unk_08 =
- (D_8016E750[playerIdx].unk_50[chanIdx].unk_00 - D_8016E750[playerIdx].unk_50[chanIdx].unk_04) /
+ // Volume is scaled relative to 127
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volTarget = (f32)val / 127.0f;
+ if (gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volCur !=
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volTarget) {
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volStep =
+ (gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volCur -
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volTarget) /
(f32)duration;
- D_8016E750[playerIdx].unk_50[chanIdx].unk_0C = duration;
- D_8016E750[playerIdx].unk_252 |= 1 << chanIdx;
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volTimer = duration;
+ gActiveSeqs[seqPlayerIndex].volChannelFlags |= 1 << channelIndex;
}
break;
- case 0x7:
- // set global io port
+ case SEQCMD_OP_SET_PLAYER_IO:
+ // Set global io port
port = (cmd & 0xFF0000) >> 16;
val = cmd & 0xFF;
- Audio_QueueCmdS8(0x46000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(port, 0, 8), val);
+ Audio_QueueCmdS8(0x46000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(port, 0, 8), val);
break;
- case 0x8:
- // set io port if channel masked
- chanIdx = (cmd & 0xF00) >> 8;
+ case SEQCMD_OP_SET_CHANNEL_IO:
+ // Set io port if channel masked
+ channelIndex = (cmd & 0xF00) >> 8;
port = (cmd & 0xFF0000) >> 16;
val = cmd & 0xFF;
- if ((D_8016E750[playerIdx].unk_258 & (1 << chanIdx)) == 0) {
- Audio_QueueCmdS8(0x06000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(chanIdx, 8, 8) | _SHIFTL(port, 0, 8),
+ if (!(gActiveSeqs[seqPlayerIndex].channelPortMask & (1 << channelIndex))) {
+ Audio_QueueCmdS8(0x06000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(channelIndex, 8, 8) |
+ _SHIFTL(port, 0, 8),
val);
}
break;
- case 0x9:
- // set channel mask for command 0x8
- D_8016E750[playerIdx].unk_258 = cmd & 0xFFFF;
+ case SEQCMD_OP_SET_CHANNEL_IO_DISABLE_MASK:
+ // Disable channel io specifically for
+ // `SEQCMD_OP_SET_CHANNEL_IO` This can be bypassed by setting channel io through `Audio_QueueCmdS8` 0x6
+ // directly. This is accomplished by setting a channel mask.
+ gActiveSeqs[seqPlayerIndex].channelPortMask = cmd & 0xFFFF;
break;
- case 0xA:
- // set channel stop mask
- channelMask = cmd & 0xFFFF;
- if (channelMask != 0) {
- // with channel mask channelMask...
- Audio_QueueCmdU16(0x90000000 | _SHIFTL(playerIdx, 16, 8), channelMask);
- // stop channels
- Audio_QueueCmdS8(0x08000000 | _SHIFTL(playerIdx, 16, 8) | 0xFF00, 1);
- }
- channelMaskReversed = channelMask ^ 0xFFFF;
- if (channelMaskReversed != 0) {
- // with channel mask ~channelMask...
- Audio_QueueCmdU16(0x90000000 | _SHIFTL(playerIdx, 16, 8), channelMaskReversed);
- // unstop channels
- Audio_QueueCmdS8(0x08000000 | _SHIFTL(playerIdx, 16, 8) | 0xFF00, 0);
+ case SEQCMD_OP_SET_CHANNEL_DISABLE_MASK:
+ // Disable or Reenable channels
+
+ // Disable channels
+ channelMaskDisable = cmd & 0xFFFF;
+ if (channelMaskDisable != 0) {
+ // Apply channel mask `channelMaskDisable`
+ Audio_QueueCmdU16(0x90000000 | _SHIFTL(seqPlayerIndex, 16, 8), channelMaskDisable);
+ // Disable channels
+ Audio_QueueCmdS8(0x08000000 | _SHIFTL(seqPlayerIndex, 16, 8) | 0xFF00, 1);
+ }
+
+ // Reenable channels
+ channelMaskEnable = (channelMaskDisable ^ 0xFFFF);
+ if (channelMaskEnable != 0) {
+ // Apply channel mask `channelMaskEnable`
+ Audio_QueueCmdU16(0x90000000 | _SHIFTL(seqPlayerIndex, 16, 8), channelMaskEnable);
+ // Enable channels
+ Audio_QueueCmdS8(0x08000000 | _SHIFTL(seqPlayerIndex, 16, 8) | 0xFF00, 0);
}
break;
- case 0xB:
- // update tempo
- D_8016E750[playerIdx].unk_14 = cmd;
+ case SEQCMD_OP_TEMPO_CMD:
+ // Update a tempo using a sub-command system.
+ // Stores the cmd for processing elsewhere.
+ gActiveSeqs[seqPlayerIndex].tempoCmd = cmd;
break;
- case 0xC:
- // start sequence with setup commands
+ case SEQCMD_OP_SETUP_CMD:
+ // Queue a sub-command to execute once the sequence is finished playing
subOp = (cmd & 0xF00000) >> 20;
- if (subOp != 0xF) {
- if (D_8016E750[playerIdx].unk_4D < 7) {
- found = D_8016E750[playerIdx].unk_4D++;
- if (found < 8) {
- D_8016E750[playerIdx].unk_2C[found] = cmd;
- D_8016E750[playerIdx].unk_4C = 2;
+ if (subOp != SEQCMD_SUB_OP_SETUP_RESET_SETUP_CMDS) {
+ // Ensure the maximum number of setup commands is not exceeded
+ if (gActiveSeqs[seqPlayerIndex].setupCmdNum < (ARRAY_COUNT(gActiveSeqs[seqPlayerIndex].setupCmd) - 1)) {
+ found = gActiveSeqs[seqPlayerIndex].setupCmdNum++;
+ if (found < ARRAY_COUNT(gActiveSeqs[seqPlayerIndex].setupCmd)) {
+ gActiveSeqs[seqPlayerIndex].setupCmd[found] = cmd;
+ // Adds a delay of 2 frames before executing any setup commands.
+ // This allows setup commands to be requested along with a new sequence on a seqPlayerIndex.
+ // This 2 frame delay ensures the player is enabled before its state is checked for
+ // the purpose of deciding if the setup commands should be run.
+ // Otherwise, the setup commands will be executed before the sequence starts,
+ // when the player is still disabled, instead of when the newly played sequence ends.
+ gActiveSeqs[seqPlayerIndex].setupCmdTimer = 2;
}
}
} else {
- D_8016E750[playerIdx].unk_4D = 0;
+ // `SEQCMD_SUB_OP_SETUP_RESET_SETUP_CMDS`
+ // Discard all setup command requests on `seqPlayerIndex`
+ gActiveSeqs[seqPlayerIndex].setupCmdNum = 0;
}
break;
- case 0xE:
+ case SEQCMD_OP_GLOBAL_CMD:
+ // Apply a command that applies to all sequence players
subOp = (cmd & 0xF00) >> 8;
val = cmd & 0xFF;
switch (subOp) {
- case 0:
- // set sound mode
+ case SEQCMD_SUB_OP_GLOBAL_SET_SOUND_MODE:
+ // Set sound mode
Audio_QueueCmdS32(0xF0000000, gSoundModeList[val]);
break;
- case 1:
- // set sequence starting disabled?
- D_80133408 = val & 1;
+
+ case SEQCMD_SUB_OP_GLOBAL_DISABLE_NEW_SEQUENCES:
+ // Disable the starting of new sequences (except for the sfx player)
+ gStartSeqDisabled = val & 1;
break;
}
break;
- case 0xF:
- // change spec
+ case SEQCMD_OP_RESET_AUDIO_HEAP:
+ // Resets the audio heap based on the audio specifications and sfx channel layout
spec = cmd & 0xFF;
gSfxChannelLayout = (cmd & 0xFF00) >> 8;
oldSpec = gAudioSpecId;
@@ -356,28 +394,31 @@ void Audio_ProcessSeqCmd(u32 cmd) {
}
}
+/**
+ * Add the sequence cmd to the `sAudioSeqCmds` queue
+ */
void Audio_QueueSeqCmd(u32 cmd) {
- sAudioSeqCmds[gSeqCmdWrPos++] = cmd;
+ sAudioSeqCmds[gSeqCmdWritePos++] = cmd;
}
void Audio_ProcessSeqCmds(void) {
- while (gSeqCmdWrPos != gSeqCmdRdPos) {
- Audio_ProcessSeqCmd(sAudioSeqCmds[gSeqCmdRdPos++]);
+ while (gSeqCmdWritePos != gSeqCmdReadPos) {
+ Audio_ProcessSeqCmd(sAudioSeqCmds[gSeqCmdReadPos++]);
}
}
-u16 func_800FA0B4(u8 playerIdx) {
- if (!gAudioContext.seqPlayers[playerIdx].enabled) {
+u16 Audio_GetActiveSeqId(u8 seqPlayerIndex) {
+ if (!gAudioContext.seqPlayers[seqPlayerIndex].enabled) {
return NA_BGM_DISABLED;
}
- return D_8016E750[playerIdx].unk_254;
+ return gActiveSeqs[seqPlayerIndex].seqId;
}
-s32 func_800FA11C(u32 arg0, u32 arg1) {
+s32 Audio_IsSeqCmdNotQueued(u32 cmdVal, u32 cmdMask) {
u8 i;
- for (i = gSeqCmdRdPos; i != gSeqCmdWrPos; i++) {
- if (arg0 == (sAudioSeqCmds[i] & arg1)) {
+ for (i = gSeqCmdReadPos; i != gSeqCmdWritePos; i++) {
+ if ((sAudioSeqCmds[i] & cmdMask) == cmdVal) {
return false;
}
}
@@ -385,263 +426,342 @@ s32 func_800FA11C(u32 arg0, u32 arg1) {
return true;
}
-void func_800FA174(u8 playerIdx) {
- D_8016E348[playerIdx] = 0;
+// Unused
+void Audio_ResetSequenceRequests(u8 seqPlayerIndex) {
+ sNumSeqRequests[seqPlayerIndex] = 0;
}
-void func_800FA18C(u8 playerIdx, u8 arg1) {
+/**
+ * Check if the setup command is queued. If it is, then replace the command
+ * with `SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME`.
+ * Unused
+ */
+void Audio_ReplaceSeqCmdSetupOpVolRestore(u8 seqPlayerIndex, u8 setupOpDisabled) {
u8 i;
- for (i = 0; i < D_8016E750[playerIdx].unk_4D; i++) {
- u8 unkb = (D_8016E750[playerIdx].unk_2C[i] & 0xF00000) >> 20;
+ for (i = 0; i < gActiveSeqs[seqPlayerIndex].setupCmdNum; i++) {
+ u8 setupOp = (gActiveSeqs[seqPlayerIndex].setupCmd[i] & 0xF00000) >> 20;
- if (unkb == arg1) {
- D_8016E750[playerIdx].unk_2C[i] = 0xFF000000;
+ if (setupOp == setupOpDisabled) {
+ gActiveSeqs[seqPlayerIndex].setupCmd[i] = 0xFF000000;
}
}
}
-void Audio_SetVolScale(u8 playerIdx, u8 scaleIdx, u8 targetVol, u8 volFadeTimer) {
+void Audio_SetVolumeScale(u8 seqPlayerIndex, u8 scaleIndex, u8 targetVol, u8 volFadeTimer) {
f32 volScale;
u8 i;
- D_8016E750[playerIdx].volScales[scaleIdx] = targetVol & 0x7F;
+ gActiveSeqs[seqPlayerIndex].volScales[scaleIndex] = targetVol & 0x7F;
if (volFadeTimer != 0) {
- D_8016E750[playerIdx].fadeVolUpdate = 1;
- D_8016E750[playerIdx].volFadeTimer = volFadeTimer;
+ gActiveSeqs[seqPlayerIndex].fadeVolUpdate = true;
+ gActiveSeqs[seqPlayerIndex].volFadeTimer = volFadeTimer;
} else {
- for (i = 0, volScale = 1.0f; i < 4; i++) {
- volScale *= D_8016E750[playerIdx].volScales[i] / 127.0f;
+ for (i = 0, volScale = 1.0f; i < VOL_SCALE_INDEX_MAX; i++) {
+ volScale *= gActiveSeqs[seqPlayerIndex].volScales[i] / 127.0f;
}
- Audio_SetVolScaleNow(playerIdx, volFadeTimer, volScale);
+ SEQCMD_SET_PLAYER_VOLUME_NOW(seqPlayerIndex, volFadeTimer, volScale);
}
}
-void func_800FA3DC(void) {
- u32 temp_a1;
- u16 temp_lo;
- u16 temp_v1;
- u16 phi_a2;
- u8 temp_v0_4;
- u8 temp_a0;
- u8 temp_s1;
- u8 temp_s0_3;
- u8 temp_a3_3;
- s32 pad[3];
- u32 dummy;
- f32 phi_f0;
- u8 phi_t0;
- u8 playerIdx;
+/**
+ * Update different commands and requests for active sequences
+ */
+void Audio_UpdateActiveSequences(void) {
+ u32 tempoCmd;
+ u8 tempoOp;
+ u16 tempoPrev;
+ u16 tempoTarget;
+ u8 setupOp;
+ u8 targetSeqPlayerIndex;
+ u8 setupVal2;
+ u8 setupVal1;
+ u16 seqId;
+ s32 pad[2];
+ u16 channelMask;
+ u32 retMsg;
+ f32 volume;
+ u8 tempoTimer;
+ u8 seqPlayerIndex;
u8 j;
- u8 k;
-
- for (playerIdx = 0; playerIdx < 4; playerIdx++) {
- if (D_8016E750[playerIdx].unk_260 != 0) {
- switch (func_800E5E20(&dummy)) {
- case 1:
- case 2:
- case 3:
- case 4:
- D_8016E750[playerIdx].unk_260 = 0;
- Audio_ProcessSeqCmd(D_8016E750[playerIdx].unk_25C);
+ u8 channelIndex;
+
+ for (seqPlayerIndex = 0; seqPlayerIndex < 4; seqPlayerIndex++) {
+
+ // The setup for this block of code was not fully implemented until Majora's Mask.
+ // The intent was to load soundfonts asynchronously before playing a
+ // sequence in `Audio_StartSequence` using `(seqArgs & 0x80)`.
+ // Checks if the requested sequence is finished loading fonts
+ if (gActiveSeqs[seqPlayerIndex].isWaitingForFonts) {
+ switch (func_800E5E20(&retMsg)) {
+ case SEQ_PLAYER_BGM_MAIN + 1:
+ case SEQ_PLAYER_FANFARE + 1:
+ case SEQ_PLAYER_SFX + 1:
+ case SEQ_PLAYER_BGM_SUB + 1:
+ // The fonts have been loaded successfully.
+ gActiveSeqs[seqPlayerIndex].isWaitingForFonts = false;
+ // Queue the same command that was stored previously
+ // The code to store this command is missing in OoT, so no command is executed
+ Audio_ProcessSeqCmd(gActiveSeqs[seqPlayerIndex].startSeqCmd);
break;
}
}
- if (D_8016E750[playerIdx].fadeVolUpdate) {
- phi_f0 = 1.0f;
- for (j = 0; j < 4; j++) {
- phi_f0 *= (D_8016E750[playerIdx].volScales[j] / 127.0f);
+ // Update global volume
+ if (gActiveSeqs[seqPlayerIndex].fadeVolUpdate) {
+ volume = 1.0f;
+ for (j = 0; j < VOL_SCALE_INDEX_MAX; j++) {
+ volume *= (gActiveSeqs[seqPlayerIndex].volScales[j] / 127.0f);
}
- Audio_SeqCmd4(playerIdx, D_8016E750[playerIdx].volFadeTimer, (u8)(phi_f0 * 127.0f));
- D_8016E750[playerIdx].fadeVolUpdate = 0;
+ SEQCMD_SET_PLAYER_VOLUME(seqPlayerIndex, gActiveSeqs[seqPlayerIndex].volFadeTimer, (u8)(volume * 127.0f));
+ gActiveSeqs[seqPlayerIndex].fadeVolUpdate = false;
}
- if (D_8016E750[playerIdx].unk_0C != 0) {
- D_8016E750[playerIdx].unk_0C--;
+ if (gActiveSeqs[seqPlayerIndex].volTimer != 0) {
+ gActiveSeqs[seqPlayerIndex].volTimer--;
- if (D_8016E750[playerIdx].unk_0C != 0) {
- D_8016E750[playerIdx].volCur = D_8016E750[playerIdx].volCur - D_8016E750[playerIdx].unk_08;
+ if (gActiveSeqs[seqPlayerIndex].volTimer != 0) {
+ gActiveSeqs[seqPlayerIndex].volCur -= gActiveSeqs[seqPlayerIndex].volStep;
} else {
- D_8016E750[playerIdx].volCur = D_8016E750[playerIdx].volTarget;
+ gActiveSeqs[seqPlayerIndex].volCur = gActiveSeqs[seqPlayerIndex].volTarget;
}
- Audio_QueueCmdF32(0x41000000 | _SHIFTL(playerIdx, 16, 8), D_8016E750[playerIdx].volCur);
+ Audio_QueueCmdF32(0x41000000 | _SHIFTL(seqPlayerIndex, 16, 8), gActiveSeqs[seqPlayerIndex].volCur);
}
- if (D_8016E750[playerIdx].unk_14 != 0) {
- temp_a1 = D_8016E750[playerIdx].unk_14;
- phi_t0 = (temp_a1 & 0xFF0000) >> 15;
- phi_a2 = temp_a1 & 0xFFF;
- if (phi_t0 == 0) {
- phi_t0++;
- }
-
- if (gAudioContext.seqPlayers[playerIdx].enabled) {
- temp_lo = gAudioContext.seqPlayers[playerIdx].tempo / 0x30;
- temp_v0_4 = (temp_a1 & 0xF000) >> 12;
- switch (temp_v0_4) {
- case 1:
- phi_a2 += temp_lo;
+ // Process tempo
+ if (gActiveSeqs[seqPlayerIndex].tempoCmd != 0) {
+ tempoCmd = gActiveSeqs[seqPlayerIndex].tempoCmd;
+ tempoTimer = (tempoCmd & 0xFF0000) >> 15;
+ tempoTarget = tempoCmd & 0xFFF;
+ if (tempoTimer == 0) {
+ tempoTimer++;
+ }
+
+ // Process tempo commands
+ if (gAudioContext.seqPlayers[seqPlayerIndex].enabled) {
+ tempoPrev = gAudioContext.seqPlayers[seqPlayerIndex].tempo / TATUMS_PER_BEAT;
+ tempoOp = (tempoCmd & 0xF000) >> 12;
+ switch (tempoOp) {
+ case SEQCMD_SUB_OP_TEMPO_SPEED_UP:
+ // Speed up tempo by `tempoTarget` amount
+ tempoTarget += tempoPrev;
break;
- case 2:
- if (phi_a2 < temp_lo) {
- phi_a2 = temp_lo - phi_a2;
+
+ case SEQCMD_SUB_OP_TEMPO_SLOW_DOWN:
+ // Slow down tempo by `tempoTarget` amount
+ if (tempoTarget < tempoPrev) {
+ tempoTarget = tempoPrev - tempoTarget;
}
break;
- case 3:
- phi_a2 = temp_lo * (phi_a2 / 100.0f);
+
+ case SEQCMD_SUB_OP_TEMPO_SCALE:
+ // Scale tempo by a multiplicative factor
+ tempoTarget = tempoPrev * (tempoTarget / 100.0f);
break;
- case 4:
- if (D_8016E750[playerIdx].unk_18) {
- phi_a2 = D_8016E750[playerIdx].unk_18;
- } else {
- phi_a2 = temp_lo;
- }
+
+ case SEQCMD_SUB_OP_TEMPO_RESET:
+ // Reset tempo to original tempo
+ tempoTarget = (gActiveSeqs[seqPlayerIndex].tempoOriginal != 0)
+ ? gActiveSeqs[seqPlayerIndex].tempoOriginal
+ : tempoPrev;
+ break;
+
+ default: // `SEQCMD_SUB_OP_TEMPO_SET`
+ // `tempoTarget` is the new tempo
break;
}
- if (phi_a2 > 300) {
- phi_a2 = 300;
+ if (tempoTarget > 300) {
+ tempoTarget = 300;
}
- if (D_8016E750[playerIdx].unk_18 == 0) {
- D_8016E750[playerIdx].unk_18 = temp_lo;
+ if (gActiveSeqs[seqPlayerIndex].tempoOriginal == 0) {
+ gActiveSeqs[seqPlayerIndex].tempoOriginal = tempoPrev;
}
- D_8016E750[playerIdx].unk_20 = phi_a2;
- D_8016E750[playerIdx].unk_1C = gAudioContext.seqPlayers[playerIdx].tempo / 0x30;
- D_8016E750[playerIdx].unk_24 = (D_8016E750[playerIdx].unk_1C - D_8016E750[playerIdx].unk_20) / phi_t0;
- D_8016E750[playerIdx].unk_28 = phi_t0;
- D_8016E750[playerIdx].unk_14 = 0;
+ gActiveSeqs[seqPlayerIndex].tempoTarget = tempoTarget;
+ gActiveSeqs[seqPlayerIndex].tempoCur = gAudioContext.seqPlayers[seqPlayerIndex].tempo / TATUMS_PER_BEAT;
+ gActiveSeqs[seqPlayerIndex].tempoStep =
+ (gActiveSeqs[seqPlayerIndex].tempoCur - gActiveSeqs[seqPlayerIndex].tempoTarget) / tempoTimer;
+ gActiveSeqs[seqPlayerIndex].tempoTimer = tempoTimer;
+ gActiveSeqs[seqPlayerIndex].tempoCmd = 0;
}
}
- if (D_8016E750[playerIdx].unk_28 != 0) {
- D_8016E750[playerIdx].unk_28--;
- if (D_8016E750[playerIdx].unk_28 != 0) {
- D_8016E750[playerIdx].unk_1C = D_8016E750[playerIdx].unk_1C - D_8016E750[playerIdx].unk_24;
+ // Step tempo to target
+ if (gActiveSeqs[seqPlayerIndex].tempoTimer != 0) {
+ gActiveSeqs[seqPlayerIndex].tempoTimer--;
+ if (gActiveSeqs[seqPlayerIndex].tempoTimer != 0) {
+ gActiveSeqs[seqPlayerIndex].tempoCur -= gActiveSeqs[seqPlayerIndex].tempoStep;
} else {
- D_8016E750[playerIdx].unk_1C = D_8016E750[playerIdx].unk_20;
+ gActiveSeqs[seqPlayerIndex].tempoCur = gActiveSeqs[seqPlayerIndex].tempoTarget;
}
- // set tempo
- Audio_QueueCmdS32(0x47000000 | _SHIFTL(playerIdx, 16, 8), D_8016E750[playerIdx].unk_1C);
+ // Set tempo
+ Audio_QueueCmdS32(0x47000000 | _SHIFTL(seqPlayerIndex, 16, 8), gActiveSeqs[seqPlayerIndex].tempoCur);
}
- if (D_8016E750[playerIdx].unk_252 != 0) {
- for (k = 0; k < 0x10; k++) {
- if (D_8016E750[playerIdx].unk_50[k].unk_0C != 0) {
- D_8016E750[playerIdx].unk_50[k].unk_0C--;
- if (D_8016E750[playerIdx].unk_50[k].unk_0C != 0) {
- D_8016E750[playerIdx].unk_50[k].unk_00 -= D_8016E750[playerIdx].unk_50[k].unk_08;
+ // Update channel volumes
+ if (gActiveSeqs[seqPlayerIndex].volChannelFlags != 0) {
+ for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
+ if (gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volTimer != 0) {
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volTimer--;
+ if (gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volTimer != 0) {
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volCur -=
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volStep;
} else {
- D_8016E750[playerIdx].unk_50[k].unk_00 = D_8016E750[playerIdx].unk_50[k].unk_04;
- D_8016E750[playerIdx].unk_252 ^= (1 << k);
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volCur =
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volTarget;
+ gActiveSeqs[seqPlayerIndex].volChannelFlags ^= (1 << channelIndex);
}
- // CHAN_UPD_VOL_SCALE (playerIdx = seq, k = chan)
- Audio_QueueCmdF32(0x01000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(k, 8, 8),
- D_8016E750[playerIdx].unk_50[k].unk_00);
+ // `CHAN_UPD_VOL_SCALE`
+ Audio_QueueCmdF32(0x01000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(channelIndex, 8, 8),
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volCur);
}
}
}
- if (D_8016E750[playerIdx].unk_250 != 0) {
- for (k = 0; k < 0x10; k++) {
- if (D_8016E750[playerIdx].unk_50[k].unk_1C != 0) {
- D_8016E750[playerIdx].unk_50[k].unk_1C--;
- if (D_8016E750[playerIdx].unk_50[k].unk_1C != 0) {
- D_8016E750[playerIdx].unk_50[k].unk_10 -= D_8016E750[playerIdx].unk_50[k].unk_18;
+ // Update frequencies
+ if (gActiveSeqs[seqPlayerIndex].freqScaleChannelFlags != 0) {
+ for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
+ if (gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleTimer != 0) {
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleTimer--;
+ if (gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleTimer != 0) {
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleCur -=
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleStep;
} else {
- D_8016E750[playerIdx].unk_50[k].unk_10 = D_8016E750[playerIdx].unk_50[k].unk_14;
- D_8016E750[playerIdx].unk_250 ^= (1 << k);
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleCur =
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleTarget;
+ gActiveSeqs[seqPlayerIndex].freqScaleChannelFlags ^= (1 << channelIndex);
}
- // CHAN_UPD_FREQ_SCALE
- Audio_QueueCmdF32(0x04000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(k, 8, 8),
- D_8016E750[playerIdx].unk_50[k].unk_10);
+ // `CHAN_UPD_FREQ_SCALE`
+ Audio_QueueCmdF32(0x04000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(channelIndex, 8, 8),
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleCur);
}
}
}
- if (D_8016E750[playerIdx].unk_4D != 0) {
- if (func_800FA11C(0xF0000000, 0xF0000000) == 0) {
- D_8016E750[playerIdx].unk_4D = 0;
+ // Process setup commands
+ if (gActiveSeqs[seqPlayerIndex].setupCmdNum != 0) {
+ // If there is a SeqCmd to reset the audio heap queued, then drop all setup commands
+ if (!Audio_IsSeqCmdNotQueued(SEQCMD_OP_RESET_AUDIO_HEAP << 28, SEQCMD_OP_MASK)) {
+ gActiveSeqs[seqPlayerIndex].setupCmdNum = 0;
return;
}
- if (D_8016E750[playerIdx].unk_4C != 0) {
- D_8016E750[playerIdx].unk_4C--;
+ // Only process setup commands once the timer reaches zero
+ if (gActiveSeqs[seqPlayerIndex].setupCmdTimer != 0) {
+ gActiveSeqs[seqPlayerIndex].setupCmdTimer--;
continue;
}
- if (gAudioContext.seqPlayers[playerIdx].enabled) {
+ // Only process setup commands if `seqPlayerIndex` if no longer playing
+ // i.e. the `seqPlayer` is no longer enabled
+ if (gAudioContext.seqPlayers[seqPlayerIndex].enabled) {
continue;
}
- for (j = 0; j < D_8016E750[playerIdx].unk_4D; j++) {
- temp_a0 = (D_8016E750[playerIdx].unk_2C[j] & 0x00F00000) >> 20;
- temp_s1 = (D_8016E750[playerIdx].unk_2C[j] & 0x000F0000) >> 16;
- temp_s0_3 = (D_8016E750[playerIdx].unk_2C[j] & 0xFF00) >> 8;
- temp_a3_3 = D_8016E750[playerIdx].unk_2C[j] & 0xFF;
+ for (j = 0; j < gActiveSeqs[seqPlayerIndex].setupCmdNum; j++) {
+ setupOp = (gActiveSeqs[seqPlayerIndex].setupCmd[j] & 0x00F00000) >> 20;
+ targetSeqPlayerIndex = (gActiveSeqs[seqPlayerIndex].setupCmd[j] & 0x000F0000) >> 16;
+ setupVal2 = (gActiveSeqs[seqPlayerIndex].setupCmd[j] & 0xFF00) >> 8;
+ setupVal1 = gActiveSeqs[seqPlayerIndex].setupCmd[j] & 0xFF;
- switch (temp_a0) {
- case 0:
- Audio_SetVolScale(temp_s1, 1, 0x7F, temp_a3_3);
+ switch (setupOp) {
+ case SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME:
+ // Restore `targetSeqPlayerIndex` volume back to normal levels
+ Audio_SetVolumeScale(targetSeqPlayerIndex, VOL_SCALE_INDEX_FANFARE, 0x7F, setupVal1);
break;
- case 7:
- if (D_8016E348[playerIdx] == temp_a3_3) {
- Audio_SetVolScale(temp_s1, 1, 0x7F, temp_s0_3);
+
+ case SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME_IF_QUEUED:
+ // Restore `targetSeqPlayerIndex` volume back to normal levels,
+ // but only if the number of sequence queue requests from `sSeqRequests`
+ // exactly matches the argument to the command
+ if (setupVal1 == sNumSeqRequests[seqPlayerIndex]) {
+ Audio_SetVolumeScale(targetSeqPlayerIndex, VOL_SCALE_INDEX_FANFARE, 0x7F, setupVal2);
}
break;
- case 1:
- Audio_SeqCmd3(playerIdx, D_8016E750[playerIdx].unk_254);
+
+ case SEQCMD_SUB_OP_SETUP_SEQ_UNQUEUE:
+ // Unqueue `seqPlayerIndex` from sSeqRequests
+ //! @bug this command does not work as intended as unqueueing
+ //! the sequence relies on `gActiveSeqs[seqPlayerIndex].seqId`
+ //! However, `gActiveSeqs[seqPlayerIndex].seqId` is reset before the sequence on
+ //! `seqPlayerIndex` is requested to stop, i.e. before the sequence is disabled and setup
+ //! commands (including this command) can run. A simple fix would have been to unqueue based on
+ //! `gActiveSeqs[seqPlayerIndex].prevSeqId` instead
+ SEQCMD_UNQUEUE_SEQUENCE(seqPlayerIndex, 0, gActiveSeqs[seqPlayerIndex].seqId);
break;
- case 2:
- Audio_StartSeq(temp_s1, 1, D_8016E750[temp_s1].unk_254);
- D_8016E750[temp_s1].fadeVolUpdate = 1;
- D_8016E750[temp_s1].volScales[1] = 0x7F;
+
+ case SEQCMD_SUB_OP_SETUP_RESTART_SEQ:
+ // Restart the currently active sequence on `targetSeqPlayerIndex` with full volume.
+ // Sequence on `targetSeqPlayerIndex` must still be active to play (can be muted)
+ SEQCMD_PLAY_SEQUENCE(targetSeqPlayerIndex, 1, 0, gActiveSeqs[targetSeqPlayerIndex].seqId);
+ gActiveSeqs[targetSeqPlayerIndex].fadeVolUpdate = true;
+ gActiveSeqs[targetSeqPlayerIndex].volScales[VOL_SCALE_INDEX_FANFARE] = 0x7F;
break;
- case 3:
- Audio_SeqCmdB30(temp_s1, temp_s0_3, temp_a3_3);
+
+ case SEQCMD_SUB_OP_SETUP_TEMPO_SCALE:
+ // Scale tempo by a multiplicative factor
+ SEQCMD_SCALE_TEMPO(targetSeqPlayerIndex, setupVal2, setupVal1);
break;
- case 4:
- Audio_SeqCmdB40(temp_s1, temp_a3_3, 0);
+
+ case SEQCMD_SUB_OP_SETUP_TEMPO_RESET:
+ // Reset tempo to previous tempo
+ SEQCMD_RESET_TEMPO(targetSeqPlayerIndex, setupVal1);
break;
- case 5:
- temp_v1 = D_8016E750[playerIdx].unk_2C[j] & 0xFFFF;
- Audio_StartSeq(temp_s1, D_8016E750[temp_s1].unk_4E, temp_v1);
- Audio_SetVolScale(temp_s1, 1, 0x7F, 0);
- D_8016E750[temp_s1].unk_4E = 0;
+
+ case SEQCMD_SUB_OP_SETUP_PLAY_SEQ:
+ // Play the requested sequence
+ // Uses the fade timer set by `SEQCMD_SUB_OP_SETUP_SET_FADE_TIMER`
+ seqId = gActiveSeqs[seqPlayerIndex].setupCmd[j] & 0xFFFF;
+ SEQCMD_PLAY_SEQUENCE(targetSeqPlayerIndex, gActiveSeqs[targetSeqPlayerIndex].setupFadeTimer, 0,
+ seqId);
+ Audio_SetVolumeScale(targetSeqPlayerIndex, VOL_SCALE_INDEX_FANFARE, 0x7F, 0);
+ gActiveSeqs[targetSeqPlayerIndex].setupFadeTimer = 0;
break;
- case 6:
- D_8016E750[playerIdx].unk_4E = temp_s0_3;
+
+ case SEQCMD_SUB_OP_SETUP_SET_FADE_TIMER:
+ // A command specifically to support `SEQCMD_SUB_OP_SETUP_PLAY_SEQ`
+ // Sets the fade timer for the sequence requested in `SEQCMD_SUB_OP_SETUP_PLAY_SEQ`
+ gActiveSeqs[seqPlayerIndex].setupFadeTimer = setupVal2;
break;
- case 8:
- Audio_SetVolScale(temp_s1, temp_s0_3, 0x7F, temp_a3_3);
+
+ case SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME_WITH_SCALE_INDEX:
+ // Restore the volume back to default levels
+ // Allows a `scaleIndex` to be specified.
+ Audio_SetVolumeScale(targetSeqPlayerIndex, setupVal2, 0x7F, setupVal1);
break;
- case 14:
- if (temp_a3_3 & 1) {
+
+ case SEQCMD_SUB_OP_SETUP_POP_PERSISTENT_CACHE:
+ // Discard audio data by popping one more audio caches from the audio heap
+ if (setupVal1 & (1 << SEQUENCE_TABLE)) {
Audio_QueueCmdS32(0xE3000000, SEQUENCE_TABLE);
}
- if (temp_a3_3 & 2) {
+ if (setupVal1 & (1 << FONT_TABLE)) {
Audio_QueueCmdS32(0xE3000000, FONT_TABLE);
}
- if (temp_a3_3 & 4) {
+ if (setupVal1 & (1 << SAMPLE_TABLE)) {
Audio_QueueCmdS32(0xE3000000, SAMPLE_TABLE);
}
break;
- case 9:
- temp_v1 = D_8016E750[playerIdx].unk_2C[j] & 0xFFFF;
- Audio_SeqCmdA(temp_s1, temp_v1);
+
+ case SEQCMD_SUB_OP_SETUP_SET_CHANNEL_DISABLE_MASK:
+ // Disable (or reenable) specific channels of `targetSeqPlayerIndex`
+ channelMask = gActiveSeqs[seqPlayerIndex].setupCmd[j] & 0xFFFF;
+ SEQCMD_SET_CHANNEL_DISABLE_MASK(targetSeqPlayerIndex, channelMask);
break;
- case 10:
- Audio_SeqCmd5(temp_s1, temp_s0_3, (temp_a3_3 * 10) & 0xFFFF);
+
+ case SEQCMD_SUB_OP_SETUP_SET_PLAYER_FREQ:
+ // Scale all channels of `targetSeqPlayerIndex`
+ SEQCMD_SET_PLAYER_FREQ(targetSeqPlayerIndex, setupVal2, (setupVal1 * 10) & 0xFFFF);
break;
}
}
- D_8016E750[playerIdx].unk_4D = 0;
+ gActiveSeqs[seqPlayerIndex].setupCmdNum = 0;
}
}
}
@@ -665,39 +785,43 @@ u8 func_800FAD34(void) {
return D_80133418;
}
-void func_800FADF8(void) {
- u8 playerIdx, j;
-
- for (playerIdx = 0; playerIdx < 4; playerIdx++) {
- D_8016E348[playerIdx] = 0;
- D_8016E750[playerIdx].unk_254 = NA_BGM_DISABLED;
- D_8016E750[playerIdx].unk_256 = NA_BGM_DISABLED;
- D_8016E750[playerIdx].unk_28 = 0;
- D_8016E750[playerIdx].unk_18 = 0;
- D_8016E750[playerIdx].unk_14 = 0;
- D_8016E750[playerIdx].unk_258 = 0;
- D_8016E750[playerIdx].unk_4D = 0;
- D_8016E750[playerIdx].unk_4E = 0;
- D_8016E750[playerIdx].unk_250 = 0;
- D_8016E750[playerIdx].unk_252 = 0;
- for (j = 0; j < 4; j++) {
- D_8016E750[playerIdx].volScales[j] = 0x7F;
+void Audio_ResetActiveSequences(void) {
+ u8 seqPlayerIndex;
+ u8 scaleIndex;
+
+ for (seqPlayerIndex = 0; seqPlayerIndex < 4; seqPlayerIndex++) {
+ sNumSeqRequests[seqPlayerIndex] = 0;
+
+ gActiveSeqs[seqPlayerIndex].seqId = NA_BGM_DISABLED;
+ gActiveSeqs[seqPlayerIndex].prevSeqId = NA_BGM_DISABLED;
+ gActiveSeqs[seqPlayerIndex].tempoTimer = 0;
+ gActiveSeqs[seqPlayerIndex].tempoOriginal = 0;
+ gActiveSeqs[seqPlayerIndex].tempoCmd = 0;
+ gActiveSeqs[seqPlayerIndex].channelPortMask = 0;
+ gActiveSeqs[seqPlayerIndex].setupCmdNum = 0;
+ gActiveSeqs[seqPlayerIndex].setupFadeTimer = 0;
+ gActiveSeqs[seqPlayerIndex].freqScaleChannelFlags = 0;
+ gActiveSeqs[seqPlayerIndex].volChannelFlags = 0;
+ for (scaleIndex = 0; scaleIndex < VOL_SCALE_INDEX_MAX; scaleIndex++) {
+ gActiveSeqs[seqPlayerIndex].volScales[scaleIndex] = 0x7F;
}
- D_8016E750[playerIdx].volFadeTimer = 1;
- D_8016E750[playerIdx].fadeVolUpdate = 1;
+
+ gActiveSeqs[seqPlayerIndex].volFadeTimer = 1;
+ gActiveSeqs[seqPlayerIndex].fadeVolUpdate = true;
}
}
-void func_800FAEB4(void) {
- u8 playerIdx, j;
+void Audio_ResetActiveSequencesAndVolume(void) {
+ u8 seqPlayerIndex;
+ u8 scaleIndex;
- for (playerIdx = 0; playerIdx < 4; playerIdx++) {
- D_8016E750[playerIdx].volCur = 1.0f;
- D_8016E750[playerIdx].unk_0C = 0;
- D_8016E750[playerIdx].fadeVolUpdate = 0;
- for (j = 0; j < 4; j++) {
- D_8016E750[playerIdx].volScales[j] = 0x7F;
+ for (seqPlayerIndex = 0; seqPlayerIndex < 4; seqPlayerIndex++) {
+ gActiveSeqs[seqPlayerIndex].volCur = 1.0f;
+ gActiveSeqs[seqPlayerIndex].volTimer = 0;
+ gActiveSeqs[seqPlayerIndex].fadeVolUpdate = false;
+ for (scaleIndex = 0; scaleIndex < VOL_SCALE_INDEX_MAX; scaleIndex++) {
+ gActiveSeqs[seqPlayerIndex].volScales[scaleIndex] = 0x7F;
}
}
- func_800FADF8();
+ Audio_ResetActiveSequences();
}
diff --git a/src/code/z_demo.c b/src/code/z_demo.c
index e1c4f7db3..9af0c6f93 100644
--- a/src/code/z_demo.c
+++ b/src/code/z_demo.c
@@ -449,15 +449,15 @@ void Cutscene_Command_StopBGM(PlayState* play, CutsceneContext* csCtx, CsCmdMusi
// Command 0x7C: Fade Background Music over duration
void Cutscene_Command_FadeBGM(PlayState* play, CutsceneContext* csCtx, CsCmdMusicFade* cmd) {
- u8 var1;
+ u8 fadeTimer;
if ((csCtx->frames == cmd->startFrame) && (csCtx->frames < cmd->endFrame)) {
- var1 = cmd->endFrame - cmd->startFrame;
+ fadeTimer = cmd->endFrame - cmd->startFrame;
if (cmd->type == 3) {
- Audio_QueueSeqCmd(var1 << 0x10 | (0x1 << 28 | SEQ_PLAYER_FANFARE << 24 | 0xFF));
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, fadeTimer);
} else {
- Audio_QueueSeqCmd(var1 << 0x10 | (0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0xFF));
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, fadeTimer);
}
}
}
diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c
index ec4941255..b589766d0 100644
--- a/src/code/z_kankyo.c
+++ b/src/code/z_kankyo.c
@@ -2035,7 +2035,7 @@ void Environment_PlaySceneSequence(PlayState* play) {
Audio_PlayNatureAmbienceSequence(NATURE_ID_KOKIRI_REGION);
} else if (((void)0, gSaveContext.forcedSeqId) != NA_BGM_GENERAL_SFX) {
if (!Environment_IsForcedSequenceDisabled()) {
- Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | (s32)((void)0, gSaveContext.forcedSeqId));
+ SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, ((void)0, gSaveContext.forcedSeqId));
}
gSaveContext.forcedSeqId = NA_BGM_GENERAL_SFX;
} else if (play->sequenceCtx.seqId == NA_BGM_NO_MUSIC) {
@@ -2102,7 +2102,7 @@ void Environment_PlayTimeBasedSequence(PlayState* play) {
if (gSaveContext.dayTime > CLOCK_TIME(17, 10)) {
if (play->envCtx.precipitation[PRECIP_RAIN_MAX] == 0 &&
play->envCtx.precipitation[PRECIP_SOS_MAX] == 0) {
- Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0xF000FF);
+ SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 240);
}
play->envCtx.timeSeqState++;
@@ -2570,7 +2570,7 @@ void Environment_StopStormNatureAmbience(PlayState* play) {
Audio_SetNatureAmbienceChannelIO(NATURE_CHANNEL_RAIN, CHANNEL_IO_PORT_1, 0);
Audio_SetNatureAmbienceChannelIO(NATURE_CHANNEL_LIGHTNING, CHANNEL_IO_PORT_1, 0);
- if (func_800FA0B4(SEQ_PLAYER_BGM_MAIN) == NA_BGM_NATURE_AMBIENCE) {
+ if (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) == NA_BGM_NATURE_AMBIENCE) {
gSaveContext.seqId = NA_BGM_NATURE_SFX_RAIN;
Environment_PlaySceneSequence(play);
}
diff --git a/src/code/z_scene.c b/src/code/z_scene.c
index 6f2115994..ac1c779ef 100644
--- a/src/code/z_scene.c
+++ b/src/code/z_scene.c
@@ -397,7 +397,7 @@ void Scene_CommandSoundSettings(PlayState* play, SceneCmd* cmd) {
play->sequenceCtx.natureAmbienceId = cmd->soundSettings.natureAmbienceId;
if (gSaveContext.seqId == (u8)NA_BGM_DISABLED) {
- Audio_QueueSeqCmd(cmd->soundSettings.specId | 0xF0000000);
+ SEQCMD_RESET_AUDIO_HEAP(0, cmd->soundSettings.specId);
}
}