summaryrefslogtreecommitdiff
path: root/soh/src/code/code_800EC960.c
diff options
context:
space:
mode:
Diffstat (limited to 'soh/src/code/code_800EC960.c')
-rw-r--r--soh/src/code/code_800EC960.c1765
1 files changed, 992 insertions, 773 deletions
diff --git a/soh/src/code/code_800EC960.c b/soh/src/code/code_800EC960.c
index 20cd7127d..59a30e379 100644
--- a/soh/src/code/code_800EC960.c
+++ b/soh/src/code/code_800EC960.c
@@ -37,7 +37,7 @@ typedef struct {
/* 0x0 */ f32 vol;
/* 0x4 */ f32 freqScale;
/* 0x8 */ s8 reverb;
- /* 0x9 */ s8 panSigned;
+ /* 0x9 */ s8 pan;
/* 0xA */ s8 stereoBits;
/* 0xB */ u8 filter;
/* 0xC */ u8 unk_0C;
@@ -92,7 +92,12 @@ typedef enum {
#define SCROLL_PRINT_BUF_SIZE 25
-#define SFX_PLAYER_CHANNEL_OCARINA 13
+typedef struct {
+ s8 x;
+ s8 y;
+} OcarinaStick;
+
+#define SFX_CHANNEL_OCARINA 13
u8 gIsLargeSoundBank[7] = { 0, 0, 0, 1, 0, 0, 0 };
@@ -119,11 +124,11 @@ f32 sBehindScreenZ[2] = { -15.0f, -65.0f };
u8 sAudioIncreasingTranspose = 0;
u8 gMorphaTransposeTable[16] = { 0, 0, 0, 1, 1, 2, 4, 6, 8, 8, 8, 8, 8, 8, 8, 8 };
u8 sPrevChargeLevel = 0;
-f32 D_801305E4[4] = { 1.0f, 1.12246f, 1.33484f, 1.33484f }; // 2**({0, 2, 5, 5}/12)
-f32 D_801305F4 = 1.0f;
-u8 D_801305F8[8] = { 127, 80, 75, 73, 70, 68, 65, 60 };
-u8 D_80130600 = 0;
-s8 D_80130604 = 2;
+f32 sSfxSwordChargeFreqLevels[4] = { 1.0f, 1.12246f, 1.33484f, 1.33484f }; // 2**({0, 2, 5, 5}/12)
+f32 sSfxSwordChargeFreq = 1.0f;
+u8 sGanonsTowerLevelsVol[8] = { 127, 80, 75, 73, 70, 68, 65, 60 };
+u8 sEnterGanonsTowerTimer = 0;
+s8 sSoundOutputMode = 2;
s8 D_80130608 = 0;
s8 sAudioCutsceneFlag = 0;
s8 sSpecReverb = 0;
@@ -133,8 +138,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;
@@ -143,7 +151,36 @@ u8 sAudioBaseFilter2 = 0;
u8 sAudioExtraFilter2 = 0;
Vec3f* sSariaBgmPtr = NULL;
f32 D_80130650 = 2000.0f;
-u8 sSeqModeInput = 0;
+u8 sSeqModeInput = 0; // decomp: debug only
+
+#define SEQ_FLAG_ENEMY (1 << 0) // Allows enemy bgm
+#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
+
+/**
+ * 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[0x6F] = {
0x2, // NA_BGM_GENERAL_SFX
0x1, // NA_BGM_NATURE_BACKGROUND
@@ -843,357 +880,380 @@ NatureAmbienceDataIO sNatureAmbienceDataIO[20] = {
},
};
-u32 sOcarinaAllowedBtnMask = (BTN_A | BTN_CUP | BTN_CDOWN | BTN_CLEFT | BTN_CRIGHT);
+u32 sOcarinaAllowedButtonMask = (BTN_A | BTN_CUP | BTN_CDOWN | BTN_CLEFT | BTN_CRIGHT);
s32 sOcarinaD5BtnMap = BTN_CUP;
s32 sOcarinaB4BtnMap = BTN_CLEFT;
s32 sOcarinaA4BtnMap = BTN_CRIGHT;
s32 sOcarinaF4BtnMap = BTN_CDOWN;
s32 sOcarinaD4BtnMap = BTN_A;
-static u8 sIsOcarinaInputEnabled = 0;
-static s8 sOcarinaInstrumentId = 0; // "OCA", ocarina active?
-static u8 sCurOcarinaPitch = 0xFF;
-static u8 sPrevOcarinaPitch = 0;
-static u8 sCurOcarinaButtonIndex = 0; // note index?
-static u8 sMusicStaffPrevPitch = 0;
+static u8 sIsOcarinaInputEnabled = false;
+static s8 sOcarinaInstrumentId = OCARINA_INSTRUMENT_OFF;
+static u8 sCurOcarinaPitch = OCARINA_PITCH_NONE;
+static u8 sPrevOcarinaPitch = OCARINA_PITCH_C4;
+static u8 sCurOcarinaButtonIndex = OCARINA_BTN_A;
+static u8 sMusicStaffPrevPitch = OCARINA_PITCH_C4;
static f32 sCurOcarinaBendFreq = 1.0f;
f32 sRelativeOcarinaVolume = 87.0f / 127.0f;
-static s8 sCurOcarinaBendIndex = 0; // pitch?
-static s8 sCurOcarinaVolume = 0x57;
+static s8 sCurOcarinaBendIndex = 0;
+static s8 sCurOcarinaVolume = 87;
static s8 sCurOcarinaVibrato = 0;
-static u8 sPlaybackState = 0; // 80130F38
-static u32 sOcarinaFlags = 0; // "SEQ"
+static u8 sPlaybackState = 0;
+static u32 sOcarinaFlags = 0;
static u32 sPlaybackNoteTimer = 0;
static u16 sPlaybackNotePos = 0;
static u16 sPlaybackStaffPos = 0;
-u16 D_80130F4C = 0;
-static u8 sPlaybackPitch = 0xFF; // Note to display on screen?
+u16 sPrevOcarinaWithMusicStaffFlags = 0;
+static u8 sPlaybackPitch = OCARINA_PITCH_NONE; // Pitch + PitchFlags
u8 sNotePlaybackVolume = 0;
u8 sNotePlaybackVibrato = 0;
-s8 sNotePlaybackTone = 0;
-f32 sNormalizedNotePlaybackTone = 1.0f;
-f32 sNormalizedNotePlaybackVolume = 1.0f;
-s32 D_80130F68 = 0;
-u8 sOcarinaNoteValues[5] = { 2, 5, 9, 11, 14 };
-u8 sOcaMinigameAppendPos = 0;
-u8 sOcaMinigameEndPos = 0;
-u8 sOcaMinigameNoteCnts[] = { 5, 6, 8 };
-
-OcarinaNote sOcarinaSongs[OCARINA_SONG_MAX][20] = {
- // Minuet
+s8 sNotePlaybackBend = 0;
+f32 sRelativeNotePlaybackBend = 1.0f;
+f32 sRelativeNotePlaybackVolume = 1.0f;
+s32 sOcarinaPlaybackTaskStart = 0;
+
+u8 sButtonToPitchMap[5] = {
+ OCARINA_PITCH_D4, // OCARINA_BTN_A
+ OCARINA_PITCH_F4, // OCARINA_BTN_C_DOWN
+ OCARINA_PITCH_A4, // OCARINA_BTN_C_RIGHT
+ OCARINA_PITCH_B4, // OCARINA_BTN_C_LEFT
+ OCARINA_PITCH_D5, // OCARINA_BTN_C_UP
+};
+
+u8 sOcaMemoryGameAppendPos = 0;
+u8 sOcaMemoryGameEndPos = 0;
+u8 sOcaMemoryGameNumNotes[] = { 5, 6, 8 };
+
+OcarinaNote sOcarinaSongNotes[OCARINA_SONG_MAX][20] = {
+ // OCARINA_SONG_MINUET
{
- { 2, 0, 18, 86, 0, 0, 0 },
- { 14, 0, 18, 92, 0, 0, 0 },
- { 11, 0, 72, 86, 0, 0, 0 },
- { 9, 0, 18, 80, 0, 0, 0 },
- { 11, 0, 18, 88, 0, 0, 0 },
- { 9, 0, 144, 86, 0, 0, 0 },
- { 0xFF, 0, 0, 86, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 18, 86, 0, 0, 0 },
+ { OCARINA_PITCH_D5, 18, 92, 0, 0, 0 },
+ { OCARINA_PITCH_B4, 72, 86, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 18, 80, 0, 0, 0 },
+ { OCARINA_PITCH_B4, 18, 88, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 144, 86, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 86, 0, 0, 0 },
},
- // Bolero
+ // OCARINA_SONG_BOLERO
{
- { 5, 0, 15, 80, 0, 0, 0 },
- { 2, 0, 15, 72, 0, 0, 0 },
- { 5, 0, 15, 84, 0, 0, 0 },
- { 2, 0, 15, 76, 0, 0, 0 },
- { 9, 0, 15, 84, 0, 0, 0 },
- { 5, 0, 15, 74, 0, 0, 0 },
- { 9, 0, 15, 78, 0, 0, 0 },
- { 5, 0, 135, 66, 0, 0, 0 },
- { 0xFF, 0, 0, 66, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 15, 80, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 15, 72, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 15, 84, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 15, 76, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 15, 84, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 15, 74, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 15, 78, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 135, 66, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 66, 0, 0, 0 },
},
- // Serenade
+ // OCARINA_SONG_SERENADE
{
- { 2, 0, 36, 60, 0, 0, 0 },
- { 5, 0, 36, 78, 0, 0, 0 },
- { 9, 0, 33, 82, 0, 0, 0 },
- { 0xFF, 0, 3, 82, 0, 0, 0 },
- { 9, 0, 36, 84, 0, 0, 0 },
- { 11, 0, 144, 90, 0, 0, 0 },
- { 0xFF, 0, 0, 90, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 36, 60, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 36, 78, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 33, 82, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 3, 82, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 36, 84, 0, 0, 0 },
+ { OCARINA_PITCH_B4, 144, 90, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 90, 0, 0, 0 },
},
- // Requiem
+ // OCARINA_SONG_REQUIEM
{
- { 2, 0, 45, 88, 0, 0, 0 },
- { 5, 0, 23, 86, 0, 0, 0 },
- { 2, 0, 22, 84, 0, 0, 0 },
- { 9, 0, 45, 86, 0, 0, 0 },
- { 5, 0, 45, 94, 0, 0, 0 },
- { 2, 0, 180, 94, 0, 0, 0 },
- { 0xFF, 0, 0, 94, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 45, 88, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 23, 86, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 22, 84, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 45, 86, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 45, 94, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 180, 94, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 94, 0, 0, 0 },
},
- // Nocturne
+ // OCARINA_SONG_NOCTURNE
{
- { 11, 0, 36, 88, 0, 0, 0 },
- { 9, 0, 33, 84, 0, 0, 0 },
- { 0xFF, 0, 3, 84, 0, 0, 0 },
- { 9, 0, 18, 82, 0, 0, 0 },
- { 2, 0, 18, 60, 0, 0, 0 },
- { 11, 0, 18, 90, 0, 0, 0 },
- { 9, 0, 18, 88, 0, 0, 0 },
- { 5, 0, 144, 96, 0, 0, 0 },
- { 0xFF, 0, 0, 96, 0, 0, 0 },
+ { OCARINA_PITCH_B4, 36, 88, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 33, 84, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 3, 84, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 18, 82, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 18, 60, 0, 0, 0 },
+ { OCARINA_PITCH_B4, 18, 90, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 18, 88, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 144, 96, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 96, 0, 0, 0 },
},
- // Prelude
+ // OCARINA_SONG_PRELUDE
{
- { 14, 0, 15, 84, 0, 0, 0 },
- { 9, 0, 45, 88, 0, 0, 0 },
- { 14, 0, 15, 88, 0, 0, 0 },
- { 9, 0, 15, 82, 0, 0, 0 },
- { 11, 0, 15, 86, 0, 0, 0 },
- { 14, 0, 60, 90, 0, 0, 0 },
- { 0xFF, 0, 75, 90, 0, 0, 0 },
- { 0xFF, 0, 0, 90, 0, 0, 0 },
+ { OCARINA_PITCH_D5, 15, 84, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 45, 88, 0, 0, 0 },
+ { OCARINA_PITCH_D5, 15, 88, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 15, 82, 0, 0, 0 },
+ { OCARINA_PITCH_B4, 15, 86, 0, 0, 0 },
+ { OCARINA_PITCH_D5, 60, 90, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 75, 90, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 90, 0, 0, 0 },
},
- // Sarias
+ // OCARINA_SONG_SARIAS
{
- { 5, 0, 17, 84, 0, 0, 0 },
- { 9, 0, 17, 88, 0, 0, 0 },
- { 11, 0, 34, 80, 0, 0, 0 },
- { 5, 0, 17, 84, 0, 0, 0 },
- { 9, 0, 17, 88, 0, 0, 0 },
- { 11, 0, 136, 80, 0, 0, 0 },
- { 0xFF, 0, 0, 90, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 17, 84, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 17, 88, 0, 0, 0 },
+ { OCARINA_PITCH_B4, 34, 80, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 17, 84, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 17, 88, 0, 0, 0 },
+ { OCARINA_PITCH_B4, 136, 80, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 90, 0, 0, 0 },
},
- // Epona
+ // OCARINA_SONG_EPONAS
{
- { 14, 0, 18, 84, 0, 0, 0 },
- { 11, 0, 18, 88, 0, 0, 0 },
- { 9, 0, 72, 80, 0, 0, 0 },
- { 14, 0, 18, 84, 0, 0, 0 },
- { 11, 0, 18, 88, 0, 0, 0 },
- { 9, 0, 144, 80, 0, 0, 0 },
- { 0xFF, 0, 0, 90, 0, 0, 0 },
+ { OCARINA_PITCH_D5, 18, 84, 0, 0, 0 },
+ { OCARINA_PITCH_B4, 18, 88, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 72, 80, 0, 0, 0 },
+ { OCARINA_PITCH_D5, 18, 84, 0, 0, 0 },
+ { OCARINA_PITCH_B4, 18, 88, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 144, 80, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 90, 0, 0, 0 },
},
- // Lullaby
+ // OCARINA_SONG_LULLABY
{
- { 11, 0, 51, 84, 0, 0, 0 },
- { 14, 0, 25, 88, 0, 0, 0 },
- { 9, 0, 78, 80, 0, 0, 0 },
- { 11, 0, 51, 84, 0, 0, 0 },
- { 14, 0, 25, 88, 0, 0, 0 },
- { 9, 0, 100, 80, 0, 0, 0 },
- { 0xFF, 0, 0, 90, 0, 0, 0 },
+ { OCARINA_PITCH_B4, 51, 84, 0, 0, 0 },
+ { OCARINA_PITCH_D5, 25, 88, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 78, 80, 0, 0, 0 },
+ { OCARINA_PITCH_B4, 51, 84, 0, 0, 0 },
+ { OCARINA_PITCH_D5, 25, 88, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 100, 80, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 90, 0, 0, 0 },
},
- // Suns
+ // OCARINA_SONG_SUNS
{
- { 9, 0, 12, 84, 0, 0, 0 },
- { 5, 0, 13, 88, 0, 0, 0 },
- { 14, 0, 29, 80, 2, 0, 0 },
- { 0xFF, 0, 9, 84, 0, 0, 0 },
- { 9, 0, 12, 84, 0, 0, 0 },
- { 5, 0, 13, 88, 0, 0, 0 },
- { 14, 0, 120, 80, 3, 0, 0 },
- { 0xFF, 0, 0, 90, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 12, 84, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 13, 88, 0, 0, 0 },
+ { OCARINA_PITCH_D5, 29, 80, 2, 0, 0 },
+ { OCARINA_PITCH_NONE, 9, 84, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 12, 84, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 13, 88, 0, 0, 0 },
+ { OCARINA_PITCH_D5, 120, 80, 3, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 90, 0, 0, 0 },
},
- // Song of Time
+ // OCARINA_SONG_TIME
{
- { 9, 0, 32, 84, 0, 0, 0 },
- { 2, 0, 65, 88, 0, 0, 0 },
- { 5, 0, 33, 80, 0, 0, 0 },
- { 9, 0, 32, 84, 0, 0, 0 },
- { 2, 0, 65, 88, 0, 0, 0 },
- { 5, 0, 99, 80, 0, 0, 0 },
- { 0xFF, 0, 0, 90, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 32, 84, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 65, 88, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 33, 80, 0, 0, 0 },
+ { OCARINA_PITCH_A4, 32, 84, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 65, 88, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 99, 80, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 90, 0, 0, 0 },
},
- // Storms
+ // OCARINA_SONG_STORMS
{
- { 2, 0, 11, 84, 0, 0, 0 },
- { 5, 0, 11, 88, 0, 0, 0 },
- { 14, 0, 45, 80, 0, 0, 0 },
- { 2, 0, 11, 84, 0, 0, 0 },
- { 5, 0, 11, 88, 0, 0, 0 },
- { 14, 0, 90, 80, 0, 0, 0 },
- { 0xFF, 0, 0, 90, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 11, 84, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 11, 88, 0, 0, 0 },
+ { OCARINA_PITCH_D5, 45, 80, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 11, 84, 0, 0, 0 },
+ { OCARINA_PITCH_F4, 11, 88, 0, 0, 0 },
+ { OCARINA_PITCH_D5, 90, 80, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 90, 0, 0, 0 },
},
- // Scarecrow
+ // OCARINA_SONG_SCARECROW_SPAWN
{
- { 2, 0, 3, 0, 0, 0, 0 },
- { 0xFF, 0, 0, 255, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 3, 0, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 255, 0, 0, 0 },
},
- // Lost Woods Memory Game
+ // OCARINA_SONG_MEMORY_GAME
{
- { 2, 0, 3, 0, 0, 0, 0 },
- { 0xFF, 0, 0, 0, 0, 0, 0 },
+ { OCARINA_PITCH_D4, 3, 0, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 0, 0, 0, 0 },
},
};
-OcarinaNote* sPlaybackSong = sOcarinaSongs[0];
+OcarinaNote* sPlaybackSong = sOcarinaSongNotes[0];
u8 sFrogsSongNotes[14] = {
- OCARINA_NOTE_D4, OCARINA_NOTE_B4, OCARINA_NOTE_A4, OCARINA_NOTE_F4, OCARINA_NOTE_B4,
- OCARINA_NOTE_A4, OCARINA_NOTE_F4, OCARINA_NOTE_D4, OCARINA_NOTE_F4, OCARINA_NOTE_D4,
- OCARINA_NOTE_F4, OCARINA_NOTE_A4, OCARINA_NOTE_B4, OCARINA_NOTE_D4,
+ OCARINA_BTN_A, OCARINA_BTN_C_LEFT, OCARINA_BTN_C_RIGHT, OCARINA_BTN_C_DOWN, OCARINA_BTN_C_LEFT,
+ OCARINA_BTN_C_RIGHT, OCARINA_BTN_C_DOWN, OCARINA_BTN_A, OCARINA_BTN_C_DOWN, OCARINA_BTN_A,
+ OCARINA_BTN_C_DOWN, OCARINA_BTN_C_RIGHT, OCARINA_BTN_C_LEFT, OCARINA_BTN_A,
};
u8* gFrogsSongPtr = sFrogsSongNotes;
-u8 sRecordingState = 0;
+u8 sRecordingState = OCARINA_RECORD_OFF;
u8 sRecordSongPos = 0;
-u32 D_80131860 = 0;
-u8 D_80131864 = 0;
-u8 D_80131868 = 0;
-u8 D_8013186C = 0;
-s8 D_80131870 = 0;
-u8 D_80131874 = 0;
-u8 D_80131878 = 0;
-u8 D_8013187C = 0;
+u32 sOcarinaRecordTaskStart = 0;
+u8 sRecordOcarinaPitch = 0;
+u8 sRecordOcarinaVolume = 0;
+u8 sRecordOcarinaVibrato = 0;
+s8 sRecordOcarinaBendIndex = 0;
+u8 sRecordOcarinaButtonIndex = 0;
+u8 sPlayedOcarinaSongIndexPlusOne = 0;
+u8 sMusicStaffNumNotesPerTest = 0;
u8 sOcarinaDropInputTimer = 0;
-OcarinaNote sPierresSong[108] = {
- { 0xFF, 0, 0, 0, 0, 0, 0 },
- { 0xFF, 0, 0, 0, 0, 0, 0 },
+OcarinaNote sScarecrowsLongSongNotes[108] = {
+ { OCARINA_PITCH_NONE, 0, 0, 0, 0, 0 },
+ { OCARINA_PITCH_NONE, 0, 0, 0, 0, 0 },
+};
+OcarinaNote* gScarecrowLongSongPtr = sScarecrowsLongSongNotes;
+
+u8* gScarecrowSpawnSongPtr = (u8*)&sOcarinaSongNotes[OCARINA_SONG_SCARECROW_SPAWN];
+OcarinaNote* sMemoryGameSongPtr = sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME];
+
+u8 sPitchToButtonMap[16] = {
+ OCARINA_BTN_A, // OCARINA_PITCH_C4
+ OCARINA_BTN_A, // OCARINA_PITCH_DFLAT4
+ OCARINA_BTN_A, // OCARINA_PITCH_D4
+ OCARINA_BTN_A, // OCARINA_PITCH_EFLAT4
+ OCARINA_BTN_C_DOWN, // OCARINA_PITCH_E4
+ OCARINA_BTN_C_DOWN, // OCARINA_PITCH_F4
+ OCARINA_BTN_C_DOWN, // OCARINA_PITCH_GFLAT4
+ OCARINA_BTN_C_RIGHT, // OCARINA_PITCH_G4
+ OCARINA_BTN_C_RIGHT, // OCARINA_PITCH_AFLAT4
+ OCARINA_BTN_C_RIGHT, // OCARINA_PITCH_A4
+ OCARINA_BTN_C_RIGHT_OR_C_LEFT, // OCARINA_PITCH_BFLAT4: Interface/Overlap between C_RIGHT and C_LEFT
+ OCARINA_BTN_C_LEFT, // OCARINA_PITCH_B4
+ OCARINA_BTN_C_LEFT, // OCARINA_PITCH_C5
+ OCARINA_BTN_C_UP, // OCARINA_PITCH_DFLAT5
+ OCARINA_BTN_C_UP, // OCARINA_PITCH_D5
+ OCARINA_BTN_C_UP, // OCARINA_PITCH_EFLAT5
};
-OcarinaNote* gScarecrowCustomSongPtr = sPierresSong;
-
-u8* gScarecrowSpawnSongPtr = (u8*)&sOcarinaSongs[OCARINA_SONG_SCARECROW];
-OcarinaNote* D_80131BEC = sOcarinaSongs[OCARINA_SONG_MEMORY_GAME];
-u8 sNoteValueIndexMap[16] = { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 5, 3, 3, 4, 4, 4 };
-OcarinaSongInfo gOcarinaSongNotes[OCARINA_SONG_MAX] = {
- // Minuet
+OcarinaSongButtons gOcarinaSongButtons[OCARINA_SONG_MAX] = {
+ // OCARINA_SONG_MINUET
{ 6,
{
- OCARINA_NOTE_D4,
- OCARINA_NOTE_D5,
- OCARINA_NOTE_B4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_B4,
- OCARINA_NOTE_A4,
+ OCARINA_BTN_A,
+ OCARINA_BTN_C_UP,
+ OCARINA_BTN_C_LEFT,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_LEFT,
+ OCARINA_BTN_C_RIGHT,
} },
- // Bolero
+ // OCARINA_SONG_BOLERO
{ 8,
{
- OCARINA_NOTE_F4,
- OCARINA_NOTE_D4,
- OCARINA_NOTE_F4,
- OCARINA_NOTE_D4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_F4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_F4,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_A,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_A,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_DOWN,
} },
- // Serenade
+ // OCARINA_SONG_SERENADE
{ 5,
{
- OCARINA_NOTE_D4,
- OCARINA_NOTE_F4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_B4,
+ OCARINA_BTN_A,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_LEFT,
} },
- // Requiem
+ // OCARINA_SONG_REQUIEM
{ 6,
{
- OCARINA_NOTE_D4,
- OCARINA_NOTE_F4,
- OCARINA_NOTE_D4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_F4,
- OCARINA_NOTE_D4,
+ OCARINA_BTN_A,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_A,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_A,
} },
- // Nocturne
+ // OCARINA_SONG_NOCTURNE
{ 7,
{
- OCARINA_NOTE_B4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_D4,
- OCARINA_NOTE_B4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_F4,
+ OCARINA_BTN_C_LEFT,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_A,
+ OCARINA_BTN_C_LEFT,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_DOWN,
} },
- // Prelude
+ // OCARINA_SONG_PRELUDE
{ 6,
{
- OCARINA_NOTE_D5,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_D5,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_B4,
- OCARINA_NOTE_D5,
+ OCARINA_BTN_C_UP,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_UP,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_LEFT,
+ OCARINA_BTN_C_UP,
} },
- // Sarias
+ // OCARINA_SONG_SARIAS
{ 6,
{
- OCARINA_NOTE_F4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_B4,
- OCARINA_NOTE_F4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_B4,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_LEFT,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_LEFT,
} },
- // Epona
+ // OCARINA_SONG_EPONAS
{ 6,
{
- OCARINA_NOTE_D5,
- OCARINA_NOTE_B4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_D5,
- OCARINA_NOTE_B4,
- OCARINA_NOTE_A4,
+ OCARINA_BTN_C_UP,
+ OCARINA_BTN_C_LEFT,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_UP,
+ OCARINA_BTN_C_LEFT,
+ OCARINA_BTN_C_RIGHT,
} },
- // Lullaby
+ // OCARINA_SONG_LULLABY
{ 6,
{
- OCARINA_NOTE_B4,
- OCARINA_NOTE_D5,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_B4,
- OCARINA_NOTE_D5,
- OCARINA_NOTE_A4,
+ OCARINA_BTN_C_LEFT,
+ OCARINA_BTN_C_UP,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_LEFT,
+ OCARINA_BTN_C_UP,
+ OCARINA_BTN_C_RIGHT,
} },
- // Suns
+ // OCARINA_SONG_SUNS
{ 6,
{
- OCARINA_NOTE_A4,
- OCARINA_NOTE_F4,
- OCARINA_NOTE_D5,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_F4,
- OCARINA_NOTE_D5,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_C_UP,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_C_UP,
} },
- // Song of Time
+ // OCARINA_SONG_TIME
{ 6,
{
- OCARINA_NOTE_A4,
- OCARINA_NOTE_D4,
- OCARINA_NOTE_F4,
- OCARINA_NOTE_A4,
- OCARINA_NOTE_D4,
- OCARINA_NOTE_F4,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_A,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_C_RIGHT,
+ OCARINA_BTN_A,
+ OCARINA_BTN_C_DOWN,
} },
- // Storms
+ // OCARINA_SONG_STORMS
{ 6,
{
- OCARINA_NOTE_D4,
- OCARINA_NOTE_F4,
- OCARINA_NOTE_D5,
- OCARINA_NOTE_D4,
- OCARINA_NOTE_F4,
- OCARINA_NOTE_D5,
+ OCARINA_BTN_A,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_C_UP,
+ OCARINA_BTN_A,
+ OCARINA_BTN_C_DOWN,
+ OCARINA_BTN_C_UP,
} },
- // Scarecrow
- { 8, { 0, 0, 0, 0, 0, 0, 0, 0 } },
- // Lost Woods Memory Game
- { 0, { 0, 0, 0, 0, 0, 0, 0, 0 } },
+ // OCARINA_SONG_SCARECROW_SPAWN
+ { 8, { 0 } },
+ // OCARINA_SONG_MEMORY_GAME
+ { 0, { 0 } },
};
// clang-format on
-/**
- * BSS
- */
-u32 sAudioUpdateStartTime; // 8016B7A0
-u32 sAudioUpdateEndTime;
+u32 sAudioUpdateStartTime; // decomp: debug only
+u32 sAudioUpdateEndTime; // decomp: debug only
f32 D_8016B7A8;
f32 D_8016B7AC;
f32 D_8016B7B0;
@@ -1203,35 +1263,31 @@ FreqLerp sWaterfallFreqScaleLerp;
f32 D_8016B7D8;
s8 D_8016B7DC;
f32 D_8016B7E0;
-u16 D_8016B7E4;
+u16 D_8016B7E4; // decomp: debug only
struct {
s8 str[5];
u16 num;
-} sAudioScrPrtBuf[SCROLL_PRINT_BUF_SIZE];
-u8 D_8016B8B0;
-u8 D_8016B8B1;
-u8 D_8016B8B2;
-u8 D_8016B8B3;
-u8 sAudioGanonDistVol;
+} sAudioScrPrtBuf[SCROLL_PRINT_BUF_SIZE]; // decomp: debug only
+u8 sRiverSoundMainBgmVol;
+u8 sRiverSoundMainBgmCurrentVol;
+u8 sRiverSoundMainBgmLower;
+u8 sRiverSoundMainBgmRestore;
+u8 sGanonsTowerVol;
SfxPlayerState sSfxChannelState[0x10];
-char sBinToStrBuf[0x20];
-u8 D_8016B9D8;
-u8 sAudioSpecPeakNumNotes[0x12];
-u8 D_8016B9F2;
+char sBinToStrBuf[0x20]; // decomp: debug only
+u8 sMalonSingingTimer;
+u8 sAudioSpecPeakNumNotes[0x12]; // decomp: debug only
+u8 sMalonSingingDisabled;
u8 D_8016B9F3;
-u8 D_8016B9F4;
-u16 D_8016B9F6;
+u8 sFanfareStartTimer;
+u16 sFanfareSeqId;
OcarinaStaff sPlayingStaff;
-OcarinaStaff sDisplayedStaff;
+OcarinaStaff sPlaybackStaff;
OcarinaStaff sRecordingStaff;
-u32 D_8016BA04;
-typedef struct {
- s8 x;
- s8 y;
-} OcarinaStick;
-OcarinaStick sCurOcaStick;
+u32 sOcarinaUpdateTaskStart;
+OcarinaStick sOcarinaInputStickAdj;
static u32 sOcarinaInputButtonCur;
static u32 sOcarinaInputButtonStart;
static u32 sOcarinaInputButtonPrev;
@@ -1244,13 +1300,18 @@ static u8 sFirstOcarinaSongIndex;
static u8 sLastOcarinaSongIndex;
static u16 sAvailOcarinaSongFlags;
static u8 sStaffOcarinaPlayingPos;
-static u16 sMusicStaffPos[0x10];
-static u16 sMusicStaffCurHeldLength[0x10];
-static u16 sMusicStaffExpectedLength[0x10];
-static u8 sMusicStaffExpectedPitch[0x10];
+static u16 sMusicStaffPos[OCARINA_SONG_MAX];
+static u16 sMusicStaffCurHeldLength[OCARINA_SONG_MAX];
+static u16 sMusicStaffExpectedLength[OCARINA_SONG_MAX];
+static u8 sMusicStaffExpectedPitch[OCARINA_SONG_MAX];
static OcarinaNote sScarecrowsLongSongSecondNote;
-static u8 sIsMalonSinging;
-static f32 sMalonSingingDist;
+static u8 sIsMalonSinging; // decomp: debug only
+static f32 sMalonSingingDist; // decomp: debug only
+u32 sDebugPadHold; // decomp: debug only
+u32 sDebugPadBtnLast; // decomp: debug only
+u32 sDebugPadPress; // decomp: debug only
+s32 sAudioUpdateTaskStart; // decomp: debug only
+s32 sAudioUpdateTaskEnd; // decomp: debug only
#define AUDIO_OCA_SHIP_SAVESTATE_FIELDS(F) \
F(sIsOcarinaInputEnabled) \
@@ -1291,23 +1352,20 @@ static f32 sMalonSingingDist;
F(sPlaybackPitch)
SHIP_SAVESTATE_DEFINE(AudioOca, AUDIO_OCA_SHIP_SAVESTATE_FIELDS)
-// Start debug bss
-u32 sDebugPadHold;
-u32 sDebugPadBtnLast;
-u32 sDebugPadPress;
-s32 sAudioUpdateTaskStart;
-s32 sAudioUpdateTaskEnd;
-
void PadMgr_RequestPadData(PadMgr* padmgr, Input* inputs, s32 mode);
void Audio_StepFreqLerp(FreqLerp* lerp);
void Audio_UpdateSceneSequenceResumePoint(void);
void Audio_PlayNatureAmbienceSequence(u8 natureAmbienceId);
-s32 Audio_SetGanonDistVol(u8 targetVol);
+s32 Audio_SetGanonsTowerBgmVolume(u8 targetVol);
+
+// =========== Audio Ocarina ===========
+
+// SoH
void Audio_PlayFanfare_Rando(GetItemEntry getItem);
-// Function originally not called, so repurposing for control mapping
-void Audio_OcaUpdateBtnMap(bool customControls) {
+// SoH: Function originally not called, so repurposing for control mapping
+void AudioOcarina_SetCustomButtonMapping(bool customControls) {
if (customControls) {
sOcarinaD5BtnMap = BTN_CUSTOM_OCARINA_NOTE_D5;
sOcarinaB4BtnMap = BTN_CUSTOM_OCARINA_NOTE_B4;
@@ -1334,21 +1392,22 @@ void Audio_OcaUpdateBtnMap(bool customControls) {
sOcarinaF4BtnMap |= BTN_CUSTOM_RSTICK_DOWN;
}
- sOcarinaAllowedBtnMask =
+ sOcarinaAllowedButtonMask =
(sOcarinaD5BtnMap | sOcarinaB4BtnMap | sOcarinaA4BtnMap | sOcarinaF4BtnMap | sOcarinaD4BtnMap);
}
-void Audio_GetOcaInput(void) {
+void AudioOcarina_ReadControllerInput(void) {
Input inputs[4];
Input* input = &inputs[0];
- u32 sp18;
+ u32 ocarinaInputButtonPrev = sOcarinaInputButtonCur;
- sp18 = sOcarinaInputButtonCur;
- PadMgr_RequestPadData(&gPadMgr, inputs, 0);
+ PadMgr_RequestPadData(&gPadMgr, inputs, false);
sOcarinaInputButtonCur = input->cur.button;
- sOcarinaInputButtonPrev = sp18;
- sCurOcaStick.x = input->rel.stick_x;
- sCurOcaStick.y = input->rel.stick_y;
+ sOcarinaInputButtonPrev = ocarinaInputButtonPrev;
+ sOcarinaInputStickAdj.x = input->rel.stick_x;
+ sOcarinaInputStickAdj.y = input->rel.stick_y;
+
+ // SoH
s8 rstick_x = input->cur.right_stick_x;
s8 rstick_y = input->cur.right_stick_y;
const s8 sensitivity = 64;
@@ -1366,218 +1425,288 @@ void Audio_GetOcaInput(void) {
}
}
-f32 Audio_OcaAdjStick(s8 inp) {
- s8 inpAdj;
- f32 ret;
-
- if (inp > 0x40) {
- inpAdj = 127;
- } else if (inp < -0x40) {
- inpAdj = -128;
- } else if (inp >= 0) {
- inpAdj = (inp * 127) / 64;
+/**
+ * Looks up the frequency to bend the pitch by.
+ * The pitch will bend up to a maximum of 2 semitones
+ * in each direction giving a total range of 4 semitones
+ */
+f32 AudioOcarina_BendPitchTwoSemitones(s8 bendIndex) {
+ s8 adjBendIndex;
+ f32 bendFreq;
+
+ if (bendIndex > 64) {
+ adjBendIndex = 127;
+ } else if (bendIndex < -64) {
+ adjBendIndex = -128;
+ } else if (bendIndex >= 0) {
+ adjBendIndex = (bendIndex * 127) / 64;
} else {
- inpAdj = (inp * 128) / 64;
+ adjBendIndex = (bendIndex * 128) / 64;
}
- ret = gBendPitchTwoSemitonesFrequencies[inpAdj + 128];
- return ret;
+
+ /**
+ * index 128 is in the middle of the table and
+ * contains the value 1.0f i.e. no bend
+ * absolute indices above 128 will bend the pitch 2 semitones upwards
+ * absolute indices below 128 will bend the pitch 2 semitones downwards
+ */
+ bendFreq = gBendPitchTwoSemitonesFrequencies[adjBendIndex + 128];
+ return bendFreq;
}
-u8 Audio_OcaGetPlayingState(void) {
- u8 ret;
+/**
+ * If an available song has been played, then return that song index
+ * If the ocarina is on, but no song has been played then return 0xFE
+ * If the ocarina is off, return 0xFF
+ */
+u8 AudioOcarina_GetPlayingState(void) {
+ u8 playedOcarinaSongIndex;
- if (D_80131878 != 0) {
- ret = D_80131878 - 1;
- D_80131878 = 0;
+ if (sPlayedOcarinaSongIndexPlusOne != 0) {
+ playedOcarinaSongIndex = sPlayedOcarinaSongIndexPlusOne - 1;
+ sPlayedOcarinaSongIndexPlusOne = 0;
} else if (sOcarinaFlags != 0) {
- ret = 0xFE;
+ playedOcarinaSongIndex = 0xFE;
} else {
- ret = 0xFF;
+ playedOcarinaSongIndex = 0xFF;
}
- return ret;
+ return playedOcarinaSongIndex;
}
-u8 Audio_OcaMapNoteValue(u8 arg0) {
- u8 temp_v1;
+u8 AudioOcarina_MapNoteToButton(u8 pitchAndBFlatFlag) {
+ u8 buttonIndex = sPitchToButtonMap[pitchAndBFlatFlag & 0x3F];
- temp_v1 = sNoteValueIndexMap[arg0 & 0x3F];
- if (temp_v1 == 5) {
- if (arg0 & 0x80) {
- return 2;
+ /**
+ * Special case for bFlat4:
+ * CRIGHT and CLEFT are the only two pitches that are 2 semitones apart
+ * which are pitches A4 and B4 respectively
+ * bFlat4 is in the middle of those two and is the only pitches that can not
+ * be resolved between the two buttons without external information.
+ * That information is stored as flags in pitch with the mask:
+ * (pitchAndBFlatFlag & 0xC0)
+ */
+ if (buttonIndex == OCARINA_BTN_C_RIGHT_OR_C_LEFT) {
+ if (pitchAndBFlatFlag & 0x80) {
+ return OCARINA_BTN_C_RIGHT;
}
- return 3;
+ return OCARINA_BTN_C_LEFT;
}
- return temp_v1;
+
+ return buttonIndex;
}
-void func_800ECB7C(u8 songIdx) {
- u8 savedSongIdx;
- u8 scarecrowSongIdx;
- u8 noteIdx;
+void AudioOcarina_MapNotesToScarecrowButtons(u8 noteSongIndex) {
+ u8 buttonSongPos = 0;
+ u8 noteSongPos = 0;
+ u8 pitch;
- savedSongIdx = 0;
- scarecrowSongIdx = 0;
- while (savedSongIdx < 8 && scarecrowSongIdx < 0x10) {
- noteIdx = sOcarinaSongs[songIdx][scarecrowSongIdx++].noteIdx;
- if (noteIdx != 0xFF) {
- gOcarinaSongNotes[OCARINA_SONG_SCARECROW].notesIdx[savedSongIdx++] = sNoteValueIndexMap[noteIdx];
+ while (buttonSongPos < 8 && noteSongPos < 16) {
+ pitch = sOcarinaSongNotes[noteSongIndex][noteSongPos++].pitch;
+
+ if (pitch != OCARINA_PITCH_NONE) {
+ gOcarinaSongButtons[OCARINA_SONG_SCARECROW_SPAWN].buttonsIndex[buttonSongPos++] = sPitchToButtonMap[pitch];
}
}
}
-// start ocarina.
-void func_800ECC04(u16 flg) {
+/**
+ * Ocarina flags:
+ * bitmask 0x3FFF:
+ * - Ocarina song id
+ * bitmask 0xC000:
+ * - 0x0000: Limits the notes to 8 notes at a time. Not playing a correct song after 8 notes will cause an ocarina
+ * error
+ * - 0x4000: (Identical to 0xC000)
+ * - 0x8000: Limits the notes to 1 note at a time. A single incorrect note will cause an ocarina error
+ * - 0xC000: Free-play, no limitations to the number of notes to play
+ * bitmask 0x7FFF0000:
+ * - ocarina action (only used to make flags != 0)
+ * bitmask 0x80000000:
+ * - unused (only used to make flags != 0)
+ *
+ * original name: Na_StartOcarinaSinglePlayCheck2
+ */
+void AudioOcarina_Start(u16 ocarinaFlags) {
u8 i;
- if ((sOcarinaSongs[OCARINA_SONG_SCARECROW][1].volume != 0xFF) && ((flg & 0xFFF) == 0xFFF)) {
- flg |= 0x1000;
+ if ((sOcarinaSongNotes[OCARINA_SONG_SCARECROW_SPAWN][1].volume != 0xFF) && ((ocarinaFlags & 0xFFF) == 0xFFF)) {
+ ocarinaFlags |= 0x1000;
}
- if ((flg == 0xCFFF) && (sOcarinaSongs[OCARINA_SONG_SCARECROW][1].volume != 0xFF)) {
- flg = 0xDFFF;
+ if ((ocarinaFlags == 0xCFFF) && (sOcarinaSongNotes[OCARINA_SONG_SCARECROW_SPAWN][1].volume != 0xFF)) {
+ ocarinaFlags = 0xDFFF;
}
- if ((flg == 0xFFF) && (sOcarinaSongs[OCARINA_SONG_SCARECROW][1].volume != 0xFF)) {
- flg = 0x1FFF;
+ if ((ocarinaFlags == 0xFFF) && (sOcarinaSongNotes[OCARINA_SONG_SCARECROW_SPAWN][1].volume != 0xFF)) {
+ ocarinaFlags = 0x1FFF;
}
- if (flg != 0xFFFF) {
- sOcarinaFlags = 0x80000000 + (u32)flg;
+ if (ocarinaFlags != 0xFFFF) {
+ sOcarinaFlags = 0x80000000 + (u32)ocarinaFlags;
sFirstOcarinaSongIndex = 0;
- sLastOcarinaSongIndex = 0xE;
- if (flg != 0xA000) {
+ sLastOcarinaSongIndex = OCARINA_SONG_MAX;
+ if (ocarinaFlags != 0xA000) {
sLastOcarinaSongIndex--;
}
- sAvailOcarinaSongFlags = flg & 0x3FFF;
- D_8013187C = 8;
- sOcarinaHasStartedSong = 0;
- D_80131878 = 0;
+ sAvailOcarinaSongFlags = ocarinaFlags & 0x3FFF;
+ sMusicStaffNumNotesPerTest = 8; // Ocarina Check
+ sOcarinaHasStartedSong = false;
+ sPlayedOcarinaSongIndexPlusOne = 0;
sStaffOcarinaPlayingPos = 0;
- sPlayingStaff.state = Audio_OcaGetPlayingState();
- sIsOcarinaInputEnabled = 1;
- D_80130F4C = 0;
- for (i = 0; i < 0xE; i++) {
+ sPlayingStaff.state = AudioOcarina_GetPlayingState();
+ sIsOcarinaInputEnabled = true;
+ sPrevOcarinaWithMusicStaffFlags = 0;
+
+ // Reset music staff song check
+ for (i = 0; i < OCARINA_SONG_MAX; i++) {
sMusicStaffPos[i] = 0;
sMusicStaffCurHeldLength[i] = 0;
sMusicStaffExpectedLength[i] = 0;
sMusicStaffExpectedPitch[i] = 0;
}
- if (flg & 0x8000) {
- D_8013187C = 0;
+ if (ocarinaFlags & 0x8000) {
+ sMusicStaffNumNotesPerTest = 0; // Ocarina Playback
}
- if (flg & 0x4000) {
+ if (ocarinaFlags & 0x4000) {
sOcarinaWithoutMusicStaffPos = 0;
}
- if (flg & 0xD000) {
- func_800ECB7C(OCARINA_SONG_SCARECROW);
+ if (ocarinaFlags & 0xD000) {
+ AudioOcarina_MapNotesToScarecrowButtons(OCARINA_SONG_SCARECROW_SPAWN);
}
} else {
sOcarinaFlags = 0;
- sIsOcarinaInputEnabled = 0;
+ sIsOcarinaInputEnabled = false;
}
}
-void func_800ECDBC(void) {
- if (sCurOcarinaPitch != 0xFF && sOcarinaHasStartedSong == 0) {
- sOcarinaHasStartedSong = 1;
- sMusicStaffPrevPitch = 0xFF;
+void AudioOcarina_CheckIfStartedSong(void) {
+ if (sCurOcarinaPitch != OCARINA_PITCH_NONE && !sOcarinaHasStartedSong) {
+ sOcarinaHasStartedSong = true;
+ sMusicStaffPrevPitch = OCARINA_PITCH_NONE;
}
}
-void func_800ECDF8(void) {
- u16 sh;
+/**
+ * Checks for ocarina songs from user input with a music staff prompt
+ * Type 1) Playback: tests note-by-note (ocarinaFlag & 0xC000 == 0x8000) eg:
+ * - learning a new song
+ * - playing the ocarina memory game
+ * Type 2) Check: tests in 8-note chunks (ocarinaFlag & 0xC000 == 0x0000) eg:
+ * - validating scarecrow spawn song as adult
+ * - ocarina prompt for zelda's lullaby, saria's song, Storms, Song of Time, etc...
+ */
+void AudioOcarina_CheckSongsWithMusicStaff(void) {
+ u16 curOcarinaSongFlag;
u16 pad;
- u8 inputChanged = 0;
+ u8 noNewValidInput = false;
u16 pad2;
- s8 sp57 = 0;
- u8 i;
- OcarinaNote* prevNote;
- OcarinaNote* note;
+ s8 staffOcarinaPlayingPosOffset = 0;
+ u8 songIndex;
+ OcarinaNote* curNote;
+ OcarinaNote* nextNote;
- func_800ECDBC();
+ AudioOcarina_CheckIfStartedSong();
if (sOcarinaHasStartedSong) {
- if ((sCurOcarinaBendIndex < 0 ? -sCurOcarinaBendIndex : sCurOcarinaBendIndex) >= 0x15) {
+ if ((sCurOcarinaBendIndex < 0 ? -sCurOcarinaBendIndex : sCurOcarinaBendIndex) > 20) {
sOcarinaFlags = 0;
return;
}
// clang-format off
- if (sPrevOcarinaPitch == sCurOcarinaPitch || sCurOcarinaPitch == 0xFF) { inputChanged = 1; }
+ if (sPrevOcarinaPitch == sCurOcarinaPitch || sCurOcarinaPitch == OCARINA_PITCH_NONE) { noNewValidInput = true; }
// clang-format on
- for (i = sFirstOcarinaSongIndex; i < sLastOcarinaSongIndex; i++) {
- sh = 1 << i;
- if (sAvailOcarinaSongFlags & sh) {
- sMusicStaffCurHeldLength[i] = sMusicStaffExpectedLength[i] + 0x12;
- if (inputChanged) {
- // (pointless if check, this is always true)
- if ((sMusicStaffCurHeldLength[i] >= sMusicStaffExpectedLength[i] - 0x12) &&
- (sMusicStaffCurHeldLength[i] >= sMusicStaffExpectedLength[i] + 0x12) &&
- (sOcarinaSongs[i][sMusicStaffPos[i]].unk_02 == 0) &&
- (sMusicStaffPrevPitch == sMusicStaffExpectedPitch[i])) {
- D_80131878 = i + 1;
- sIsOcarinaInputEnabled = 0;
+ for (songIndex = sFirstOcarinaSongIndex; songIndex < sLastOcarinaSongIndex; songIndex++) {
+ curOcarinaSongFlag = 1 << songIndex;
+
+ if (sAvailOcarinaSongFlags & curOcarinaSongFlag) {
+ sMusicStaffCurHeldLength[songIndex] = sMusicStaffExpectedLength[songIndex] + 18;
+
+ if (noNewValidInput) {
+ if ((sMusicStaffCurHeldLength[songIndex] >= sMusicStaffExpectedLength[songIndex] - 18) &&
+ (sMusicStaffCurHeldLength[songIndex] >= sMusicStaffExpectedLength[songIndex] + 18) &&
+ (sOcarinaSongNotes[songIndex][sMusicStaffPos[songIndex]].length == 0) &&
+ (sMusicStaffPrevPitch == sMusicStaffExpectedPitch[songIndex])) {
+ // This case is taken if the song is finished and successfully played
+ // (i.e. .length == 0 indicates that the song is at the end)
+ sPlayedOcarinaSongIndexPlusOne = songIndex + 1;
+ sIsOcarinaInputEnabled = false;
sOcarinaFlags = 0;
}
- } else if (sMusicStaffCurHeldLength[i] >= (sMusicStaffExpectedLength[i] - 0x12)) {
- if (sMusicStaffPrevPitch != 0xFF) {
- if (sMusicStaffPrevPitch == sMusicStaffExpectedPitch[i]) {
- if (i == 12) {
- sMusicStaffCurHeldLength[i] = 0;
+ } else if (sMusicStaffCurHeldLength[songIndex] >= (sMusicStaffExpectedLength[songIndex] - 18)) {
+ // This else-if statement always holds true, taken if a new note is played
+ if (sMusicStaffPrevPitch != OCARINA_PITCH_NONE) {
+ // New note is played
+ if (sMusicStaffPrevPitch == sMusicStaffExpectedPitch[songIndex]) {
+ // Note is part of expected song
+ if (songIndex == OCARINA_SONG_SCARECROW_SPAWN) {
+ sMusicStaffCurHeldLength[songIndex] = 0;
}
} else {
- sAvailOcarinaSongFlags ^= sh;
+ // Note is not part of expected song, so this song is no longer available as an option in
+ // this playback
+ sAvailOcarinaSongFlags ^= curOcarinaSongFlag;
}
}
- prevNote = &sOcarinaSongs[i][sMusicStaffPos[i]];
- note = &sOcarinaSongs[i][++sMusicStaffPos[i]];
- sMusicStaffExpectedLength[i] = prevNote->unk_02;
- sMusicStaffExpectedPitch[i] = prevNote->noteIdx;
+ curNote = &sOcarinaSongNotes[songIndex][sMusicStaffPos[songIndex]];
+ nextNote = &sOcarinaSongNotes[songIndex][++sMusicStaffPos[songIndex]];
+ sMusicStaffExpectedLength[songIndex] = curNote->length;
+ sMusicStaffExpectedPitch[songIndex] = curNote->pitch;
- if (sCurOcarinaPitch != sMusicStaffExpectedPitch[i]) {
- sAvailOcarinaSongFlags ^= sh;
+ // The current note is not the expected note.
+ if (sCurOcarinaPitch != sMusicStaffExpectedPitch[songIndex]) {
+ sAvailOcarinaSongFlags ^= curOcarinaSongFlag;
}
- while (prevNote->noteIdx == note->noteIdx ||
- (note->noteIdx == OCARINA_NOTE_INVALID && note->unk_02 != 0)) {
- sMusicStaffExpectedLength[i] += note->unk_02;
- prevNote = &sOcarinaSongs[i][sMusicStaffPos[i]];
- note = &sOcarinaSongs[i][sMusicStaffPos[i] + 1];
- sMusicStaffPos[i]++;
+ while (curNote->pitch == nextNote->pitch ||
+ (nextNote->pitch == OCARINA_BTN_INVALID && nextNote->length != 0)) {
+ sMusicStaffExpectedLength[songIndex] += nextNote->length;
+ curNote = &sOcarinaSongNotes[songIndex][sMusicStaffPos[songIndex]];
+ nextNote = &sOcarinaSongNotes[songIndex][sMusicStaffPos[songIndex] + 1];
+ sMusicStaffPos[songIndex]++;
}
- } else if (sMusicStaffCurHeldLength[i] < 0xA) {
- sp57 = -1;
- sMusicStaffCurHeldLength[i] = 0;
+ } else if (sMusicStaffCurHeldLength[songIndex] < 10) {
+ // case never taken
+ staffOcarinaPlayingPosOffset = -1;
+ sMusicStaffCurHeldLength[songIndex] = 0;
sMusicStaffPrevPitch = sCurOcarinaPitch;
} else {
- sAvailOcarinaSongFlags ^= sh;
+ // case never taken
+ sAvailOcarinaSongFlags ^= curOcarinaSongFlag;
}
}
- if (sAvailOcarinaSongFlags == 0 && sStaffOcarinaPlayingPos >= D_8013187C) {
- sIsOcarinaInputEnabled = 0;
- if (CHECK_BTN_ANY(sOcarinaFlags, BTN_B) && sCurOcarinaPitch == sOcarinaSongs[i][0].noteIdx) {
- D_80130F4C = sOcarinaFlags;
+ // if a note is played that doesn't match a song, the song bit in sAvailOcarinaSongFlags is turned off
+ // if there are no more songs remaining that it could be and the maximum position has been exceeded, then
+ if (sAvailOcarinaSongFlags == 0 && sStaffOcarinaPlayingPos >= sMusicStaffNumNotesPerTest) {
+ sIsOcarinaInputEnabled = false;
+ if (CHECK_BTN_ANY(sOcarinaFlags, BTN_B) && sCurOcarinaPitch == sOcarinaSongNotes[songIndex][0].pitch) {
+ // case never taken, this function is not called if (sOcarinaFlags & 0x4000) is set
+ sPrevOcarinaWithMusicStaffFlags = sOcarinaFlags;
}
sOcarinaFlags = 0;
return;
}
}
- if (!inputChanged) {
+ if (!noNewValidInput) {
sMusicStaffPrevPitch = sCurOcarinaPitch;
- sStaffOcarinaPlayingPos += sp57 + 1;
+ sStaffOcarinaPlayingPos += staffOcarinaPlayingPosOffset + 1;
}
}
}
-void func_800ED200(void) {
- u32 temp_v0;
+/**
+ * Checks for ocarina songs from user input with no music staff prompt.
+ * Includes ocarina actions such as free play, no warp
+ */
+void AudioOcarina_CheckSongsWithoutMusicStaff(void) {
+ u32 pitch;
u8 i;
u8 j;
u8 k;
@@ -1590,15 +1719,15 @@ void func_800ED200(void) {
}
if (CHECK_BTN_ANY(sOcarinaInputButtonCur, disableSongBtnMap) &&
- CHECK_BTN_ANY(sOcarinaInputButtonCur, sOcarinaAllowedBtnMask)) {
- func_800ECC04((u16)sOcarinaFlags);
+ CHECK_BTN_ANY(sOcarinaInputButtonCur, sOcarinaAllowedButtonMask)) {
+ AudioOcarina_Start((u16)sOcarinaFlags);
return;
}
- func_800ECDBC();
+ AudioOcarina_CheckIfStartedSong();
if (sOcarinaHasStartedSong) {
- if ((sPrevOcarinaPitch != sCurOcarinaPitch) && (sCurOcarinaPitch != 0xFF)) {
+ if ((sPrevOcarinaPitch != sCurOcarinaPitch) && (sCurOcarinaPitch != OCARINA_PITCH_NONE)) {
sStaffOcarinaPlayingPos++;
if (sStaffOcarinaPlayingPos >= 9) {
sStaffOcarinaPlayingPos = 1;
@@ -1612,29 +1741,34 @@ void func_800ED200(void) {
sOcarinaWithoutMusicStaffPos++;
}
- if ((sCurOcarinaBendIndex < 0 ? -sCurOcarinaBendIndex : sCurOcarinaBendIndex) >= 0x15) {
- sCurOcarinaSongWithoutMusicStaff[sOcarinaWithoutMusicStaffPos - 1] = 0xFF;
+ if ((sCurOcarinaBendIndex < 0 ? -sCurOcarinaBendIndex : sCurOcarinaBendIndex) > 20) {
+ sCurOcarinaSongWithoutMusicStaff[sOcarinaWithoutMusicStaffPos - 1] = OCARINA_PITCH_NONE;
} else {
sCurOcarinaSongWithoutMusicStaff[sOcarinaWithoutMusicStaffPos - 1] = sCurOcarinaPitch;
}
+ // This nested for-loop tests to see if the notes from the ocarina are identical
+ // to any of the songIndex from sFirstOcarinaSongIndex to sLastOcarinaSongIndex
+
+ // Loop through each of the songs
for (i = sFirstOcarinaSongIndex; i < sLastOcarinaSongIndex; i++) {
+ // Checks to see if the song is available to be played
if (sAvailOcarinaSongFlags & (u16)(1 << i)) {
- for (j = 0, k = 0; j < gOcarinaSongNotes[i].len && k == 0 &&
- sOcarinaWithoutMusicStaffPos >= gOcarinaSongNotes[i].len;) {
- temp_v0 =
- sCurOcarinaSongWithoutMusicStaff[(sOcarinaWithoutMusicStaffPos - gOcarinaSongNotes[i].len) +
- j];
- if (temp_v0 == sOcarinaNoteValues[gOcarinaSongNotes[i].notesIdx[j]]) {
+ for (j = 0, k = 0; j < gOcarinaSongButtons[i].numButtons && k == 0 &&
+ sOcarinaWithoutMusicStaffPos >= gOcarinaSongButtons[i].numButtons;) {
+ pitch = sCurOcarinaSongWithoutMusicStaff[(sOcarinaWithoutMusicStaffPos -
+ gOcarinaSongButtons[i].numButtons) +
+ j];
+ if (pitch == sButtonToPitchMap[gOcarinaSongButtons[i].buttonsIndex[j]]) {
j++;
} else {
k++;
}
}
- if (j == gOcarinaSongNotes[i].len) {
- D_80131878 = i + 1;
- sIsOcarinaInputEnabled = 0;
+ if (j == gOcarinaSongButtons[i].numButtons) {
+ sPlayedOcarinaSongIndexPlusOne = i + 1;
+ sIsOcarinaInputEnabled = false;
sOcarinaFlags = 0;
}
}
@@ -1643,10 +1777,12 @@ void func_800ED200(void) {
}
}
-void func_800ED458(s32 arg0) {
- u32 phi_v1_2;
+// This unused argument is used in Majora's Mask as a u8
+void AudioOcarina_PlayControllerInput(u8 unused) {
+ u32 ocarinaBtnsHeld;
bool customControls = CVarGetInteger(CVAR_SETTING("CustomOcarina.Enabled"), 0);
+ // Prevents two different ocarina notes from being played on two consecutive frames
if (sOcarinaFlags != 0 && sOcarinaDropInputTimer != 0) {
sOcarinaDropInputTimer--;
if (!CVarGetInteger(CVAR_ENHANCEMENT("DpadNoDropOcarinaInput"), 0)) {
@@ -1654,154 +1790,194 @@ void func_800ED458(s32 arg0) {
}
}
- if ((sOcarinaInputButtonStart == 0) ||
- ((sOcarinaInputButtonStart & sOcarinaAllowedBtnMask) != (sOcarinaInputButtonCur & sOcarinaAllowedBtnMask))) {
+ // Ensures the button pressed to start the ocarina does not also play an ocarina note
+ if ((sOcarinaInputButtonStart == 0) || ((sOcarinaInputButtonStart & sOcarinaAllowedButtonMask) !=
+ (sOcarinaInputButtonCur & sOcarinaAllowedButtonMask))) {
sOcarinaInputButtonStart = 0;
- sCurOcarinaPitch = 0xFF;
- sCurOcarinaButtonIndex = 0xFF;
- phi_v1_2 =
- (sOcarinaInputButtonCur & sOcarinaAllowedBtnMask) & (sOcarinaInputButtonPrev & sOcarinaAllowedBtnMask);
- if (!(sOcarinaInputButtonPress & phi_v1_2) && (sOcarinaInputButtonCur != 0)) {
+ sCurOcarinaPitch = OCARINA_PITCH_NONE;
+ sCurOcarinaButtonIndex = OCARINA_BTN_INVALID;
+ ocarinaBtnsHeld = (sOcarinaInputButtonCur & sOcarinaAllowedButtonMask) &
+ (sOcarinaInputButtonPrev & sOcarinaAllowedButtonMask);
+ if (!(sOcarinaInputButtonPress & ocarinaBtnsHeld) && (sOcarinaInputButtonCur != 0)) {
sOcarinaInputButtonPress = sOcarinaInputButtonCur;
} else {
- sOcarinaInputButtonPress &= phi_v1_2;
+ sOcarinaInputButtonPress &= ocarinaBtnsHeld;
}
- Audio_OcaUpdateBtnMap(customControls);
+ AudioOcarina_SetCustomButtonMapping(customControls);
+
+ // Interprets and transforms controller input into ocarina buttons and notes
if (sOcarinaInputButtonPress & sOcarinaD4BtnMap && GameInteractor_Should(VB_HAVE_OCARINA_NOTE_D4, true)) {
osSyncPrintf("Presss NA_KEY_D4 %08x\n", sOcarinaD4BtnMap);
- sCurOcarinaPitch = 2;
- sCurOcarinaButtonIndex = 0;
+ sCurOcarinaPitch = OCARINA_PITCH_D4;
+ sCurOcarinaButtonIndex = OCARINA_BTN_A;
} else if (sOcarinaInputButtonPress & sOcarinaF4BtnMap &&
GameInteractor_Should(VB_HAVE_OCARINA_NOTE_F4, true)) {
osSyncPrintf("Presss NA_KEY_F4 %08x\n", sOcarinaF4BtnMap);
- sCurOcarinaPitch = 5;
- sCurOcarinaButtonIndex = 1;
+ sCurOcarinaPitch = OCARINA_PITCH_F4;
+ sCurOcarinaButtonIndex = OCARINA_BTN_C_DOWN;
} else if (sOcarinaInputButtonPress & sOcarinaA4BtnMap &&
GameInteractor_Should(VB_HAVE_OCARINA_NOTE_A4, true)) {
osSyncPrintf("Presss NA_KEY_A4 %08x\n", sOcarinaA4BtnMap);
- sCurOcarinaPitch = 9;
- sCurOcarinaButtonIndex = 2;
+ sCurOcarinaPitch = OCARINA_PITCH_A4;
+ sCurOcarinaButtonIndex = OCARINA_BTN_C_RIGHT;
} else if (sOcarinaInputButtonPress & sOcarinaB4BtnMap &&
GameInteractor_Should(VB_HAVE_OCARINA_NOTE_B4, true)) {
osSyncPrintf("Presss NA_KEY_B4 %08x\n", sOcarinaA4BtnMap);
- sCurOcarinaPitch = 0xB;
- sCurOcarinaButtonIndex = 3;
+ sCurOcarinaPitch = OCARINA_PITCH_B4;
+ sCurOcarinaButtonIndex = OCARINA_BTN_C_LEFT;
} else if (sOcarinaInputButtonPress & sOcarinaD5BtnMap &&
GameInteractor_Should(VB_HAVE_OCARINA_NOTE_D5, true)) {
osSyncPrintf("Presss NA_KEY_D5 %08x\n", sOcarinaD5BtnMap);
- sCurOcarinaPitch = 0xE;
- sCurOcarinaButtonIndex = 4;
+ sCurOcarinaPitch = OCARINA_PITCH_D5;
+ sCurOcarinaButtonIndex = OCARINA_BTN_C_UP;
}
+ // SoH
u32 noteSharpBtnMap;
if (customControls) {
noteSharpBtnMap = BTN_CUSTOM_OCARINA_PITCH_UP;
} else {
noteSharpBtnMap = BTN_R;
}
- if ((sCurOcarinaPitch != 0xFF) && (sOcarinaInputButtonCur & noteSharpBtnMap) && (sRecordingState != 2)) {
- sCurOcarinaButtonIndex += 0x80;
- sCurOcarinaPitch++;
+ if ((sCurOcarinaPitch != OCARINA_PITCH_NONE) && (sOcarinaInputButtonCur & noteSharpBtnMap) &&
+ (sRecordingState != OCARINA_RECORD_SCARECROW_SPAWN)) {
+ sCurOcarinaButtonIndex += 0x80; // Flag to resolve B Flat 4
+ sCurOcarinaPitch++; // Raise the pitch by 1 semitone
}
+ // SoH
u32 noteFlatBtnMap;
if (customControls) {
noteFlatBtnMap = BTN_CUSTOM_OCARINA_PITCH_DOWN;
} else {
noteFlatBtnMap = BTN_Z;
}
- if ((sCurOcarinaPitch != 0xFF) && (sOcarinaInputButtonCur & noteFlatBtnMap) && (sRecordingState != 2)) {
- sCurOcarinaButtonIndex += 0x40;
- sCurOcarinaPitch--;
+ if ((sCurOcarinaPitch != OCARINA_PITCH_NONE) && (sOcarinaInputButtonCur & noteFlatBtnMap) &&
+ (sRecordingState != OCARINA_RECORD_SCARECROW_SPAWN)) {
+ sCurOcarinaButtonIndex += 0x40; // Flag to resolve B Flat 4
+ sCurOcarinaPitch--; // Lower the pitch by 1 semitone
}
- if (sRecordingState != 2) {
- sCurOcarinaBendIndex = sCurOcaStick.y;
- sCurOcarinaBendFreq = Audio_OcaAdjStick(sCurOcarinaBendIndex);
+ if (sRecordingState != OCARINA_RECORD_SCARECROW_SPAWN) {
+ // Bend the pitch of the note based on y control stick
+ sCurOcarinaBendIndex = sOcarinaInputStickAdj.y;
+ sCurOcarinaBendFreq = AudioOcarina_BendPitchTwoSemitones(sCurOcarinaBendIndex);
- sCurOcarinaVibrato = (sCurOcaStick.x < 0 ? -sCurOcaStick.x : sCurOcaStick.x) >> 2;
+ // Add vibrato of the ocarina note based on the x control stick
+ sCurOcarinaVibrato =
+ (sOcarinaInputStickAdj.x < 0 ? -sOcarinaInputStickAdj.x : sOcarinaInputStickAdj.x) >> 2;
+ // Sets vibrato to io port 6
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | 0xD06, sCurOcarinaVibrato);
} else {
+ // no bending or vibrato for recording state OCARINA_RECORD_SCARECROW_SPAWN
sCurOcarinaBendIndex = 0;
- sCurOcarinaBendFreq = 1.0f;
+ sCurOcarinaVibrato = 0; // PAL/NTSC 1.1 version
+ sCurOcarinaBendFreq = 1.0f; // No bend
}
- if ((sCurOcarinaPitch != 0xFF) && (sPrevOcarinaPitch != sCurOcarinaPitch)) {
+ // Processes new and valid notes
+ if ((sCurOcarinaPitch != OCARINA_PITCH_NONE) && (sPrevOcarinaPitch != sCurOcarinaPitch)) {
+ // Sets ocarina instrument Id to channelIndex io port 7, which is used
+ // as an index in seq 0 to get the true instrument Id
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | 0xD07, sOcarinaInstrumentId - 1);
+ // Sets pitch to io port 5
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | 0xD05, sCurOcarinaPitch);
Audio_PlaySoundGeneral(NA_SE_OC_OCARINA, &gSfxDefaultPos, 4, &sCurOcarinaBendFreq, &sRelativeOcarinaVolume,
&gSfxDefaultReverb);
- } else if ((sPrevOcarinaPitch != 0xFF) && (sCurOcarinaPitch == 0xFF)) {
+ } else if ((sPrevOcarinaPitch != OCARINA_PITCH_NONE) && (sCurOcarinaPitch == OCARINA_PITCH_NONE)) {
+ // Stops ocarina sound when transitioning from playing to not playing a note
Audio_StopSfxById(NA_SE_OC_OCARINA);
}
+
GameInteractor_ExecuteOnOcarinaNote(sCurOcarinaPitch, sCurOcarinaBendFreq, sOcarinaInstrumentId);
}
}
-void func_800ED848(u8 inputEnabled) {
+/**
+ * Directly enable the ocarina to receive input without
+ * properly resetting it based on an ocarina instrument id
+ * Unused.
+ */
+void AudioOcarina_EnableInput(u8 inputEnabled) {
sIsOcarinaInputEnabled = inputEnabled;
}
-void AudioOcarina_SetInstrument(u8 arg0) {
- if (sOcarinaInstrumentId == arg0) {
+/**
+ * Resets ocarina properties based on the ocarina instrument id
+ * If ocarina instrument id is "OCARINA_INSTRUMENT_OFF", turn off the ocarina
+ * For all ocarina instrument ids, turn the ocarina on with the instrument id
+ */
+void AudioOcarina_SetInstrument(u8 ocarinaInstrumentId) {
+ if (sOcarinaInstrumentId == ocarinaInstrumentId) {
return;
}
- u16 sfxEditorId = arg0 + 0x81;
+ // SoH
+ u16 sfxEditorId = ocarinaInstrumentId + 0x81;
u16 newArg0 = AudioEditor_GetReplacementSeq(sfxEditorId);
if (newArg0 != sfxEditorId) {
gAudioContext.seqReplaced[SEQ_PLAYER_SFX] = 1;
- arg0 = newArg0 - 0x81;
+ ocarinaInstrumentId = newArg0 - 0x81;
}
- Audio_SeqCmd8(SEQ_PLAYER_SFX, 1, SFX_PLAYER_CHANNEL_OCARINA, arg0);
- sOcarinaInstrumentId = arg0;
- if (arg0 == 0) {
+ Audio_SeqCmd8(SEQ_PLAYER_SFX, 1, SFX_CHANNEL_OCARINA, ocarinaInstrumentId);
+ sOcarinaInstrumentId = ocarinaInstrumentId;
+ if (ocarinaInstrumentId == OCARINA_INSTRUMENT_OFF) {
sOcarinaInputButtonCur = 0;
sOcarinaInputButtonPrev = 0;
sOcarinaInputButtonPress = 0;
+
sOcarinaInputButtonStart = 0xFFFF;
- func_800ED458(0);
+
+ AudioOcarina_PlayControllerInput(false);
Audio_StopSfxById(NA_SE_OC_OCARINA);
- Audio_SetSoundBanksMute(0);
+ Audio_SetSfxBanksMute(0);
sPlaybackState = 0;
sPlaybackStaffPos = 0;
- sIsOcarinaInputEnabled = 0;
+ sIsOcarinaInputEnabled = false;
sOcarinaFlags = 0;
- Audio_ClearBGMMute(SFX_PLAYER_CHANNEL_OCARINA);
+ // return to full volume for players 0 and 3 (background bgm) after ocarina is finished
+ Audio_ClearBGMMute(SFX_CHANNEL_OCARINA);
} else {
sOcarinaInputButtonCur = 0;
- Audio_GetOcaInput();
+ AudioOcarina_ReadControllerInput();
+ // Store button used to turn on ocarina
sOcarinaInputButtonStart = sOcarinaInputButtonCur;
- Audio_QueueSeqCmdMute(SFX_PLAYER_CHANNEL_OCARINA);
+ // lowers volumes of players 0 and 3 (background bgm) while playing ocarina
+ Audio_QueueSeqCmdMute(SFX_CHANNEL_OCARINA);
}
}
-void Audio_OcaSetSongPlayback(s8 songIdxPlusOne, s8 playbackState) {
- if (songIdxPlusOne == 0) {
+void AudioOcarina_SetPlaybackSong(s8 songIndexPlusOne, s8 playbackState) {
+ if (songIndexPlusOne == 0) {
sPlaybackState = 0;
Audio_StopSfxById(NA_SE_OC_OCARINA);
return;
}
- if (songIdxPlusOne < 0xF) {
- sPlaybackSong = sOcarinaSongs[songIdxPlusOne - 1];
+ if (songIndexPlusOne < (OCARINA_SONG_SCARECROW_LONG + 1)) {
+ sPlaybackSong = sOcarinaSongNotes[songIndexPlusOne - 1];
} else {
- sPlaybackSong = sPierresSong;
+ sPlaybackSong = sScarecrowsLongSongNotes;
}
sPlaybackState = playbackState;
sPlaybackNoteTimer = 0;
- sPlaybackPitch = 0xFF;
+ sPlaybackPitch = OCARINA_PITCH_NONE;
sPlaybackNotePos = 0;
sPlaybackStaffPos = 0;
- while (sPlaybackSong[sPlaybackNotePos].noteIdx == OCARINA_NOTE_INVALID) {
+
+ while (sPlaybackSong[sPlaybackNotePos].pitch == OCARINA_PITCH_NONE) {
sPlaybackNotePos++;
}
}
-void Audio_OcaPlayback(void) {
+/**
+ * Play a song with the ocarina to the user that is
+ * based on OcarinaNote data and not user input
+ */
+void AudioOcarina_PlaybackSong(void) {
u32 noteTimerStep;
u32 nextNoteTimerStep = 0;
@@ -1809,7 +1985,7 @@ void Audio_OcaPlayback(void) {
if (sPlaybackStaffPos == 0) {
noteTimerStep = 3;
} else {
- noteTimerStep = D_8016BA04 - D_80130F68;
+ noteTimerStep = sOcarinaUpdateTaskStart - sOcarinaPlaybackTaskStart;
}
if (noteTimerStep < sPlaybackNoteTimer) {
@@ -1821,7 +1997,7 @@ void Audio_OcaPlayback(void) {
if (sPlaybackNoteTimer == 0) {
- sPlaybackNoteTimer = sPlaybackSong[sPlaybackNotePos].unk_02;
+ sPlaybackNoteTimer = sPlaybackSong[sPlaybackNotePos].length;
if (sPlaybackNotePos == 1) {
sPlaybackNoteTimer++;
@@ -1832,7 +2008,7 @@ void Audio_OcaPlayback(void) {
if (sPlaybackState != 0) {
sPlaybackNotePos = 0;
sPlaybackStaffPos = 0;
- sPlaybackPitch = 0xFF;
+ sPlaybackPitch = OCARINA_PITCH_NONE;
} else {
Audio_StopSfxById(NA_SE_OC_OCARINA);
}
@@ -1841,42 +2017,51 @@ void Audio_OcaPlayback(void) {
sPlaybackNoteTimer -= nextNoteTimerStep;
}
+ // Update volume
if (sNotePlaybackVolume != sPlaybackSong[sPlaybackNotePos].volume) {
sNotePlaybackVolume = sPlaybackSong[sPlaybackNotePos].volume;
- sNormalizedNotePlaybackVolume = sNotePlaybackVolume / 127.0f;
+ sRelativeNotePlaybackVolume = sNotePlaybackVolume / 127.0f;
}
+ // Update vibrato
if (sNotePlaybackVibrato != sPlaybackSong[sPlaybackNotePos].vibrato) {
sNotePlaybackVibrato = sPlaybackSong[sPlaybackNotePos].vibrato;
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | 0xD06, sNotePlaybackVibrato);
}
- if (sNotePlaybackTone != sPlaybackSong[sPlaybackNotePos].tone) {
- sNotePlaybackTone = sPlaybackSong[sPlaybackNotePos].tone;
- sNormalizedNotePlaybackTone = Audio_OcaAdjStick(sNotePlaybackTone);
+ // Update bend
+ if (sNotePlaybackBend != sPlaybackSong[sPlaybackNotePos].bend) {
+ sNotePlaybackBend = sPlaybackSong[sPlaybackNotePos].bend;
+ sRelativeNotePlaybackBend = AudioOcarina_BendPitchTwoSemitones(sNotePlaybackBend);
}
+ // No changes in volume, vibrato, or bend between notes
if ((sPlaybackSong[sPlaybackNotePos].volume == sPlaybackSong[sPlaybackNotePos - 1].volume &&
(sPlaybackSong[sPlaybackNotePos].vibrato == sPlaybackSong[sPlaybackNotePos - 1].vibrato) &&
- (sPlaybackSong[sPlaybackNotePos].tone == sPlaybackSong[sPlaybackNotePos - 1].tone))) {
+ (sPlaybackSong[sPlaybackNotePos].bend == sPlaybackSong[sPlaybackNotePos - 1].bend))) {
sPlaybackPitch = 0xFE;
}
- if (sPlaybackPitch != sPlaybackSong[sPlaybackNotePos].noteIdx) {
- u8 tmp = sPlaybackSong[sPlaybackNotePos].noteIdx;
+ if (sPlaybackPitch != sPlaybackSong[sPlaybackNotePos].pitch) {
+ u8 pitch = sPlaybackSong[sPlaybackNotePos].pitch;
- if (tmp == 0xA) {
- sPlaybackPitch = tmp + sPlaybackSong[sPlaybackNotePos].semitone;
+ // As bFlat4 is exactly in the middle of notes B & A, a flag is
+ // added to the pitch to resolve which button to map Bflat4 to
+ if (pitch == OCARINA_PITCH_BFLAT4) {
+ sPlaybackPitch = pitch + sPlaybackSong[sPlaybackNotePos].bFlat4Flag;
} else {
- sPlaybackPitch = tmp;
+ sPlaybackPitch = pitch;
}
- if (sPlaybackPitch != 0xFF) {
+ if (sPlaybackPitch != OCARINA_PITCH_NONE) {
sPlaybackStaffPos++;
+ // Sets ocarina instrument Id to channelIndex io port 7, which is used
+ // as an index in seq 0 to get the true instrument Id
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | 0xD07, sOcarinaInstrumentId - 1);
+ // Sets sPlaybackPitch to channelIndex io port 5
Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | 0xD05, sPlaybackPitch & 0x3F);
- Audio_PlaySoundGeneral(NA_SE_OC_OCARINA, &gSfxDefaultPos, 4, &sNormalizedNotePlaybackTone,
- &sNormalizedNotePlaybackVolume, &gSfxDefaultReverb);
+ Audio_PlaySoundGeneral(NA_SE_OC_OCARINA, &gSfxDefaultPos, 4, &sRelativeNotePlaybackBend,
+ &sRelativeNotePlaybackVolume, &gSfxDefaultReverb);
} else {
Audio_StopSfxById(NA_SE_OC_OCARINA);
}
@@ -1886,231 +2071,261 @@ void Audio_OcaPlayback(void) {
}
}
-void func_800EDD68(u8 arg0) {
+void AudioOcarina_SetRecordingSong(u8 isRecordingComplete) {
u16 i;
u16 i2;
u16 pad;
- u8 lastNote;
+ u8 pitch;
OcarinaNote* note;
u8 j;
u8 k;
s32 t;
- OcarinaNote* song;
+ OcarinaNote* recordedSong;
- if (sRecordingState == 1) {
- song = gScarecrowCustomSongPtr;
+ if (sRecordingState == OCARINA_RECORD_SCARECROW_LONG) {
+ recordedSong = gScarecrowLongSongPtr;
} else {
- song = D_80131BEC;
- }
- song[sRecordSongPos].noteIdx = D_80131864;
- song[sRecordSongPos].unk_02 = D_8016BA04 - D_80131860;
- song[sRecordSongPos].volume = D_80131868;
- song[sRecordSongPos].vibrato = D_8013186C;
- song[sRecordSongPos].tone = D_80131870;
- song[sRecordSongPos].semitone = D_80131874 & 0xC0;
- D_80131864 = sCurOcarinaPitch;
- D_80131868 = sCurOcarinaVolume;
- D_8013186C = sCurOcarinaVibrato;
- D_80131870 = sCurOcarinaBendIndex;
- D_80131874 = sCurOcarinaButtonIndex;
+ /**
+ * OCARINA_RECORD_SCARECROW_SPAWN
+ *
+ * The notes for scarecrows spawn song are first recorded into the ocarina memory
+ * game address to act as a buffer. That way, if a new scarecrow spawn song is
+ * rejected, the previous scarecrow spawn song is not overwritten. If the scarecrow
+ * spawn song is accepted, then the notes are copied over to the scarecrow spawn
+ * song address
+ */
+ recordedSong = sMemoryGameSongPtr;
+ }
+
+ recordedSong[sRecordSongPos].pitch = sRecordOcarinaPitch;
+ recordedSong[sRecordSongPos].length = sOcarinaUpdateTaskStart - sOcarinaRecordTaskStart;
+ recordedSong[sRecordSongPos].volume = sRecordOcarinaVolume;
+ recordedSong[sRecordSongPos].vibrato = sRecordOcarinaVibrato;
+ recordedSong[sRecordSongPos].bend = sRecordOcarinaBendIndex;
+ recordedSong[sRecordSongPos].bFlat4Flag = sRecordOcarinaButtonIndex & 0xC0;
+
+ sRecordOcarinaPitch = sCurOcarinaPitch;
+ sRecordOcarinaVolume = sCurOcarinaVolume;
+ sRecordOcarinaVibrato = sCurOcarinaVibrato;
+ sRecordOcarinaBendIndex = sCurOcarinaBendIndex;
+ sRecordOcarinaButtonIndex = sCurOcarinaButtonIndex;
+
sRecordSongPos++;
- if ((sRecordSongPos != 107) && (arg0 == 0)) {
+ if ((sRecordSongPos != 107) && !isRecordingComplete) {
+ // Continue recording
return;
}
+ // Recording is complete
+
i = sRecordSongPos;
- lastNote = 0xFF;
- while (i != 0 && lastNote == 0xFF) {
+ pitch = OCARINA_PITCH_NONE;
+ while (i != 0 && pitch == OCARINA_PITCH_NONE) {
i--;
- lastNote = song[i].noteIdx;
+ pitch = recordedSong[i].pitch;
}
if (sRecordSongPos != (i + 1)) {
sRecordSongPos = i + 2;
- song[sRecordSongPos - 1].unk_02 = 0;
+ recordedSong[sRecordSongPos - 1].length = 0;
}
- song[sRecordSongPos].unk_02 = 0;
+ recordedSong[sRecordSongPos].length = 0;
- if (sRecordingState == 2) {
+ if (sRecordingState == OCARINA_RECORD_SCARECROW_SPAWN) {
if (sStaffOcarinaPlayingPos >= 8) {
for (i = 0; i < sRecordSongPos; i++) {
- song[i] = song[i + 1];
+ recordedSong[i] = recordedSong[i + 1];
}
- func_800ECB7C(OCARINA_SONG_MEMORY_GAME);
-
- for (i = 0; i < OCARINA_SONG_SCARECROW; i++) {
- for (j = 0; j < 9 - gOcarinaSongNotes[i].len; j++) {
- for (k = 0;
- k < gOcarinaSongNotes[i].len && k + j < 8 &&
- gOcarinaSongNotes[i].notesIdx[k] == gOcarinaSongNotes[OCARINA_SONG_SCARECROW].notesIdx[k + j];
+ // Copies Notes from buffer into scarecrows spawn buttons to be tested for acceptance or rejection
+ AudioOcarina_MapNotesToScarecrowButtons(OCARINA_SONG_MEMORY_GAME);
+
+ // Loop through each of the songs
+ for (i = 0; i < OCARINA_SONG_SCARECROW_SPAWN; i++) {
+ // Loops through all possible starting indices
+ for (j = 0; j < 9 - gOcarinaSongButtons[i].numButtons; j++) {
+ // Loops through the notes of song i
+ for (k = 0; k < gOcarinaSongButtons[i].numButtons && k + j < 8 &&
+ gOcarinaSongButtons[i].buttonsIndex[k] ==
+ gOcarinaSongButtons[OCARINA_SONG_SCARECROW_SPAWN].buttonsIndex[k + j];
k++) {
;
}
- if (k == gOcarinaSongNotes[i].len) {
- sRecordingState = 0xFF;
- sOcarinaSongs[OCARINA_SONG_SCARECROW][1].volume = 0xFF;
+ // This conditional is true if the recorded song contains a reserved song
+ if (k == gOcarinaSongButtons[i].numButtons) {
+ sRecordingState = OCARINA_RECORD_REJECTED;
+ sOcarinaSongNotes[OCARINA_SONG_SCARECROW_SPAWN][1].volume = 0xFF;
return;
}
}
}
+ // Counts how many times a note is repeated
i = 1;
while (i < 8) {
- if (gOcarinaSongNotes[OCARINA_SONG_SCARECROW].notesIdx[0] !=
- gOcarinaSongNotes[OCARINA_SONG_SCARECROW].notesIdx[i]) {
+ if (gOcarinaSongButtons[OCARINA_SONG_SCARECROW_SPAWN].buttonsIndex[0] !=
+ gOcarinaSongButtons[OCARINA_SONG_SCARECROW_SPAWN].buttonsIndex[i]) {
i = 9;
} else {
i++;
}
}
+ // This condition is true if all 8 notes are the same pitch
if (i == 8) {
- sRecordingState = 0xFF;
- sOcarinaSongs[OCARINA_SONG_SCARECROW][1].volume = 0xFF;
+ sRecordingState = OCARINA_RECORD_REJECTED;
+ sOcarinaSongNotes[OCARINA_SONG_SCARECROW_SPAWN][1].volume = 0xFF;
return;
}
+ // The scarecrow spawn song is accepted and copied from the buffer to the scarecrow spawn notes
for (i = 0; i < sRecordSongPos; i++) {
- sOcarinaSongs[OCARINA_SONG_SCARECROW][i] = sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][i];
+ sOcarinaSongNotes[OCARINA_SONG_SCARECROW_SPAWN][i] = sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][i];
}
- sIsOcarinaInputEnabled = 0;
+ sIsOcarinaInputEnabled = false;
} else {
- sOcarinaSongs[OCARINA_SONG_SCARECROW][1].volume = 0xFF;
+ sOcarinaSongNotes[OCARINA_SONG_SCARECROW_SPAWN][1].volume = 0xFF;
}
}
- sRecordingState = 0;
+ sRecordingState = OCARINA_RECORD_OFF;
}
-// start custom song?
/**
- * recordingState = 1, start long scarecrows song
- * recordingState = 0, end
- * recordingState = 2, also scarecrows song
+ * recordingState = OCARINA_RECORD_OFF, end
+ * recordingState = OCARINA_RECORD_SCARECROW_LONG, start long scarecrows song
+ * recordingState = OCARINA_RECORD_SCARECROW_SPAWN, start spawn scarecrows song
*/
-void Audio_OcaSetRecordingState(u8 recordingState) {
+void AudioOcarina_SetRecordingState(u8 recordingState) {
if ((u32)recordingState == sRecordingState) {
return;
}
- if (recordingState != 0) {
- D_80131860 = D_8016BA04;
- D_80131864 = 0xFF;
- D_80131868 = 0x57;
- D_8013186C = 0;
- D_80131870 = 0;
- D_80131874 = 0;
+ if (recordingState != OCARINA_RECORD_OFF) {
+ sOcarinaRecordTaskStart = sOcarinaUpdateTaskStart;
+ sRecordOcarinaPitch = OCARINA_PITCH_NONE;
+ sRecordOcarinaVolume = 0x57;
+ sRecordOcarinaVibrato = 0;
+ sRecordOcarinaBendIndex = 0;
+ sRecordOcarinaButtonIndex = 0;
sRecordSongPos = 0;
- sIsOcarinaInputEnabled = 1;
+ sIsOcarinaInputEnabled = true;
sStaffOcarinaPlayingPos = 0;
- sScarecrowsLongSongSecondNote = sPierresSong[1];
+ sScarecrowsLongSongSecondNote = sScarecrowsLongSongNotes[1];
} else {
if (sRecordSongPos == 0) {
- sPierresSong[1] = sScarecrowsLongSongSecondNote;
+ sScarecrowsLongSongNotes[1] = sScarecrowsLongSongSecondNote;
} else {
- if (sRecordingState == 2) {
+ if (sRecordingState == OCARINA_RECORD_SCARECROW_SPAWN) {
sStaffOcarinaPlayingPos = 1;
}
- func_800EDD68(1);
+ AudioOcarina_SetRecordingSong(true);
}
- sIsOcarinaInputEnabled = 0;
+ sIsOcarinaInputEnabled = false;
sStaffOcarinaPlayingPos = 0;
}
sRecordingState = recordingState;
}
-void Audio_OcaUpdateRecordingStaff(void) {
+void AudioOcarina_UpdateRecordingStaff(void) {
sRecordingStaff.state = sRecordingState;
sRecordingStaff.pos = sStaffOcarinaPlayingPos;
- if (sRecordingState == 0xFF) {
- sRecordingState = 0;
+ if (sRecordingState == OCARINA_RECORD_REJECTED) {
+ sRecordingState = OCARINA_RECORD_OFF;
}
}
-void Audio_OcaUpdatePlayingStaff(void) {
- sPlayingStaff.noteIdx = sCurOcarinaButtonIndex & 0x3F;
- sPlayingStaff.state = Audio_OcaGetPlayingState();
+void AudioOcarina_UpdatePlayingStaff(void) {
+ sPlayingStaff.buttonIndex = sCurOcarinaButtonIndex & 0x3F;
+ sPlayingStaff.state = AudioOcarina_GetPlayingState();
sPlayingStaff.pos = sStaffOcarinaPlayingPos;
}
-void Audio_OcaUpdateDisplayedStaff(void) {
- if ((sPlaybackPitch & 0x3F) < 0x10) {
- sDisplayedStaff.noteIdx = Audio_OcaMapNoteValue(sPlaybackPitch);
+void AudioOcarina_UpdatePlaybackStaff(void) {
+ if ((sPlaybackPitch & 0x3F) <= OCARINA_PITCH_EFLAT5) {
+ sPlaybackStaff.buttonIndex = AudioOcarina_MapNoteToButton(sPlaybackPitch);
}
- sDisplayedStaff.state = sPlaybackState;
+ sPlaybackStaff.state = sPlaybackState;
- if (sPlaybackSong != sPierresSong) {
- sDisplayedStaff.pos = sPlaybackStaffPos;
+ if (sPlaybackSong != sScarecrowsLongSongNotes) {
+ sPlaybackStaff.pos = sPlaybackStaffPos;
} else if (sPlaybackStaffPos == 0) {
- sDisplayedStaff.pos = 0;
+ sPlaybackStaff.pos = 0;
} else {
- sDisplayedStaff.pos = ((sPlaybackStaffPos - 1) % 8) + 1;
+ sPlaybackStaff.pos = ((sPlaybackStaffPos - 1) % 8) + 1;
}
}
-OcarinaStaff* Audio_OcaGetRecordingStaff(void) {
+OcarinaStaff* AudioOcarina_GetRecordingStaff(void) {
return &sRecordingStaff;
}
-OcarinaStaff* Audio_OcaGetPlayingStaff(void) {
+OcarinaStaff* AudioOcarina_GetPlayingStaff(void) {
if (sPlayingStaff.state < 0xFE) {
sOcarinaFlags = 0;
}
+
return &sPlayingStaff;
}
-OcarinaStaff* Audio_OcaGetDisplayingStaff(void) {
- return &sDisplayedStaff;
+OcarinaStaff* AudioOcarina_GetPlaybackStaff(void) {
+ return &sPlaybackStaff;
}
-void func_800EE404(void) {
+void AudioOcarina_RecordSong(void) {
s32 noteChanged;
- if ((sRecordingState != 0) && ((D_8016BA04 - D_80131860) >= 3)) {
+ if ((sRecordingState != OCARINA_RECORD_OFF) && ((sOcarinaUpdateTaskStart - sOcarinaRecordTaskStart) >= 3)) {
noteChanged = false;
- if (D_80131864 != sCurOcarinaPitch) {
- if (sCurOcarinaPitch != 0xFF) {
- sRecordingStaff.noteIdx = sCurOcarinaButtonIndex & 0x3F;
+ if (sRecordOcarinaPitch != sCurOcarinaPitch) {
+ if (sCurOcarinaPitch != OCARINA_PITCH_NONE) {
+ sRecordingStaff.buttonIndex = sCurOcarinaButtonIndex & 0x3F;
sStaffOcarinaPlayingPos++;
- } else if ((sRecordingState == 2) && (sStaffOcarinaPlayingPos == 8)) {
- func_800EDD68(1);
+ } else if ((sRecordingState == OCARINA_RECORD_SCARECROW_SPAWN) && (sStaffOcarinaPlayingPos == 8)) {
+ AudioOcarina_SetRecordingSong(true);
return;
}
if (sStaffOcarinaPlayingPos > 8) {
- if (sRecordingState == 2) {
+ if (sRecordingState == OCARINA_RECORD_SCARECROW_SPAWN) {
// notes played are over 8 and in recording mode.
- func_800EDD68(1);
+ AudioOcarina_SetRecordingSong(true);
return;
}
- sStaffOcarinaPlayingPos = true;
+ sStaffOcarinaPlayingPos = 1;
}
noteChanged = true;
- } else if (D_80131868 != sCurOcarinaVolume) {
- noteChanged = true;
- } else if (D_8013186C != sCurOcarinaVibrato) {
+ } else if (sRecordOcarinaVolume != sCurOcarinaVolume) {
noteChanged = true;
- } else if (D_80131870 != sCurOcarinaBendIndex) {
+ } else if (sRecordOcarinaVibrato != sCurOcarinaVibrato) {
+ // PAL/NTSC 1.1 version
+ if (sRecordingState != OCARINA_RECORD_SCARECROW_SPAWN) {
+ noteChanged = true;
+ }
noteChanged = true;
+ } else if (sRecordOcarinaBendIndex != sCurOcarinaBendIndex) {
+ // PAL/NTSC 1.1 version
+ if (sRecordingState != OCARINA_RECORD_SCARECROW_SPAWN) {
+ noteChanged = true;
+ }
}
if (noteChanged) {
- func_800EDD68(0);
- D_80131860 = D_8016BA04;
+ AudioOcarina_SetRecordingSong(false);
+ sOcarinaRecordTaskStart = sOcarinaUpdateTaskStart;
}
}
}
-void Audio_OcaMemoryGameStart(u8 minigameRound) {
+void AudioOcarina_MemoryGameInit(u8 minigameRound) {
u8 i;
// #region SOH [Enhancement]
@@ -2127,11 +2342,11 @@ void Audio_OcaMemoryGameStart(u8 minigameRound) {
minigameRound = 2;
}
- sOcaMinigameAppendPos = 0;
- sOcaMinigameEndPos = modMinigameNoteCnts[minigameRound];
+ sOcaMemoryGameAppendPos = 0;
+ sOcaMemoryGameEndPos = modMinigameNoteCnts[minigameRound];
for (i = 0; i < startingNotes; i++) {
- Audio_OcaMemoryGameGenNote();
+ AudioOcarina_MemoryGameNextNote();
}
// #endregion
} else {
@@ -2139,28 +2354,28 @@ void Audio_OcaMemoryGameStart(u8 minigameRound) {
minigameRound = 2;
}
- sOcaMinigameAppendPos = 0;
- sOcaMinigameEndPos = sOcaMinigameNoteCnts[minigameRound];
+ sOcaMemoryGameAppendPos = 0;
+ sOcaMemoryGameEndPos = sOcaMemoryGameNumNotes[minigameRound];
for (i = 0; i < 3; i++) {
- Audio_OcaMemoryGameGenNote();
+ AudioOcarina_MemoryGameNextNote();
}
}
}
-s32 Audio_OcaMemoryGameGenNote(void) {
- u32 rnd;
- u8 rndNote;
+s32 AudioOcarina_MemoryGameNextNote(void) {
+ u32 randomButtonIndex;
+ u8 randomPitch;
- if (sOcaMinigameAppendPos == sOcaMinigameEndPos) {
+ if (sOcaMemoryGameAppendPos == sOcaMemoryGameEndPos) {
return 1;
}
- rnd = Audio_NextRandom();
- rndNote = sOcarinaNoteValues[rnd % 5];
+ randomButtonIndex = Audio_NextRandom();
+ randomPitch = sButtonToPitchMap[randomButtonIndex % 5];
- if (sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos - 1].noteIdx == rndNote) {
- rndNote = sOcarinaNoteValues[(rnd + 1) % 5];
+ if (sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos - 1].pitch == randomPitch) {
+ randomPitch = sButtonToPitchMap[(randomButtonIndex + 1) % 5];
}
// #region SOH [Enhancement]
@@ -2168,107 +2383,108 @@ s32 Audio_OcaMemoryGameGenNote(void) {
int noteSpeed = 0x2D;
noteSpeed = noteSpeed / CVarGetInteger(CVAR_ENHANCEMENT("OcarinaGame.NoteSpeed"), 1);
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].noteIdx = rndNote;
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].unk_02 = noteSpeed;
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].volume = 0x50;
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].vibrato = 0;
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].tone = 0;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos].pitch = randomPitch;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos].length = noteSpeed;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos].volume = 0x50;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos].vibrato = 0;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos].bend = 0;
// #endregion
} else {
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].noteIdx = rndNote;
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].unk_02 = 0x2D;
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].volume = 0x50;
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].vibrato = 0;
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].tone = 0;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos].pitch = randomPitch;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos].length = 0x2D;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos].volume = 0x50;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos].vibrato = 0;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos].bend = 0;
}
- sOcaMinigameAppendPos++;
+ sOcaMemoryGameAppendPos++;
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].noteIdx = 0xFF;
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].unk_02 = 0;
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos + 1].noteIdx = 0xFF;
- sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos + 1].unk_02 = 0;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos].pitch = OCARINA_PITCH_NONE;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos].length = 0;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos + 1].pitch = OCARINA_PITCH_NONE;
+ sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos + 1].length = 0;
return 0;
}
-// input update?
-void func_800EE6F4(void) {
- D_8016BA04 = gAudioContext.totalTaskCnt;
- if (sOcarinaInstrumentId != 0) {
- if (sIsOcarinaInputEnabled == 1) {
- Audio_GetOcaInput();
+void AudioOcarina_Update(void) {
+ sOcarinaUpdateTaskStart = gAudioContext.totalTaskCnt;
+ if (sOcarinaInstrumentId != OCARINA_INSTRUMENT_OFF) {
+ if (sIsOcarinaInputEnabled == true) {
+ AudioOcarina_ReadControllerInput();
}
- if ((sPlaybackState == 0) && (sIsOcarinaInputEnabled == 1)) {
- func_800ED458(0);
+ if ((sPlaybackState == 0) && (sIsOcarinaInputEnabled == true)) {
+ AudioOcarina_PlayControllerInput(false);
}
if (sOcarinaFlags != 0) {
if (sOcarinaFlags & 0x4000) {
- func_800ED200();
+ AudioOcarina_CheckSongsWithoutMusicStaff();
} else {
- func_800ECDF8();
+ AudioOcarina_CheckSongsWithMusicStaff();
}
}
- Audio_OcaPlayback();
- D_80130F68 = D_8016BA04;
+ AudioOcarina_PlaybackSong();
+ sOcarinaPlaybackTaskStart = sOcarinaUpdateTaskStart;
if (sPlaybackState == 0) {
- func_800EE404();
+ AudioOcarina_RecordSong();
}
if ((sOcarinaFlags != 0) && (sPrevOcarinaPitch != sCurOcarinaPitch)) {
- sOcarinaDropInputTimer = 1;
+ sOcarinaDropInputTimer = 1; // Drops ocarina input for 1 frame
}
sPrevOcarinaPitch = sCurOcarinaPitch;
}
- Audio_OcaUpdatePlayingStaff();
- Audio_OcaUpdateDisplayedStaff();
- Audio_OcaUpdateRecordingStaff();
+ AudioOcarina_UpdatePlayingStaff();
+ AudioOcarina_UpdatePlaybackStaff();
+ AudioOcarina_UpdateRecordingStaff();
}
-void func_800EE824(void) {
- static u8 D_80131C80 = 0;
- static u8 D_80131C84 = 1;
- static u16 D_80131C88 = 1200;
+void AudioOcarina_PlayLongScarecrowSong(void) {
+ static u8 sScarecrowAfterCreditsState = 0;
+ static u8 sScarecrowAfterCreditsIntrumentId = OCARINA_INSTRUMENT_DEFAULT;
+ static u16 sScarecrowAfterCreditsTimer = 1200;
- switch (D_80131C80) {
+ switch (sScarecrowAfterCreditsState) {
case 0:
- if (D_80131C88-- == 0) {
- if (D_80131C84 < 7) {
- D_80131C80++;
+ if (sScarecrowAfterCreditsTimer-- == 0) {
+ if (sScarecrowAfterCreditsIntrumentId < OCARINA_INSTRUMENT_MAX) {
+ // set next ocarina instrument and restart
+ sScarecrowAfterCreditsState++;
} else {
- D_80131C80 = 3;
- AudioOcarina_SetInstrument(0);
+ // finished
+ sScarecrowAfterCreditsState = 3;
+ AudioOcarina_SetInstrument(OCARINA_INSTRUMENT_OFF);
}
- D_80131C88 = 1200;
+ sScarecrowAfterCreditsTimer = 1200;
}
break;
case 1:
- Audio_SetSoundBanksMute(0);
- AudioOcarina_SetInstrument(D_80131C84);
- Audio_OcaSetSongPlayback(OCARINA_SONG_SCARECROW_LONG + 1, 1);
- D_80131C84++;
- D_80131C80++;
+ Audio_SetSfxBanksMute(0);
+ AudioOcarina_SetInstrument(sScarecrowAfterCreditsIntrumentId);
+ AudioOcarina_SetPlaybackSong(OCARINA_SONG_SCARECROW_LONG + 1, 1);
+ sScarecrowAfterCreditsIntrumentId++;
+ sScarecrowAfterCreditsState++;
break;
case 2:
- if (Audio_OcaGetDisplayingStaff()->state == 0) {
- D_80131C80 = 0;
+ if (AudioOcarina_GetPlaybackStaff()->state == 0) {
+ sScarecrowAfterCreditsState = 0;
}
break;
}
}
-void func_800EE930(void) {
- sPlayingStaff.noteIdx = OCARINA_NOTE_INVALID;
+void AudioOcarina_ResetStaffs(void) {
+ sPlayingStaff.buttonIndex = OCARINA_BTN_INVALID;
sPlayingStaff.state = 0xFF;
sPlayingStaff.pos = 0;
- sDisplayedStaff.noteIdx = OCARINA_NOTE_INVALID;
- sDisplayedStaff.state = 0;
- sDisplayedStaff.pos = 0;
- sRecordingStaff.noteIdx = OCARINA_NOTE_INVALID;
- sRecordingStaff.state = 0xFF;
+ sPlaybackStaff.buttonIndex = OCARINA_BTN_INVALID;
+ sPlaybackStaff.state = 0;
+ sPlaybackStaff.pos = 0;
+ sRecordingStaff.buttonIndex = OCARINA_BTN_INVALID;
+ sRecordingStaff.state = OCARINA_RECORD_REJECTED;
sRecordingStaff.pos = 0;
sOcarinaDropInputTimer = 0;
}
@@ -2277,7 +2493,7 @@ f32 D_80131C8C = 0.0f;
// === Audio Debugging ===
-// These variables come between in-function statics in func_800EE824 and Audio_SplitBgmChannels
+// These variables come between in-function statics in AudioOcarina_PlayLongScarecrowSong and Audio_SplitBgmChannels
f32 sAudioUpdateDuration = 0.0f;
f32 sAudioUpdateDurationMax = 0.0f;
@@ -2933,11 +3149,11 @@ void AudioDebug_Draw(GfxPrint* printer) {
case PAGE_OCARINA_TEST:
SETCOL(255, 255, 255);
GfxPrint_SetPos(printer, 3, 4);
- GfxPrint_Printf(printer, "SEQ INFO : %2d %02x %d", sDisplayedStaff.noteIdx, sDisplayedStaff.state,
- sDisplayedStaff.pos);
+ GfxPrint_Printf(printer, "SEQ INFO : %2d %02x %d", sPlaybackStaff.buttonIndex, sPlaybackStaff.state,
+ sPlaybackStaff.pos);
GfxPrint_SetPos(printer, 3, 5);
- GfxPrint_Printf(printer, "PLAY INFO : %2d %02x %d", sPlayingStaff.noteIdx, sPlayingStaff.state,
+ GfxPrint_Printf(printer, "PLAY INFO : %2d %02x %d", sPlayingStaff.buttonIndex, sPlayingStaff.state,
sPlayingStaff.pos);
GfxPrint_SetPos(printer, 3, 6);
@@ -3017,7 +3233,7 @@ void AudioDebug_Draw(GfxPrint* printer) {
GfxPrint_Printf(printer, "ENEMY DIST %f VOL %3d", sAudioEnemyDist, sAudioEnemyVol);
GfxPrint_SetPos(printer, 3, 11);
- GfxPrint_Printf(printer, "GANON DIST VOL %3d", sAudioGanonDistVol);
+ GfxPrint_Printf(printer, "GANON DIST VOL %3d", sGanonsTowerVol);
GfxPrint_SetPos(printer, 3, 12);
GfxPrint_Printf(printer, "DEMO FLAG %d", sAudioCutsceneFlag);
@@ -3149,7 +3365,7 @@ void AudioDebug_ProcessInput_SndCont(void) {
case 9:
break;
case 10:
- Audio_SetSoundBanksMute(sAudioSndContWork[sAudioSndContSel] * 0x7F);
+ Audio_SetSfxBanksMute(sAudioSndContWork[sAudioSndContSel] * 0x7F);
break;
}
}
@@ -3577,7 +3793,7 @@ void AudioDebug_ProcessInput(void) {
}
if (sAudioSfxMuted) {
- Audio_SetSoundBanksMute(0x6F);
+ Audio_SetSfxBanksMute(0x6F);
}
if (CHECK_BTN_ANY(sDebugPadPress, BTN_L)) {
@@ -3616,7 +3832,7 @@ void AudioDebug_ProcessInput(void) {
if (CHECK_BTN_ANY(sDebugPadPress, BTN_B)) {
sAudioSfxMuted ^= 1;
if (!sAudioSfxMuted) {
- Audio_SetSoundBanksMute(0);
+ Audio_SetSfxBanksMute(0);
}
}
break;
@@ -3658,11 +3874,14 @@ void AudioDebug_ProcessInput(void) {
void func_800F4A70(void);
void Audio_UpdateFanfare(void);
-void func_800F3054(void) {
+/**
+ * This is Audio_Update for the graph thread
+ */
+void Audio_Update(void) {
if (func_800FAD34() == 0) {
sAudioUpdateTaskStart = gAudioContext.totalTaskCnt;
sAudioUpdateStartTime = osGetTime();
- func_800EE6F4();
+ AudioOcarina_Update();
Audio_StepFreqLerp(&sRiverFreqScaleLerp);
Audio_StepFreqLerp(&sWaterfallFreqScaleLerp);
func_800F4A70();
@@ -3927,12 +4146,12 @@ s8 func_800F3990(f32 arg0, u16 sfxParams) {
return ret | 1;
}
-void Audio_SetSoundProperties(u8 bankId, u8 entryIdx, u8 channelIdx) {
+void Audio_SetSfxProperties(u8 bankId, u8 entryIdx, u8 channelIdx) {
f32 vol = 1.0f;
s8 volS8;
s8 reverb = 0;
f32 freqScale = 1.0f;
- s8 panSigned = 0x40;
+ s8 pan = 0x40;
u8 stereoBits = 0;
u8 filter = 0;
s8 sp38 = 0;
@@ -3946,7 +4165,7 @@ void Audio_SetSoundProperties(u8 bankId, u8 entryIdx, u8 channelIdx) {
case BANK_ENV:
case BANK_ENEMY:
case BANK_VOICE:
- if (D_80130604 == 2) {
+ if (sSoundOutputMode == 2) {
sp38 = func_800F3990(*entry->posY, entry->sfxParams);
}
// fallthrough
@@ -3954,9 +4173,9 @@ void Audio_SetSoundProperties(u8 bankId, u8 entryIdx, u8 channelIdx) {
entry->dist = sqrtf(entry->dist);
vol = Audio_ComputeSoundVolume(bankId, entryIdx) * *entry->vol;
reverb = Audio_ComputeSoundReverb(bankId, entryIdx, channelIdx);
- panSigned = Audio_ComputeSoundPanSigned(*entry->posX, *entry->posZ, entry->token);
+ pan = Audio_ComputeSoundPanSigned(*entry->posX, *entry->posZ, entry->token);
freqScale = Audio_ComputeSoundFreqScale(bankId, entryIdx) * *entry->freqScale;
- if (D_80130604 == 2) {
+ if (sSoundOutputMode == 2) {
behindScreenZ = sBehindScreenZ[(entry->sfxParams & 0x400) >> 10];
if (!(entry->sfxParams & 0x800)) {
if (*entry->posZ < behindScreenZ) {
@@ -3964,7 +4183,7 @@ void Audio_SetSoundProperties(u8 bankId, u8 entryIdx, u8 channelIdx) {
}
if ((sSfxChannelState[channelIdx].stereoBits ^ stereoBits) & 0x10) {
- if (panSigned < 0x40) {
+ if (pan < 0x40) {
stereoBits = sSfxChannelState[channelIdx].stereoBits ^ 0x14;
} else {
stereoBits = sSfxChannelState[channelIdx].stereoBits ^ 0x18;
@@ -3982,8 +4201,8 @@ void Audio_SetSoundProperties(u8 bankId, u8 entryIdx, u8 channelIdx) {
if ((baseFilter | sAudioExtraFilter) != 0) {
filter = (baseFilter | sAudioExtraFilter);
- } else if (D_80130604 == 2 && (entry->sfxParams & 0x2000) == 0) {
- filter = func_800F37B8(behindScreenZ, entry, panSigned);
+ } else if (sSoundOutputMode == 2 && (entry->sfxParams & 0x2000) == 0) {
+ filter = func_800F37B8(behindScreenZ, entry, pan);
}
break;
case BANK_SYSTEM:
@@ -4023,9 +4242,9 @@ void Audio_SetSoundProperties(u8 bankId, u8 entryIdx, u8 channelIdx) {
Audio_QueueCmdU16(0xD << 24 | SEQ_PLAYER_SFX << 16 | (channelIdx << 8), ((u16)(sp38) << 8) + 0xFF);
sSfxChannelState[channelIdx].unk_0C = sp38;
}
- if (panSigned != sSfxChannelState[channelIdx].panSigned) {
- Audio_QueueCmdS8(0x3 << 24 | SEQ_PLAYER_SFX << 16 | (channelIdx << 8), panSigned);
- sSfxChannelState[channelIdx].panSigned = panSigned;
+ if (pan != sSfxChannelState[channelIdx].pan) {
+ Audio_QueueCmdS8(0x3 << 24 | SEQ_PLAYER_SFX << 16 | (channelIdx << 8), pan);
+ sSfxChannelState[channelIdx].pan = pan;
}
}
@@ -4038,13 +4257,13 @@ void Audio_ResetSfxChannelState(void) {
state->vol = 1.0f;
state->freqScale = 1.0f;
state->reverb = 0;
- state->panSigned = 0x40;
+ state->pan = 0x40;
state->stereoBits = 0;
state->filter = 0xFF;
state->unk_0C = 0xFF;
}
- sSfxChannelState[SFX_PLAYER_CHANNEL_OCARINA].unk_0C = 0;
+ sSfxChannelState[SFX_CHANNEL_OCARINA].unk_0C = 0;
sPrevSeqMode = 0;
sAudioCodeReverb = 0;
}
@@ -4171,14 +4390,14 @@ void Audio_PlaySoundRandom(Vec3f* pos, u16 baseSfxId, u8 randLim) {
void func_800F4254(Vec3f* pos, u8 level) {
level &= 3;
if (level != sPrevChargeLevel) {
- D_801305F4 = D_801305E4[level];
+ sSfxSwordChargeFreq = sSfxSwordChargeFreqLevels[level];
switch (level) {
case 1:
- Audio_PlaySoundGeneral(NA_SE_PL_SWORD_CHARGE, pos, 4, &D_801305F4, &gSfxDefaultFreqAndVolScale,
+ Audio_PlaySoundGeneral(NA_SE_PL_SWORD_CHARGE, pos, 4, &sSfxSwordChargeFreq, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultReverb);
break;
case 2:
- Audio_PlaySoundGeneral(NA_SE_PL_SWORD_CHARGE, pos, 4, &D_801305F4, &gSfxDefaultFreqAndVolScale,
+ Audio_PlaySoundGeneral(NA_SE_PL_SWORD_CHARGE, pos, 4, &sSfxSwordChargeFreq, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultReverb);
break;
}
@@ -4187,8 +4406,8 @@ void func_800F4254(Vec3f* pos, u8 level) {
}
if (level != 0) {
- Audio_PlaySoundGeneral(NA_SE_IT_SWORD_CHARGE - SFX_FLAG, pos, 4, &D_801305F4, &gSfxDefaultFreqAndVolScale,
- &gSfxDefaultReverb);
+ Audio_PlaySoundGeneral(NA_SE_IT_SWORD_CHARGE - SFX_FLAG, pos, 4, &sSfxSwordChargeFreq,
+ &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
}
}
@@ -4302,19 +4521,19 @@ void func_800F4870(u8 arg0) {
}
if (arg0 == 7) {
- D_80130600 = 2;
+ sEnterGanonsTowerTimer = 2;
} else {
- Audio_SetGanonDistVol(D_801305F8[arg0 & 7]);
+ Audio_SetGanonsTowerBgmVolume(sGanonsTowerLevelsVol[arg0 & 7]);
}
}
// (name derived from debug strings, should probably update. used in ganon/ganon_boss scenes)
-s32 Audio_SetGanonDistVol(u8 targetVol) {
+s32 Audio_SetGanonsTowerBgmVolume(u8 targetVol) {
u8 phi_v0;
u16 phi_v0_2;
u8 i;
- if (sAudioGanonDistVol != targetVol) {
+ if (sGanonsTowerVol != targetVol) {
Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 0, targetVol, 2);
if (targetVol < 0x40) {
phi_v0 = 0x10;
@@ -4340,34 +4559,34 @@ s32 Audio_SetGanonDistVol(u8 targetVol) {
}
}
}
- sAudioGanonDistVol = targetVol;
+ sGanonsTowerVol = targetVol;
}
return -1;
}
void func_800F4A54(u8 arg0) {
- D_8016B8B0 = arg0;
- D_8016B8B2 = 1;
+ sRiverSoundMainBgmVol = arg0;
+ sRiverSoundMainBgmLower = 1;
}
void func_800F4A70(void) {
- if (D_8016B8B2 == 1) {
- if (D_8016B8B1 != D_8016B8B0) {
- Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 0, D_8016B8B0, 0xA);
- D_8016B8B1 = D_8016B8B0;
- D_8016B8B3 = 1;
- }
- D_8016B8B2 = 0;
- } else if (D_8016B8B3 == 1 && D_80130608 == 0) {
+ if (sRiverSoundMainBgmLower == 1) {
+ if (sRiverSoundMainBgmCurrentVol != sRiverSoundMainBgmVol) {
+ Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 0, sRiverSoundMainBgmVol, 0xA);
+ sRiverSoundMainBgmCurrentVol = sRiverSoundMainBgmVol;
+ sRiverSoundMainBgmRestore = 1;
+ }
+ sRiverSoundMainBgmLower = 0;
+ } else if (sRiverSoundMainBgmRestore == 1 && D_80130608 == 0) {
Audio_SetVolScale(SEQ_PLAYER_BGM_MAIN, 0, 0x7F, 0xA);
- D_8016B8B1 = 0x7F;
- D_8016B8B3 = 0;
+ sRiverSoundMainBgmCurrentVol = 0x7F;
+ sRiverSoundMainBgmRestore = 0;
}
- if (D_80130600 != 0) {
- D_80130600--;
- if (D_80130600 == 0) {
- Audio_SetGanonDistVol(D_801305F8[7]);
+ if (sEnterGanonsTowerTimer != 0) {
+ sEnterGanonsTowerTimer--;
+ if (sEnterGanonsTowerTimer == 0) {
+ Audio_SetGanonsTowerBgmVolume(sGanonsTowerLevelsVol[7]);
}
}
}
@@ -4575,23 +4794,23 @@ void Audio_PlaySceneSequence(u16 seqId) {
Audio_QueueCmdS32(0xF8000000, 0);
}
- if ((Audio_GetSeqFlags(D_80130630) & 0x20) && Audio_GetSeqFlags((seqId & 0xFF) & 0xFF) & 0x10) {
+ if ((Audio_GetSeqFlags(sPrevSceneSeqId) & 0x20) && Audio_GetSeqFlags((seqId & 0xFF) & 0xFF) & 0x10) {
- if ((D_8013062C & 0x3F) != 0) {
+ if ((sSeqResumePoint & 0x3F) != 0) {
sp27 = 0x1E;
}
- Audio_PlaySequenceWithSeqPlayerIO(SEQ_PLAYER_BGM_MAIN, seqId, sp27, 7, D_8013062C);
+ Audio_PlaySequenceWithSeqPlayerIO(SEQ_PLAYER_BGM_MAIN, seqId, sp27, 7, sSeqResumePoint);
- D_8013062C = 0;
+ sSeqResumePoint = 0;
} else {
nv = (Audio_GetSeqFlags((seqId & 0xFF) & 0xFF) & 0x40) ? 1 : 0xFF;
Audio_PlaySequenceWithSeqPlayerIO(SEQ_PLAYER_BGM_MAIN, seqId, 0, 7, nv);
if (!(Audio_GetSeqFlags(seqId) & 0x20)) {
- D_8013062C = 0xC0;
+ sSeqResumePoint = 0xC0;
}
}
- D_80130630 = seqId & 0xFF;
+ sPrevSceneSeqId = seqId & 0xFF;
}
}
@@ -4602,10 +4821,10 @@ void Audio_UpdateSceneSequenceResumePoint(void) {
temp_v0 = func_800FA0B4(SEQ_PLAYER_BGM_MAIN);
bvar = temp_v0 & 0xFF;
if ((temp_v0 != NA_BGM_DISABLED) && (Audio_GetSeqFlags(bvar) & 0x10)) {
- if (D_8013062C != 0xC0) {
- D_8013062C = gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3];
+ if (sSeqResumePoint != 0xC0) {
+ sSeqResumePoint = gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3];
} else {
- D_8013062C = 0;
+ sSeqResumePoint = 0;
}
}
}
@@ -4764,16 +4983,16 @@ void Audio_PlayFanfare(u16 seqId) {
if (!curFontId || !requestedFontId) {
// disable BGM, we're about to null deref!
- D_8016B9F4 = 1;
+ sFanfareStartTimer = 1;
} else {
if ((curSeqId == NA_BGM_DISABLED) || (*curFontId == *requestedFontId)) {
- D_8016B9F4 = 1;
+ sFanfareStartTimer = 1;
} else {
- D_8016B9F4 = 5;
+ sFanfareStartTimer = 5;
Audio_SeqCmd1(SEQ_PLAYER_FANFARE, 0);
}
}
- D_8016B9F6 = seqId;
+ sFanfareSeqId = seqId;
}
void Audio_UpdateFanfare(void) {
@@ -4781,9 +5000,9 @@ void Audio_UpdateFanfare(void) {
u16 pad;
u16 sp22;
- if (D_8016B9F4 != 0) {
- D_8016B9F4--;
- if (D_8016B9F4 == 0) {
+ if (sFanfareStartTimer != 0) {
+ sFanfareStartTimer--;
+ if (sFanfareStartTimer == 0) {
Audio_QueueCmdS32(0xE3000000, SEQUENCE_TABLE);
Audio_QueueCmdS32(0xE3000000, FONT_TABLE);
func_800FA0B4(SEQ_PLAYER_BGM_MAIN);
@@ -4799,7 +5018,7 @@ void Audio_UpdateFanfare(void) {
Audio_SeqCmdC(SEQ_PLAYER_FANFARE, 0x93, 0, 0);
}
}
- Audio_StartSeq(SEQ_PLAYER_FANFARE, 1, D_8016B9F6);
+ Audio_StartSeq(SEQ_PLAYER_FANFARE, 1, sFanfareSeqId);
Audio_SeqCmdA(0, 0xFFFF);
if (sp22 != NA_BGM_LONLON) {
Audio_SeqCmdA(SEQ_PLAYER_BGM_SUB, 0xFFFF);
@@ -4919,7 +5138,7 @@ void Audio_UpdateMalonSinging(f32 dist, u16 arg1) {
sIsMalonSinging = true;
sMalonSingingDist = dist;
- if (D_8016B9F2 == 0) {
+ if (sMalonSingingDisabled == 0) {
temp_a0 = (s8)(func_800FA0B4(SEQ_PLAYER_BGM_MAIN) & 0xFF);
if (temp_a0 == (arg1 & 0xFF)) {
if ((arg1 & 0xFF) == NA_BGM_LONLON) {
@@ -4935,16 +5154,16 @@ void Audio_UpdateMalonSinging(f32 dist, u16 arg1) {
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++;
+ if (sMalonSingingTimer == 0) {
+ sMalonSingingTimer++;
}
}
} 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)) {
+ if ((temp_a0 != (arg1 & 0xFF)) && (sMalonSingingTimer < 10)) {
Audio_PlaySequenceWithSeqPlayerIO(SEQ_PLAYER_BGM_SUB, NA_BGM_LONLON, 0, 0, 0);
Audio_SeqCmdA(SEQ_PLAYER_BGM_SUB, 0xFFFC);
- D_8016B9D8 = 10;
+ sMalonSingingTimer = 10;
}
if (dist > 2000.0f) {
@@ -4959,8 +5178,8 @@ void Audio_UpdateMalonSinging(f32 dist, u16 arg1) {
Audio_SeqCmd6(SEQ_PLAYER_BGM_SUB, 3, 1, 127 - phi_v1);
}
- if (D_8016B9D8 < 10) {
- D_8016B9D8++;
+ if (sMalonSingingTimer < 10) {
+ sMalonSingingTimer++;
}
}
}
@@ -4982,7 +5201,7 @@ void Audio_ToggleMalonSinging(u8 arg0) {
u8 playerIdx;
u16 sp34;
- D_8016B9F2 = arg0;
+ sMalonSingingDisabled = arg0;
if ((func_800FA0B4(SEQ_PLAYER_BGM_MAIN) & 0xFF) == NA_BGM_LONLON) {
playerIdx = SEQ_PLAYER_BGM_MAIN;
sp34 = 0;
@@ -5027,25 +5246,25 @@ void Audio_SetSoundOutputMode(s8 arg0) {
switch (arg0) {
case 0:
sp1F = 0;
- D_80130604 = 0;
+ sSoundOutputMode = 0;
// SOH [Port] Inform LUS of audio setting change
SetAudioChannels(audioStereo);
break;
case 1:
sp1F = 3;
- D_80130604 = 3;
+ sSoundOutputMode = 3;
// SOH [Port] Inform LUS of audio setting change
SetAudioChannels(audioStereo);
break;
case 2:
sp1F = 1;
- D_80130604 = 1;
+ sSoundOutputMode = 1;
// SOH [Port] Inform LUS of audio setting change
SetAudioChannels(audioStereo);
break;
case 3:
sp1F = 0;
- D_80130604 = 2;
+ sSoundOutputMode = 2;
// SOH [Port] Inform LUS of audio setting change
SetAudioChannels(audioMatrix51);
break;
@@ -5134,7 +5353,7 @@ void Audio_StopBgmAndFanfare(u16 arg0) {
}
void func_800F6B3C(void) {
- func_800F9280(SEQ_PLAYER_SFX, 0, 0xFF, 5);
+ Audio_StartSequence(SEQ_PLAYER_SFX, 0, 0xFF, 5);
}
void Audio_DisableAllSeq(void) {
@@ -5171,26 +5390,26 @@ void func_800F6C34(void) {
sAudioExtraFilter = 0;
sAudioBaseFilter2 = 0;
sAudioExtraFilter2 = 0;
- AudioOcarina_SetInstrument(0);
+ AudioOcarina_SetInstrument(OCARINA_INSTRUMENT_OFF);
sRiverFreqScaleLerp.remainingFrames = 0;
sWaterfallFreqScaleLerp.remainingFrames = 0;
sRiverFreqScaleLerp.value = 1.0f;
sWaterfallFreqScaleLerp.value = 1.0f;
D_8016B7D8 = 1.0f;
- D_8016B8B0 = 0x7F;
- D_8016B8B1 = 0x7F;
- D_8016B8B2 = 0;
- D_8016B8B3 = 0;
- sAudioGanonDistVol = 0xFF;
- D_8016B9D8 = 0;
+ sRiverSoundMainBgmVol = 0x7F;
+ sRiverSoundMainBgmCurrentVol = 0x7F;
+ sRiverSoundMainBgmLower = 0;
+ sRiverSoundMainBgmRestore = 0;
+ sGanonsTowerVol = 0xFF;
+ sMalonSingingTimer = 0;
sSpecReverb = sSpecReverbs[gAudioSpecId];
D_80130608 = 0;
sPrevMainBgmSeqId = NA_BGM_DISABLED;
Audio_QueueCmdS8(0x46 << 24 | SEQ_PLAYER_BGM_MAIN << 16, -1);
sSariaBgmPtr = NULL;
- D_8016B9F4 = 0;
+ sFanfareStartTimer = 0;
D_8016B9F3 = 1;
- D_8016B9F2 = 0;
+ sMalonSingingDisabled = 0;
}
void Audio_SetNatureAmbienceChannelIO(u8 channelIdxRange, u8 port, u8 val) {
@@ -5206,7 +5425,7 @@ void Audio_SetNatureAmbienceChannelIO(u8 channelIdxRange, u8 port, u8 val) {
// 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;
+ sMalonSingingTimer = 0;
}
}
@@ -5274,7 +5493,7 @@ void Audio_PlayNatureAmbienceSequence(u8 natureAmbienceId) {
Audio_QueueSeqCmd(0x80000000 | (SEQ_PLAYER_BGM_MAIN << 24) | (port << 0x10) | (channelIdx << 8) | val);
}
- Audio_SeqCmd8(SEQ_PLAYER_BGM_MAIN, CHANNEL_IO_PORT_7, NATURE_CHANNEL_UNK, D_80130604);
+ Audio_SeqCmd8(SEQ_PLAYER_BGM_MAIN, CHANNEL_IO_PORT_7, NATURE_CHANNEL_UNK, sSoundOutputMode);
}
}
@@ -5284,15 +5503,15 @@ void Audio_Init(void) {
void Audio_InitSound(void) {
func_800F6C34();
- func_800EE930();
+ AudioOcarina_ResetStaffs();
Audio_ResetSfxChannelState();
func_800FAEB4();
Audio_ResetSounds();
- 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);
@@ -5301,7 +5520,7 @@ void func_800F7170(void) {
void func_800F71BC(s32 arg0) {
D_80133418 = 1;
func_800F6C34();
- func_800EE930();
+ AudioOcarina_ResetStaffs();
Audio_ResetSfxChannelState();
Audio_ResetActiveSequences();
Audio_ResetSounds();
@@ -5312,5 +5531,5 @@ void func_800F7208(void) {
Audio_QueueCmdS32(0xF2000000, 1);
func_800F6C34();
Audio_ResetSfxChannelState();
- func_800F9280(SEQ_PLAYER_SFX, 0, 0x70, 1);
+ Audio_StartSequence(SEQ_PLAYER_SFX, 0, 0x70, 1);
}