diff --git a/assets/xml/objects/object_bw.xml b/assets/xml/objects/object_bw.xml index f7d5ecead7..c2b76fd91e 100644 --- a/assets/xml/objects/object_bw.xml +++ b/assets/xml/objects/object_bw.xml @@ -1,29 +1,40 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/xml/objects/object_ice_objects.xml b/assets/xml/objects/object_ice_objects.xml index a4e2e9b12b..d21164bc15 100644 --- a/assets/xml/objects/object_ice_objects.xml +++ b/assets/xml/objects/object_ice_objects.xml @@ -2,23 +2,23 @@ - - - + + + - + - + - + - - + + diff --git a/assets/xml/objects/object_mori_hineri1.xml b/assets/xml/objects/object_mori_hineri1.xml index 517c02780b..a2033a6f97 100644 --- a/assets/xml/objects/object_mori_hineri1.xml +++ b/assets/xml/objects/object_mori_hineri1.xml @@ -1,4 +1,5 @@ + diff --git a/assets/xml/objects/object_mori_hineri1a.xml b/assets/xml/objects/object_mori_hineri1a.xml index fb20482ddf..d7e3489044 100644 --- a/assets/xml/objects/object_mori_hineri1a.xml +++ b/assets/xml/objects/object_mori_hineri1a.xml @@ -1,4 +1,5 @@ + diff --git a/assets/xml/objects/object_mori_hineri2.xml b/assets/xml/objects/object_mori_hineri2.xml index a23d9060c0..9f1c892afb 100644 --- a/assets/xml/objects/object_mori_hineri2.xml +++ b/assets/xml/objects/object_mori_hineri2.xml @@ -1,4 +1,5 @@ + diff --git a/assets/xml/objects/object_mori_hineri2a.xml b/assets/xml/objects/object_mori_hineri2a.xml index 282fd267f6..6fd6818562 100644 --- a/assets/xml/objects/object_mori_hineri2a.xml +++ b/assets/xml/objects/object_mori_hineri2a.xml @@ -1,4 +1,5 @@ + diff --git a/assets/xml/objects/object_mori_objects.xml b/assets/xml/objects/object_mori_objects.xml index bef9686f5c..aa24a38d70 100644 --- a/assets/xml/objects/object_mori_objects.xml +++ b/assets/xml/objects/object_mori_objects.xml @@ -1,4 +1,5 @@ + diff --git a/assets/xml/objects/object_mori_tex.xml b/assets/xml/objects/object_mori_tex.xml index ad4ba38e34..89fb06d354 100644 --- a/assets/xml/objects/object_mori_tex.xml +++ b/assets/xml/objects/object_mori_tex.xml @@ -1,5 +1,30 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/include/functions.h b/include/functions.h index fed4e51a11..08ce84c8cd 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1013,13 +1013,13 @@ s32 Player_InBlockingCsMode(PlayState* play, Player* this); s32 Player_InCsMode(PlayState* play); s32 func_8008E9C4(Player* this); s32 Player_IsChildWithHylianShield(Player* this); -s32 Player_ActionToModelGroup(Player* this, s32 actionParam); +s32 Player_ActionToModelGroup(Player* this, s32 itemAction); void Player_SetModelsForHoldingShield(Player* this); void Player_SetModels(Player* this, s32 modelGroup); void Player_SetModelGroup(Player* this, s32 modelGroup); void func_8008EC70(Player* this); void Player_SetEquipmentData(PlayState* play, Player* this); -void Player_UpdateBottleHeld(PlayState* play, Player* this, s32 item, s32 actionParam); +void Player_UpdateBottleHeld(PlayState* play, Player* this, s32 item, s32 itemAction); void func_8008EDF0(Player* this); void func_8008EE08(Player* this); void func_8008EEAC(PlayState* play, Actor* actor); @@ -1030,18 +1030,18 @@ u8 Player_GetMask(PlayState* play); Player* Player_UnsetMask(PlayState* play); s32 Player_HasMirrorShieldEquipped(PlayState* play); s32 Player_HasMirrorShieldSetToDraw(PlayState* play); -s32 Player_ActionToMagicSpell(Player* this, s32 actionParam); +s32 Player_ActionToMagicSpell(Player* this, s32 itemAction); s32 Player_HoldsHookshot(Player* this); s32 func_8008F128(Player* this); -s32 Player_ActionToMeleeWeapon(s32 actionParam); +s32 Player_ActionToMeleeWeapon(s32 itemAction); s32 Player_GetMeleeWeaponHeld(Player* this); s32 Player_HoldsTwoHandedWeapon(Player* this); s32 Player_HoldsBrokenKnife(Player* this); -s32 Player_ActionToBottle(Player* this, s32 actionParam); +s32 Player_ActionToBottle(Player* this, s32 itemAction); s32 Player_GetBottleHeld(Player* this); -s32 Player_ActionToExplosive(Player* this, s32 actionParam); +s32 Player_ActionToExplosive(Player* this, s32 itemAction); s32 Player_GetExplosiveHeld(Player* this); -s32 func_8008F2BC(Player* this, s32 actionParam); +s32 func_8008F2BC(Player* this, s32 itemAction); s32 func_8008F2F8(PlayState* play); void Player_DrawImpl(PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount, s32 lod, s32 tunic, s32 boots, s32 face, OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, @@ -1866,9 +1866,9 @@ void Audio_ClearSariaBgm(void); void Audio_ClearSariaBgmAtPos(Vec3f* pos); void Audio_PlaySariaBgm(Vec3f* pos, u16 seqId, u16 distMax); void Audio_ClearSariaBgm2(void); -void func_800F5510(u16 seqId); -void func_800F5550(u16 seqId); -void func_800F574C(f32 arg0, u8 arg2); +void Audio_PlayMorningSceneSequence(u16 seqId); +void Audio_PlaySceneSequence(u16 seqId); +void func_800F574C(f32 scaleTempoAndFreq, u8 duration); void func_800F5718(void); void func_800F5918(void); void func_800F595C(u16); @@ -1879,12 +1879,12 @@ void func_800F5B58(void); void func_800F5BF0(u8 natureAmbienceId); void Audio_PlayFanfare(u16); void func_800F5C2C(void); -void func_800F5E18(u8 playerIdx, u16 seqId, u8 fadeTimer, s8 arg3, s8 arg4); +void Audio_PlaySequenceWithSeqPlayerIO(u8 seqPlayerIndex, u16 seqId, u8 fadeInDuration, s8 ioPort, s8 ioData); void Audio_SetSequenceMode(u8 seqMode); void Audio_SetBgmEnemyVolume(f32 dist); -void func_800F6268(f32 dist, u16); +void Audio_UpdateMalonSinging(f32 dist, u16 seqId); void func_800F64E0(u8 arg0); -void func_800F6584(u8 arg0); +void Audio_ToggleMalonSinging(u8 malonSingingDisabled); void Audio_SetEnvReverb(s8 reverb); void Audio_SetCodeReverb(s8 reverb); void func_800F6700(s8 audioSetting); @@ -1898,7 +1898,7 @@ void func_800F6AB0(u16); // ? func_800F6BB8(?); void Audio_PreNMI(void); // ? func_800F6C34(?); -void Audio_SetNatureAmbienceChannelIO(u8 channelIdxRange, u8 port, u8 val); +void Audio_SetNatureAmbienceChannelIO(u8 channelIdxRange, u8 ioPort, u8 ioData); void Audio_PlayNatureAmbienceSequence(u8 natureAmbienceId); void Audio_Init(void); void Audio_InitSound(void); @@ -1915,8 +1915,6 @@ void Audio_StopSfxByBank(u8 bankId); void func_800F8884(u8 bankId, Vec3f* pos); void Audio_StopSfxByPosAndBank(u8 bankId, Vec3f* pos); void Audio_StopSfxByPos(Vec3f* pos); -void func_800F9280(u8 playerIdx, u8 seqId, u8 arg2, u16 fadeTimer); -void Audio_QueueSeqCmd(u32 cmd); void Audio_StopSfxByPosAndId(Vec3f* pos, u16 sfxId); void Audio_StopSfxByTokenAndId(u8 token, u16 sfxId); void Audio_StopSfxById(u32 sfxId); @@ -1924,19 +1922,17 @@ void Audio_ProcessSfxRequests(void); void func_800F8F88(void); u8 Audio_IsSfxPlaying(u32 sfxId); void Audio_ResetSfx(void); -void func_800F9474(u8, u16); -void func_800F94FC(u32); -void Audio_ProcessSeqCmd(u32); +void Audio_StartSequence(u8 seqPlayerIndex, u8 seqId, u8 seqArgs, u16 fadeInDuration); +void Audio_StopSequence(u8 seqPlayerIndex, u16 fadeOutDuration); +void Audio_QueueSeqCmd(u32 cmd); void Audio_ProcessSeqCmds(void); -u16 func_800FA0B4(u8 playerIdx); -s32 func_800FA11C(u32 arg0, u32 arg1); -void func_800FA174(u8); -void func_800FA18C(u8, u8); -void Audio_SetVolScale(u8 playerIdx, u8 scaleIdx, u8 targetVol, u8 volFadeTimer); -void func_800FA3DC(void); +u16 Audio_GetActiveSeqId(u8 seqPlayerIndex); +s32 Audio_IsSeqCmdNotQueued(u32 cmdVal, u32 cmdMask); +void Audio_SetVolumeScale(u8 seqPlayerIndex, u8 scaleIndex, u8 targetVol, u8 volFadeTimer); +void Audio_UpdateActiveSequences(void); u8 func_800FAD34(void); -void func_800FADF8(void); -void func_800FAEB4(void); +void Audio_ResetActiveSequences(void); +void Audio_ResetActiveSequencesAndVolume(void); void GfxPrint_SetColor(GfxPrint* this, u32 r, u32 g, u32 b, u32 a); void GfxPrint_SetPosPx(GfxPrint* this, s32 x, s32 y); void GfxPrint_SetPos(GfxPrint* this, s32 x, s32 y); diff --git a/include/regs.h b/include/regs.h index a873e34c96..7c58c035c7 100644 --- a/include/regs.h +++ b/include/regs.h @@ -106,6 +106,8 @@ #define R_TRANS_DBG_TYPE CREG(12) #define R_ENV_WIND_DIR(i) CREG(16 + (i)) #define R_ENV_WIND_SPEED CREG(19) +#define R_PAUSE_STICK_REPEAT_DELAY XREG(6) +#define R_PAUSE_STICK_REPEAT_DELAY_FIRST XREG(8) #define R_A_BTN_Y XREG(16) #define R_A_BTN_X XREG(17) #define R_A_ICON_Y XREG(19) diff --git a/include/seqcmd.h b/include/seqcmd.h new file mode 100644 index 0000000000..a2649b775f --- /dev/null +++ b/include/seqcmd.h @@ -0,0 +1,506 @@ +#ifndef SEQCMD_H +#define SEQCMD_H + +// ==== Primary commands ==== + +#define SEQCMD_OP_MASK 0xF0000000 + +typedef enum { + /* 0x0 */ SEQCMD_OP_PLAY_SEQUENCE, + /* 0x1 */ SEQCMD_OP_STOP_SEQUENCE, + /* 0x2 */ SEQCMD_OP_QUEUE_SEQUENCE, + /* 0x3 */ SEQCMD_OP_UNQUEUE_SEQUENCE, + /* 0x4 */ SEQCMD_OP_SET_PLAYER_VOLUME, + /* 0x5 */ SEQCMD_OP_SET_PLAYER_FREQ, + /* 0x6 */ SEQCMD_OP_SET_CHANNEL_VOLUME, + /* 0x7 */ SEQCMD_OP_SET_PLAYER_IO, + /* 0x8 */ SEQCMD_OP_SET_CHANNEL_IO, + /* 0x9 */ SEQCMD_OP_SET_CHANNEL_IO_DISABLE_MASK, + /* 0xA */ SEQCMD_OP_SET_CHANNEL_DISABLE_MASK, + /* 0xB */ SEQCMD_OP_TEMPO_CMD, + /* 0xC */ SEQCMD_OP_SETUP_CMD, + /* 0xD */ SEQCMD_OP_SET_CHANNEL_FREQ, + /* 0xE */ SEQCMD_OP_GLOBAL_CMD, + /* 0xF */ SEQCMD_OP_RESET_AUDIO_HEAP +} SeqCmdOp; + +// ==== Secondary commands ==== + +// Subset of `SEQCMD_OP_TEMPO_CMD` +typedef enum { + /* 0x0 */ SEQCMD_SUB_OP_TEMPO_SET, + /* 0x1 */ SEQCMD_SUB_OP_TEMPO_SPEED_UP, + /* 0x2 */ SEQCMD_SUB_OP_TEMPO_SLOW_DOWN, + /* 0x3 */ SEQCMD_SUB_OP_TEMPO_SCALE, + /* 0x4 */ SEQCMD_SUB_OP_TEMPO_RESET +} SeqCmdTempoCmdOp; + +// Subset of `SEQCMD_OP_SETUP_CMD` +typedef enum { + /* 0x0 */ SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME, + /* 0x1 */ SEQCMD_SUB_OP_SETUP_SEQ_UNQUEUE, + /* 0x2 */ SEQCMD_SUB_OP_SETUP_RESTART_SEQ, + /* 0x3 */ SEQCMD_SUB_OP_SETUP_TEMPO_SCALE, + /* 0x4 */ SEQCMD_SUB_OP_SETUP_TEMPO_RESET, + /* 0x5 */ SEQCMD_SUB_OP_SETUP_PLAY_SEQ, + /* 0x6 */ SEQCMD_SUB_OP_SETUP_SET_FADE_TIMER, + /* 0x7 */ SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME_IF_QUEUED, + /* 0x8 */ SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME_WITH_SCALE_INDEX, + /* 0x9 */ SEQCMD_SUB_OP_SETUP_SET_CHANNEL_DISABLE_MASK, + /* 0xA */ SEQCMD_SUB_OP_SETUP_SET_PLAYER_FREQ, + /* 0xE */ SEQCMD_SUB_OP_SETUP_POP_PERSISTENT_CACHE = 0xE, + /* 0xF */ SEQCMD_SUB_OP_SETUP_RESET_SETUP_CMDS +} SeqCmdSetupCmdOp; + +// Subset of `SEQCMD_OP_GLOBAL_CMD` +typedef enum { + /* 0x0 */ SEQCMD_SUB_OP_GLOBAL_SET_SOUND_MODE, + /* 0x1 */ SEQCMD_SUB_OP_GLOBAL_DISABLE_NEW_SEQUENCES +} SeqCmdSubCmdOp; + +// ==== Audio Sequence Primary Commands ==== + +/** + * Play a sequence on a given seqPlayer + * + * @param seqPlayerIndex the index of the seqPlayer to play the sequence + * @param fadeInDuration duration the sequence will fade in over + * @param seqArg no effect: < 0x7F, skip ticks: = 0x7F, will not play: >= 0x80 (see note) + * @param seqId the id of the sequence to play, see `SeqId` + * + * @note seqArg will also be stored in gActiveSeqs.seqId, any check against that seqId must also include seqArg. + * seqArg = 0x7F will interpret the duration as the number of ticks to skip. + * seqArg >= 0x80 was intented to load a soundFont asynchronously but the code is unfinished (based on MM). + */ +#define SEQCMD_PLAY_SEQUENCE(seqPlayerIndex, fadeInDuration, seqArg, seqId) \ + Audio_QueueSeqCmd((SEQCMD_OP_PLAY_SEQUENCE << 28) | ((u8)(seqPlayerIndex) << 24) | ((u8)(fadeInDuration) << 16) | \ + ((u8)(seqArg) << 8) | (u16)(seqId)) + +/** + * Stop a sequence on a given seqPlayer + * + * @param seqPlayerIndex the index of the seqPlayer to play the sequence + * @param fadeOutDuration duration the sequence will fade out over + * + * @note the 0xFF in the command is not read from at all, but is common in all Stop SeqPlayer Commands + */ +#define SEQCMD_STOP_SEQUENCE(seqPlayerIndex, fadeOutDuration) \ + Audio_QueueSeqCmd((SEQCMD_OP_STOP_SEQUENCE << 28) | 0xFF | ((u8)(seqPlayerIndex) << 24) | \ + ((u8)(fadeOutDuration) << 16)) + +/** + * Add a sequence to a queue of sequences associated with a given seqPlayer. + * If the sequence is first in queue, play the sequence + * + * @param seqPlayerIndex the index of the seqPlayer to queue the sequence + * @param fadeInDuration if the sequence is played, duration the sequence will fade in over + * @param priority priority in the queue. The highest valued priority will be queued to play first. Also used as `seqArg`. + * @param seqId the id of the sequence to play, see `SeqId` + * + * @note for the next sequence in the queue to play, the current sequence must be unqueued with the unqueue command + * @note for a priority >= 0x7F, similar effects happen as `seqArg` in the play sequence command + */ +#define SEQCMD_QUEUE_SEQUENCE(seqPlayerIndex, fadeInDuration, priority, seqId) \ + Audio_QueueSeqCmd((SEQCMD_OP_QUEUE_SEQUENCE << 28) | ((u8)(seqPlayerIndex) << 24) | ((u8)(fadeInDuration) << 16) | \ + ((u8)(priority) << 8) | (u8)(seqId)) + +/** + * Remove a sequence from a queue of sequences associated with a given seqPlayer. + * If the sequence is first in queue, stop the sequence, and play the next one in queue if any + * + * @param seqPlayerIndex the index of the seqPlayer to queue the sequence + * @param fadeInDuration if the sequence is stopped, duration the sequence will fade out over, and duration the next seq will fade in over + * @param seqId the id of the sequence to remove, see `SeqId` + * + * @note for the next sequence in the queue to play, the current sequence must be unqueued with this command + */ +#define SEQCMD_UNQUEUE_SEQUENCE(seqPlayerIndex, fadeOutInDuration, seqId) \ + Audio_QueueSeqCmd((SEQCMD_OP_UNQUEUE_SEQUENCE << 28) | ((u8)(seqPlayerIndex) << 24) | \ + ((u8)(fadeOutInDuration) << 16) | (seqId)) + +/** + * Set the volume of an entire sequence on a given seqPlayer. Fade to the volume over a specified duration + * + * @param seqPlayerIndex the index of the seqPlayer to modify + * @param duration duration to transition to the volume + * @param volume the target volume for the sequence. Ranged from 0-0xFF, with 0x7F mapping to 1.0f + */ +#define SEQCMD_SET_PLAYER_VOLUME(seqPlayerIndex, duration, volume) \ + Audio_QueueSeqCmd((SEQCMD_OP_SET_PLAYER_VOLUME << 28) | ((u8)(seqPlayerIndex) << 24) | ((duration) << 16) | \ + (volume)) + +/** + * Scale the frequency of every channel on a given seqPlayer over a specified duration. + * + * @param seqPlayerIndex the index of the seqPlayer to modify + * @param duration duration to transition to the frequency + * @param freqScale the scaling factor to shift the pitch. Ranged from 0-0xFFFF, with 1000 mapping to 1.0f + * + * @note 2000 will double the frequency (raise an octave), 500 will halve the frequency (lower an octave). + * Cannot be used with `SEQCMD_SET_CHANNEL_FREQ` as they will overwrite one another. + */ +#define SEQCMD_SET_PLAYER_FREQ(seqPlayerIndex, duration, freqScale) \ + Audio_QueueSeqCmd((SEQCMD_OP_SET_PLAYER_FREQ << 28) | ((u8)(seqPlayerIndex) << 24) | ((duration) << 16) | \ + (freqScale)) + +/** + * Scale the frequency of a specific channel on a given seqPlayer over a specified duration + * + * @param seqPlayerIndex the index of the seqPlayer to modify + * @param channelIndex the index of the channel to modify + * @param duration duration to transition to the frequency + * @param freqScale the scaling factor to shift the pitch. Ranged from 0-0xFFF, with 1000 mapping to 1.0f + * + * @note a frequency of 2000 will double the frequency (raise an octave), 500 will halve the frequency (lower an octave). + * Cannot be used with `SEQCMD_SET_PLAYER_FREQ` as they will overwrite one another. + */ +#define SEQCMD_SET_CHANNEL_FREQ(seqPlayerIndex, channelIndex, duration, freqScale) \ + Audio_QueueSeqCmd((SEQCMD_OP_SET_CHANNEL_FREQ << 28) | ((u8)(seqPlayerIndex) << 24) | ((duration) << 16) | \ + ((channelIndex) << 12) | (freqScale)) + +/** + * Set the volume of a specific channel on a given seqPlayer. Fade to the volume over a specified duration + * + * @param seqPlayerIndex the index of the seqPlayer to modify + * @param channelIndex the index of the channel to modify + * @param duration duration to transition to the volume + * @param volume the target volume for the sequence. Ranged from 0-0xFF, with 0x7F mapping to 1.0f + */ +#define SEQCMD_SET_CHANNEL_VOLUME(seqPlayerIndex, channelIndex, duration, volume) \ + Audio_QueueSeqCmd((SEQCMD_OP_SET_CHANNEL_VOLUME << 28) | ((u8)(seqPlayerIndex) << 24) | ((u8)(duration) << 16) | \ + ((u8)(channelIndex) << 8) | ((u8)volume)) + +/** + * Write a value that can be read as input directly by the sequence itself. This will be set to the global + * ioPort, which can affect the entire sequence. + * + * @param seqPlayerIndex the index of the seqPlayer to write the input to + * @param ioPort the index of the array to store the input-output value, + * @param ioData the value s8 that's written to the input-output array + * + * @note Each seqPlayer has 8 global ioPorts indexed 0-7. + * ioPort 0 and 1 are read-only-once, and will reset after being read by the sequence. + * ioPort 2-7 can be read multiple times. + */ +#define SEQCMD_SET_PLAYER_IO(seqPlayerIndex, ioPort, ioData) \ + Audio_QueueSeqCmd((SEQCMD_OP_SET_PLAYER_IO << 28) | ((u8)(seqPlayerIndex) << 24) | ((u8)(ioPort) << 16) | \ + (u8)(ioData)) + +/** + * Write a value that can be read as input directly by the sequence itself. This will be set to the channel + * ioPort, which will only affect a single channel. + * + * @param seqPlayerIndex the index of the seqPlayer to write the input to + * @param channelIndex the index of the channel to write the input to + * @param ioPort the index of the array to store the input-output value + * @param ioData the value s8 that's written to the input-output array + * + * @note Each channel has 8 channel ioPorts indexed 0-7. + * ioPort 0 and 1 are read-only-once, and will reset after being read by the sequence. + * ioPort 2-7 can be read multiple times. + */ +#define SEQCMD_SET_CHANNEL_IO(seqPlayerIndex, channelIndex, ioPort, ioData) \ + Audio_QueueSeqCmd((SEQCMD_OP_SET_CHANNEL_IO << 28) | ((u8)(seqPlayerIndex) << 24) | ((u8)(ioPort) << 16) | \ + ((u8)(channelIndex) << 8) | (u8)(ioData)) + +/** + * Disable (or reenable) specific channels from receiving input set by `SEQCMD_SET_CHANNEL_IO` + * + * @param seqPlayerIndex the index of the seqPlayer to modify + * @param channelMask a 16 bit mask where each bit maps to a channel. Bitflag on to disable + * + * @note using Audio_QueueCmdS8 0x06 will bypass this channelMask + */ +#define SEQCMD_SET_CHANNEL_IO_DISABLE_MASK(seqPlayerIndex, channelMask) \ + Audio_QueueSeqCmd((SEQCMD_OP_SET_CHANNEL_IO_DISABLE_MASK << 28) | ((u8)(seqPlayerIndex) << 24) | (u16)(channelMask)) + +/** + * Disable (or reenable) specific channels + * + * @param seqPlayerIndex the index of the seqPlayer to modify + * @param channelMask a 16 bit mask where each bit maps to a channel. Bitflag on to disable + */ +#define SEQCMD_SET_CHANNEL_DISABLE_MASK(seqPlayerIndex, channelMask) \ + Audio_QueueSeqCmd((SEQCMD_OP_SET_CHANNEL_DISABLE_MASK << 28) | ((u8)(seqPlayerIndex) << 24) | (u16)(channelMask)) + +// ==== Audio Sequence Tempo Commands ==== + +/** + * Set the absolute tempo of a sequence on a given seqPlayer, fading over a specified duration + * + * @param seqPlayerIndex the index of the seqPlayer to modify + * @param duration duration to transition to the tempo + * @param tempoTarget the target tempo for the sequence + * + * @note the absolute tempo is constrained to a maximum of 300 + */ +#define SEQCMD_SET_TEMPO(seqPlayerIndex, duration, tempoTarget) \ + Audio_QueueSeqCmd((SEQCMD_OP_TEMPO_CMD << 28) | (SEQCMD_SUB_OP_TEMPO_SET << 12) | ((u8)(seqPlayerIndex) << 24) | \ + ((u8)(duration) << 16) | (u16)(tempoTarget)) + +/** + * Increase the tempo of a sequence by a relative value on a given seqPlayer over a specified duration + * + * @param seqPlayerIndex the index of the seqPlayer to modify + * @param duration duration to transition to the tempo + * @param tempoIncrease the change to add to the current tempo + * + * @note the absolute tempo is constrained to a maximum of 300 + */ +#define SEQCMD_SPEED_UP_TEMPO(seqPlayerIndex, duration, tempoIncrease) \ + Audio_QueueSeqCmd((SEQCMD_OP_TEMPO_CMD << 28) | (SEQCMD_SUB_OP_TEMPO_SPEED_UP << 12) | \ + ((u8)(seqPlayerIndex) << 24) | ((u8)(duration) << 16) | (u16)(tempoIncrease)) + +/** + * Decrease the tempo of a sequence by a relative value on a given seqPlayer over a specified duration + * + * @param seqPlayerIndex the index of the seqPlayer to modify + * @param duration duration to transition to the tempo + * @param tempoDecrease the change to subtract to the current tempo + * + * @note the absolute tempo is constrained to a maximum of 300 + */ +#define SEQCMD_SLOW_DOWN_TEMPO(seqPlayerIndex, duration, tempoDecrease) \ + Audio_QueueSeqCmd((SEQCMD_OP_TEMPO_CMD << 28) | (SEQCMD_SUB_OP_TEMPO_SLOW_DOWN << 12) | \ + ((u8)(seqPlayerIndex) << 24) | ((u8)(duration) << 16) | (u16)(tempoDecrease)) + +/** + * Scale the tempo of a sequence by a multiplicative value on a given seqPlayer over a specified duration + * + * @param seqPlayerIndex the index of the seqPlayer to modify + * @param duration duration to transition to the tempo + * @param tempoScale the scaling factor of the tempo, relative to 100 + * + * @note a tempoScale of 200 will go double-time, 50 will go half-time. + * the absolute tempo is constrained to a maximum of 300 + */ +#define SEQCMD_SCALE_TEMPO(seqPlayerIndex, duration, tempoScale) \ + Audio_QueueSeqCmd((SEQCMD_OP_TEMPO_CMD << 28) | (SEQCMD_SUB_OP_TEMPO_SCALE << 12) | ((u8)(seqPlayerIndex) << 24) | \ + ((u8)(duration) << 16) | (u16)(tempoScale)) + +/** + * Reset the tempo of a sequence to the original tempo on a given seqPlayer over a specified duration + * + * @param seqPlayerIndex the index of the seqPlayer to modify + * @param duration duration to transition to the tempo + */ +#define SEQCMD_RESET_TEMPO(seqPlayerIndex, duration) \ + Audio_QueueSeqCmd((SEQCMD_OP_TEMPO_CMD << 28) | (SEQCMD_SUB_OP_TEMPO_RESET << 12) | ((u8)(seqPlayerIndex) << 24) | \ + ((u8)(duration) << 16)) + +/** + * ==== Audio Sequence Setup Commands ==== + * + * The setup commands are designed to wait to be executed. + * Up to 8 commands can be queued per `seqPlayerIndex`. + * These commands will only execute once that `seqPlayerIndex` is finished playing and is no longer enabled. + * They will often target a different player (`targetSeqPlayerIndex`) but not always. + */ + +/** + * Setup a request to restore a volume on target seqPlayer once a setup seqPlayer is finished playing and disabled + * + * @param setupSeqPlayerIndex the index of the seqPlayer to wait for to be disabled + * @param targetSeqPlayerIndex the index of the seqPlayer to modify + * @param duration duration to transition to the volume + */ +#define SEQCMD_SETUP_RESTORE_PLAYER_VOLUME(setupSeqPlayerIndex, targetSeqPlayerIndex, duration) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME << 20) | \ + ((u8)(setupSeqPlayerIndex) << 24) | ((u8)(targetSeqPlayerIndex) << 16) | (u8)(duration)) + +/** + * Setup a request to unqueue a seqPlayer once that same setup seqPlayer is finished playing and disabled + * + * @param setupSeqPlayerIndex the index of the seqPlayer to unqueue once the same seqPlayer is disabled + * + * @bug this command was misimplemented and fails to unqueue. The command relies on `gActiveSeqs.seqId` for + * unqueueing, but seqId is reset before being used to unqueue. A simple fix is to unqueue based on + * `gActiveSeqs.prevSeqId` instead. + */ +#define SEQCMD_SETUP_UNQUEUE_SEQUENCE(setupSeqPlayerIndex) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_SEQ_UNQUEUE << 20) | \ + ((u8)(setupSeqPlayerIndex) << 24)) + +/** + * Setup a request to restart and play an active sequence currently playing on a target seqPlayer + * once a setup seqPlayer is finished playing and disabled + * + * @param setupSeqPlayerIndex the index of the seqPlayer to wait for to be disabled + * @param targetSeqPlayerIndex the index of the seqPlayer to restart its active sequence + */ +#define SEQCMD_SETUP_RESTART_SEQUENCE(setupSeqPlayerIndex, targetSeqPlayerIndex) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_RESTART_SEQ << 20) | \ + ((u8)(setupSeqPlayerIndex) << 24) | ((u8)(targetSeqPlayerIndex) << 16)) + +/** + * Setup a request to scale the tempo of a sequence by a multiplicative value on a target seqPlayer + * once a setup seqPlayer is finished playing and disabled + * + * @param setupSeqPlayerIndex the index of the seqPlayer to wait for to be disabled + * @param targetSeqPlayerIndex the index of the seqPlayer to modify + * @param duration duration to transition to the tempo + * @param tempoScale the scaling factor of the tempo, relative to 100 + * + * @note a tempoScale of 200 will go double-time, 50 will go half-time. + * the absolute tempo is constrained to a maximum of 300 + */ +#define SEQCMD_SETUP_SCALE_TEMPO(setupSeqPlayerIndex, targetSeqPlayerIndex, duration, tempoScale) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_TEMPO_SCALE << 20) | \ + ((u8)(setupSeqPlayerIndex) << 24) | ((u8)(targetSeqPlayerIndex) << 16) | ((u8)(duration) << 8) | \ + (u8)(tempoScale)) + +/** + * Setup a request to reset the tempo of a sequence to the original tempo on a target seqPlayer + * once a setup seqPlayer is finished playing and disabled + * + * @param setupSeqPlayerIndex the index of the seqPlayer to wait for to be disabled + * @param targetSeqPlayerIndex the index of the seqPlayer to modify + * @param duration duration to transition to the tempo + */ +#define SEQCMD_SETUP_RESET_TEMPO(setupSeqPlayerIndex, targetSeqPlayerIndex, duration) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_TEMPO_RESET << 20) | \ + ((u8)(setupSeqPlayerIndex) << 24) | ((u8)(targetSeqPlayerIndex) << 16) | (u8)(duration)) + +/** + * Setup a request to play a sequence on a target seqPlayer once a setup seqPlayer is finished playing and disabled. + * This command is optionally paired with `SEQCMD_SETUP_SET_FADE_IN_TIMER` to set the fade in duration + * + * @param setupSeqPlayerIndex the index of the seqPlayer to wait for to be disabled + * @param targetSeqPlayerIndex the index of the seqPlayer to play the sequence + * @param seqId the id of the sequence to play, see `SeqId` + */ +#define SEQCMD_SETUP_PLAY_SEQUENCE(setupSeqPlayerIndex, targetSeqPlayerIndex, seqId) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_PLAY_SEQ << 20) | \ + ((u8)(setupSeqPlayerIndex) << 24) | ((u8)(targetSeqPlayerIndex) << 16) | (u16)(seqId)) + +/** + * This command is an optional command before `SEQCMD_SETUP_PLAY_SEQUENCE` to set the fade in duration + * (see cmd above) + * + * @param targetSeqPlayerIndex the index of the seqPlayer to play the sequence + * @param fadeInDuration duration the sequence will fade in over + */ +#define SEQCMD_SETUP_SET_FADE_IN_TIMER(targetSeqPlayerIndex, fadeInDuration) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_SET_FADE_TIMER << 20) | \ + ((u8)(targetSeqPlayerIndex) << 24) | ((u8)(fadeInDuration) << 8)) + +/** + * Setup a request to restore a volume on target seqPlayer once a setup seqPlayer is finished playing and disabled. + * Specifically, it will only restore volume if the number of queued requests on the setup seqPlayer matches + * the number of sequences queued + * + * @param setupSeqPlayerIndex the index of the seqPlayer to wait for to be disabled + * @param targetSeqPlayerIndex the index of the seqPlayer to modify + * @param duration duration to transition to the volume + * @param numSeqRequests the number of sequence requests queued that must match the actual number of sequence requests + */ +#define SEQCMD_SETUP_RESTORE_PLAYER_VOLUME_IF_QUEUED(setupSeqPlayerIndex, targetSeqPlayerIndex, duration, \ + numSeqRequests) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME_IF_QUEUED << 20) | \ + ((u8)(setupSeqPlayerIndex) << 24) | ((u8)(targetSeqPlayerIndex) << 16) | ((u8)(duration) << 8) | \ + (u8)(numSeqRequests)) + +/** + * Setup a request to restore a volume on target seqPlayer once a setup seqPlayer is finished playing and disabled. + * Allows `scaleIndex` to be specified. + * + * @param setupSeqPlayerIndex the index of the seqPlayer to wait for to be disabled + * @param targetSeqPlayerIndex the index of the seqPlayer to modify + * @param scaleIndex the scale index of a seqPlayer + * @param duration duration to transition to the volume + */ +#define SEQCMD_SETUP_RESTORE_PLAYER_VOLUME_WITH_SCALE_INDEX(setupSeqPlayerIndex, targetSeqPlayerIndex, scaleIndex, duration) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME_WITH_SCALE_INDEX << 20) | \ + ((u8)(setupSeqPlayerIndex) << 24) | ((u8)(targetSeqPlayerIndex) << 16) | \ + ((u8)(scaleIndex) << 8) | (u8)(duration)) + +/** + * Setup a request to disable (or reenable) specific channels on a target seqPlayer + * once a setup seqPlayer is finished playing and disabled. + * + * @param setupSeqPlayerIndex the index of the seqPlayer to wait for to be disabled + * @param targetSeqPlayerIndex the index of the seqPlayer to modify + * @param channelMask a 16 bit mask where each bit maps to a channel. Bitflag on to disable + */ +#define SEQCMD_SETUP_SET_CHANNEL_DISABLE_MASK(setupSeqPlayerIndex, targetSeqPlayerIndex, channelMask) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_SET_CHANNEL_DISABLE_MASK << 20) | \ + ((u8)(setupSeqPlayerIndex) << 24) | ((u8)(targetSeqPlayerIndex) << 16) | (u16)(channelMask)) + +/** + * Queue a request to scale the frequency of an entire sequence on a target seqPlayer + * once a setup seqPlayer is finished playing and disabled. + * + * @param setupSeqPlayerIndex the index of the seqPlayer to wait for to be disabled + * @param targetSeqPlayerIndex the index of the seqPlayer to modify + * @param duration duration to transition to the frequency + * @param freqScale the scaling factor to shift the pitch. Ranged from 0-0xFF, with 100 mapping to 1.0f + * + * @note The base value for frequency, 100, is 10 times smaller than other frequency commands. + * 200 will double the frequency (raise an octave), 50 will halve the frequency (lower an octave). + */ +#define SEQCMD_SETUP_SET_PLAYER_FREQ(setupSeqPlayerIndex, targetSeqPlayerIndex, duration, freqScale) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_SET_PLAYER_FREQ << 20) | \ + ((u8)(setupSeqPlayerIndex) << 24) | ((u8)(targetSeqPlayerIndex) << 16) | ((u8)(duration) << 8) | \ + (u8)(freqScale)) + +/** + * Queue a request to discard audio data by popping an entry from the persistent caches on the audio heap, + * once a setup seqPlayer is finished playing and disabled. + * + * @param setupSeqPlayerIndex the index of the seqPlayer to wait for to be disabled + * @param tableTypeFlag All tables with the flag `(tableTypeFlag & (1 << tableType))` will be discarded. Specifically: + * `(tableTypeFlag & 1)` will discard the `SEQUENCE_TABLE` + * `(tableTypeFlag & 2)` will discard the `FONT_TABLE` + * `(tableTypeFlag & 4)` will discard the `SAMPLE_TABLE` + */ +#define SEQCMD_SETUP_POP_PERSISTENT_CACHE(setupSeqPlayerIndex, tableTypeFlag) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_POP_PERSISTENT_CACHE << 20) | \ + ((u8)(setupSeqPlayerIndex) << 24) | ((u8)tableTypeFlag)) + +/** + * Discard all setup command requests on a seqPlayerIndex by resetting the setup command queue + * + * @param setupSeqPlayerIndex the index of the seqPlayer to disable all setup commands + */ +#define SEQCMD_RESET_SETUP_CMDS(setupSeqPlayerIndex) \ + Audio_QueueSeqCmd((SEQCMD_OP_SETUP_CMD << 28) | (SEQCMD_SUB_OP_SETUP_RESET_SETUP_CMDS << 20) | \ + ((u8)(setupSeqPlayerIndex) << 24)) + +/** + * ==== Audio Sequence Global Commands ==== + * + * The global commands will apply to the entire audio system and all 4 sequence players + */ + +/** + * Change the sound mode of audio + * + * @param soundMode see the `SoundMode` enum + */ +#define SEQCMD_SET_SOUND_MODE(soundMode) \ + Audio_QueueSeqCmd((SEQCMD_OP_GLOBAL_CMD << 28) | (SEQCMD_SUB_OP_GLOBAL_SET_SOUND_MODE << 8) | (u8)(soundMode)) + +/** + * Disable (or reenable) new sequences from starting + * + * @param isDisabled true to disable, false to enable + * + * @note this does not disable the sfx player + */ +#define SEQCMD_DISABLE_PLAY_SEQUENCES(isDisabled) \ + Audio_QueueSeqCmd((SEQCMD_OP_GLOBAL_CMD << 28) | (SEQCMD_SUB_OP_GLOBAL_DISABLE_NEW_SEQUENCES << 8) | \ + (u16)(isDisabled)) + +/** + * Restart the audio heap with the specified settings + * + * @param sfxChannelLayout index for different mappings between the 7 banks and the 16 channels + * @param specId index for the audio specifications to set high-level audio parameters + * + * @note: For sfxChannelLayout, There are 4 possible layouts indexed by 0-3. + * However, only index 0 is properly implemented. Other indices lead to bugs and softlocks. + */ +#define SEQCMD_RESET_AUDIO_HEAP(sfxChannelLayout, specId) \ + Audio_QueueSeqCmd((SEQCMD_OP_RESET_AUDIO_HEAP << 28) | ((u8)(sfxChannelLayout) << 8) | (u8)(specId)) + +#endif diff --git a/include/sequence.h b/include/sequence.h index 6093b464ad..5f040d1ce9 100644 --- a/include/sequence.h +++ b/include/sequence.h @@ -1,121 +1,121 @@ #ifndef SEQUENCE_H #define SEQUENCE_H -#define NA_BGM_STOP 0x100000FF - -#define NA_BGM_GENERAL_SFX 0x0 // General Sound Effects -#define NA_BGM_NATURE_AMBIENCE 0x1 // Environmental nature background sounds -#define NA_BGM_FIELD_LOGIC 0x2 // Hyrule Field -#define NA_BGM_FIELD_INIT 0x3 // Hyrule Field Initial Segment From Loading Area -#define NA_BGM_FIELD_DEFAULT_1 0x4 // Hyrule Field Moving Segment 1 -#define NA_BGM_FIELD_DEFAULT_2 0x5 // Hyrule Field Moving Segment 2 -#define NA_BGM_FIELD_DEFAULT_3 0x6 // Hyrule Field Moving Segment 3 -#define NA_BGM_FIELD_DEFAULT_4 0x7 // Hyrule Field Moving Segment 4 -#define NA_BGM_FIELD_DEFAULT_5 0x8 // Hyrule Field Moving Segment 5 -#define NA_BGM_FIELD_DEFAULT_6 0x9 // Hyrule Field Moving Segment 6 -#define NA_BGM_FIELD_DEFAULT_7 0x0A // Hyrule Field Moving Segment 7 -#define NA_BGM_FIELD_DEFAULT_8 0x0B // Hyrule Field Moving Segment 8 -#define NA_BGM_FIELD_DEFAULT_9 0x0C // Hyrule Field Moving Segment 9 -#define NA_BGM_FIELD_DEFAULT_A 0x0D // Hyrule Field Moving Segment 10 -#define NA_BGM_FIELD_DEFAULT_B 0x0E // Hyrule Field Moving Segment 11 -#define NA_BGM_FIELD_ENEMY_INIT 0x0F // Hyrule Field Enemy Approaches -#define NA_BGM_FIELD_ENEMY_1 0x10 // Hyrule Field Enemy Near Segment 1 -#define NA_BGM_FIELD_ENEMY_2 0x11 // Hyrule Field Enemy Near Segment 2 -#define NA_BGM_FIELD_ENEMY_3 0x12 // Hyrule Field Enemy Near Segment 3 -#define NA_BGM_FIELD_ENEMY_4 0x13 // Hyrule Field Enemy Near Segment 4 -#define NA_BGM_FIELD_STILL_1 0x14 // Hyrule Field Standing Still Segment 1 -#define NA_BGM_FIELD_STILL_2 0x15 // Hyrule Field Standing Still Segment 2 -#define NA_BGM_FIELD_STILL_3 0x16 // Hyrule Field Standing Still Segment 3 -#define NA_BGM_FIELD_STILL_4 0x17 // Hyrule Field Standing Still Segment 4 -#define NA_BGM_DUNGEON 0x18 // Dodongo's Cavern -#define NA_BGM_KAKARIKO_ADULT 0x19 // Kakariko Village (Adult) -#define NA_BGM_ENEMY 0x1A // Battle -#define NA_BGM_BOSS 0x1B // Boss Battle "NA_BGM_BOSS00" -#define NA_BGM_INSIDE_DEKU_TREE 0x1C // Inside the Deku Tree "NA_BGM_FAIRY_DUNGEON" -#define NA_BGM_MARKET 0x1D // Market -#define NA_BGM_TITLE 0x1E // Title Theme -#define NA_BGM_LINK_HOUSE 0x1F // House -#define NA_BGM_GAME_OVER 0x20 // Game Over -#define NA_BGM_BOSS_CLEAR 0x21 // Boss Clear -#define NA_BGM_ITEM_GET 0x22 // Obtain Item -#define NA_BGM_OPENING_GANON 0x23 // Enter Ganondorf -#define NA_BGM_HEART_GET 0x24 // Obtain Heart Container -#define NA_BGM_OCA_LIGHT 0x25 // Prelude of Light -#define NA_BGM_JABU_JABU 0x26 // Inside Jabu-Jabu's Belly "NA_BGM_BUYO_DUNGEON" -#define NA_BGM_KAKARIKO_KID 0x27 // Kakariko Village (Child) -#define NA_BGM_GREAT_FAIRY 0x28 // Great Fairy's Fountain "NA_BGM_GODESS" -#define NA_BGM_ZELDA_THEME 0x29 // Zelda's Theme "NA_BGM_HIME" -#define NA_BGM_FIRE_TEMPLE 0x2A // Fire Temple "NA_BGM_FIRE_DUNGEON" -#define NA_BGM_OPEN_TRE_BOX 0x2B // Open Treasure Chest -#define NA_BGM_FOREST_TEMPLE 0x2C // Forest Temple "NA_BGM_FORST_DUNGEON" -#define NA_BGM_COURTYARD 0x2D // Hyrule Castle Courtyard "NA_BGM_HIRAL_GARDEN" -#define NA_BGM_GANON_TOWER 0x2E // Ganondorf's Theme -#define NA_BGM_LONLON 0x2F // Lon Lon Ranch "NA_BGM_RONRON" -#define NA_BGM_GORON_CITY 0x30 // Goron City "NA_BGM_GORON" -#define NA_BGM_FIELD_MORNING 0x31 // Hyrule Field Morning Theme -#define NA_BGM_SPIRITUAL_STONE 0x32 // Spiritual Stone Get "NA_BGM_SPIRIT_STONE" -#define NA_BGM_OCA_BOLERO 0x33 // Bolero of Fire "NA_BGM_OCA_FLAME" -#define NA_BGM_OCA_MINUET 0x34 // Minuet of Forest "NA_BGM_OCA_WIND" -#define NA_BGM_OCA_SERENADE 0x35 // Serenade of Water "NA_BGM_OCA_WATER" -#define NA_BGM_OCA_REQUIEM 0x36 // Requiem of Spirit "NA_BGM_OCA_SOUL" -#define NA_BGM_OCA_NOCTURNE 0x37 // Nocturne of Shadow "NA_BGM_OCA_DARKNESS" -#define NA_BGM_MINI_BOSS 0x38 // Mini-Boss Battle "NA_BGM_MIDDLE_BOSS" -#define NA_BGM_SMALL_ITEM_GET 0x39 // Obtain Small Item "NA_BGM_S_ITEM_GET" -#define NA_BGM_TEMPLE_OF_TIME 0x3A // Temple of Time "NA_BGM_SHRINE_OF_TIME" -#define NA_BGM_EVENT_CLEAR 0x3B // Escape from Lon Lon Ranch -#define NA_BGM_KOKIRI 0x3C // Kokiri Forest -#define NA_BGM_OCA_FAIRY_GET 0x3D // Obtain Fairy Ocarina "NA_BGM_OCA_YOUSEI" -#define NA_BGM_SARIA_THEME 0x3E // Lost Woods "NA_BGM_MAYOIMORI" -#define NA_BGM_SPIRIT_TEMPLE 0x3F // Spirit Temple "NA_BGM_SOUL_DUNGEON" -#define NA_BGM_HORSE 0x40 // Horse Race -#define NA_BGM_HORSE_GOAL 0x41 // Horse Race Goal -#define NA_BGM_INGO 0x42 // Ingo's Theme -#define NA_BGM_MEDALLION_GET 0x43 // Obtain Medallion "NA_BGM_MEDAL_GET" -#define NA_BGM_OCA_SARIA 0x44 // Ocarina Saria's Song -#define NA_BGM_OCA_EPONA 0x45 // Ocarina Epona's Song -#define NA_BGM_OCA_ZELDA 0x46 // Ocarina Zelda's Lullaby -#define NA_BGM_OCA_SUNS 0x47 // Ocarina Sun's Song "NA_BGM_OCA_SUNMOON" -#define NA_BGM_OCA_TIME 0x48 // Ocarina Song of Time -#define NA_BGM_OCA_STORM 0x49 // Ocarina Song of Storms -#define NA_BGM_NAVI_OPENING 0x4A // Fairy Flying "NA_BGM_NAVI" -#define NA_BGM_DEKU_TREE_CS 0x4B // Deku Tree "NA_BGM_DEKUNOKI" -#define NA_BGM_WINDMILL 0x4C // Windmill Hut "NA_BGM_FUSHA" -#define NA_BGM_HYRULE_CS 0x4D // Legend of Hyrule "NA_BGM_HIRAL_DEMO" -#define NA_BGM_MINI_GAME 0x4E // Shooting Gallery -#define NA_BGM_SHEIK 0x4F // Sheik's Theme "NA_BGM_SEAK" -#define NA_BGM_ZORA_DOMAIN 0x50 // Zora's Domain "NA_BGM_ZORA" -#define NA_BGM_APPEAR 0x51 // Enter Zelda -#define NA_BGM_ADULT_LINK 0x52 // Goodbye to Zelda -#define NA_BGM_MASTER_SWORD 0x53 // Master Sword -#define NA_BGM_INTRO_GANON 0x54 -#define NA_BGM_SHOP 0x55 // Shop -#define NA_BGM_CHAMBER_OF_SAGES 0x56 // Chamber of the Sages "NA_BGM_KENJA" -#define NA_BGM_FILE_SELECT 0x57 // File Select -#define NA_BGM_ICE_CAVERN 0x58 // Ice Cavern "NA_BGM_ICE_DUNGEON" -#define NA_BGM_DOOR_OF_TIME 0x59 // Open Door of Temple of Time "NA_BGM_GATE_OPEN" -#define NA_BGM_OWL 0x5A // Kaepora Gaebora's Theme -#define NA_BGM_SHADOW_TEMPLE 0x5B // Shadow Temple "NA_BGM_DARKNESS_DUNGEON" -#define NA_BGM_WATER_TEMPLE 0x5C // Water Temple "NA_BGM_AQUA_DUNGEON" -#define NA_BGM_BRIDGE_TO_GANONS 0x5D // Ganon's Castle Bridge "NA_BGM_BRIDGE" -#define NA_BGM_OCARINA_OF_TIME 0x5E // Ocarina of Time "NA_BGM_SARIA" -#define NA_BGM_GERUDO_VALLEY 0x5F // Gerudo Valley "NA_BGM_GERUDO" -#define NA_BGM_POTION_SHOP 0x60 // Potion Shop "NA_BGM_DRUGSTORE" -#define NA_BGM_KOTAKE_KOUME 0x61 // Kotake & Koume's Theme -#define NA_BGM_ESCAPE 0x62 // Escape from Ganon's Castle -#define NA_BGM_UNDERGROUND 0x63 // Ganon's Castle Under Ground -#define NA_BGM_GANONDORF_BOSS 0x64 // Ganondorf Battle -#define NA_BGM_GANON_BOSS 0x65 // Ganon Battle -#define NA_BGM_END_DEMO 0x66 // Seal of Six Sages -#define NA_BGM_STAFF_1 0x67 // End Credits I -#define NA_BGM_STAFF_2 0x68 // End Credits II -#define NA_BGM_STAFF_3 0x69 // End Credits III -#define NA_BGM_STAFF_4 0x6A // End Credits IV -#define NA_BGM_FIRE_BOSS 0x6B // King Dodongo & Volvagia Boss Battle "NA_BGM_BOSS01" -#define NA_BGM_TIMED_MINI_GAME 0x6C // Mini-Game -#define NA_BGM_CUTSCENE_EFFECTS 0x6D // A small collection of various cutscene sounds -#define NA_BGM_NO_MUSIC 0x7F // No bgm music is played -#define NA_BGM_NATURE_SFX_RAIN 0x80 // Related to rain -#define NA_BGM_DISABLED 0xFFFF +typedef enum { + /* 0x00 */ NA_BGM_GENERAL_SFX, // General Sound Effects + /* 0x01 */ NA_BGM_NATURE_AMBIENCE, // Environmental nature background sounds + /* 0x02 */ NA_BGM_FIELD_LOGIC, // Hyrule Field + /* 0x03 */ NA_BGM_FIELD_INIT, // Hyrule Field Initial Segment From Loading Area + /* 0x04 */ NA_BGM_FIELD_DEFAULT_1, // Hyrule Field Moving Segment 1 + /* 0x05 */ NA_BGM_FIELD_DEFAULT_2, // Hyrule Field Moving Segment 2 + /* 0x06 */ NA_BGM_FIELD_DEFAULT_3, // Hyrule Field Moving Segment 3 + /* 0x07 */ NA_BGM_FIELD_DEFAULT_4, // Hyrule Field Moving Segment 4 + /* 0x08 */ NA_BGM_FIELD_DEFAULT_5, // Hyrule Field Moving Segment 5 + /* 0x09 */ NA_BGM_FIELD_DEFAULT_6, // Hyrule Field Moving Segment 6 + /* 0x0A */ NA_BGM_FIELD_DEFAULT_7, // Hyrule Field Moving Segment 7 + /* 0x0B */ NA_BGM_FIELD_DEFAULT_8, // Hyrule Field Moving Segment 8 + /* 0x0C */ NA_BGM_FIELD_DEFAULT_9, // Hyrule Field Moving Segment 9 + /* 0x0D */ NA_BGM_FIELD_DEFAULT_A, // Hyrule Field Moving Segment 10 + /* 0x0E */ NA_BGM_FIELD_DEFAULT_B, // Hyrule Field Moving Segment 11 + /* 0x0F */ NA_BGM_FIELD_ENEMY_INIT, // Hyrule Field Enemy Approaches + /* 0x10 */ NA_BGM_FIELD_ENEMY_1, // Hyrule Field Enemy Near Segment 1 + /* 0x11 */ NA_BGM_FIELD_ENEMY_2, // Hyrule Field Enemy Near Segment 2 + /* 0x12 */ NA_BGM_FIELD_ENEMY_3, // Hyrule Field Enemy Near Segment 3 + /* 0x13 */ NA_BGM_FIELD_ENEMY_4, // Hyrule Field Enemy Near Segment 4 + /* 0x14 */ NA_BGM_FIELD_STILL_1, // Hyrule Field Standing Still Segment 1 + /* 0x15 */ NA_BGM_FIELD_STILL_2, // Hyrule Field Standing Still Segment 2 + /* 0x16 */ NA_BGM_FIELD_STILL_3, // Hyrule Field Standing Still Segment 3 + /* 0x17 */ NA_BGM_FIELD_STILL_4, // Hyrule Field Standing Still Segment 4 + /* 0x18 */ NA_BGM_DUNGEON, // Dodongo's Cavern + /* 0x19 */ NA_BGM_KAKARIKO_ADULT, // Kakariko Village (Adult) + /* 0x1A */ NA_BGM_ENEMY, // Battle + /* 0x1B */ NA_BGM_BOSS, // Boss Battle "NA_BGM_BOSS00" + /* 0x1C */ NA_BGM_INSIDE_DEKU_TREE, // Inside the Deku Tree "NA_BGM_FAIRY_DUNGEON" + /* 0x1D */ NA_BGM_MARKET, // Market + /* 0x1E */ NA_BGM_TITLE, // Title Theme + /* 0x1F */ NA_BGM_LINK_HOUSE, // House + /* 0x20 */ NA_BGM_GAME_OVER, // Game Over + /* 0x21 */ NA_BGM_BOSS_CLEAR, // Boss Clear + /* 0x22 */ NA_BGM_ITEM_GET, // Obtain Item + /* 0x23 */ NA_BGM_OPENING_GANON, // Enter Ganondorf + /* 0x24 */ NA_BGM_HEART_GET, // Obtain Heart Container + /* 0x25 */ NA_BGM_OCA_LIGHT, // Prelude of Light + /* 0x26 */ NA_BGM_JABU_JABU, // Inside Jabu-Jabu's Belly "NA_BGM_BUYO_DUNGEON" + /* 0x27 */ NA_BGM_KAKARIKO_KID, // Kakariko Village (Child) + /* 0x28 */ NA_BGM_GREAT_FAIRY, // Great Fairy's Fountain "NA_BGM_GODESS" + /* 0x29 */ NA_BGM_ZELDA_THEME, // Zelda's Theme "NA_BGM_HIME" + /* 0x2A */ NA_BGM_FIRE_TEMPLE, // Fire Temple "NA_BGM_FIRE_DUNGEON" + /* 0x2B */ NA_BGM_OPEN_TRE_BOX, // Open Treasure Chest + /* 0x2C */ NA_BGM_FOREST_TEMPLE, // Forest Temple "NA_BGM_FORST_DUNGEON" + /* 0x2D */ NA_BGM_COURTYARD, // Hyrule Castle Courtyard "NA_BGM_HIRAL_GARDEN" + /* 0x2E */ NA_BGM_GANON_TOWER, // Ganondorf's Theme + /* 0x2F */ NA_BGM_LONLON, // Lon Lon Ranch "NA_BGM_RONRON" + /* 0x30 */ NA_BGM_GORON_CITY, // Goron City "NA_BGM_GORON" + /* 0x31 */ NA_BGM_FIELD_MORNING, // Hyrule Field Morning Theme + /* 0x32 */ NA_BGM_SPIRITUAL_STONE, // Spiritual Stone Get "NA_BGM_SPIRIT_STONE" + /* 0x33 */ NA_BGM_OCA_BOLERO, // Bolero of Fire "NA_BGM_OCA_FLAME" + /* 0x34 */ NA_BGM_OCA_MINUET, // Minuet of Forest "NA_BGM_OCA_WIND" + /* 0x35 */ NA_BGM_OCA_SERENADE, // Serenade of Water "NA_BGM_OCA_WATER" + /* 0x36 */ NA_BGM_OCA_REQUIEM, // Requiem of Spirit "NA_BGM_OCA_SOUL" + /* 0x37 */ NA_BGM_OCA_NOCTURNE, // Nocturne of Shadow "NA_BGM_OCA_DARKNESS" + /* 0x38 */ NA_BGM_MINI_BOSS, // Mini-Boss Battle "NA_BGM_MIDDLE_BOSS" + /* 0x39 */ NA_BGM_SMALL_ITEM_GET, // Obtain Small Item "NA_BGM_S_ITEM_GET" + /* 0x3A */ NA_BGM_TEMPLE_OF_TIME, // Temple of Time "NA_BGM_SHRINE_OF_TIME" + /* 0x3B */ NA_BGM_EVENT_CLEAR, // Escape from Lon Lon Ranch + /* 0x3C */ NA_BGM_KOKIRI, // Kokiri Forest + /* 0x3D */ NA_BGM_OCA_FAIRY_GET, // Obtain Fairy Ocarina "NA_BGM_OCA_YOUSEI" + /* 0x3E */ NA_BGM_SARIA_THEME, // Lost Woods "NA_BGM_MAYOIMORI" + /* 0x3F */ NA_BGM_SPIRIT_TEMPLE, // Spirit Temple "NA_BGM_SOUL_DUNGEON" + /* 0x40 */ NA_BGM_HORSE, // Horse Race + /* 0x41 */ NA_BGM_HORSE_GOAL, // Horse Race Goal + /* 0x42 */ NA_BGM_INGO, // Ingo's Theme + /* 0x43 */ NA_BGM_MEDALLION_GET, // Obtain Medallion "NA_BGM_MEDAL_GET" + /* 0x44 */ NA_BGM_OCA_SARIA, // Ocarina Saria's Song + /* 0x45 */ NA_BGM_OCA_EPONA, // Ocarina Epona's Song + /* 0x46 */ NA_BGM_OCA_ZELDA, // Ocarina Zelda's Lullaby + /* 0x47 */ NA_BGM_OCA_SUNS, // Ocarina Sun's Song "NA_BGM_OCA_SUNMOON" + /* 0x48 */ NA_BGM_OCA_TIME, // Ocarina Song of Time + /* 0x49 */ NA_BGM_OCA_STORM, // Ocarina Song of Storms + /* 0x4A */ NA_BGM_NAVI_OPENING, // Fairy Flying "NA_BGM_NAVI" + /* 0x4B */ NA_BGM_DEKU_TREE_CS, // Deku Tree "NA_BGM_DEKUNOKI" + /* 0x4C */ NA_BGM_WINDMILL, // Windmill Hut "NA_BGM_FUSHA" + /* 0x4D */ NA_BGM_HYRULE_CS, // Legend of Hyrule "NA_BGM_HIRAL_DEMO" + /* 0x4E */ NA_BGM_MINI_GAME, // Shooting Gallery + /* 0x4F */ NA_BGM_SHEIK, // Sheik's Theme "NA_BGM_SEAK" + /* 0x50 */ NA_BGM_ZORA_DOMAIN, // Zora's Domain "NA_BGM_ZORA" + /* 0x51 */ NA_BGM_APPEAR, // Enter Zelda + /* 0x52 */ NA_BGM_ADULT_LINK, // Goodbye to Zelda + /* 0x53 */ NA_BGM_MASTER_SWORD, // Master Sword + /* 0x54 */ NA_BGM_INTRO_GANON, + /* 0x55 */ NA_BGM_SHOP, // Shop + /* 0x56 */ NA_BGM_CHAMBER_OF_SAGES, // Chamber of the Sages "NA_BGM_KENJA" + /* 0x57 */ NA_BGM_FILE_SELECT, // File Select + /* 0x58 */ NA_BGM_ICE_CAVERN, // Ice Cavern "NA_BGM_ICE_DUNGEON" + /* 0x59 */ NA_BGM_DOOR_OF_TIME, // Open Door of Temple of Time "NA_BGM_GATE_OPEN" + /* 0x5A */ NA_BGM_OWL, // Kaepora Gaebora's Theme + /* 0x5B */ NA_BGM_SHADOW_TEMPLE, // Shadow Temple "NA_BGM_DARKNESS_DUNGEON" + /* 0x5C */ NA_BGM_WATER_TEMPLE, // Water Temple "NA_BGM_AQUA_DUNGEON" + /* 0x5D */ NA_BGM_BRIDGE_TO_GANONS, // Ganon's Castle Bridge "NA_BGM_BRIDGE" + /* 0x5E */ NA_BGM_OCARINA_OF_TIME, // Ocarina of Time "NA_BGM_SARIA" + /* 0x5F */ NA_BGM_GERUDO_VALLEY, // Gerudo Valley "NA_BGM_GERUDO" + /* 0x60 */ NA_BGM_POTION_SHOP, // Potion Shop "NA_BGM_DRUGSTORE" + /* 0x61 */ NA_BGM_KOTAKE_KOUME, // Kotake & Koume's Theme + /* 0x62 */ NA_BGM_ESCAPE, // Escape from Ganon's Castle + /* 0x63 */ NA_BGM_UNDERGROUND, // Ganon's Castle Under Ground + /* 0x64 */ NA_BGM_GANONDORF_BOSS, // Ganondorf Battle + /* 0x65 */ NA_BGM_GANON_BOSS, // Ganon Battle + /* 0x66 */ NA_BGM_END_DEMO, // Seal of Six Sages + /* 0x67 */ NA_BGM_STAFF_1, // End Credits I + /* 0x68 */ NA_BGM_STAFF_2, // End Credits II + /* 0x69 */ NA_BGM_STAFF_3, // End Credits III + /* 0x6A */ NA_BGM_STAFF_4, // End Credits IV + /* 0x6B */ NA_BGM_FIRE_BOSS, // King Dodongo & Volvagia Boss Battle "NA_BGM_BOSS01" + /* 0x6C */ NA_BGM_TIMED_MINI_GAME, // Mini-Game + /* 0x6D */ NA_BGM_CUTSCENE_EFFECTS, // A small collection of various cutscene sounds + /* 0x7F */ NA_BGM_NO_MUSIC = 0x7F, // No bgm music is played + /* 0x80 */ NA_BGM_NATURE_SFX_RAIN = 0x80, // Related to rain + /* 0xFFFF */ NA_BGM_DISABLED = 0xFFFF +} SeqId; typedef enum { /* 0 */ SEQ_PLAYER_BGM_MAIN, @@ -161,6 +161,53 @@ typedef enum { /* 0x7 */ CHANNEL_IO_PORT_7 } ChannelIOPort; +typedef enum { + /* 0 */ VOL_SCALE_INDEX_BGM_MAIN, + /* 1 */ VOL_SCALE_INDEX_FANFARE, + /* 2 */ VOL_SCALE_INDEX_SFX, + /* 3 */ VOL_SCALE_INDEX_BGM_SUB, + /* 4 */ VOL_SCALE_INDEX_MAX +} VolumeScaleIndex; // May be worth using SequencePlayerId instead + +typedef struct { + /* 0x00 */ f32 volCur; + /* 0x04 */ f32 volTarget; + /* 0x08 */ f32 volStep; + /* 0x0C */ u16 volTimer; + /* 0x10 */ f32 freqScaleCur; + /* 0x14 */ f32 freqScaleTarget; + /* 0x18 */ f32 freqScaleStep; + /* 0x1C */ u16 freqScaleTimer; +} ActiveSequenceChannelData; // size = 0x20 + +typedef struct { + /* 0x000 */ f32 volCur; + /* 0x004 */ f32 volTarget; + /* 0x008 */ f32 volStep; + /* 0x00C */ u16 volTimer; + /* 0x00E */ u8 volScales[VOL_SCALE_INDEX_MAX]; + /* 0x012 */ u8 volFadeTimer; + /* 0x013 */ u8 fadeVolUpdate; + /* 0x014 */ u32 tempoCmd; + /* 0x018 */ u16 tempoOriginal; // stores the original tempo before modifying it (to reset back to) + /* 0x01C */ f32 tempoCur; + /* 0x020 */ f32 tempoTarget; + /* 0x024 */ f32 tempoStep; + /* 0x028 */ u16 tempoTimer; + /* 0x02C */ u32 setupCmd[8]; // a queue of cmds to execute once the player is disabled + /* 0x04C */ u8 setupCmdTimer; // only execute setup commands when the timer is at 0. + /* 0x04D */ u8 setupCmdNum; // number of setup commands requested once the player is disabled + /* 0x04E */ u8 setupFadeTimer; + /* 0x050 */ ActiveSequenceChannelData channelData[16]; + /* 0x250 */ u16 freqScaleChannelFlags; + /* 0x252 */ u16 volChannelFlags; + /* 0x254 */ u16 seqId; // active seqId currently playing. Resets when sequence stops + /* 0x256 */ u16 prevSeqId; // last seqId played on a player. Does not reset when sequence stops + /* 0x258 */ u16 channelPortMask; + /* 0x25C */ u32 startSeqCmd; // This name comes from MM + /* 0x260 */ u8 isWaitingForFonts; // This name comes from MM +} ActiveSequence; // size = 0x264 + typedef enum { /* 0x0 */ NATURE_CHANNEL_STREAM_0, /* 0x1 */ NATURE_CHANNEL_CRITTER_0, @@ -175,7 +222,7 @@ typedef enum { /* 0xD */ NATURE_CHANNEL_UNK, /* 0xE */ NATURE_CHANNEL_RAIN, /* 0xF */ NATURE_CHANNEL_LIGHTNING -} NatureChannelIdx; // playerIdx = 0 (Overlaps with main bgm) +} NatureChannelIndex; // seqPlayerIndex = 0 (Overlaps with main bgm) typedef enum { /* 0x00 */ NATURE_ID_GENERAL_NIGHT, diff --git a/include/variables.h b/include/variables.h index 55ef82ef39..f04847e12c 100644 --- a/include/variables.h +++ b/include/variables.h @@ -150,10 +150,10 @@ extern s8 gSfxDefaultReverb; extern u8 D_801333F0; extern u8 gAudioSfxSwapOff; extern u8 D_801333F8; -extern u8 gSeqCmdWrPos; -extern u8 gSeqCmdRdPos; -extern u8 D_80133408; -extern u8 D_8013340C; +extern u8 gSeqCmdWritePos; +extern u8 gSeqCmdReadPos; +extern u8 gStartSeqDisabled; +extern u8 gAudioDebugPrintSeqCmd; extern u8 gSoundModeList[]; extern u8 gAudioSpecId; extern u8 D_80133418; @@ -217,8 +217,8 @@ extern u8 gSfxBankMuted[]; extern u16 gAudioSfxSwapSource[10]; extern u16 gAudioSfxSwapTarget[10]; extern u8 gAudioSfxSwapMode[10]; -extern unk_D_8016E750 D_8016E750[4]; -extern AudioContext gAudioContext; +extern ActiveSequence gActiveSeqs[4]; +extern AudioContext gAudioCtx; extern void(*D_801755D0)(void); extern u32 __osMalloc_FreeBlockTest_Enable; diff --git a/include/z64.h b/include/z64.h index b793d5f876..340bccbd73 100644 --- a/include/z64.h +++ b/include/z64.h @@ -27,6 +27,7 @@ #include "z64transition.h" #include "z64interface.h" #include "alignment.h" +#include "seqcmd.h" #include "sequence.h" #include "sfx.h" #include "color.h" @@ -786,7 +787,7 @@ typedef struct { /* 0x022C */ s16 cursorY[5]; // "cur_ypt" /* 0x0236 */ s16 dungeonMapSlot; /* 0x0238 */ s16 cursorSpecialPos; // "key_angle" - /* 0x023A */ s16 pageSwitchTimer; + /* 0x023A */ s16 pageSwitchInputTimer; // Used to introduce a delay before switching page when arriving on the "scroll left/right" positions while holding stick left/right. /* 0x023C */ u16 namedItem; // "zoom_name" /* 0x023E */ u16 cursorItem[4]; // "select_name" /* 0x0246 */ u16 cursorSlot[4]; diff --git a/include/z64audio.h b/include/z64audio.h index a6d90d4c4a..fe63f75702 100644 --- a/include/z64audio.h +++ b/include/z64audio.h @@ -7,8 +7,9 @@ #define TATUMS_PER_BEAT 48 -#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((u32)(ptr) != (u32)&gAudioContext.sequenceChannelNone) +#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((u32)(ptr) != (u32)&gAudioCtx.sequenceChannelNone) #define SEQ_NUM_CHANNELS 16 +#define SEQ_IO_VAL_NONE -1 #define MAX_CHANNELS_PER_BANK 3 @@ -975,43 +976,4 @@ typedef struct { /* 0x08 */ u32 permanentPoolSize; } AudioHeapInitSizes; // size = 0xC -typedef struct { - /* 0x00 */ f32 unk_00; - /* 0x04 */ f32 unk_04; - /* 0x08 */ f32 unk_08; - /* 0x0C */ u16 unk_0C; - /* 0x10 */ f32 unk_10; - /* 0x14 */ f32 unk_14; - /* 0x18 */ f32 unk_18; - /* 0x1C */ u16 unk_1C; -} unk_50_s; // size = 0x20 - -typedef struct { - /* 0x000 */ f32 volCur; - /* 0x004 */ f32 volTarget; - /* 0x008 */ f32 unk_08; - /* 0x00C */ u16 unk_0C; - /* 0x00E */ u8 volScales[0x4]; - /* 0x012 */ u8 volFadeTimer; - /* 0x013 */ u8 fadeVolUpdate; - /* 0x014 */ u32 unk_14; - /* 0x018 */ u16 unk_18; - /* 0x01C */ f32 unk_1C; - /* 0x020 */ f32 unk_20; - /* 0x024 */ f32 unk_24; - /* 0x028 */ u16 unk_28; - /* 0x02C */ u32 unk_2C[8]; - /* 0x04C */ u8 unk_4C; - /* 0x04D */ u8 unk_4D; - /* 0x04E */ u8 unk_4E; - /* 0x050 */ unk_50_s unk_50[0x10]; - /* 0x250 */ u16 unk_250; - /* 0x252 */ u16 unk_252; - /* 0x254 */ u16 unk_254; - /* 0x256 */ u16 unk_256; - /* 0x258 */ u16 unk_258; - /* 0x25C */ u32 unk_25C; - /* 0x260 */ u8 unk_260; -} unk_D_8016E750; // size = 0x264 - #endif diff --git a/include/z64player.h b/include/z64player.h index cb178b200b..cbeb641f5d 100644 --- a/include/z64player.h +++ b/include/z64player.h @@ -62,75 +62,75 @@ typedef enum { } PlayerMask; typedef enum { - /* 0x00 */ PLAYER_AP_NONE, - /* 0x01 */ PLAYER_AP_LAST_USED, - /* 0x02 */ PLAYER_AP_FISHING_POLE, - /* 0x03 */ PLAYER_AP_SWORD_MASTER, - /* 0x04 */ PLAYER_AP_SWORD_KOKIRI, - /* 0x05 */ PLAYER_AP_SWORD_BGS, - /* 0x06 */ PLAYER_AP_STICK, - /* 0x07 */ PLAYER_AP_HAMMER, - /* 0x08 */ PLAYER_AP_BOW, - /* 0x09 */ PLAYER_AP_BOW_FIRE, - /* 0x0A */ PLAYER_AP_BOW_ICE, - /* 0x0B */ PLAYER_AP_BOW_LIGHT, - /* 0x0C */ PLAYER_AP_BOW_0C, - /* 0x0D */ PLAYER_AP_BOW_0D, - /* 0x0E */ PLAYER_AP_BOW_0E, - /* 0x0F */ PLAYER_AP_SLINGSHOT, - /* 0x10 */ PLAYER_AP_HOOKSHOT, - /* 0x11 */ PLAYER_AP_LONGSHOT, - /* 0x12 */ PLAYER_AP_BOMB, - /* 0x13 */ PLAYER_AP_BOMBCHU, - /* 0x14 */ PLAYER_AP_BOOMERANG, - /* 0x15 */ PLAYER_AP_MAGIC_SPELL_15, - /* 0x16 */ PLAYER_AP_MAGIC_SPELL_16, - /* 0x17 */ PLAYER_AP_MAGIC_SPELL_17, - /* 0x18 */ PLAYER_AP_FARORES_WIND, - /* 0x19 */ PLAYER_AP_NAYRUS_LOVE, - /* 0x1A */ PLAYER_AP_DINS_FIRE, - /* 0x1B */ PLAYER_AP_NUT, - /* 0x1C */ PLAYER_AP_OCARINA_FAIRY, - /* 0x1D */ PLAYER_AP_OCARINA_TIME, - /* 0x1E */ PLAYER_AP_BOTTLE, - /* 0x1F */ PLAYER_AP_BOTTLE_FISH, - /* 0x20 */ PLAYER_AP_BOTTLE_FIRE, - /* 0x21 */ PLAYER_AP_BOTTLE_BUG, - /* 0x22 */ PLAYER_AP_BOTTLE_POE, - /* 0x23 */ PLAYER_AP_BOTTLE_BIG_POE, - /* 0x24 */ PLAYER_AP_BOTTLE_LETTER, - /* 0x25 */ PLAYER_AP_BOTTLE_POTION_RED, - /* 0x26 */ PLAYER_AP_BOTTLE_POTION_BLUE, - /* 0x27 */ PLAYER_AP_BOTTLE_POTION_GREEN, - /* 0x28 */ PLAYER_AP_BOTTLE_MILK, - /* 0x29 */ PLAYER_AP_BOTTLE_MILK_HALF, - /* 0x2A */ PLAYER_AP_BOTTLE_FAIRY, - /* 0x2B */ PLAYER_AP_LETTER_ZELDA, - /* 0x2C */ PLAYER_AP_WEIRD_EGG, - /* 0x2D */ PLAYER_AP_CHICKEN, - /* 0x2E */ PLAYER_AP_BEAN, - /* 0x2F */ PLAYER_AP_POCKET_EGG, - /* 0x30 */ PLAYER_AP_POCKET_CUCCO, - /* 0x31 */ PLAYER_AP_COJIRO, - /* 0x32 */ PLAYER_AP_ODD_MUSHROOM, - /* 0x33 */ PLAYER_AP_ODD_POTION, - /* 0x34 */ PLAYER_AP_SAW, - /* 0x35 */ PLAYER_AP_SWORD_BROKEN, - /* 0x36 */ PLAYER_AP_PRESCRIPTION, - /* 0x37 */ PLAYER_AP_FROG, - /* 0x38 */ PLAYER_AP_EYEDROPS, - /* 0x39 */ PLAYER_AP_CLAIM_CHECK, - /* 0x3A */ PLAYER_AP_MASK_KEATON, - /* 0x3B */ PLAYER_AP_MASK_SKULL, - /* 0x3C */ PLAYER_AP_MASK_SPOOKY, - /* 0x3D */ PLAYER_AP_MASK_BUNNY, - /* 0x3E */ PLAYER_AP_MASK_GORON, - /* 0x3F */ PLAYER_AP_MASK_ZORA, - /* 0x40 */ PLAYER_AP_MASK_GERUDO, - /* 0x41 */ PLAYER_AP_MASK_TRUTH, - /* 0x42 */ PLAYER_AP_LENS, - /* 0x43 */ PLAYER_AP_MAX -} PlayerActionParam; + /* 0x00 */ PLAYER_IA_NONE, + /* 0x01 */ PLAYER_IA_LAST_USED, + /* 0x02 */ PLAYER_IA_FISHING_POLE, + /* 0x03 */ PLAYER_IA_SWORD_MASTER, + /* 0x04 */ PLAYER_IA_SWORD_KOKIRI, + /* 0x05 */ PLAYER_IA_SWORD_BGS, + /* 0x06 */ PLAYER_IA_STICK, + /* 0x07 */ PLAYER_IA_HAMMER, + /* 0x08 */ PLAYER_IA_BOW, + /* 0x09 */ PLAYER_IA_BOW_FIRE, + /* 0x0A */ PLAYER_IA_BOW_ICE, + /* 0x0B */ PLAYER_IA_BOW_LIGHT, + /* 0x0C */ PLAYER_IA_BOW_0C, + /* 0x0D */ PLAYER_IA_BOW_0D, + /* 0x0E */ PLAYER_IA_BOW_0E, + /* 0x0F */ PLAYER_IA_SLINGSHOT, + /* 0x10 */ PLAYER_IA_HOOKSHOT, + /* 0x11 */ PLAYER_IA_LONGSHOT, + /* 0x12 */ PLAYER_IA_BOMB, + /* 0x13 */ PLAYER_IA_BOMBCHU, + /* 0x14 */ PLAYER_IA_BOOMERANG, + /* 0x15 */ PLAYER_IA_MAGIC_SPELL_15, + /* 0x16 */ PLAYER_IA_MAGIC_SPELL_16, + /* 0x17 */ PLAYER_IA_MAGIC_SPELL_17, + /* 0x18 */ PLAYER_IA_FARORES_WIND, + /* 0x19 */ PLAYER_IA_NAYRUS_LOVE, + /* 0x1A */ PLAYER_IA_DINS_FIRE, + /* 0x1B */ PLAYER_IA_NUT, + /* 0x1C */ PLAYER_IA_OCARINA_FAIRY, + /* 0x1D */ PLAYER_IA_OCARINA_TIME, + /* 0x1E */ PLAYER_IA_BOTTLE, + /* 0x1F */ PLAYER_IA_BOTTLE_FISH, + /* 0x20 */ PLAYER_IA_BOTTLE_FIRE, + /* 0x21 */ PLAYER_IA_BOTTLE_BUG, + /* 0x22 */ PLAYER_IA_BOTTLE_POE, + /* 0x23 */ PLAYER_IA_BOTTLE_BIG_POE, + /* 0x24 */ PLAYER_IA_BOTTLE_LETTER, + /* 0x25 */ PLAYER_IA_BOTTLE_POTION_RED, + /* 0x26 */ PLAYER_IA_BOTTLE_POTION_BLUE, + /* 0x27 */ PLAYER_IA_BOTTLE_POTION_GREEN, + /* 0x28 */ PLAYER_IA_BOTTLE_MILK, + /* 0x29 */ PLAYER_IA_BOTTLE_MILK_HALF, + /* 0x2A */ PLAYER_IA_BOTTLE_FAIRY, + /* 0x2B */ PLAYER_IA_LETTER_ZELDA, + /* 0x2C */ PLAYER_IA_WEIRD_EGG, + /* 0x2D */ PLAYER_IA_CHICKEN, + /* 0x2E */ PLAYER_IA_BEAN, + /* 0x2F */ PLAYER_IA_POCKET_EGG, + /* 0x30 */ PLAYER_IA_POCKET_CUCCO, + /* 0x31 */ PLAYER_IA_COJIRO, + /* 0x32 */ PLAYER_IA_ODD_MUSHROOM, + /* 0x33 */ PLAYER_IA_ODD_POTION, + /* 0x34 */ PLAYER_IA_SAW, + /* 0x35 */ PLAYER_IA_SWORD_BROKEN, + /* 0x36 */ PLAYER_IA_PRESCRIPTION, + /* 0x37 */ PLAYER_IA_FROG, + /* 0x38 */ PLAYER_IA_EYEDROPS, + /* 0x39 */ PLAYER_IA_CLAIM_CHECK, + /* 0x3A */ PLAYER_IA_MASK_KEATON, + /* 0x3B */ PLAYER_IA_MASK_SKULL, + /* 0x3C */ PLAYER_IA_MASK_SPOOKY, + /* 0x3D */ PLAYER_IA_MASK_BUNNY, + /* 0x3E */ PLAYER_IA_MASK_GORON, + /* 0x3F */ PLAYER_IA_MASK_ZORA, + /* 0x40 */ PLAYER_IA_MASK_GERUDO, + /* 0x41 */ PLAYER_IA_MASK_TRUTH, + /* 0x42 */ PLAYER_IA_LENS, + /* 0x43 */ PLAYER_IA_MAX +} PlayerItemAction; typedef enum { /* 0x00 */ PLAYER_LIMB_NONE, @@ -469,10 +469,10 @@ typedef struct Player { /* 0x014E */ s8 currentShield; // current shield from `PlayerShield` /* 0x014F */ s8 currentBoots; // current boots from `PlayerBoots` /* 0x0150 */ s8 heldItemButton; // Button index for the item currently used - /* 0x0151 */ s8 heldItemActionParam; // Action param for the item currently used + /* 0x0151 */ s8 heldItemAction; // Item action for the item currently used /* 0x0152 */ u8 heldItemId; // Item id for the item currently used /* 0x0153 */ s8 prevBoots; // previous boots from `PlayerBoots` - /* 0x0154 */ s8 itemActionParam; // the difference between this and heldItemActionParam is unclear + /* 0x0154 */ s8 itemAction; // the difference between this and heldItemAction is unclear /* 0x0155 */ char unk_155[0x003]; /* 0x0158 */ u8 modelGroup; /* 0x0159 */ u8 nextModelGroup; diff --git a/spec b/spec index 871b242804..fdd90baba3 100644 --- a/spec +++ b/spec @@ -4124,7 +4124,7 @@ beginseg name "object_mori_tex" romalign 0x1000 include "build/assets/objects/object_mori_tex/object_mori_tex.o" - number 6 + number 8 endseg beginseg diff --git a/src/code/audio_effects.c b/src/code/audio_effects.c index 75a0937cea..6844d8ae57 100644 --- a/src/code/audio_effects.c +++ b/src/code/audio_effects.c @@ -124,7 +124,7 @@ f32 Audio_GetVibratoFreqScale(VibratoState* vib) { return 1.0f; } - //! @bug this probably meant to compare with gAudioContext.sequenceChannelNone. + //! @bug this probably meant to compare with gAudioCtx.sequenceChannelNone. //! -1 isn't used as a channel pointer anywhere else. if (channel != ((SequenceChannel*)(-1))) { if (vib->extentChangeTimer) { @@ -264,7 +264,7 @@ f32 Audio_AdsrUpdate(AdsrState* adsr) { break; default: - adsr->delay *= gAudioContext.audioBufferParameters.updatesPerFrameScaled; + adsr->delay *= gAudioCtx.audioBufferParameters.updatesPerFrameScaled; if (adsr->delay == 0) { adsr->delay = 1; } diff --git a/src/code/audio_external_data.c b/src/code/audio_external_data.c index 3dcf0fd1de..6a4c29eda7 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/audio_heap.c b/src/code/audio_heap.c index 504b56244e..fd61dc9846 100644 --- a/src/code/audio_heap.c +++ b/src/code/audio_heap.c @@ -16,7 +16,7 @@ void AudioHeap_DiscardSampleBanks(void); * i.e. (256.0f * `updatesPerFrameInvScaled`) is just `updatesPerFrameInv` */ f32 AudioHeap_CalculateAdsrDecay(f32 scaleInv) { - return (256.0f * gAudioContext.audioBufferParameters.updatesPerFrameInvScaled) / scaleInv; + return (256.0f * gAudioCtx.audioBufferParameters.updatesPerFrameInvScaled) / scaleInv; } /** @@ -25,45 +25,45 @@ f32 AudioHeap_CalculateAdsrDecay(f32 scaleInv) { void AudioHeap_InitAdsrDecayTable(void) { s32 i; - gAudioContext.adsrDecayTable[255] = AudioHeap_CalculateAdsrDecay(0.25f); - gAudioContext.adsrDecayTable[254] = AudioHeap_CalculateAdsrDecay(0.33f); - gAudioContext.adsrDecayTable[253] = AudioHeap_CalculateAdsrDecay(0.5f); - gAudioContext.adsrDecayTable[252] = AudioHeap_CalculateAdsrDecay(0.66f); - gAudioContext.adsrDecayTable[251] = AudioHeap_CalculateAdsrDecay(0.75f); + gAudioCtx.adsrDecayTable[255] = AudioHeap_CalculateAdsrDecay(0.25f); + gAudioCtx.adsrDecayTable[254] = AudioHeap_CalculateAdsrDecay(0.33f); + gAudioCtx.adsrDecayTable[253] = AudioHeap_CalculateAdsrDecay(0.5f); + gAudioCtx.adsrDecayTable[252] = AudioHeap_CalculateAdsrDecay(0.66f); + gAudioCtx.adsrDecayTable[251] = AudioHeap_CalculateAdsrDecay(0.75f); for (i = 128; i < 251; i++) { - gAudioContext.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(251 - i); + gAudioCtx.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(251 - i); } for (i = 16; i < 128; i++) { - gAudioContext.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(4 * (143 - i)); + gAudioCtx.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(4 * (143 - i)); } for (i = 1; i < 16; i++) { - gAudioContext.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(60 * (23 - i)); + gAudioCtx.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(60 * (23 - i)); } - gAudioContext.adsrDecayTable[0] = 0.0f; + gAudioCtx.adsrDecayTable[0] = 0.0f; } void AudioHeap_ResetLoadStatus(void) { s32 i; for (i = 0; i < 0x30; i++) { - if (gAudioContext.fontLoadStatus[i] != LOAD_STATUS_PERMANENTLY_LOADED) { - gAudioContext.fontLoadStatus[i] = LOAD_STATUS_NOT_LOADED; + if (gAudioCtx.fontLoadStatus[i] != LOAD_STATUS_PERMANENTLY_LOADED) { + gAudioCtx.fontLoadStatus[i] = LOAD_STATUS_NOT_LOADED; } } for (i = 0; i < 0x30; i++) { - if (gAudioContext.sampleFontLoadStatus[i] != LOAD_STATUS_PERMANENTLY_LOADED) { - gAudioContext.sampleFontLoadStatus[i] = LOAD_STATUS_NOT_LOADED; + if (gAudioCtx.sampleFontLoadStatus[i] != LOAD_STATUS_PERMANENTLY_LOADED) { + gAudioCtx.sampleFontLoadStatus[i] = LOAD_STATUS_NOT_LOADED; } } for (i = 0; i < 0x80; i++) { - if (gAudioContext.seqLoadStatus[i] != LOAD_STATUS_PERMANENTLY_LOADED) { - gAudioContext.seqLoadStatus[i] = LOAD_STATUS_NOT_LOADED; + if (gAudioCtx.seqLoadStatus[i] != LOAD_STATUS_PERMANENTLY_LOADED) { + gAudioCtx.seqLoadStatus[i] = LOAD_STATUS_NOT_LOADED; } } } @@ -71,8 +71,8 @@ void AudioHeap_ResetLoadStatus(void) { void AudioHeap_DiscardFont(s32 fontId) { s32 i; - for (i = 0; i < gAudioContext.numNotes; i++) { - Note* note = &gAudioContext.notes[i]; + for (i = 0; i < gAudioCtx.numNotes; i++) { + Note* note = &gAudioCtx.notes[i]; if (note->playbackState.fontId == fontId) { if (note->playbackState.unk_04 == 0 && note->playbackState.priority != 0) { @@ -81,7 +81,7 @@ void AudioHeap_DiscardFont(s32 fontId) { } Audio_NoteDisable(note); Audio_AudioListRemove(¬e->listItem); - AudioSeq_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, ¬e->listItem); + AudioSeq_AudioListPushBack(&gAudioCtx.noteFreeLists.disabled, ¬e->listItem); } } } @@ -89,14 +89,14 @@ void AudioHeap_DiscardFont(s32 fontId) { void AudioHeap_ReleaseNotesForFont(s32 fontId) { s32 i; - for (i = 0; i < gAudioContext.numNotes; i++) { - Note* note = &gAudioContext.notes[i]; + for (i = 0; i < gAudioCtx.numNotes; i++) { + Note* note = &gAudioCtx.notes[i]; NotePlaybackState* playbackState = ¬e->playbackState; if (playbackState->fontId == fontId) { if ((playbackState->priority != 0) && (playbackState->adsr.action.s.state == ADSR_STATE_DECAY)) { playbackState->priority = 1; - playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv; playbackState->adsr.action.s.release = true; } } @@ -106,9 +106,9 @@ void AudioHeap_ReleaseNotesForFont(s32 fontId) { void AudioHeap_DiscardSequence(s32 seqId) { s32 i; - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - if (gAudioContext.seqPlayers[i].enabled && gAudioContext.seqPlayers[i].seqId == seqId) { - AudioSeq_SequencePlayerDisable(&gAudioContext.seqPlayers[i]); + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + if (gAudioCtx.seqPlayers[i].enabled && gAudioCtx.seqPlayers[i].seqId == seqId) { + AudioSeq_SequencePlayerDisable(&gAudioCtx.seqPlayers[i]); } } } @@ -128,8 +128,8 @@ void AudioHeap_WritebackDCache(void* ramAddr, u32 size) { void* AudioHeap_AllocZeroedAttemptExternal(AudioAllocPool* pool, u32 size) { void* ramAddr = NULL; - if (gAudioContext.externalPool.startRamAddr != NULL) { - ramAddr = AudioHeap_AllocZeroed(&gAudioContext.externalPool, size); + if (gAudioCtx.externalPool.startRamAddr != NULL) { + ramAddr = AudioHeap_AllocZeroed(&gAudioCtx.externalPool, size); } if (ramAddr == NULL) { ramAddr = AudioHeap_AllocZeroed(pool, size); @@ -140,8 +140,8 @@ void* AudioHeap_AllocZeroedAttemptExternal(AudioAllocPool* pool, u32 size) { void* AudioHeap_AllocAttemptExternal(AudioAllocPool* pool, u32 size) { void* ramAddr = NULL; - if (gAudioContext.externalPool.startRamAddr != NULL) { - ramAddr = AudioHeap_Alloc(&gAudioContext.externalPool, size); + if (gAudioCtx.externalPool.startRamAddr != NULL) { + ramAddr = AudioHeap_Alloc(&gAudioCtx.externalPool, size); } if (ramAddr == NULL) { ramAddr = AudioHeap_Alloc(pool, size); @@ -237,18 +237,18 @@ void AudioHeap_PopPersistentCache(s32 tableType) { switch (tableType) { case SEQUENCE_TABLE: - loadedCache = &gAudioContext.seqCache; - loadStatus = gAudioContext.seqLoadStatus; + loadedCache = &gAudioCtx.seqCache; + loadStatus = gAudioCtx.seqLoadStatus; break; case FONT_TABLE: - loadedCache = &gAudioContext.fontCache; - loadStatus = gAudioContext.fontLoadStatus; + loadedCache = &gAudioCtx.fontCache; + loadStatus = gAudioCtx.fontLoadStatus; break; case SAMPLE_TABLE: - loadedCache = &gAudioContext.sampleBankCache; - loadStatus = gAudioContext.sampleFontLoadStatus; + loadedCache = &gAudioCtx.sampleBankCache; + loadStatus = gAudioCtx.sampleFontLoadStatus; break; } @@ -275,57 +275,56 @@ void AudioHeap_PopPersistentCache(s32 tableType) { } void AudioHeap_InitMainPools(s32 initPoolSize) { - AudioHeap_InitPool(&gAudioContext.initPool, gAudioContext.audioHeap, initPoolSize); - AudioHeap_InitPool(&gAudioContext.sessionPool, gAudioContext.audioHeap + initPoolSize, - gAudioContext.audioHeapSize - initPoolSize); - gAudioContext.externalPool.startRamAddr = NULL; + AudioHeap_InitPool(&gAudioCtx.initPool, gAudioCtx.audioHeap, initPoolSize); + AudioHeap_InitPool(&gAudioCtx.sessionPool, gAudioCtx.audioHeap + initPoolSize, + gAudioCtx.audioHeapSize - initPoolSize); + gAudioCtx.externalPool.startRamAddr = NULL; } void AudioHeap_InitSessionPools(AudioSessionPoolSplit* split) { - gAudioContext.sessionPool.curRamAddr = gAudioContext.sessionPool.startRamAddr; - AudioHeap_InitPool(&gAudioContext.miscPool, AudioHeap_Alloc(&gAudioContext.sessionPool, split->miscPoolSize), + gAudioCtx.sessionPool.curRamAddr = gAudioCtx.sessionPool.startRamAddr; + AudioHeap_InitPool(&gAudioCtx.miscPool, AudioHeap_Alloc(&gAudioCtx.sessionPool, split->miscPoolSize), split->miscPoolSize); - AudioHeap_InitPool(&gAudioContext.cachePool, AudioHeap_Alloc(&gAudioContext.sessionPool, split->cachePoolSize), + AudioHeap_InitPool(&gAudioCtx.cachePool, AudioHeap_Alloc(&gAudioCtx.sessionPool, split->cachePoolSize), split->cachePoolSize); } void AudioHeap_InitCachePools(AudioCachePoolSplit* split) { - gAudioContext.cachePool.curRamAddr = gAudioContext.cachePool.startRamAddr; - AudioHeap_InitPool(&gAudioContext.persistentCommonPool, - AudioHeap_Alloc(&gAudioContext.cachePool, split->persistentCommonPoolSize), + gAudioCtx.cachePool.curRamAddr = gAudioCtx.cachePool.startRamAddr; + AudioHeap_InitPool(&gAudioCtx.persistentCommonPool, + AudioHeap_Alloc(&gAudioCtx.cachePool, split->persistentCommonPoolSize), split->persistentCommonPoolSize); - AudioHeap_InitPool(&gAudioContext.temporaryCommonPool, - AudioHeap_Alloc(&gAudioContext.cachePool, split->temporaryCommonPoolSize), + AudioHeap_InitPool(&gAudioCtx.temporaryCommonPool, + AudioHeap_Alloc(&gAudioCtx.cachePool, split->temporaryCommonPoolSize), split->temporaryCommonPoolSize); } void AudioHeap_InitPersistentPoolsAndCaches(AudioCommonPoolSplit* split) { - gAudioContext.persistentCommonPool.curRamAddr = gAudioContext.persistentCommonPool.startRamAddr; - AudioHeap_InitPool(&gAudioContext.seqCache.persistent.pool, - AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->seqCacheSize), split->seqCacheSize); - AudioHeap_InitPool(&gAudioContext.fontCache.persistent.pool, - AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->fontCacheSize), - split->fontCacheSize); - AudioHeap_InitPool(&gAudioContext.sampleBankCache.persistent.pool, - AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->sampleBankCacheSize), + gAudioCtx.persistentCommonPool.curRamAddr = gAudioCtx.persistentCommonPool.startRamAddr; + AudioHeap_InitPool(&gAudioCtx.seqCache.persistent.pool, + AudioHeap_Alloc(&gAudioCtx.persistentCommonPool, split->seqCacheSize), split->seqCacheSize); + AudioHeap_InitPool(&gAudioCtx.fontCache.persistent.pool, + AudioHeap_Alloc(&gAudioCtx.persistentCommonPool, split->fontCacheSize), split->fontCacheSize); + AudioHeap_InitPool(&gAudioCtx.sampleBankCache.persistent.pool, + AudioHeap_Alloc(&gAudioCtx.persistentCommonPool, split->sampleBankCacheSize), split->sampleBankCacheSize); - AudioHeap_InitPersistentCache(&gAudioContext.seqCache.persistent); - AudioHeap_InitPersistentCache(&gAudioContext.fontCache.persistent); - AudioHeap_InitPersistentCache(&gAudioContext.sampleBankCache.persistent); + AudioHeap_InitPersistentCache(&gAudioCtx.seqCache.persistent); + AudioHeap_InitPersistentCache(&gAudioCtx.fontCache.persistent); + AudioHeap_InitPersistentCache(&gAudioCtx.sampleBankCache.persistent); } void AudioHeap_InitTemporaryPoolsAndCaches(AudioCommonPoolSplit* split) { - gAudioContext.temporaryCommonPool.curRamAddr = gAudioContext.temporaryCommonPool.startRamAddr; - AudioHeap_InitPool(&gAudioContext.seqCache.temporary.pool, - AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->seqCacheSize), split->seqCacheSize); - AudioHeap_InitPool(&gAudioContext.fontCache.temporary.pool, - AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->fontCacheSize), split->fontCacheSize); - AudioHeap_InitPool(&gAudioContext.sampleBankCache.temporary.pool, - AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->sampleBankCacheSize), + gAudioCtx.temporaryCommonPool.curRamAddr = gAudioCtx.temporaryCommonPool.startRamAddr; + AudioHeap_InitPool(&gAudioCtx.seqCache.temporary.pool, + AudioHeap_Alloc(&gAudioCtx.temporaryCommonPool, split->seqCacheSize), split->seqCacheSize); + AudioHeap_InitPool(&gAudioCtx.fontCache.temporary.pool, + AudioHeap_Alloc(&gAudioCtx.temporaryCommonPool, split->fontCacheSize), split->fontCacheSize); + AudioHeap_InitPool(&gAudioCtx.sampleBankCache.temporary.pool, + AudioHeap_Alloc(&gAudioCtx.temporaryCommonPool, split->sampleBankCacheSize), split->sampleBankCacheSize); - AudioHeap_InitTemporaryCache(&gAudioContext.seqCache.temporary); - AudioHeap_InitTemporaryCache(&gAudioContext.fontCache.temporary); - AudioHeap_InitTemporaryCache(&gAudioContext.sampleBankCache.temporary); + AudioHeap_InitTemporaryCache(&gAudioCtx.seqCache.temporary); + AudioHeap_InitTemporaryCache(&gAudioCtx.fontCache.temporary); + AudioHeap_InitTemporaryCache(&gAudioCtx.sampleBankCache.temporary); } void* AudioHeap_AllocCached(s32 tableType, s32 size, s32 cache, s32 id) { @@ -342,18 +341,18 @@ void* AudioHeap_AllocCached(s32 tableType, s32 size, s32 cache, s32 id) { switch (tableType) { case SEQUENCE_TABLE: - loadedCache = &gAudioContext.seqCache; - loadStatus = gAudioContext.seqLoadStatus; + loadedCache = &gAudioCtx.seqCache; + loadStatus = gAudioCtx.seqLoadStatus; break; case FONT_TABLE: - loadedCache = &gAudioContext.fontCache; - loadStatus = gAudioContext.fontLoadStatus; + loadedCache = &gAudioCtx.fontCache; + loadStatus = gAudioCtx.fontLoadStatus; break; case SAMPLE_TABLE: - loadedCache = &gAudioContext.sampleBankCache; - loadStatus = gAudioContext.sampleFontLoadStatus; + loadedCache = &gAudioCtx.sampleBankCache; + loadStatus = gAudioCtx.sampleFontLoadStatus; break; } @@ -372,28 +371,28 @@ void* AudioHeap_AllocCached(s32 tableType, s32 size, s32 cache, s32 id) { if (tableType == FONT_TABLE) { if (loadStatusEntry0 == LOAD_STATUS_MAYBE_DISCARDABLE) { - for (i = 0; i < gAudioContext.numNotes; i++) { - if (gAudioContext.notes[i].playbackState.fontId == temporaryCache->entries[0].id && - gAudioContext.notes[i].noteSubEu.bitField0.enabled) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + if (gAudioCtx.notes[i].playbackState.fontId == temporaryCache->entries[0].id && + gAudioCtx.notes[i].noteSubEu.bitField0.enabled) { break; } } - if (i == gAudioContext.numNotes) { + if (i == gAudioCtx.numNotes) { AudioLoad_SetFontLoadStatus(temporaryCache->entries[0].id, LOAD_STATUS_DISCARDABLE); loadStatusEntry0 = LOAD_STATUS_DISCARDABLE; } } if (loadStatusEntry1 == LOAD_STATUS_MAYBE_DISCARDABLE) { - for (i = 0; i < gAudioContext.numNotes; i++) { - if (gAudioContext.notes[i].playbackState.fontId == temporaryCache->entries[1].id && - gAudioContext.notes[i].noteSubEu.bitField0.enabled) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + if (gAudioCtx.notes[i].playbackState.fontId == temporaryCache->entries[1].id && + gAudioCtx.notes[i].noteSubEu.bitField0.enabled) { break; } } - if (i == gAudioContext.numNotes) { + if (i == gAudioCtx.numNotes) { AudioLoad_SetFontLoadStatus(temporaryCache->entries[1].id, LOAD_STATUS_DISCARDABLE); loadStatusEntry1 = LOAD_STATUS_DISCARDABLE; } @@ -414,54 +413,54 @@ void* AudioHeap_AllocCached(s32 tableType, s32 size, s32 cache, s32 id) { // Check if there is a side which isn't in active use, if so, evict that one. if (tableType == SEQUENCE_TABLE) { if (loadStatusEntry0 == LOAD_STATUS_COMPLETE) { - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - if (gAudioContext.seqPlayers[i].enabled && - gAudioContext.seqPlayers[i].seqId == temporaryCache->entries[0].id) { + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + if (gAudioCtx.seqPlayers[i].enabled && + gAudioCtx.seqPlayers[i].seqId == temporaryCache->entries[0].id) { break; } } - if (i == gAudioContext.audioBufferParameters.numSequencePlayers) { + if (i == gAudioCtx.audioBufferParameters.numSequencePlayers) { temporaryCache->nextSide = 0; goto done; } } if (loadStatusEntry1 == LOAD_STATUS_COMPLETE) { - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - if (gAudioContext.seqPlayers[i].enabled && - gAudioContext.seqPlayers[i].seqId == temporaryCache->entries[1].id) { + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + if (gAudioCtx.seqPlayers[i].enabled && + gAudioCtx.seqPlayers[i].seqId == temporaryCache->entries[1].id) { break; } } - if (i == gAudioContext.audioBufferParameters.numSequencePlayers) { + if (i == gAudioCtx.audioBufferParameters.numSequencePlayers) { temporaryCache->nextSide = 1; goto done; } } } else if (tableType == FONT_TABLE) { if (loadStatusEntry0 == LOAD_STATUS_COMPLETE) { - for (i = 0; i < gAudioContext.numNotes; i++) { - if (gAudioContext.notes[i].playbackState.fontId == temporaryCache->entries[0].id && - gAudioContext.notes[i].noteSubEu.bitField0.enabled) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + if (gAudioCtx.notes[i].playbackState.fontId == temporaryCache->entries[0].id && + gAudioCtx.notes[i].noteSubEu.bitField0.enabled) { break; } } - if (i == gAudioContext.numNotes) { + if (i == gAudioCtx.numNotes) { temporaryCache->nextSide = 0; goto done; } } if (loadStatusEntry1 == LOAD_STATUS_COMPLETE) { - for (i = 0; i < gAudioContext.numNotes; i++) { - if (gAudioContext.notes[i].playbackState.fontId == temporaryCache->entries[1].id && - gAudioContext.notes[i].noteSubEu.bitField0.enabled) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + if (gAudioCtx.notes[i].playbackState.fontId == temporaryCache->entries[1].id && + gAudioCtx.notes[i].noteSubEu.bitField0.enabled) { break; } } - if (i == gAudioContext.numNotes) { + if (i == gAudioCtx.numNotes) { temporaryCache->nextSide = 1; goto done; } @@ -618,15 +617,15 @@ void* AudioHeap_SearchRegularCaches(s32 tableType, s32 cache, s32 id) { switch (tableType) { case SEQUENCE_TABLE: - loadedCache = &gAudioContext.seqCache; + loadedCache = &gAudioCtx.seqCache; break; case FONT_TABLE: - loadedCache = &gAudioContext.fontCache; + loadedCache = &gAudioCtx.fontCache; break; case SAMPLE_TABLE: - loadedCache = &gAudioContext.sampleBankCache; + loadedCache = &gAudioCtx.sampleBankCache; break; } @@ -738,15 +737,15 @@ void AudioHeap_UpdateReverbs(void) { s32 i; s32 j; - if (gAudioContext.audioBufferParameters.specUnk4 == 2) { + if (gAudioCtx.audioBufferParameters.specUnk4 == 2) { count = 2; } else { count = 1; } - for (i = 0; i < gAudioContext.numSynthesisReverbs; i++) { + for (i = 0; i < gAudioCtx.numSynthesisReverbs; i++) { for (j = 0; j < count; j++) { - AudioHeap_UpdateReverb(&gAudioContext.synthesisReverbs[i]); + AudioHeap_UpdateReverb(&gAudioCtx.synthesisReverbs[i]); } } } @@ -755,13 +754,13 @@ void AudioHeap_UpdateReverbs(void) { * Clear the current Audio Interface Buffer */ void AudioHeap_ClearCurrentAiBuffer(void) { - s32 curAiBufferIndex = gAudioContext.curAiBufIndex; + s32 curAiBufferIndex = gAudioCtx.curAiBufIndex; s32 i; - gAudioContext.aiBufLengths[curAiBufferIndex] = gAudioContext.audioBufferParameters.minAiBufferLength; + gAudioCtx.aiBufLengths[curAiBufferIndex] = gAudioCtx.audioBufferParameters.minAiBufferLength; for (i = 0; i < AIBUF_LEN; i++) { - gAudioContext.aiBuffers[curAiBufferIndex][i] = 0; + gAudioCtx.aiBuffers[curAiBufferIndex][i] = 0; } } @@ -770,55 +769,55 @@ s32 AudioHeap_ResetStep(void) { s32 j; s32 sp24; - if (gAudioContext.audioBufferParameters.specUnk4 == 2) { + if (gAudioCtx.audioBufferParameters.specUnk4 == 2) { sp24 = 2; } else { sp24 = 1; } - switch (gAudioContext.resetStatus) { + switch (gAudioCtx.resetStatus) { case 5: - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - AudioSeq_SequencePlayerDisableAsFinished(&gAudioContext.seqPlayers[i]); + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + AudioSeq_SequencePlayerDisableAsFinished(&gAudioCtx.seqPlayers[i]); } - gAudioContext.audioResetFadeOutFramesLeft = 2 / sp24; - gAudioContext.resetStatus--; + gAudioCtx.audioResetFadeOutFramesLeft = 2 / sp24; + gAudioCtx.resetStatus--; break; case 4: - if (gAudioContext.audioResetFadeOutFramesLeft != 0) { - gAudioContext.audioResetFadeOutFramesLeft--; + if (gAudioCtx.audioResetFadeOutFramesLeft != 0) { + gAudioCtx.audioResetFadeOutFramesLeft--; AudioHeap_UpdateReverbs(); } else { - for (i = 0; i < gAudioContext.numNotes; i++) { - if (gAudioContext.notes[i].noteSubEu.bitField0.enabled && - gAudioContext.notes[i].playbackState.adsr.action.s.state != ADSR_STATE_DISABLED) { - gAudioContext.notes[i].playbackState.adsr.fadeOutVel = - gAudioContext.audioBufferParameters.updatesPerFrameInv; - gAudioContext.notes[i].playbackState.adsr.action.s.release = true; + for (i = 0; i < gAudioCtx.numNotes; i++) { + if (gAudioCtx.notes[i].noteSubEu.bitField0.enabled && + gAudioCtx.notes[i].playbackState.adsr.action.s.state != ADSR_STATE_DISABLED) { + gAudioCtx.notes[i].playbackState.adsr.fadeOutVel = + gAudioCtx.audioBufferParameters.updatesPerFrameInv; + gAudioCtx.notes[i].playbackState.adsr.action.s.release = true; } } - gAudioContext.audioResetFadeOutFramesLeft = 8 / sp24; - gAudioContext.resetStatus--; + gAudioCtx.audioResetFadeOutFramesLeft = 8 / sp24; + gAudioCtx.resetStatus--; } break; case 3: - if (gAudioContext.audioResetFadeOutFramesLeft != 0) { - gAudioContext.audioResetFadeOutFramesLeft--; + if (gAudioCtx.audioResetFadeOutFramesLeft != 0) { + gAudioCtx.audioResetFadeOutFramesLeft--; AudioHeap_UpdateReverbs(); } else { - gAudioContext.audioResetFadeOutFramesLeft = 2 / sp24; - gAudioContext.resetStatus--; + gAudioCtx.audioResetFadeOutFramesLeft = 2 / sp24; + gAudioCtx.resetStatus--; } break; case 2: AudioHeap_ClearCurrentAiBuffer(); - if (gAudioContext.audioResetFadeOutFramesLeft != 0) { - gAudioContext.audioResetFadeOutFramesLeft--; + if (gAudioCtx.audioResetFadeOutFramesLeft != 0) { + gAudioCtx.audioResetFadeOutFramesLeft--; } else { - gAudioContext.resetStatus--; + gAudioCtx.resetStatus--; AudioHeap_DiscardSampleCaches(); AudioHeap_DiscardSampleBanks(); } @@ -826,17 +825,17 @@ s32 AudioHeap_ResetStep(void) { case 1: AudioHeap_Init(); - gAudioContext.resetStatus = 0; + gAudioCtx.resetStatus = 0; for (i = 0; i < 3; i++) { - gAudioContext.aiBufLengths[i] = gAudioContext.audioBufferParameters.maxAiBufferLength; + gAudioCtx.aiBufLengths[i] = gAudioCtx.audioBufferParameters.maxAiBufferLength; for (j = 0; j < AIBUF_LEN; j++) { - gAudioContext.aiBuffers[i][j] = 0; + gAudioCtx.aiBuffers[i][j] = 0; } } break; } - if (gAudioContext.resetStatus < 3) { + if (gAudioCtx.resetStatus < 3) { return false; } @@ -854,66 +853,61 @@ void AudioHeap_Init(void) { s32 i; s32 j; s32 pad2; - AudioSpec* spec = &gAudioSpecs[gAudioContext.audioResetSpecIdToLoad]; // Audio Specifications + AudioSpec* spec = &gAudioSpecs[gAudioCtx.audioResetSpecIdToLoad]; // Audio Specifications - gAudioContext.sampleDmaCount = 0; + gAudioCtx.sampleDmaCount = 0; // audio buffer parameters - gAudioContext.audioBufferParameters.samplingFrequency = spec->samplingFrequency; - gAudioContext.audioBufferParameters.aiSamplingFrequency = - osAiSetFrequency(gAudioContext.audioBufferParameters.samplingFrequency); - gAudioContext.audioBufferParameters.samplesPerFrameTarget = - ALIGN16(gAudioContext.audioBufferParameters.samplingFrequency / gAudioContext.refreshRate); - gAudioContext.audioBufferParameters.minAiBufferLength = - gAudioContext.audioBufferParameters.samplesPerFrameTarget - 0x10; - gAudioContext.audioBufferParameters.maxAiBufferLength = - gAudioContext.audioBufferParameters.samplesPerFrameTarget + 0x10; - gAudioContext.audioBufferParameters.updatesPerFrame = - ((gAudioContext.audioBufferParameters.samplesPerFrameTarget + 0x10) / 0xD0) + 1; - gAudioContext.audioBufferParameters.samplesPerUpdate = (gAudioContext.audioBufferParameters.samplesPerFrameTarget / - gAudioContext.audioBufferParameters.updatesPerFrame) & - ~7; - gAudioContext.audioBufferParameters.samplesPerUpdateMax = gAudioContext.audioBufferParameters.samplesPerUpdate + 8; - gAudioContext.audioBufferParameters.samplesPerUpdateMin = gAudioContext.audioBufferParameters.samplesPerUpdate - 8; - gAudioContext.audioBufferParameters.resampleRate = - 32000.0f / (s32)gAudioContext.audioBufferParameters.samplingFrequency; - gAudioContext.audioBufferParameters.updatesPerFrameInvScaled = - (1.0f / 256.0f) / gAudioContext.audioBufferParameters.updatesPerFrame; - gAudioContext.audioBufferParameters.updatesPerFrameScaled = - gAudioContext.audioBufferParameters.updatesPerFrame / 4.0f; - gAudioContext.audioBufferParameters.updatesPerFrameInv = 1.0f / gAudioContext.audioBufferParameters.updatesPerFrame; + gAudioCtx.audioBufferParameters.samplingFrequency = spec->samplingFrequency; + gAudioCtx.audioBufferParameters.aiSamplingFrequency = + osAiSetFrequency(gAudioCtx.audioBufferParameters.samplingFrequency); + gAudioCtx.audioBufferParameters.samplesPerFrameTarget = + ALIGN16(gAudioCtx.audioBufferParameters.samplingFrequency / gAudioCtx.refreshRate); + gAudioCtx.audioBufferParameters.minAiBufferLength = gAudioCtx.audioBufferParameters.samplesPerFrameTarget - 0x10; + gAudioCtx.audioBufferParameters.maxAiBufferLength = gAudioCtx.audioBufferParameters.samplesPerFrameTarget + 0x10; + gAudioCtx.audioBufferParameters.updatesPerFrame = + ((gAudioCtx.audioBufferParameters.samplesPerFrameTarget + 0x10) / 0xD0) + 1; + gAudioCtx.audioBufferParameters.samplesPerUpdate = + (gAudioCtx.audioBufferParameters.samplesPerFrameTarget / gAudioCtx.audioBufferParameters.updatesPerFrame) & ~7; + gAudioCtx.audioBufferParameters.samplesPerUpdateMax = gAudioCtx.audioBufferParameters.samplesPerUpdate + 8; + gAudioCtx.audioBufferParameters.samplesPerUpdateMin = gAudioCtx.audioBufferParameters.samplesPerUpdate - 8; + gAudioCtx.audioBufferParameters.resampleRate = 32000.0f / (s32)gAudioCtx.audioBufferParameters.samplingFrequency; + gAudioCtx.audioBufferParameters.updatesPerFrameInvScaled = + (1.0f / 256.0f) / gAudioCtx.audioBufferParameters.updatesPerFrame; + gAudioCtx.audioBufferParameters.updatesPerFrameScaled = gAudioCtx.audioBufferParameters.updatesPerFrame / 4.0f; + gAudioCtx.audioBufferParameters.updatesPerFrameInv = 1.0f / gAudioCtx.audioBufferParameters.updatesPerFrame; // SampleDma buffer size - gAudioContext.sampleDmaBufSize1 = spec->sampleDmaBufSize1; - gAudioContext.sampleDmaBufSize2 = spec->sampleDmaBufSize2; + gAudioCtx.sampleDmaBufSize1 = spec->sampleDmaBufSize1; + gAudioCtx.sampleDmaBufSize2 = spec->sampleDmaBufSize2; - gAudioContext.numNotes = spec->numNotes; - gAudioContext.audioBufferParameters.numSequencePlayers = spec->numSequencePlayers; - if (gAudioContext.audioBufferParameters.numSequencePlayers > 4) { - gAudioContext.audioBufferParameters.numSequencePlayers = 4; + gAudioCtx.numNotes = spec->numNotes; + gAudioCtx.audioBufferParameters.numSequencePlayers = spec->numSequencePlayers; + if (gAudioCtx.audioBufferParameters.numSequencePlayers > 4) { + gAudioCtx.audioBufferParameters.numSequencePlayers = 4; } - gAudioContext.unk_2 = spec->unk_14; - gAudioContext.tempoInternalToExternal = (u32)(gAudioContext.audioBufferParameters.updatesPerFrame * 2880000.0f / - gTatumsPerBeat / gAudioContext.unk_2960); + gAudioCtx.unk_2 = spec->unk_14; + gAudioCtx.tempoInternalToExternal = + (u32)(gAudioCtx.audioBufferParameters.updatesPerFrame * 2880000.0f / gTatumsPerBeat / gAudioCtx.unk_2960); - gAudioContext.unk_2870 = gAudioContext.refreshRate; - gAudioContext.unk_2870 *= gAudioContext.audioBufferParameters.updatesPerFrame; - gAudioContext.unk_2870 /= gAudioContext.audioBufferParameters.aiSamplingFrequency; - gAudioContext.unk_2870 /= gAudioContext.tempoInternalToExternal; + gAudioCtx.unk_2870 = gAudioCtx.refreshRate; + gAudioCtx.unk_2870 *= gAudioCtx.audioBufferParameters.updatesPerFrame; + gAudioCtx.unk_2870 /= gAudioCtx.audioBufferParameters.aiSamplingFrequency; + gAudioCtx.unk_2870 /= gAudioCtx.tempoInternalToExternal; - gAudioContext.audioBufferParameters.specUnk4 = spec->unk_04; - gAudioContext.audioBufferParameters.samplesPerFrameTarget *= gAudioContext.audioBufferParameters.specUnk4; - gAudioContext.audioBufferParameters.maxAiBufferLength *= gAudioContext.audioBufferParameters.specUnk4; - gAudioContext.audioBufferParameters.minAiBufferLength *= gAudioContext.audioBufferParameters.specUnk4; - gAudioContext.audioBufferParameters.updatesPerFrame *= gAudioContext.audioBufferParameters.specUnk4; + gAudioCtx.audioBufferParameters.specUnk4 = spec->unk_04; + gAudioCtx.audioBufferParameters.samplesPerFrameTarget *= gAudioCtx.audioBufferParameters.specUnk4; + gAudioCtx.audioBufferParameters.maxAiBufferLength *= gAudioCtx.audioBufferParameters.specUnk4; + gAudioCtx.audioBufferParameters.minAiBufferLength *= gAudioCtx.audioBufferParameters.specUnk4; + gAudioCtx.audioBufferParameters.updatesPerFrame *= gAudioCtx.audioBufferParameters.specUnk4; - if (gAudioContext.audioBufferParameters.specUnk4 >= 2) { - gAudioContext.audioBufferParameters.maxAiBufferLength -= 0x10; + if (gAudioCtx.audioBufferParameters.specUnk4 >= 2) { + gAudioCtx.audioBufferParameters.maxAiBufferLength -= 0x10; } // Determine the length of the buffer for storing the audio command list passed to the rsp audio microcode - gAudioContext.maxAudioCmds = gAudioContext.numNotes * 0x10 * gAudioContext.audioBufferParameters.updatesPerFrame + - spec->numReverbs * 0x18 + 0x140; + gAudioCtx.maxAudioCmds = + gAudioCtx.numNotes * 0x10 * gAudioCtx.audioBufferParameters.updatesPerFrame + spec->numReverbs * 0x18 + 0x140; // Calculate sizes for various caches on the audio heap persistentSize = @@ -921,62 +915,61 @@ void AudioHeap_Init(void) { temporarySize = spec->temporarySeqCacheSize + spec->temporaryFontCacheSize + spec->temporarySampleBankCacheSize + 0x10; cachePoolSize = persistentSize + temporarySize; - miscPoolSize = gAudioContext.sessionPool.size - cachePoolSize - 0x100; + miscPoolSize = gAudioCtx.sessionPool.size - cachePoolSize - 0x100; - if (gAudioContext.externalPool.startRamAddr != NULL) { - gAudioContext.externalPool.curRamAddr = gAudioContext.externalPool.startRamAddr; + if (gAudioCtx.externalPool.startRamAddr != NULL) { + gAudioCtx.externalPool.curRamAddr = gAudioCtx.externalPool.startRamAddr; } // Session Pool Split (split into Cache and Misc pools) - gAudioContext.sessionPoolSplit.miscPoolSize = miscPoolSize; - gAudioContext.sessionPoolSplit.cachePoolSize = cachePoolSize; - AudioHeap_InitSessionPools(&gAudioContext.sessionPoolSplit); + gAudioCtx.sessionPoolSplit.miscPoolSize = miscPoolSize; + gAudioCtx.sessionPoolSplit.cachePoolSize = cachePoolSize; + AudioHeap_InitSessionPools(&gAudioCtx.sessionPoolSplit); // Cache Pool Split (split into Persistent and Temporary pools) - gAudioContext.cachePoolSplit.persistentCommonPoolSize = persistentSize; - gAudioContext.cachePoolSplit.temporaryCommonPoolSize = temporarySize; - AudioHeap_InitCachePools(&gAudioContext.cachePoolSplit); + gAudioCtx.cachePoolSplit.persistentCommonPoolSize = persistentSize; + gAudioCtx.cachePoolSplit.temporaryCommonPoolSize = temporarySize; + AudioHeap_InitCachePools(&gAudioCtx.cachePoolSplit); // Persistent Pool Split (split into Sequences, SoundFonts, Samples pools) - gAudioContext.persistentCommonPoolSplit.seqCacheSize = spec->persistentSeqCacheSize; - gAudioContext.persistentCommonPoolSplit.fontCacheSize = spec->persistentFontCacheSize; - gAudioContext.persistentCommonPoolSplit.sampleBankCacheSize = spec->persistentSampleBankCacheSize; - AudioHeap_InitPersistentPoolsAndCaches(&gAudioContext.persistentCommonPoolSplit); + gAudioCtx.persistentCommonPoolSplit.seqCacheSize = spec->persistentSeqCacheSize; + gAudioCtx.persistentCommonPoolSplit.fontCacheSize = spec->persistentFontCacheSize; + gAudioCtx.persistentCommonPoolSplit.sampleBankCacheSize = spec->persistentSampleBankCacheSize; + AudioHeap_InitPersistentPoolsAndCaches(&gAudioCtx.persistentCommonPoolSplit); // Temporary Pool Split (split into Sequences, SoundFonts, Samples pools) - gAudioContext.temporaryCommonPoolSplit.seqCacheSize = spec->temporarySeqCacheSize; - gAudioContext.temporaryCommonPoolSplit.fontCacheSize = spec->temporaryFontCacheSize; - gAudioContext.temporaryCommonPoolSplit.sampleBankCacheSize = spec->temporarySampleBankCacheSize; - AudioHeap_InitTemporaryPoolsAndCaches(&gAudioContext.temporaryCommonPoolSplit); + gAudioCtx.temporaryCommonPoolSplit.seqCacheSize = spec->temporarySeqCacheSize; + gAudioCtx.temporaryCommonPoolSplit.fontCacheSize = spec->temporaryFontCacheSize; + gAudioCtx.temporaryCommonPoolSplit.sampleBankCacheSize = spec->temporarySampleBankCacheSize; + AudioHeap_InitTemporaryPoolsAndCaches(&gAudioCtx.temporaryCommonPoolSplit); AudioHeap_ResetLoadStatus(); // Initialize notes - gAudioContext.notes = AudioHeap_AllocZeroed(&gAudioContext.miscPool, gAudioContext.numNotes * sizeof(Note)); + gAudioCtx.notes = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, gAudioCtx.numNotes * sizeof(Note)); Audio_NoteInitAll(); Audio_InitNoteFreeList(); - gAudioContext.noteSubsEu = - AudioHeap_AllocZeroed(&gAudioContext.miscPool, gAudioContext.audioBufferParameters.updatesPerFrame * - gAudioContext.numNotes * sizeof(NoteSubEu)); + gAudioCtx.noteSubsEu = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, gAudioCtx.audioBufferParameters.updatesPerFrame * + gAudioCtx.numNotes * sizeof(NoteSubEu)); // Initialize audio binary interface command list buffers for (i = 0; i != 2; i++) { - gAudioContext.abiCmdBufs[i] = - AudioHeap_AllocDmaMemoryZeroed(&gAudioContext.miscPool, gAudioContext.maxAudioCmds * sizeof(Acmd)); + gAudioCtx.abiCmdBufs[i] = + AudioHeap_AllocDmaMemoryZeroed(&gAudioCtx.miscPool, gAudioCtx.maxAudioCmds * sizeof(Acmd)); } // Initialize the decay rate table for adsr - gAudioContext.adsrDecayTable = AudioHeap_Alloc(&gAudioContext.miscPool, 256 * sizeof(f32)); + gAudioCtx.adsrDecayTable = AudioHeap_Alloc(&gAudioCtx.miscPool, 256 * sizeof(f32)); AudioHeap_InitAdsrDecayTable(); // Initialize reverbs for (i = 0; i < 4; i++) { - gAudioContext.synthesisReverbs[i].useReverb = 0; + gAudioCtx.synthesisReverbs[i].useReverb = 0; } - gAudioContext.numSynthesisReverbs = spec->numReverbs; - for (i = 0; i < gAudioContext.numSynthesisReverbs; i++) { + gAudioCtx.numSynthesisReverbs = spec->numReverbs; + for (i = 0; i < gAudioCtx.numSynthesisReverbs; i++) { ReverbSettings* settings = &spec->reverbSettings[i]; - SynthesisReverb* reverb = &gAudioContext.synthesisReverbs[i]; + SynthesisReverb* reverb = &gAudioCtx.synthesisReverbs[i]; reverb->downsampleRate = settings->downsampleRate; reverb->windowSize = settings->windowSize * 64; @@ -992,9 +985,9 @@ void AudioHeap_Init(void) { reverb->unk_08 = settings->unk_12; reverb->useReverb = 8; reverb->leftRingBuf = - AudioHeap_AllocZeroedAttemptExternal(&gAudioContext.miscPool, reverb->windowSize * SAMPLE_SIZE); + AudioHeap_AllocZeroedAttemptExternal(&gAudioCtx.miscPool, reverb->windowSize * SAMPLE_SIZE); reverb->rightRingBuf = - AudioHeap_AllocZeroedAttemptExternal(&gAudioContext.miscPool, reverb->windowSize * SAMPLE_SIZE); + AudioHeap_AllocZeroedAttemptExternal(&gAudioCtx.miscPool, reverb->windowSize * SAMPLE_SIZE); reverb->nextRingBufPos = 0; reverb->unk_20 = 0; reverb->curFrame = 0; @@ -1014,16 +1007,16 @@ void AudioHeap_Init(void) { if (reverb->downsampleRate != 1) { reverb->unk_0E = 0x8000 / reverb->downsampleRate; - reverb->unk_30 = AudioHeap_AllocZeroed(&gAudioContext.miscPool, sizeof(RESAMPLE_STATE)); - reverb->unk_34 = AudioHeap_AllocZeroed(&gAudioContext.miscPool, sizeof(RESAMPLE_STATE)); - reverb->unk_38 = AudioHeap_AllocZeroed(&gAudioContext.miscPool, sizeof(RESAMPLE_STATE)); - reverb->unk_3C = AudioHeap_AllocZeroed(&gAudioContext.miscPool, sizeof(RESAMPLE_STATE)); - for (j = 0; j < gAudioContext.audioBufferParameters.updatesPerFrame; j++) { - ramAddr = AudioHeap_AllocZeroedAttemptExternal(&gAudioContext.miscPool, DMEM_2CH_SIZE); + reverb->unk_30 = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(RESAMPLE_STATE)); + reverb->unk_34 = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(RESAMPLE_STATE)); + reverb->unk_38 = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(RESAMPLE_STATE)); + reverb->unk_3C = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(RESAMPLE_STATE)); + for (j = 0; j < gAudioCtx.audioBufferParameters.updatesPerFrame; j++) { + ramAddr = AudioHeap_AllocZeroedAttemptExternal(&gAudioCtx.miscPool, DMEM_2CH_SIZE); reverb->items[0][j].toDownsampleLeft = ramAddr; reverb->items[0][j].toDownsampleRight = ramAddr + DMEM_1CH_SIZE / SAMPLE_SIZE; - ramAddr = AudioHeap_AllocZeroedAttemptExternal(&gAudioContext.miscPool, DMEM_2CH_SIZE); + ramAddr = AudioHeap_AllocZeroedAttemptExternal(&gAudioCtx.miscPool, DMEM_2CH_SIZE); reverb->items[1][j].toDownsampleLeft = ramAddr; reverb->items[1][j].toDownsampleRight = ramAddr + DMEM_1CH_SIZE / SAMPLE_SIZE; } @@ -1031,8 +1024,8 @@ void AudioHeap_Init(void) { if (settings->lowPassFilterCutoffLeft != 0) { reverb->filterLeftState = - AudioHeap_AllocDmaMemoryZeroed(&gAudioContext.miscPool, 2 * (FILTER_BUF_PART1 + FILTER_BUF_PART2)); - reverb->filterLeft = AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, FILTER_SIZE); + AudioHeap_AllocDmaMemoryZeroed(&gAudioCtx.miscPool, 2 * (FILTER_BUF_PART1 + FILTER_BUF_PART2)); + reverb->filterLeft = AudioHeap_AllocDmaMemory(&gAudioCtx.miscPool, FILTER_SIZE); AudioHeap_LoadLowPassFilter(reverb->filterLeft, settings->lowPassFilterCutoffLeft); } else { reverb->filterLeft = NULL; @@ -1040,8 +1033,8 @@ void AudioHeap_Init(void) { if (settings->lowPassFilterCutoffRight != 0) { reverb->filterRightState = - AudioHeap_AllocDmaMemoryZeroed(&gAudioContext.miscPool, 2 * (FILTER_BUF_PART1 + FILTER_BUF_PART2)); - reverb->filterRight = AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, FILTER_SIZE); + AudioHeap_AllocDmaMemoryZeroed(&gAudioCtx.miscPool, 2 * (FILTER_BUF_PART1 + FILTER_BUF_PART2)); + reverb->filterRight = AudioHeap_AllocDmaMemory(&gAudioCtx.miscPool, FILTER_SIZE); AudioHeap_LoadLowPassFilter(reverb->filterRight, settings->lowPassFilterCutoffRight); } else { reverb->filterRight = NULL; @@ -1050,21 +1043,21 @@ void AudioHeap_Init(void) { // Initialize sequence players AudioSeq_InitSequencePlayers(); - for (j = 0; j < gAudioContext.audioBufferParameters.numSequencePlayers; j++) { + for (j = 0; j < gAudioCtx.audioBufferParameters.numSequencePlayers; j++) { AudioSeq_InitSequencePlayerChannels(j); - AudioSeq_ResetSequencePlayer(&gAudioContext.seqPlayers[j]); + AudioSeq_ResetSequencePlayer(&gAudioCtx.seqPlayers[j]); } // Initialize two additional sample caches for individual samples AudioHeap_InitSampleCaches(spec->persistentSampleCacheSize, spec->temporarySampleCacheSize); - AudioLoad_InitSampleDmaBuffers(gAudioContext.numNotes); + AudioLoad_InitSampleDmaBuffers(gAudioCtx.numNotes); // Initialize Loads - gAudioContext.preloadSampleStackTop = 0; + gAudioCtx.preloadSampleStackTop = 0; AudioLoad_InitSlowLoads(); AudioLoad_InitScriptLoads(); AudioLoad_InitAsyncLoads(); - gAudioContext.unk_4 = 0x1000; + gAudioCtx.unk_4 = 0x1000; AudioLoad_LoadPermanentSamples(); intMask = osSetIntMask(OS_IM_NONE); @@ -1075,9 +1068,9 @@ void AudioHeap_Init(void) { void* AudioHeap_SearchPermanentCache(s32 tableType, s32 id) { s32 i; - for (i = 0; i < gAudioContext.permanentPool.numEntries; i++) { - if (gAudioContext.permanentCache[i].tableType == tableType && gAudioContext.permanentCache[i].id == id) { - return gAudioContext.permanentCache[i].ramAddr; + for (i = 0; i < gAudioCtx.permanentPool.numEntries; i++) { + if (gAudioCtx.permanentCache[i].tableType == tableType && gAudioCtx.permanentCache[i].id == id) { + return gAudioCtx.permanentCache[i].ramAddr; } } return NULL; @@ -1085,16 +1078,16 @@ void* AudioHeap_SearchPermanentCache(s32 tableType, s32 id) { void* AudioHeap_AllocPermanent(s32 tableType, s32 id, u32 size) { void* ramAddr; - s32 index = gAudioContext.permanentPool.numEntries; + s32 index = gAudioCtx.permanentPool.numEntries; - ramAddr = AudioHeap_Alloc(&gAudioContext.permanentPool, size); - gAudioContext.permanentCache[index].ramAddr = ramAddr; + ramAddr = AudioHeap_Alloc(&gAudioCtx.permanentPool, size); + gAudioCtx.permanentCache[index].ramAddr = ramAddr; if (ramAddr == NULL) { return NULL; } - gAudioContext.permanentCache[index].tableType = tableType; - gAudioContext.permanentCache[index].id = id; - gAudioContext.permanentCache[index].size = size; + gAudioCtx.permanentCache[index].tableType = tableType; + gAudioCtx.permanentCache[index].id = id; + gAudioCtx.permanentCache[index].size = size; //! @bug UB: missing return. "ramAddr" is in v0 at this point, but doing an //! explicit return uses an additional register. @@ -1128,20 +1121,20 @@ void* AudioHeap_AllocSampleCache(u32 size, s32 fontId, void* sampleAddr, s8 medi void AudioHeap_InitSampleCaches(u32 persistentSampleCacheSize, u32 temporarySampleCacheSize) { void* ramAddr; - ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.miscPool, persistentSampleCacheSize); + ramAddr = AudioHeap_AllocAttemptExternal(&gAudioCtx.miscPool, persistentSampleCacheSize); if (ramAddr == NULL) { - gAudioContext.persistentSampleCache.pool.size = 0; + gAudioCtx.persistentSampleCache.pool.size = 0; } else { - AudioHeap_InitPool(&gAudioContext.persistentSampleCache.pool, ramAddr, persistentSampleCacheSize); + AudioHeap_InitPool(&gAudioCtx.persistentSampleCache.pool, ramAddr, persistentSampleCacheSize); } - ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.miscPool, temporarySampleCacheSize); + ramAddr = AudioHeap_AllocAttemptExternal(&gAudioCtx.miscPool, temporarySampleCacheSize); if (ramAddr == NULL) { - gAudioContext.temporarySampleCache.pool.size = 0; + gAudioCtx.temporarySampleCache.pool.size = 0; } else { - AudioHeap_InitPool(&gAudioContext.temporarySampleCache.pool, ramAddr, temporarySampleCacheSize); + AudioHeap_InitPool(&gAudioCtx.temporarySampleCache.pool, ramAddr, temporarySampleCacheSize); } - gAudioContext.persistentSampleCache.numEntries = 0; - gAudioContext.temporarySampleCache.numEntries = 0; + gAudioCtx.persistentSampleCache.numEntries = 0; + gAudioCtx.temporarySampleCache.numEntries = 0; } SampleCacheEntry* AudioHeap_AllocTemporarySampleCacheEntry(u32 size) { @@ -1156,7 +1149,7 @@ SampleCacheEntry* AudioHeap_AllocTemporarySampleCacheEntry(u32 size) { u8* startRamAddr; u8* endRamAddr; - cache = &gAudioContext.temporarySampleCache; + cache = &gAudioCtx.temporarySampleCache; allocBefore = cache->pool.curRamAddr; ramAddr = AudioHeap_Alloc(&cache->pool, size); if (ramAddr == NULL) { @@ -1177,8 +1170,8 @@ SampleCacheEntry* AudioHeap_AllocTemporarySampleCacheEntry(u32 size) { allocAfter = cache->pool.curRamAddr; index = -1; - for (i = 0; i < gAudioContext.preloadSampleStackTop; i++) { - preload = &gAudioContext.preloadSampleStack[i]; + for (i = 0; i < gAudioCtx.preloadSampleStackTop; i++) { + preload = &gAudioCtx.preloadSampleStack[i]; if (preload->isFree == false) { startRamAddr = preload->ramAddr; endRamAddr = preload->ramAddr + preload->sample->size - 1; @@ -1237,7 +1230,7 @@ void AudioHeap_UnapplySampleCacheForFont(SampleCacheEntry* entry, s32 fontId) { s32 drumId; s32 sfxId; - for (instId = 0; instId < gAudioContext.soundFontList[fontId].numInstruments; instId++) { + for (instId = 0; instId < gAudioCtx.soundFontList[fontId].numInstruments; instId++) { inst = Audio_GetInstrumentInner(fontId, instId); if (inst != NULL) { if (inst->normalRangeLo != 0) { @@ -1250,14 +1243,14 @@ void AudioHeap_UnapplySampleCacheForFont(SampleCacheEntry* entry, s32 fontId) { } } - for (drumId = 0; drumId < gAudioContext.soundFontList[fontId].numDrums; drumId++) { + for (drumId = 0; drumId < gAudioCtx.soundFontList[fontId].numDrums; drumId++) { drum = Audio_GetDrum(fontId, drumId); if (drum != NULL) { AudioHeap_UnapplySampleCache(entry, drum->tunedSample.sample); } } - for (sfxId = 0; sfxId < gAudioContext.soundFontList[fontId].numSfx; sfxId++) { + for (sfxId = 0; sfxId < gAudioCtx.soundFontList[fontId].numSfx; sfxId++) { soundEffect = Audio_GetSoundEffect(fontId, sfxId); if (soundEffect != NULL) { AudioHeap_UnapplySampleCache(entry, soundEffect->tunedSample.sample); @@ -1271,10 +1264,10 @@ void AudioHeap_DiscardSampleCacheEntry(SampleCacheEntry* entry) { s32 sampleBankId2; s32 fontId; - numFonts = gAudioContext.soundFontTable->numEntries; + numFonts = gAudioCtx.soundFontTable->numEntries; for (fontId = 0; fontId < numFonts; fontId++) { - sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1; + sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2; if (((sampleBankId1 != 0xFF) && (entry->sampleBankId == sampleBankId1)) || ((sampleBankId2 != 0xFF) && (entry->sampleBankId == sampleBankId2)) || entry->sampleBankId == 0) { if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, fontId) != NULL) { @@ -1300,7 +1293,7 @@ SampleCacheEntry* AudioHeap_AllocPersistentSampleCacheEntry(u32 size) { SampleCacheEntry* entry; void* ramAddr; - cache = &gAudioContext.persistentSampleCache; + cache = &gAudioCtx.persistentSampleCache; ramAddr = AudioHeap_Alloc(&cache->pool, size); if (ramAddr == NULL) { return NULL; @@ -1328,10 +1321,10 @@ void AudioHeap_DiscardSampleCaches(void) { s32 fontId; s32 j; - numFonts = gAudioContext.soundFontTable->numEntries; + numFonts = gAudioCtx.soundFontTable->numEntries; for (fontId = 0; fontId < numFonts; fontId++) { - sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1; + sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2; if ((sampleBankId1 == 0xFF) && (sampleBankId2 == 0xFF)) { continue; } @@ -1340,12 +1333,12 @@ void AudioHeap_DiscardSampleCaches(void) { continue; } - for (j = 0; j < gAudioContext.persistentSampleCache.numEntries; j++) { - AudioHeap_DiscardSampleCacheForFont(&gAudioContext.persistentSampleCache.entries[j], sampleBankId1, + for (j = 0; j < gAudioCtx.persistentSampleCache.numEntries; j++) { + AudioHeap_DiscardSampleCacheForFont(&gAudioCtx.persistentSampleCache.entries[j], sampleBankId1, sampleBankId2, fontId); } - for (j = 0; j < gAudioContext.temporarySampleCache.numEntries; j++) { - AudioHeap_DiscardSampleCacheForFont(&gAudioContext.temporarySampleCache.entries[j], sampleBankId1, + for (j = 0; j < gAudioCtx.temporarySampleCache.numEntries; j++) { + AudioHeap_DiscardSampleCacheForFont(&gAudioCtx.temporarySampleCache.entries[j], sampleBankId1, sampleBankId2, fontId); } } @@ -1397,8 +1390,8 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) { u32* fakematch; s32 pad[4]; - sampleBankTable = gAudioContext.sampleBankTable; - numFonts = gAudioContext.soundFontTable->numEntries; + sampleBankTable = gAudioCtx.sampleBankTable; + numFonts = gAudioCtx.soundFontTable->numEntries; change.oldAddr = (u32)AudioHeap_SearchCaches(SAMPLE_TABLE, CACHE_EITHER, sampleBankId); if (change.oldAddr == 0) { return; @@ -1424,8 +1417,8 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) { } for (fontId = 0; fontId < numFonts; fontId++) { - sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1; + sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2; if ((sampleBankId1 != 0xFF) || (sampleBankId2 != 0xFF)) { if (!AudioLoad_IsFontLoadComplete(fontId) || AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, fontId) == NULL) { @@ -1438,7 +1431,7 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) { continue; } - for (instId = 0; instId < gAudioContext.soundFontList[fontId].numInstruments; instId++) { + for (instId = 0; instId < gAudioCtx.soundFontList[fontId].numInstruments; instId++) { inst = Audio_GetInstrumentInner(fontId, instId); if (inst != NULL) { if (inst->normalRangeLo != 0) { @@ -1451,14 +1444,14 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) { } } - for (drumId = 0; drumId < gAudioContext.soundFontList[fontId].numDrums; drumId++) { + for (drumId = 0; drumId < gAudioCtx.soundFontList[fontId].numDrums; drumId++) { drum = Audio_GetDrum(fontId, drumId); if (drum != NULL) { AudioHeap_ChangeStorage(&change, drum->tunedSample.sample); } } - for (sfxId = 0; sfxId < gAudioContext.soundFontList[fontId].numSfx; sfxId++) { + for (sfxId = 0; sfxId < gAudioCtx.soundFontList[fontId].numSfx; sfxId++) { soundEffect = Audio_GetSoundEffect(fontId, sfxId); if (soundEffect != NULL) { AudioHeap_ChangeStorage(&change, soundEffect->tunedSample.sample); @@ -1474,7 +1467,7 @@ void AudioHeap_DiscardSampleBanks(void) { AudioTemporaryCache* temporary; u32 i; - cache = &gAudioContext.sampleBankCache; + cache = &gAudioCtx.sampleBankCache; temporary = &cache->temporary; if (temporary->entries[0].id != -1) { diff --git a/src/code/audio_init_params.c b/src/code/audio_init_params.c index 28ccec031e..56b8999930 100644 --- a/src/code/audio_init_params.c +++ b/src/code/audio_init_params.c @@ -1,7 +1,7 @@ #include "global.h" u8 D_8016F0E0[0xA0]; // unused -AudioContext gAudioContext; +AudioContext gAudioCtx; void (*D_801755D0)(void); s32 D_801755D8[3]; // unused @@ -17,7 +17,7 @@ const s16 D_8014A6C0[] = { #define SFX_SOUNDFONT_2_SIZE 0x17B0 // Sizes of everything on the init pool -#define AI_BUFFERS_SIZE (AIBUF_SIZE * ARRAY_COUNT(gAudioContext.aiBuffers)) +#define AI_BUFFERS_SIZE (AIBUF_SIZE * ARRAY_COUNT(gAudioCtx.aiBuffers)) #define SOUNDFONT_LIST_SIZE (NUM_SOUNDFONTS * sizeof(SoundFont)) #define PERMANENT_POOL_SIZE (SFX_SEQ_SIZE + SFX_SOUNDFONT_1_SIZE + SFX_SOUNDFONT_2_SIZE) diff --git a/src/code/audio_load.c b/src/code/audio_load.c index c234538f34..b32b47963e 100644 --- a/src/code/audio_load.c +++ b/src/code/audio_load.c @@ -75,33 +75,33 @@ s32 gAudioContextInitialized = false; void AudioLoad_DecreaseSampleDmaTtls(void) { u32 i; - for (i = 0; i < gAudioContext.sampleDmaListSize1; i++) { - SampleDma* dma = &gAudioContext.sampleDmas[i]; + for (i = 0; i < gAudioCtx.sampleDmaListSize1; i++) { + SampleDma* dma = &gAudioCtx.sampleDmas[i]; if (dma->ttl != 0) { dma->ttl--; if (dma->ttl == 0) { - dma->reuseIndex = gAudioContext.sampleDmaReuseQueue1WrPos; - gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1WrPos] = i; - gAudioContext.sampleDmaReuseQueue1WrPos++; + dma->reuseIndex = gAudioCtx.sampleDmaReuseQueue1WrPos; + gAudioCtx.sampleDmaReuseQueue1[gAudioCtx.sampleDmaReuseQueue1WrPos] = i; + gAudioCtx.sampleDmaReuseQueue1WrPos++; } } } - for (i = gAudioContext.sampleDmaListSize1; i < gAudioContext.sampleDmaCount; i++) { - SampleDma* dma = &gAudioContext.sampleDmas[i]; + for (i = gAudioCtx.sampleDmaListSize1; i < gAudioCtx.sampleDmaCount; i++) { + SampleDma* dma = &gAudioCtx.sampleDmas[i]; if (dma->ttl != 0) { dma->ttl--; if (dma->ttl == 0) { - dma->reuseIndex = gAudioContext.sampleDmaReuseQueue2WrPos; - gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2WrPos] = i; - gAudioContext.sampleDmaReuseQueue2WrPos++; + dma->reuseIndex = gAudioCtx.sampleDmaReuseQueue2WrPos; + gAudioCtx.sampleDmaReuseQueue2[gAudioCtx.sampleDmaReuseQueue2WrPos] = i; + gAudioCtx.sampleDmaReuseQueue2WrPos++; } } } - gAudioContext.unused2628 = 0; + gAudioCtx.unused2628 = 0; } void* AudioLoad_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, s32 medium) { @@ -115,24 +115,22 @@ void* AudioLoad_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, s32 bufferPos; u32 i; - if (arg2 != 0 || *dmaIndexRef >= gAudioContext.sampleDmaListSize1) { - for (i = gAudioContext.sampleDmaListSize1; i < gAudioContext.sampleDmaCount; i++) { - dma = &gAudioContext.sampleDmas[i]; + if (arg2 != 0 || *dmaIndexRef >= gAudioCtx.sampleDmaListSize1) { + for (i = gAudioCtx.sampleDmaListSize1; i < gAudioCtx.sampleDmaCount; i++) { + dma = &gAudioCtx.sampleDmas[i]; bufferPos = devAddr - dma->devAddr; if (0 <= bufferPos && (u32)bufferPos <= dma->size - size) { // We already have a DMA request for this memory range. - if (dma->ttl == 0 && - gAudioContext.sampleDmaReuseQueue2RdPos != gAudioContext.sampleDmaReuseQueue2WrPos) { + if (dma->ttl == 0 && gAudioCtx.sampleDmaReuseQueue2RdPos != gAudioCtx.sampleDmaReuseQueue2WrPos) { // Move the DMA out of the reuse queue, by swapping it with the // read pos, and then incrementing the read pos. - if (dma->reuseIndex != gAudioContext.sampleDmaReuseQueue2RdPos) { - gAudioContext.sampleDmaReuseQueue2[dma->reuseIndex] = - gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2RdPos]; - gAudioContext - .sampleDmas[gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2RdPos]] + if (dma->reuseIndex != gAudioCtx.sampleDmaReuseQueue2RdPos) { + gAudioCtx.sampleDmaReuseQueue2[dma->reuseIndex] = + gAudioCtx.sampleDmaReuseQueue2[gAudioCtx.sampleDmaReuseQueue2RdPos]; + gAudioCtx.sampleDmas[gAudioCtx.sampleDmaReuseQueue2[gAudioCtx.sampleDmaReuseQueue2RdPos]] .reuseIndex = dma->reuseIndex; } - gAudioContext.sampleDmaReuseQueue2RdPos++; + gAudioCtx.sampleDmaReuseQueue2RdPos++; } dma->ttl = 32; *dmaIndexRef = (u8)i; @@ -144,16 +142,16 @@ void* AudioLoad_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, goto search_short_lived; } - if (gAudioContext.sampleDmaReuseQueue2RdPos != gAudioContext.sampleDmaReuseQueue2WrPos && arg2 != 0) { + if (gAudioCtx.sampleDmaReuseQueue2RdPos != gAudioCtx.sampleDmaReuseQueue2WrPos && arg2 != 0) { // Allocate a DMA from reuse queue 2, unless full. - dmaIndex = gAudioContext.sampleDmaReuseQueue2[gAudioContext.sampleDmaReuseQueue2RdPos]; - gAudioContext.sampleDmaReuseQueue2RdPos++; - dma = gAudioContext.sampleDmas + dmaIndex; + dmaIndex = gAudioCtx.sampleDmaReuseQueue2[gAudioCtx.sampleDmaReuseQueue2RdPos]; + gAudioCtx.sampleDmaReuseQueue2RdPos++; + dma = gAudioCtx.sampleDmas + dmaIndex; hasDma = true; } } else { search_short_lived: - dma = gAudioContext.sampleDmas + *dmaIndexRef; + dma = gAudioCtx.sampleDmas + *dmaIndexRef; i = 0; again: bufferPos = devAddr - dma->devAddr; @@ -162,31 +160,30 @@ void* AudioLoad_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, if (dma->ttl == 0) { // Move the DMA out of the reuse queue, by swapping it with the // read pos, and then incrementing the read pos. - if (dma->reuseIndex != gAudioContext.sampleDmaReuseQueue1RdPos) { - gAudioContext.sampleDmaReuseQueue1[dma->reuseIndex] = - gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1RdPos]; - gAudioContext - .sampleDmas[gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1RdPos]] + if (dma->reuseIndex != gAudioCtx.sampleDmaReuseQueue1RdPos) { + gAudioCtx.sampleDmaReuseQueue1[dma->reuseIndex] = + gAudioCtx.sampleDmaReuseQueue1[gAudioCtx.sampleDmaReuseQueue1RdPos]; + gAudioCtx.sampleDmas[gAudioCtx.sampleDmaReuseQueue1[gAudioCtx.sampleDmaReuseQueue1RdPos]] .reuseIndex = dma->reuseIndex; } - gAudioContext.sampleDmaReuseQueue1RdPos++; + gAudioCtx.sampleDmaReuseQueue1RdPos++; } dma->ttl = 2; return dma->ramAddr + (devAddr - dma->devAddr); } - dma = gAudioContext.sampleDmas + i++; - if (i <= gAudioContext.sampleDmaListSize1) { + dma = gAudioCtx.sampleDmas + i++; + if (i <= gAudioCtx.sampleDmaListSize1) { goto again; } } if (!hasDma) { - if (gAudioContext.sampleDmaReuseQueue1RdPos == gAudioContext.sampleDmaReuseQueue1WrPos) { + if (gAudioCtx.sampleDmaReuseQueue1RdPos == gAudioCtx.sampleDmaReuseQueue1WrPos) { return NULL; } // Allocate a DMA from reuse queue 1. - dmaIndex = gAudioContext.sampleDmaReuseQueue1[gAudioContext.sampleDmaReuseQueue1RdPos++]; - dma = gAudioContext.sampleDmas + dmaIndex; + dmaIndex = gAudioCtx.sampleDmaReuseQueue1[gAudioCtx.sampleDmaReuseQueue1RdPos++]; + dma = gAudioCtx.sampleDmas + dmaIndex; hasDma = true; } @@ -195,9 +192,8 @@ void* AudioLoad_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, dma->ttl = 3; dma->devAddr = dmaDevAddr; dma->sizeUnused = transfer; - AudioLoad_Dma(&gAudioContext.currAudioFrameDmaIoMsgBuf[gAudioContext.curAudioFrameDmaCount++], OS_MESG_PRI_NORMAL, - OS_READ, dmaDevAddr, dma->ramAddr, transfer, &gAudioContext.currAudioFrameDmaQueue, medium, - "SUPERDMA"); + AudioLoad_Dma(&gAudioCtx.currAudioFrameDmaIoMsgBuf[gAudioCtx.curAudioFrameDmaCount++], OS_MESG_PRI_NORMAL, OS_READ, + dmaDevAddr, dma->ramAddr, transfer, &gAudioCtx.currAudioFrameDmaQueue, medium, "SUPERDMA"); *dmaIndexRef = dmaIndex; return (devAddr - dmaDevAddr) + dma->ramAddr; } @@ -208,76 +204,75 @@ void AudioLoad_InitSampleDmaBuffers(s32 numNotes) { s32 t2; s32 j; - gAudioContext.sampleDmaBufSize = gAudioContext.sampleDmaBufSize1; - gAudioContext.sampleDmas = - AudioHeap_Alloc(&gAudioContext.miscPool, - 4 * gAudioContext.numNotes * sizeof(SampleDma) * gAudioContext.audioBufferParameters.specUnk4); - t2 = 3 * gAudioContext.numNotes * gAudioContext.audioBufferParameters.specUnk4; + gAudioCtx.sampleDmaBufSize = gAudioCtx.sampleDmaBufSize1; + gAudioCtx.sampleDmas = AudioHeap_Alloc(&gAudioCtx.miscPool, 4 * gAudioCtx.numNotes * sizeof(SampleDma) * + gAudioCtx.audioBufferParameters.specUnk4); + t2 = 3 * gAudioCtx.numNotes * gAudioCtx.audioBufferParameters.specUnk4; for (i = 0; i < t2; i++) { - dma = &gAudioContext.sampleDmas[gAudioContext.sampleDmaCount]; - dma->ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.miscPool, gAudioContext.sampleDmaBufSize); + dma = &gAudioCtx.sampleDmas[gAudioCtx.sampleDmaCount]; + dma->ramAddr = AudioHeap_AllocAttemptExternal(&gAudioCtx.miscPool, gAudioCtx.sampleDmaBufSize); if (dma->ramAddr == NULL) { break; } else { - AudioHeap_WritebackDCache(dma->ramAddr, gAudioContext.sampleDmaBufSize); - dma->size = gAudioContext.sampleDmaBufSize; + AudioHeap_WritebackDCache(dma->ramAddr, gAudioCtx.sampleDmaBufSize); + dma->size = gAudioCtx.sampleDmaBufSize; dma->devAddr = 0; dma->sizeUnused = 0; dma->unused = 0; dma->ttl = 0; - gAudioContext.sampleDmaCount++; + gAudioCtx.sampleDmaCount++; } } - for (i = 0; (u32)i < gAudioContext.sampleDmaCount; i++) { - gAudioContext.sampleDmaReuseQueue1[i] = i; - gAudioContext.sampleDmas[i].reuseIndex = i; + for (i = 0; (u32)i < gAudioCtx.sampleDmaCount; i++) { + gAudioCtx.sampleDmaReuseQueue1[i] = i; + gAudioCtx.sampleDmas[i].reuseIndex = i; } - for (i = gAudioContext.sampleDmaCount; i < 0x100; i++) { - gAudioContext.sampleDmaReuseQueue1[i] = 0; + for (i = gAudioCtx.sampleDmaCount; i < 0x100; i++) { + gAudioCtx.sampleDmaReuseQueue1[i] = 0; } - gAudioContext.sampleDmaReuseQueue1RdPos = 0; - gAudioContext.sampleDmaReuseQueue1WrPos = gAudioContext.sampleDmaCount; - gAudioContext.sampleDmaListSize1 = gAudioContext.sampleDmaCount; - gAudioContext.sampleDmaBufSize = gAudioContext.sampleDmaBufSize2; + gAudioCtx.sampleDmaReuseQueue1RdPos = 0; + gAudioCtx.sampleDmaReuseQueue1WrPos = gAudioCtx.sampleDmaCount; + gAudioCtx.sampleDmaListSize1 = gAudioCtx.sampleDmaCount; + gAudioCtx.sampleDmaBufSize = gAudioCtx.sampleDmaBufSize2; - for (j = 0; j < gAudioContext.numNotes; j++) { - dma = &gAudioContext.sampleDmas[gAudioContext.sampleDmaCount]; - dma->ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.miscPool, gAudioContext.sampleDmaBufSize); + for (j = 0; j < gAudioCtx.numNotes; j++) { + dma = &gAudioCtx.sampleDmas[gAudioCtx.sampleDmaCount]; + dma->ramAddr = AudioHeap_AllocAttemptExternal(&gAudioCtx.miscPool, gAudioCtx.sampleDmaBufSize); if (dma->ramAddr == NULL) { break; } else { - AudioHeap_WritebackDCache(dma->ramAddr, gAudioContext.sampleDmaBufSize); - dma->size = gAudioContext.sampleDmaBufSize; + AudioHeap_WritebackDCache(dma->ramAddr, gAudioCtx.sampleDmaBufSize); + dma->size = gAudioCtx.sampleDmaBufSize; dma->devAddr = 0U; dma->sizeUnused = 0; dma->unused = 0; dma->ttl = 0; - gAudioContext.sampleDmaCount++; + gAudioCtx.sampleDmaCount++; } } - for (i = gAudioContext.sampleDmaListSize1; (u32)i < gAudioContext.sampleDmaCount; i++) { - gAudioContext.sampleDmaReuseQueue2[i - gAudioContext.sampleDmaListSize1] = i; - gAudioContext.sampleDmas[i].reuseIndex = i - gAudioContext.sampleDmaListSize1; + for (i = gAudioCtx.sampleDmaListSize1; (u32)i < gAudioCtx.sampleDmaCount; i++) { + gAudioCtx.sampleDmaReuseQueue2[i - gAudioCtx.sampleDmaListSize1] = i; + gAudioCtx.sampleDmas[i].reuseIndex = i - gAudioCtx.sampleDmaListSize1; } - for (i = gAudioContext.sampleDmaCount; i < 0x100; i++) { - gAudioContext.sampleDmaReuseQueue2[i] = gAudioContext.sampleDmaListSize1; + for (i = gAudioCtx.sampleDmaCount; i < 0x100; i++) { + gAudioCtx.sampleDmaReuseQueue2[i] = gAudioCtx.sampleDmaListSize1; } - gAudioContext.sampleDmaReuseQueue2RdPos = 0; - gAudioContext.sampleDmaReuseQueue2WrPos = gAudioContext.sampleDmaCount - gAudioContext.sampleDmaListSize1; + gAudioCtx.sampleDmaReuseQueue2RdPos = 0; + gAudioCtx.sampleDmaReuseQueue2WrPos = gAudioCtx.sampleDmaCount - gAudioCtx.sampleDmaListSize1; } s32 AudioLoad_IsFontLoadComplete(s32 fontId) { if (fontId == 0xFF) { return true; - } else if (gAudioContext.fontLoadStatus[fontId] >= LOAD_STATUS_COMPLETE) { + } else if (gAudioCtx.fontLoadStatus[fontId] >= LOAD_STATUS_COMPLETE) { return true; - } else if (gAudioContext.fontLoadStatus[AudioLoad_GetRealTableIndex(FONT_TABLE, fontId)] >= LOAD_STATUS_COMPLETE) { + } else if (gAudioCtx.fontLoadStatus[AudioLoad_GetRealTableIndex(FONT_TABLE, fontId)] >= LOAD_STATUS_COMPLETE) { return true; } else { return false; @@ -287,10 +282,9 @@ s32 AudioLoad_IsFontLoadComplete(s32 fontId) { s32 AudioLoad_IsSeqLoadComplete(s32 seqId) { if (seqId == 0xFF) { return true; - } else if (gAudioContext.seqLoadStatus[seqId] >= LOAD_STATUS_COMPLETE) { + } else if (gAudioCtx.seqLoadStatus[seqId] >= LOAD_STATUS_COMPLETE) { return true; - } else if (gAudioContext.seqLoadStatus[AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId)] >= - LOAD_STATUS_COMPLETE) { + } else if (gAudioCtx.seqLoadStatus[AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId)] >= LOAD_STATUS_COMPLETE) { return true; } else { return false; @@ -300,9 +294,9 @@ s32 AudioLoad_IsSeqLoadComplete(s32 seqId) { s32 AudioLoad_IsSampleLoadComplete(s32 sampleBankId) { if (sampleBankId == 0xFF) { return true; - } else if (gAudioContext.sampleFontLoadStatus[sampleBankId] >= LOAD_STATUS_COMPLETE) { + } else if (gAudioCtx.sampleFontLoadStatus[sampleBankId] >= LOAD_STATUS_COMPLETE) { return true; - } else if (gAudioContext.sampleFontLoadStatus[AudioLoad_GetRealTableIndex(SAMPLE_TABLE, sampleBankId)] >= + } else if (gAudioCtx.sampleFontLoadStatus[AudioLoad_GetRealTableIndex(SAMPLE_TABLE, sampleBankId)] >= LOAD_STATUS_COMPLETE) { return true; } else { @@ -311,34 +305,33 @@ s32 AudioLoad_IsSampleLoadComplete(s32 sampleBankId) { } void AudioLoad_SetFontLoadStatus(s32 fontId, s32 loadStatus) { - if ((fontId != 0xFF) && (gAudioContext.fontLoadStatus[fontId] != LOAD_STATUS_PERMANENTLY_LOADED)) { - gAudioContext.fontLoadStatus[fontId] = loadStatus; + if ((fontId != 0xFF) && (gAudioCtx.fontLoadStatus[fontId] != LOAD_STATUS_PERMANENTLY_LOADED)) { + gAudioCtx.fontLoadStatus[fontId] = loadStatus; } } void AudioLoad_SetSeqLoadStatus(s32 seqId, s32 loadStatus) { - if ((seqId != 0xFF) && (gAudioContext.seqLoadStatus[seqId] != LOAD_STATUS_PERMANENTLY_LOADED)) { - gAudioContext.seqLoadStatus[seqId] = loadStatus; + if ((seqId != 0xFF) && (gAudioCtx.seqLoadStatus[seqId] != LOAD_STATUS_PERMANENTLY_LOADED)) { + gAudioCtx.seqLoadStatus[seqId] = loadStatus; } } void AudioLoad_SetSampleFontLoadStatusAndApplyCaches(s32 sampleBankId, s32 loadStatus) { if (sampleBankId != 0xFF) { - if (gAudioContext.sampleFontLoadStatus[sampleBankId] != LOAD_STATUS_PERMANENTLY_LOADED) { - gAudioContext.sampleFontLoadStatus[sampleBankId] = loadStatus; + if (gAudioCtx.sampleFontLoadStatus[sampleBankId] != LOAD_STATUS_PERMANENTLY_LOADED) { + gAudioCtx.sampleFontLoadStatus[sampleBankId] = loadStatus; } - if ((gAudioContext.sampleFontLoadStatus[sampleBankId] == LOAD_STATUS_PERMANENTLY_LOADED) || - (gAudioContext.sampleFontLoadStatus[sampleBankId] == LOAD_STATUS_COMPLETE)) { + if ((gAudioCtx.sampleFontLoadStatus[sampleBankId] == LOAD_STATUS_PERMANENTLY_LOADED) || + (gAudioCtx.sampleFontLoadStatus[sampleBankId] == LOAD_STATUS_COMPLETE)) { AudioHeap_ApplySampleBankCache(sampleBankId); } } } void AudioLoad_SetSampleFontLoadStatus(s32 sampleBankId, s32 loadStatus) { - if ((sampleBankId != 0xFF) && - (gAudioContext.sampleFontLoadStatus[sampleBankId] != LOAD_STATUS_PERMANENTLY_LOADED)) { - gAudioContext.sampleFontLoadStatus[sampleBankId] = loadStatus; + if ((sampleBankId != 0xFF) && (gAudioCtx.sampleFontLoadStatus[sampleBankId] != LOAD_STATUS_PERMANENTLY_LOADED)) { + gAudioCtx.sampleFontLoadStatus[sampleBankId] = loadStatus; } } @@ -363,16 +356,16 @@ SoundFontData* AudioLoad_SyncLoadSeqFonts(s32 seqId, u32* outDefaultFontId) { s32 fontId; s32 i; - if (seqId >= gAudioContext.numSequences) { + if (seqId >= gAudioCtx.numSequences) { return NULL; } fontId = 0xFF; - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; - numFonts = gAudioContext.sequenceFontTable[index++]; + index = ((u16*)gAudioCtx.sequenceFontTable)[seqId]; + numFonts = gAudioCtx.sequenceFontTable[index++]; while (numFonts > 0) { - fontId = gAudioContext.sequenceFontTable[index++]; + fontId = gAudioCtx.sequenceFontTable[index++]; fontData = AudioLoad_SyncLoadFont(fontId); numFonts--; } @@ -385,7 +378,7 @@ void AudioLoad_SyncLoadSeqParts(s32 seqId, s32 arg1) { s32 pad; u32 defaultFontId; - if (seqId < gAudioContext.numSequences) { + if (seqId < gAudioCtx.numSequences) { if (arg1 & 2) { AudioLoad_SyncLoadSeqFonts(seqId, &defaultFontId); } @@ -408,7 +401,7 @@ s32 AudioLoad_SyncLoadSample(Sample* sample, s32 fontId) { if (sample->medium == MEDIUM_UNK) { AudioLoad_SyncDmaUnkMedium((u32)sample->sampleAddr, sampleAddr, sample->size, - gAudioContext.sampleBankTable->unkMediumParam); + gAudioCtx.sampleBankTable->unkMediumParam); } else { AudioLoad_SyncDma((u32)sample->sampleAddr, sampleAddr, sample->size, sample->medium); } @@ -462,23 +455,23 @@ void AudioLoad_AsyncLoadFont(s32 fontId, s32 arg1, s32 retData, OSMesgQueue* ret } u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) { - s32 index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; + s32 index = ((u16*)gAudioCtx.sequenceFontTable)[seqId]; - *outNumFonts = gAudioContext.sequenceFontTable[index++]; + *outNumFonts = gAudioCtx.sequenceFontTable[index++]; if (*outNumFonts == 0) { return NULL; } - return &gAudioContext.sequenceFontTable[index]; + return &gAudioCtx.sequenceFontTable[index]; } void AudioLoad_DiscardSeqFonts(s32 seqId) { s32 fontId; - s32 index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; - s32 numFonts = gAudioContext.sequenceFontTable[index++]; + s32 index = ((u16*)gAudioCtx.sequenceFontTable)[seqId]; + s32 numFonts = gAudioCtx.sequenceFontTable[index++]; while (numFonts > 0) { numFonts--; - fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.sequenceFontTable[index++]); + fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioCtx.sequenceFontTable[index++]); if (AudioHeap_SearchPermanentCache(FONT_TABLE, fontId) == NULL) { AudioLoad_DiscardFont(fontId); AudioLoad_SetFontLoadStatus(fontId, LOAD_STATUS_NOT_LOADED); @@ -488,7 +481,7 @@ void AudioLoad_DiscardSeqFonts(s32 seqId) { void AudioLoad_DiscardFont(s32 fontId) { u32 i; - AudioCache* pool = &gAudioContext.fontCache; + AudioCache* pool = &gAudioCtx.fontCache; AudioPersistentCache* persistent; if (fontId == pool->temporary.entries[0].id) { @@ -508,11 +501,11 @@ void AudioLoad_DiscardFont(s32 fontId) { } s32 AudioLoad_SyncInitSeqPlayer(s32 playerIdx, s32 seqId, s32 arg2) { - if (gAudioContext.resetTimer != 0) { + if (gAudioCtx.resetTimer != 0) { return 0; } - gAudioContext.seqPlayers[playerIdx].skipTicks = 0; + gAudioCtx.seqPlayers[playerIdx].skipTicks = 0; AudioLoad_SyncInitSeqPlayerInternal(playerIdx, seqId, arg2); // Intentionally missing return. Returning the result of the above function // call matches but is UB because it too is missing a return, and using the @@ -521,34 +514,34 @@ s32 AudioLoad_SyncInitSeqPlayer(s32 playerIdx, s32 seqId, s32 arg2) { } s32 AudioLoad_SyncInitSeqPlayerSkipTicks(s32 playerIdx, s32 seqId, s32 skipTicks) { - if (gAudioContext.resetTimer != 0) { + if (gAudioCtx.resetTimer != 0) { return 0; } - gAudioContext.seqPlayers[playerIdx].skipTicks = skipTicks; + gAudioCtx.seqPlayers[playerIdx].skipTicks = skipTicks; AudioLoad_SyncInitSeqPlayerInternal(playerIdx, seqId, 0); // Missing return, see above. } s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) { - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx]; u8* seqData; s32 index; s32 numFonts; s32 fontId; - if (seqId >= gAudioContext.numSequences) { + if (seqId >= gAudioCtx.numSequences) { return 0; } AudioSeq_SequencePlayerDisable(seqPlayer); fontId = 0xFF; - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; - numFonts = gAudioContext.sequenceFontTable[index++]; + index = ((u16*)gAudioCtx.sequenceFontTable)[seqId]; + numFonts = gAudioCtx.sequenceFontTable[index++]; while (numFonts > 0) { - fontId = gAudioContext.sequenceFontTable[index++]; + fontId = gAudioCtx.sequenceFontTable[index++]; AudioLoad_SyncLoadFont(fontId); numFonts--; } @@ -576,7 +569,7 @@ u8* AudioLoad_SyncLoadSeq(s32 seqId) { s32 pad; s32 didAllocate; - if (gAudioContext.seqLoadStatus[AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId)] == LOAD_STATUS_IN_PROGRESS) { + if (gAudioCtx.seqLoadStatus[AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId)] == LOAD_STATUS_IN_PROGRESS) { return NULL; } @@ -596,7 +589,7 @@ u32 AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad sampleBankTable = AudioLoad_GetLoadTable(SAMPLE_TABLE); ramAddr = AudioLoad_SearchCaches(SAMPLE_TABLE, realTableId); if (ramAddr != NULL) { - if (gAudioContext.sampleFontLoadStatus[realTableId] != LOAD_STATUS_IN_PROGRESS) { + if (gAudioCtx.sampleFontLoadStatus[realTableId] != LOAD_STATUS_IN_PROGRESS) { AudioLoad_SetSampleFontLoadStatus(realTableId, LOAD_STATUS_COMPLETE); } *outMedium = MEDIUM_RAM; @@ -627,11 +620,11 @@ SoundFontData* AudioLoad_SyncLoadFont(u32 fontId) { SampleBankRelocInfo sampleBankReloc; s32 realFontId = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId); - if (gAudioContext.fontLoadStatus[realFontId] == LOAD_STATUS_IN_PROGRESS) { + if (gAudioCtx.fontLoadStatus[realFontId] == LOAD_STATUS_IN_PROGRESS) { return NULL; } - sampleBankId1 = gAudioContext.soundFontList[realFontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFontList[realFontId].sampleBankId2; + sampleBankId1 = gAudioCtx.soundFontList[realFontId].sampleBankId1; + sampleBankId2 = gAudioCtx.soundFontList[realFontId].sampleBankId2; sampleBankReloc.sampleBankId1 = sampleBankId1; sampleBankReloc.sampleBankId2 = sampleBankId2; @@ -773,11 +766,11 @@ AudioTable* AudioLoad_GetLoadTable(s32 tableType) { switch (tableType) { case SEQUENCE_TABLE: - table = gAudioContext.sequenceTable; + table = gAudioCtx.sequenceTable; break; case FONT_TABLE: - table = gAudioContext.soundFontTable; + table = gAudioCtx.soundFontTable; break; default: @@ -785,7 +778,7 @@ AudioTable* AudioLoad_GetLoadTable(s32 tableType) { break; case SAMPLE_TABLE: - table = gAudioContext.sampleBankTable; + table = gAudioCtx.sampleBankTable; break; } return table; @@ -806,9 +799,9 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample Drum* drum; SoundEffect* soundEffect; s32 i; - s32 numDrums = gAudioContext.soundFontList[fontId].numDrums; - s32 numInstruments = gAudioContext.soundFontList[fontId].numInstruments; - s32 numSfx = gAudioContext.soundFontList[fontId].numSfx; + s32 numDrums = gAudioCtx.soundFontList[fontId].numDrums; + s32 numInstruments = gAudioCtx.soundFontList[fontId].numInstruments; + s32 numSfx = gAudioCtx.soundFontList[fontId].numSfx; u32* fontData = (u32*)fontDataStartAddr; // Relocate an offset (relative to the start of the font data) to a pointer (a ram address) @@ -914,14 +907,14 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample #undef FONT_DATA_RELOC // Store the relocated pointers - gAudioContext.soundFontList[fontId].drums = (Drum**)fontData[0]; - gAudioContext.soundFontList[fontId].soundEffects = (SoundEffect*)fontData[1]; - gAudioContext.soundFontList[fontId].instruments = (Instrument**)(fontData + 2); + gAudioCtx.soundFontList[fontId].drums = (Drum**)fontData[0]; + gAudioCtx.soundFontList[fontId].soundEffects = (SoundEffect*)fontData[1]; + gAudioCtx.soundFontList[fontId].instruments = (Instrument**)(fontData + 2); } void AudioLoad_SyncDma(u32 devAddr, u8* ramAddr, u32 size, s32 medium) { - OSMesgQueue* msgQueue = &gAudioContext.syncDmaQueue; - OSIoMesg* ioMesg = &gAudioContext.syncDmaIoMesg; + OSMesgQueue* msgQueue = &gAudioCtx.syncDmaQueue; + OSIoMesg* ioMesg = &gAudioCtx.syncDmaIoMesg; size = ALIGN16(size); Audio_InvalDCache(ramAddr, size); @@ -950,19 +943,19 @@ s32 AudioLoad_Dma(OSIoMesg* mesg, u32 priority, s32 direction, u32 devAddr, void OSMesgQueue* reqQueue, s32 medium, const char* dmaFuncType) { OSPiHandle* handle; - if (gAudioContext.resetTimer > 16) { + if (gAudioCtx.resetTimer > 16) { return -1; } switch (medium) { case MEDIUM_CART: - handle = gAudioContext.cartHandle; + handle = gAudioCtx.cartHandle; break; case MEDIUM_DISK_DRIVE: // driveHandle is uninitialized and corresponds to stubbed-out disk drive support. // SM64 Shindou called osDriveRomInit here. - handle = gAudioContext.driveHandle; + handle = gAudioCtx.driveHandle; break; default: @@ -1005,19 +998,19 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData, switch (tableType) { case SEQUENCE_TABLE: - if (gAudioContext.seqLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) { + if (gAudioCtx.seqLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) { return NULL; } break; case FONT_TABLE: - if (gAudioContext.fontLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) { + if (gAudioCtx.fontLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) { return NULL; } break; case SAMPLE_TABLE: - if (gAudioContext.sampleFontLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) { + if (gAudioCtx.sampleFontLoadStatus[realId] == LOAD_STATUS_IN_PROGRESS) { return NULL; } break; @@ -1113,8 +1106,8 @@ void AudioLoad_SetUnusedHandler(void* callback) { } void AudioLoad_InitSoundFont(s32 fontId) { - SoundFont* font = &gAudioContext.soundFontList[fontId]; - AudioTableEntry* entry = &gAudioContext.soundFontTable->entries[fontId]; + SoundFont* font = &gAudioCtx.soundFontList[fontId]; + AudioTableEntry* entry = &gAudioCtx.soundFontTable->entries[fontId]; font->sampleBankId1 = (entry->shortData1 >> 8) & 0xFF; font->sampleBankId2 = (entry->shortData1) & 0xFF; @@ -1130,118 +1123,118 @@ void AudioLoad_Init(void* heap, u32 heapSize) { s32 i; D_801755D0 = NULL; - gAudioContext.resetTimer = 0; + gAudioCtx.resetTimer = 0; { s32 i; - u8* audioContextPtr = (u8*)&gAudioContext; + u8* audioContextPtr = (u8*)&gAudioCtx; - for (i = sizeof(gAudioContext); i >= 0; i--) { + for (i = sizeof(gAudioCtx); i >= 0; i--) { *audioContextPtr++ = 0; } } switch (osTvType) { case OS_TV_PAL: - gAudioContext.unk_2960 = 20.03042f; - gAudioContext.refreshRate = 50; + gAudioCtx.unk_2960 = 20.03042f; + gAudioCtx.refreshRate = 50; break; case OS_TV_MPAL: - gAudioContext.unk_2960 = 16.546f; - gAudioContext.refreshRate = 60; + gAudioCtx.unk_2960 = 16.546f; + gAudioCtx.refreshRate = 60; break; case OS_TV_NTSC: default: - gAudioContext.unk_2960 = 16.713f; - gAudioContext.refreshRate = 60; + gAudioCtx.unk_2960 = 16.713f; + gAudioCtx.refreshRate = 60; break; } Audio_InitMesgQueues(); for (i = 0; i < 3; i++) { - gAudioContext.aiBufLengths[i] = 0xA0; + gAudioCtx.aiBufLengths[i] = 0xA0; } - gAudioContext.totalTaskCount = 0; - gAudioContext.rspTaskIndex = 0; - gAudioContext.curAiBufIndex = 0; - gAudioContext.soundMode = SOUNDMODE_STEREO; - gAudioContext.curTask = NULL; - gAudioContext.rspTask[0].task.t.data_size = 0; - gAudioContext.rspTask[1].task.t.data_size = 0; - osCreateMesgQueue(&gAudioContext.syncDmaQueue, &gAudioContext.syncDmaMesg, 1); - osCreateMesgQueue(&gAudioContext.currAudioFrameDmaQueue, gAudioContext.currAudioFrameDmaMsgBuf, - ARRAY_COUNT(gAudioContext.currAudioFrameDmaMsgBuf)); - osCreateMesgQueue(&gAudioContext.externalLoadQueue, gAudioContext.externalLoadMsgBuf, - ARRAY_COUNT(gAudioContext.externalLoadMsgBuf)); - osCreateMesgQueue(&gAudioContext.preloadSampleQueue, gAudioContext.preloadSampleMsgBuf, - ARRAY_COUNT(gAudioContext.preloadSampleMsgBuf)); - gAudioContext.curAudioFrameDmaCount = 0; - gAudioContext.sampleDmaCount = 0; - gAudioContext.cartHandle = osCartRomInit(); + gAudioCtx.totalTaskCount = 0; + gAudioCtx.rspTaskIndex = 0; + gAudioCtx.curAiBufIndex = 0; + gAudioCtx.soundMode = SOUNDMODE_STEREO; + gAudioCtx.curTask = NULL; + gAudioCtx.rspTask[0].task.t.data_size = 0; + gAudioCtx.rspTask[1].task.t.data_size = 0; + osCreateMesgQueue(&gAudioCtx.syncDmaQueue, &gAudioCtx.syncDmaMesg, 1); + osCreateMesgQueue(&gAudioCtx.currAudioFrameDmaQueue, gAudioCtx.currAudioFrameDmaMsgBuf, + ARRAY_COUNT(gAudioCtx.currAudioFrameDmaMsgBuf)); + osCreateMesgQueue(&gAudioCtx.externalLoadQueue, gAudioCtx.externalLoadMsgBuf, + ARRAY_COUNT(gAudioCtx.externalLoadMsgBuf)); + osCreateMesgQueue(&gAudioCtx.preloadSampleQueue, gAudioCtx.preloadSampleMsgBuf, + ARRAY_COUNT(gAudioCtx.preloadSampleMsgBuf)); + gAudioCtx.curAudioFrameDmaCount = 0; + gAudioCtx.sampleDmaCount = 0; + gAudioCtx.cartHandle = osCartRomInit(); if (heap == NULL) { - gAudioContext.audioHeap = gAudioHeap; - gAudioContext.audioHeapSize = gAudioHeapInitSizes.heapSize; + gAudioCtx.audioHeap = gAudioHeap; + gAudioCtx.audioHeapSize = gAudioHeapInitSizes.heapSize; } else { void** hp = &heap; - gAudioContext.audioHeap = *hp; - gAudioContext.audioHeapSize = heapSize; + gAudioCtx.audioHeap = *hp; + gAudioCtx.audioHeapSize = heapSize; } - for (i = 0; i < (s32)gAudioContext.audioHeapSize / 8; i++) { - ((u64*)gAudioContext.audioHeap)[i] = 0; + for (i = 0; i < (s32)gAudioCtx.audioHeapSize / 8; i++) { + ((u64*)gAudioCtx.audioHeap)[i] = 0; } // Main Pool Split (split entirety of audio heap into initPool and sessionPool) AudioHeap_InitMainPools(gAudioHeapInitSizes.initPoolSize); // Initialize the audio interface buffers - for (i = 0; i < ARRAY_COUNT(gAudioContext.aiBuffers); i++) { - gAudioContext.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioContext.initPool, AIBUF_SIZE); + for (i = 0; i < ARRAY_COUNT(gAudioCtx.aiBuffers); i++) { + gAudioCtx.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioCtx.initPool, AIBUF_SIZE); } // Set audio tables pointers - gAudioContext.sequenceTable = (AudioTable*)gSequenceTable; - gAudioContext.soundFontTable = (AudioTable*)gSoundFontTable; - gAudioContext.sampleBankTable = (AudioTable*)gSampleBankTable; - gAudioContext.sequenceFontTable = gSequenceFontTable; + gAudioCtx.sequenceTable = (AudioTable*)gSequenceTable; + gAudioCtx.soundFontTable = (AudioTable*)gSoundFontTable; + gAudioCtx.sampleBankTable = (AudioTable*)gSampleBankTable; + gAudioCtx.sequenceFontTable = gSequenceFontTable; - gAudioContext.numSequences = gAudioContext.sequenceTable->numEntries; + gAudioCtx.numSequences = gAudioCtx.sequenceTable->numEntries; - gAudioContext.audioResetSpecIdToLoad = 0; - gAudioContext.resetStatus = 1; // Set reset to immediately initialize the audio heap + gAudioCtx.audioResetSpecIdToLoad = 0; + gAudioCtx.resetStatus = 1; // Set reset to immediately initialize the audio heap AudioHeap_ResetStep(); // Initialize audio tables - AudioLoad_InitTable(gAudioContext.sequenceTable, (u32)_AudioseqSegmentRomStart, 0); - AudioLoad_InitTable(gAudioContext.soundFontTable, (u32)_AudiobankSegmentRomStart, 0); - AudioLoad_InitTable(gAudioContext.sampleBankTable, (u32)_AudiotableSegmentRomStart, 0); - numFonts = gAudioContext.soundFontTable->numEntries; - gAudioContext.soundFontList = AudioHeap_Alloc(&gAudioContext.initPool, numFonts * sizeof(SoundFont)); + AudioLoad_InitTable(gAudioCtx.sequenceTable, (u32)_AudioseqSegmentRomStart, 0); + AudioLoad_InitTable(gAudioCtx.soundFontTable, (u32)_AudiobankSegmentRomStart, 0); + AudioLoad_InitTable(gAudioCtx.sampleBankTable, (u32)_AudiotableSegmentRomStart, 0); + numFonts = gAudioCtx.soundFontTable->numEntries; + gAudioCtx.soundFontList = AudioHeap_Alloc(&gAudioCtx.initPool, numFonts * sizeof(SoundFont)); for (i = 0; i < numFonts; i++) { AudioLoad_InitSoundFont(i); } - ramAddr = AudioHeap_Alloc(&gAudioContext.initPool, gAudioHeapInitSizes.permanentPoolSize); + ramAddr = AudioHeap_Alloc(&gAudioCtx.initPool, gAudioHeapInitSizes.permanentPoolSize); if (ramAddr == NULL) { // cast away const from gAudioHeapInitSizes *((u32*)&gAudioHeapInitSizes.permanentPoolSize) = 0; } - AudioHeap_InitPool(&gAudioContext.permanentPool, ramAddr, gAudioHeapInitSizes.permanentPoolSize); + AudioHeap_InitPool(&gAudioCtx.permanentPool, ramAddr, gAudioHeapInitSizes.permanentPoolSize); gAudioContextInitialized = true; - osSendMesg(gAudioContext.taskStartQueueP, (OSMesg)gAudioContext.totalTaskCount, OS_MESG_NOBLOCK); + osSendMesg(gAudioCtx.taskStartQueueP, (OSMesg)gAudioCtx.totalTaskCount, OS_MESG_NOBLOCK); } void AudioLoad_InitSlowLoads(void) { - gAudioContext.slowLoads[0].state = SLOW_LOAD_STATE_WAITING; - gAudioContext.slowLoads[1].state = SLOW_LOAD_STATE_WAITING; + gAudioCtx.slowLoads[0].state = SLOW_LOAD_STATE_WAITING; + gAudioCtx.slowLoads[1].state = SLOW_LOAD_STATE_WAITING; } s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* status) { @@ -1259,7 +1252,7 @@ s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* status) { return 0; } - slowLoad = &gAudioContext.slowLoads[gAudioContext.slowLoadPos]; + slowLoad = &gAudioCtx.slowLoads[gAudioCtx.slowLoadPos]; if (slowLoad->state == SLOW_LOAD_STATE_DONE) { slowLoad->state = SLOW_LOAD_STATE_WAITING; } @@ -1287,10 +1280,10 @@ s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* status) { slowLoad->seqOrFontId = fontId; slowLoad->instId = instId; if (slowLoad->medium == MEDIUM_UNK) { - slowLoad->unkMediumParam = gAudioContext.sampleBankTable->unkMediumParam; + slowLoad->unkMediumParam = gAudioCtx.sampleBankTable->unkMediumParam; } - gAudioContext.slowLoadPos ^= 1; + gAudioCtx.slowLoadPos ^= 1; return 0; } @@ -1346,9 +1339,9 @@ void AudioLoad_ProcessSlowLoads(s32 resetStatus) { AudioSlowLoad* slowLoad; s32 i; - for (i = 0; i < ARRAY_COUNT(gAudioContext.slowLoads); i++) { - slowLoad = &gAudioContext.slowLoads[i]; - switch (gAudioContext.slowLoads[i].state) { + for (i = 0; i < ARRAY_COUNT(gAudioCtx.slowLoads); i++) { + slowLoad = &gAudioCtx.slowLoads[i]; + switch (gAudioCtx.slowLoads[i].state) { case SLOW_LOAD_STATE_LOADING: if (slowLoad->medium != MEDIUM_UNK) { osRecvMesg(&slowLoad->msgQueue, NULL, OS_MESG_BLOCK); @@ -1406,14 +1399,14 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* status) { AudioTable* seqTable; u32 size; - if (seqId >= gAudioContext.numSequences) { + if (seqId >= gAudioCtx.numSequences) { *status = 0; return -1; } seqId = AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId); seqTable = AudioLoad_GetLoadTable(SEQUENCE_TABLE); - slowLoad = &gAudioContext.slowLoads[gAudioContext.slowLoadPos]; + slowLoad = &gAudioCtx.slowLoads[gAudioCtx.slowLoadPos]; if (slowLoad->state == SLOW_LOAD_STATE_DONE) { slowLoad->state = SLOW_LOAD_STATE_WAITING; } @@ -1434,15 +1427,15 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* status) { slowLoad->unkMediumParam = seqTable->unkMediumParam; } - gAudioContext.slowLoadPos ^= 1; + gAudioCtx.slowLoadPos ^= 1; return 0; } void AudioLoad_InitAsyncLoads(void) { s32 i; - for (i = 0; i < ARRAY_COUNT(gAudioContext.asyncLoads); i++) { - gAudioContext.asyncLoads[i].status = 0; + for (i = 0; i < ARRAY_COUNT(gAudioCtx.asyncLoads); i++) { + gAudioCtx.asyncLoads[i].status = 0; } } @@ -1456,7 +1449,7 @@ AudioAsyncLoad* AudioLoad_StartAsyncLoadUnkMedium(s32 unkMediumParam, u32 devAdd return NULL; } - osSendMesg(&gAudioContext.asyncLoadUnkMediumQueue, (OSMesg)asyncLoad, OS_MESG_NOBLOCK); + osSendMesg(&gAudioCtx.asyncLoadUnkMediumQueue, (OSMesg)asyncLoad, OS_MESG_NOBLOCK); asyncLoad->unkMediumParam = unkMediumParam; return asyncLoad; } @@ -1466,15 +1459,15 @@ AudioAsyncLoad* AudioLoad_StartAsyncLoad(u32 devAddr, void* ramAddr, u32 size, s AudioAsyncLoad* asyncLoad; s32 i; - for (i = 0; i < ARRAY_COUNT(gAudioContext.asyncLoads); i++) { - if (gAudioContext.asyncLoads[i].status == 0) { - asyncLoad = &gAudioContext.asyncLoads[i]; + for (i = 0; i < ARRAY_COUNT(gAudioCtx.asyncLoads); i++) { + if (gAudioCtx.asyncLoads[i].status == 0) { + asyncLoad = &gAudioCtx.asyncLoads[i]; break; } } // no more available async loads - if (i == ARRAY_COUNT(gAudioContext.asyncLoads)) { + if (i == ARRAY_COUNT(gAudioCtx.asyncLoads)) { return NULL; } @@ -1507,29 +1500,29 @@ void AudioLoad_ProcessAsyncLoads(s32 resetStatus) { AudioAsyncLoad* asyncLoad; s32 i; - if (gAudioContext.resetTimer == 1) { + if (gAudioCtx.resetTimer == 1) { return; } - if (gAudioContext.curUnkMediumLoad == NULL) { + if (gAudioCtx.curUnkMediumLoad == NULL) { if (resetStatus != 0) { // Clear and ignore queue if resetting. do { - } while (osRecvMesg(&gAudioContext.asyncLoadUnkMediumQueue, (OSMesg*)&asyncLoad, OS_MESG_NOBLOCK) != -1); - } else if (osRecvMesg(&gAudioContext.asyncLoadUnkMediumQueue, (OSMesg*)&asyncLoad, OS_MESG_NOBLOCK) == -1) { - gAudioContext.curUnkMediumLoad = NULL; + } while (osRecvMesg(&gAudioCtx.asyncLoadUnkMediumQueue, (OSMesg*)&asyncLoad, OS_MESG_NOBLOCK) != -1); + } else if (osRecvMesg(&gAudioCtx.asyncLoadUnkMediumQueue, (OSMesg*)&asyncLoad, OS_MESG_NOBLOCK) == -1) { + gAudioCtx.curUnkMediumLoad = NULL; } else { - gAudioContext.curUnkMediumLoad = asyncLoad; + gAudioCtx.curUnkMediumLoad = asyncLoad; } } - if (gAudioContext.curUnkMediumLoad != NULL) { - AudioLoad_ProcessAsyncLoadUnkMedium(gAudioContext.curUnkMediumLoad, resetStatus); + if (gAudioCtx.curUnkMediumLoad != NULL) { + AudioLoad_ProcessAsyncLoadUnkMedium(gAudioCtx.curUnkMediumLoad, resetStatus); } - for (i = 0; i < ARRAY_COUNT(gAudioContext.asyncLoads); i++) { - if (gAudioContext.asyncLoads[i].status == 1) { - asyncLoad = &gAudioContext.asyncLoads[i]; + for (i = 0; i < ARRAY_COUNT(gAudioCtx.asyncLoads); i++) { + if (gAudioCtx.asyncLoads[i].status == 1) { + asyncLoad = &gAudioCtx.asyncLoads[i]; if (asyncLoad->medium != MEDIUM_UNK) { AudioLoad_ProcessAsyncLoad(asyncLoad, resetStatus); } @@ -1561,8 +1554,8 @@ void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) { case FONT_TABLE: fontId = ASYNC_ID(retMsg); - sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1; + sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2; sampleBankReloc.sampleBankId1 = sampleBankId1; sampleBankReloc.sampleBankId2 = sampleBankId2; sampleBankReloc.baseAddr1 = @@ -1581,7 +1574,7 @@ void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) { } void AudioLoad_ProcessAsyncLoad(AudioAsyncLoad* asyncLoad, s32 resetStatus) { - AudioTable* sampleBankTable = gAudioContext.sampleBankTable; + AudioTable* sampleBankTable = gAudioCtx.sampleBankTable; if (asyncLoad->delay >= 2) { asyncLoad->delay--; @@ -1692,7 +1685,7 @@ void AudioLoad_RelocateSample(TunedSample* tunedSample, SoundFontData* fontData, sample->isRelocated = true; if (sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) { - gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; + gAudioCtx.usedSamples[gAudioCtx.numUsedSamples++] = sample; } } } @@ -1718,27 +1711,27 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData s32 i; preloadInProgress = false; - if (gAudioContext.preloadSampleStackTop != 0) { + if (gAudioCtx.preloadSampleStackTop != 0) { preloadInProgress = true; } else { D_8016B780 = 0; } - gAudioContext.numUsedSamples = 0; + gAudioCtx.numUsedSamples = 0; AudioLoad_RelocateFont(fontId, fontData, sampleBankReloc); size = 0; - for (i = 0; i < gAudioContext.numUsedSamples; i++) { - size += ALIGN16(gAudioContext.usedSamples[i]->size); + for (i = 0; i < gAudioCtx.numUsedSamples; i++) { + size += ALIGN16(gAudioCtx.usedSamples[i]->size); } if (size && size) {} - for (i = 0; i < gAudioContext.numUsedSamples; i++) { - if (gAudioContext.preloadSampleStackTop == 120) { + for (i = 0; i < gAudioCtx.numUsedSamples; i++) { + if (gAudioCtx.preloadSampleStackTop == 120) { break; } - sample = gAudioContext.usedSamples[i]; + sample = gAudioCtx.usedSamples[i]; sampleRamAddr = NULL; switch (isAsync) { case false: @@ -1775,7 +1768,7 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData case false: if (sample->medium == MEDIUM_UNK) { AudioLoad_SyncDmaUnkMedium((u32)sample->sampleAddr, sampleRamAddr, sample->size, - gAudioContext.sampleBankTable->unkMediumParam); + gAudioCtx.sampleBankTable->unkMediumParam); sample->sampleAddr = sampleRamAddr; sample->medium = MEDIUM_RAM; } else { @@ -1787,24 +1780,24 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData break; case true: - preload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop]; + preload = &gAudioCtx.preloadSampleStack[gAudioCtx.preloadSampleStackTop]; preload->sample = sample; preload->ramAddr = sampleRamAddr; - preload->encodedInfo = (gAudioContext.preloadSampleStackTop << 24) | 0xFFFFFF; + preload->encodedInfo = (gAudioCtx.preloadSampleStackTop << 24) | 0xFFFFFF; preload->isFree = false; preload->endAndMediumKey = (u32)sample->sampleAddr + sample->size + sample->medium; - gAudioContext.preloadSampleStackTop++; + gAudioCtx.preloadSampleStackTop++; break; } } - gAudioContext.numUsedSamples = 0; + gAudioCtx.numUsedSamples = 0; - if (gAudioContext.preloadSampleStackTop != 0 && !preloadInProgress) { - topPreload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop - 1]; + if (gAudioCtx.preloadSampleStackTop != 0 && !preloadInProgress) { + topPreload = &gAudioCtx.preloadSampleStack[gAudioCtx.preloadSampleStackTop - 1]; sample = topPreload->sample; nChunks = (sample->size >> 12) + 1; AudioLoad_StartAsyncLoad((u32)sample->sampleAddr, topPreload->ramAddr, sample->size, sample->medium, nChunks, - &gAudioContext.preloadSampleQueue, topPreload->encodedInfo); + &gAudioCtx.preloadSampleQueue, topPreload->encodedInfo); } } @@ -1816,20 +1809,20 @@ s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) { u32 nChunks; s32 pad; - if (gAudioContext.preloadSampleStackTop > 0) { + if (gAudioCtx.preloadSampleStackTop > 0) { if (resetStatus != 0) { // Clear result queue and preload stack and return. - osRecvMesg(&gAudioContext.preloadSampleQueue, (OSMesg*)&preloadIndex, OS_MESG_NOBLOCK); - gAudioContext.preloadSampleStackTop = 0; + osRecvMesg(&gAudioCtx.preloadSampleQueue, (OSMesg*)&preloadIndex, OS_MESG_NOBLOCK); + gAudioCtx.preloadSampleStackTop = 0; return false; } - if (osRecvMesg(&gAudioContext.preloadSampleQueue, (OSMesg*)&preloadIndex, OS_MESG_NOBLOCK) == -1) { + if (osRecvMesg(&gAudioCtx.preloadSampleQueue, (OSMesg*)&preloadIndex, OS_MESG_NOBLOCK) == -1) { // Previous preload is not done yet. return false; } preloadIndex >>= 24; - preload = &gAudioContext.preloadSampleStack[preloadIndex]; + preload = &gAudioCtx.preloadSampleStack[preloadIndex]; if (preload->isFree == false) { sample = preload->sample; @@ -1845,12 +1838,12 @@ s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) { // Pop requests with isFree = true off the stack, as far as possible, // and dispatch the next DMA. while (true) { - if (gAudioContext.preloadSampleStackTop <= 0) { + if (gAudioCtx.preloadSampleStackTop <= 0) { break; } - preload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop - 1]; + preload = &gAudioCtx.preloadSampleStack[gAudioCtx.preloadSampleStackTop - 1]; if (preload->isFree == true) { - gAudioContext.preloadSampleStackTop--; + gAudioCtx.preloadSampleStackTop--; continue; } @@ -1859,10 +1852,10 @@ s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) { key = (u32)sample->sampleAddr + sample->size + sample->medium; if (key != preload->endAndMediumKey) { preload->isFree = true; - gAudioContext.preloadSampleStackTop--; + gAudioCtx.preloadSampleStackTop--; } else { AudioLoad_StartAsyncLoad((u32)sample->sampleAddr, preload->ramAddr, sample->size, sample->medium, - nChunks, &gAudioContext.preloadSampleQueue, preload->encodedInfo); + nChunks, &gAudioCtx.preloadSampleQueue, preload->encodedInfo); break; } } @@ -1890,8 +1883,8 @@ s32 AudioLoad_AddToSampleSet(Sample* sample, s32 numSamples, Sample** sampleSet) s32 AudioLoad_GetSamplesForFont(s32 fontId, Sample** sampleSet) { s32 i; s32 numSamples = 0; - s32 numDrums = gAudioContext.soundFontList[fontId].numDrums; - s32 numInstruments = gAudioContext.soundFontList[fontId].numInstruments; + s32 numDrums = gAudioCtx.soundFontList[fontId].numDrums; + s32 numInstruments = gAudioCtx.soundFontList[fontId].numInstruments; for (i = 0; i < numDrums; i++) { Drum* drum = Audio_GetDrum(fontId, i); @@ -1924,7 +1917,7 @@ void AudioLoad_AddUsedSample(TunedSample* tunedSample) { Sample* sample = tunedSample->sample; if ((sample->size != 0) && sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) { - gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; + gAudioCtx.usedSamples[gAudioCtx.numUsedSamples++] = sample; } } @@ -1945,15 +1938,15 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, SampleBankRelocInfo* s32 nChunks; preloadInProgress = false; - if (gAudioContext.preloadSampleStackTop != 0) { + if (gAudioCtx.preloadSampleStackTop != 0) { preloadInProgress = true; } - gAudioContext.numUsedSamples = 0; + gAudioCtx.numUsedSamples = 0; - numDrums = gAudioContext.soundFontList[fontId].numDrums; - numInstruments = gAudioContext.soundFontList[fontId].numInstruments; - numSfx = gAudioContext.soundFontList[fontId].numSfx; + numDrums = gAudioCtx.soundFontList[fontId].numDrums; + numInstruments = gAudioCtx.soundFontList[fontId].numInstruments; + numSfx = gAudioCtx.soundFontList[fontId].numSfx; for (i = 0; i < numInstruments; i++) { instrument = Audio_GetInstrumentInner(fontId, i); @@ -1982,22 +1975,22 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, SampleBankRelocInfo* } } - if (gAudioContext.numUsedSamples == 0) { + if (gAudioCtx.numUsedSamples == 0) { return; } size = 0; - for (i = 0; i < gAudioContext.numUsedSamples; i++) { - size += ALIGN16(gAudioContext.usedSamples[i]->size); + for (i = 0; i < gAudioCtx.numUsedSamples; i++) { + size += ALIGN16(gAudioCtx.usedSamples[i]->size); } if (size) {} - for (i = 0; i < gAudioContext.numUsedSamples; i++) { - if (gAudioContext.preloadSampleStackTop == 120) { + for (i = 0; i < gAudioCtx.numUsedSamples; i++) { + if (gAudioCtx.preloadSampleStackTop == 120) { break; } - sample = gAudioContext.usedSamples[i]; + sample = gAudioCtx.usedSamples[i]; if (sample->medium == MEDIUM_RAM) { continue; } @@ -2031,7 +2024,7 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, SampleBankRelocInfo* case false: if (sample->medium == MEDIUM_UNK) { AudioLoad_SyncDmaUnkMedium((u32)sample->sampleAddr, addr, sample->size, - gAudioContext.sampleBankTable->unkMediumParam); + gAudioCtx.sampleBankTable->unkMediumParam); sample->sampleAddr = addr; sample->medium = MEDIUM_RAM; } else { @@ -2042,24 +2035,24 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, SampleBankRelocInfo* break; case true: - preload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop]; + preload = &gAudioCtx.preloadSampleStack[gAudioCtx.preloadSampleStackTop]; preload->sample = sample; preload->ramAddr = addr; - preload->encodedInfo = (gAudioContext.preloadSampleStackTop << 24) | 0xFFFFFF; + preload->encodedInfo = (gAudioCtx.preloadSampleStackTop << 24) | 0xFFFFFF; preload->isFree = false; preload->endAndMediumKey = (u32)sample->sampleAddr + sample->size + sample->medium; - gAudioContext.preloadSampleStackTop++; + gAudioCtx.preloadSampleStackTop++; break; } } - gAudioContext.numUsedSamples = 0; + gAudioCtx.numUsedSamples = 0; - if (gAudioContext.preloadSampleStackTop != 0 && !preloadInProgress) { - topPreload = &gAudioContext.preloadSampleStack[gAudioContext.preloadSampleStackTop - 1]; + if (gAudioCtx.preloadSampleStackTop != 0 && !preloadInProgress) { + topPreload = &gAudioCtx.preloadSampleStack[gAudioCtx.preloadSampleStackTop - 1]; sample = topPreload->sample; nChunks = (sample->size >> 12) + 1; AudioLoad_StartAsyncLoad((u32)sample->sampleAddr, topPreload->ramAddr, sample->size, sample->medium, nChunks, - &gAudioContext.preloadSampleQueue, topPreload->encodedInfo); + &gAudioCtx.preloadSampleQueue, topPreload->encodedInfo); } } @@ -2071,13 +2064,13 @@ void AudioLoad_LoadPermanentSamples(void) { s32 i; sampleBankTable = AudioLoad_GetLoadTable(SAMPLE_TABLE); - for (i = 0; i < gAudioContext.permanentPool.numEntries; i++) { + for (i = 0; i < gAudioCtx.permanentPool.numEntries; i++) { SampleBankRelocInfo sampleBankReloc; - if (gAudioContext.permanentCache[i].tableType == FONT_TABLE) { - fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.permanentCache[i].id); - sampleBankReloc.sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; - sampleBankReloc.sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + if (gAudioCtx.permanentCache[i].tableType == FONT_TABLE) { + fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioCtx.permanentCache[i].id); + sampleBankReloc.sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1; + sampleBankReloc.sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2; if (sampleBankReloc.sampleBankId1 != 0xFF) { sampleBankReloc.sampleBankId1 = diff --git a/src/code/audio_playback.c b/src/code/audio_playback.c index 87ad945a65..87e2f792c2 100644 --- a/src/code/audio_playback.c +++ b/src/code/audio_playback.c @@ -31,7 +31,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) { sub->bitField0.stereoStrongLeft = false; sub->bitField0.stereoHeadsetEffects = stereoData.stereoHeadsetEffects; sub->bitField0.usesHeadsetPanEffects = stereoData.usesHeadsetPanEffects; - if (stereoHeadsetEffects && (gAudioContext.soundMode == SOUNDMODE_HEADSET)) { + if (stereoHeadsetEffects && (gAudioCtx.soundMode == SOUNDMODE_HEADSET)) { halfPanIndex = pan >> 1; if (halfPanIndex > 0x3F) { halfPanIndex = 0x3F; @@ -43,7 +43,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) { volLeft = gHeadsetPanVolume[pan]; volRight = gHeadsetPanVolume[0x7F - pan]; - } else if (stereoHeadsetEffects && (gAudioContext.soundMode == SOUNDMODE_STEREO)) { + } else if (stereoHeadsetEffects && (gAudioCtx.soundMode == SOUNDMODE_STEREO)) { strongLeft = strongRight = 0; sub->haasEffectLeftDelaySize = 0; sub->haasEffectRightDelaySize = 0; @@ -80,7 +80,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) { break; } - } else if (gAudioContext.soundMode == SOUNDMODE_MONO) { + } else if (gAudioCtx.soundMode == SOUNDMODE_MONO) { sub->bitField0.stereoHeadsetEffects = false; sub->bitField0.usesHeadsetPanEffects = false; volLeft = 0.707f; // approx 1/sqrt(2) @@ -163,9 +163,9 @@ void Audio_ProcessNotes(void) { f32 scale; s32 i; - for (i = 0; i < gAudioContext.numNotes; i++) { - note = &gAudioContext.notes[i]; - noteSubEu2 = &gAudioContext.noteSubsEu[gAudioContext.noteSubEuOffset + i]; + for (i = 0; i < gAudioCtx.numNotes; i++) { + note = &gAudioCtx.notes[i]; + noteSubEu2 = &gAudioCtx.noteSubsEu[gAudioCtx.noteSubEuOffset + i]; playbackState = ¬e->playbackState; if (playbackState->parentLayer != NO_LAYER) { if ((u32)playbackState->parentLayer < 0x7FFFFFFF) { @@ -174,7 +174,7 @@ void Audio_ProcessNotes(void) { if (note != playbackState->parentLayer->note && playbackState->unk_04 == 0) { playbackState->adsr.action.s.release = true; - playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv; playbackState->priority = 1; playbackState->unk_04 = 2; goto out; @@ -285,7 +285,7 @@ void Audio_ProcessNotes(void) { } subAttrs.frequency *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale; - subAttrs.frequency *= gAudioContext.audioBufferParameters.resampleRate; + subAttrs.frequency *= gAudioCtx.audioBufferParameters.resampleRate; subAttrs.velocity *= scale; Audio_InitNoteSub(note, noteSubEu2, &subAttrs); noteSubEu->bitField1.bookOffset = bookOffset; @@ -315,18 +315,18 @@ Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) { } if (!AudioLoad_IsFontLoadComplete(fontId)) { - gAudioContext.audioErrorFlags = fontId + 0x10000000; + gAudioCtx.audioErrorFlags = fontId + 0x10000000; return NULL; } - if (instId >= gAudioContext.soundFontList[fontId].numInstruments) { - gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000; + if (instId >= gAudioCtx.soundFontList[fontId].numInstruments) { + gAudioCtx.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000; return NULL; } - inst = gAudioContext.soundFontList[fontId].instruments[instId]; + inst = gAudioCtx.soundFontList[fontId].instruments[instId]; if (inst == NULL) { - gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000; + gAudioCtx.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000; return inst; } @@ -341,21 +341,21 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) { } if (!AudioLoad_IsFontLoadComplete(fontId)) { - gAudioContext.audioErrorFlags = fontId + 0x10000000; + gAudioCtx.audioErrorFlags = fontId + 0x10000000; return NULL; } - if (drumId >= gAudioContext.soundFontList[fontId].numDrums) { - gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000; + if (drumId >= gAudioCtx.soundFontList[fontId].numDrums) { + gAudioCtx.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000; return NULL; } - if ((u32)gAudioContext.soundFontList[fontId].drums < AUDIO_RELOCATED_ADDRESS_START) { + if ((u32)gAudioCtx.soundFontList[fontId].drums < AUDIO_RELOCATED_ADDRESS_START) { return NULL; } - drum = gAudioContext.soundFontList[fontId].drums[drumId]; + drum = gAudioCtx.soundFontList[fontId].drums[drumId]; if (drum == NULL) { - gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000; + gAudioCtx.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000; } return drum; @@ -369,23 +369,23 @@ SoundEffect* Audio_GetSoundEffect(s32 fontId, s32 sfxId) { } if (!AudioLoad_IsFontLoadComplete(fontId)) { - gAudioContext.audioErrorFlags = fontId + 0x10000000; + gAudioCtx.audioErrorFlags = fontId + 0x10000000; return NULL; } - if (sfxId >= gAudioContext.soundFontList[fontId].numSfx) { - gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000; + if (sfxId >= gAudioCtx.soundFontList[fontId].numSfx) { + gAudioCtx.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000; return NULL; } - if ((u32)gAudioContext.soundFontList[fontId].soundEffects < AUDIO_RELOCATED_ADDRESS_START) { + if ((u32)gAudioCtx.soundFontList[fontId].soundEffects < AUDIO_RELOCATED_ADDRESS_START) { return NULL; } - soundEffect = &gAudioContext.soundFontList[fontId].soundEffects[sfxId]; + soundEffect = &gAudioCtx.soundFontList[fontId].soundEffects[sfxId]; if (soundEffect == NULL) { - gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000; + gAudioCtx.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000; } if (soundEffect->tunedSample.sample == NULL) { @@ -406,24 +406,24 @@ s32 Audio_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* val switch (instrumentType) { case 0: - if (index >= gAudioContext.soundFontList[fontId].numDrums) { + if (index >= gAudioCtx.soundFontList[fontId].numDrums) { return -3; } - gAudioContext.soundFontList[fontId].drums[index] = value; + gAudioCtx.soundFontList[fontId].drums[index] = value; break; case 1: - if (index >= gAudioContext.soundFontList[fontId].numSfx) { + if (index >= gAudioCtx.soundFontList[fontId].numSfx) { return -3; } - gAudioContext.soundFontList[fontId].soundEffects[index] = *(SoundEffect*)value; + gAudioCtx.soundFontList[fontId].soundEffects[index] = *(SoundEffect*)value; break; default: - if (index >= gAudioContext.soundFontList[fontId].numInstruments) { + if (index >= gAudioCtx.soundFontList[fontId].numInstruments) { return -3; } - gAudioContext.soundFontList[fontId].instruments[index] = value; + gAudioCtx.soundFontList[fontId].instruments[index] = value; break; } @@ -456,7 +456,7 @@ void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) { if (note->playbackState.parentLayer != layer) { if (note->playbackState.parentLayer == NO_LAYER && note->playbackState.wantedParentLayer == NO_LAYER && note->playbackState.prevParentLayer == layer && target != ADSR_STATE_DECAY) { - note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.action.s.release = true; } return; @@ -500,16 +500,16 @@ void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) { note->playbackState.prevParentLayer = note->playbackState.parentLayer; note->playbackState.parentLayer = NO_LAYER; if (target == ADSR_STATE_RELEASE) { - note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.action.s.release = true; note->playbackState.unk_04 = 2; } else { note->playbackState.unk_04 = 1; note->playbackState.adsr.action.s.decay = true; if (layer->adsr.decayIndex == 0) { - note->playbackState.adsr.fadeOutVel = gAudioContext.adsrDecayTable[layer->channel->adsr.decayIndex]; + note->playbackState.adsr.fadeOutVel = gAudioCtx.adsrDecayTable[layer->channel->adsr.decayIndex]; } else { - note->playbackState.adsr.fadeOutVel = gAudioContext.adsrDecayTable[layer->adsr.decayIndex]; + note->playbackState.adsr.fadeOutVel = gAudioCtx.adsrDecayTable[layer->adsr.decayIndex]; } note->playbackState.adsr.sustain = ((f32)(s32)(layer->channel->adsr.sustain) * note->playbackState.adsr.current) / 256.0f; @@ -616,11 +616,11 @@ void Audio_InitNoteLists(NotePool* pool) { void Audio_InitNoteFreeList(void) { s32 i; - Audio_InitNoteLists(&gAudioContext.noteFreeLists); - for (i = 0; i < gAudioContext.numNotes; i++) { - gAudioContext.notes[i].listItem.u.value = &gAudioContext.notes[i]; - gAudioContext.notes[i].listItem.prev = NULL; - AudioSeq_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, &gAudioContext.notes[i].listItem); + Audio_InitNoteLists(&gAudioCtx.noteFreeLists); + for (i = 0; i < gAudioCtx.numNotes; i++) { + gAudioCtx.notes[i].listItem.u.value = &gAudioCtx.notes[i]; + gAudioCtx.notes[i].listItem.prev = NULL; + AudioSeq_AudioListPushBack(&gAudioCtx.noteFreeLists.disabled, &gAudioCtx.notes[i].listItem); } } @@ -634,22 +634,22 @@ void Audio_NotePoolClear(NotePool* pool) { switch (i) { case 0: source = &pool->disabled; - dest = &gAudioContext.noteFreeLists.disabled; + dest = &gAudioCtx.noteFreeLists.disabled; break; case 1: source = &pool->decaying; - dest = &gAudioContext.noteFreeLists.decaying; + dest = &gAudioCtx.noteFreeLists.decaying; break; case 2: source = &pool->releasing; - dest = &gAudioContext.noteFreeLists.releasing; + dest = &gAudioCtx.noteFreeLists.releasing; break; case 3: source = &pool->active; - dest = &gAudioContext.noteFreeLists.active; + dest = &gAudioCtx.noteFreeLists.active; break; } @@ -680,22 +680,22 @@ void Audio_NotePoolFill(NotePool* pool, s32 count) { switch (i) { case 0: - source = &gAudioContext.noteFreeLists.disabled; + source = &gAudioCtx.noteFreeLists.disabled; dest = &pool->disabled; break; case 1: - source = &gAudioContext.noteFreeLists.decaying; + source = &gAudioCtx.noteFreeLists.decaying; dest = &pool->decaying; break; case 2: - source = &gAudioContext.noteFreeLists.releasing; + source = &gAudioCtx.noteFreeLists.releasing; dest = &pool->releasing; break; case 3: - source = &gAudioContext.noteFreeLists.active; + source = &gAudioCtx.noteFreeLists.active; dest = &pool->active; break; } @@ -805,7 +805,7 @@ void Audio_NoteReleaseAndTakeOwnership(Note* note, SequenceLayer* layer) { note->playbackState.wantedParentLayer = layer; note->playbackState.priority = layer->channel->notePriority; - note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.action.s.release = true; } @@ -899,9 +899,9 @@ Note* Audio_AllocNote(SequenceLayer* layer) { } if (policy & 8) { - if (!(note = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) && - !(note = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) && - !(note = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) { + if (!(note = Audio_AllocNoteFromDisabled(&gAudioCtx.noteFreeLists, layer)) && + !(note = Audio_AllocNoteFromDecaying(&gAudioCtx.noteFreeLists, layer)) && + !(note = Audio_AllocNoteFromActive(&gAudioCtx.noteFreeLists, layer))) { goto null_return; } return note; @@ -909,13 +909,13 @@ Note* Audio_AllocNote(SequenceLayer* layer) { if (!(note = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) && !(note = Audio_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) && - !(note = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) && + !(note = Audio_AllocNoteFromDisabled(&gAudioCtx.noteFreeLists, layer)) && !(note = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) && !(note = Audio_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) && - !(note = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) && + !(note = Audio_AllocNoteFromDecaying(&gAudioCtx.noteFreeLists, layer)) && !(note = Audio_AllocNoteFromActive(&layer->channel->notePool, layer)) && !(note = Audio_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer)) && - !(note = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) { + !(note = Audio_AllocNoteFromActive(&gAudioCtx.noteFreeLists, layer))) { goto null_return; } return note; @@ -929,8 +929,8 @@ void Audio_NoteInitAll(void) { Note* note; s32 i; - for (i = 0; i < gAudioContext.numNotes; i++) { - note = &gAudioContext.notes[i]; + for (i = 0; i < gAudioCtx.numNotes; i++) { + note = &gAudioCtx.notes[i]; note->noteSubEu = gZeroNoteSub; note->playbackState.priority = 0; note->playbackState.unk_04 = 0; @@ -947,6 +947,6 @@ void Audio_NoteInitAll(void) { note->playbackState.stereoHeadsetEffects = false; note->startSamplePos = 0; note->synthesisState.synthesisBuffers = - AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, sizeof(NoteSynthesisBuffers)); + AudioHeap_AllocDmaMemory(&gAudioCtx.miscPool, sizeof(NoteSynthesisBuffers)); } } diff --git a/src/code/audio_seqplayer.c b/src/code/audio_seqplayer.c index 389a039fc6..008bedea61 100644 --- a/src/code/audio_seqplayer.c +++ b/src/code/audio_seqplayer.c @@ -252,7 +252,7 @@ s32 AudioSeq_HandleScriptFlowControl(SequencePlayer* seqPlayer, SeqScriptState* void AudioSeq_InitSequenceChannel(SequenceChannel* channel) { s32 i; - if (channel == &gAudioContext.sequenceChannelNone) { + if (channel == &gAudioCtx.sequenceChannelNone) { return; } @@ -297,7 +297,7 @@ void AudioSeq_InitSequenceChannel(SequenceChannel* channel) { channel->freqScale = 1.0f; for (i = 0; i < ARRAY_COUNT(channel->soundScriptIO); i++) { - channel->soundScriptIO[i] = -1; + channel->soundScriptIO[i] = SEQ_IO_VAL_NONE; } channel->unused = false; @@ -309,7 +309,7 @@ s32 AudioSeq_SeqChannelSetLayer(SequenceChannel* channel, s32 layerIndex) { s32 pad; if (channel->layers[layerIndex] == NULL) { - layer = AudioSeq_AudioListPopBack(&gAudioContext.layerFreeList); + layer = AudioSeq_AudioListPopBack(&gAudioCtx.layerFreeList); channel->layers[layerIndex] = layer; if (layer == NULL) { channel->layers[layerIndex] = NULL; @@ -353,7 +353,7 @@ s32 AudioSeq_SeqChannelSetLayer(SequenceChannel* channel, s32 layerIndex) { void AudioSeq_SeqLayerDisable(SequenceLayer* layer) { if (layer != NULL) { - if (layer->channel != &gAudioContext.sequenceChannelNone && layer->channel->seqPlayer->finished == 1) { + if (layer->channel != &gAudioCtx.sequenceChannelNone && layer->channel->seqPlayer->finished == 1) { Audio_SeqLayerNoteRelease(layer); } else { Audio_SeqLayerNoteDecay(layer); @@ -367,7 +367,7 @@ void AudioSeq_SeqLayerFree(SequenceChannel* channel, s32 layerIndex) { SequenceLayer* layer = channel->layers[layerIndex]; if (layer != NULL) { - AudioSeq_AudioListPushBack(&gAudioContext.layerFreeList, &layer->listItem); + AudioSeq_AudioListPushBack(&gAudioCtx.layerFreeList, &layer->listItem); AudioSeq_SeqLayerDisable(layer); channel->layers[layerIndex] = NULL; } @@ -452,10 +452,10 @@ void AudioSeq_SequencePlayerDisable(SequencePlayer* seqPlayer) { AudioLoad_SetFontLoadStatus(seqPlayer->defaultFont, LOAD_STATUS_MAYBE_DISCARDABLE); } - if (seqPlayer->defaultFont == gAudioContext.fontCache.temporary.entries[0].id) { - gAudioContext.fontCache.temporary.nextSide = 0; - } else if (seqPlayer->defaultFont == gAudioContext.fontCache.temporary.entries[1].id) { - gAudioContext.fontCache.temporary.nextSide = 1; + if (seqPlayer->defaultFont == gAudioCtx.fontCache.temporary.entries[0].id) { + gAudioCtx.fontCache.temporary.nextSide = 0; + } else if (seqPlayer->defaultFont == gAudioCtx.fontCache.temporary.entries[1].id) { + gAudioCtx.fontCache.temporary.nextSide = 1; } } @@ -488,15 +488,15 @@ void* AudioSeq_AudioListPopBack(AudioListItem* list) { void AudioSeq_InitLayerFreelist(void) { s32 i; - gAudioContext.layerFreeList.prev = &gAudioContext.layerFreeList; - gAudioContext.layerFreeList.next = &gAudioContext.layerFreeList; - gAudioContext.layerFreeList.u.count = 0; - gAudioContext.layerFreeList.pool = NULL; + gAudioCtx.layerFreeList.prev = &gAudioCtx.layerFreeList; + gAudioCtx.layerFreeList.next = &gAudioCtx.layerFreeList; + gAudioCtx.layerFreeList.u.count = 0; + gAudioCtx.layerFreeList.pool = NULL; - for (i = 0; i < ARRAY_COUNT(gAudioContext.sequenceLayers); i++) { - gAudioContext.sequenceLayers[i].listItem.u.value = &gAudioContext.sequenceLayers[i]; - gAudioContext.sequenceLayers[i].listItem.prev = NULL; - AudioSeq_AudioListPushBack(&gAudioContext.layerFreeList, &gAudioContext.sequenceLayers[i].listItem); + for (i = 0; i < ARRAY_COUNT(gAudioCtx.sequenceLayers); i++) { + gAudioCtx.sequenceLayers[i].listItem.u.value = &gAudioCtx.sequenceLayers[i]; + gAudioCtx.sequenceLayers[i].listItem.prev = NULL; + AudioSeq_AudioListPushBack(&gAudioCtx.layerFreeList, &gAudioCtx.sequenceLayers[i].listItem); } } @@ -873,7 +873,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { layer->tunedSample = NULL; tuning = 1.0f; if (instOrWave >= 0xC0) { - layer->tunedSample = &gAudioContext.synthesisReverbs[instOrWave - 0xC0].tunedSample; + layer->tunedSample = &gAudioCtx.synthesisReverbs[instOrWave - 0xC0].tunedSample; } } @@ -903,12 +903,12 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { portamento->extent = (freqScale2 / freqScale) - 1.0f; if (PORTAMENTO_IS_SPECIAL(*portamento)) { - speed = seqPlayer->tempo * 0x8000 / gAudioContext.tempoInternalToExternal; + speed = seqPlayer->tempo * 0x8000 / gAudioCtx.tempoInternalToExternal; if (layer->delay != 0) { speed = speed * 0x100 / (layer->delay * layer->portamentoTime); } } else { - speed = 0x20000 / (layer->portamentoTime * gAudioContext.audioBufferParameters.updatesPerFrame); + speed = 0x20000 / (layer->portamentoTime * gAudioCtx.audioBufferParameters.updatesPerFrame); } if (speed >= 0x7FFF) { @@ -935,7 +935,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { layer->tunedSample = NULL; layer->freqScale = gPitchFrequencies[semitone2]; if (instOrWave >= 0xC0) { - layer->tunedSample = &gAudioContext.synthesisReverbs[instOrWave - 0xC0].tunedSample; + layer->tunedSample = &gAudioCtx.synthesisReverbs[instOrWave - 0xC0].tunedSample; } } break; @@ -951,7 +951,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { time = 0.0f; } time *= seqPlayer->tempo; - time *= gAudioContext.unk_2870; + time *= gAudioCtx.unk_2870; time /= layer->freqScale; if (time > 0x7FFE) { time = 0x7FFE; @@ -964,7 +964,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { // (It's a bit unclear if 'portamento' has actually always been // set when this is reached...) if (PORTAMENTO_IS_SPECIAL(*portamento)) { - speed2 = seqPlayer->tempo * 0x8000 / gAudioContext.tempoInternalToExternal; + speed2 = seqPlayer->tempo * 0x8000 / gAudioCtx.tempoInternalToExternal; speed2 = speed2 * 0x100 / (layer->delay * layer->portamentoTime); if (speed2 >= 0x7FFF) { speed2 = 0x7FFF; @@ -1043,8 +1043,8 @@ s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd) { } if (channel->velocityRandomVariance != 0) { - floatDelta = layer->velocitySquare * (gAudioContext.audioRandom % channel->velocityRandomVariance) / 100.0f; - if ((gAudioContext.audioRandom & 0x8000) != 0) { + floatDelta = layer->velocitySquare * (gAudioCtx.audioRandom % channel->velocityRandomVariance) / 100.0f; + if ((gAudioCtx.audioRandom & 0x8000) != 0) { floatDelta = -floatDelta; } @@ -1064,8 +1064,8 @@ s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd) { if (channel->gateTimeRandomVariance != 0) { //! @bug should probably be gateTimeRandomVariance - intDelta = (layer->gateDelay * (gAudioContext.audioRandom % channel->velocityRandomVariance)) / 100; - if ((gAudioContext.audioRandom & 0x4000) != 0) { + intDelta = (layer->gateDelay * (gAudioCtx.audioRandom % channel->velocityRandomVariance)) / 100; + if ((gAudioCtx.audioRandom & 0x4000) != 0) { intDelta = -intDelta; } @@ -1244,9 +1244,9 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { cmd = (u8)cmdArgs[0]; if (seqPlayer->defaultFont != 0xFF) { - cmdArgU16 = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId]; - lowBits = gAudioContext.sequenceFontTable[cmdArgU16]; - cmd = gAudioContext.sequenceFontTable[cmdArgU16 + lowBits - cmd]; + cmdArgU16 = ((u16*)gAudioCtx.sequenceFontTable)[seqPlayer->seqId]; + lowBits = gAudioCtx.sequenceFontTable[cmdArgU16]; + cmd = gAudioCtx.sequenceFontTable[cmdArgU16 + lowBits - cmd]; } if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, cmd)) { @@ -1373,9 +1373,9 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { cmd = (u8)cmdArgs[0]; if (seqPlayer->defaultFont != 0xFF) { - cmdArgU16 = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId]; - lowBits = gAudioContext.sequenceFontTable[cmdArgU16]; - cmd = gAudioContext.sequenceFontTable[cmdArgU16 + lowBits - cmd]; + cmdArgU16 = ((u16*)gAudioCtx.sequenceFontTable)[seqPlayer->seqId]; + lowBits = gAudioCtx.sequenceFontTable[cmdArgU16]; + cmd = gAudioCtx.sequenceFontTable[cmdArgU16 + lowBits - cmd]; } if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, cmd)) { @@ -1569,12 +1569,12 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { case 0xB7: channel->unk_22 = - (cmdArgs[0] == 0) ? gAudioContext.audioRandom & 0xFFFF : gAudioContext.audioRandom % cmdArgs[0]; + (cmdArgs[0] == 0) ? gAudioCtx.audioRandom & 0xFFFF : gAudioCtx.audioRandom % cmdArgs[0]; break; case 0xB8: scriptState->value = - (cmdArgs[0] == 0) ? gAudioContext.audioRandom & 0xFFFF : gAudioContext.audioRandom % cmdArgs[0]; + (cmdArgs[0] == 0) ? gAudioCtx.audioRandom & 0xFFFF : gAudioCtx.audioRandom % cmdArgs[0]; break; case 0xBD: @@ -1664,12 +1664,12 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { case 0x10: if (lowBits < 8) { - channel->soundScriptIO[lowBits] = -1; + channel->soundScriptIO[lowBits] = SEQ_IO_VAL_NONE; if (AudioLoad_SlowLoadSample(channel->fontId, scriptState->value, &channel->soundScriptIO[lowBits]) == -1) {} } else { lowBits -= 8; - channel->soundScriptIO[lowBits] = -1; + channel->soundScriptIO[lowBits] = SEQ_IO_VAL_NONE; if (AudioLoad_SlowLoadSample(channel->fontId, channel->unk_22 + 0x100, &channel->soundScriptIO[lowBits]) == -1) {} } @@ -1678,7 +1678,7 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { case 0x60: scriptState->value = channel->soundScriptIO[lowBits]; if (lowBits < 2) { - channel->soundScriptIO[lowBits] = -1; + channel->soundScriptIO[lowBits] = SEQ_IO_VAL_NONE; } break; @@ -1746,11 +1746,11 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { seqPlayer->tempoAcc += seqPlayer->tempo; seqPlayer->tempoAcc += (s16)seqPlayer->unk_0C; - if (seqPlayer->tempoAcc < gAudioContext.tempoInternalToExternal) { + if (seqPlayer->tempoAcc < gAudioCtx.tempoInternalToExternal) { return; } - seqPlayer->tempoAcc -= (u16)gAudioContext.tempoInternalToExternal; + seqPlayer->tempoAcc -= (u16)gAudioCtx.tempoInternalToExternal; if (seqPlayer->stopScript == true) { return; @@ -1811,8 +1811,8 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { case 0xDD: seqPlayer->tempo = AudioSeq_ScriptReadU8(seqScript) * TATUMS_PER_BEAT; - if (seqPlayer->tempo > gAudioContext.tempoInternalToExternal) { - seqPlayer->tempo = (u16)gAudioContext.tempoInternalToExternal; + if (seqPlayer->tempo > gAudioCtx.tempoInternalToExternal) { + seqPlayer->tempo = (u16)gAudioCtx.tempoInternalToExternal; } if ((s16)seqPlayer->tempo <= 0) { @@ -1909,9 +1909,9 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { case 0xCE: cmd = AudioSeq_ScriptReadU8(seqScript); if (cmd == 0) { - seqScript->value = (gAudioContext.audioRandom >> 2) & 0xFF; + seqScript->value = (gAudioCtx.audioRandom >> 2) & 0xFF; } else { - seqScript->value = (gAudioContext.audioRandom >> 2) % cmd; + seqScript->value = (gAudioCtx.audioRandom >> 2) % cmd; } break; @@ -1992,7 +1992,7 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { case 0x80: seqScript->value = seqPlayer->soundScriptIO[cmdLowBits]; if (cmdLowBits < 2) { - seqPlayer->soundScriptIO[cmdLowBits] = -1; + seqPlayer->soundScriptIO[cmdLowBits] = SEQ_IO_VAL_NONE; } break; @@ -2038,11 +2038,10 @@ void AudioSeq_ProcessSequences(s32 arg0) { SequencePlayer* seqPlayer; u32 i; - gAudioContext.noteSubEuOffset = - (gAudioContext.audioBufferParameters.updatesPerFrame - arg0 - 1) * gAudioContext.numNotes; + gAudioCtx.noteSubEuOffset = (gAudioCtx.audioBufferParameters.updatesPerFrame - arg0 - 1) * gAudioCtx.numNotes; - for (i = 0; i < (u32)gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - seqPlayer = &gAudioContext.seqPlayers[i]; + for (i = 0; i < (u32)gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + seqPlayer = &gAudioCtx.seqPlayers[i]; if (seqPlayer->enabled == true) { AudioSeq_SequencePlayerProcessSequence(seqPlayer); Audio_SequencePlayerProcessSound(seqPlayer); @@ -2089,14 +2088,14 @@ void AudioSeq_ResetSequencePlayer(SequencePlayer* seqPlayer) { void AudioSeq_InitSequencePlayerChannels(s32 playerIdx) { SequenceChannel* channel; - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx]; s32 i; s32 j; for (i = 0; i < SEQ_NUM_CHANNELS; i++) { - seqPlayer->channels[i] = AudioHeap_AllocZeroed(&gAudioContext.miscPool, sizeof(SequenceChannel)); + seqPlayer->channels[i] = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(SequenceChannel)); if (seqPlayer->channels[i] == NULL) { - seqPlayer->channels[i] = &gAudioContext.sequenceChannelNone; + seqPlayer->channels[i] = &gAudioCtx.sequenceChannelNone; } else { channel = seqPlayer->channels[i]; channel->seqPlayer = seqPlayer; @@ -2114,7 +2113,7 @@ void AudioSeq_InitSequencePlayer(SequencePlayer* seqPlayer) { s32 j; for (i = 0; i < SEQ_NUM_CHANNELS; i++) { - seqPlayer->channels[i] = &gAudioContext.sequenceChannelNone; + seqPlayer->channels[i] = &gAudioCtx.sequenceChannelNone; } seqPlayer->enabled = false; @@ -2124,7 +2123,7 @@ void AudioSeq_InitSequencePlayer(SequencePlayer* seqPlayer) { seqPlayer->applyBend = false; for (j = 0; j < ARRAY_COUNT(seqPlayer->soundScriptIO); j++) { - seqPlayer->soundScriptIO[j] = -1; + seqPlayer->soundScriptIO[j] = SEQ_IO_VAL_NONE; } seqPlayer->muteBehavior = MUTE_BEHAVIOR_SOFTEN | MUTE_BEHAVIOR_STOP_NOTES; @@ -2139,12 +2138,12 @@ void AudioSeq_InitSequencePlayers(void) { AudioSeq_InitLayerFreelist(); - for (i = 0; i < ARRAY_COUNT(gAudioContext.sequenceLayers); i++) { - gAudioContext.sequenceLayers[i].channel = NULL; - gAudioContext.sequenceLayers[i].enabled = false; + for (i = 0; i < ARRAY_COUNT(gAudioCtx.sequenceLayers); i++) { + gAudioCtx.sequenceLayers[i].channel = NULL; + gAudioCtx.sequenceLayers[i].enabled = false; } - for (i = 0; i < ARRAY_COUNT(gAudioContext.seqPlayers); i++) { - AudioSeq_InitSequencePlayer(&gAudioContext.seqPlayers[i]); + for (i = 0; i < ARRAY_COUNT(gAudioCtx.seqPlayers); i++) { + AudioSeq_InitSequencePlayer(&gAudioCtx.seqPlayers[i]); } } diff --git a/src/code/audio_synthesis.c b/src/code/audio_synthesis.c index 587b7e60e0..ca7467f91c 100644 --- a/src/code/audio_synthesis.c +++ b/src/code/audio_synthesis.c @@ -61,7 +61,7 @@ u8 sNumSamplesPerWavePeriod[] = { void AudioSynth_InitNextRingBuf(s32 chunkLen, s32 updateIndex, s32 reverbIndex) { ReverbRingBufferItem* bufItem; s32 pad[3]; - SynthesisReverb* reverb = &gAudioContext.synthesisReverbs[reverbIndex]; + SynthesisReverb* reverb = &gAudioCtx.synthesisReverbs[reverbIndex]; s32 temp_a0_2; s32 temp_a0_4; s32 numSamples; @@ -135,10 +135,10 @@ void func_800DB03C(s32 updateIndex) { s32 baseIndex; s32 i; - baseIndex = gAudioContext.numNotes * updateIndex; - for (i = 0; i < gAudioContext.numNotes; i++) { - subEu = &gAudioContext.notes[i].noteSubEu; - subEu2 = &gAudioContext.noteSubsEu[baseIndex + i]; + baseIndex = gAudioCtx.numNotes * updateIndex; + for (i = 0; i < gAudioCtx.numNotes; i++) { + subEu = &gAudioCtx.notes[i].noteSubEu; + subEu2 = &gAudioCtx.noteSubsEu[baseIndex + i]; if (subEu->bitField0.enabled) { subEu->bitField0.needsInit = false; } else { @@ -158,42 +158,41 @@ Acmd* AudioSynth_Update(Acmd* cmdStart, s32* cmdCnt, s16* aiStart, s32 aiBufLen) SynthesisReverb* reverb; cmdP = cmdStart; - for (i = gAudioContext.audioBufferParameters.updatesPerFrame; i > 0; i--) { + for (i = gAudioCtx.audioBufferParameters.updatesPerFrame; i > 0; i--) { AudioSeq_ProcessSequences(i - 1); - func_800DB03C(gAudioContext.audioBufferParameters.updatesPerFrame - i); + func_800DB03C(gAudioCtx.audioBufferParameters.updatesPerFrame - i); } aiBufP = aiStart; - gAudioContext.curLoadedBook = NULL; + gAudioCtx.curLoadedBook = NULL; - for (i = gAudioContext.audioBufferParameters.updatesPerFrame; i > 0; i--) { + for (i = gAudioCtx.audioBufferParameters.updatesPerFrame; i > 0; i--) { if (i == 1) { chunkLen = aiBufLen; - } else if ((aiBufLen / i) >= gAudioContext.audioBufferParameters.samplesPerUpdateMax) { - chunkLen = gAudioContext.audioBufferParameters.samplesPerUpdateMax; - } else if (gAudioContext.audioBufferParameters.samplesPerUpdateMin >= (aiBufLen / i)) { - chunkLen = gAudioContext.audioBufferParameters.samplesPerUpdateMin; + } else if ((aiBufLen / i) >= gAudioCtx.audioBufferParameters.samplesPerUpdateMax) { + chunkLen = gAudioCtx.audioBufferParameters.samplesPerUpdateMax; + } else if (gAudioCtx.audioBufferParameters.samplesPerUpdateMin >= (aiBufLen / i)) { + chunkLen = gAudioCtx.audioBufferParameters.samplesPerUpdateMin; } else { - chunkLen = gAudioContext.audioBufferParameters.samplesPerUpdate; + chunkLen = gAudioCtx.audioBufferParameters.samplesPerUpdate; } - for (j = 0; j < gAudioContext.numSynthesisReverbs; j++) { - if (gAudioContext.synthesisReverbs[j].useReverb) { - AudioSynth_InitNextRingBuf(chunkLen, gAudioContext.audioBufferParameters.updatesPerFrame - i, j); + for (j = 0; j < gAudioCtx.numSynthesisReverbs; j++) { + if (gAudioCtx.synthesisReverbs[j].useReverb) { + AudioSynth_InitNextRingBuf(chunkLen, gAudioCtx.audioBufferParameters.updatesPerFrame - i, j); } } - cmdP = AudioSynth_DoOneAudioUpdate(aiBufP, chunkLen, cmdP, - gAudioContext.audioBufferParameters.updatesPerFrame - i); + cmdP = AudioSynth_DoOneAudioUpdate(aiBufP, chunkLen, cmdP, gAudioCtx.audioBufferParameters.updatesPerFrame - i); aiBufLen -= chunkLen; aiBufP += 2 * chunkLen; } - for (j = 0; j < gAudioContext.numSynthesisReverbs; j++) { - if (gAudioContext.synthesisReverbs[j].framesToIgnore != 0) { - gAudioContext.synthesisReverbs[j].framesToIgnore--; + for (j = 0; j < gAudioCtx.numSynthesisReverbs; j++) { + if (gAudioCtx.synthesisReverbs[j].framesToIgnore != 0) { + gAudioCtx.synthesisReverbs[j].framesToIgnore--; } - gAudioContext.synthesisReverbs[j].curFrame ^= 1; + gAudioCtx.synthesisReverbs[j].curFrame ^= 1; } *cmdCnt = cmdP - cmdStart; @@ -204,8 +203,8 @@ void func_800DB2C0(s32 updateIndex, s32 noteIndex) { NoteSubEu* noteSubEu; s32 i; - for (i = updateIndex + 1; i < gAudioContext.audioBufferParameters.updatesPerFrame; i++) { - noteSubEu = &gAudioContext.noteSubsEu[(gAudioContext.numNotes * i) + noteIndex]; + for (i = updateIndex + 1; i < gAudioCtx.audioBufferParameters.updatesPerFrame; i++) { + noteSubEu = &gAudioCtx.noteSubsEu[(gAudioCtx.numNotes * i) + noteIndex]; if (!noteSubEu->bitField0.needsInit) { noteSubEu->bitField0.enabled = false; } else { @@ -332,7 +331,7 @@ Acmd* AudioSynth_FilterReverb(Acmd* cmd, s32 size, SynthesisReverb* reverb) { Acmd* AudioSynth_MaybeMixRingBuffer1(Acmd* cmd, SynthesisReverb* reverb, s32 updateIndex) { SynthesisReverb* temp_a3; - temp_a3 = &gAudioContext.synthesisReverbs[reverb->unk_05]; + temp_a3 = &gAudioCtx.synthesisReverbs[reverb->unk_05]; if (temp_a3->downsampleRate == 1) { cmd = AudioSynth_LoadRingBuffer1AtTemp(cmd, temp_a3, updateIndex); aMix(cmd++, DMEM_2CH_SIZE >> 4, reverb->unk_08, DMEM_WET_LEFT_CH, DMEM_WET_TEMP); @@ -593,27 +592,27 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat NoteSubEu* noteSubEu2; s32 unk14; - t = gAudioContext.numNotes * updateIndex; + t = gAudioCtx.numNotes * updateIndex; count = 0; - if (gAudioContext.numSynthesisReverbs == 0) { - for (i = 0; i < gAudioContext.numNotes; i++) { - if (gAudioContext.noteSubsEu[t + i].bitField0.enabled) { + if (gAudioCtx.numSynthesisReverbs == 0) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + if (gAudioCtx.noteSubsEu[t + i].bitField0.enabled) { noteIndices[count++] = i; } } } else { - for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) { - for (i = 0; i < gAudioContext.numNotes; i++) { - noteSubEu = &gAudioContext.noteSubsEu[t + i]; + for (reverbIndex = 0; reverbIndex < gAudioCtx.numSynthesisReverbs; reverbIndex++) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + noteSubEu = &gAudioCtx.noteSubsEu[t + i]; if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex == reverbIndex) { noteIndices[count++] = i; } } } - for (i = 0; i < gAudioContext.numNotes; i++) { - noteSubEu = &gAudioContext.noteSubsEu[t + i]; - if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex >= gAudioContext.numSynthesisReverbs) { + for (i = 0; i < gAudioCtx.numNotes; i++) { + noteSubEu = &gAudioCtx.noteSubsEu[t + i]; + if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex >= gAudioCtx.numSynthesisReverbs) { noteIndices[count++] = i; } } @@ -622,8 +621,8 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat aClearBuffer(cmd++, DMEM_LEFT_CH, DMEM_2CH_SIZE); i = 0; - for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) { - reverb = &gAudioContext.synthesisReverbs[reverbIndex]; + for (reverbIndex = 0; reverbIndex < gAudioCtx.numSynthesisReverbs; reverbIndex++) { + reverb = &gAudioCtx.synthesisReverbs[reverbIndex]; useReverb = reverb->useReverb; if (useReverb) { @@ -660,11 +659,11 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat } while (i < count) { - noteSubEu2 = &gAudioContext.noteSubsEu[noteIndices[i] + t]; + noteSubEu2 = &gAudioCtx.noteSubsEu[noteIndices[i] + t]; if (noteSubEu2->bitField1.reverbIndex == reverbIndex) { - cmd = AudioSynth_ProcessNote(noteIndices[i], noteSubEu2, - &gAudioContext.notes[noteIndices[i]].synthesisState, aiBuf, aiBufLen, cmd, - updateIndex); + cmd = + AudioSynth_ProcessNote(noteIndices[i], noteSubEu2, &gAudioCtx.notes[noteIndices[i]].synthesisState, + aiBuf, aiBufLen, cmd, updateIndex); } else { break; } @@ -689,9 +688,9 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat } while (i < count) { - cmd = AudioSynth_ProcessNote(noteIndices[i], &gAudioContext.noteSubsEu[t + noteIndices[i]], - &gAudioContext.notes[noteIndices[i]].synthesisState, aiBuf, aiBufLen, cmd, - updateIndex); + cmd = + AudioSynth_ProcessNote(noteIndices[i], &gAudioCtx.noteSubsEu[t + noteIndices[i]], + &gAudioCtx.notes[noteIndices[i]].synthesisState, aiBuf, aiBufLen, cmd, updateIndex); i++; } @@ -756,7 +755,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS bookOffset = noteSubEu->bitField1.bookOffset; finished = noteSubEu->bitField0.finished; - note = &gAudioContext.notes[noteIndex]; + note = &gAudioCtx.notes[noteIndex]; flags = A_CONTINUE; if (noteSubEu->bitField0.needsInit == true) { @@ -814,24 +813,24 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS } if (sample->codec == CODEC_ADPCM || sample->codec == CODEC_SMALL_ADPCM) { - if (gAudioContext.curLoadedBook != sample->book->book) { + if (gAudioCtx.curLoadedBook != sample->book->book) { u32 nEntries; switch (bookOffset) { case 1: - gAudioContext.curLoadedBook = &D_8012FBA8[1]; + gAudioCtx.curLoadedBook = &D_8012FBA8[1]; break; case 2: case 3: default: - gAudioContext.curLoadedBook = sample->book->book; + gAudioCtx.curLoadedBook = sample->book->book; break; } if (1) {} if (1) {} if (1) {} nEntries = SAMPLES_PER_FRAME * sample->book->order * sample->book->numPredictors; - aLoadADPCM(cmd++, nEntries, gAudioContext.curLoadedBook); + aLoadADPCM(cmd++, nEntries, gAudioCtx.curLoadedBook); } } diff --git a/src/code/code_800E4FE0.c b/src/code/code_800E4FE0.c index 3b140b6cf7..7b575d025a 100644 --- a/src/code/code_800E4FE0.c +++ b/src/code/code_800E4FE0.c @@ -53,32 +53,32 @@ AudioTask* func_800E5000(void) { s32 sp48; s32 i; - gAudioContext.totalTaskCount++; - if (gAudioContext.totalTaskCount % (gAudioContext.audioBufferParameters.specUnk4) != 0) { + gAudioCtx.totalTaskCount++; + if (gAudioCtx.totalTaskCount % (gAudioCtx.audioBufferParameters.specUnk4) != 0) { if (D_801755D0 != NULL) { D_801755D0(); } - if ((gAudioContext.totalTaskCount % gAudioContext.audioBufferParameters.specUnk4) + 1 == - gAudioContext.audioBufferParameters.specUnk4) { + if ((gAudioCtx.totalTaskCount % gAudioCtx.audioBufferParameters.specUnk4) + 1 == + gAudioCtx.audioBufferParameters.specUnk4) { return sWaitingAudioTask; } else { return NULL; } } - osSendMesg(gAudioContext.taskStartQueueP, (OSMesg)gAudioContext.totalTaskCount, OS_MESG_NOBLOCK); - gAudioContext.rspTaskIndex ^= 1; - gAudioContext.curAiBufIndex++; - gAudioContext.curAiBufIndex %= 3; - index = (gAudioContext.curAiBufIndex - 2 + 3) % 3; + osSendMesg(gAudioCtx.taskStartQueueP, (OSMesg)gAudioCtx.totalTaskCount, OS_MESG_NOBLOCK); + gAudioCtx.rspTaskIndex ^= 1; + gAudioCtx.curAiBufIndex++; + gAudioCtx.curAiBufIndex %= 3; + index = (gAudioCtx.curAiBufIndex - 2 + 3) % 3; samplesRemainingInAi = osAiGetLength() / 4; - if (gAudioContext.resetTimer < 16) { - if (gAudioContext.aiBufLengths[index] != 0) { - osAiSetNextBuffer(gAudioContext.aiBuffers[index], gAudioContext.aiBufLengths[index] * 4); - if (gAudioContext.aiBuffers[index]) {} - if (gAudioContext.aiBufLengths[index]) {} + if (gAudioCtx.resetTimer < 16) { + if (gAudioCtx.aiBufLengths[index] != 0) { + osAiSetNextBuffer(gAudioCtx.aiBuffers[index], gAudioCtx.aiBufLengths[index] * 4); + if (gAudioCtx.aiBuffers[index]) {} + if (gAudioCtx.aiBufLengths[index]) {} } } @@ -86,36 +86,35 @@ AudioTask* func_800E5000(void) { D_801755D0(); } - sp5C = gAudioContext.curAudioFrameDmaCount; - for (i = 0; i < gAudioContext.curAudioFrameDmaCount; i++) { - if (osRecvMesg(&gAudioContext.currAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK) == 0) { + sp5C = gAudioCtx.curAudioFrameDmaCount; + for (i = 0; i < gAudioCtx.curAudioFrameDmaCount; i++) { + if (osRecvMesg(&gAudioCtx.currAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK) == 0) { sp5C--; } } if (sp5C != 0) { for (i = 0; i < sp5C; i++) { - osRecvMesg(&gAudioContext.currAudioFrameDmaQueue, NULL, OS_MESG_BLOCK); + osRecvMesg(&gAudioCtx.currAudioFrameDmaQueue, NULL, OS_MESG_BLOCK); } } - sp48 = MQ_GET_COUNT(&gAudioContext.currAudioFrameDmaQueue); + sp48 = MQ_GET_COUNT(&gAudioCtx.currAudioFrameDmaQueue); if (sp48 != 0) { for (i = 0; i < sp48; i++) { - osRecvMesg(&gAudioContext.currAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK); + osRecvMesg(&gAudioCtx.currAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK); } } - gAudioContext.curAudioFrameDmaCount = 0; + gAudioCtx.curAudioFrameDmaCount = 0; AudioLoad_DecreaseSampleDmaTtls(); - AudioLoad_ProcessLoads(gAudioContext.resetStatus); + AudioLoad_ProcessLoads(gAudioCtx.resetStatus); AudioLoad_ProcessScriptLoads(); - if (gAudioContext.resetStatus != 0) { + if (gAudioCtx.resetStatus != 0) { if (AudioHeap_ResetStep() == 0) { - if (gAudioContext.resetStatus == 0) { - osSendMesg(gAudioContext.audioResetQueueP, (OSMesg)(u32)gAudioContext.audioResetSpecIdToLoad, - OS_MESG_NOBLOCK); + if (gAudioCtx.resetStatus == 0) { + osSendMesg(gAudioCtx.audioResetQueueP, (OSMesg)(u32)gAudioCtx.audioResetSpecIdToLoad, OS_MESG_NOBLOCK); } sWaitingAudioTask = NULL; @@ -123,63 +122,62 @@ AudioTask* func_800E5000(void) { } } - if (gAudioContext.resetTimer > 16) { + if (gAudioCtx.resetTimer > 16) { return NULL; } - if (gAudioContext.resetTimer != 0) { - gAudioContext.resetTimer++; + if (gAudioCtx.resetTimer != 0) { + gAudioCtx.resetTimer++; } - gAudioContext.curTask = &gAudioContext.rspTask[gAudioContext.rspTaskIndex]; - gAudioContext.curAbiCmdBuf = gAudioContext.abiCmdBufs[gAudioContext.rspTaskIndex]; + gAudioCtx.curTask = &gAudioCtx.rspTask[gAudioCtx.rspTaskIndex]; + gAudioCtx.curAbiCmdBuf = gAudioCtx.abiCmdBufs[gAudioCtx.rspTaskIndex]; - index = gAudioContext.curAiBufIndex; - currAiBuffer = gAudioContext.aiBuffers[index]; + index = gAudioCtx.curAiBufIndex; + currAiBuffer = gAudioCtx.aiBuffers[index]; - gAudioContext.aiBufLengths[index] = - (s16)((((gAudioContext.audioBufferParameters.samplesPerFrameTarget - samplesRemainingInAi) + + gAudioCtx.aiBufLengths[index] = + (s16)((((gAudioCtx.audioBufferParameters.samplesPerFrameTarget - samplesRemainingInAi) + EXTRA_BUFFERED_AI_SAMPLES_TARGET) & ~0xF) + SAMPLES_TO_OVERPRODUCE); - if (gAudioContext.aiBufLengths[index] < gAudioContext.audioBufferParameters.minAiBufferLength) { - gAudioContext.aiBufLengths[index] = gAudioContext.audioBufferParameters.minAiBufferLength; + if (gAudioCtx.aiBufLengths[index] < gAudioCtx.audioBufferParameters.minAiBufferLength) { + gAudioCtx.aiBufLengths[index] = gAudioCtx.audioBufferParameters.minAiBufferLength; } - if (gAudioContext.aiBufLengths[index] > gAudioContext.audioBufferParameters.maxAiBufferLength) { - gAudioContext.aiBufLengths[index] = gAudioContext.audioBufferParameters.maxAiBufferLength; + if (gAudioCtx.aiBufLengths[index] > gAudioCtx.audioBufferParameters.maxAiBufferLength) { + gAudioCtx.aiBufLengths[index] = gAudioCtx.audioBufferParameters.maxAiBufferLength; } j = 0; - if (gAudioContext.resetStatus == 0) { + if (gAudioCtx.resetStatus == 0) { // msg = 0000RREE R = read pos, E = End Pos - while (osRecvMesg(gAudioContext.cmdProcQueueP, (OSMesg*)&sp4C, OS_MESG_NOBLOCK) != -1) { + while (osRecvMesg(gAudioCtx.cmdProcQueueP, (OSMesg*)&sp4C, OS_MESG_NOBLOCK) != -1) { if (1) {} Audio_ProcessCmds(sp4C); j++; } - if ((j == 0) && (gAudioContext.cmdQueueFinished)) { + if ((j == 0) && (gAudioCtx.cmdQueueFinished)) { Audio_ScheduleProcessCmds(); } } - gAudioContext.curAbiCmdBuf = - AudioSynth_Update(gAudioContext.curAbiCmdBuf, &abiCmdCnt, currAiBuffer, gAudioContext.aiBufLengths[index]); + gAudioCtx.curAbiCmdBuf = + AudioSynth_Update(gAudioCtx.curAbiCmdBuf, &abiCmdCnt, currAiBuffer, gAudioCtx.aiBufLengths[index]); // Update audioRandom to the next random number - gAudioContext.audioRandom = (gAudioContext.audioRandom + gAudioContext.totalTaskCount) * osGetCount(); - gAudioContext.audioRandom = - gAudioContext.audioRandom + gAudioContext.aiBuffers[index][gAudioContext.totalTaskCount & 0xFF]; + gAudioCtx.audioRandom = (gAudioCtx.audioRandom + gAudioCtx.totalTaskCount) * osGetCount(); + gAudioCtx.audioRandom = gAudioCtx.audioRandom + gAudioCtx.aiBuffers[index][gAudioCtx.totalTaskCount & 0xFF]; // gWaveSamples[8] interprets compiled assembly code as s16 samples as a way to generate sound with noise. // Start with the address of func_800E4FE0, and offset it by a random number between 0 - 0xFFF0 // Use the resulting address as the starting address to interpret an array of samples i.e. `s16 samples[]` - gWaveSamples[8] = (s16*)(((u8*)func_800E4FE0) + (gAudioContext.audioRandom & 0xFFF0)); + gWaveSamples[8] = (s16*)(((u8*)func_800E4FE0) + (gAudioCtx.audioRandom & 0xFFF0)); - index = gAudioContext.rspTaskIndex; - gAudioContext.curTask->msgQueue = NULL; - gAudioContext.curTask->unk_44 = NULL; + index = gAudioCtx.rspTaskIndex; + gAudioCtx.curTask->msgQueue = NULL; + gAudioCtx.curTask->unk_44 = NULL; - task = &gAudioContext.curTask->task.t; + task = &gAudioCtx.curTask->task.t; task->type = M_AUDTASK; task->flags = 0; task->ucode_boot = aspMainTextStart; @@ -193,7 +191,7 @@ AudioTask* func_800E5000(void) { task->output_buff = NULL; task->output_buff_size = NULL; if (1) {} - task->data_ptr = (u64*)gAudioContext.abiCmdBufs[index]; + task->data_ptr = (u64*)gAudioCtx.abiCmdBufs[index]; task->data_size = abiCmdCnt * sizeof(Acmd); task->yield_data_ptr = NULL; task->yield_data_size = 0; @@ -202,10 +200,10 @@ AudioTask* func_800E5000(void) { sMaxAbiCmdCnt = abiCmdCnt; } - if (gAudioContext.audioBufferParameters.specUnk4 == 1) { - return gAudioContext.curTask; + if (gAudioCtx.audioBufferParameters.specUnk4 == 1) { + return gAudioCtx.curTask; } else { - sWaitingAudioTask = gAudioContext.curTask; + sWaitingAudioTask = gAudioCtx.curTask; return NULL; } } @@ -235,9 +233,9 @@ void func_800E5584(AudioCmd* cmd) { break; case 0x83: - if (gAudioContext.seqPlayers[cmd->arg0].enabled) { + if (gAudioCtx.seqPlayers[cmd->arg0].enabled) { if (cmd->asInt == 0) { - AudioSeq_SequencePlayerDisableAsFinished(&gAudioContext.seqPlayers[cmd->arg0]); + AudioSeq_SequencePlayerDisableAsFinished(&gAudioCtx.seqPlayers[cmd->arg0]); } else { func_800E5958(cmd->arg0, cmd->asInt); } @@ -245,12 +243,12 @@ void func_800E5584(AudioCmd* cmd) { break; case 0xF0: - gAudioContext.soundMode = cmd->asUInt; + gAudioCtx.soundMode = cmd->asUInt; break; case 0xF1: - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[i]; seqPlayer->muted = 1; seqPlayer->recalculateVolume = 1; @@ -259,8 +257,8 @@ void func_800E5584(AudioCmd* cmd) { case 0xF2: if (cmd->asUInt == 1) { - for (i = 0; i < gAudioContext.numNotes; i++) { - Note* note = &gAudioContext.notes[i]; + for (i = 0; i < gAudioCtx.numNotes; i++) { + Note* note = &gAudioCtx.notes[i]; NoteSubEu* subEu = ¬e->noteSubEu; if (subEu->bitField0.enabled && note->playbackState.unk_04 == 0) { @@ -271,8 +269,8 @@ void func_800E5584(AudioCmd* cmd) { } } - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[i]; seqPlayer->muted = 0; seqPlayer->recalculateVolume = 1; @@ -284,15 +282,15 @@ void func_800E5584(AudioCmd* cmd) { break; case 0xF4: - AudioLoad_AsyncLoadSampleBank(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue); + AudioLoad_AsyncLoadSampleBank(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue); break; case 0xF5: - AudioLoad_AsyncLoadFont(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue); + AudioLoad_AsyncLoadFont(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue); break; case 0xFC: - AudioLoad_AsyncLoadSeq(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue); + AudioLoad_AsyncLoadSeq(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue); break; case 0xF6: @@ -300,12 +298,12 @@ void func_800E5584(AudioCmd* cmd) { break; case 0x90: - gAudioContext.unk_5BDC[cmd->arg0] = cmd->asUShort; + gAudioCtx.unk_5BDC[cmd->arg0] = cmd->asUShort; break; case 0xF9: - gAudioContext.resetStatus = 5; - gAudioContext.audioResetSpecIdToLoad = cmd->asUInt; + gAudioCtx.resetStatus = 5; + gAudioCtx.audioResetSpecIdToLoad = cmd->asUInt; break; case 0xFB: @@ -321,8 +319,8 @@ void func_800E5584(AudioCmd* cmd) { case 0xFE: temp_t7 = cmd->asUInt; if (temp_t7 == 1) { - for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; + for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) { + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[i]; if (seqPlayer->enabled) { AudioSeq_SequencePlayerDisableAsFinished(seqPlayer); @@ -343,7 +341,7 @@ void func_800E5584(AudioCmd* cmd) { // SetFadeOutTimer void func_800E5958(s32 playerIdx, s32 fadeTimer) { - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx]; if (fadeTimer == 0) { fadeTimer = 1; @@ -359,7 +357,7 @@ void func_800E59AC(s32 playerIdx, s32 fadeTimer) { SequencePlayer* seqPlayer; if (fadeTimer != 0) { - seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + seqPlayer = &gAudioCtx.seqPlayers[playerIdx]; seqPlayer->state = 1; seqPlayer->fadeTimerUnkEu = fadeTimer; seqPlayer->fadeTimer = fadeTimer; @@ -369,30 +367,27 @@ void func_800E59AC(s32 playerIdx, s32 fadeTimer) { } void Audio_InitMesgQueuesInternal(void) { - gAudioContext.cmdWrPos = 0; - gAudioContext.cmdRdPos = 0; - gAudioContext.cmdQueueFinished = 0; - gAudioContext.taskStartQueueP = &gAudioContext.taskStartQueue; - gAudioContext.cmdProcQueueP = &gAudioContext.cmdProcQueue; - gAudioContext.audioResetQueueP = &gAudioContext.audioResetQueue; - osCreateMesgQueue(gAudioContext.taskStartQueueP, gAudioContext.taskStartMsgBuf, - ARRAY_COUNT(gAudioContext.taskStartMsgBuf)); - osCreateMesgQueue(gAudioContext.cmdProcQueueP, gAudioContext.cmdProcMsgBuf, - ARRAY_COUNT(gAudioContext.cmdProcMsgBuf)); - osCreateMesgQueue(gAudioContext.audioResetQueueP, gAudioContext.audioResetMsgBuf, - ARRAY_COUNT(gAudioContext.audioResetMsgBuf)); + gAudioCtx.cmdWrPos = 0; + gAudioCtx.cmdRdPos = 0; + gAudioCtx.cmdQueueFinished = 0; + gAudioCtx.taskStartQueueP = &gAudioCtx.taskStartQueue; + gAudioCtx.cmdProcQueueP = &gAudioCtx.cmdProcQueue; + gAudioCtx.audioResetQueueP = &gAudioCtx.audioResetQueue; + osCreateMesgQueue(gAudioCtx.taskStartQueueP, gAudioCtx.taskStartMsgBuf, ARRAY_COUNT(gAudioCtx.taskStartMsgBuf)); + osCreateMesgQueue(gAudioCtx.cmdProcQueueP, gAudioCtx.cmdProcMsgBuf, ARRAY_COUNT(gAudioCtx.cmdProcMsgBuf)); + osCreateMesgQueue(gAudioCtx.audioResetQueueP, gAudioCtx.audioResetMsgBuf, ARRAY_COUNT(gAudioCtx.audioResetMsgBuf)); } void Audio_QueueCmd(u32 opArgs, void** data) { - AudioCmd* cmd = &gAudioContext.cmdBuf[gAudioContext.cmdWrPos & 0xFF]; + AudioCmd* cmd = &gAudioCtx.cmdBuf[gAudioCtx.cmdWrPos & 0xFF]; cmd->opArgs = opArgs; cmd->data = *data; - gAudioContext.cmdWrPos++; + gAudioCtx.cmdWrPos++; - if (gAudioContext.cmdWrPos == gAudioContext.cmdRdPos) { - gAudioContext.cmdWrPos--; + if (gAudioCtx.cmdWrPos == gAudioCtx.cmdRdPos) { + gAudioCtx.cmdWrPos--; } } @@ -420,15 +415,14 @@ s32 Audio_ScheduleProcessCmds(void) { static s32 D_801304E8 = 0; s32 ret; - if (D_801304E8 < (u8)((gAudioContext.cmdWrPos - gAudioContext.cmdRdPos) + 0x100)) { - D_801304E8 = (u8)((gAudioContext.cmdWrPos - gAudioContext.cmdRdPos) + 0x100); + if (D_801304E8 < (u8)((gAudioCtx.cmdWrPos - gAudioCtx.cmdRdPos) + 0x100)) { + D_801304E8 = (u8)((gAudioCtx.cmdWrPos - gAudioCtx.cmdRdPos) + 0x100); } - ret = - osSendMesg(gAudioContext.cmdProcQueueP, - (OSMesg)(((gAudioContext.cmdRdPos & 0xFF) << 8) | (gAudioContext.cmdWrPos & 0xFF)), OS_MESG_NOBLOCK); + ret = osSendMesg(gAudioCtx.cmdProcQueueP, + (OSMesg)(((gAudioCtx.cmdRdPos & 0xFF) << 8) | (gAudioCtx.cmdWrPos & 0xFF)), OS_MESG_NOBLOCK); if (ret != -1) { - gAudioContext.cmdRdPos = gAudioContext.cmdWrPos; + gAudioCtx.cmdRdPos = gAudioCtx.cmdWrPos; ret = 0; } else { return -1; @@ -438,8 +432,8 @@ s32 Audio_ScheduleProcessCmds(void) { } void Audio_ResetCmdQueue(void) { - gAudioContext.cmdQueueFinished = 0; - gAudioContext.cmdRdPos = gAudioContext.cmdWrPos; + gAudioCtx.cmdQueueFinished = 0; + gAudioCtx.cmdRdPos = gAudioCtx.cmdWrPos; } void Audio_ProcessCmd(AudioCmd* cmd) { @@ -452,8 +446,8 @@ void Audio_ProcessCmd(AudioCmd* cmd) { return; } - if (cmd->arg0 < gAudioContext.audioBufferParameters.numSequencePlayers) { - seqPlayer = &gAudioContext.seqPlayers[cmd->arg0]; + if (cmd->arg0 < gAudioCtx.audioBufferParameters.numSequencePlayers) { + seqPlayer = &gAudioCtx.seqPlayers[cmd->arg0]; if (cmd->op & 0x80) { func_800E5584(cmd); return; @@ -468,7 +462,7 @@ void Audio_ProcessCmd(AudioCmd* cmd) { return; } if (cmd->arg1 == 0xFF) { - phi_v0 = gAudioContext.unk_5BDC[cmd->arg0]; + phi_v0 = gAudioCtx.unk_5BDC[cmd->arg0]; for (i = 0; i < 16; i++) { if (phi_v0 & 1) { func_800E6300(seqPlayer->channels[i], cmd); @@ -484,20 +478,20 @@ void Audio_ProcessCmds(u32 msg) { AudioCmd* cmd; u8 endPos; - if (!gAudioContext.cmdQueueFinished) { + if (!gAudioCtx.cmdQueueFinished) { curCmdRdPos = msg >> 8; } while (true) { endPos = msg & 0xFF; if (curCmdRdPos == endPos) { - gAudioContext.cmdQueueFinished = 0; + gAudioCtx.cmdQueueFinished = 0; return; } - cmd = &gAudioContext.cmdBuf[curCmdRdPos++ & 0xFF]; + cmd = &gAudioCtx.cmdBuf[curCmdRdPos++ & 0xFF]; if (cmd->op == 0xF8) { - gAudioContext.cmdQueueFinished = 1; + gAudioCtx.cmdQueueFinished = 1; return; } @@ -509,7 +503,7 @@ void Audio_ProcessCmds(u32 msg) { u32 func_800E5E20(u32* out) { u32 sp1C; - if (osRecvMesg(&gAudioContext.externalLoadQueue, (OSMesg*)&sp1C, OS_MESG_NOBLOCK) == -1) { + if (osRecvMesg(&gAudioCtx.externalLoadQueue, (OSMesg*)&sp1C, OS_MESG_NOBLOCK) == -1) { *out = 0; return 0; } @@ -522,17 +516,17 @@ u8* func_800E5E84(s32 arg0, u32* arg1) { } void Audio_GetSampleBankIdsOfFont(s32 fontId, u32* sampleBankId1, u32* sampleBankId2) { - *sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; - *sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + *sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1; + *sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2; } s32 func_800E5EDC(void) { s32 pad; s32 sp18; - if (osRecvMesg(gAudioContext.audioResetQueueP, (OSMesg*)&sp18, OS_MESG_NOBLOCK) == -1) { + if (osRecvMesg(gAudioCtx.audioResetQueueP, (OSMesg*)&sp18, OS_MESG_NOBLOCK) == -1) { return 0; - } else if (gAudioContext.audioResetSpecIdToLoad != sp18) { + } else if (gAudioCtx.audioResetSpecIdToLoad != sp18) { return -1; } else { return 1; @@ -542,7 +536,7 @@ s32 func_800E5EDC(void) { void func_800E5F34(void) { // macro? // clang-format off - s32 chk = -1; OSMesg msg; do {} while (osRecvMesg(gAudioContext.audioResetQueueP, &msg, OS_MESG_NOBLOCK) != chk); + s32 chk = -1; OSMesg msg; do {} while (osRecvMesg(gAudioCtx.audioResetQueueP, &msg, OS_MESG_NOBLOCK) != chk); // clang-format on } @@ -552,16 +546,16 @@ s32 func_800E5F88(s32 resetPreloadID) { s32 pad; func_800E5F34(); - resetStatus = gAudioContext.resetStatus; + resetStatus = gAudioCtx.resetStatus; if (resetStatus != 0) { Audio_ResetCmdQueue(); - if (gAudioContext.audioResetSpecIdToLoad == resetPreloadID) { + if (gAudioCtx.audioResetSpecIdToLoad == resetPreloadID) { return -2; } else if (resetStatus > 2) { - gAudioContext.audioResetSpecIdToLoad = resetPreloadID; + gAudioCtx.audioResetSpecIdToLoad = resetPreloadID; return -3; } else { - osRecvMesg(gAudioContext.audioResetQueueP, &msg, OS_MESG_BLOCK); + osRecvMesg(gAudioCtx.audioResetQueueP, &msg, OS_MESG_BLOCK); } } @@ -572,15 +566,15 @@ s32 func_800E5F88(s32 resetPreloadID) { } void Audio_PreNMIInternal(void) { - gAudioContext.resetTimer = 1; + gAudioCtx.resetTimer = 1; if (gAudioContextInitialized) { func_800E5F88(0); - gAudioContext.resetStatus = 0; + gAudioCtx.resetStatus = 0; } } s8 func_800E6070(s32 playerIdx, s32 channelIdx, s32 scriptIdx) { - SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx]; SequenceChannel* channel; if (seqPlayer->enabled) { @@ -592,15 +586,15 @@ s8 func_800E6070(s32 playerIdx, s32 channelIdx, s32 scriptIdx) { } s8 func_800E60C4(s32 playerIdx, s32 port) { - return gAudioContext.seqPlayers[playerIdx].soundScriptIO[port]; + return gAudioCtx.seqPlayers[playerIdx].soundScriptIO[port]; } void Audio_InitExternalPool(void* ramAddr, u32 size) { - AudioHeap_InitPool(&gAudioContext.externalPool, ramAddr, size); + AudioHeap_InitPool(&gAudioCtx.externalPool, ramAddr, size); } void Audio_DestroyExternalPool(void) { - gAudioContext.externalPool.startRamAddr = NULL; + gAudioCtx.externalPool.startRamAddr = NULL; } void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) { @@ -780,8 +774,8 @@ void func_800E651C(u32 arg0, s32 arg1) { } void Audio_WaitForAudioTask(void) { - osRecvMesg(gAudioContext.taskStartQueueP, NULL, OS_MESG_NOBLOCK); - osRecvMesg(gAudioContext.taskStartQueueP, NULL, OS_MESG_BLOCK); + osRecvMesg(gAudioCtx.taskStartQueueP, NULL, OS_MESG_NOBLOCK); + osRecvMesg(gAudioCtx.taskStartQueueP, NULL, OS_MESG_BLOCK); } s32 func_800E6590(s32 playerIdx, s32 arg1, s32 arg2) { @@ -792,7 +786,7 @@ s32 func_800E6590(s32 playerIdx, s32 arg1, s32 arg2) { s32 loopEnd; s32 samplePos; - seqPlayer = &gAudioContext.seqPlayers[playerIdx]; + seqPlayer = &gAudioCtx.seqPlayers[playerIdx]; if (seqPlayer->enabled && seqPlayer->channels[arg1]->enabled) { layer = seqPlayer->channels[arg1]->layers[arg2]; if (layer == NULL) { @@ -841,8 +835,8 @@ s32 func_800E66C0(s32 arg0) { TunedSample* tunedSample; phi_v1 = 0; - for (i = 0; i < gAudioContext.numNotes; i++) { - note = &gAudioContext.notes[i]; + for (i = 0; i < gAudioCtx.numNotes; i++) { + note = &gAudioCtx.notes[i]; playbackState = ¬e->playbackState; if (note->noteSubEu.bitField0.enabled) { noteSubEu = ¬e->noteSubEu; @@ -859,7 +853,7 @@ s32 func_800E66C0(s32 arg0) { phi_v1++; if ((arg0 & 1) == 1) { - playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; + playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv; playbackState->adsr.action.s.release = 1; } } @@ -871,8 +865,8 @@ s32 func_800E66C0(s32 arg0) { u32 Audio_NextRandom(void) { static u32 audRand = 0x12345678; - audRand = ((osGetCount() + 0x1234567) * (audRand + gAudioContext.totalTaskCount)); - audRand += gAudioContext.audioRandom; + audRand = ((osGetCount() + 0x1234567) * (audRand + gAudioCtx.totalTaskCount)); + audRand += gAudioCtx.audioRandom; return audRand; } diff --git a/src/code/code_800EC960.c b/src/code/code_800EC960.c index db828c39af..7c649b6e33 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)) @@ -132,8 +112,11 @@ u8 sPrevSeqMode = 0; f32 sAudioEnemyDist = 0.0f; s8 sAudioEnemyVol = 127; u16 sPrevMainBgmSeqId = NA_BGM_DISABLED; -u8 D_8013062C = 0; -u8 D_80130630 = NA_BGM_GENERAL_SFX; + +#define SEQ_RESUME_POINT_NONE 0xC0 +u8 sSeqResumePoint = 0; +u8 sPrevSceneSeqId = NA_BGM_GENERAL_SFX; + u32 sNumFramesStill = 0; u32 sNumFramesMoving = 0; u8 sAudioBaseFilter = 0; @@ -148,12 +131,31 @@ u8 sSeqModeInput = 0; #define SEQ_FLAG_FANFARE (1 << 1) #define SEQ_FLAG_FANFARE_GANON (1 << 2) #define SEQ_FLAG_RESTORE (1 << 3) // required for func_800F5B58 to restore a sequence after func_800F5ACC -#define SEQ_FLAG_4 (1 << 4) -#define SEQ_FLAG_5 (1 << 5) -#define SEQ_FLAG_6 (1 << 6) + +/** + * These two sequence flags work together to implement a “resume playing from where you left off” system for scene + * sequences when leaving and returning to a scene. For a scene to resume playing from the point where it left off, it + * must have `SEQ_FLAG_RESUME` attached to it. Then, if the scene changes and the new scene sequence contain + * `SEQ_FLAG_RESUME_PREV`, the point from the previous scene sequence will be stored. Then, when returning to the + * scene with the sequence `SEQ_FLAG_RESUME`, then the sequence will resume playing from where it left off. + * + * There are only 5 sequences with `SEQ_FLAG_RESUME`, and all 5 of those sequences have special sequence + * instructions in their .seq files to read io port 7 and branch to different starting points along the sequence + * i.e. this system will only work for: kokiri forest, kakariko child, kakariko adult, zoras domain, gerudo valley + */ +#define SEQ_FLAG_RESUME (1 << 4) +#define SEQ_FLAG_RESUME_PREV (1 << 5) + +/** + * Will write a value of 1 to ioPort 7 when called through the scene. How it's used depends on the sequence: + * NA_BGM_CHAMBER_OF_SAGES - ioPort 7 is never read from + * NA_BGM_FILE_SELECT - ioPort 7 skips the harp intro when a value of 1 is written to it. + * Note: NA_BGM_FILE_SELECT is not called through the scene. So this flag serves no purpose + */ +#define SEQ_FLAG_SKIP_HARP_INTRO (1 << 6) #define SEQ_FLAG_NO_AMBIENCE (1 << 7) -u8 sSeqFlags[0x6E] = { +u8 sSeqFlags[] = { SEQ_FLAG_FANFARE, // NA_BGM_GENERAL_SFX SEQ_FLAG_ENEMY, // NA_BGM_NATURE_BACKGROUND 0, // NA_BGM_FIELD_LOGIC @@ -178,14 +180,14 @@ u8 sSeqFlags[0x6E] = { 0, // NA_BGM_FIELD_STILL_2 0, // NA_BGM_FIELD_STILL_3 0, // NA_BGM_FIELD_STILL_4 - SEQ_FLAG_5 | SEQ_FLAG_ENEMY, // NA_BGM_DUNGEON - SEQ_FLAG_4, // NA_BGM_KAKARIKO_ADULT + SEQ_FLAG_RESUME_PREV | SEQ_FLAG_ENEMY, // NA_BGM_DUNGEON + SEQ_FLAG_RESUME, // NA_BGM_KAKARIKO_ADULT 0, // NA_BGM_ENEMY SEQ_FLAG_NO_AMBIENCE | SEQ_FLAG_RESTORE, // NA_BGM_BOSS SEQ_FLAG_ENEMY, // NA_BGM_INSIDE_DEKU_TREE 0, // NA_BGM_MARKET 0, // NA_BGM_TITLE - SEQ_FLAG_5, // NA_BGM_LINK_HOUSE + SEQ_FLAG_RESUME_PREV, // NA_BGM_LINK_HOUSE 0, // NA_BGM_GAME_OVER 0, // NA_BGM_BOSS_CLEAR SEQ_FLAG_FANFARE, // NA_BGM_ITEM_GET @@ -193,7 +195,7 @@ u8 sSeqFlags[0x6E] = { SEQ_FLAG_FANFARE, // NA_BGM_HEART_GET SEQ_FLAG_FANFARE, // NA_BGM_OCA_LIGHT SEQ_FLAG_ENEMY, // NA_BGM_JABU_JABU - SEQ_FLAG_4, // NA_BGM_KAKARIKO_KID + SEQ_FLAG_RESUME, // NA_BGM_KAKARIKO_KID 0, // NA_BGM_GREAT_FAIRY 0, // NA_BGM_ZELDA_THEME SEQ_FLAG_ENEMY, // NA_BGM_FIRE_TEMPLE @@ -214,7 +216,7 @@ u8 sSeqFlags[0x6E] = { SEQ_FLAG_FANFARE, // NA_BGM_SMALL_ITEM_GET 0, // NA_BGM_TEMPLE_OF_TIME SEQ_FLAG_FANFARE, // NA_BGM_EVENT_CLEAR - SEQ_FLAG_4 | SEQ_FLAG_ENEMY, // NA_BGM_KOKIRI + SEQ_FLAG_RESUME | SEQ_FLAG_ENEMY, // NA_BGM_KOKIRI SEQ_FLAG_FANFARE, // NA_BGM_OCA_FAIRY_GET SEQ_FLAG_ENEMY, // NA_BGM_SARIA_THEME SEQ_FLAG_ENEMY, // NA_BGM_SPIRIT_TEMPLE @@ -232,16 +234,16 @@ u8 sSeqFlags[0x6E] = { 0, // NA_BGM_DEKU_TREE_CS 0, // NA_BGM_WINDMILL 0, // NA_BGM_HYRULE_CS - SEQ_FLAG_5, // NA_BGM_MINI_GAME + SEQ_FLAG_RESUME_PREV, // NA_BGM_MINI_GAME 0, // NA_BGM_SHEIK - SEQ_FLAG_4, // NA_BGM_ZORA_DOMAIN + SEQ_FLAG_RESUME, // NA_BGM_ZORA_DOMAIN SEQ_FLAG_FANFARE, // NA_BGM_APPEAR 0, // NA_BGM_ADULT_LINK 0, // NA_BGM_MASTER_SWORD SEQ_FLAG_FANFARE_GANON, // NA_BGM_INTRO_GANON - SEQ_FLAG_5, // NA_BGM_SHOP - SEQ_FLAG_6, // NA_BGM_CHAMBER_OF_SAGES - SEQ_FLAG_6, // NA_BGM_FILE_SELECT + SEQ_FLAG_RESUME_PREV, // NA_BGM_SHOP + SEQ_FLAG_SKIP_HARP_INTRO, // NA_BGM_CHAMBER_OF_SAGES + SEQ_FLAG_SKIP_HARP_INTRO, // NA_BGM_FILE_SELECT SEQ_FLAG_ENEMY, // NA_BGM_ICE_CAVERN SEQ_FLAG_FANFARE, // NA_BGM_DOOR_OF_TIME SEQ_FLAG_FANFARE, // NA_BGM_OWL @@ -249,7 +251,7 @@ u8 sSeqFlags[0x6E] = { SEQ_FLAG_ENEMY, // NA_BGM_WATER_TEMPLE SEQ_FLAG_FANFARE, // NA_BGM_BRIDGE_TO_GANONS 0, // NA_BGM_OCARINA_OF_TIME - SEQ_FLAG_4 | SEQ_FLAG_ENEMY, // NA_BGM_GERUDO_VALLEY + SEQ_FLAG_RESUME | SEQ_FLAG_ENEMY, // NA_BGM_GERUDO_VALLEY 0, // NA_BGM_POTION_SHOP 0, // NA_BGM_KOTAKE_KOUME SEQ_FLAG_NO_AMBIENCE, // NA_BGM_ESCAPE @@ -1235,9 +1237,9 @@ u8 sRiverSoundMainBgmRestore; u8 sGanonsTowerVol; SfxPlayerState sSfxChannelState[0x10]; char sBinToStrBuf[0x20]; -u8 D_8016B9D8; +u8 sMalonSingingTimer; u8 sAudioSpecPeakNumNotes[0x12]; -u8 D_8016B9F2; +u8 sMalonSingingDisabled; u8 D_8016B9F3; u8 D_8016B9F4; u16 D_8016B9F6; @@ -1264,13 +1266,13 @@ u16 sMusicStaffCurHeldLength[OCARINA_SONG_MAX]; u16 sMusicStaffExpectedLength[OCARINA_SONG_MAX]; u8 sMusicStaffExpectedPitch[OCARINA_SONG_MAX]; OcarinaNote sScarecrowsLongSongSecondNote; -u8 sAudioHasMalonBgm; -f32 sAudioMalonBgmDist; +u8 sIsMalonSinging; +f32 sMalonSingingDist; void PadMgr_RequestPadData(PadMgr* padMgr, Input* inputs, s32 gameRequest); void Audio_StepFreqLerp(FreqLerp* lerp); -void func_800F56A8(void); +void Audio_UpdateSceneSequenceResumePoint(void); void Audio_PlayNatureAmbienceSequence(u8 natureAmbienceId); s32 Audio_SetGanonsTowerBgmVolume(u8 targetVol); @@ -1768,7 +1770,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; @@ -2220,7 +2222,7 @@ s32 AudioOcarina_MemoryGameNextNote(void) { } void AudioOcarina_Update(void) { - sOcarinaUpdateTaskStart = gAudioContext.totalTaskCount; + sOcarinaUpdateTaskStart = gAudioCtx.totalTaskCount; if (sOcarinaInstrumentId != OCARINA_INSTRUMENT_OFF) { if (sIsOcarinaInputEnabled == true) { AudioOcarina_ReadControllerInput(); @@ -2424,7 +2426,7 @@ void AudioDebug_Draw(GfxPrint* printer) { GfxPrint_Printf(printer, "- %s -", sAudioDebugPageNames[sAudioDebugPage]); for (i = 0; i < gAudioSpecs[gAudioSpecId].numNotes; i++) { - if (gAudioContext.notes[i].noteSubEu.bitField0.enabled == 1) { + if (gAudioCtx.notes[i].noteSubEu.bitField0.enabled == 1) { numEnabledNotes++; } } @@ -2549,7 +2551,7 @@ void AudioDebug_Draw(GfxPrint* printer) { for (k2 = 0; k2 < gChannelsPerBank[gSfxChannelLayout][k]; k2++) { #define entryIndex (gActiveSfx[k][k2].entryIndex) #define entry (&gSfxBanks[k][entryIndex]) -#define chan (gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[entry->channelIdx]) +#define chan (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[entry->channelIdx]) GfxPrint_SetPos(printer, 2 + sAudioIntInfoX, 5 + ind + sAudioIntInfoY); if (sAudioIntInfoBankPage[k] == 1) { if ((entryIndex != 0xFF) && @@ -2712,14 +2714,14 @@ void AudioDebug_Draw(GfxPrint* printer) { GfxPrint_Printf(printer, "%1X", i); GfxPrint_SetPos(printer, 15 + i, 7); - if (gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->enabled) { + if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->enabled) { GfxPrint_Printf(printer, "O"); } else { GfxPrint_Printf(printer, "X"); } GfxPrint_SetPos(printer, 15 + i, 8); - if (gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->stopSomething2) { + if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->stopSomething2) { GfxPrint_Printf(printer, "O"); } else { GfxPrint_Printf(printer, "X"); @@ -2728,7 +2730,7 @@ void AudioDebug_Draw(GfxPrint* printer) { GfxPrint_SetPos(printer, 15 + i, 9); ctr = 0; for (j = 0; j < 4; j++) { - if (gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->layers[j] != NULL) { + if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->layers[j] != NULL) { ctr++; } } @@ -2783,33 +2785,32 @@ void AudioDebug_Draw(GfxPrint* printer) { for (i = 0; i < 8; i++) { GfxPrint_SetPos(printer, 15 + 3 * i, 22); GfxPrint_Printf(printer, "%02X ", - (u8)gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + (u8)gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->soundScriptIO[i]); } - if (gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->enabled) { + if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->enabled) { GfxPrint_SetPos(printer, 15, 11); GfxPrint_Printf(printer, "%d", - (u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->volume * 127.1)); GfxPrint_SetPos(printer, 15, 12); GfxPrint_Printf(printer, "%d", - (u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->volumeScale * 127.1)); GfxPrint_SetPos(printer, 15, 13); - GfxPrint_Printf(printer, "%X", - gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] - .channels[sAudioSubTrackInfoChannelSel] - ->fontId); + GfxPrint_Printf( + printer, "%X", + gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->fontId); - ctr = (u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + ctr = (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->instOrWave); @@ -2825,46 +2826,44 @@ void AudioDebug_Draw(GfxPrint* printer) { GfxPrint_Printf(printer, "%d", ctr2); GfxPrint_SetPos(printer, 15, 15); - GfxPrint_Printf(printer, "%d", - gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] - .channels[sAudioSubTrackInfoChannelSel] - ->newPan); + GfxPrint_Printf( + printer, "%d", + gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->newPan); GfxPrint_SetPos(printer, 15, 16); GfxPrint_Printf(printer, "%d", - gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->panChannelWeight); GfxPrint_SetPos(printer, 15, 17); - GfxPrint_Printf(printer, "%d", - gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] - .channels[sAudioSubTrackInfoChannelSel] - ->reverb); + GfxPrint_Printf( + printer, "%d", + gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->reverb); GfxPrint_SetPos(printer, 15, 18); GfxPrint_Printf(printer, "%d", - gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->notePriority); GfxPrint_SetPos(printer, 15, 19); GfxPrint_Printf(printer, "%d", - (u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->vibratoRateTarget / 32)); GfxPrint_SetPos(printer, 15, 20); GfxPrint_Printf(printer, "%d", - (u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->vibratoExtentTarget / 8)); GfxPrint_SetPos(printer, 15, 21); GfxPrint_Printf(printer, "%d", - (u16)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] + (u16)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel] .channels[sAudioSubTrackInfoChannelSel] ->freqScale * 100)); @@ -2878,47 +2877,46 @@ void AudioDebug_Draw(GfxPrint* printer) { GfxPrint_SetPos(printer, 3, 5); GfxPrint_Printf(printer, "DRIVER %05X / %05X", - gAudioContext.miscPool.curRamAddr - gAudioContext.miscPool.startRamAddr, - gAudioContext.miscPool.size); + gAudioCtx.miscPool.curRamAddr - gAudioCtx.miscPool.startRamAddr, gAudioCtx.miscPool.size); GfxPrint_SetPos(printer, 3, 6); GfxPrint_Printf( - printer, "AT-SEQ %02X-%02X (%05X-%05X / %05X)", (u8)gAudioContext.seqCache.temporary.entries[0].id, - (u8)gAudioContext.seqCache.temporary.entries[1].id, gAudioContext.seqCache.temporary.entries[0].size, - gAudioContext.seqCache.temporary.entries[1].size, gAudioContext.seqCache.temporary.pool.size); + printer, "AT-SEQ %02X-%02X (%05X-%05X / %05X)", (u8)gAudioCtx.seqCache.temporary.entries[0].id, + (u8)gAudioCtx.seqCache.temporary.entries[1].id, gAudioCtx.seqCache.temporary.entries[0].size, + gAudioCtx.seqCache.temporary.entries[1].size, gAudioCtx.seqCache.temporary.pool.size); GfxPrint_SetPos(printer, 3, 7); GfxPrint_Printf( - printer, "AT-BNK %02X-%02X (%05X-%05X / %05X)", (u8)gAudioContext.fontCache.temporary.entries[0].id, - (u8)gAudioContext.fontCache.temporary.entries[1].id, gAudioContext.fontCache.temporary.entries[0].size, - gAudioContext.fontCache.temporary.entries[1].size, gAudioContext.fontCache.temporary.pool.size); + printer, "AT-BNK %02X-%02X (%05X-%05X / %05X)", (u8)gAudioCtx.fontCache.temporary.entries[0].id, + (u8)gAudioCtx.fontCache.temporary.entries[1].id, gAudioCtx.fontCache.temporary.entries[0].size, + gAudioCtx.fontCache.temporary.entries[1].size, gAudioCtx.fontCache.temporary.pool.size); GfxPrint_SetPos(printer, 3, 8); - GfxPrint_Printf(printer, "ST-SEQ %02Xseqs (%05X / %06X)", gAudioContext.seqCache.persistent.numEntries, - gAudioContext.seqCache.persistent.pool.curRamAddr - - gAudioContext.seqCache.persistent.pool.startRamAddr, - gAudioContext.seqCache.persistent.pool.size); + GfxPrint_Printf(printer, "ST-SEQ %02Xseqs (%05X / %06X)", gAudioCtx.seqCache.persistent.numEntries, + gAudioCtx.seqCache.persistent.pool.curRamAddr - + gAudioCtx.seqCache.persistent.pool.startRamAddr, + gAudioCtx.seqCache.persistent.pool.size); - for (k = 0; (u32)k < gAudioContext.seqCache.persistent.numEntries; k++) { + for (k = 0; (u32)k < gAudioCtx.seqCache.persistent.numEntries; k++) { GfxPrint_SetPos(printer, 3 + 3 * k, 9); - GfxPrint_Printf(printer, "%02x", gAudioContext.seqCache.persistent.entries[k].id); + GfxPrint_Printf(printer, "%02x", gAudioCtx.seqCache.persistent.entries[k].id); } GfxPrint_SetPos(printer, 3, 10); - GfxPrint_Printf(printer, "ST-BNK %02Xbanks (%05X / %06X)", gAudioContext.fontCache.persistent.numEntries, - gAudioContext.fontCache.persistent.pool.curRamAddr - - gAudioContext.fontCache.persistent.pool.startRamAddr, - gAudioContext.fontCache.persistent.pool.size); + GfxPrint_Printf(printer, "ST-BNK %02Xbanks (%05X / %06X)", gAudioCtx.fontCache.persistent.numEntries, + gAudioCtx.fontCache.persistent.pool.curRamAddr - + gAudioCtx.fontCache.persistent.pool.startRamAddr, + gAudioCtx.fontCache.persistent.pool.size); - for (k = 0; (u32)k < gAudioContext.fontCache.persistent.numEntries; k++) { + for (k = 0; (u32)k < gAudioCtx.fontCache.persistent.numEntries; k++) { GfxPrint_SetPos(printer, 3 + 3 * k, 11); - GfxPrint_Printf(printer, "%02x", gAudioContext.fontCache.persistent.entries[k].id); + GfxPrint_Printf(printer, "%02x", gAudioCtx.fontCache.persistent.entries[k].id); } GfxPrint_SetPos(printer, 3, 12); GfxPrint_Printf(printer, "E-MEM %05X / %05X", - gAudioContext.permanentPool.curRamAddr - gAudioContext.permanentPool.startRamAddr, - gAudioContext.permanentPool.size); + gAudioCtx.permanentPool.curRamAddr - gAudioCtx.permanentPool.startRamAddr, + gAudioCtx.permanentPool.size); break; case PAGE_BLOCK_CHANGE_BGM: @@ -2937,34 +2935,34 @@ void AudioDebug_Draw(GfxPrint* printer) { SETCOL(255, 255, 255); GfxPrint_SetPos(printer, 3, 7); GfxPrint_Printf(printer, "NEXT SCENE %02X %s", - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2], - sAudioSceneNames[(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2]]); + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2], + sAudioSceneNames[(u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2]]); GfxPrint_SetPos(printer, 3, 8); GfxPrint_Printf(printer, "NOW SCENE %02X %s", - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4], - sAudioSceneNames[(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4]]); + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4], + sAudioSceneNames[(u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4]]); GfxPrint_SetPos(printer, 3, 9); GfxPrint_Printf(printer, "NOW BLOCK %02X", - (gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5] + 1) & 0xFF); + (gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5] + 1) & 0xFF); GfxPrint_SetPos(printer, 3, 11); GfxPrint_Printf(printer, "PORT"); GfxPrint_SetPos(printer, 3, 12); GfxPrint_Printf(printer, "%02X %02X %02X %02X", - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[0], - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[1], - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2], - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]); + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[0], + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[1], + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2], + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]); GfxPrint_SetPos(printer, 3, 13); GfxPrint_Printf(printer, "%02X %02X %02X %02X", - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4], - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5], - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[6], - (u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[7]); + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4], + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5], + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[6], + (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[7]); break; case PAGE_OCARINA_TEST: @@ -3060,9 +3058,9 @@ void AudioDebug_Draw(GfxPrint* printer) { GfxPrint_Printf(printer, "DEMO FLAG %d", sAudioCutsceneFlag); GfxPrint_SetPos(printer, 3, 12); - if (sAudioHasMalonBgm == true) { - GfxPrint_Printf(printer, "MARON BGM DIST %f", sAudioMalonBgmDist); - sAudioHasMalonBgm = false; + if (sIsMalonSinging == true) { + GfxPrint_Printf(printer, "MARON BGM DIST %f", sMalonSingingDist); + sIsMalonSinging = false; } GfxPrint_SetPos(printer, 3, 23); @@ -3158,7 +3156,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 +3168,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 +3193,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 +3486,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 +3642,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 +3689,7 @@ void AudioDebug_ProcessInput(void) { break; } - D_8013340C = sAudioScrPrtWork[10]; + gAudioDebugPrintSeqCmd = sAudioScrPrtWork[10]; } void Audio_UpdateRiverSoundVolumes(void); @@ -3702,13 +3700,13 @@ void func_800F5CF8(void); */ void func_800F3054(void) { if (func_800FAD34() == 0) { - sAudioUpdateTaskStart = gAudioContext.totalTaskCount; + sAudioUpdateTaskStart = gAudioCtx.totalTaskCount; sAudioUpdateStartTime = osGetTime(); AudioOcarina_Update(); Audio_StepFreqLerp(&sRiverFreqScaleLerp); Audio_StepFreqLerp(&sWaterfallFreqScaleLerp); Audio_UpdateRiverSoundVolumes(); - func_800F56A8(); + Audio_UpdateSceneSequenceResumePoint(); func_800F5CF8(); if (gAudioSpecId == 7) { Audio_ClearSariaBgm(); @@ -3716,11 +3714,11 @@ void func_800F3054(void) { Audio_ProcessSfxRequests(); Audio_ProcessSeqCmds(); func_800F8F88(); - func_800FA3DC(); + Audio_UpdateActiveSequences(); AudioDebug_SetInput(); AudioDebug_ProcessInput(); Audio_ScheduleProcessCmds(); - sAudioUpdateTaskEnd = gAudioContext.totalTaskCount; + sAudioUpdateTaskEnd = gAudioCtx.totalTaskCount; sAudioUpdateEndTime = osGetTime(); } } @@ -3794,9 +3792,9 @@ s8 Audio_ComputeSfxReverb(u8 bankId, u8 entryIdx, u8 channelIdx) { } } - if (IS_SEQUENCE_CHANNEL_VALID(gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx])) { - scriptAdd = gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1]; - if (gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1] < 0) { + if (IS_SEQUENCE_CHANNEL_VALID(gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx])) { + scriptAdd = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1]; + if (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1] <= SEQ_IO_VAL_NONE) { scriptAdd = 0; } } @@ -3863,7 +3861,7 @@ f32 Audio_ComputeSfxFreqScale(u8 bankId, u8 entryIdx) { f32 freq = 1.0f; if (entry->sfxParams & SFX_FLAG_14) { - freq = 1.0f - ((gAudioContext.audioRandom & 0xF) / 192.0f); + freq = 1.0f - ((gAudioCtx.audioRandom & 0xF) / 192.0f); } switch (bankId) { @@ -3887,7 +3885,7 @@ f32 Audio_ComputeSfxFreqScale(u8 bankId, u8 entryIdx) { if (phi_v0 == 1) { if (!(entry->sfxParams & SFX_FLAG_11)) { - freq *= (1.0293 - ((gAudioContext.audioRandom & 0xF) / 144.0f)); + freq *= (1.0293 - ((gAudioCtx.audioRandom & 0xF) / 144.0f)); } } @@ -4094,8 +4092,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); } } @@ -4129,7 +4127,7 @@ void func_800F4010(Vec3f* pos, u16 sfxId, f32 arg2) { sp24 = 1.0f; } else { phi_f0 = 1.1f; - phi_v0 = gAudioContext.audioRandom % 2; + phi_v0 = gAudioCtx.audioRandom % 2; } if ((phi_f0 < arg2) && (phi_v0 != 0)) { @@ -4263,17 +4261,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 +4313,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,19 +4325,18 @@ 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++) { - if (gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx] != - &gAudioContext.sequenceChannelNone) { + if (gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx] != &gAudioCtx.sequenceChannelNone) { // soundScriptIO[5] is set to 0x40 in channels 0, 1, and 4 - if ((u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] != 0xFF) { + if ((u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] != + (u8)SEQ_IO_VAL_NONE) { // Higher volume leads to lower reverb - reverb = - ((u16)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] - - targetVol) + - 0x7F; + reverb = ((u16)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] - + targetVol) + + 0x7F; if (reverb > 0x7F) { reverb = 0x7F; } @@ -4369,14 +4366,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 +4461,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 +4491,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 @@ -4515,7 +4512,7 @@ void Audio_SplitBgmChannels(s8 volSplit) { channelBits = 0; for (channelIdx = 0; channelIdx < 16; channelIdx++) { - if (notePriority > gAudioContext.seqPlayers[bgmPlayers[i]].channels[channelIdx]->notePriority) { + if (notePriority > gAudioCtx.seqPlayers[bgmPlayers[i]].channels[channelIdx]->notePriority) { // If the note currently playing in the channel is a high enough priority, // then keep the channel on by setting a channelBit // If this condition fails, then the channel will be shut off @@ -4523,7 +4520,7 @@ void Audio_SplitBgmChannels(s8 volSplit) { } } - Audio_SeqCmdA(bgmPlayers[i], channelBits); + SEQCMD_SET_CHANNEL_DISABLE_MASK(bgmPlayers[i], channelBits); } } } @@ -4542,7 +4539,7 @@ void Audio_PlaySariaBgm(Vec3f* pos, u16 seqId, u16 distMax) { dist = sqrtf(SQ(pos->z) + SQ(pos->x)); if (sSariaBgmPtr == NULL) { sSariaBgmPtr = pos; - func_800F5E18(SEQ_PLAYER_BGM_SUB, seqId, 0, 7, 2); + Audio_PlaySequenceWithSeqPlayerIO(SEQ_PLAYER_BGM_SUB, seqId, 0, 7, 2); } else { prevDist = sqrtf(SQ(sSariaBgmPtr->z) + SQ(sSariaBgmPtr->x)); if (dist < prevDist) { @@ -4570,82 +4567,92 @@ 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) { sSariaBgmPtr = NULL; } -void func_800F5510(u16 seqId) { - func_800F5550(seqId); - func_800F5E18(SEQ_PLAYER_BGM_MAIN, seqId, 0, 0, 1); +void Audio_PlayMorningSceneSequence(u16 seqId) { + Audio_PlaySceneSequence(seqId); + // Writing a value of 1 to ioPort 0 will be used by + // `NA_BGM_FIELD_LOGIC` to play `NA_BGM_FIELD_MORNING` first + Audio_PlaySequenceWithSeqPlayerIO(SEQ_PLAYER_BGM_MAIN, seqId, 0, 0, 1); } -void func_800F5550(u16 seqId) { - u8 sp27 = 0; - u16 nv; +void Audio_PlaySceneSequence(u16 seqId) { + u8 fadeInDuration = 0; + u8 skipHarpIntro; - 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); + // Terminate all internal audio cmds Audio_QueueCmdS32(0xF8000000, 0); } - if ((sSeqFlags[D_80130630] & SEQ_FLAG_5) && sSeqFlags[(seqId & 0xFF) & 0xFF] & SEQ_FLAG_4) { - - if ((D_8013062C & 0x3F) != 0) { - sp27 = 0x1E; + if ((sSeqFlags[sPrevSceneSeqId] & SEQ_FLAG_RESUME_PREV) && sSeqFlags[seqId & 0xFF & 0xFF] & SEQ_FLAG_RESUME) { + // Resume the sequence from the point where it left off last time it was played in the scene + if ((sSeqResumePoint & 0x3F) != 0) { + fadeInDuration = 30; } - func_800F5E18(SEQ_PLAYER_BGM_MAIN, seqId, sp27, 7, D_8013062C); + // Write the sequence resumePoint to start from into ioPort 7 + Audio_PlaySequenceWithSeqPlayerIO(SEQ_PLAYER_BGM_MAIN, seqId, fadeInDuration, 7, sSeqResumePoint); - D_8013062C = 0; + sSeqResumePoint = 0; } else { - nv = (sSeqFlags[(seqId & 0xFF) & 0xFF] & SEQ_FLAG_6) ? 1 : 0xFF; - func_800F5E18(SEQ_PLAYER_BGM_MAIN, seqId, 0, 7, nv); - if (!(sSeqFlags[seqId] & SEQ_FLAG_5)) { - D_8013062C = 0xC0; + // Start the sequence from the beginning + + // Writes to ioPort 7. See `SEQ_FLAG_SKIP_HARP_INTRO` for writing a value of 1 to ioPort 7. + skipHarpIntro = (sSeqFlags[seqId & 0xFF & 0xFF] & SEQ_FLAG_SKIP_HARP_INTRO) ? 1 : (u8)SEQ_IO_VAL_NONE; + Audio_PlaySequenceWithSeqPlayerIO(SEQ_PLAYER_BGM_MAIN, seqId, 0, 7, skipHarpIntro); + + if (!(sSeqFlags[seqId] & SEQ_FLAG_RESUME_PREV)) { + // Reset the sequence resumePoint + sSeqResumePoint = SEQ_RESUME_POINT_NONE; } } - D_80130630 = seqId & 0xFF; + sPrevSceneSeqId = seqId & 0xFF; } } -void func_800F56A8(void) { - u16 temp_v0; - u8 bvar; +void Audio_UpdateSceneSequenceResumePoint(void) { + u16 seqId = Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN); - temp_v0 = func_800FA0B4(SEQ_PLAYER_BGM_MAIN); - bvar = temp_v0 & 0xFF; - if ((temp_v0 != NA_BGM_DISABLED) && (sSeqFlags[bvar] & SEQ_FLAG_4)) { - if (D_8013062C != 0xC0) { - D_8013062C = gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]; + if ((seqId != NA_BGM_DISABLED) && (sSeqFlags[(u8)seqId & 0xFF] & SEQ_FLAG_RESUME)) { + if (sSeqResumePoint != SEQ_RESUME_POINT_NONE) { + // Get the current point to resume from + sSeqResumePoint = gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]; } else { - D_8013062C = 0; + // Initialize the point to resume from to the start of the sequence. + sSeqResumePoint = 0; } } } 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 +4662,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); + Audio_PlaySequenceWithSeqPlayerIO(SEQ_PLAYER_BGM_MAIN, arg0, 0, 7, SEQ_IO_VAL_NONE); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 0); } } @@ -4667,11 +4674,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 +4691,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 +4703,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 +4713,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 +4721,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 +4737,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 +4751,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 +4762,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 Audio_PlaySequenceWithSeqPlayerIO(u8 seqPlayerIndex, u16 seqId, u8 fadeInDuration, s8 ioPort, s8 ioData) { + SEQCMD_SET_PLAYER_IO(seqPlayerIndex, ioPort, ioData); + SEQCMD_PLAY_SEQUENCE(seqPlayerIndex, fadeInDuration, 0, seqId); } void Audio_SetSequenceMode(u8 seqMode) { @@ -4815,9 +4827,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 +4838,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 +4888,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,68 +4907,81 @@ 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); } } sAudioEnemyDist = dist; } -void func_800F6268(f32 dist, u16 arg1) { +void Audio_UpdateMalonSinging(f32 dist, u16 seqId) { s8 pad; - s8 phi_v1; - s16 temp_a0; + s8 melodyVolume; + s16 curSeqId; - sAudioHasMalonBgm = true; - sAudioMalonBgmDist = dist; - if (D_8016B9F2 == 0) { - temp_a0 = (s8)(func_800FA0B4(SEQ_PLAYER_BGM_MAIN) & 0xFF); - if (temp_a0 == (arg1 & 0xFF)) { - if ((arg1 & 0xFF) == NA_BGM_LONLON) { + sIsMalonSinging = true; + sMalonSingingDist = dist; - if (dist > 2000.0f) { - phi_v1 = 127; - } else if (dist < 200.0f) { - phi_v1 = 0; - } else { - 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); - 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); - 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); - D_8016B9D8 = 10; - } + if (sMalonSingingDisabled) { + return; + } + + curSeqId = (s8)(Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) & 0xFF); + + if (curSeqId == (seqId & 0xFF)) { + if ((seqId & 0xFF) == NA_BGM_LONLON) { + // Malon is singing along with the Lon Lon Sequence if (dist > 2000.0f) { - phi_v1 = 127; + melodyVolume = 127; } else if (dist < 200.0f) { - phi_v1 = 0; + melodyVolume = 0; } else { - phi_v1 = (s8)(((dist - 200.0f) * 127.0f) / 1800.0f); + melodyVolume = (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); + + // Update volume for channels 0 & 1, which contain Malon's singing + SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_MAIN, 0, 3, 127 - melodyVolume); + SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_MAIN, 1, 3, 127 - melodyVolume); + + // Update volume for channel 13, which contains the melody line for Lon Lon's Sequence + SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_MAIN, 13, 3, melodyVolume); + if (sMalonSingingTimer == 0) { + sMalonSingingTimer++; + } + } + } else if ((curSeqId == NA_BGM_NATURE_AMBIENCE) && ((seqId & 0xFF) == NA_BGM_LONLON)) { + // Malon is singing along with ambience + curSeqId = (s8)(Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB) & 0xFF); + + if ((curSeqId != (seqId & 0xFF)) && (sMalonSingingTimer < 10)) { + Audio_PlaySequenceWithSeqPlayerIO(SEQ_PLAYER_BGM_SUB, NA_BGM_LONLON, 0, 0, 0); + // Disable all channels between 2-15. + // Only allow the two channels with Malon's singing to play, and suppress the full lon lon sequence. + SEQCMD_SET_CHANNEL_DISABLE_MASK(SEQ_PLAYER_BGM_SUB, 0xFFFC); + sMalonSingingTimer = 10; } - if (D_8016B9D8 < 10) { - D_8016B9D8++; + if (dist > 2000.0f) { + melodyVolume = 127; + } else if (dist < 200.0f) { + melodyVolume = 0; + } else { + melodyVolume = (s8)(((dist - 200.0f) * 127.0f) / 1800.0f); } + + // Update volume for channels 0 & 1, which contain Malon's singing + SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_SUB, 0, 3, 127 - melodyVolume); + SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_SUB, 1, 3, 127 - melodyVolume); + } + + if (sMalonSingingTimer < 10) { + sMalonSingingTimer++; } } @@ -4969,35 +4998,55 @@ void func_800F64E0(u8 arg0) { } } -void func_800F6584(u8 arg0) { - u8 playerIdx; - u16 sp34; +/** + * Enable or disable Malon's singing + * + * @param malonSingingDisabled true to disable, false to enable + */ +void Audio_ToggleMalonSinging(u8 malonSingingDisabled) { + u8 seqPlayerIndex; + u16 channelMaskDisable; - D_8016B9F2 = arg0; - if ((func_800FA0B4(SEQ_PLAYER_BGM_MAIN) & 0xFF) == NA_BGM_LONLON) { - playerIdx = SEQ_PLAYER_BGM_MAIN; - sp34 = 0; - } else if ((func_800FA0B4(SEQ_PLAYER_BGM_SUB) & 0xFF) == NA_BGM_LONLON) { - playerIdx = SEQ_PLAYER_BGM_SUB; - sp34 = 0xFFFC; + sMalonSingingDisabled = malonSingingDisabled; + + if ((Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) & 0xFF) == NA_BGM_LONLON) { + // Malon is singing along with the Lon Lon Sequence + seqPlayerIndex = SEQ_PLAYER_BGM_MAIN; + // Do not disable any channel. + // Allow the full lon lon sequence to play in addition to Malon's singing. + channelMaskDisable = 0; + } else if ((u8)Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB) == NA_BGM_LONLON) { + // Malon is singing along with ambience + seqPlayerIndex = SEQ_PLAYER_BGM_SUB; + // Disable all channels between 2-15. + // Only allow the two channels with Malon's singing to play, and suppress the full lon lon sequence. + channelMaskDisable = 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); + if (malonSingingDisabled) { + // Turn volume off for channels 0 & 1, which contain Malon's singing + SEQCMD_SET_CHANNEL_VOLUME(seqPlayerIndex, 0, 1, 0); + SEQCMD_SET_CHANNEL_VOLUME(seqPlayerIndex, 1, 1, 0); + + if (seqPlayerIndex == SEQ_PLAYER_BGM_SUB) { + // When singing along with ambience, disable all 16 channels + SEQCMD_SET_CHANNEL_DISABLE_MASK(seqPlayerIndex, channelMaskDisable | 3); } } else { - if (playerIdx == SEQ_PLAYER_BGM_SUB) { - func_800F5E18(SEQ_PLAYER_BGM_SUB, NA_BGM_LONLON, 0, 0, 0); + if (seqPlayerIndex == SEQ_PLAYER_BGM_SUB) { + // When singing along with ambience, start the sequence + Audio_PlaySequenceWithSeqPlayerIO(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); + + // Turn volume on for only channels 0 & 1, which contain Malon's singing + SEQCMD_SET_CHANNEL_VOLUME(seqPlayerIndex, 0, 1, 0x7F); + SEQCMD_SET_CHANNEL_VOLUME(seqPlayerIndex, 1, 1, 0x7F); + + if (seqPlayerIndex == SEQ_PLAYER_BGM_SUB) { + // When singing along with ambience, disable channels 2-15 + SEQCMD_SET_CHANNEL_DISABLE_MASK(seqPlayerIndex, channelMaskDisable); } } } @@ -5037,7 +5086,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 +5108,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 +5136,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 +5153,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) { @@ -5168,7 +5217,7 @@ void func_800F6C34(void) { sRiverSoundMainBgmLower = false; sRiverSoundMainBgmRestore = false; sGanonsTowerVol = 0xFF; - D_8016B9D8 = 0; + sMalonSingingTimer = 0; sSpecReverb = sSpecReverbs[gAudioSpecId]; D_80130608 = 0; sPrevMainBgmSeqId = NA_BGM_DISABLED; @@ -5176,23 +5225,24 @@ void func_800F6C34(void) { sSariaBgmPtr = NULL; D_8016B9F4 = 0; D_8016B9F3 = 1; - D_8016B9F2 = 0; + sMalonSingingDisabled = false; } -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) { - D_8016B9D8 = 0; + // 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) { + sMalonSingingTimer = 0; } } @@ -5204,38 +5254,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 +5293,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 +5321,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 +5338,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 c8f24736f8..7cfdae4202 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); } } @@ -441,7 +441,7 @@ void Audio_PlayActiveSfx(u8 bankId) { entryIndex = gActiveSfx[bankId][i].entryIndex; if (entryIndex != 0xFF) { entry = &gSfxBanks[bankId][entryIndex]; - channel = gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIdx]; + channel = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIdx]; if (entry->state == SFX_STATE_READY) { entry->channelIdx = sCurSfxPlayerChannelIdx; if (entry->sfxParams & SFX_FLAG_3) { @@ -476,7 +476,7 @@ void Audio_PlayActiveSfx(u8 bankId) { } else { entry->state = SFX_STATE_PLAYING_2; } - } else if ((u8)channel->soundScriptIO[1] == 0xFF) { + } else if ((u8)channel->soundScriptIO[1] == (u8)SEQ_IO_VAL_NONE) { Audio_RemoveSfxBankEntry(bankId, entryIndex); } else if (entry->state == SFX_STATE_PLAYING_REFRESH) { Audio_SetSfxProperties(bankId, entryIndex, sCurSfxPlayerChannelIdx); @@ -661,7 +661,7 @@ void Audio_StepUnusedBankLerp(u8 bankId) { void func_800F8F88(void) { u8 bankId; - if (IS_SEQUENCE_CHANNEL_VALID(gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[0])) { + if (IS_SEQUENCE_CHANNEL_VALID(gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[0])) { sCurSfxPlayerChannelIdx = 0; for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) { Audio_ChooseActiveSfx(bankId); diff --git a/src/code/code_800F9280.c b/src/code/code_800F9280.c index 86ca22831d..115789fe5f 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]; +ActiveSequence gActiveSeqs[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; +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 * gAudioCtx.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)gAudioCtx.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)gAudioCtx.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; - } - D_8016E320[playerIdx][found].unk_1 = seqArgs; - D_8016E320[playerIdx][found].unk_0 = seqId; + 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; + } + + // 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); + 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); } - 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); + + // 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 (!gAudioCtx.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; + u8 channelIndex; - 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); + 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++; + // Process tempo + if (gActiveSeqs[seqPlayerIndex].tempoCmd != 0) { + tempoCmd = gActiveSeqs[seqPlayerIndex].tempoCmd; + tempoTimer = (tempoCmd & 0xFF0000) >> 15; + tempoTarget = tempoCmd & 0xFFF; + if (tempoTimer == 0) { + tempoTimer++; } - 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 commands + if (gAudioCtx.seqPlayers[seqPlayerIndex].enabled) { + tempoPrev = gAudioCtx.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 = gAudioCtx.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 (gAudioCtx.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; +void Audio_ResetActiveSequences(void) { + u8 seqPlayerIndex; + u8 scaleIndex; - 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; + 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_construct.c b/src/code/z_construct.c index 440949b426..9a40a33914 100644 --- a/src/code/z_construct.c +++ b/src/code/z_construct.c @@ -345,9 +345,9 @@ void func_80111070(void) { XREG(3) = -4; XREG(4) = 3; XREG(5) = 0; - XREG(6) = 2; + R_PAUSE_STICK_REPEAT_DELAY = 2; XREG(7) = 30; - XREG(8) = 10; + R_PAUSE_STICK_REPEAT_DELAY_FIRST = 10; XREG(9) = 0; XREG(10) = -9550; XREG(11) = 9950; diff --git a/src/code/z_demo.c b/src/code/z_demo.c index e1c4f7db39..9af0c6f930 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 ec49412555..d52f8db996 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) { @@ -2050,12 +2050,12 @@ void Environment_PlaySceneSequence(PlayState* play) { osSyncPrintf("\n\n\nBGM設定game_play->sound_info.BGM=[%d] old_bgm=[%d]\n\n", play->sequenceCtx.seqId, ((void)0, gSaveContext.seqId)); if (((void)0, gSaveContext.seqId) != play->sequenceCtx.seqId) { - func_800F5550(play->sequenceCtx.seqId); + Audio_PlaySceneSequence(play->sequenceCtx.seqId); } } else if (((void)0, gSaveContext.dayTime) >= CLOCK_TIME(7, 0) && ((void)0, gSaveContext.dayTime) <= CLOCK_TIME(17, 10)) { if (((void)0, gSaveContext.seqId) != play->sequenceCtx.seqId) { - func_800F5550(play->sequenceCtx.seqId); + Audio_PlaySceneSequence(play->sequenceCtx.seqId); } play->envCtx.timeSeqState = TIMESEQ_FADE_DAY_BGM; @@ -2092,7 +2092,7 @@ void Environment_PlayTimeBasedSequence(PlayState* play) { if (play->envCtx.precipitation[PRECIP_RAIN_MAX] == 0 && play->envCtx.precipitation[PRECIP_SOS_MAX] == 0) { osSyncPrintf("\n\n\nNa_StartMorinigBgm\n\n"); - func_800F5510(play->sequenceCtx.seqId); + Audio_PlayMorningSceneSequence(play->sequenceCtx.seqId); } play->envCtx.timeSeqState++; @@ -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_player_lib.c b/src/code/z_player_lib.c index cfdc0897a7..1dd2a13bc4 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -24,75 +24,75 @@ s16 sBootData[PLAYER_BOOTS_MAX][17] = { { 200, 1000, 300, 800, 500, 400, 800, 400, 800, 550, -100, 600, 540, 750, 125, 400, 200 }, }; -// Used to map action params to model groups -u8 sActionModelGroups[PLAYER_AP_MAX] = { - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_NONE - PLAYER_MODELGROUP_15, // PLAYER_AP_LAST_USED - PLAYER_MODELGROUP_10, // PLAYER_AP_FISHING_POLE - PLAYER_MODELGROUP_SWORD, // PLAYER_AP_SWORD_MASTER - PLAYER_MODELGROUP_SWORD, // PLAYER_AP_SWORD_KOKIRI - PLAYER_MODELGROUP_BGS, // PLAYER_AP_SWORD_BGS - PLAYER_MODELGROUP_10, // PLAYER_AP_STICK - PLAYER_MODELGROUP_HAMMER, // PLAYER_AP_HAMMER - PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_AP_BOW - PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_AP_BOW_FIRE - PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_AP_BOW_ICE - PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_AP_BOW_LIGHT - PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_AP_BOW_0C - PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_AP_BOW_0D - PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_AP_BOW_0E - PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_AP_SLINGSHOT - PLAYER_MODELGROUP_HOOKSHOT, // PLAYER_AP_HOOKSHOT - PLAYER_MODELGROUP_HOOKSHOT, // PLAYER_AP_LONGSHOT - PLAYER_MODELGROUP_EXPLOSIVES, // PLAYER_AP_BOMB - PLAYER_MODELGROUP_EXPLOSIVES, // PLAYER_AP_BOMBCHU - PLAYER_MODELGROUP_BOOMERANG, // PLAYER_AP_BOOMERANG - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_MAGIC_SPELL_15 - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_MAGIC_SPELL_16 - PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_AP_MAGIC_SPELL_17 - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_FARORES_WIND - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_NAYRUS_LOVE - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_DINS_FIRE - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_NUT - PLAYER_MODELGROUP_OCARINA, // PLAYER_AP_OCARINA_FAIRY - PLAYER_MODELGROUP_OOT, // PLAYER_AP_OCARINA_TIME - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE_FISH - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE_FIRE - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE_BUG - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE_POE - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE_BIG_POE - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE_LETTER - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE_POTION_RED - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE_POTION_BLUE - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE_POTION_GREEN - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE_MILK - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE_MILK_HALF - PLAYER_MODELGROUP_BOTTLE, // PLAYER_AP_BOTTLE_FAIRY - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_LETTER_ZELDA - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_WEIRD_EGG - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_CHICKEN - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_BEAN - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_POCKET_EGG - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_POCKET_CUCCO - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_COJIRO - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_ODD_MUSHROOM - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_ODD_POTION - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_SAW - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_SWORD_BROKEN - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_PRESCRIPTION - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_FROG - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_EYEDROPS - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_CLAIM_CHECK - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_MASK_KEATON - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_MASK_SKULL - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_MASK_SPOOKY - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_MASK_BUNNY - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_MASK_GORON - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_MASK_ZORA - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_MASK_GERUDO - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_MASK_TRUTH - PLAYER_MODELGROUP_DEFAULT, // PLAYER_AP_LENS +// Used to map item actions to model groups +u8 sActionModelGroups[PLAYER_IA_MAX] = { + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_NONE + PLAYER_MODELGROUP_15, // PLAYER_IA_LAST_USED + PLAYER_MODELGROUP_10, // PLAYER_IA_FISHING_POLE + PLAYER_MODELGROUP_SWORD, // PLAYER_IA_SWORD_MASTER + PLAYER_MODELGROUP_SWORD, // PLAYER_IA_SWORD_KOKIRI + PLAYER_MODELGROUP_BGS, // PLAYER_IA_SWORD_BGS + PLAYER_MODELGROUP_10, // PLAYER_IA_STICK + PLAYER_MODELGROUP_HAMMER, // PLAYER_IA_HAMMER + PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_IA_BOW + PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_IA_BOW_FIRE + PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_IA_BOW_ICE + PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_IA_BOW_LIGHT + PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_IA_BOW_0C + PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_IA_BOW_0D + PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_IA_BOW_0E + PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_IA_SLINGSHOT + PLAYER_MODELGROUP_HOOKSHOT, // PLAYER_IA_HOOKSHOT + PLAYER_MODELGROUP_HOOKSHOT, // PLAYER_IA_LONGSHOT + PLAYER_MODELGROUP_EXPLOSIVES, // PLAYER_IA_BOMB + PLAYER_MODELGROUP_EXPLOSIVES, // PLAYER_IA_BOMBCHU + PLAYER_MODELGROUP_BOOMERANG, // PLAYER_IA_BOOMERANG + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_MAGIC_SPELL_15 + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_MAGIC_SPELL_16 + PLAYER_MODELGROUP_BOW_SLINGSHOT, // PLAYER_IA_MAGIC_SPELL_17 + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_FARORES_WIND + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_NAYRUS_LOVE + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_DINS_FIRE + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_NUT + PLAYER_MODELGROUP_OCARINA, // PLAYER_IA_OCARINA_FAIRY + PLAYER_MODELGROUP_OOT, // PLAYER_IA_OCARINA_TIME + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE_FISH + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE_FIRE + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE_BUG + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE_POE + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE_BIG_POE + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE_LETTER + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE_POTION_RED + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE_POTION_BLUE + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE_POTION_GREEN + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE_MILK + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE_MILK_HALF + PLAYER_MODELGROUP_BOTTLE, // PLAYER_IA_BOTTLE_FAIRY + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_LETTER_ZELDA + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_WEIRD_EGG + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_CHICKEN + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_BEAN + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_POCKET_EGG + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_POCKET_CUCCO + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_COJIRO + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_ODD_MUSHROOM + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_ODD_POTION + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_SAW + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_SWORD_BROKEN + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_PRESCRIPTION + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_FROG + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_EYEDROPS + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_CLAIM_CHECK + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_MASK_KEATON + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_MASK_SKULL + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_MASK_SPOOKY + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_MASK_BUNNY + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_MASK_GORON + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_MASK_ZORA + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_MASK_GERUDO + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_MASK_TRUTH + PLAYER_MODELGROUP_DEFAULT, // PLAYER_IA_LENS }; TextTriggerEntry sTextTriggers[] = { @@ -491,8 +491,7 @@ s32 Player_InBlockingCsMode(PlayState* play, Player* this) { return (this->stateFlags1 & (PLAYER_STATE1_7 | PLAYER_STATE1_29)) || (this->csMode != 0) || (play->transitionTrigger == TRANS_TRIGGER_START) || (this->stateFlags1 & PLAYER_STATE1_0) || (this->stateFlags3 & PLAYER_STATE3_7) || - ((gSaveContext.magicState != MAGIC_STATE_IDLE) && - (Player_ActionToMagicSpell(this, this->itemActionParam) >= 0)); + ((gSaveContext.magicState != MAGIC_STATE_IDLE) && (Player_ActionToMagicSpell(this, this->itemAction) >= 0)); } s32 Player_InCsMode(PlayState* play) { @@ -509,8 +508,8 @@ s32 Player_IsChildWithHylianShield(Player* this) { return gSaveContext.linkAge != LINK_AGE_ADULT && (this->currentShield == PLAYER_SHIELD_HYLIAN); } -s32 Player_ActionToModelGroup(Player* this, s32 actionParam) { - s32 modelGroup = sActionModelGroups[actionParam]; +s32 Player_ActionToModelGroup(Player* this, s32 itemAction) { + s32 modelGroup = sActionModelGroups[itemAction]; if ((modelGroup == PLAYER_MODELGROUP_SWORD) && Player_IsChildWithHylianShield(this)) { // child, using kokiri sword with hylian shield equipped @@ -522,7 +521,7 @@ s32 Player_ActionToModelGroup(Player* this, s32 actionParam) { void Player_SetModelsForHoldingShield(Player* this) { if ((this->stateFlags1 & PLAYER_STATE1_22) && - ((this->itemActionParam < 0) || (this->itemActionParam == this->heldItemActionParam))) { + ((this->itemAction < 0) || (this->itemAction == this->heldItemAction))) { if (!Player_HoldsTwoHandedWeapon(this) && !Player_IsChildWithHylianShield(this)) { this->rightHandType = PLAYER_MODELTYPE_RH_SHIELD; this->rightHandDLists = sPlayerDListGroups[PLAYER_MODELTYPE_RH_SHIELD] + ((void)0, gSaveContext.linkAge); @@ -533,7 +532,7 @@ void Player_SetModelsForHoldingShield(Player* this) { } this->sheathDLists = sPlayerDListGroups[this->sheathType] + ((void)0, gSaveContext.linkAge); this->modelAnimType = PLAYER_ANIMTYPE_2; - this->itemActionParam = -1; + this->itemAction = -1; } } } @@ -572,8 +571,8 @@ void Player_SetModelGroup(Player* this, s32 modelGroup) { } void func_8008EC70(Player* this) { - this->itemActionParam = this->heldItemActionParam; - Player_SetModelGroup(this, Player_ActionToModelGroup(this, this->heldItemActionParam)); + this->itemAction = this->heldItemAction; + Player_SetModelGroup(this, Player_ActionToModelGroup(this, this->heldItemAction)); this->unk_6AD = 0; } @@ -583,20 +582,20 @@ void Player_SetEquipmentData(PlayState* play, Player* this) { this->currentTunic = TUNIC_EQUIP_TO_PLAYER(CUR_EQUIP_VALUE(EQUIP_TYPE_TUNIC)); this->currentBoots = BOOTS_EQUIP_TO_PLAYER(CUR_EQUIP_VALUE(EQUIP_TYPE_BOOTS)); this->currentSwordItemId = B_BTN_ITEM; - Player_SetModelGroup(this, Player_ActionToModelGroup(this, this->heldItemActionParam)); + Player_SetModelGroup(this, Player_ActionToModelGroup(this, this->heldItemAction)); Player_SetBootData(play, this); } } -void Player_UpdateBottleHeld(PlayState* play, Player* this, s32 item, s32 actionParam) { +void Player_UpdateBottleHeld(PlayState* play, Player* this, s32 item, s32 itemAction) { Inventory_UpdateBottleItem(play, item, this->heldItemButton); if (item != ITEM_BOTTLE) { this->heldItemId = item; - this->heldItemActionParam = actionParam; + this->heldItemAction = itemAction; } - this->itemActionParam = actionParam; + this->itemAction = itemAction; } void func_8008EDF0(Player* this) { @@ -645,7 +644,7 @@ s32 Player_IsBurningStickInRange(PlayState* play, Vec3f* pos, f32 xzRange, f32 y Vec3f diff; s32 pad; - if ((this->heldItemActionParam == PLAYER_AP_STICK) && (this->unk_860 != 0)) { + if ((this->heldItemAction == PLAYER_IA_STICK) && (this->unk_860 != 0)) { Math_Vec3f_Diff(&this->meleeWeaponInfo[0].tip, pos, &diff); return ((SQ(diff.x) + SQ(diff.z)) <= SQ(xzRange)) && (0.0f <= diff.y) && (diff.y <= yRange); } else { @@ -691,8 +690,8 @@ s32 Player_HasMirrorShieldSetToDraw(PlayState* play) { return (this->rightHandType == PLAYER_MODELTYPE_RH_SHIELD) && (this->currentShield == PLAYER_SHIELD_MIRROR); } -s32 Player_ActionToMagicSpell(Player* this, s32 actionParam) { - s32 magicSpell = actionParam - PLAYER_AP_MAGIC_SPELL_15; +s32 Player_ActionToMagicSpell(Player* this, s32 itemAction) { + s32 magicSpell = itemAction - PLAYER_IA_MAGIC_SPELL_15; if ((magicSpell >= 0) && (magicSpell < 6)) { return magicSpell; @@ -702,15 +701,15 @@ s32 Player_ActionToMagicSpell(Player* this, s32 actionParam) { } s32 Player_HoldsHookshot(Player* this) { - return (this->heldItemActionParam == PLAYER_AP_HOOKSHOT) || (this->heldItemActionParam == PLAYER_AP_LONGSHOT); + return (this->heldItemAction == PLAYER_IA_HOOKSHOT) || (this->heldItemAction == PLAYER_IA_LONGSHOT); } s32 func_8008F128(Player* this) { return Player_HoldsHookshot(this) && (this->heldActor == NULL); } -s32 Player_ActionToMeleeWeapon(s32 actionParam) { - s32 meleeWeapon = actionParam - PLAYER_AP_FISHING_POLE; +s32 Player_ActionToMeleeWeapon(s32 itemAction) { + s32 meleeWeapon = itemAction - PLAYER_IA_FISHING_POLE; if ((meleeWeapon > 0) && (meleeWeapon < 6)) { return meleeWeapon; @@ -720,11 +719,11 @@ s32 Player_ActionToMeleeWeapon(s32 actionParam) { } s32 Player_GetMeleeWeaponHeld(Player* this) { - return Player_ActionToMeleeWeapon(this->heldItemActionParam); + return Player_ActionToMeleeWeapon(this->heldItemAction); } s32 Player_HoldsTwoHandedWeapon(Player* this) { - if ((this->heldItemActionParam >= PLAYER_AP_SWORD_BGS) && (this->heldItemActionParam <= PLAYER_AP_HAMMER)) { + if ((this->heldItemAction >= PLAYER_IA_SWORD_BGS) && (this->heldItemAction <= PLAYER_IA_HAMMER)) { return 1; } else { return 0; @@ -732,11 +731,11 @@ s32 Player_HoldsTwoHandedWeapon(Player* this) { } s32 Player_HoldsBrokenKnife(Player* this) { - return (this->heldItemActionParam == PLAYER_AP_SWORD_BGS) && (gSaveContext.swordHealth <= 0.0f); + return (this->heldItemAction == PLAYER_IA_SWORD_BGS) && (gSaveContext.swordHealth <= 0.0f); } -s32 Player_ActionToBottle(Player* this, s32 actionParam) { - s32 bottle = actionParam - PLAYER_AP_BOTTLE; +s32 Player_ActionToBottle(Player* this, s32 itemAction) { + s32 bottle = itemAction - PLAYER_IA_BOTTLE; if ((bottle >= 0) && (bottle < 13)) { return bottle; @@ -746,11 +745,11 @@ s32 Player_ActionToBottle(Player* this, s32 actionParam) { } s32 Player_GetBottleHeld(Player* this) { - return Player_ActionToBottle(this, this->heldItemActionParam); + return Player_ActionToBottle(this, this->heldItemAction); } -s32 Player_ActionToExplosive(Player* this, s32 actionParam) { - s32 explosive = actionParam - PLAYER_AP_BOMB; +s32 Player_ActionToExplosive(Player* this, s32 itemAction) { + s32 explosive = itemAction - PLAYER_IA_BOMB; if ((explosive >= 0) && (explosive < 2)) { return explosive; @@ -760,14 +759,14 @@ s32 Player_ActionToExplosive(Player* this, s32 actionParam) { } s32 Player_GetExplosiveHeld(Player* this) { - return Player_ActionToExplosive(this, this->heldItemActionParam); + return Player_ActionToExplosive(this, this->heldItemAction); } -s32 func_8008F2BC(Player* this, s32 actionParam) { +s32 func_8008F2BC(Player* this, s32 itemAction) { s32 sword = 0; - if (actionParam != PLAYER_AP_LAST_USED) { - sword = actionParam - PLAYER_AP_SWORD_MASTER; + if (itemAction != PLAYER_IA_LAST_USED) { + sword = itemAction - PLAYER_IA_SWORD_MASTER; if ((sword < 0) || (sword >= 3)) { goto return_neg; } @@ -979,7 +978,7 @@ void func_8008F87C(PlayState* play, Player* this, SkelAnime* skelAnime, Vec3f* p s32 temp3; if ((this->actor.scale.y >= 0.0f) && !(this->stateFlags1 & PLAYER_STATE1_7) && - (Player_ActionToMagicSpell(this, this->itemActionParam) < 0)) { + (Player_ActionToMagicSpell(this, this->itemAction) < 0)) { s32 pad; sp7C = D_80126058[(void)0, gSaveContext.linkAge]; @@ -1454,7 +1453,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList, Ve Math_Vec3f_Copy(&this->leftHandPos, sCurBodyPartPos); - if (this->itemActionParam == PLAYER_AP_STICK) { + if (this->itemAction == PLAYER_IA_STICK) { Vec3f sp124[3]; OPEN_DISPS(play->state.gfxCtx, "../z_player_lib.c", 2633); @@ -1490,7 +1489,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList, Ve func_80090A28(this, spE4); func_800906D4(play, this, spE4); } else if ((*dList != NULL) && (this->leftHandType == PLAYER_MODELTYPE_LH_BOTTLE)) { - Color_RGB8* bottleColor = &sBottleColors[Player_ActionToBottle(this, this->itemActionParam)]; + Color_RGB8* bottleColor = &sBottleColors[Player_ActionToBottle(this, this->itemAction)]; OPEN_DISPS(play->state.gfxCtx, "../z_player_lib.c", 2710); @@ -1580,8 +1579,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList, Ve } if (this->actor.scale.y >= 0.0f) { - if ((this->heldItemActionParam == PLAYER_AP_HOOKSHOT) || - (this->heldItemActionParam == PLAYER_AP_LONGSHOT)) { + if ((this->heldItemAction == PLAYER_IA_HOOKSHOT) || (this->heldItemAction == PLAYER_IA_LONGSHOT)) { Matrix_MultVec3f(&D_80126184, &this->unk_3C8); if (heldActor != NULL) { @@ -1596,8 +1594,8 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList, Ve if (func_8002DD78(this) != 0) { Matrix_Translate(500.0f, 300.0f, 0.0f, MTXMODE_APPLY); - Player_DrawHookshotReticle( - play, this, (this->heldItemActionParam == PLAYER_AP_HOOKSHOT) ? 38600.0f : 77600.0f); + Player_DrawHookshotReticle(play, this, + (this->heldItemAction == PLAYER_IA_HOOKSHOT) ? 38600.0f : 77600.0f); } } } diff --git a/src/code/z_scene.c b/src/code/z_scene.c index 6f21159949..ac1c779ef5 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); } } diff --git a/src/overlays/actors/ovl_Arms_Hook/z_arms_hook.c b/src/overlays/actors/ovl_Arms_Hook/z_arms_hook.c index 2cef55d6e2..66e85a9841 100644 --- a/src/overlays/actors/ovl_Arms_Hook/z_arms_hook.c +++ b/src/overlays/actors/ovl_Arms_Hook/z_arms_hook.c @@ -84,7 +84,7 @@ void ArmsHook_Wait(ArmsHook* this, PlayState* play) { if (this->actor.parent == NULL) { Player* player = GET_PLAYER(play); // get correct timer length for hookshot or longshot - s32 length = (player->heldItemActionParam == PLAYER_AP_HOOKSHOT) ? 13 : 26; + s32 length = (player->heldItemAction == PLAYER_IA_HOOKSHOT) ? 13 : 26; ArmsHook_SetupAction(this, ArmsHook_Shoot); func_8002D9A4(&this->actor, 20.0f); @@ -120,7 +120,7 @@ s32 ArmsHook_CheckForCancel(ArmsHook* this) { Player* player = (Player*)this->actor.parent; if (Player_HoldsHookshot(player)) { - if ((player->itemActionParam != player->heldItemActionParam) || (player->actor.flags & ACTOR_FLAG_8) || + if ((player->itemAction != player->heldItemAction) || (player->actor.flags & ACTOR_FLAG_8) || ((player->stateFlags1 & (PLAYER_STATE1_7 | PLAYER_STATE1_26)))) { this->timer = 0; ArmsHook_DetachHookFromActor(this); diff --git a/src/overlays/actors/ovl_Bg_Ice_Shelter/z_bg_ice_shelter.c b/src/overlays/actors/ovl_Bg_Ice_Shelter/z_bg_ice_shelter.c index a33b969926..c79be69f9e 100644 --- a/src/overlays/actors/ovl_Bg_Ice_Shelter/z_bg_ice_shelter.c +++ b/src/overlays/actors/ovl_Bg_Ice_Shelter/z_bg_ice_shelter.c @@ -1,18 +1,27 @@ +/* + * File: z_bg_ice_shelter.c + * Overlay: Bg_Ice_Shelter + * Description: Red Ice + */ + #include "z_bg_ice_shelter.h" #include "assets/objects/object_ice_objects/object_ice_objects.h" #define FLAGS 0 +#define BGICESHELTER_GET_TYPE(thisx) (((thisx)->params >> 8) & 7) +#define BGICESHELTER_NO_SWITCH_FLAG(thisx) (((thisx)->params >> 6) & 1) + void BgIceShelter_Init(Actor* thisx, PlayState* play); void BgIceShelter_Destroy(Actor* thisx, PlayState* play); void BgIceShelter_Update(Actor* thisx, PlayState* play); void BgIceShelter_Draw(Actor* thisx, PlayState* play2); -void func_80891064(BgIceShelter* this); -void func_808911BC(BgIceShelter* this); +void BgIceShelter_SetupIdle(BgIceShelter* this); +void BgIceShelter_SetupMelt(BgIceShelter* this); -void func_8089107C(BgIceShelter* this, PlayState* play); -void func_808911D4(BgIceShelter* this, PlayState* play); +void BgIceShelter_Idle(BgIceShelter* this, PlayState* play); +void BgIceShelter_Melt(BgIceShelter* this, PlayState* play); const ActorInit Bg_Ice_Shelter_InitVars = { ACTOR_BG_ICE_SHELTER, @@ -26,12 +35,12 @@ const ActorInit Bg_Ice_Shelter_InitVars = { (ActorFunc)BgIceShelter_Draw, }; -static f32 sScales[] = { 0.1f, 0.06f, 0.1f, 0.1f, 0.25f }; +static f32 sRedIceScales[] = { 0.1f, 0.06f, 0.1f, 0.1f, 0.25f }; -static Color_RGBA8 sDustPrimColor = { 250, 250, 250, 255 }; -static Color_RGBA8 sDustEnvColor = { 180, 180, 180, 255 }; +static Color_RGBA8 sSteamPrimColor = { 250, 250, 250, 255 }; +static Color_RGBA8 sSteamEnvColor = { 180, 180, 180, 255 }; -static ColliderCylinderInit D_8089170C = { +static ColliderCylinderInit sCylinderInit1 = { { COLTYPE_NONE, AT_NONE, @@ -51,7 +60,7 @@ static ColliderCylinderInit D_8089170C = { { 0, 0, 0, { 0, 0, 0 } }, }; -static ColliderCylinderInit D_80891738 = { +static ColliderCylinderInit sCylinderInit2 = { { COLTYPE_HARD, AT_NONE, @@ -71,34 +80,39 @@ static ColliderCylinderInit D_80891738 = { { 0, 0, 0, { 0, 0, 0 } }, }; -void func_80890740(BgIceShelter* this, PlayState* play) { +/** + * Initializes either one or both cylinder colliders, depending on the actor's type. + */ +void BgIceShelter_InitColliders(BgIceShelter* this, PlayState* play) { static s16 cylinderRadii[] = { 47, 33, 44, 41, 100 }; static s16 cylinderHeights[] = { 80, 54, 90, 60, 200 }; s32 pad; - s32 type = (this->dyna.actor.params >> 8) & 7; + s32 type = BGICESHELTER_GET_TYPE(&this->dyna.actor); + // All types use at least one collider in order to detect blue fire Collider_InitCylinder(play, &this->cylinder1); - Collider_SetCylinder(play, &this->cylinder1, &this->dyna.actor, &D_8089170C); + Collider_SetCylinder(play, &this->cylinder1, &this->dyna.actor, &sCylinderInit1); Collider_UpdateCylinder(&this->dyna.actor, &this->cylinder1); this->cylinder1.dim.radius = cylinderRadii[type]; this->cylinder1.dim.height = cylinderHeights[type]; - if (type == 0 || type == 1 || type == 4) { + // The wall and platform types use DynaPoly for collision, so they don't need the second collider + if (type == RED_ICE_LARGE || type == RED_ICE_SMALL || type == RED_ICE_KING_ZORA) { Collider_InitCylinder(play, &this->cylinder2); - Collider_SetCylinder(play, &this->cylinder2, &this->dyna.actor, &D_80891738); + Collider_SetCylinder(play, &this->cylinder2, &this->dyna.actor, &sCylinderInit2); Collider_UpdateCylinder(&this->dyna.actor, &this->cylinder2); this->cylinder2.dim.radius = cylinderRadii[type]; this->cylinder2.dim.height = cylinderHeights[type]; } - if (type == 4) { + if (type == RED_ICE_KING_ZORA) { this->cylinder1.dim.pos.z += 30; this->cylinder2.dim.pos.z += 30; } } -void func_80890874(BgIceShelter* this, PlayState* play, CollisionHeader* collision, s32 moveFlag) { +void BgIceShelter_InitDynaPoly(BgIceShelter* this, PlayState* play, CollisionHeader* collision, s32 moveFlag) { s32 pad; CollisionHeader* colHeader = NULL; s32 pad2; @@ -114,7 +128,7 @@ void func_80890874(BgIceShelter* this, PlayState* play, CollisionHeader* collisi } } -void func_808908FC(Vec3f* dest, Vec3f* src, s16 angle) { +void BgIceShelter_RotateY(Vec3f* dest, Vec3f* src, s16 angle) { f32 sin = Math_SinS(angle); f32 cos = Math_CosS(angle); @@ -132,42 +146,45 @@ static InitChainEntry sInitChain[] = { void BgIceShelter_Init(Actor* thisx, PlayState* play) { static Vec3f kzIceScale = { 0.18f, 0.27f, 0.24f }; BgIceShelter* this = (BgIceShelter*)thisx; - s16 type = (this->dyna.actor.params >> 8) & 7; + s16 type = BGICESHELTER_GET_TYPE(&this->dyna.actor); Actor_ProcessInitChain(&this->dyna.actor, sInitChain); - if (type == 4) { + if (type == RED_ICE_KING_ZORA) { this->dyna.actor.world.rot.x += 0xBB8; this->dyna.actor.world.pos.y -= 45.0f; this->dyna.actor.shape.rot.x = this->dyna.actor.world.rot.x; this->dyna.actor.world.pos.z -= 38.0f; } - if (type == 4) { + if (type == RED_ICE_KING_ZORA) { Math_Vec3f_Copy(&this->dyna.actor.scale, &kzIceScale); } else { - Actor_SetScale(&this->dyna.actor, sScales[type]); + Actor_SetScale(&this->dyna.actor, sRedIceScales[type]); } + // Only 2 types use DynaPoly switch (type) { - case 2: - func_80890874(this, play, &object_ice_objects_Col_001C1C, 0); + case RED_ICE_PLATFORM: + BgIceShelter_InitDynaPoly(this, play, &gRedIcePlatformCol, 0); break; - case 3: - func_80890874(this, play, &object_ice_objects_Col_002920, 0); + case RED_ICE_WALL: + BgIceShelter_InitDynaPoly(this, play, &gRedIceWallCol, 0); break; } - func_80890740(this, play); + // All types use at least one collider + BgIceShelter_InitColliders(this, play); this->dyna.actor.colChkInfo.mass = MASS_IMMOVABLE; - if (!((this->dyna.actor.params >> 6) & 1) && (Flags_GetSwitch(play, this->dyna.actor.params & 0x3F))) { + // The only red ice actor in the game that doesn't use a switch flag is the one for King Zora + if (!BGICESHELTER_NO_SWITCH_FLAG(&this->dyna.actor) && (Flags_GetSwitch(play, this->dyna.actor.params & 0x3F))) { Actor_Kill(&this->dyna.actor); return; } - func_80891064(this); + BgIceShelter_SetupIdle(this); osSyncPrintf("(ice shelter)(arg_data 0x%04x)\n", this->dyna.actor.params); } @@ -175,15 +192,15 @@ void BgIceShelter_Init(Actor* thisx, PlayState* play) { void BgIceShelter_Destroy(Actor* thisx, PlayState* play) { BgIceShelter* this = (BgIceShelter*)thisx; - switch ((this->dyna.actor.params >> 8) & 7) { - case 2: - case 3: + switch (BGICESHELTER_GET_TYPE(&this->dyna.actor)) { + case RED_ICE_PLATFORM: + case RED_ICE_WALL: DynaPoly_DeleteBgActor(play, &play->colCtx.dyna, this->dyna.bgId); break; - case 0: - case 1: - case 4: + case RED_ICE_LARGE: + case RED_ICE_SMALL: + case RED_ICE_KING_ZORA: Collider_DestroyCylinder(play, &this->cylinder2); break; } @@ -191,126 +208,155 @@ void BgIceShelter_Destroy(Actor* thisx, PlayState* play) { Collider_DestroyCylinder(play, &this->cylinder1); } -static s16 D_80891794[] = { 0x0000, 0x4000, 0x2000, 0x6000, 0x1000, 0x5000, 0x3000, 0x7000 }; -static s16 D_808917A4[] = { 0x0000, 0x003C, 0x0018, 0x0054, 0x0030, 0x000C, 0x0048, 0x0024 }; +/** + * Angles used to spawn steam particles in a circle. + */ +static s16 sSteamCircleAngles[] = { 0x0000, 0x4000, 0x2000, 0x6000, 0x1000, 0x5000, 0x3000, 0x7000 }; -void func_80890B8C(BgIceShelter* this, PlayState* play, f32 chance, f32 scale) { +/** + * Positions used to spawn steam particles in a straight line. + */ +static s16 sSteamLinePositions[] = { 0x0000, 0x003C, 0x0018, 0x0054, 0x0030, 0x000C, 0x0048, 0x0024 }; + +/** + * Spawns steam particle effects in a circle around the ice block. + * + * On each frame the function is called, two particles have a chance to appear, at the same distance and opposite + * sides from the center. + */ +void BgIceShelter_SpawnSteamAround(BgIceShelter* this, PlayState* play, f32 particleSpawningChance, + f32 steamEffectScale) { f32 cos; f32 sin; - f32 xzOffset; + f32 distance; Vec3f* icePos; s16 angle; - s16 frames; + s16 frameCounter; s32 i; s32 pad[2]; - Vec3f dustPos; - Vec3f dustVel; - Vec3f dustAccel; + Vec3f steamPos; + Vec3f steamVel; + Vec3f steamAccel; - frames = (s16)play->state.frames & 7; + frameCounter = (s16)play->state.frames & 7; for (i = 0; i < 2; i++) { - if (chance < Rand_ZeroOne()) { + if (particleSpawningChance < Rand_ZeroOne()) { continue; } - xzOffset = 42.0f * scale; + // The steamEffectScale is used here to make the particles appear at the edges of the red ice. + distance = 42.0f * steamEffectScale; icePos = &this->dyna.actor.world.pos; - angle = D_80891794[frames] + (i * 0x8000); + angle = sSteamCircleAngles[frameCounter] + (i * 0x8000); sin = Math_SinS(angle); cos = Math_CosS(angle); - dustPos.x = (xzOffset * sin) + icePos->x; - dustPos.y = (16.0f * scale) + icePos->y; - dustPos.z = (xzOffset * cos) + icePos->z; + steamPos.x = (distance * sin) + icePos->x; + steamPos.y = (16.0f * steamEffectScale) + icePos->y; + steamPos.z = (distance * cos) + icePos->z; - dustVel.x = ((Rand_ZeroOne() * 3.0f) - 1.0f) * sin; - dustVel.y = 0.0f; - dustVel.z = ((Rand_ZeroOne() * 3.0f) - 1.0f) * cos; + steamVel.x = ((Rand_ZeroOne() * 3.0f) - 1.0f) * sin; + steamVel.y = 0.0f; + steamVel.z = ((Rand_ZeroOne() * 3.0f) - 1.0f) * cos; - dustAccel.x = 0.07f * sin; - dustAccel.y = 0.8f; - dustAccel.z = 0.07f * cos; + steamAccel.x = 0.07f * sin; + steamAccel.y = 0.8f; + steamAccel.z = 0.07f * cos; - func_8002829C(play, &dustPos, &dustVel, &dustAccel, &sDustPrimColor, &sDustEnvColor, 450.0f * scale, - (s16)((Rand_ZeroOne() * 40.0f) + 40.0f) * scale); + func_8002829C(play, &steamPos, &steamVel, &steamAccel, &sSteamPrimColor, &sSteamEnvColor, + 450.0f * steamEffectScale, (s16)((Rand_ZeroOne() * 40.0f) + 40.0f) * steamEffectScale); } } -void func_80890E00(BgIceShelter* this, PlayState* play, f32 chance, f32 arg3) { - static f32 D_808917B4[] = { -1.0f, 1.0f }; +/** + * Spawns steam particle effects in a straight line. Only used for the ice wall type. + * + * On each frame the function is called, two particles have a chance to appear, at the same distance and opposite + * sides from the midpoint. + * + * The last argument is unused because only one red ice type can call this function, so the scale isn't needed. + */ +void BgIceShelter_SpawnSteamAlong(BgIceShelter* this, PlayState* play, f32 particleSpawningChance, f32 unusedArg) { + static f32 signs[] = { -1.0f, 1.0f }; Vec3f* icePos; - s16 frames; + s16 frameCounter; s32 pad[2]; - Vec3f dustPos; - Vec3f dustVel; - Vec3f dustAccel; + Vec3f steamPos; + Vec3f steamVel; + Vec3f steamAccel; Vec3f posOffset; s32 i; - frames = (s16)play->state.frames & 7; + frameCounter = (s16)play->state.frames & 7; for (i = 0; i < 2; i++) { icePos = &this->dyna.actor.world.pos; - if (chance < Rand_ZeroOne()) { + if (particleSpawningChance < Rand_ZeroOne()) { continue; } - posOffset.x = (D_808917A4[frames] + ((Rand_ZeroOne() * 12.0f) - 6.0f)) * D_808917B4[i]; + posOffset.x = (sSteamLinePositions[frameCounter] + ((Rand_ZeroOne() * 12.0f) - 6.0f)) * signs[i]; posOffset.y = 15.0f; posOffset.z = ((84.0f - posOffset.x) * 0.2f) + (Rand_ZeroOne() * 20.0f); - func_808908FC(&dustPos, &posOffset, this->dyna.actor.world.rot.y); - Math_Vec3f_Sum(&dustPos, icePos, &dustPos); + // Convert the position offset from relative to the ice wall to absolute. + BgIceShelter_RotateY(&steamPos, &posOffset, this->dyna.actor.world.rot.y); + Math_Vec3f_Sum(&steamPos, icePos, &steamPos); - dustVel.x = (Rand_ZeroOne() * 3.0f) - 1.5f; - dustVel.y = 0.0f; - dustVel.z = (Rand_ZeroOne() * 3.0f) - 1.5f; + steamVel.x = (Rand_ZeroOne() * 3.0f) - 1.5f; + steamVel.y = 0.0f; + steamVel.z = (Rand_ZeroOne() * 3.0f) - 1.5f; - dustAccel.x = (Rand_ZeroOne() * 0.14f) - 0.07f; - dustAccel.y = 0.8f; - dustAccel.z = (Rand_ZeroOne() * 0.14f) - 0.07f; + steamAccel.x = (Rand_ZeroOne() * 0.14f) - 0.07f; + steamAccel.y = 0.8f; + steamAccel.z = (Rand_ZeroOne() * 0.14f) - 0.07f; - func_8002829C(play, &dustPos, &dustVel, &dustAccel, &sDustPrimColor, &sDustEnvColor, 450, + func_8002829C(play, &steamPos, &steamVel, &steamAccel, &sSteamPrimColor, &sSteamEnvColor, 450, (Rand_ZeroOne() * 40.0f) + 40.0f); } } -void func_80891064(BgIceShelter* this) { - this->actionFunc = func_8089107C; +void BgIceShelter_SetupIdle(BgIceShelter* this) { + this->actionFunc = BgIceShelter_Idle; this->alpha = 255; } -void func_8089107C(BgIceShelter* this, PlayState* play) { +/** + * Checks for collision with blue fire. Also used to freeze King Zora's actor. + */ +void BgIceShelter_Idle(BgIceShelter* this, PlayState* play) { s32 pad; - s16 type = (this->dyna.actor.params >> 8) & 7; + s16 type = BGICESHELTER_GET_TYPE(&this->dyna.actor); - if (type == 4) { + // Freeze King Zora + if (type == RED_ICE_KING_ZORA) { if (this->dyna.actor.parent != NULL) { this->dyna.actor.parent->freezeTimer = 10000; } } + // Detect blue fire if (this->cylinder1.base.acFlags & AC_HIT) { this->cylinder1.base.acFlags &= ~AC_HIT; if ((this->cylinder1.base.ac != NULL) && (this->cylinder1.base.ac->id == ACTOR_EN_ICE_HONO)) { - if (type == 4) { + if (type == RED_ICE_KING_ZORA) { if (this->dyna.actor.parent != NULL) { this->dyna.actor.parent->freezeTimer = 50; } } - func_808911BC(this); + BgIceShelter_SetupMelt(this); Audio_PlayActorSfx2(&this->dyna.actor, NA_SE_EV_ICE_MELT); } } switch (type) { - case 0: - case 1: - case 4: + case RED_ICE_LARGE: + case RED_ICE_SMALL: + case RED_ICE_KING_ZORA: CollisionCheck_SetOC(play, &play->colChkCtx, &this->cylinder1.base); CollisionCheck_SetAC(play, &play->colChkCtx, &this->cylinder2.base); break; @@ -319,57 +365,73 @@ void func_8089107C(BgIceShelter* this, PlayState* play) { CollisionCheck_SetAC(play, &play->colChkCtx, &this->cylinder1.base); } -void func_808911BC(BgIceShelter* this) { - this->actionFunc = func_808911D4; +void BgIceShelter_SetupMelt(BgIceShelter* this) { + this->actionFunc = BgIceShelter_Melt; this->alpha = 255; } -static f32 D_808917BC[] = { -0.0015f, -0.0009f, -0.0016f, -0.0016f, -0.00375f }; -static f32 D_808917D0[] = { 1.0f, 0.6f, 1.2f, 1.0f, 1.8f }; +/** + * Values added to the ice block's height every frame while it's melting. + */ +static f32 sMeltingRates[] = { -0.0015f, -0.0009f, -0.0016f, -0.0016f, -0.00375f }; -static void (*sEffSpawnFuncs[])(BgIceShelter* this, PlayState* play, f32 chance, f32 scale) = { - func_80890B8C, func_80890B8C, func_80890B8C, func_80890E00, func_80890B8C, +/** + * Values used to scale and position the steam effects so they match the ice block's size. + */ +static f32 sSteamEffectScales[] = { 1.0f, 0.6f, 1.2f, 1.0f, 1.8f }; + +/** + * Functions used to spawn steam effects at the base of the red ice. + */ +static void (*sSteamSpawnFuncs[])(BgIceShelter* this, PlayState* play, f32 particleSpawningChance, + f32 steamEffectScale) = { + BgIceShelter_SpawnSteamAround, BgIceShelter_SpawnSteamAround, BgIceShelter_SpawnSteamAround, + BgIceShelter_SpawnSteamAlong, BgIceShelter_SpawnSteamAround, }; -void func_808911D4(BgIceShelter* this, PlayState* play) { +/** + * Progressively reduces the height and opacity of the red ice, while spawning steam effects at its base. + */ +void BgIceShelter_Melt(BgIceShelter* this, PlayState* play) { s32 pad; - s32 type = (this->dyna.actor.params >> 8) & 7; - f32 phi_f0; + s32 type = BGICESHELTER_GET_TYPE(&this->dyna.actor); + f32 particleSpawningChance; this->alpha -= 5; this->alpha = CLAMP(this->alpha, 0, 255); - this->dyna.actor.scale.y += D_808917BC[type]; + this->dyna.actor.scale.y += sMeltingRates[type]; this->dyna.actor.scale.y = CLAMP_MIN(this->dyna.actor.scale.y, 0.0001f); if (this->alpha > 80) { switch (type) { - case 0: - case 1: - case 4: + case RED_ICE_LARGE: + case RED_ICE_SMALL: + case RED_ICE_KING_ZORA: CollisionCheck_SetOC(play, &play->colChkCtx, &this->cylinder1.base); CollisionCheck_SetAC(play, &play->colChkCtx, &this->cylinder2.base); break; } } + // As the ice melts, the steam intensity is reduced by lowering the chance of each steam particle to appear if (this->alpha > 180) { - phi_f0 = 1.0f; + particleSpawningChance = 1.0f; } else if (this->alpha > 60) { - phi_f0 = 0.5f; + particleSpawningChance = 0.5f; } else { - phi_f0 = 0.0f; + particleSpawningChance = 0.0f; } - sEffSpawnFuncs[type](this, play, phi_f0, D_808917D0[type]); + sSteamSpawnFuncs[type](this, play, particleSpawningChance, sSteamEffectScales[type]); if (this->alpha <= 0) { - if (!((this->dyna.actor.params >> 6) & 1)) { + if (!BGICESHELTER_NO_SWITCH_FLAG(&this->dyna.actor)) { Flags_SetSwitch(play, this->dyna.actor.params & 0x3F); } - if (type == 4) { + if (type == RED_ICE_KING_ZORA) { func_80078884(NA_SE_SY_CORRECT_CHIME); } @@ -394,29 +456,29 @@ void BgIceShelter_Draw(Actor* thisx, PlayState* play2) { gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx, "../z_bg_ice_shelter.c", 751), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - switch ((this->dyna.actor.params >> 8) & 7) { - case 0: - case 1: - case 2: - case 4: + switch (BGICESHELTER_GET_TYPE(&this->dyna.actor)) { + case RED_ICE_LARGE: + case RED_ICE_SMALL: + case RED_ICE_PLATFORM: + case RED_ICE_KING_ZORA: func_8002ED80(&this->dyna.actor, play, 0); break; } gDPSetEnvColor(POLY_XLU_DISP++, 255, 0, 0, this->alpha); - switch ((this->dyna.actor.params >> 8) & 7) { - case 0: - case 1: - case 4: + switch (BGICESHELTER_GET_TYPE(&this->dyna.actor)) { + case RED_ICE_LARGE: + case RED_ICE_SMALL: + case RED_ICE_KING_ZORA: gSPSegment(POLY_XLU_DISP++, 0x08, Gfx_TwoTexScroll(play->state.gfxCtx, G_TX_RENDERTILE, -play->gameplayFrames & 0x7F, -play->gameplayFrames & 0x7F, 0x20, 0x20, 1, -play->gameplayFrames & 0x7F, play->gameplayFrames & 0x7F, 0x20, 0x20)); - gSPDisplayList(POLY_XLU_DISP++, object_ice_objects_DL_0006F0); + gSPDisplayList(POLY_XLU_DISP++, gRedIceBlockDL); break; - case 2: + case RED_ICE_PLATFORM: gSPSegment(POLY_XLU_DISP++, 0x08, Gfx_TwoTexScroll(play->state.gfxCtx, G_TX_RENDERTILE, 0, play->gameplayFrames & 0xFF, 0x40, 0x40, 1, 0, -play->gameplayFrames & 0xFF, 0x40, 0x40)); @@ -424,11 +486,11 @@ void BgIceShelter_Draw(Actor* thisx, PlayState* play2) { Gfx_TwoTexScroll(play->state.gfxCtx, G_TX_RENDERTILE, -play->gameplayFrames & 0xFF, play->gameplayFrames & 0xFF, 0x40, 0x40, 1, play->gameplayFrames & 0xFF, play->gameplayFrames & 0xFF, 0x40, 0x40)); - gSPDisplayList(POLY_XLU_DISP++, object_ice_objects_DL_0012A0); + gSPDisplayList(POLY_XLU_DISP++, gRedIcePlatformDL); break; - case 3: - gSPDisplayList(POLY_XLU_DISP++, object_ice_objects_DL_002640); + case RED_ICE_WALL: + gSPDisplayList(POLY_XLU_DISP++, gRedIceWallDL); break; } diff --git a/src/overlays/actors/ovl_Bg_Ice_Shelter/z_bg_ice_shelter.h b/src/overlays/actors/ovl_Bg_Ice_Shelter/z_bg_ice_shelter.h index 40c715f644..7fb4a0514b 100644 --- a/src/overlays/actors/ovl_Bg_Ice_Shelter/z_bg_ice_shelter.h +++ b/src/overlays/actors/ovl_Bg_Ice_Shelter/z_bg_ice_shelter.h @@ -8,11 +8,19 @@ struct BgIceShelter; typedef void (*BgIceShelterActionFunc)(struct BgIceShelter*, PlayState*); +typedef enum { + /* 0 */ RED_ICE_LARGE, // Large red ice block + /* 1 */ RED_ICE_SMALL, // Small red ice block + /* 2 */ RED_ICE_PLATFORM, // Complex structure that can be climbed and walked on. Unused in vanilla OoT, used in MQ to cover the Ice Cavern Map chest + /* 3 */ RED_ICE_WALL, // Vertical ice sheets blocking corridors + /* 4 */ RED_ICE_KING_ZORA // Giant red ice block covering King Zora +} RedIceType; + typedef struct BgIceShelter { /* 0x0000 */ DynaPolyActor dyna; /* 0x0164 */ BgIceShelterActionFunc actionFunc; - /* 0x0168 */ ColliderCylinder cylinder1; - /* 0x01B4 */ ColliderCylinder cylinder2; + /* 0x0168 */ ColliderCylinder cylinder1; // Used to detect blue fire and also as OC for no-dynapoly types + /* 0x01B4 */ ColliderCylinder cylinder2; // Only used by no-dynapoly types to make weapons bounce off /* 0x0200 */ s16 alpha; } BgIceShelter; // size = 0x0204 diff --git a/src/overlays/actors/ovl_Bg_Toki_Swd/z_bg_toki_swd.c b/src/overlays/actors/ovl_Bg_Toki_Swd/z_bg_toki_swd.c index 96d8cc302d..5c6c9ec702 100644 --- a/src/overlays/actors/ovl_Bg_Toki_Swd/z_bg_toki_swd.c +++ b/src/overlays/actors/ovl_Bg_Toki_Swd/z_bg_toki_swd.c @@ -107,8 +107,8 @@ void func_808BAF40(BgTokiSwd* this, PlayState* play) { } else { play->csCtx.segment = D_808BB7A0; } - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_STOP); - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_MASTER_SWORD); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_MASTER_SWORD); gSaveContext.cutsceneTrigger = 1; this->actor.parent = NULL; BgTokiSwd_SetupAction(this, func_808BB0AC); diff --git a/src/overlays/actors/ovl_Bg_Ydan_Sp/z_bg_ydan_sp.c b/src/overlays/actors/ovl_Bg_Ydan_Sp/z_bg_ydan_sp.c index 25ff811ec2..69737cdf65 100644 --- a/src/overlays/actors/ovl_Bg_Ydan_Sp/z_bg_ydan_sp.c +++ b/src/overlays/actors/ovl_Bg_Ydan_Sp/z_bg_ydan_sp.c @@ -399,7 +399,7 @@ void BgYdanSp_WallWebIdle(BgYdanSp* this, PlayState* play) { if (Flags_GetSwitch(play, this->burnSwitchFlag) || (this->trisCollider.base.acFlags & AC_HIT)) { this->dyna.actor.home.pos.y = this->dyna.actor.world.pos.y + 80.0f; BgYdanSp_BurnWeb(this, play); - } else if (player->heldItemActionParam == PLAYER_AP_STICK && player->unk_860 != 0) { + } else if (player->heldItemAction == PLAYER_IA_STICK && player->unk_860 != 0) { func_8002DBD0(&this->dyna.actor, &sp30, &player->meleeWeaponInfo[0].tip); if (fabsf(sp30.x) < 100.0f && sp30.z < 1.0f && sp30.y < 200.0f) { OnePointCutscene_Init(play, 3020, 40, &this->dyna.actor, CAM_ID_MAIN); diff --git a/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c b/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c index aef29c7aee..ace123bcfd 100644 --- a/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c +++ b/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c @@ -319,7 +319,7 @@ void BossDodongo_IntroCutscene(BossDodongo* this, PlayState* play) { BossDodongo_Walk(this, play); if (this->unk_196 == 1) { - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); } if (this->unk_196 == 0) { @@ -407,7 +407,7 @@ void BossDodongo_IntroCutscene(BossDodongo* this, PlayState* play) { SEGMENTED_TO_VIRTUAL(&object_kingdodongo_Blob_017410), 0xA0, 0xB4, 0x80, 0x28); } - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_FIRE_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_FIRE_BOSS); } if (this->unk_198 == 0) { @@ -1284,7 +1284,7 @@ void BossDodongo_SetupDeathCutscene(BossDodongo* this) { this->csState = 0; this->actor.flags &= ~(ACTOR_FLAG_0 | ACTOR_FLAG_2); this->unk_1BC = 1; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); } void BossDodongo_DeathCutscene(BossDodongo* this, PlayState* play) { @@ -1598,7 +1598,7 @@ void BossDodongo_DeathCutscene(BossDodongo* this, PlayState* play) { } if (this->unk_1DA == 820) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS_CLEAR); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS_CLEAR); Actor_Spawn(&play->actorCtx, play, ACTOR_ITEM_B_HEART, Math_SinS(this->actor.shape.rot.y) * -50.0f + this->actor.world.pos.x, this->actor.world.pos.y, diff --git a/src/overlays/actors/ovl_Boss_Fd/z_boss_fd.c b/src/overlays/actors/ovl_Boss_Fd/z_boss_fd.c index fd16437c74..477b3a2186 100644 --- a/src/overlays/actors/ovl_Boss_Fd/z_boss_fd.c +++ b/src/overlays/actors/ovl_Boss_Fd/z_boss_fd.c @@ -185,7 +185,7 @@ void BossFd_Init(Actor* thisx, PlayState* play) { SkelAnime_Init(play, &this->skelAnimeLeftArm, &gVolvagiaLeftArmSkel, &gVolvagiaLeftArmEmergeAnim, NULL, NULL, 0); this->introState = BFD_CS_WAIT; if (this->introState == BFD_CS_NONE) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_FIRE_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_FIRE_BOSS); } this->actor.world.pos.x = this->actor.world.pos.z = 0.0f; @@ -486,7 +486,7 @@ void BossFd_Fly(BossFd* this, PlayState* play) { this->subCamAtYOffset = Math_CosS(this->work[BFD_MOVE_TIMER] * 0x8000) * this->subCamShake; } if (this->timers[3] == 160) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_FIRE_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_FIRE_BOSS); } if ((this->timers[3] == 130) && !GET_EVENTCHKINF(EVENTCHKINF_73)) { TitleCard_InitBossName(play, &play->actorCtx.titleCtx, @@ -743,7 +743,7 @@ void BossFd_Fly(BossFd* this, PlayState* play) { if (this->skinSegments != 0) { this->skinSegments--; if (this->skinSegments == 0) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS_CLEAR); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS_CLEAR); } } else { this->work[BFD_ACTION_STATE] = BOSSFD_BONES_FALL; diff --git a/src/overlays/actors/ovl_Boss_Fd2/z_boss_fd2.c b/src/overlays/actors/ovl_Boss_Fd2/z_boss_fd2.c index 8642c77c04..43afbefc9b 100644 --- a/src/overlays/actors/ovl_Boss_Fd2/z_boss_fd2.c +++ b/src/overlays/actors/ovl_Boss_Fd2/z_boss_fd2.c @@ -884,7 +884,7 @@ void BossFd2_CollisionCheck(BossFd2* this, PlayState* play) { BossFd2_SetupDeath(this, play); this->work[FD2_DAMAGE_FLASH_TIMER] = 10; this->work[FD2_INVINC_TIMER] = 30000; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); Audio_PlayActorSfx2(&this->actor, NA_SE_EN_VALVAISA_DEAD); Enemy_StartFinishingBlow(play, &this->actor); } else if (damage) { diff --git a/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c b/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c index 371330da66..b44e7191b2 100644 --- a/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c +++ b/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c @@ -575,7 +575,7 @@ void BossGanon_IntroCutscene(BossGanon* this, PlayState* play) { this->unk_198 = 2; this->timers[2] = 110; gSaveContext.healthAccumulator = 0x140; - Audio_QueueSeqCmd(NA_BGM_STOP); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0); } else { this->useOpenHand = true; BossGanon_SetIntroCsCamera(this, 0); @@ -807,7 +807,7 @@ void BossGanon_IntroCutscene(BossGanon* this, PlayState* play) { BossGanon_SetIntroCsCamera(this, 9); if (this->csTimer == 30) { - Audio_QueueSeqCmd(0x100100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); this->fwork[GDF_FWORK_1] = Animation_GetLastFrame(&gGanondorfStopPlayingOrganAnim); Animation_MorphToPlayOnce(&this->skelAnime, &gGanondorfStopPlayingOrganAnim, -5.0f); } @@ -1074,7 +1074,7 @@ void BossGanon_IntroCutscene(BossGanon* this, PlayState* play) { sCape->attachShouldersTimer = 18.0f; Audio_PlayActorSfx2(&this->actor, NA_SE_EV_GANON_MANTLE); this->unk_198 = 0; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_GANONDORF_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_GANONDORF_BOSS); } if (this->csTimer == 50) { @@ -2738,7 +2738,7 @@ void BossGanon_UpdateDamage(BossGanon* this, PlayState* play) { Audio_PlayActorSfx2(&this->actor, NA_SE_EN_GANON_DEAD); Audio_PlayActorSfx2(&this->actor, NA_SE_EN_GANON_DD_THUNDER); func_80078914(&sZeroVec, NA_SE_EN_LAST_DAMAGE); - Audio_QueueSeqCmd(0x100100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); this->screenFlashTimer = 4; } else { Audio_PlayActorSfx2(&this->actor, NA_SE_EN_GANON_DAMAGE2); diff --git a/src/overlays/actors/ovl_Boss_Ganon2/z_boss_ganon2.c b/src/overlays/actors/ovl_Boss_Ganon2/z_boss_ganon2.c index 49e1748028..cce407735a 100644 --- a/src/overlays/actors/ovl_Boss_Ganon2/z_boss_ganon2.c +++ b/src/overlays/actors/ovl_Boss_Ganon2/z_boss_ganon2.c @@ -296,7 +296,7 @@ void func_808FD5F4(BossGanon2* this, PlayState* play) { this->unk_339 = 4; if (this->unk_398 == 10) { func_80078914(&D_80906D6C, NA_SE_EV_STONE_BOUND); - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_STOP); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0); } if (this->unk_398 == 20) { sZelda->unk_3C8 = 3; @@ -447,7 +447,7 @@ void func_808FD5F4(BossGanon2* this, PlayState* play) { this->actor.world.pos.x = -200.0f; this->actor.world.pos.y = this->actor.world.pos.y - 30.0f; this->actor.world.pos.z = -200.0f; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_OPENING_GANON); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_OPENING_GANON); } else { break; } @@ -592,7 +592,7 @@ void func_808FD5F4(BossGanon2* this, PlayState* play) { case 18: this->unk_339 = 6; if (this->unk_398 == 30) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_GANON_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_GANON_BOSS); } Math_ApproachF(&this->unk_30C, 7.0f, 1.0f, 0.1f); Math_ApproachF(&this->subCamEye.x, (this->actor.world.pos.x + 500.0f) - 350.0f, 0.1f, 1.0f); @@ -1636,7 +1636,7 @@ void func_8090120C(BossGanon2* this, PlayState* play) { temp_f12 = this->unk_1B8.z - player->actor.world.pos.z; temp_a0_2 = Math_Atan2S(temp_f12, temp_f14) - player->actor.shape.rot.y; if ((ABS(temp_a0_2) < 0x2000) && (sqrtf(SQ(temp_f14) + SQ(temp_f12)) < 70.0f) && - (player->meleeWeaponState != 0) && (player->heldItemActionParam == PLAYER_AP_SWORD_MASTER)) { + (player->meleeWeaponState != 0) && (player->heldItemAction == PLAYER_IA_SWORD_MASTER)) { func_80064520(play, &play->csCtx); this->subCamId = Play_CreateSubCamera(play); Play_ChangeCameraStatus(play, CAM_ID_MAIN, CAM_STAT_WAIT); @@ -1694,7 +1694,7 @@ void func_8090120C(BossGanon2* this, PlayState* play) { this->subCamAt.z = D_80907050[phi_a1].z + player->actor.world.pos.z; } if (this->unk_398 > 80) { - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); this->unk_39C = 75; this->unk_398 = 0; this->subCamEye.x = 112.0f; diff --git a/src/overlays/actors/ovl_Boss_Ganondrof/z_boss_ganondrof.c b/src/overlays/actors/ovl_Boss_Ganondrof/z_boss_ganondrof.c index e0d4ac4014..5388fb65be 100644 --- a/src/overlays/actors/ovl_Boss_Ganondrof/z_boss_ganondrof.c +++ b/src/overlays/actors/ovl_Boss_Ganondrof/z_boss_ganondrof.c @@ -928,7 +928,7 @@ void BossGanondrof_SetupDeath(BossGanondrof* this, PlayState* play) { Animation_PlayOnce(&this->skelAnime, &gPhantomGanonDeathBlowAnim); this->fwork[GND_END_FRAME] = Animation_GetLastFrame(&gPhantomGanonDeathBlowAnim); this->actionFunc = BossGanondrof_Death; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); Audio_PlayActorSfx2(&this->actor, NA_SE_EN_FANTOM_DEAD); this->deathState = DEATH_START; this->actor.flags &= ~ACTOR_FLAG_0; @@ -1101,7 +1101,7 @@ void BossGanondrof_Death(BossGanondrof* this, PlayState* play) { holdCamera = true; bodyDecayLevel = 10; if (this->timers[0] == 150) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS_CLEAR); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS_CLEAR); Actor_Spawn(&play->actorCtx, play, ACTOR_DOOR_WARP1, GND_BOSSROOM_CENTER_X, GND_BOSSROOM_CENTER_Y, GND_BOSSROOM_CENTER_Z, 0, 0, 0, WARP_DUNGEON_ADULT); } diff --git a/src/overlays/actors/ovl_Boss_Goma/z_boss_goma.c b/src/overlays/actors/ovl_Boss_Goma/z_boss_goma.c index 391a1026e9..e2c6bd4d06 100644 --- a/src/overlays/actors/ovl_Boss_Goma/z_boss_goma.c +++ b/src/overlays/actors/ovl_Boss_Goma/z_boss_goma.c @@ -407,7 +407,7 @@ void BossGoma_SetupDefeated(BossGoma* this, PlayState* play) { this->actor.flags &= ~(ACTOR_FLAG_0 | ACTOR_FLAG_2); this->actor.speedXZ = 0.0f; this->actor.shape.shadowScale = 0.0f; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); Audio_PlayActorSfx2(&this->actor, NA_SE_EN_GOMA_DEAD); } @@ -659,7 +659,7 @@ void BossGoma_SetupEncounterState4(BossGoma* this, PlayState* play) { this->subCamAt.y = this->actor.world.pos.y; this->subCamAt.z = this->actor.world.pos.z; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); } /** @@ -924,7 +924,7 @@ void BossGoma_Encounter(BossGoma* this, PlayState* play) { 0xA0, 0xB4, 0x80, 0x28); } - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS); SET_EVENTCHKINF(EVENTCHKINF_70); } @@ -1108,7 +1108,7 @@ void BossGoma_Defeated(BossGoma* this, PlayState* play) { Math_SmoothStepToF(&this->subCamAt.z, this->firstTailLimbWorldPos.z, 0.2f, 50.0f, 0.1f); if (this->timer == 80) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS_CLEAR); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS_CLEAR); } if (this->timer == 0) { diff --git a/src/overlays/actors/ovl_Boss_Mo/z_boss_mo.c b/src/overlays/actors/ovl_Boss_Mo/z_boss_mo.c index 09e7e8ca1b..4531854e27 100644 --- a/src/overlays/actors/ovl_Boss_Mo/z_boss_mo.c +++ b/src/overlays/actors/ovl_Boss_Mo/z_boss_mo.c @@ -360,7 +360,7 @@ void BossMo_Init(Actor* thisx, PlayState* play2) { return; } if (GET_EVENTCHKINF(EVENTCHKINF_74)) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS); this->tentMaxAngle = 5.0f; this->timers[0] = 50; } else { @@ -1101,7 +1101,7 @@ void BossMo_Tentacle(BossMo* this, PlayState* play) { -280.0f, this->actor.world.pos.z, 0, 0, 0, WARP_DUNGEON_ADULT); Actor_Spawn(&play->actorCtx, play, ACTOR_ITEM_B_HEART, this->actor.world.pos.x + 200.0f, -280.0f, this->actor.world.pos.z, 0, 0, 0, 0); - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS_CLEAR); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS_CLEAR); Flags_SetClear(play, play->roomCtx.curRoom.num); } } @@ -1236,7 +1236,7 @@ void BossMo_IntroCs(BossMo* this, PlayState* play) { this->actor.world.rot.y = 0x721A; sMorphaTent1->work[MO_TENT_ACTION_STATE] = MO_TENT_READY; sMorphaTent1->timers[0] = 30000; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x3200FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 50); Message_CloseTextbox(play); } else { break; @@ -1417,7 +1417,7 @@ void BossMo_IntroCs(BossMo* this, PlayState* play) { this->subCamAccel = 0.01f; } if (this->timers[2] == 150) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS); } if (this->timers[2] == 130) { TitleCard_InitBossName(play, &play->actorCtx.titleCtx, SEGMENTED_TO_VIRTUAL(gMorphaTitleCardTex), 0xA0, @@ -1775,7 +1775,7 @@ void BossMo_CoreCollisionCheck(BossMo* this, PlayState* play) { ((sMorphaTent1->subCamId == SUB_CAM_ID_DONE) && (sMorphaTent2 != NULL) && (sMorphaTent2->subCamId == SUB_CAM_ID_DONE))) { Enemy_StartFinishingBlow(play, &this->actor); - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); this->csState = MO_DEATH_START; sMorphaTent1->drawActor = false; sMorphaTent1->work[MO_TENT_ACTION_STATE] = MO_TENT_DEATH_START; @@ -3576,11 +3576,11 @@ void BossMo_Unknown(void) { if (BREG(32) != 0) { BREG(32)--; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); func_80078914(&zeroVec, unkSfx[BREG(33)]); } if (BREG(34) != 0) { BREG(34) = 0; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | (u16)BREG(35)); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, BREG(35)); } } diff --git a/src/overlays/actors/ovl_Boss_Sst/z_boss_sst.c b/src/overlays/actors/ovl_Boss_Sst/z_boss_sst.c index 80ca1c97ed..76b7e5454c 100644 --- a/src/overlays/actors/ovl_Boss_Sst/z_boss_sst.c +++ b/src/overlays/actors/ovl_Boss_Sst/z_boss_sst.c @@ -381,7 +381,7 @@ void BossSst_HeadSetupIntro(BossSst* this, PlayState* play) { } Play_CameraSetAtEye(play, sSubCamId, &sSubCamAt, &sSubCamEye); - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); this->actionFunc = BossSst_HeadIntro; } @@ -601,7 +601,7 @@ void BossSst_HeadIntro(BossSst* this, PlayState* play) { TitleCard_InitBossName(play, &play->actorCtx.titleCtx, SEGMENTED_TO_VIRTUAL(gBongoTitleCardTex), 160, 180, 128, 40); } - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS); Animation_MorphToPlayOnce(&this->skelAnime, &gBongoHeadEyeCloseAnim, -5.0f); BossSst_HeadSfx(this, NA_SE_EN_SHADEST_DISAPPEAR); } @@ -1015,7 +1015,7 @@ void BossSst_HeadSetupDeath(BossSst* this, PlayState* play) { this->colliderJntSph.base.ocFlags1 &= ~OC1_ON; sHands[LEFT]->colliderJntSph.base.ocFlags1 &= ~OC1_ON; sHands[RIGHT]->colliderJntSph.base.ocFlags1 &= ~OC1_ON; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); sSubCamId = Play_CreateSubCamera(play); Play_ChangeCameraStatus(play, CAM_ID_MAIN, CAM_STAT_WAIT); Play_ChangeCameraStatus(play, sSubCamId, CAM_STAT_ACTIVE); @@ -1160,7 +1160,7 @@ void BossSst_HeadMelt(BossSst* this, PlayState* play) { void BossSst_HeadSetupFinish(BossSst* this) { this->actor.draw = BossSst_DrawEffects; this->timer = 40; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS_CLEAR); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS_CLEAR); BossSst_SetCameraTargets(1.0 / 40, 6); this->actionFunc = BossSst_HeadFinish; } diff --git a/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c b/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c index b21d10703c..d1085f3a18 100644 --- a/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c +++ b/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c @@ -519,7 +519,7 @@ void BossTw_Init(Actor* thisx, PlayState* play2) { this->actor.world.pos.x = -600.0f; this->actor.world.pos.y = 400.0f; this->actor.world.pos.z = 0.0f; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS); } else { BossTw_SetupCSWait(this, play); } @@ -1512,7 +1512,7 @@ void BossTw_TwinrovaMergeCS(BossTw* this, PlayState* play) { this->workf[UNK_F9] = 0.0f; this->workf[UNK_F10] = 0.0f; this->workf[UNK_F11] = 600.0f; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0xC800FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 200); this->work[CS_TIMER_2] = 0; FALLTHROUGH; case 1: @@ -1641,7 +1641,7 @@ void BossTw_TwinrovaMergeCS(BossTw* this, PlayState* play) { this->timers[0] = 50; func_8002DF54(play, &this->actor, 2); Audio_PlayActorSfx2(&this->actor, NA_SE_EN_TWINROBA_TRANSFORM); - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS); } } @@ -1782,7 +1782,7 @@ void BossTw_TwinrovaIntroCS(BossTw* this, PlayState* play) { if (this->csSfxTimer == 180) { func_80078914(&D_8094A7D0, NA_SE_EN_TWINROBA_LAUGH); func_80078914(&D_8094A7D0, NA_SE_EN_TWINROBA_LAUGH2); - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_KOTAKE_KOUME); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_KOTAKE_KOUME); } this->csSfxTimer++; @@ -2206,7 +2206,7 @@ void BossTw_TwinrovaIntroCS(BossTw* this, PlayState* play) { } if (this->work[CS_TIMER_1] == 90) { - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x5A00FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 90); } if (this->work[CS_TIMER_1] == 120) { @@ -2217,7 +2217,7 @@ void BossTw_TwinrovaIntroCS(BossTw* this, PlayState* play) { TitleCard_InitBossName(play, &play->actorCtx.titleCtx, SEGMENTED_TO_VIRTUAL(object_tw_Blob_02E170), 0xA0, 0xB4, 0x80, 0x28); SET_EVENTCHKINF(EVENTCHKINF_75); - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS); } if (this->work[CS_TIMER_1] >= 160) { @@ -2512,7 +2512,7 @@ void BossTw_DeathCSMsgSfx(BossTw* this, PlayState* play) { if (this->work[CS_TIMER_2] == 820) { msgId1 = 0x6057; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x5000FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 80); } if (this->work[CS_TIMER_2] == 860) { @@ -2688,7 +2688,7 @@ void BossTw_TwinrovaDeathCS(BossTw* this, PlayState* play) { Play_ChangeCameraStatus(play, this->subCamId, CAM_STAT_ACTIVE); this->subCamEye = mainCam->eye; this->subCamAt = mainCam->at; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); break; case 1: spD0.x = Math_SinS(this->actor.world.rot.y) * 200.0f; @@ -2763,7 +2763,7 @@ void BossTw_TwinrovaDeathCS(BossTw* this, PlayState* play) { sKoumePtr->visible = 1; sKotakePtr->visible = 1; func_80078884(NA_SE_EN_TWINROBA_TRANSFORM); - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_KOTAKE_KOUME); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_KOTAKE_KOUME); this->csState2 = 3; this->work[CS_TIMER_2] = 0; this->subCamYaw = this->subCamYawStep = this->actor.speedXZ = this->subCamDistStep = 0.0f; @@ -2811,7 +2811,7 @@ void BossTw_TwinrovaDeathCS(BossTw* this, PlayState* play) { this->subCamId = SUB_CAM_ID_DONE; func_80064534(play, &play->csCtx); func_8002DF54(play, &this->actor, 7); - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS_CLEAR); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS_CLEAR); Actor_SpawnAsChild(&play->actorCtx, &this->actor, play, ACTOR_DOOR_WARP1, 600.0f, 230.0f, 0.0f, 0, 0, 0, WARP_DUNGEON_ADULT); Actor_Spawn(&play->actorCtx, play, ACTOR_ITEM_B_HEART, -600.0f, 230.f, 0.0f, 0, 0, 0, 0); diff --git a/src/overlays/actors/ovl_Boss_Va/z_boss_va.c b/src/overlays/actors/ovl_Boss_Va/z_boss_va.c index c0c4a78cbb..5426855675 100644 --- a/src/overlays/actors/ovl_Boss_Va/z_boss_va.c +++ b/src/overlays/actors/ovl_Boss_Va/z_boss_va.c @@ -957,7 +957,7 @@ void BossVa_BodyIntro(BossVa* this, PlayState* play) { play->envCtx.lightSettingOverride = 1; func_8002DF54(play, &this->actor, 8); } else if (this->timer >= 35000) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS); } this->timer += this->unk_1F2; @@ -1512,7 +1512,7 @@ void BossVa_BodyPhase4(BossVa* this, PlayState* play) { void BossVa_SetupBodyDeath(BossVa* this, PlayState* play) { func_800F436C(&this->actor.projectedPos, NA_SE_EN_BALINADE_LEVEL - SFX_FLAG, 1.0f); this->actor.flags &= ~(ACTOR_FLAG_0 | ACTOR_FLAG_2); - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); this->vaCamRotMod = 0xC31; sCsState = DEATH_START; this->actor.speedXZ = 0.0f; @@ -1597,7 +1597,7 @@ void BossVa_BodyDeath(BossVa* this, PlayState* play) { break; case DEATH_CORE_BURST: if (this->timer == 13) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS_CLEAR); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS_CLEAR); } this->timer--; diff --git a/src/overlays/actors/ovl_Door_Warp1/z_door_warp1.c b/src/overlays/actors/ovl_Door_Warp1/z_door_warp1.c index 6f4e3a6ded..a86d617068 100644 --- a/src/overlays/actors/ovl_Door_Warp1/z_door_warp1.c +++ b/src/overlays/actors/ovl_Door_Warp1/z_door_warp1.c @@ -376,7 +376,7 @@ void DoorWarp1_ChooseInitialAction(DoorWarp1* this, PlayState* play) { void DoorWarp1_AwaitClearFlag(DoorWarp1* this, PlayState* play) { if (Flags_GetTempClear(play, this->actor.room)) { this->warpTimer = 200; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS_CLEAR); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS_CLEAR); DoorWarp1_SetupAction(this, func_809995D4); } } diff --git a/src/overlays/actors/ovl_En_Butte/z_en_butte.c b/src/overlays/actors/ovl_En_Butte/z_en_butte.c index 3631d18268..9068a5483d 100644 --- a/src/overlays/actors/ovl_En_Butte/z_en_butte.c +++ b/src/overlays/actors/ovl_En_Butte/z_en_butte.c @@ -268,8 +268,7 @@ void EnButte_FlyAround(EnButte* this, PlayState* play) { EnButte_SelectFlightParams(this, &sFlyAroundParams[this->flightParamsIdx]); } - if (((this->actor.params & 1) == 1) && (player->heldItemActionParam == PLAYER_AP_STICK) && - (this->swordDownTimer <= 0) && + if (((this->actor.params & 1) == 1) && (player->heldItemAction == PLAYER_IA_STICK) && (this->swordDownTimer <= 0) && ((Math3D_Dist2DSq(player->actor.world.pos.x, player->actor.world.pos.z, this->actor.home.pos.x, this->actor.home.pos.z) < SQ(120.0f)) || (this->actor.xzDistToPlayer < 60.0f))) { @@ -334,7 +333,7 @@ void EnButte_FollowLink(EnButte* this, PlayState* play) { distSqFromHome = Math3D_Dist2DSq(this->actor.world.pos.x, this->actor.world.pos.z, this->actor.home.pos.x, this->actor.home.pos.z); - if (!((player->heldItemActionParam == PLAYER_AP_STICK) && (fabsf(player->actor.speedXZ) < 1.8f) && + if (!((player->heldItemAction == PLAYER_IA_STICK) && (fabsf(player->actor.speedXZ) < 1.8f) && (this->swordDownTimer <= 0) && (distSqFromHome < SQ(320.0f)))) { EnButte_SetupFlyAround(this); } else if (distSqFromHome > SQ(240.0f)) { diff --git a/src/overlays/actors/ovl_En_Bw/z_en_bw.c b/src/overlays/actors/ovl_En_Bw/z_en_bw.c index dd40911c48..7ecebbc52e 100644 --- a/src/overlays/actors/ovl_En_Bw/z_en_bw.c +++ b/src/overlays/actors/ovl_En_Bw/z_en_bw.c @@ -132,8 +132,8 @@ void EnBw_Init(Actor* thisx, PlayState* play) { Actor_SetScale(&this->actor, 0.012999999f); this->actor.naviEnemyId = NAVI_ENEMY_TORCH_SLUG; this->actor.gravity = -2.0f; - SkelAnime_Init(play, &this->skelAnime, &object_bw_Skel_0020F0, &object_bw_Anim_000228, this->jointTable, - this->morphTable, 12); + SkelAnime_Init(play, &this->skelAnime, &gTorchSlugSkel, &gTorchSlugEyestalkWaveAnim, this->jointTable, + this->morphTable, TORCH_SLUG_LIMB_MAX); ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 40.0f); this->actor.colChkInfo.damageTable = &sDamageTable; this->actor.colChkInfo.health = 6; @@ -174,7 +174,7 @@ void func_809CE884(EnBw* this, PlayState* play) { } void func_809CE9A8(EnBw* this) { - Animation_MorphToLoop(&this->skelAnime, &object_bw_Anim_000228, -2.0f); + Animation_MorphToLoop(&this->skelAnime, &gTorchSlugEyestalkWaveAnim, -2.0f); this->unk_220 = 2; this->unk_222 = Rand_ZeroOne() * 200.0f + 200.0f; this->unk_232 = 0; @@ -393,7 +393,7 @@ void func_809CEA24(EnBw* this, PlayState* play) { } void func_809CF72C(EnBw* this) { - Animation_MorphToPlayOnce(&this->skelAnime, &object_bw_Anim_0021A0, -2.0f); + Animation_MorphToPlayOnce(&this->skelAnime, &gTorchSlugEyestalkRaiseAnim, -2.0f); this->unk_220 = 3; this->unk_221 = 0; this->unk_250 = 0.6f; @@ -425,7 +425,7 @@ void func_809CF7AC(EnBw* this, PlayState* play) { } void func_809CF8F0(EnBw* this) { - Animation_MorphToPlayOnce(&this->skelAnime, &object_bw_Anim_002250, -1.0f); + Animation_MorphToPlayOnce(&this->skelAnime, &gTorchSlugEyestalkFlailAnim, -1.0f); this->actor.speedXZ = 7.0f; this->actor.world.rot.y = this->actor.shape.rot.y = this->actor.yawTowardsPlayer; this->unk_220 = 4; @@ -470,7 +470,7 @@ void func_809CF984(EnBw* this, PlayState* play) { } void func_809CFBA8(EnBw* this) { - Animation_MorphToLoop(&this->skelAnime, &object_bw_Anim_002250, -1.0f); + Animation_MorphToLoop(&this->skelAnime, &gTorchSlugEyestalkFlailAnim, -1.0f); this->unk_220 = 5; this->unk_222 = 1000; this->unk_260 = 0.0f; @@ -528,7 +528,7 @@ void func_809CFC4C(EnBw* this, PlayState* play) { } void func_809CFF10(EnBw* this) { - Animation_MorphToLoop(&this->skelAnime, &object_bw_Anim_002250, -1.0f); + Animation_MorphToLoop(&this->skelAnime, &gTorchSlugEyestalkFlailAnim, -1.0f); this->unk_220 = 6; this->unk_222 = 1000; this->unk_221 = 3; @@ -814,7 +814,7 @@ void EnBw_Update(Actor* thisx, PlayState* play2) { s32 EnBw_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* thisx, Gfx** gfx) { EnBw* this = (EnBw*)thisx; - if (limbIndex == 1) { + if (limbIndex == TORCH_SLUG_LIMB_BODY) { gSPSegment( (*gfx)++, 0x09, Gfx_TwoTexScroll(play->state.gfxCtx, G_TX_RENDERTILE, 0, 0, 0x20, 0x20, 1, 0, this->unk_23A, 0x20, 0x20)); diff --git a/src/overlays/actors/ovl_En_Bw/z_en_bw.h b/src/overlays/actors/ovl_En_Bw/z_en_bw.h index ffdc3bba4e..dfd70e440a 100644 --- a/src/overlays/actors/ovl_En_Bw/z_en_bw.h +++ b/src/overlays/actors/ovl_En_Bw/z_en_bw.h @@ -7,11 +7,27 @@ struct EnBw; typedef void (*EnBwActionFunc)(struct EnBw*, PlayState*); +typedef enum { + /* 0 */ TORCH_SLUG_LIMB_NONE, + /* 1 */ TORCH_SLUG_LIMB_BODY, + /* 2 */ TORCH_SLUG_LIMB_LEFT_EYESTALK_ROOT_ROOT, + /* 3 */ TORCH_SLUG_LIMB_LEFT_EYESTALK_ROOT, + /* 4 */ TORCH_SLUG_LIMB_LEFT_UPPER_EYESTALK_ROOT, + /* 5 */ TORCH_SLUG_LIMB_LEFT_UPPER_EYESTALK, + /* 6 */ TORCH_SLUG_LIMB_LEFT_LOWER_EYESTALK, + /* 7 */ TORCH_SLUG_LIMB_RIGHT_EYESTALK_ROOT_ROOT, + /* 8 */ TORCH_SLUG_LIMB_RIGHT_EYESTALK_ROOT, + /* 9 */ TORCH_SLUG_LIMB_RIGHT_UPPER_EYESTALK_ROOT, + /* 10 */ TORCH_SLUG_LIMB_RIGHT_UPPER_EYESTALK, + /* 11 */ TORCH_SLUG_LIMB_RIGHT_LOWER_EYESTALK, + /* 12 */ TORCH_SLUG_LIMB_MAX +} TorchSlugLimb; + typedef struct EnBw { /* 0x0000 */ Actor actor; /* 0x014C */ SkelAnime skelAnime; - /* 0x0190 */ Vec3s jointTable[12]; - /* 0x01D8 */ Vec3s morphTable[12]; + /* 0x0190 */ Vec3s jointTable[TORCH_SLUG_LIMB_MAX]; + /* 0x01D8 */ Vec3s morphTable[TORCH_SLUG_LIMB_MAX]; /* 0x0220 */ u8 unk_220; /* 0x0221 */ u8 unk_221; /* 0x0222 */ s16 unk_222; diff --git a/src/overlays/actors/ovl_En_Dnt_Demo/z_en_dnt_demo.c b/src/overlays/actors/ovl_En_Dnt_Demo/z_en_dnt_demo.c index e5b6539ff2..bd8ad7a782 100644 --- a/src/overlays/actors/ovl_En_Dnt_Demo/z_en_dnt_demo.c +++ b/src/overlays/actors/ovl_En_Dnt_Demo/z_en_dnt_demo.c @@ -159,7 +159,7 @@ void EnDntDemo_Judge(EnDntDemo* this, PlayState* play) { if (!GET_ITEMGETINF(ITEMGETINF_1E)) { reaction = DNT_SIGNAL_CELEBRATE; this->prize = DNT_PRIZE_STICK; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_SARIA_THEME); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_SARIA_THEME); break; } FALLTHROUGH; @@ -208,17 +208,17 @@ void EnDntDemo_Judge(EnDntDemo* this, PlayState* play) { this->action = sResultValues[resultIdx][1]; switch (this->action) { case DNT_ACTION_LOW_RUPEES: - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_COURTYARD); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_COURTYARD); break; case DNT_ACTION_ATTACK: if (this->subCamId != SUB_CAM_ID_DONE) { this->subCamId = SUB_CAM_ID_DONE; OnePointCutscene_Init(play, 2350, -99, &this->scrubs[3]->actor, CAM_ID_MAIN); } - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_ENEMY | 0x800); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 8, NA_BGM_ENEMY); break; case DNT_ACTION_DANCE: - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_SHOP); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_SHOP); break; } osSyncPrintf("\n\n"); diff --git a/src/overlays/actors/ovl_En_Dnt_Jiji/z_en_dnt_jiji.c b/src/overlays/actors/ovl_En_Dnt_Jiji/z_en_dnt_jiji.c index 9e97ea5a8c..0ef7cb61a8 100644 --- a/src/overlays/actors/ovl_En_Dnt_Jiji/z_en_dnt_jiji.c +++ b/src/overlays/actors/ovl_En_Dnt_Jiji/z_en_dnt_jiji.c @@ -358,7 +358,7 @@ void EnDntJiji_Return(EnDntJiji* this, PlayState* play) { if ((this->stage->actor.update != NULL) && (this->stage->leaderSignal == DNT_SIGNAL_NONE)) { this->stage->leaderSignal = DNT_SIGNAL_HIDE; this->stage->action = DNT_ACTION_ATTACK; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_ENEMY | 0x800); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 8, NA_BGM_ENEMY); } } this->actor.speedXZ = 0.0f; diff --git a/src/overlays/actors/ovl_En_Eg/z_en_eg.c b/src/overlays/actors/ovl_En_Eg/z_en_eg.c index 0f20f07565..8e007d9e71 100644 --- a/src/overlays/actors/ovl_En_Eg/z_en_eg.c +++ b/src/overlays/actors/ovl_En_Eg/z_en_eg.c @@ -52,7 +52,7 @@ void func_809FFDC8(EnEg* this, PlayState* play) { // Void the player out Play_TriggerRespawn(play); gSaveContext.respawnFlag = -2; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_STOP); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0); play->transitionType = TRANS_TYPE_FADE_BLACK; EnEg_PlayVoidOutSFX(); voided = true; diff --git a/src/overlays/actors/ovl_En_Gb/z_en_gb.c b/src/overlays/actors/ovl_En_Gb/z_en_gb.c index f91d4da7be..0518d4875a 100644 --- a/src/overlays/actors/ovl_En_Gb/z_en_gb.c +++ b/src/overlays/actors/ovl_En_Gb/z_en_gb.c @@ -317,7 +317,7 @@ void func_80A2F9C0(EnGb* this, PlayState* play) { SET_INFTABLE(INFTABLE_B6); } func_80A2F180(this); - Player_UpdateBottleHeld(play, GET_PLAYER(play), ITEM_BOTTLE, PLAYER_AP_BOTTLE); + Player_UpdateBottleHeld(play, GET_PLAYER(play), ITEM_BOTTLE, PLAYER_IA_BOTTLE); Rupees_ChangeBy(10); this->actionFunc = func_80A2F83C; } @@ -329,7 +329,7 @@ void func_80A2FA50(EnGb* this, PlayState* play) { SET_INFTABLE(INFTABLE_B6); } func_80A2F180(this); - Player_UpdateBottleHeld(play, GET_PLAYER(play), ITEM_BOTTLE, PLAYER_AP_BOTTLE); + Player_UpdateBottleHeld(play, GET_PLAYER(play), ITEM_BOTTLE, PLAYER_IA_BOTTLE); Rupees_ChangeBy(50); HIGH_SCORE(HS_POE_POINTS) += 100; if (HIGH_SCORE(HS_POE_POINTS) != 1000) { diff --git a/src/overlays/actors/ovl_En_Horse/z_en_horse.c b/src/overlays/actors/ovl_En_Horse/z_en_horse.c index 74581e7ddf..69149c8e7e 100644 --- a/src/overlays/actors/ovl_En_Horse/z_en_horse.c +++ b/src/overlays/actors/ovl_En_Horse/z_en_horse.c @@ -2548,7 +2548,7 @@ void EnHorse_UpdateHorsebackArchery(EnHorse* this, PlayState* play) { if ((play->interfaceCtx.hbaAmmo == 0) || (this->hbaFlags & 2)) { if (this->hbaFlags & 4) { this->hbaFlags &= ~4; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_HORSE_GOAL); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_HORSE_GOAL); } } diff --git a/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c b/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c index ba0b382f40..933c71617e 100644 --- a/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c +++ b/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c @@ -182,7 +182,7 @@ s32 EnHorseGameCheck_UpdateIngoRace(EnHorseGameCheckBase* base, PlayState* play) if (this->playerFinish > 0) { this->result = INGORACE_PLAYER_WIN; this->finishTimer = 55; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_HORSE_GOAL); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_HORSE_GOAL); Audio_PlaySfxGeneral(NA_SE_SY_START_SHOT, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); } @@ -198,7 +198,7 @@ s32 EnHorseGameCheck_UpdateIngoRace(EnHorseGameCheckBase* base, PlayState* play) this->result = INGORACE_INGO_WIN; this->finishTimer = 70; ingoHorse->stateFlags |= ENHORSE_INGO_WON; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_HORSE_GOAL); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_HORSE_GOAL); Audio_PlaySfxGeneral(NA_SE_SY_START_SHOT, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); } @@ -207,12 +207,12 @@ s32 EnHorseGameCheck_UpdateIngoRace(EnHorseGameCheckBase* base, PlayState* play) } } if (((player2->rideActor != NULL) && AT_RANCH_EXIT(player2->rideActor)) || AT_RANCH_EXIT(&player2->actor)) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_HORSE_GOAL); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_HORSE_GOAL); this->result = INGORACE_INGO_WIN; this->finishTimer = 20; } if ((gSaveContext.timer1Value >= 180) && (this->startFlags & 2)) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_HORSE_GOAL); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_HORSE_GOAL); this->result = INGORACE_TIME_UP; this->finishTimer = 20; } @@ -378,7 +378,7 @@ s32 EnHorseGameCheck_UpdateMalonRace(EnHorseGameCheckBase* base, PlayState* play this->finishTimer = 30; } else if (this->fenceCheck[15] == 1) { this->lapCount = 2; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_HORSE_GOAL); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_HORSE_GOAL); Audio_PlaySfxGeneral(NA_SE_SY_START_SHOT, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); this->result = MALONRACE_SUCCESS; diff --git a/src/overlays/actors/ovl_En_Hy/z_en_hy.c b/src/overlays/actors/ovl_En_Hy/z_en_hy.c index 1d2191f3d9..c8161c3a9e 100644 --- a/src/overlays/actors/ovl_En_Hy/z_en_hy.c +++ b/src/overlays/actors/ovl_En_Hy/z_en_hy.c @@ -592,7 +592,7 @@ s16 func_80A70058(PlayState* play, Actor* thisx) { case 0x70F3: Rupees_ChangeBy(beggarRewards[this->actor.textId - 0x70F0]); Animation_ChangeByInfo(&this->skelAnime, sAnimationInfo, ENHY_ANIM_17); - Player_UpdateBottleHeld(play, GET_PLAYER(play), ITEM_BOTTLE, PLAYER_AP_BOTTLE); + Player_UpdateBottleHeld(play, GET_PLAYER(play), ITEM_BOTTLE, PLAYER_IA_BOTTLE); break; case 0x7016: SET_INFTABLE(INFTABLE_C0); diff --git a/src/overlays/actors/ovl_En_Ma1/z_en_ma1.c b/src/overlays/actors/ovl_En_Ma1/z_en_ma1.c index 039969f0e6..6248a77dde 100644 --- a/src/overlays/actors/ovl_En_Ma1/z_en_ma1.c +++ b/src/overlays/actors/ovl_En_Ma1/z_en_ma1.c @@ -247,14 +247,16 @@ void func_80AA0AF4(EnMa1* this, PlayState* play) { void func_80AA0B74(EnMa1* this) { if (this->skelAnime.animation == &gMalonChildSingAnim) { if (this->unk_1E8.unk_00 == 0) { - if (this->unk_1E0 != 0) { - this->unk_1E0 = 0; - func_800F6584(0); + if (this->isNotSinging) { + // Turn on singing + this->isNotSinging = false; + Audio_ToggleMalonSinging(false); } } else { - if (this->unk_1E0 == 0) { - this->unk_1E0 = 1; - func_800F6584(1); + if (!this->isNotSinging) { + // Turn off singing + this->isNotSinging = true; + Audio_ToggleMalonSinging(true); } } } @@ -447,14 +449,14 @@ void EnMa1_PostLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot, void EnMa1_Draw(Actor* thisx, PlayState* play) { EnMa1* this = (EnMa1*)thisx; Camera* activeCam; - f32 distFromCamera; + f32 distFromCamEye; s32 pad; OPEN_DISPS(play->state.gfxCtx, "../z_en_ma1.c", 1226); activeCam = GET_ACTIVE_CAM(play); - distFromCamera = Math_Vec3f_DistXZ(&this->actor.world.pos, &activeCam->eye); - func_800F6268(distFromCamera, NA_BGM_LONLON); + distFromCamEye = Math_Vec3f_DistXZ(&this->actor.world.pos, &activeCam->eye); + Audio_UpdateMalonSinging(distFromCamEye, NA_BGM_LONLON); Gfx_SetupDL_25Opa(play->state.gfxCtx); gSPSegment(POLY_OPA_DISP++, 0x09, SEGMENTED_TO_VIRTUAL(sMouthTextures[this->mouthIndex])); diff --git a/src/overlays/actors/ovl_En_Ma1/z_en_ma1.h b/src/overlays/actors/ovl_En_Ma1/z_en_ma1.h index 078a0ed117..ec3593f83f 100644 --- a/src/overlays/actors/ovl_En_Ma1/z_en_ma1.h +++ b/src/overlays/actors/ovl_En_Ma1/z_en_ma1.h @@ -13,7 +13,7 @@ typedef struct EnMa1 { /* 0x014C */ SkelAnime skelAnime; /* 0x0190 */ EnMa1ActionFunc actionFunc; /* 0x0194 */ ColliderCylinder collider; - /* 0x01E0 */ s16 unk_1E0; + /* 0x01E0 */ s16 isNotSinging; /* 0x01E2 */ s16 blinkTimer; /* 0x01E4 */ s16 eyeIndex; /* 0x01E6 */ s16 mouthIndex; diff --git a/src/overlays/actors/ovl_En_Ma2/z_en_ma2.c b/src/overlays/actors/ovl_En_Ma2/z_en_ma2.c index 417c45e4aa..8c34610a44 100644 --- a/src/overlays/actors/ovl_En_Ma2/z_en_ma2.c +++ b/src/overlays/actors/ovl_En_Ma2/z_en_ma2.c @@ -196,14 +196,16 @@ void EnMa2_ChangeAnim(EnMa2* this, s32 index) { void func_80AA1DB4(EnMa2* this, PlayState* play) { if (this->skelAnime.animation == &gMalonAdultSingAnim) { if (this->unk_1E0.unk_00 == 0) { - if (this->unk_20A != 0) { - func_800F6584(0); - this->unk_20A = 0; + if (this->isNotSinging) { + // Turn on singing + Audio_ToggleMalonSinging(false); + this->isNotSinging = false; } } else { - if (this->unk_20A == 0) { - func_800F6584(1); - this->unk_20A = 1; + if (!this->isNotSinging) { + // Turn off singing + Audio_ToggleMalonSinging(true); + this->isNotSinging = true; } } } @@ -374,14 +376,14 @@ void EnMa2_Draw(Actor* thisx, PlayState* play) { EnMa2* this = (EnMa2*)thisx; Camera* activeCam; - f32 someFloat; + f32 distFromCamEye; s32 pad; OPEN_DISPS(play->state.gfxCtx, "../z_en_ma2.c", 955); activeCam = GET_ACTIVE_CAM(play); - someFloat = Math_Vec3f_DistXZ(&this->actor.world.pos, &activeCam->eye); - func_800F6268(someFloat, NA_BGM_LONLON); + distFromCamEye = Math_Vec3f_DistXZ(&this->actor.world.pos, &activeCam->eye); + Audio_UpdateMalonSinging(distFromCamEye, NA_BGM_LONLON); Gfx_SetupDL_25Opa(play->state.gfxCtx); gSPSegment(POLY_OPA_DISP++, 0x09, SEGMENTED_TO_VIRTUAL(sMouthTextures[this->mouthIndex])); diff --git a/src/overlays/actors/ovl_En_Ma2/z_en_ma2.h b/src/overlays/actors/ovl_En_Ma2/z_en_ma2.h index 249bb55741..e6985e0547 100644 --- a/src/overlays/actors/ovl_En_Ma2/z_en_ma2.h +++ b/src/overlays/actors/ovl_En_Ma2/z_en_ma2.h @@ -38,7 +38,7 @@ typedef struct EnMa2 { /* 0x0194 */ ColliderCylinder collider; /* 0x01E0 */ struct_80034A14_arg1 unk_1E0; /* 0x0208 */ s16 unk_208; - /* 0x020A */ s16 unk_20A; + /* 0x020A */ s16 isNotSinging; /* 0x020C */ s16 blinkTimer; /* 0x020E */ s16 eyeIndex; /* 0x0210 */ s16 mouthIndex; diff --git a/src/overlays/actors/ovl_En_Ma3/z_en_ma3.c b/src/overlays/actors/ovl_En_Ma3/z_en_ma3.c index d23aeef5f5..bf3110892e 100644 --- a/src/overlays/actors/ovl_En_Ma3/z_en_ma3.c +++ b/src/overlays/actors/ovl_En_Ma3/z_en_ma3.c @@ -298,13 +298,15 @@ void EnMa3_Update(Actor* thisx, PlayState* play) { func_800343CC(play, &this->actor, &this->unk_1E0.unk_00, (f32)this->collider.dim.radius + 150.0f, func_80AA2AA0, func_80AA2BD4); if (this->unk_1E0.unk_00 == 0) { - if (this->unk_20A != 0) { - func_800F6584(0); - this->unk_20A = 0; + if (this->isNotSinging) { + // Turn on singing + Audio_ToggleMalonSinging(false); + this->isNotSinging = false; } - } else if (this->unk_20A == 0) { - func_800F6584(1); - this->unk_20A = 1; + } else if (!this->isNotSinging) { + // Turn off singing + Audio_ToggleMalonSinging(true); + this->isNotSinging = true; } } @@ -357,14 +359,14 @@ void EnMa3_Draw(Actor* thisx, PlayState* play) { static void* sEyeTextures[] = { gMalonAdultEyeOpenTex, gMalonAdultEyeHalfTex, gMalonAdultEyeClosedTex }; EnMa3* this = (EnMa3*)thisx; Camera* activeCam; - f32 someFloat; + f32 distFromCamEye; s32 pad; OPEN_DISPS(play->state.gfxCtx, "../z_en_ma3.c", 978); activeCam = GET_ACTIVE_CAM(play); - someFloat = Math_Vec3f_DistXZ(&this->actor.world.pos, &activeCam->eye); - func_800F6268(someFloat, NA_BGM_LONLON); + distFromCamEye = Math_Vec3f_DistXZ(&this->actor.world.pos, &activeCam->eye); + Audio_UpdateMalonSinging(distFromCamEye, NA_BGM_LONLON); Gfx_SetupDL_25Opa(play->state.gfxCtx); gSPSegment(POLY_OPA_DISP++, 0x09, SEGMENTED_TO_VIRTUAL(sMouthTextures[this->mouthIndex])); diff --git a/src/overlays/actors/ovl_En_Ma3/z_en_ma3.h b/src/overlays/actors/ovl_En_Ma3/z_en_ma3.h index 549d60c975..1debd32f54 100644 --- a/src/overlays/actors/ovl_En_Ma3/z_en_ma3.h +++ b/src/overlays/actors/ovl_En_Ma3/z_en_ma3.h @@ -38,7 +38,7 @@ typedef struct EnMa3 { /* 0x0194 */ ColliderCylinder collider; /* 0x01E0 */ struct_80034A14_arg1 unk_1E0; /* 0x0208 */ s16 unk_208; - /* 0x020A */ s16 unk_20A; + /* 0x020A */ s16 isNotSinging; /* 0x020C */ s16 blinkTimer; /* 0x020E */ s16 eyeIndex; /* 0x0210 */ s16 mouthIndex; diff --git a/src/overlays/actors/ovl_En_Okarina_Effect/z_en_okarina_effect.c b/src/overlays/actors/ovl_En_Okarina_Effect/z_en_okarina_effect.c index e1713e2763..b71f566213 100644 --- a/src/overlays/actors/ovl_En_Okarina_Effect/z_en_okarina_effect.c +++ b/src/overlays/actors/ovl_En_Okarina_Effect/z_en_okarina_effect.c @@ -93,7 +93,7 @@ void EnOkarinaEffect_ManageStorm(EnOkarinaEffect* this, PlayState* play) { play->envCtx.precipitation[PRECIP_SOS_MAX] = 0; if (play->csCtx.state == CS_STATE_IDLE) { Environment_StopStormNatureAmbience(play); - } else if (func_800FA0B4(SEQ_PLAYER_BGM_MAIN) == NA_BGM_NATURE_AMBIENCE) { + } else if (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) == NA_BGM_NATURE_AMBIENCE) { Audio_SetNatureAmbienceChannelIO(NATURE_CHANNEL_LIGHTNING, CHANNEL_IO_PORT_1, 0); Audio_SetNatureAmbienceChannelIO(NATURE_CHANNEL_RAIN, CHANNEL_IO_PORT_1, 0); } diff --git a/src/overlays/actors/ovl_En_Okarina_Tag/z_en_okarina_tag.c b/src/overlays/actors/ovl_En_Okarina_Tag/z_en_okarina_tag.c index 66b49d19f1..9bae7993a9 100644 --- a/src/overlays/actors/ovl_En_Okarina_Tag/z_en_okarina_tag.c +++ b/src/overlays/actors/ovl_En_Okarina_Tag/z_en_okarina_tag.c @@ -243,7 +243,7 @@ void func_80ABF4C8(EnOkarinaTag* this, PlayState* play) { case 2: play->csCtx.segment = D_80ABF9D0; gSaveContext.cutsceneTrigger = 1; - func_800F574C(1.18921f, 0x5A); + func_800F574C(1.18921f, 90); break; case 4: play->csCtx.segment = D_80ABFB40; diff --git a/src/overlays/actors/ovl_En_Owl/z_en_owl.c b/src/overlays/actors/ovl_En_Owl/z_en_owl.c index 42defa3100..49e8fe6059 100644 --- a/src/overlays/actors/ovl_En_Owl/z_en_owl.c +++ b/src/overlays/actors/ovl_En_Owl/z_en_owl.c @@ -340,7 +340,7 @@ void func_80ACA76C(EnOwl* this, PlayState* play) { func_8002DF54(play, &this->actor, 8); if (Actor_TextboxIsClosing(&this->actor, play)) { - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_FANFARE << 24 | 0xFF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 0); func_80ACA62C(this, play); this->actor.flags &= ~ACTOR_FLAG_16; } @@ -350,7 +350,7 @@ void func_80ACA7E0(EnOwl* this, PlayState* play) { func_8002DF54(play, &this->actor, 8); if (Actor_TextboxIsClosing(&this->actor, play)) { - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_FANFARE << 24 | 0xFF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 0); if ((this->unk_3EE & 0x3F) == 0) { func_80ACA62C(this, play); } else { @@ -550,7 +550,7 @@ void func_80ACB03C(EnOwl* this, PlayState* play) { func_8002DF54(play, &this->actor, 8); if (Actor_TextboxIsClosing(&this->actor, play)) { - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_FANFARE << 24 | 0xFF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 0); func_80ACA62C(this, play); this->actor.flags &= ~ACTOR_FLAG_16; } @@ -579,7 +579,7 @@ void EnOwl_WaitZoraRiver(EnOwl* this, PlayState* play) { void func_80ACB148(EnOwl* this, PlayState* play) { if (Actor_TextboxIsClosing(&this->actor, play)) { - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_FANFARE << 24 | 0xFF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 0); func_80ACA5C8(this); this->actionFunc = func_80ACC30C; Flags_SetSwitch(play, 0x23); @@ -600,7 +600,7 @@ void EnOwl_WaitHyliaShortcut(EnOwl* this, PlayState* play) { void func_80ACB22C(EnOwl* this, PlayState* play) { if (Actor_TextboxIsClosing(&this->actor, play)) { - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_FANFARE << 24 | 0xFF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 0); func_80ACA5C8(this); this->actionFunc = func_80ACC30C; } @@ -608,7 +608,7 @@ void func_80ACB22C(EnOwl* this, PlayState* play) { void func_80ACB274(EnOwl* this, PlayState* play) { if (Actor_TextboxIsClosing(&this->actor, play)) { - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_FANFARE << 24 | 0xFF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 0); this->actionFunc = EnOwl_WaitDeathMountainShortcut; } } diff --git a/src/overlays/actors/ovl_En_Syateki_Man/z_en_syateki_man.c b/src/overlays/actors/ovl_En_Syateki_Man/z_en_syateki_man.c index ccc3bc509e..bb1e656eb4 100644 --- a/src/overlays/actors/ovl_En_Syateki_Man/z_en_syateki_man.c +++ b/src/overlays/actors/ovl_En_Syateki_Man/z_en_syateki_man.c @@ -505,6 +505,6 @@ void EnSyatekiMan_Draw(Actor* thisx, PlayState* play) { void EnSyatekiMan_SetBgm(void) { if (BREG(80)) { BREG(80) = false; - Audio_QueueSeqCmd(sBgmList[BREG(81)]); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, sBgmList[BREG(81)]); } } diff --git a/src/overlays/actors/ovl_En_Ta/z_en_ta.c b/src/overlays/actors/ovl_En_Ta/z_en_ta.c index 1fc9cbb5ae..b6b9e2c054 100644 --- a/src/overlays/actors/ovl_En_Ta/z_en_ta.c +++ b/src/overlays/actors/ovl_En_Ta/z_en_ta.c @@ -708,7 +708,7 @@ void func_80B154FC(EnTa* this, PlayState* play) { this->unk_2E0 &= ~0x10; this->unk_2E0 &= ~0x100; SET_EVENTINF(EVENTINF_HORSES_08); - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_STOP); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0); this->unk_2E0 &= ~0x200; Audio_PlayFanfare(NA_BGM_SMALL_ITEM_GET); return; @@ -737,7 +737,7 @@ void func_80B154FC(EnTa* this, PlayState* play) { } if (gSaveContext.timer1Value == 0 && !Play_InCsMode(play)) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_STOP); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0); this->unk_2E0 &= ~0x200; func_80078884(NA_SE_SY_FOUND); gSaveContext.timer1State = 0; diff --git a/src/overlays/actors/ovl_En_Test/z_en_test.c b/src/overlays/actors/ovl_En_Test/z_en_test.c index e78a0cefee..f8f5ad91e6 100644 --- a/src/overlays/actors/ovl_En_Test/z_en_test.c +++ b/src/overlays/actors/ovl_En_Test/z_en_test.c @@ -663,7 +663,7 @@ void EnTest_WalkAndBlock(EnTest* this, PlayState* play) { EnTest_SetupJumpslash(this); return; } - } else if (player->heldItemActionParam != PLAYER_AP_NONE) { + } else if (player->heldItemAction != PLAYER_IA_NONE) { if (this->actor.isTargeted) { if ((play->gameplayFrames % 2) != 0) { func_808627C4(this, play); @@ -1462,7 +1462,7 @@ void func_808628C8(EnTest* this, PlayState* play) { if (!EnTest_ReactToProjectile(play, this)) { EnTest_ChooseAction(this, play); } - } else if (player->heldItemActionParam != PLAYER_AP_NONE) { + } else if (player->heldItemAction != PLAYER_IA_NONE) { if ((play->gameplayFrames % 2) != 0) { EnTest_SetupIdle(this); } else { diff --git a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c index 893af07c3c..1ee8bde7a7 100644 --- a/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c +++ b/src/overlays/actors/ovl_En_Torch2/z_en_torch2.c @@ -96,7 +96,7 @@ void EnTorch2_Init(Actor* thisx, PlayState* play2) { sInput.cur.button = sInput.press.button = sInput.rel.button = 0; sInput.cur.stick_x = sInput.cur.stick_y = 0; this->currentShield = PLAYER_SHIELD_HYLIAN; - this->heldItemActionParam = this->heldItemId = PLAYER_AP_SWORD_MASTER; + this->heldItemAction = this->heldItemId = PLAYER_IA_SWORD_MASTER; Player_SetModelGroup(this, PLAYER_MODELGROUP_SWORD); play->playerInit(this, play, &gDarkLinkSkel); this->actor.naviEnemyId = NAVI_ENEMY_DARK_LINK; diff --git a/src/overlays/actors/ovl_En_Viewer/z_en_viewer.c b/src/overlays/actors/ovl_En_Viewer/z_en_viewer.c index d88d7742ab..e704160da4 100644 --- a/src/overlays/actors/ovl_En_Viewer/z_en_viewer.c +++ b/src/overlays/actors/ovl_En_Viewer/z_en_viewer.c @@ -241,7 +241,7 @@ void EnViewer_UpdateImpl(EnViewer* this, PlayState* play) { } } if (play->csCtx.frames == 1020) { - Audio_QueueSeqCmd(SEQ_PLAYER_FANFARE << 24 | NA_BGM_OPENING_GANON); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_FANFARE, 0, 0, NA_BGM_OPENING_GANON); } if (play->csCtx.frames == 960) { Audio_PlaySfxGeneral(NA_SE_EV_HORSE_GROAN, &this->actor.projectedPos, 4, &gSfxDefaultFreqAndVolScale, diff --git a/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c b/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c index 0ca2474fc1..91c99fd4e5 100644 --- a/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c +++ b/src/overlays/actors/ovl_En_Zl3/z_en_zl3.c @@ -86,7 +86,7 @@ void EnZl3_Destroy(Actor* thisx, PlayState* play) { } void func_80B53468(void) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_ESCAPE); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_ESCAPE); } BossGanon2* func_80B53488(EnZl3* this, PlayState* play) { diff --git a/src/overlays/actors/ovl_En_fHG/z_en_fhg.c b/src/overlays/actors/ovl_En_fHG/z_en_fhg.c index 94f88ef272..c253f9906e 100644 --- a/src/overlays/actors/ovl_En_fHG/z_en_fhg.c +++ b/src/overlays/actors/ovl_En_fHG/z_en_fhg.c @@ -142,7 +142,7 @@ void EnfHG_Intro(EnfHG* this, PlayState* play) { } if (this->timers[0] == 51) { Audio_PlayActorSfx2(this->actor.child, NA_SE_EV_SPEAR_FENCE); - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS); } if (this->timers[0] == 0) { EnfHG_SetupApproach(this, play, Rand_ZeroOne() * 5.99f); @@ -158,7 +158,7 @@ void EnfHG_Intro(EnfHG* this, PlayState* play) { this->cutsceneState = INTRO_FENCE; this->timers[0] = 60; this->actor.world.pos.y = GND_BOSSROOM_CENTER_Y - 7.0f; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); SET_EVENTCHKINF(EVENTCHKINF_72); Flags_SetSwitch(play, 0x23); FALLTHROUGH; @@ -195,7 +195,7 @@ void EnfHG_Intro(EnfHG* this, PlayState* play) { func_8002DF54(play, &this->actor, 9); } if (this->timers[0] == 1) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_OPENING_GANON); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_OPENING_GANON); } Math_ApproachF(&this->subCamEye.x, GND_BOSSROOM_CENTER_X + 40.0f, 0.05f, this->subCamVelFactor * 20.0f); Math_ApproachF(&this->subCamEye.y, GND_BOSSROOM_CENTER_Y + 37.0f, 0.05f, this->subCamVelFactor * 20.0f); @@ -284,7 +284,7 @@ void EnfHG_Intro(EnfHG* this, PlayState* play) { this->bossGndSignal = FHG_RIDE; } if (this->timers[0] == 130) { - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x5000FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 80); } if (this->timers[0] == 30) { bossGnd->work[GND_EYE_STATE] = GND_EYESTATE_BRIGHTEN; @@ -297,7 +297,7 @@ void EnfHG_Intro(EnfHG* this, PlayState* play) { func_80078914(&audioVec, NA_SE_EN_FANTOM_ST_LAUGH); } if (this->timers[0] == 20) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_BOSS); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_BOSS); } if (this->timers[0] == 2) { this->subCamVelFactor = 0.0f; diff --git a/src/overlays/actors/ovl_Fishing/z_fishing.c b/src/overlays/actors/ovl_Fishing/z_fishing.c index ab0754b0a9..a90b22a57d 100644 --- a/src/overlays/actors/ovl_Fishing/z_fishing.c +++ b/src/overlays/actors/ovl_Fishing/z_fishing.c @@ -867,7 +867,7 @@ void Fishing_Init(Actor* thisx, PlayState* play2) { D_80B7E0AC = 0; D_80B7E0A6 = 10; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x0100FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1); if (sLinkAge == LINK_AGE_CHILD) { if ((HIGH_SCORE(HS_FISHING) & 0x7F) != 0) { @@ -3586,7 +3586,7 @@ void Fishing_UpdateFish(Actor* thisx, PlayState* play2) { this->unk_198 = 1.7f; this->unk_19C = 7000.0f; D_80B7E124 = 1; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_ENEMY | 0x800); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 8, NA_BGM_ENEMY); D_80B7E0A6 = 0; if (this->unk_150 == 1) { @@ -3791,7 +3791,7 @@ void Fishing_UpdateFish(Actor* thisx, PlayState* play2) { } else { D_80B7E086 = 0x4082; Rumble_Override(0.0f, 1, 3, 1); - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x0A00FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 10); } this->unk_158 = this->unk_15A = 0; @@ -3859,7 +3859,7 @@ void Fishing_UpdateFish(Actor* thisx, PlayState* play2) { } if (this->unk_17A[0] == 90) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_HEART_GET | 0x900); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 9, NA_BGM_HEART_GET); D_80B7A67C = 40; if (this->unk_150 == 0) { @@ -3974,7 +3974,7 @@ void Fishing_UpdateFish(Actor* thisx, PlayState* play2) { D_80B7E148 = 520.0f; D_80B7E144 = 195.0f; - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0xA00FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 10); D_80B7E0A6 = 20; D_80B7A6CC = 3; } @@ -5207,7 +5207,7 @@ void Fishing_UpdateOwner(Actor* thisx, PlayState* play2) { D_80B7A6CC = 20; Rumble_Override(0.0f, 150, 10, 10); func_80078884(NA_SE_SY_TRE_BOX_APPEAR); - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x1400FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 20); } if (KREG(0) != 0) { @@ -5216,7 +5216,7 @@ void Fishing_UpdateOwner(Actor* thisx, PlayState* play2) { D_80B7A6CC = 20; Rumble_Override(0.0f, 150, 10, 10); func_80078884(NA_SE_SY_TRE_BOX_APPEAR); - Audio_QueueSeqCmd(0x1 << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0x1400FF); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 20); } if (D_80B7A6D0 != 0) { @@ -5432,7 +5432,7 @@ void Fishing_UpdateOwner(Actor* thisx, PlayState* play2) { case 22: if (D_80B7A6D0 == 30) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_ITEM_GET | 0x900); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 9, NA_BGM_ITEM_GET); } D_80B7A6D4 = 1; @@ -5741,15 +5741,15 @@ void Fishing_DrawOwner(Actor* thisx, PlayState* play) { if (D_80B7E0A6 == 0) { if (sLinkAge != LINK_AGE_CHILD) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_KAKARIKO_ADULT); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_KAKARIKO_ADULT); } else { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_KAKARIKO_KID); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_KAKARIKO_KID); } if (sLinkAge != LINK_AGE_CHILD) { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_KAKARIKO_ADULT); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_KAKARIKO_ADULT); } else { - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_KAKARIKO_KID); + SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0, 0, NA_BGM_KAKARIKO_KID); } } } diff --git a/src/overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.c b/src/overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.c index b620726e36..e0b56f9e7d 100644 --- a/src/overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.c +++ b/src/overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.c @@ -175,7 +175,7 @@ void ObjSyokudai_Update(Actor* thisx, PlayState* play2) { if (dmgFlags & (DMG_FIRE | DMG_ARROW_NORMAL)) { interactionType = 1; } - } else if (player->heldItemActionParam == PLAYER_AP_STICK) { + } else if (player->heldItemAction == PLAYER_IA_STICK) { Math_Vec3f_Diff(&player->meleeWeaponInfo[0].tip, &this->actor.world.pos, &tipToFlame); tipToFlame.y -= 67.0f; if ((SQ(tipToFlame.x) + SQ(tipToFlame.y) + SQ(tipToFlame.z)) < SQ(20.0f)) { diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 6a0fab022d..5905d18a17 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -47,7 +47,7 @@ typedef struct { typedef struct { /* 0x00 */ s16 actorId; /* 0x02 */ u8 itemId; - /* 0x03 */ u8 actionParam; + /* 0x03 */ u8 itemAction; /* 0x04 */ u8 textId; } BottleCatchInfo; // size = 0x06 @@ -128,7 +128,7 @@ void func_8083377C(PlayState* play, Player* this); void func_808337D4(PlayState* play, Player* this); void func_80833910(PlayState* play, Player* this); void func_80833984(PlayState* play, Player* this); -void func_8083399C(PlayState* play, Player* this, s8 actionParam); +void func_8083399C(PlayState* play, Player* this, s8 itemAction); s32 func_8083485C(Player* this, PlayState* play); s32 func_808349DC(Player* this, PlayState* play); s32 func_80834A2C(Player* this, PlayState* play); @@ -1023,70 +1023,70 @@ static u8 D_80853E7C[] = { 0, 0, 1, 1, 2, 2, 2, 2, 10, 10, 10, 10, 10, 10, 3, 3, 4, 4, 8, 8, 5, 5, 6, 6, 7, 7, 9, 9, 0, }; -// Used to map item IDs to action params -static s8 sItemActionParams[] = { - PLAYER_AP_STICK, - PLAYER_AP_NUT, - PLAYER_AP_BOMB, - PLAYER_AP_BOW, - PLAYER_AP_BOW_FIRE, - PLAYER_AP_DINS_FIRE, - PLAYER_AP_SLINGSHOT, - PLAYER_AP_OCARINA_FAIRY, - PLAYER_AP_OCARINA_TIME, - PLAYER_AP_BOMBCHU, - PLAYER_AP_HOOKSHOT, - PLAYER_AP_LONGSHOT, - PLAYER_AP_BOW_ICE, - PLAYER_AP_FARORES_WIND, - PLAYER_AP_BOOMERANG, - PLAYER_AP_LENS, - PLAYER_AP_BEAN, - PLAYER_AP_HAMMER, - PLAYER_AP_BOW_LIGHT, - PLAYER_AP_NAYRUS_LOVE, - PLAYER_AP_BOTTLE, - PLAYER_AP_BOTTLE_POTION_RED, - PLAYER_AP_BOTTLE_POTION_GREEN, - PLAYER_AP_BOTTLE_POTION_BLUE, - PLAYER_AP_BOTTLE_FAIRY, - PLAYER_AP_BOTTLE_FISH, - PLAYER_AP_BOTTLE_MILK, - PLAYER_AP_BOTTLE_LETTER, - PLAYER_AP_BOTTLE_FIRE, - PLAYER_AP_BOTTLE_BUG, - PLAYER_AP_BOTTLE_BIG_POE, - PLAYER_AP_BOTTLE_MILK_HALF, - PLAYER_AP_BOTTLE_POE, - PLAYER_AP_WEIRD_EGG, - PLAYER_AP_CHICKEN, - PLAYER_AP_LETTER_ZELDA, - PLAYER_AP_MASK_KEATON, - PLAYER_AP_MASK_SKULL, - PLAYER_AP_MASK_SPOOKY, - PLAYER_AP_MASK_BUNNY, - PLAYER_AP_MASK_GORON, - PLAYER_AP_MASK_ZORA, - PLAYER_AP_MASK_GERUDO, - PLAYER_AP_MASK_TRUTH, - PLAYER_AP_SWORD_MASTER, - PLAYER_AP_POCKET_EGG, - PLAYER_AP_POCKET_CUCCO, - PLAYER_AP_COJIRO, - PLAYER_AP_ODD_MUSHROOM, - PLAYER_AP_ODD_POTION, - PLAYER_AP_SAW, - PLAYER_AP_SWORD_BROKEN, - PLAYER_AP_PRESCRIPTION, - PLAYER_AP_FROG, - PLAYER_AP_EYEDROPS, - PLAYER_AP_CLAIM_CHECK, - PLAYER_AP_BOW_FIRE, - PLAYER_AP_BOW_ICE, - PLAYER_AP_BOW_LIGHT, - PLAYER_AP_SWORD_KOKIRI, - PLAYER_AP_SWORD_MASTER, - PLAYER_AP_SWORD_BGS, +// Used to map item IDs to item actions +static s8 sItemActions[] = { + PLAYER_IA_STICK, + PLAYER_IA_NUT, + PLAYER_IA_BOMB, + PLAYER_IA_BOW, + PLAYER_IA_BOW_FIRE, + PLAYER_IA_DINS_FIRE, + PLAYER_IA_SLINGSHOT, + PLAYER_IA_OCARINA_FAIRY, + PLAYER_IA_OCARINA_TIME, + PLAYER_IA_BOMBCHU, + PLAYER_IA_HOOKSHOT, + PLAYER_IA_LONGSHOT, + PLAYER_IA_BOW_ICE, + PLAYER_IA_FARORES_WIND, + PLAYER_IA_BOOMERANG, + PLAYER_IA_LENS, + PLAYER_IA_BEAN, + PLAYER_IA_HAMMER, + PLAYER_IA_BOW_LIGHT, + PLAYER_IA_NAYRUS_LOVE, + PLAYER_IA_BOTTLE, + PLAYER_IA_BOTTLE_POTION_RED, + PLAYER_IA_BOTTLE_POTION_GREEN, + PLAYER_IA_BOTTLE_POTION_BLUE, + PLAYER_IA_BOTTLE_FAIRY, + PLAYER_IA_BOTTLE_FISH, + PLAYER_IA_BOTTLE_MILK, + PLAYER_IA_BOTTLE_LETTER, + PLAYER_IA_BOTTLE_FIRE, + PLAYER_IA_BOTTLE_BUG, + PLAYER_IA_BOTTLE_BIG_POE, + PLAYER_IA_BOTTLE_MILK_HALF, + PLAYER_IA_BOTTLE_POE, + PLAYER_IA_WEIRD_EGG, + PLAYER_IA_CHICKEN, + PLAYER_IA_LETTER_ZELDA, + PLAYER_IA_MASK_KEATON, + PLAYER_IA_MASK_SKULL, + PLAYER_IA_MASK_SPOOKY, + PLAYER_IA_MASK_BUNNY, + PLAYER_IA_MASK_GORON, + PLAYER_IA_MASK_ZORA, + PLAYER_IA_MASK_GERUDO, + PLAYER_IA_MASK_TRUTH, + PLAYER_IA_SWORD_MASTER, + PLAYER_IA_POCKET_EGG, + PLAYER_IA_POCKET_CUCCO, + PLAYER_IA_COJIRO, + PLAYER_IA_ODD_MUSHROOM, + PLAYER_IA_ODD_POTION, + PLAYER_IA_SAW, + PLAYER_IA_SWORD_BROKEN, + PLAYER_IA_PRESCRIPTION, + PLAYER_IA_FROG, + PLAYER_IA_EYEDROPS, + PLAYER_IA_CLAIM_CHECK, + PLAYER_IA_BOW_FIRE, + PLAYER_IA_BOW_ICE, + PLAYER_IA_BOW_LIGHT, + PLAYER_IA_SWORD_KOKIRI, + PLAYER_IA_SWORD_MASTER, + PLAYER_IA_SWORD_BGS, }; static s32 (*D_80853EDC[])(Player* this, PlayState* play) = { @@ -1403,7 +1403,7 @@ void func_808323B4(PlayState* play, Player* this) { } if (Player_GetExplosiveHeld(this) >= 0) { - func_8083399C(play, this, PLAYER_AP_NONE); + func_8083399C(play, this, PLAYER_IA_NONE); this->heldItemId = ITEM_NONE_FE; } } @@ -1436,7 +1436,7 @@ void func_80832440(PlayState* play, Player* this) { } s32 func_80832528(PlayState* play, Player* this) { - if (this->heldItemActionParam >= PLAYER_AP_FISHING_POLE) { + if (this->heldItemAction >= PLAYER_IA_FISHING_POLE) { func_80835F44(play, this, ITEM_NONE); return 1; } else { @@ -1852,7 +1852,7 @@ void func_80833638(Player* this, PlayerFunc82C arg1) { func_808326F0(this); } -void func_80833664(PlayState* play, Player* this, s8 actionParam) { +void func_80833664(PlayState* play, Player* this, s8 itemAction) { LinkAnimationHeader* current = this->skelAnime.animation; LinkAnimationHeader** iter = D_80853914 + this->modelAnimType; u32 i; @@ -1866,22 +1866,22 @@ void func_80833664(PlayState* play, Player* this, s8 actionParam) { iter += PLAYER_ANIMTYPE_MAX; } - func_8083399C(play, this, actionParam); + func_8083399C(play, this, itemAction); if (i < PLAYER_ANIMGROUP_MAX) { this->skelAnime.animation = GET_PLAYER_ANIM(i, this->modelAnimType); } } -s8 Player_ItemToActionParam(s32 item) { +s8 Player_ItemToItemAction(s32 item) { if (item >= ITEM_NONE_FE) { - return PLAYER_AP_NONE; + return PLAYER_IA_NONE; } else if (item == ITEM_LAST_USED) { - return PLAYER_AP_LAST_USED; + return PLAYER_IA_LAST_USED; } else if (item == ITEM_FISHING_POLE) { - return PLAYER_AP_FISHING_POLE; + return PLAYER_IA_FISHING_POLE; } else { - return sItemActionParams[item]; + return sItemActions[item]; } } @@ -1898,7 +1898,7 @@ void func_80833790(PlayState* play, Player* this) { void func_8083379C(PlayState* play, Player* this) { this->stateFlags1 |= PLAYER_STATE1_3; - if (this->heldItemActionParam != PLAYER_AP_SLINGSHOT) { + if (this->heldItemAction != PLAYER_IA_SLINGSHOT) { this->unk_860 = -1; } else { this->unk_860 = -2; @@ -1952,17 +1952,17 @@ void func_80833984(PlayState* play, Player* this) { this->stateFlags1 |= PLAYER_STATE1_24; } -void func_8083399C(PlayState* play, Player* this, s8 actionParam) { +void func_8083399C(PlayState* play, Player* this, s8 itemAction) { this->unk_860 = 0; this->unk_85C = 0.0f; this->unk_858 = 0.0f; - this->heldItemActionParam = this->itemActionParam = actionParam; + this->heldItemAction = this->itemAction = itemAction; this->modelGroup = this->nextModelGroup; this->stateFlags1 &= ~(PLAYER_STATE1_3 | PLAYER_STATE1_24); - D_80853FE8[actionParam](play, this); + D_80853FE8[itemAction](play, this); Player_SetModelGroup(this, this->modelGroup); } @@ -1972,14 +1972,14 @@ void func_80833A20(Player* this, s32 newMeleeWeaponState) { u16 voiceSfx; if (this->meleeWeaponState == 0) { - if ((this->heldItemActionParam == PLAYER_AP_SWORD_BGS) && (gSaveContext.swordHealth > 0.0f)) { + if ((this->heldItemAction == PLAYER_IA_SWORD_BGS) && (gSaveContext.swordHealth > 0.0f)) { itemSfx = NA_SE_IT_HAMMER_SWING; } else { itemSfx = NA_SE_IT_SWORD_SWING; } voiceSfx = NA_SE_VO_LI_SWORD_N; - if (this->heldItemActionParam == PLAYER_AP_HAMMER) { + if (this->heldItemAction == PLAYER_IA_HAMMER) { itemSfx = NA_SE_IT_HAMMER_SWING; } else if (this->meleeWeaponAnimation >= PLAYER_MWA_SPIN_ATTACK_1H) { itemSfx = 0; @@ -2039,15 +2039,15 @@ void func_80833C3C(Player* this) { } s32 func_80833C50(Player* this, s32 item) { - if ((item < ITEM_NONE_FE) && (Player_ItemToActionParam(item) == this->itemActionParam)) { + if ((item < ITEM_NONE_FE) && (Player_ItemToItemAction(item) == this->itemAction)) { return 1; } else { return 0; } } -s32 func_80833C98(s32 item1, s32 actionParam) { - if ((item1 < ITEM_NONE_FE) && (Player_ItemToActionParam(item1) == actionParam)) { +s32 func_80833C98(s32 item1, s32 itemAction) { + if ((item1 < ITEM_NONE_FE) && (Player_ItemToItemAction(item1) == itemAction)) { return 1; } else { return 0; @@ -2071,20 +2071,20 @@ s32 func_80833CDC(PlayState* play, s32 index) { } void func_80833DF8(Player* this, PlayState* play) { - s32 maskActionParam; + s32 maskItemAction; s32 item; s32 i; if (this->currentMask != PLAYER_MASK_NONE) { - maskActionParam = this->currentMask - 1 + PLAYER_AP_MASK_KEATON; - if (!func_80833C98(C_BTN_ITEM(0), maskActionParam) && !func_80833C98(C_BTN_ITEM(1), maskActionParam) && - !func_80833C98(C_BTN_ITEM(2), maskActionParam)) { + maskItemAction = this->currentMask - 1 + PLAYER_IA_MASK_KEATON; + if (!func_80833C98(C_BTN_ITEM(0), maskItemAction) && !func_80833C98(C_BTN_ITEM(1), maskItemAction) && + !func_80833C98(C_BTN_ITEM(2), maskItemAction)) { this->currentMask = PLAYER_MASK_NONE; } } if (!(this->stateFlags1 & (PLAYER_STATE1_11 | PLAYER_STATE1_29)) && !func_8008F128(this)) { - if (this->itemActionParam >= PLAYER_AP_FISHING_POLE) { + if (this->itemAction >= PLAYER_IA_FISHING_POLE) { if (!func_80833C50(this, B_BTN_ITEM) && !func_80833C50(this, C_BTN_ITEM(0)) && !func_80833C50(this, C_BTN_ITEM(1)) && !func_80833C50(this, C_BTN_ITEM(2))) { func_80835F44(play, this, ITEM_NONE); @@ -2107,7 +2107,7 @@ void func_80833DF8(Player* this, PlayState* play) { } item = func_80833CDC(play, i); - if ((item < ITEM_NONE_FE) && (Player_ItemToActionParam(item) == this->heldItemActionParam)) { + if ((item < ITEM_NONE_FE) && (Player_ItemToItemAction(item) == this->heldItemAction)) { D_80853618 = true; } } else { @@ -2127,15 +2127,15 @@ void func_808340DC(Player* this, PlayState* play) { s8 sp37; s32 nextAnimType; - sp37 = Player_ItemToActionParam(this->heldItemId); + sp37 = Player_ItemToItemAction(this->heldItemId); func_80833638(this, func_80834A2C); nextAnimType = gPlayerModelTypes[this->nextModelGroup][PLAYER_MODELGROUPENTRY_ANIM]; sp38 = D_80854164[gPlayerModelTypes[this->modelGroup][PLAYER_MODELGROUPENTRY_ANIM]][nextAnimType]; - if ((sp37 == PLAYER_AP_BOTTLE) || (sp37 == PLAYER_AP_BOOMERANG) || - ((sp37 == PLAYER_AP_NONE) && - ((this->heldItemActionParam == PLAYER_AP_BOTTLE) || (this->heldItemActionParam == PLAYER_AP_BOOMERANG)))) { - sp38 = (sp37 == PLAYER_AP_NONE) ? -PLAYER_D_808540F4_13 : PLAYER_D_808540F4_13; + if ((sp37 == PLAYER_IA_BOTTLE) || (sp37 == PLAYER_IA_BOOMERANG) || + ((sp37 == PLAYER_IA_NONE) && + ((this->heldItemAction == PLAYER_IA_BOTTLE) || (this->heldItemAction == PLAYER_IA_BOOMERANG)))) { + sp38 = (sp37 == PLAYER_IA_NONE) ? -PLAYER_D_808540F4_13 : PLAYER_D_808540F4_13; } this->unk_15A = ABS(sp38); @@ -2157,7 +2157,7 @@ void func_808340DC(Player* this, PlayState* play) { phi_f12 = phi_f2; } - if (sp37 != PLAYER_AP_NONE) { + if (sp37 != PLAYER_IA_NONE) { phi_f0 *= 2.0f; } @@ -2168,7 +2168,7 @@ void func_808340DC(Player* this, PlayState* play) { void func_80834298(Player* this, PlayState* play) { if ((this->actor.category == ACTORCAT_PLAYER) && !(this->stateFlags1 & PLAYER_STATE1_8) && - ((this->heldItemActionParam == this->itemActionParam) || (this->stateFlags1 & PLAYER_STATE1_22)) && + ((this->heldItemAction == this->itemAction) || (this->stateFlags1 & PLAYER_STATE1_22)) && (gSaveContext.health != 0) && (play->csCtx.state == CS_STATE_IDLE) && (this->csMode == 0) && (play->shootingGalleryStatus == 0) && (play->activeCamId == CAM_ID_MAIN) && (play->transitionTrigger != TRANS_TRIGGER_START) && (gSaveContext.timer1State != 10)) { @@ -2186,7 +2186,7 @@ s32 func_80834380(PlayState* play, Player* this, s32* itemPtr, s32* typePtr) { if (this->stateFlags1 & PLAYER_STATE1_23) { *typePtr = ARROW_NORMAL_HORSE; } else { - *typePtr = ARROW_NORMAL + (this->heldItemActionParam - PLAYER_AP_BOW); + *typePtr = ARROW_NORMAL + (this->heldItemAction - PLAYER_IA_BOW); } } else { *itemPtr = ITEM_SLINGSHOT; @@ -2207,7 +2207,7 @@ s32 func_8083442C(Player* this, PlayState* play) { s32 arrowType; s32 magicArrowType; - if ((this->heldItemActionParam >= PLAYER_AP_BOW_FIRE) && (this->heldItemActionParam <= PLAYER_AP_BOW_0E) && + if ((this->heldItemAction >= PLAYER_IA_BOW_FIRE) && (this->heldItemAction <= PLAYER_IA_BOW_0E) && (gSaveContext.magicState != MAGIC_STATE_IDLE)) { func_80078884(NA_SE_SY_ERROR); } else { @@ -2242,8 +2242,8 @@ s32 func_8083442C(Player* this, PlayState* play) { } void func_80834594(PlayState* play, Player* this) { - if (this->heldItemActionParam != PLAYER_AP_NONE) { - if (func_8008F2BC(this, this->heldItemActionParam) >= 0) { + if (this->heldItemAction != PLAYER_IA_NONE) { + if (func_8008F2BC(this, this->heldItemAction) >= 0) { func_808328EC(this, NA_SE_IT_SWORD_PUTAWAY); } else { func_808328EC(this, NA_SE_PL_CHANGE_ARMS); @@ -2252,9 +2252,9 @@ void func_80834594(PlayState* play, Player* this) { func_80835F44(play, this, this->heldItemId); - if (func_8008F2BC(this, this->heldItemActionParam) >= 0) { + if (func_8008F2BC(this, this->heldItemAction) >= 0) { func_808328EC(this, NA_SE_IT_SWORD_PICKOUT); - } else if (this->heldItemActionParam != PLAYER_AP_NONE) { + } else if (this->heldItemAction != PLAYER_IA_NONE) { func_808328EC(this, NA_SE_PL_CHANGE_ARMS); } } @@ -2264,7 +2264,7 @@ void func_80834644(PlayState* play, Player* this) { func_80834594(play, this); } - func_80833638(this, D_80853EDC[this->heldItemActionParam]); + func_80833638(this, D_80853EDC[this->heldItemAction]); this->unk_834 = 0; this->unk_6AC = 0; func_808323B4(play, this); @@ -2287,7 +2287,7 @@ s32 func_80834758(PlayState* play, Player* this) { f32 frame; if (!(this->stateFlags1 & (PLAYER_STATE1_22 | PLAYER_STATE1_23 | PLAYER_STATE1_29)) && - (play->shootingGalleryStatus == 0) && (this->heldItemActionParam == this->itemActionParam) && + (play->shootingGalleryStatus == 0) && (this->heldItemAction == this->itemAction) && (this->currentShield != PLAYER_SHIELD_NONE) && !Player_IsChildWithHylianShield(this) && func_80833BCC(this) && CHECK_BTN_ALL(sControlInput->cur.button, BTN_R)) { @@ -2313,7 +2313,7 @@ s32 func_8083485C(Player* this, PlayState* play) { void func_80834894(Player* this) { func_80833638(this, func_80834C74); - if (this->itemActionParam < 0) { + if (this->itemAction < 0) { func_8008EC70(this); } @@ -2355,10 +2355,10 @@ s32 func_808349DC(Player* this, PlayState* play) { s32 func_80834A2C(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime2) || - ((Player_ItemToActionParam(this->heldItemId) == this->heldItemActionParam) && + ((Player_ItemToItemAction(this->heldItemId) == this->heldItemAction) && (D_80853614 = (D_80853614 || ((this->modelAnimType != PLAYER_ANIMTYPE_3) && (play->shootingGalleryStatus == 0)))))) { - func_80833638(this, D_80853EDC[this->heldItemActionParam]); + func_80833638(this, D_80853EDC[this->heldItemAction]); this->unk_834 = 0; this->unk_6AC = 0; D_80853618 = D_80853614; @@ -2409,7 +2409,7 @@ s32 func_80834C74(Player* this, PlayState* play) { D_80853614 = D_80853618; if (D_80853614 || LinkAnimation_Update(play, &this->skelAnime2)) { - func_80833638(this, D_80853EDC[this->heldItemActionParam]); + func_80833638(this, D_80853EDC[this->heldItemAction]); LinkAnimation_PlayLoop(play, &this->skelAnime2, GET_PLAYER_ANIM(PLAYER_ANIMGROUP_0, this->modelAnimType)); this->unk_6AC = 0; this->func_82C(this, play); @@ -2422,7 +2422,7 @@ s32 func_80834C74(Player* this, PlayState* play) { s32 func_80834D2C(Player* this, PlayState* play) { LinkAnimationHeader* anim; - if (this->heldItemActionParam != PLAYER_AP_BOOMERANG) { + if (this->heldItemAction != PLAYER_IA_BOOMERANG) { if (!func_8083442C(this, play)) { return 0; } @@ -2820,8 +2820,7 @@ s32 func_80835C58(PlayState* play, Player* this, PlayerFunc674 func, s32 flags) this->func_674 = func; - if ((this->itemActionParam != this->heldItemActionParam) && - (!(flags & 1) || !(this->stateFlags1 & PLAYER_STATE1_22))) { + if ((this->itemAction != this->heldItemAction) && (!(flags & 1) || !(this->stateFlags1 & PLAYER_STATE1_22))) { func_8008EC70(this); } @@ -2855,12 +2854,12 @@ void func_80835DAC(PlayState* play, Player* this, PlayerFunc674 func, s32 flags) void func_80835DE4(PlayState* play, Player* this, PlayerFunc674 func, s32 flags) { s32 temp; - if (this->itemActionParam >= 0) { - temp = this->itemActionParam; - this->itemActionParam = this->heldItemActionParam; + if (this->itemAction >= 0) { + temp = this->itemAction; + this->itemAction = this->heldItemAction; func_80835C58(play, this, func, flags); - this->itemActionParam = temp; - Player_SetModels(this, Player_ActionToModelGroup(this, this->itemActionParam)); + this->itemAction = temp; + Player_SetModels(this, Player_ActionToModelGroup(this, this->itemAction)); } } @@ -2892,30 +2891,29 @@ void func_80835EFC(Player* this) { } void func_80835F44(PlayState* play, Player* this, s32 item) { - s8 actionParam; + s8 itemAction; s32 temp; s32 nextAnimType; - actionParam = Player_ItemToActionParam(item); + itemAction = Player_ItemToItemAction(item); - if (((this->heldItemActionParam == this->itemActionParam) && - (!(this->stateFlags1 & PLAYER_STATE1_22) || (Player_ActionToMeleeWeapon(actionParam) != 0) || - (actionParam == PLAYER_AP_NONE))) || - ((this->itemActionParam < 0) && - ((Player_ActionToMeleeWeapon(actionParam) != 0) || (actionParam == PLAYER_AP_NONE)))) { + if (((this->heldItemAction == this->itemAction) && + (!(this->stateFlags1 & PLAYER_STATE1_22) || (Player_ActionToMeleeWeapon(itemAction) != 0) || + (itemAction == PLAYER_IA_NONE))) || + ((this->itemAction < 0) && ((Player_ActionToMeleeWeapon(itemAction) != 0) || (itemAction == PLAYER_IA_NONE)))) { - if ((actionParam == PLAYER_AP_NONE) || !(this->stateFlags1 & PLAYER_STATE1_27) || + if ((itemAction == PLAYER_IA_NONE) || !(this->stateFlags1 & PLAYER_STATE1_27) || ((this->actor.bgCheckFlags & BGCHECKFLAG_GROUND) && - ((actionParam == PLAYER_AP_HOOKSHOT) || (actionParam == PLAYER_AP_LONGSHOT)))) { + ((itemAction == PLAYER_IA_HOOKSHOT) || (itemAction == PLAYER_IA_LONGSHOT)))) { if ((play->bombchuBowlingStatus == 0) && - (((actionParam == PLAYER_AP_STICK) && (AMMO(ITEM_STICK) == 0)) || - ((actionParam == PLAYER_AP_BEAN) && (AMMO(ITEM_BEAN) == 0)) || - (temp = Player_ActionToExplosive(this, actionParam), + (((itemAction == PLAYER_IA_STICK) && (AMMO(ITEM_STICK) == 0)) || + ((itemAction == PLAYER_IA_BEAN) && (AMMO(ITEM_BEAN) == 0)) || + (temp = Player_ActionToExplosive(this, itemAction), ((temp >= 0) && ((AMMO(sExplosiveInfos[temp].itemId) == 0) || (play->actorCtx.actorLists[ACTORCAT_EXPLOSIVE].length >= 3)))))) { func_80078884(NA_SE_SY_ERROR); - } else if (actionParam == PLAYER_AP_LENS) { + } else if (itemAction == PLAYER_IA_LENS) { if (Magic_RequestChange(play, 0, MAGIC_CONSUME_LENS)) { if (play->actorCtx.lensActive) { Actor_DisableLens(play); @@ -2927,43 +2925,43 @@ void func_80835F44(PlayState* play, Player* this, s32 item) { } else { func_80078884(NA_SE_SY_ERROR); } - } else if (actionParam == PLAYER_AP_NUT) { + } else if (itemAction == PLAYER_IA_NUT) { if (AMMO(ITEM_NUT) != 0) { func_8083C61C(play, this); } else { func_80078884(NA_SE_SY_ERROR); } - } else if ((temp = Player_ActionToMagicSpell(this, actionParam)) >= 0) { - if (((actionParam == PLAYER_AP_FARORES_WIND) && (gSaveContext.respawn[RESPAWN_MODE_TOP].data > 0)) || + } else if ((temp = Player_ActionToMagicSpell(this, itemAction)) >= 0) { + if (((itemAction == PLAYER_IA_FARORES_WIND) && (gSaveContext.respawn[RESPAWN_MODE_TOP].data > 0)) || ((gSaveContext.magicCapacity != 0) && (gSaveContext.magicState == MAGIC_STATE_IDLE) && (gSaveContext.magic >= sMagicSpellCosts[temp]))) { - this->itemActionParam = actionParam; + this->itemAction = itemAction; this->unk_6AD = 4; } else { func_80078884(NA_SE_SY_ERROR); } - } else if (actionParam >= PLAYER_AP_MASK_KEATON) { + } else if (itemAction >= PLAYER_IA_MASK_KEATON) { if (this->currentMask != PLAYER_MASK_NONE) { this->currentMask = PLAYER_MASK_NONE; } else { - this->currentMask = actionParam - PLAYER_AP_MASK_KEATON + 1; + this->currentMask = itemAction - PLAYER_IA_MASK_KEATON + 1; } func_808328EC(this, NA_SE_PL_CHANGE_ARMS); - } else if (((actionParam >= PLAYER_AP_OCARINA_FAIRY) && (actionParam <= PLAYER_AP_OCARINA_TIME)) || - (actionParam >= PLAYER_AP_BOTTLE_FISH)) { + } else if (((itemAction >= PLAYER_IA_OCARINA_FAIRY) && (itemAction <= PLAYER_IA_OCARINA_TIME)) || + (itemAction >= PLAYER_IA_BOTTLE_FISH)) { if (!func_8008E9C4(this) || - ((actionParam >= PLAYER_AP_BOTTLE_POTION_RED) && (actionParam <= PLAYER_AP_BOTTLE_FAIRY))) { + ((itemAction >= PLAYER_IA_BOTTLE_POTION_RED) && (itemAction <= PLAYER_IA_BOTTLE_FAIRY))) { TitleCard_Clear(play, &play->actorCtx.titleCtx); this->unk_6AD = 4; - this->itemActionParam = actionParam; + this->itemAction = itemAction; } - } else if ((actionParam != this->heldItemActionParam) || - ((this->heldActor == NULL) && (Player_ActionToExplosive(this, actionParam) >= 0))) { - this->nextModelGroup = Player_ActionToModelGroup(this, actionParam); + } else if ((itemAction != this->heldItemAction) || + ((this->heldActor == NULL) && (Player_ActionToExplosive(this, itemAction) >= 0))) { + this->nextModelGroup = Player_ActionToModelGroup(this, itemAction); nextAnimType = gPlayerModelTypes[this->nextModelGroup][PLAYER_MODELGROUPENTRY_ANIM]; - if ((this->heldItemActionParam >= 0) && (Player_ActionToMagicSpell(this, actionParam) < 0) && + if ((this->heldItemAction >= 0) && (Player_ActionToMagicSpell(this, itemAction) < 0) && (item != this->heldItemId) && (D_80854164[gPlayerModelTypes[this->modelGroup][PLAYER_MODELGROUPENTRY_ANIM]][nextAnimType] != PLAYER_D_808540F4_0)) { @@ -2972,7 +2970,7 @@ void func_80835F44(PlayState* play, Player* this, s32 item) { } else { func_80835EFC(this); func_808323B4(play, this); - func_80833664(play, this, actionParam); + func_80833664(play, this, itemAction); } } else { D_80853614 = D_80853618 = true; @@ -3021,8 +3019,7 @@ s32 func_808365C8(Player* this) { return (!(func_808458D0 == this->func_674) || ((this->stateFlags1 & PLAYER_STATE1_8) && ((this->heldItemId == ITEM_LAST_USED) || (this->heldItemId == ITEM_NONE)))) && - (!(func_80834A2C == this->func_82C) || - (Player_ItemToActionParam(this->heldItemId) == this->heldItemActionParam)); + (!(func_80834A2C == this->func_82C) || (Player_ItemToItemAction(this->heldItemId) == this->heldItemAction)); } s32 func_80836670(Player* this, PlayState* play) { @@ -3175,7 +3172,7 @@ void func_80836BEC(Player* this, PlayState* play) { if (cond || (this->unk_66C != 0) || (this->stateFlags1 & (PLAYER_STATE1_12 | PLAYER_STATE1_25))) { if (!cond) { if (!(this->stateFlags1 & PLAYER_STATE1_25) && - ((this->heldItemActionParam != PLAYER_AP_FISHING_POLE) || (this->unk_860 == 0)) && + ((this->heldItemAction != PLAYER_IA_FISHING_POLE) || (this->unk_860 == 0)) && CHECK_BTN_ALL(sControlInput->press.button, BTN_Z)) { if (this->actor.category == ACTORCAT_PLAYER) { @@ -3407,7 +3404,7 @@ s32 func_808375D8(Player* this) { s8 temp2; s32 i; - if ((this->heldItemActionParam == PLAYER_AP_STICK) || Player_HoldsBrokenKnife(this)) { + if ((this->heldItemAction == PLAYER_IA_STICK) || Player_HoldsBrokenKnife(this)) { return 0; } @@ -3473,7 +3470,7 @@ s32 func_80837818(Player* this) { s32 sp1C = this->unk_84B[this->unk_846]; s32 sp18; - if (this->heldItemActionParam == PLAYER_AP_HAMMER) { + if (this->heldItemAction == PLAYER_IA_HAMMER) { if (sp1C < 0) { sp1C = 0; } @@ -3498,7 +3495,7 @@ s32 func_80837818(Player* this) { } } } - if (this->heldItemActionParam == PLAYER_AP_STICK) { + if (this->heldItemAction == PLAYER_IA_STICK) { sp18 = PLAYER_MWA_FORWARD_SLASH_1H; } } @@ -4954,7 +4951,7 @@ s32 func_8083B040(Player* this, PlayState* play) { if (!func_8083ADD4(play, this)) { if (this->unk_6AD == 4) { - sp2C = Player_ActionToMagicSpell(this, this->itemActionParam); + sp2C = Player_ActionToMagicSpell(this, this->itemAction); if (sp2C >= 0) { if ((sp2C != 3) || (gSaveContext.respawn[RESPAWN_MODE_TOP].data <= 0)) { func_8083AF44(play, this, sp2C); @@ -4969,13 +4966,13 @@ s32 func_8083B040(Player* this, PlayState* play) { return 1; } - sp2C = this->itemActionParam - PLAYER_AP_LETTER_ZELDA; + sp2C = this->itemAction - PLAYER_IA_LETTER_ZELDA; if ((sp2C >= 0) || - (sp28 = Player_ActionToBottle(this, this->itemActionParam) - 1, + (sp28 = Player_ActionToBottle(this, this->itemAction) - 1, ((sp28 >= 0) && (sp28 < 6) && - ((this->itemActionParam > PLAYER_AP_BOTTLE_POE) || + ((this->itemAction > PLAYER_IA_BOTTLE_POE) || ((this->targetActor != NULL) && - (((this->itemActionParam == PLAYER_AP_BOTTLE_POE) && (this->exchangeItemId == EXCH_ITEM_POE)) || + (((this->itemAction == PLAYER_IA_BOTTLE_POE) && (this->exchangeItemId == EXCH_ITEM_POE)) || (this->exchangeItemId == EXCH_ITEM_BLUE_FIRE))))))) { if ((play->actorCtx.titleCtx.delayTimer == 0) && (play->actorCtx.titleCtx.alpha == 0)) { @@ -4999,10 +4996,10 @@ s32 func_8083B040(Player* this, PlayState* play) { if ((targetActor != NULL) && ((this->exchangeItemId == sp2C) || (this->exchangeItemId == EXCH_ITEM_BLUE_FIRE) || ((this->exchangeItemId == EXCH_ITEM_POE) && - (this->itemActionParam == PLAYER_AP_BOTTLE_BIG_POE)) || + (this->itemAction == PLAYER_IA_BOTTLE_BIG_POE)) || ((this->exchangeItemId == EXCH_ITEM_BEAN) && - (this->itemActionParam == PLAYER_AP_BOTTLE_BUG))) && - ((this->exchangeItemId != EXCH_ITEM_BEAN) || (this->itemActionParam == PLAYER_AP_BEAN))) { + (this->itemAction == PLAYER_IA_BOTTLE_BUG))) && + ((this->exchangeItemId != EXCH_ITEM_BEAN) || (this->itemAction == PLAYER_IA_BEAN))) { if (this->exchangeItemId == EXCH_ITEM_BEAN) { Inventory_ChangeAmmo(ITEM_BEAN, -1); func_80835DE4(play, this, func_8084279C, 0); @@ -5036,7 +5033,7 @@ s32 func_8083B040(Player* this, PlayState* play) { return 1; } - sp2C = Player_ActionToBottle(this, this->itemActionParam); + sp2C = Player_ActionToBottle(this, this->itemAction); if (sp2C >= 0) { if (sp2C == 0xC) { func_80835DE4(play, this, func_8084EED8, 0); @@ -5359,7 +5356,7 @@ s32 func_8083C1DC(Player* this, PlayState* play) { if (func_8083BC7C(this, play)) { return 1; } - if ((this->unk_837 == 0) && (this->heldItemActionParam >= PLAYER_AP_SWORD_MASTER)) { + if ((this->unk_837 == 0) && (this->heldItemAction >= PLAYER_IA_SWORD_MASTER)) { func_80835F44(play, this, ITEM_NONE); } else { this->stateFlags2 ^= PLAYER_STATE2_20; @@ -5440,8 +5437,8 @@ void func_8083C50C(Player* this) { s32 func_8083C544(Player* this, PlayState* play) { if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_B)) { if (!(this->stateFlags1 & PLAYER_STATE1_22) && (Player_GetMeleeWeaponHeld(this) != 0) && (this->unk_844 == 1) && - (this->heldItemActionParam != PLAYER_AP_STICK)) { - if ((this->heldItemActionParam != PLAYER_AP_SWORD_BGS) || (gSaveContext.swordHealth > 0.0f)) { + (this->heldItemAction != PLAYER_IA_STICK)) { + if ((this->heldItemAction != PLAYER_IA_SWORD_BGS) || (gSaveContext.swordHealth > 0.0f)) { func_808377DC(play, this); return 1; } @@ -5488,7 +5485,7 @@ s32 func_8083C6B8(PlayState* play, Player* this) { return 1; } - if (this->heldItemActionParam == PLAYER_AP_FISHING_POLE) { + if (this->heldItemAction == PLAYER_IA_FISHING_POLE) { sp24 = this->actor.world.pos; sp24.y += 50.0f; @@ -6221,16 +6218,16 @@ s32 func_8083E5A8(Player* this, PlayState* play) { if ((this->heldActor == NULL) || Player_HoldsHookshot(this)) { if ((interactedActor->id == ACTOR_BG_TOKI_SWD) && LINK_IS_ADULT) { - s32 sp24 = this->itemActionParam; + s32 sp24 = this->itemAction; - this->itemActionParam = PLAYER_AP_NONE; + this->itemAction = PLAYER_IA_NONE; this->modelAnimType = PLAYER_ANIMTYPE_0; - this->heldItemActionParam = this->itemActionParam; + this->heldItemAction = this->itemAction; func_80836898(play, this, func_8083A0F4); - if (sp24 == PLAYER_AP_SWORD_MASTER) { - this->nextModelGroup = Player_ActionToModelGroup(this, PLAYER_AP_LAST_USED); - func_8083399C(play, this, PLAYER_AP_LAST_USED); + if (sp24 == PLAYER_IA_SWORD_MASTER) { + this->nextModelGroup = Player_ActionToModelGroup(this, PLAYER_IA_LAST_USED); + func_8083399C(play, this, PLAYER_IA_LAST_USED); } else { func_80835F44(play, this, ITEM_LAST_USED); } @@ -7714,7 +7711,7 @@ void func_80842A88(PlayState* play, Player* this) { } s32 func_80842AC4(PlayState* play, Player* this) { - if ((this->heldItemActionParam == PLAYER_AP_STICK) && (this->unk_85C > 0.5f)) { + if ((this->heldItemAction == PLAYER_IA_STICK) && (this->unk_85C > 0.5f)) { if (AMMO(ITEM_STICK) != 0) { EffectSsStick_Spawn(play, &this->bodyPartsPos[PLAYER_BODYPART_R_HAND], this->actor.shape.rot.y + 0x8000); this->unk_85C = 0.5f; @@ -7729,7 +7726,7 @@ s32 func_80842AC4(PlayState* play, Player* this) { } s32 func_80842B7C(PlayState* play, Player* this) { - if (this->heldItemActionParam == PLAYER_AP_SWORD_BGS) { + if (this->heldItemAction == PLAYER_IA_SWORD_BGS) { if (!gSaveContext.bgsFlag && (gSaveContext.swordHealth > 0.0f)) { if ((gSaveContext.swordHealth -= 1.0f) <= 0.0f) { EffectSsStick_Spawn(play, &this->bodyPartsPos[PLAYER_BODYPART_R_HAND], @@ -7811,7 +7808,7 @@ s32 func_80842DF4(PlayState* play, Player* this) { (SurfaceType_GetFloorType(&play->colCtx, sp78, sp74) != FLOOR_TYPE_6) && (func_8002F9EC(play, &this->actor, sp78, sp74, &sp5C) == 0)) { - if (this->heldItemActionParam == PLAYER_AP_HAMMER) { + if (this->heldItemAction == PLAYER_IA_HAMMER) { func_80832630(play); func_80842A28(play, this); func_80842D20(play, this); @@ -7856,7 +7853,7 @@ s32 func_80842DF4(PlayState* play, Player* this) { } } - if ((func_80842AC4(play, this) == 0) && (this->heldItemActionParam != PLAYER_AP_HAMMER)) { + if ((func_80842AC4(play, this) == 0) && (this->heldItemAction != PLAYER_IA_HAMMER)) { func_80842B7C(play, this); if (this->actor.colChkInfo.atHitEffect == 1) { @@ -7948,7 +7945,7 @@ void func_80843188(Player* this, PlayState* play) { ANIMMODE_ONCE, 0.0f); func_80832F54(play, this, 4); } else { - if (this->itemActionParam < 0) { + if (this->itemAction < 0) { func_8008EC70(this); } func_8083A098(this, GET_PLAYER_ANIM(PLAYER_ANIMGROUP_22, this->modelAnimType), play); @@ -9220,15 +9217,15 @@ static u8 D_808546F0[] = { ITEM_SWORD_MASTER, ITEM_SWORD_KOKIRI }; void func_80846720(PlayState* play, Player* this, s32 arg2) { s32 item = D_808546F0[(void)0, gSaveContext.linkAge]; - s32 actionParam = sItemActionParams[item]; + s32 itemAction = sItemActions[item]; func_80835EFC(this); func_808323B4(play, this); this->heldItemId = item; - this->nextModelGroup = Player_ActionToModelGroup(this, actionParam); + this->nextModelGroup = Player_ActionToModelGroup(this, itemAction); - func_8083399C(play, this, actionParam); + func_8083399C(play, this, itemAction); func_80834644(play, this); if (arg2 != 0) { @@ -9358,7 +9355,7 @@ void Player_Init(Actor* thisx, PlayState* play2) { thisx->room = -1; this->ageProperties = &sAgeProperties[gSaveContext.linkAge]; - this->itemActionParam = this->heldItemActionParam = -1; + this->itemAction = this->heldItemAction = -1; this->heldItemId = ITEM_NONE; func_80835F44(play, this, ITEM_NONE); @@ -9525,7 +9522,7 @@ void func_808473D4(PlayState* play, Player* this) { if (!Player_InBlockingCsMode(play, this)) { if (this->stateFlags1 & PLAYER_STATE1_20) { doAction = DO_ACTION_RETURN; - } else if ((this->heldItemActionParam == PLAYER_AP_FISHING_POLE) && (this->unk_860 != 0)) { + } else if ((this->heldItemAction == PLAYER_IA_FISHING_POLE) && (this->unk_860 != 0)) { if (this->unk_860 == 2) { doAction = DO_ACTION_REEL; } @@ -9601,7 +9598,7 @@ void func_808473D4(PlayState* play, Player* this) { } else if ((play->roomCtx.curRoom.behaviorType1 != ROOM_BEHAVIOR_TYPE1_2) && func_80833BCC(this) && (sp20 > 0)) { doAction = DO_ACTION_JUMP; - } else if ((this->heldItemActionParam >= PLAYER_AP_SWORD_MASTER) || + } else if ((this->heldItemAction >= PLAYER_IA_SWORD_MASTER) || ((this->stateFlags2 & PLAYER_STATE2_20) && (play->actorCtx.targetCtx.arrowPointedActor == NULL))) { doAction = DO_ACTION_PUTAWAY; @@ -10220,9 +10217,9 @@ void Player_UpdateCommon(Player* this, PlayState* play, Input* input) { func_808473D4(play, this); func_80836BEC(this, play); - if ((this->heldItemActionParam == PLAYER_AP_STICK) && (this->unk_860 != 0)) { + if ((this->heldItemAction == PLAYER_IA_STICK) && (this->unk_860 != 0)) { func_80848A04(play, this); - } else if ((this->heldItemActionParam == PLAYER_AP_FISHING_POLE) && (this->unk_860 < 0)) { + } else if ((this->heldItemAction == PLAYER_IA_FISHING_POLE) && (this->unk_860 < 0)) { this->unk_860++; } @@ -11002,8 +10999,8 @@ s32 func_8084B3CC(PlayState* play, Player* this) { } void func_8084B498(Player* this) { - this->itemActionParam = - (INV_CONTENT(ITEM_OCARINA_FAIRY) == ITEM_OCARINA_FAIRY) ? PLAYER_AP_OCARINA_FAIRY : PLAYER_AP_OCARINA_TIME; + this->itemAction = + (INV_CONTENT(ITEM_OCARINA_FAIRY) == ITEM_OCARINA_FAIRY) ? PLAYER_IA_OCARINA_FAIRY : PLAYER_IA_OCARINA_TIME; } s32 func_8084B4D4(PlayState* play, Player* this) { @@ -11056,8 +11053,7 @@ void func_8084B530(Player* this, PlayState* play) { } else if (!func_8008E9C4(this) && LinkAnimation_Update(play, &this->skelAnime)) { if (this->skelAnime.moveFlags != 0) { func_80832DBC(this); - if ((this->targetActor->category == ACTORCAT_NPC) && - (this->heldItemActionParam != PLAYER_AP_FISHING_POLE)) { + if ((this->targetActor->category == ACTORCAT_NPC) && (this->heldItemAction != PLAYER_IA_FISHING_POLE)) { func_808322D0(play, this, &gPlayerAnim_link_normal_talk_free); } else { func_80832284(play, this, func_80833338(this)); @@ -12395,7 +12391,7 @@ static u8 D_808549FC[] = { void func_8084EAC0(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { if (this->unk_850 == 0) { - if (this->itemActionParam == PLAYER_AP_BOTTLE_POE) { + if (this->itemAction == PLAYER_IA_BOTTLE_POE) { s32 rand = Rand_S16Offset(-1, 3); if (rand == 0) { @@ -12412,7 +12408,7 @@ void func_8084EAC0(Player* this, PlayState* play) { gSaveContext.healthAccumulator = rand * 0x10; } } else { - s32 sp28 = D_808549FC[this->itemActionParam - PLAYER_AP_BOTTLE_POTION_RED]; + s32 sp28 = D_808549FC[this->itemAction - PLAYER_IA_BOTTLE_POTION_RED]; if (sp28 & 1) { gSaveContext.healthAccumulator = 0x140; @@ -12438,7 +12434,7 @@ void func_8084EAC0(Player* this, PlayState* play) { if ((gSaveContext.healthAccumulator == 0) && (gSaveContext.magicState != MAGIC_STATE_FILL)) { func_80832B78(play, this, &gPlayerAnim_link_bottle_drink_demo_end); this->unk_850 = 2; - Player_UpdateBottleHeld(play, this, ITEM_BOTTLE, PLAYER_AP_BOTTLE); + Player_UpdateBottleHeld(play, this, ITEM_BOTTLE, PLAYER_IA_BOTTLE); } func_80832698(this, NA_SE_VO_LI_DRINK - SFX_FLAG); } else if ((this->unk_850 == 2) && LinkAnimation_OnFrame(&this->skelAnime, 29.0f)) { @@ -12447,10 +12443,10 @@ void func_8084EAC0(Player* this, PlayState* play) { } static BottleCatchInfo sBottleCatchInfos[] = { - { ACTOR_EN_ELF, ITEM_FAIRY, PLAYER_AP_BOTTLE_FAIRY, 0x46 }, - { ACTOR_EN_FISH, ITEM_FISH, PLAYER_AP_BOTTLE_FISH, 0x47 }, - { ACTOR_EN_ICE_HONO, ITEM_BLUE_FIRE, PLAYER_AP_BOTTLE_FIRE, 0x5D }, - { ACTOR_EN_INSECT, ITEM_BUG, PLAYER_AP_BOTTLE_BUG, 0x7A }, + { ACTOR_EN_ELF, ITEM_FAIRY, PLAYER_IA_BOTTLE_FAIRY, 0x46 }, + { ACTOR_EN_FISH, ITEM_FISH, PLAYER_IA_BOTTLE_FISH, 0x47 }, + { ACTOR_EN_ICE_HONO, ITEM_BLUE_FIRE, PLAYER_IA_BOTTLE_FIRE, 0x5D }, + { ACTOR_EN_INSECT, ITEM_BUG, PLAYER_IA_BOTTLE_BUG, 0x7A }, }; void func_8084ECA4(Player* this, PlayState* play) { @@ -12500,7 +12496,7 @@ void func_8084ECA4(Player* this, PlayState* play) { this->unk_850 = 0; this->stateFlags1 |= PLAYER_STATE1_28 | PLAYER_STATE1_29; this->interactRangeActor->parent = &this->actor; - Player_UpdateBottleHeld(play, this, catchInfo->itemId, ABS(catchInfo->actionParam)); + Player_UpdateBottleHeld(play, this, catchInfo->itemId, ABS(catchInfo->itemAction)); func_808322D0(play, this, sp24->unk_04); func_80835EA4(play, 4); } @@ -12529,7 +12525,7 @@ void func_8084EED8(Player* this, PlayState* play) { if (LinkAnimation_OnFrame(&this->skelAnime, 37.0f)) { Player_SpawnFairy(play, this, &this->leftHandPos, &D_80854A1C, FAIRY_REVIVE_BOTTLE); - Player_UpdateBottleHeld(play, this, ITEM_BOTTLE, PLAYER_AP_BOTTLE); + Player_UpdateBottleHeld(play, this, ITEM_BOTTLE, PLAYER_IA_BOTTLE); func_8002F7DC(&this->actor, NA_SE_EV_BOTTLE_CAP_OPEN); func_8002F7DC(&this->actor, NA_SE_EV_FIATY_HEAL - SFX_FLAG); } else if (LinkAnimation_OnFrame(&this->skelAnime, 47.0f)) { @@ -12558,14 +12554,14 @@ void func_8084EFC0(Player* this, PlayState* play) { } if (LinkAnimation_OnFrame(&this->skelAnime, 76.0f)) { - BottleDropInfo* dropInfo = &D_80854A28[this->itemActionParam - PLAYER_AP_BOTTLE_FISH]; + BottleDropInfo* dropInfo = &D_80854A28[this->itemAction - PLAYER_IA_BOTTLE_FISH]; Actor_Spawn(&play->actorCtx, play, dropInfo->actorId, (Math_SinS(this->actor.shape.rot.y) * 5.0f) + this->leftHandPos.x, this->leftHandPos.y, (Math_CosS(this->actor.shape.rot.y) * 5.0f) + this->leftHandPos.z, 0x4000, this->actor.shape.rot.y, 0, dropInfo->actorParams); - Player_UpdateBottleHeld(play, this, ITEM_BOTTLE, PLAYER_AP_BOTTLE); + Player_UpdateBottleHeld(play, this, ITEM_BOTTLE, PLAYER_IA_BOTTLE); return; } @@ -12594,7 +12590,7 @@ void func_8084F104(Player* this, PlayState* play) { } else { GetItemEntry* giEntry = &sGetItemTable[D_80854528[this->exchangeItemId - 1] - 1]; - if (this->itemActionParam >= PLAYER_AP_LETTER_ZELDA) { + if (this->itemAction >= PLAYER_IA_LETTER_ZELDA) { if (giEntry->gi >= 0) { this->unk_862 = giEntry->gi; } else { @@ -12605,7 +12601,7 @@ void func_8084F104(Player* this, PlayState* play) { if (this->unk_850 == 0) { Message_StartTextbox(play, this->actor.textId, &this->actor); - if ((this->itemActionParam == PLAYER_AP_CHICKEN) || (this->itemActionParam == PLAYER_AP_POCKET_CUCCO)) { + if ((this->itemAction == PLAYER_IA_CHICKEN) || (this->itemAction == PLAYER_IA_POCKET_CUCCO)) { func_8002F7DC(&this->actor, NA_SE_EV_CHICKEN_CRY_M); } @@ -13013,7 +13009,7 @@ void func_808502D0(Player* this, PlayState* play) { if (!func_80842DF4(play, this)) { func_8084285C(this, 0.0f, sp44->unk_0C, sp44->unk_0D); - if ((this->stateFlags2 & PLAYER_STATE2_30) && (this->heldItemActionParam != PLAYER_AP_HAMMER) && + if ((this->stateFlags2 & PLAYER_STATE2_30) && (this->heldItemAction != PLAYER_IA_HAMMER) && LinkAnimation_OnFrame(&this->skelAnime, 0.0f)) { this->linearVelocity = 15.0f; this->stateFlags2 &= ~PLAYER_STATE2_30; @@ -13050,7 +13046,7 @@ void func_808502D0(Player* this, PlayState* play) { this->skelAnime.moveFlags = sp43; this->stateFlags3 |= PLAYER_STATE3_3; } - } else if (this->heldItemActionParam == PLAYER_AP_HAMMER) { + } else if (this->heldItemAction == PLAYER_IA_HAMMER) { if ((this->meleeWeaponAnimation == PLAYER_MWA_HAMMER_FORWARD) || (this->meleeWeaponAnimation == PLAYER_MWA_JUMPSLASH_FINISH)) { static Vec3f zeroVec = { 0.0f, 0.0f, 0.0f }; @@ -13180,7 +13176,7 @@ static struct_80832924 D_80854A8C[][2] = { void func_808507F4(Player* this, PlayState* play) { if (LinkAnimation_Update(play, &this->skelAnime)) { if (this->unk_84F < 0) { - if ((this->itemActionParam == PLAYER_AP_NAYRUS_LOVE) || (gSaveContext.magicState == MAGIC_STATE_IDLE)) { + if ((this->itemAction == PLAYER_IA_NAYRUS_LOVE) || (gSaveContext.magicState == MAGIC_STATE_IDLE)) { func_80839FFC(this, play); func_8005B1A4(Play_GetCamera(play, CAM_ID_MAIN)); } @@ -13936,7 +13932,7 @@ void func_80851CA4(PlayState* play, Player* this, CsCmdActorAction* arg2) { void func_80851D2C(PlayState* play, Player* this, CsCmdActorAction* arg2) { func_80850F1C(play, this, &gPlayerAnim_link_normal_okarina_start); func_8084B498(this); - Player_SetModels(this, Player_ActionToModelGroup(this, this->itemActionParam)); + Player_SetModels(this, Player_ActionToModelGroup(this, this->itemAction)); } static struct_80832924 D_808551B8[] = { @@ -14190,9 +14186,9 @@ void func_80852648(PlayState* play, Player* this, CsCmdActorAction* arg2) { LinkAnimation_Update(play, &this->skelAnime); if (LinkAnimation_OnFrame(&this->skelAnime, 10.0f)) { - this->heldItemActionParam = this->itemActionParam = PLAYER_AP_NONE; + this->heldItemAction = this->itemAction = PLAYER_IA_NONE; this->heldItemId = ITEM_NONE; - this->modelGroup = this->nextModelGroup = Player_ActionToModelGroup(this, PLAYER_AP_NONE); + this->modelGroup = this->nextModelGroup = Player_ActionToModelGroup(this, PLAYER_IA_NONE); this->leftHandDLists = gPlayerLeftHandOpenDLs; Inventory_ChangeEquipment(EQUIP_TYPE_SWORD, EQUIP_VALUE_SWORD_MASTER); gSaveContext.equips.buttonItems[0] = ITEM_SWORD_MASTER; @@ -14253,7 +14249,7 @@ void func_808528C8(PlayState* play, Player* this, CsCmdActorAction* arg2) { func_8084285C(this, 0.0f, 99.0f, this->skelAnime.endFrame - 8.0f); } - if (this->heldItemActionParam != PLAYER_AP_SWORD_MASTER) { + if (this->heldItemAction != PLAYER_IA_SWORD_MASTER) { func_80846720(play, this, 1); } } @@ -14377,7 +14373,7 @@ void func_80852E14(Player* this, PlayState* play) { s32 Player_IsDroppingFish(PlayState* play) { Player* this = GET_PLAYER(play); - return (func_8084EFC0 == this->func_674) && (this->itemActionParam == PLAYER_AP_BOTTLE_FISH); + return (func_8084EFC0 == this->func_674) && (this->itemAction == PLAYER_IA_BOTTLE_FISH); } s32 Player_StartFishing(PlayState* play) { @@ -14472,7 +14468,7 @@ void func_80853148(PlayState* play, Actor* actor) { if (func_808332B8(this)) { func_80836898(play, this, func_8083A2F8); func_80832C6C(play, this, &gPlayerAnim_link_swimer_swim_wait); - } else if ((actor->category != ACTORCAT_NPC) || (this->heldItemActionParam == PLAYER_AP_FISHING_POLE)) { + } else if ((actor->category != ACTORCAT_NPC) || (this->heldItemAction == PLAYER_IA_FISHING_POLE)) { func_8083A2F8(play, this); if (!func_8008E9C4(this)) { diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 9a0462541a..f9f103731d 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1894,6 +1894,7 @@ void FileSelect_Init(GameState* thisx) { this->state.destroy = FileSelect_Destroy; FileSelect_InitContext(&this->state); Font_LoadOrderedFont(&this->font); - Audio_QueueSeqCmd(0xF << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0xA); - func_800F5E18(SEQ_PLAYER_BGM_MAIN, NA_BGM_FILE_SELECT, 0, 7, 1); + SEQCMD_RESET_AUDIO_HEAP(0, 10); + // Setting ioData to 1 and writing it to ioPort 7 will skip the harp intro + Audio_PlaySequenceWithSeqPlayerIO(SEQ_PLAYER_BGM_MAIN, NA_BGM_FILE_SELECT, 0, 7, 1); } diff --git a/src/overlays/gamestates/ovl_select/z_select.c b/src/overlays/gamestates/ovl_select/z_select.c index 7fa97d93db..2a7aee5eec 100644 --- a/src/overlays/gamestates/ovl_select/z_select.c +++ b/src/overlays/gamestates/ovl_select/z_select.c @@ -30,7 +30,7 @@ void MapSelect_LoadGame(MapSelectState* this, s32 entranceIndex) { gSaveContext.buttonStatus[0] = gSaveContext.buttonStatus[1] = gSaveContext.buttonStatus[2] = gSaveContext.buttonStatus[3] = gSaveContext.buttonStatus[4] = BTN_ENABLED; gSaveContext.unk_13E7 = gSaveContext.unk_13E8 = gSaveContext.unk_13EA = gSaveContext.unk_13EC = 0; - Audio_QueueSeqCmd(SEQ_PLAYER_BGM_MAIN << 24 | NA_BGM_STOP); + SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 0); gSaveContext.entranceIndex = entranceIndex; gSaveContext.respawnFlag = 0; gSaveContext.respawn[RESPAWN_MODE_DOWN].entranceIndex = ENTR_LOAD_OPENING; diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index 2fbad6a1f9..cfdb53cf85 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -313,7 +313,7 @@ void KaleidoScope_MoveCursorToSpecialPos(PlayState* play, u16 specialPos) { PauseContext* pauseCtx = &play->pauseCtx; pauseCtx->cursorSpecialPos = specialPos; - pauseCtx->pageSwitchTimer = 0; + pauseCtx->pageSwitchInputTimer = 0; Audio_PlaySfxGeneral(NA_SE_SY_DECIDE, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); @@ -409,21 +409,21 @@ void KaleidoScope_HandlePageToggles(PauseContext* pauseCtx, Input* input) { if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) { if (pauseCtx->stickAdjX < -30) { - pauseCtx->pageSwitchTimer++; - if ((pauseCtx->pageSwitchTimer >= 10) || (pauseCtx->pageSwitchTimer == 0)) { + pauseCtx->pageSwitchInputTimer++; + if ((pauseCtx->pageSwitchInputTimer >= 10) || (pauseCtx->pageSwitchInputTimer == 0)) { KaleidoScope_SwitchPage(pauseCtx, 0); } } else { - pauseCtx->pageSwitchTimer = -1; + pauseCtx->pageSwitchInputTimer = -1; } } else if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_RIGHT) { if (pauseCtx->stickAdjX > 30) { - pauseCtx->pageSwitchTimer++; - if ((pauseCtx->pageSwitchTimer >= 10) || (pauseCtx->pageSwitchTimer == 0)) { + pauseCtx->pageSwitchInputTimer++; + if ((pauseCtx->pageSwitchInputTimer >= 10) || (pauseCtx->pageSwitchInputTimer == 0)) { KaleidoScope_SwitchPage(pauseCtx, 2); } } else { - pauseCtx->pageSwitchTimer = -1; + pauseCtx->pageSwitchInputTimer = -1; } } } @@ -508,10 +508,10 @@ void KaleidoScope_DrawPages(PlayState* play, GraphicsContext* gfxCtx) { }; static s16 D_8082AD3C = 20; static s16 D_8082AD40 = 0; - static s16 D_8082AD44 = 0; - static s16 D_8082AD48 = 0; - static s16 D_8082AD4C = 0; - static s16 D_8082AD50 = 0; + static s16 sStickXRepeatTimer = 0; + static s16 sStickYRepeatTimer = 0; + static s16 sStickXRepeatState = 0; + static s16 sStickYRepeatState = 0; PauseContext* pauseCtx = &play->pauseCtx; s16 stepR; s16 stepG; @@ -553,55 +553,59 @@ void KaleidoScope_DrawPages(PlayState* play, GraphicsContext* gfxCtx) { } if (pauseCtx->stickAdjX < -30) { - if (D_8082AD4C == -1) { - if (--D_8082AD44 < 0) { - D_8082AD44 = XREG(6); + if (sStickXRepeatState == -1) { + sStickXRepeatTimer--; + if (sStickXRepeatTimer < 0) { + sStickXRepeatTimer = R_PAUSE_STICK_REPEAT_DELAY; } else { pauseCtx->stickAdjX = 0; } } else { - D_8082AD44 = XREG(8); - D_8082AD4C = -1; + sStickXRepeatTimer = R_PAUSE_STICK_REPEAT_DELAY_FIRST; + sStickXRepeatState = -1; } } else if (pauseCtx->stickAdjX > 30) { - if (D_8082AD4C == 1) { - if (--D_8082AD44 < 0) { - D_8082AD44 = XREG(6); + if (sStickXRepeatState == 1) { + sStickXRepeatTimer--; + if (sStickXRepeatTimer < 0) { + sStickXRepeatTimer = R_PAUSE_STICK_REPEAT_DELAY; } else { pauseCtx->stickAdjX = 0; } } else { - D_8082AD44 = XREG(8); - D_8082AD4C = 1; + sStickXRepeatTimer = R_PAUSE_STICK_REPEAT_DELAY_FIRST; + sStickXRepeatState = 1; } } else { - D_8082AD4C = 0; + sStickXRepeatState = 0; } if (pauseCtx->stickAdjY < -30) { - if (D_8082AD50 == -1) { - if (--D_8082AD48 < 0) { - D_8082AD48 = XREG(6); + if (sStickYRepeatState == -1) { + sStickYRepeatTimer--; + if (sStickYRepeatTimer < 0) { + sStickYRepeatTimer = R_PAUSE_STICK_REPEAT_DELAY; } else { pauseCtx->stickAdjY = 0; } } else { - D_8082AD48 = XREG(8); - D_8082AD50 = -1; + sStickYRepeatTimer = R_PAUSE_STICK_REPEAT_DELAY_FIRST; + sStickYRepeatState = -1; } } else if (pauseCtx->stickAdjY > 30) { - if (D_8082AD50 == 1) { - if (--D_8082AD48 < 0) { - D_8082AD48 = XREG(6); + if (sStickYRepeatState == 1) { + sStickYRepeatTimer--; + if (sStickYRepeatTimer < 0) { + sStickYRepeatTimer = R_PAUSE_STICK_REPEAT_DELAY; } else { pauseCtx->stickAdjY = 0; } } else { - D_8082AD48 = XREG(8); - D_8082AD50 = 1; + sStickYRepeatTimer = R_PAUSE_STICK_REPEAT_DELAY_FIRST; + sStickYRepeatState = 1; } } else { - D_8082AD50 = 0; + sStickYRepeatState = 0; } } @@ -3406,7 +3410,7 @@ void KaleidoScope_Update(PlayState* play) { gSaveContext.respawnFlag = -2; gSaveContext.nextTransitionType = TRANS_TYPE_FADE_BLACK; gSaveContext.health = 0x30; - Audio_QueueSeqCmd(0xF << 28 | SEQ_PLAYER_BGM_MAIN << 24 | 0xA); + SEQCMD_RESET_AUDIO_HEAP(0, 10); gSaveContext.healthAccumulator = 0; gSaveContext.magicState = MAGIC_STATE_IDLE; gSaveContext.prevMagicState = MAGIC_STATE_IDLE;