diff --git a/include/functions.h b/include/functions.h index 481da6a853..08ce84c8cd 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1882,9 +1882,9 @@ void func_800F5C2C(void); 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); diff --git a/src/code/code_800EC960.c b/src/code/code_800EC960.c index 0ccb800840..7c649b6e33 100644 --- a/src/code/code_800EC960.c +++ b/src/code/code_800EC960.c @@ -1237,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; @@ -1266,8 +1266,8 @@ 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); @@ -3058,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); @@ -4919,56 +4919,69 @@ void Audio_SetBgmEnemyVolume(f32 dist) { 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)(Audio_GetActiveSeqId(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 - SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_MAIN, 0, 3, 127 - phi_v1); - SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_MAIN, 1, 3, 127 - phi_v1); - SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_MAIN, 13, 3, phi_v1); - if (D_8016B9D8 == 0) { - D_8016B9D8++; - } - } - } else if ((temp_a0 == NA_BGM_NATURE_AMBIENCE) && ((arg1 & 0xFF) == NA_BGM_LONLON)) { - temp_a0 = (s8)(Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB) & 0xFF); - if ((temp_a0 != (arg1 & 0xFF)) && (D_8016B9D8 < 10)) { - Audio_PlaySequenceWithSeqPlayerIO(SEQ_PLAYER_BGM_SUB, NA_BGM_LONLON, 0, 0, 0); - SEQCMD_SET_CHANNEL_DISABLE_MASK(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 - SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_SUB, 0, 3, 127 - phi_v1); - SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_SUB, 1, 3, 127 - phi_v1); + + // 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++; } } @@ -4985,35 +4998,55 @@ void func_800F64E0(u8 arg0) { } } -void func_800F6584(u8 arg0) { +/** + * Enable or disable Malon's singing + * + * @param malonSingingDisabled true to disable, false to enable + */ +void Audio_ToggleMalonSinging(u8 malonSingingDisabled) { u8 seqPlayerIndex; - u16 sp34; + u16 channelMaskDisable; + + sMalonSingingDisabled = malonSingingDisabled; - D_8016B9F2 = arg0; 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; - sp34 = 0; - } else if ((Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB) & 0xFF) == NA_BGM_LONLON) { + // 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; - sp34 = 0xFFFC; + // 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) { + 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) { - SEQCMD_SET_CHANNEL_DISABLE_MASK(seqPlayerIndex, sp34 | 3); + // When singing along with ambience, disable all 16 channels + SEQCMD_SET_CHANNEL_DISABLE_MASK(seqPlayerIndex, channelMaskDisable | 3); } } else { 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); } + + // 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) { - SEQCMD_SET_CHANNEL_DISABLE_MASK(seqPlayerIndex, sp34); + // When singing along with ambience, disable channels 2-15 + SEQCMD_SET_CHANNEL_DISABLE_MASK(seqPlayerIndex, channelMaskDisable); } } } @@ -5184,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; @@ -5192,7 +5225,7 @@ void func_800F6C34(void) { sSariaBgmPtr = NULL; D_8016B9F4 = 0; D_8016B9F3 = 1; - D_8016B9F2 = 0; + sMalonSingingDisabled = false; } void Audio_SetNatureAmbienceChannelIO(u8 channelIdxRange, u8 ioPort, u8 ioData) { @@ -5209,7 +5242,7 @@ void Audio_SetNatureAmbienceChannelIO(u8 channelIdxRange, u8 ioPort, u8 ioData) // channelIdxRange = 01 on ioPort 1 if (((channelIdxRange << 8) + ioPort) == ((NATURE_CHANNEL_CRITTER_0 << 8) + CHANNEL_IO_PORT_1)) { if (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB) != NA_BGM_LONLON) { - D_8016B9D8 = 0; + sMalonSingingTimer = 0; } } 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;