summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio/debug.inc.c47
-rw-r--r--src/audio/general.c271
-rw-r--r--src/audio/lib/effects.c42
-rw-r--r--src/audio/lib/heap.c49
-rw-r--r--src/audio/lib/load.c19
-rw-r--r--src/audio/lib/playback.c42
-rw-r--r--src/audio/lib/seqplayer.c154
-rw-r--r--src/audio/lib/synthesis.c71
-rw-r--r--src/audio/lib/thread.c458
-rw-r--r--src/audio/sequence.c135
-rw-r--r--src/audio/session_config.c8
-rw-r--r--src/audio/sfx.c66
-rw-r--r--src/code/audio_thread_manager.c2
-rw-r--r--src/code/game.c2
-rw-r--r--src/code/graph.c2
-rw-r--r--src/code/speed_meter.c4
16 files changed, 682 insertions, 690 deletions
diff --git a/src/audio/debug.inc.c b/src/audio/debug.inc.c
index c400306e0..5af3030f3 100644
--- a/src/audio/debug.inc.c
+++ b/src/audio/debug.inc.c
@@ -240,7 +240,7 @@ void AudioDebug_Draw(GfxPrint* printer) {
for (k2 = 0; k2 < gChannelsPerBank[gSfxChannelLayout][k]; k2++) {
#define entryIndex (gActiveSfx[k][k2].entryIndex)
#define entry (&gSfxBanks[k][entryIndex])
-#define chan (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[entry->channelIdx])
+#define chan (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[entry->channelIndex])
GfxPrint_SetPos(printer, 2 + sAudioIntInfoX, 5 + ind + sAudioIntInfoY);
if (sAudioIntInfoBankPage[k] == 1) {
if ((entryIndex != 0xFF) &&
@@ -265,7 +265,7 @@ void AudioDebug_Draw(GfxPrint* printer) {
((entry->state == SFX_STATE_PLAYING_1) || (entry->state == SFX_STATE_PLAYING_2))) {
GfxPrint_Printf(printer, "%2X %5d %5d %5d %3d %3d %04X", entryIndex, (s32)*entry->posX,
(s32)*entry->posY, (s32)*entry->posZ, (s32)(chan->freqScale * 100.0f),
- chan->reverb, entry->sfxId);
+ chan->targetReverbVol, entry->sfxId);
} else {
GfxPrint_Printf(printer, "FF ----- ----- ----- --- --- ----");
}
@@ -410,7 +410,7 @@ void AudioDebug_Draw(GfxPrint* printer) {
}
GfxPrint_SetPos(printer, 15 + i, 8);
- if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->stopSomething2) {
+ if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->muted) {
GfxPrint_Printf(printer, "O");
} else {
GfxPrint_Printf(printer, "X");
@@ -476,7 +476,7 @@ void AudioDebug_Draw(GfxPrint* printer) {
GfxPrint_Printf(printer, "%02X ",
(u8)gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel]
.channels[sAudioSubTrackInfoChannelSel]
- ->soundScriptIO[i]);
+ ->seqScriptIO[i]);
}
if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->enabled) {
@@ -526,9 +526,10 @@ void AudioDebug_Draw(GfxPrint* printer) {
->panChannelWeight);
GfxPrint_SetPos(printer, 15, 17);
- GfxPrint_Printf(
- printer, "%d",
- gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->reverb);
+ GfxPrint_Printf(printer, "%d",
+ gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel]
+ .channels[sAudioSubTrackInfoChannelSel]
+ ->targetReverbVol);
GfxPrint_SetPos(printer, 15, 18);
GfxPrint_Printf(printer, "%d",
@@ -547,7 +548,7 @@ void AudioDebug_Draw(GfxPrint* printer) {
GfxPrint_Printf(printer, "%d",
(u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel]
.channels[sAudioSubTrackInfoChannelSel]
- ->vibratoExtentTarget /
+ ->vibratoDepthTarget /
8));
GfxPrint_SetPos(printer, 15, 21);
@@ -623,35 +624,33 @@ void AudioDebug_Draw(GfxPrint* printer) {
SETCOL(255, 255, 255);
GfxPrint_SetPos(printer, 3, 7);
- GfxPrint_Printf(printer, "NEXT SCENE %02X %s",
- (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2],
- sAudioSceneNames[(u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2]]);
+ GfxPrint_Printf(printer, "NEXT SCENE %02X %s", (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[2],
+ sAudioSceneNames[(u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[2]]);
GfxPrint_SetPos(printer, 3, 8);
- GfxPrint_Printf(printer, "NOW SCENE %02X %s",
- (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4],
- sAudioSceneNames[(u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4]]);
+ GfxPrint_Printf(printer, "NOW SCENE %02X %s", (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[4],
+ sAudioSceneNames[(u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[4]]);
GfxPrint_SetPos(printer, 3, 9);
GfxPrint_Printf(printer, "NOW BLOCK %02X",
- (gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5] + 1) & 0xFF);
+ (gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[5] + 1) & 0xFF);
GfxPrint_SetPos(printer, 3, 11);
GfxPrint_Printf(printer, "PORT");
GfxPrint_SetPos(printer, 3, 12);
GfxPrint_Printf(printer, "%02X %02X %02X %02X",
- (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[0],
- (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[1],
- (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2],
- (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]);
+ (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[0],
+ (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[1],
+ (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[2],
+ (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[3]);
GfxPrint_SetPos(printer, 3, 13);
GfxPrint_Printf(printer, "%02X %02X %02X %02X",
- (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4],
- (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5],
- (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[6],
- (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[7]);
+ (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[4],
+ (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[5],
+ (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[6],
+ (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[7]);
break;
case PAGE_OCARINA_TEST:
@@ -1174,7 +1173,7 @@ void AudioDebug_ProcessInput_BlkChgBgm(void) {
}
if (CHECK_BTN_ANY(sDebugPadPress, BTN_A)) {
- Audio_QueueCmdS8(MK_CMD(0x46, SEQ_PLAYER_BGM_MAIN, 0x00, 0x00), sAudioBlkChgBgmWork[1]);
+ AUDIOCMD_SEQPLAYER_SET_IO(SEQ_PLAYER_BGM_MAIN, 0, sAudioBlkChgBgmWork[1]);
SEQCMD_PLAY_SEQUENCE(SEQ_PLAYER_BGM_MAIN, 1, 0, sAudioBlkChgBgmWork[0]);
}
diff --git a/src/audio/general.c b/src/audio/general.c
index 881c98a93..a70a35823 100644
--- a/src/audio/general.c
+++ b/src/audio/general.c
@@ -1,18 +1,16 @@
#include "ultra64.h"
#include "global.h"
-#define Audio_DisableSeq(seqPlayerIndex, fadeOut) Audio_QueueCmdS32(0x83000000 | ((u8)seqPlayerIndex << 16), fadeOut)
-
#define ABS_ALT(x) ((x) < 0 ? -(x) : (x))
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;
+ /* 0xC */ u8 combFilterGain;
} SfxPlayerState;
typedef enum {
@@ -1728,7 +1726,7 @@ void AudioOcarina_PlayControllerInput(u8 unused) {
// Add vibrato of the ocarina note based on the x control stick
sCurOcarinaVibrato = ABS_ALT(sOcarinaInputStickAdj.x) >> 2;
// Sets vibrato to io port 6
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | SFX_CHANNEL_OCARINA << 8 | 6, sCurOcarinaVibrato);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 6, sCurOcarinaVibrato);
} else {
// no bending or vibrato for recording state OCARINA_RECORD_SCARECROW_SPAWN
sCurOcarinaBendIndex = 0;
@@ -1737,11 +1735,11 @@ void AudioOcarina_PlayControllerInput(u8 unused) {
// Processes new and valid notes
if ((sCurOcarinaPitch != OCARINA_PITCH_NONE) && (sPrevOcarinaPitch != sCurOcarinaPitch)) {
- // Sets ocarina instrument Id to channelIdx io port 7, which is used
+ // 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 | SFX_CHANNEL_OCARINA << 8 | 7, sOcarinaInstrumentId - 1);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 7, sOcarinaInstrumentId - 1);
// Sets pitch to io port 5
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | SFX_CHANNEL_OCARINA << 8 | 5, sCurOcarinaPitch);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 5, sCurOcarinaPitch);
Audio_PlaySfxGeneral(NA_SE_OC_OCARINA, &gSfxDefaultPos, 4, &sCurOcarinaBendFreq, &sRelativeOcarinaVolume,
&gSfxDefaultReverb);
} else if ((sPrevOcarinaPitch != OCARINA_PITCH_NONE) && (sCurOcarinaPitch == OCARINA_PITCH_NONE)) {
@@ -1879,7 +1877,7 @@ void AudioOcarina_PlaybackSong(void) {
if (sNotePlaybackVibrato != sPlaybackSong[sPlaybackNotePos].vibrato) {
sNotePlaybackVibrato = sPlaybackSong[sPlaybackNotePos].vibrato;
// Sets vibrato to io port 6
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | SFX_CHANNEL_OCARINA << 8 | 6, sNotePlaybackVibrato);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 6, sNotePlaybackVibrato);
}
// Update bend
@@ -1908,13 +1906,11 @@ void AudioOcarina_PlaybackSong(void) {
if (sPlaybackPitch != OCARINA_PITCH_NONE) {
sPlaybackStaffPos++;
- // Sets ocarina instrument Id to channelIdx io port 7, which is used
+ // 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 | SFX_CHANNEL_OCARINA << 8 | 7,
- sOcarinaInstrumentId - 1);
- // Sets sPlaybackPitch to channelIdx io port 5
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | SFX_CHANNEL_OCARINA << 8 | 5,
- sPlaybackPitch & 0x3F);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 7, sOcarinaInstrumentId - 1);
+ // Sets sPlaybackPitch to channelIndex io port 5
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, SFX_CHANNEL_OCARINA, 5, sPlaybackPitch & 0x3F);
Audio_PlaySfxGeneral(NA_SE_OC_OCARINA, &gSfxDefaultPos, 4, &sRelativeNotePlaybackBend,
&sRelativeNotePlaybackVolume, &gSfxDefaultReverb);
} else {
@@ -2198,7 +2194,7 @@ s32 AudioOcarina_MemoryGameNextNote(void) {
return 1;
}
- randomButtonIndex = Audio_NextRandom();
+ randomButtonIndex = AudioThread_NextRandom();
randomPitch = sButtonToPitchMap[randomButtonIndex % 5];
if (sOcarinaSongNotes[OCARINA_SONG_MEMORY_GAME][sOcaMemoryGameAppendPos - 1].pitch == randomPitch) {
@@ -2322,7 +2318,7 @@ void Audio_UpdateFanfare(void);
/**
* This is Audio_Update for the graph thread
*/
-void func_800F3054(void) {
+void Audio_Update(void) {
if (func_800FAD34() == 0) {
#if OOT_DEBUG
sAudioUpdateTaskStart = gAudioCtx.totalTaskCount;
@@ -2348,7 +2344,7 @@ void func_800F3054(void) {
AudioDebug_ProcessInput();
#endif
- Audio_ScheduleProcessCmds();
+ AudioThread_ScheduleProcessCmds();
#if OOT_DEBUG
sAudioUpdateTaskEnd = gAudioCtx.totalTaskCount;
@@ -2363,8 +2359,8 @@ void func_800F3138(UNK_TYPE arg0) {
void func_800F3140(UNK_TYPE arg0, UNK_TYPE arg1) {
}
-void func_800F314C(s8 arg0) {
- Audio_QueueCmdS32(0x82 << 24 | SEQ_PLAYER_BGM_MAIN << 16 | (((u8)arg0 & 0xFF) << 8), 1);
+void func_800F314C(s8 seqId) {
+ AUDIOCMD_GLOBAL_INIT_SEQPLAYER(SEQ_PLAYER_BGM_MAIN, (u8)seqId, 1);
}
f32 Audio_ComputeSfxVolume(u8 bankId, u8 entryIdx) {
@@ -2427,8 +2423,8 @@ s8 Audio_ComputeSfxReverb(u8 bankId, u8 entryIdx, u8 channelIdx) {
}
if (IS_SEQUENCE_CHANNEL_VALID(gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx])) {
- scriptAdd = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1];
- if (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1] <= SEQ_IO_VAL_NONE) {
+ scriptAdd = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->seqScriptIO[1];
+ if (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->seqScriptIO[1] <= SEQ_IO_VAL_NONE) {
scriptAdd = 0;
}
}
@@ -2588,28 +2584,28 @@ u8 func_800F37B8(f32 behindScreenZ, SfxBankEntry* arg1, s8 arg2) {
return (phi_v1 * 0x10) + (u8)((phi_f0 * phi_f12) / (10000.0f / 5.2f));
}
-s8 func_800F3990(f32 arg0, u16 sfxParams) {
- s8 ret = 0;
+s8 func_800F3990(f32 posY, u16 sfxParams) {
+ s8 combFilterGain = 0;
- if (arg0 >= 0.0f) {
- if (arg0 > 625.0f) {
- ret = 127;
+ if (posY >= 0.0f) {
+ if (posY > 625.0f) {
+ combFilterGain = 127;
} else {
- ret = (arg0 / 625.0f) * 126.0f;
+ combFilterGain = (posY / 625.0f) * 126.0f;
}
}
- return ret | 1;
+ return combFilterGain | 1;
}
-void Audio_SetSfxProperties(u8 bankId, u8 entryIdx, u8 channelIdx) {
+void Audio_SetSfxProperties(u8 bankId, u8 entryIdx, u8 channelIndex) {
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;
+ s8 combFilterGain = 0;
f32 behindScreenZ;
u8 baseFilter = 0;
SfxBankEntry* entry = &gSfxBanks[bankId][entryIdx];
@@ -2621,15 +2617,15 @@ void Audio_SetSfxProperties(u8 bankId, u8 entryIdx, u8 channelIdx) {
case BANK_ENEMY:
case BANK_VOICE:
if (sSoundMode == SOUNDMODE_SURROUND) {
- sp38 = func_800F3990(*entry->posY, entry->sfxParams);
+ combFilterGain = func_800F3990(*entry->posY, entry->sfxParams);
}
FALLTHROUGH;
case BANK_OCARINA:
entry->dist = sqrtf(entry->dist * SFX_DIST_SCALING);
vol = Audio_ComputeSfxVolume(bankId, entryIdx) * *entry->vol;
- reverb = Audio_ComputeSfxReverb(bankId, entryIdx, channelIdx);
- panSigned = Audio_ComputeSfxPanSigned(*entry->posX, *entry->posZ, entry->token);
+ reverb = Audio_ComputeSfxReverb(bankId, entryIdx, channelIndex);
+ pan = Audio_ComputeSfxPanSigned(*entry->posX, *entry->posZ, entry->token);
freqScale = Audio_ComputeSfxFreqScale(bankId, entryIdx) * *entry->freqScale;
if (sSoundMode == SOUNDMODE_SURROUND) {
@@ -2639,14 +2635,14 @@ void Audio_SetSfxProperties(u8 bankId, u8 entryIdx, u8 channelIdx) {
stereoBits = 0x10;
}
- if ((sSfxChannelState[channelIdx].stereoBits ^ stereoBits) & 0x10) {
- if (panSigned < 0x40) {
- stereoBits = sSfxChannelState[channelIdx].stereoBits ^ 0x14;
+ if ((sSfxChannelState[channelIndex].stereoBits ^ stereoBits) & 0x10) {
+ if (pan < 0x40) {
+ stereoBits = sSfxChannelState[channelIndex].stereoBits ^ 0x14;
} else {
- stereoBits = sSfxChannelState[channelIdx].stereoBits ^ 0x18;
+ stereoBits = sSfxChannelState[channelIndex].stereoBits ^ 0x18;
}
} else {
- stereoBits = sSfxChannelState[channelIdx].stereoBits;
+ stereoBits = sSfxChannelState[channelIndex].stereoBits;
}
}
}
@@ -2659,49 +2655,54 @@ void Audio_SetSfxProperties(u8 bankId, u8 entryIdx, u8 channelIdx) {
if ((baseFilter | sAudioExtraFilter) != 0) {
filter = (baseFilter | sAudioExtraFilter);
} else if ((sSoundMode == SOUNDMODE_SURROUND) && !(entry->sfxParams & SFX_FLAG_13)) {
- filter = func_800F37B8(behindScreenZ, entry, panSigned);
+ filter = func_800F37B8(behindScreenZ, entry, pan);
}
break;
case BANK_SYSTEM:
break;
}
- if (sSfxChannelState[channelIdx].vol != vol) {
+ if (sSfxChannelState[channelIndex].vol != vol) {
volS8 = (u8)(vol * 127.0f);
- sSfxChannelState[channelIdx].vol = vol;
+ sSfxChannelState[channelIndex].vol = vol;
} else {
volS8 = -1;
}
// CHAN_UPD_SCRIPT_IO (slot 2, sets volume)
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | (channelIdx << 8) | 2, volS8);
- if (reverb != sSfxChannelState[channelIdx].reverb) {
- Audio_QueueCmdS8(0x5 << 24 | SEQ_PLAYER_SFX << 16 | (channelIdx << 8), reverb);
- sSfxChannelState[channelIdx].reverb = reverb;
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, channelIndex, 2, volS8);
+
+ if (reverb != sSfxChannelState[channelIndex].reverb) {
+ AUDIOCMD_CHANNEL_SET_REVERB_VOLUME(SEQ_PLAYER_SFX, channelIndex, reverb);
+ sSfxChannelState[channelIndex].reverb = reverb;
}
- if (freqScale != sSfxChannelState[channelIdx].freqScale) {
- Audio_QueueCmdF32(0x4 << 24 | SEQ_PLAYER_SFX << 16 | (channelIdx << 8), freqScale);
- sSfxChannelState[channelIdx].freqScale = freqScale;
+
+ if (freqScale != sSfxChannelState[channelIndex].freqScale) {
+ AUDIOCMD_CHANNEL_SET_FREQ_SCALE(SEQ_PLAYER_SFX, channelIndex, freqScale);
+ sSfxChannelState[channelIndex].freqScale = freqScale;
}
- if (stereoBits != sSfxChannelState[channelIdx].stereoBits) {
- Audio_QueueCmdS8(0xE << 24 | SEQ_PLAYER_SFX << 16 | (channelIdx << 8), stereoBits | 0x10);
- sSfxChannelState[channelIdx].stereoBits = stereoBits;
+
+ //! @bug: comparing a `u8` to an `s8`. if the most significant bit is set,
+ //! it'll always pass because the s8 value will be <0 and the u8 value is always >=0
+ if (stereoBits != sSfxChannelState[channelIndex].stereoBits) {
+ AUDIOCMD_CHANNEL_SET_STEREO(SEQ_PLAYER_SFX, channelIndex, stereoBits | 0x10);
+ sSfxChannelState[channelIndex].stereoBits = stereoBits;
}
- if (filter != sSfxChannelState[channelIdx].filter) {
- // CHAN_UPD_SCRIPT_IO (slot 3, sets filter)
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | (channelIdx << 8) | 3, filter);
- sSfxChannelState[channelIdx].filter = filter;
+
+ if (filter != sSfxChannelState[channelIndex].filter) {
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, channelIndex, 3, filter);
+ sSfxChannelState[channelIndex].filter = filter;
}
- if (sp38 != sSfxChannelState[channelIdx].unk_0C) {
- // CHAN_UPD_UNK_0F
- Audio_QueueCmdS8(0xC << 24 | SEQ_PLAYER_SFX << 16 | (channelIdx << 8), 0x10);
- // CHAN_UPD_UNK_20
- Audio_QueueCmdU16(0xD << 24 | SEQ_PLAYER_SFX << 16 | (channelIdx << 8), ((u16)(sp38) << 8) + 0xFF);
- sSfxChannelState[channelIdx].unk_0C = sp38;
+
+ if (combFilterGain != sSfxChannelState[channelIndex].combFilterGain) {
+ AUDIOCMD_CHANNEL_SET_COMB_FILTER_SIZE(SEQ_PLAYER_SFX, channelIndex, 0x10);
+ AUDIOCMD_CHANNEL_SET_COMB_FILTER_GAIN(SEQ_PLAYER_SFX, channelIndex, ((u16)(combFilterGain) << 8) + 0xFF);
+ sSfxChannelState[channelIndex].combFilterGain = combFilterGain;
}
- if (panSigned != sSfxChannelState[channelIdx].panSigned) {
- Audio_QueueCmdS8(0x3 << 24 | SEQ_PLAYER_SFX << 16 | (channelIdx << 8), panSigned);
- sSfxChannelState[channelIdx].panSigned = panSigned;
+
+ if (pan != sSfxChannelState[channelIndex].pan) {
+ AUDIOCMD_CHANNEL_SET_PAN(SEQ_PLAYER_SFX, channelIndex, pan);
+ sSfxChannelState[channelIndex].pan = pan;
}
}
@@ -2714,13 +2715,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;
+ state->combFilterGain = 0xFF;
}
- sSfxChannelState[SFX_CHANNEL_OCARINA].unk_0C = 0;
+ sSfxChannelState[SFX_CHANNEL_OCARINA].combFilterGain = 0;
sPrevSeqMode = 0;
sAudioCodeReverb = 0;
}
@@ -2788,7 +2789,7 @@ void func_800F4190(Vec3f* pos, u16 sfxId) {
Audio_PlaySfxGeneral(sfxId, pos, 4, &D_801305B0, &gSfxDefaultFreqAndVolScale, &D_801305B4);
}
void Audio_PlaySfxRandom(Vec3f* pos, u16 baseSfxId, u8 randLim) {
- u8 offset = Audio_NextRandom() % randLim;
+ u8 offset = AudioThread_NextRandom() % randLim;
Audio_PlaySfxGeneral(baseSfxId + offset, pos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultReverb);
@@ -2916,19 +2917,17 @@ void Audio_SetMainBgmVolume(u8 targetVol, u8 volFadeTimer) {
* Incrementally increase volume of NA_BGM_GANON_TOWER for each new room during the climb of Ganon's Tower
*/
void Audio_SetGanonsTowerBgmVolumeLevel(u8 ganonsTowerLevel) {
- u8 channelIdx;
- s8 pan = 0;
+ u8 channelIndex;
+ s8 panChannelWeight = 0; // Pan comes entirely from the SequenceLayer
// Ganondorf's Lair
if (ganonsTowerLevel == 0) {
- pan = 0x7F;
+ // Pan comes entirely from the SequenceChannel
+ panChannelWeight = 0x7F;
}
- for (channelIdx = 0; channelIdx < 16; channelIdx++) {
- // CHAN_UPD_PAN_UNSIGNED
- Audio_QueueCmdS8(_SHIFTL(0x7, 24, 8) | _SHIFTL(SEQ_PLAYER_BGM_MAIN, 16, 8) | _SHIFTL(channelIdx, 8, 8) |
- _SHIFTL(0, 0, 8),
- pan);
+ for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
+ AUDIOCMD_CHANNEL_SET_PAN_WEIGHT(SEQ_PLAYER_BGM_MAIN, (u32)channelIndex, panChannelWeight);
}
// Lowest room in Ganon's Tower (Entrance Room)
@@ -2947,7 +2946,7 @@ void Audio_SetGanonsTowerBgmVolumeLevel(u8 ganonsTowerLevel) {
s32 Audio_SetGanonsTowerBgmVolume(u8 targetVol) {
u8 lowPassFilterCutoff;
u16 reverb;
- u8 channelIdx;
+ u8 channelIndex;
if (sGanonsTowerVol != targetVol) {
// Sets the volume
@@ -2966,22 +2965,19 @@ s32 Audio_SetGanonsTowerBgmVolume(u8 targetVol) {
SEQCMD_SET_CHANNEL_IO(SEQ_PLAYER_BGM_MAIN, 15, 4, lowPassFilterCutoff);
// Sets the reverb
- for (channelIdx = 0; channelIdx < 16; channelIdx++) {
- if (gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx] != &gAudioCtx.sequenceChannelNone) {
- // soundScriptIO[5] is set to 0x40 in channels 0, 1, and 4
- if ((u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] !=
+ for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
+ if (gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex] != &gAudioCtx.sequenceChannelNone) {
+ // seqScriptIO[5] is set to 0x40 in channels 0, 1, and 4
+ if ((u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]->seqScriptIO[5] !=
(u8)SEQ_IO_VAL_NONE) {
// Higher volume leads to lower reverb
- reverb = ((u16)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] -
+ reverb = ((u16)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]->seqScriptIO[5] -
targetVol) +
0x7F;
if (reverb > 0x7F) {
reverb = 0x7F;
}
- // CHAN_UPD_REVERB
- Audio_QueueCmdS8(_SHIFTL(0x5, 24, 8) | _SHIFTL(SEQ_PLAYER_BGM_MAIN, 16, 8) |
- _SHIFTL(channelIdx, 8, 8) | _SHIFTL(0, 0, 8),
- (u8)reverb);
+ AUDIOCMD_CHANNEL_SET_REVERB_VOLUME(SEQ_PLAYER_BGM_MAIN, (u32)channelIndex, (u8)reverb);
}
}
}
@@ -3043,31 +3039,30 @@ void Audio_PlaySfxTransposed(Vec3f* pos, u16 sfxId, s8 semitone) {
&gSfxDefaultReverb);
}
-void func_800F4C58(Vec3f* pos, u16 sfxId, u8 arg2) {
- u8 phi_s1 = 0;
+void func_800F4C58(Vec3f* pos, u16 sfxId, u8 ioData) {
+ u8 channelIndex = 0;
u8 i;
u8 bankId;
bankId = SFX_BANK_SHIFT(sfxId);
for (i = 0; i < bankId; i++) {
- phi_s1 += gChannelsPerBank[gSfxChannelLayout][i];
+ channelIndex += gChannelsPerBank[gSfxChannelLayout][i];
}
for (i = 0; i < gChannelsPerBank[gSfxChannelLayout][bankId]; i++) {
if ((gActiveSfx[bankId][i].entryIndex != 0xFF) &&
(sfxId == gSfxBanks[bankId][gActiveSfx[bankId][i].entryIndex].sfxId)) {
- Audio_QueueCmdS8(
- _SHIFTL(0x6, 24, 8) | _SHIFTL(SEQ_PLAYER_SFX, 16, 8) | _SHIFTL(phi_s1, 8, 8) | _SHIFTL(6, 0, 8), arg2);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, channelIndex, 6, ioData);
}
- phi_s1++;
+ channelIndex++;
}
Audio_PlaySfxGeneral(sfxId, pos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
}
void func_800F4E30(Vec3f* pos, f32 arg1) {
f32 phi_f22;
- s8 phi_s4;
- u8 i;
+ s8 pan;
+ u8 channelIndex;
if (sSariaBgmPtr == NULL) {
sSariaBgmPtr = pos;
@@ -3082,11 +3077,11 @@ void func_800F4E30(Vec3f* pos, f32 arg1) {
}
if (sSariaBgmPtr->x > 100.0f) {
- phi_s4 = 0x7F;
+ pan = 0x7F;
} else if (sSariaBgmPtr->x < -100.0f) {
- phi_s4 = 0;
+ pan = 0;
} else {
- phi_s4 = ((sSariaBgmPtr->x / 100.0f) * 64.0f) + 64.0f;
+ pan = ((sSariaBgmPtr->x / 100.0f) * 64.0f) + 64.0f;
}
if (D_80130650 > 400.0f) {
@@ -3097,10 +3092,10 @@ void func_800F4E30(Vec3f* pos, f32 arg1) {
phi_f22 = ((1.0f - ((D_80130650 - 120.0f) / 280.0f)) * 0.9f) + 0.1f;
}
- for (i = 0; i < 0x10; i++) {
- if (i != 9) {
- SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_MAIN, i, 2, (127.0f * phi_f22));
- Audio_QueueCmdS8(0x3 << 24 | SEQ_PLAYER_BGM_MAIN << 16 | ((u8)((u32)i) << 8), phi_s4);
+ for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
+ if (channelIndex != 9) {
+ SEQCMD_SET_CHANNEL_VOLUME(SEQ_PLAYER_BGM_MAIN, channelIndex, 2, (127.0f * phi_f22));
+ AUDIOCMD_CHANNEL_SET_PAN(SEQ_PLAYER_BGM_MAIN, (u32)channelIndex, pan);
}
}
}
@@ -3227,8 +3222,7 @@ void Audio_PlaySceneSequence(u16 seqId) {
if (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) != NA_BGM_WINDMILL) {
if (Audio_GetActiveSeqId(SEQ_PLAYER_BGM_SUB) == NA_BGM_LONLON) {
Audio_StopSequence(SEQ_PLAYER_BGM_SUB, 0);
- // Terminate all internal audio cmds
- Audio_QueueCmdS32(0xF8000000, 0);
+ AUDIOCMD_GLOBAL_STOP_AUDIOCMDS();
}
if ((sSeqFlags[sPrevSceneSeqId] & SEQ_FLAG_RESUME_PREV) && (sSeqFlags[seqId & 0xFF & 0xFF] & SEQ_FLAG_RESUME)) {
@@ -3263,7 +3257,7 @@ void Audio_UpdateSceneSequenceResumePoint(void) {
if ((seqId != NA_BGM_DISABLED) && (sSeqFlags[seqId & 0xFF & 0xFF] & SEQ_FLAG_RESUME)) {
if (sSeqResumePoint != SEQ_RESUME_POINT_NONE) {
// Get the current point to resume from
- sSeqResumePoint = gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3];
+ sSeqResumePoint = gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].seqScriptIO[3];
} else {
// Initialize the point to resume from to the start of the sequence.
sSeqResumePoint = 0;
@@ -3285,7 +3279,7 @@ void Audio_SetMainBgmTempoFreqAfterFanfare(f32 scaleTempoAndFreq, u8 duration) {
SEQCMD_SETUP_SCALE_TEMPO(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_MAIN, duration, scaleTempoAndFreq * 100.0f);
}
- SEQCMD_SETUP_SET_PLAYER_FREQ(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_MAIN, duration, scaleTempoAndFreq * 100.0f);
+ SEQCMD_SETUP_SET_SEQPLAYER_FREQ(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_MAIN, duration, scaleTempoAndFreq * 100.0f);
}
/**
@@ -3406,8 +3400,8 @@ void Audio_PlayFanfare(u16 seqId) {
curSeqId = Audio_GetActiveSeqId(SEQ_PLAYER_FANFARE);
- curFontId = func_800E5E84(curSeqId & 0xFF, &outNumFonts);
- requestedFontId = func_800E5E84(seqId & 0xFF, &outNumFonts);
+ curFontId = AudioThread_GetFontsForSequence(curSeqId & 0xFF, &outNumFonts);
+ requestedFontId = AudioThread_GetFontsForSequence(seqId & 0xFF, &outNumFonts);
if ((curSeqId == NA_BGM_DISABLED) || (*curFontId == *requestedFontId)) {
sFanfareStartTimer = 1;
@@ -3428,8 +3422,8 @@ void Audio_UpdateFanfare(void) {
if (sFanfareStartTimer != 0) {
sFanfareStartTimer--;
if (sFanfareStartTimer == 0) {
- Audio_QueueCmdS32(0xE3000000, SEQUENCE_TABLE);
- Audio_QueueCmdS32(0xE3000000, FONT_TABLE);
+ AUDIOCMD_GLOBAL_POP_PERSISTENT_CACHE(SEQUENCE_TABLE);
+ AUDIOCMD_GLOBAL_POP_PERSISTENT_CACHE(FONT_TABLE);
seqIdBgmMain = Audio_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN);
seqIdFanfare = Audio_GetActiveSeqId(SEQ_PLAYER_FANFARE);
@@ -3439,10 +3433,10 @@ void Audio_UpdateFanfare(void) {
if (seqIdFanfare == NA_BGM_DISABLED) {
Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_FANFARE, 0, 5);
Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, VOL_SCALE_INDEX_FANFARE, 0, 5);
- SEQCMD_SETUP_RESTORE_PLAYER_VOLUME_WITH_SCALE_INDEX(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_MAIN,
- VOL_SCALE_INDEX_FANFARE, 10);
- SEQCMD_SETUP_RESTORE_PLAYER_VOLUME_WITH_SCALE_INDEX(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_SUB,
- VOL_SCALE_INDEX_FANFARE, 10);
+ SEQCMD_SETUP_RESTORE_SEQPLAYER_VOLUME_WITH_SCALE_INDEX(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_MAIN,
+ VOL_SCALE_INDEX_FANFARE, 10);
+ SEQCMD_SETUP_RESTORE_SEQPLAYER_VOLUME_WITH_SCALE_INDEX(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_SUB,
+ VOL_SCALE_INDEX_FANFARE, 10);
SEQCMD_SETUP_SET_CHANNEL_DISABLE_MASK(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_MAIN, 0);
if (seqIdBgmSub != NA_BGM_LONLON) {
SEQCMD_SETUP_SET_CHANNEL_DISABLE_MASK(SEQ_PLAYER_FANFARE, SEQ_PLAYER_BGM_SUB, 0);
@@ -3458,7 +3452,7 @@ void Audio_UpdateFanfare(void) {
}
void Audio_PlaySequenceWithSeqPlayerIO(u8 seqPlayerIndex, u16 seqId, u8 fadeInDuration, s8 ioPort, s8 ioData) {
- SEQCMD_SET_PLAYER_IO(seqPlayerIndex, ioPort, ioData);
+ SEQCMD_SET_SEQPLAYER_IO(seqPlayerIndex, ioPort, ioData);
SEQCMD_PLAY_SEQUENCE(seqPlayerIndex, fadeInDuration, 0, seqId);
}
@@ -3537,7 +3531,7 @@ void Audio_SetSequenceMode(u8 seqMode) {
}
sPrevSeqMode = seqMode;
- SEQCMD_SET_PLAYER_IO(SEQ_PLAYER_BGM_MAIN, 2, seqMode);
+ SEQCMD_SET_SEQPLAYER_IO(SEQ_PLAYER_BGM_MAIN, 2, seqMode);
}
}
}
@@ -3641,11 +3635,11 @@ void func_800F64E0(u8 arg0) {
if (arg0 != 0) {
Audio_PlaySfxGeneral(NA_SE_SY_WIN_OPEN, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
- Audio_QueueCmdS32(0xF1000000, 0);
+ AUDIOCMD_GLOBAL_MUTE();
} else {
Audio_PlaySfxGeneral(NA_SE_SY_WIN_CLOSE, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
- Audio_QueueCmdS32(0xF2000000, 0);
+ AUDIOCMD_GLOBAL_UNMUTE(0);
}
}
@@ -3754,16 +3748,13 @@ void Audio_SetBaseFilter(u8 filter) {
}
void Audio_SetExtraFilter(u8 filter) {
- u32 t;
- u8 i;
+ u8 channelIndex;
sAudioExtraFilter2 = filter;
sAudioExtraFilter = filter;
if (gActiveSeqs[SEQ_PLAYER_BGM_MAIN].seqId == NA_BGM_NATURE_AMBIENCE) {
- for (i = 0; i < 16; i++) {
- t = i;
- // CHAN_UPD_SCRIPT_IO (seq player 0, all channels, slot 6)
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_BGM_MAIN << 16 | ((t & 0xFF) << 8) | 6, filter);
+ for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_BGM_MAIN, (u32)channelIndex, 6, filter);
}
}
}
@@ -3824,11 +3815,11 @@ void func_800F6B3C(void) {
}
void Audio_DisableAllSeq(void) {
- Audio_DisableSeq(SEQ_PLAYER_BGM_MAIN, 0);
- Audio_DisableSeq(SEQ_PLAYER_FANFARE, 0);
- Audio_DisableSeq(SEQ_PLAYER_SFX, 0);
- Audio_DisableSeq(SEQ_PLAYER_BGM_SUB, 0);
- Audio_ScheduleProcessCmds();
+ AUDIOCMD_GLOBAL_DISABLE_SEQPLAYER(SEQ_PLAYER_BGM_MAIN, 0);
+ AUDIOCMD_GLOBAL_DISABLE_SEQPLAYER(SEQ_PLAYER_FANFARE, 0);
+ AUDIOCMD_GLOBAL_DISABLE_SEQPLAYER(SEQ_PLAYER_SFX, 0);
+ AUDIOCMD_GLOBAL_DISABLE_SEQPLAYER(SEQ_PLAYER_BGM_SUB, 0);
+ AudioThread_ScheduleProcessCmds();
}
s8 func_800F6BB8(void) {
@@ -3837,7 +3828,7 @@ s8 func_800F6BB8(void) {
void func_800F6BDC(void) {
Audio_DisableAllSeq();
- Audio_ScheduleProcessCmds();
+ AudioThread_ScheduleProcessCmds();
while (true) {
if (!func_800F6BB8()) {
return;
@@ -3846,7 +3837,7 @@ void func_800F6BDC(void) {
}
void Audio_PreNMI(void) {
- Audio_PreNMIInternal();
+ AudioThread_PreNMIInternal();
}
void func_800F6C34(void) {
@@ -3872,7 +3863,7 @@ void func_800F6C34(void) {
sSpecReverb = sSpecReverbs[gAudioSpecId];
D_80130608 = 0;
sPrevMainBgmSeqId = NA_BGM_DISABLED;
- Audio_QueueCmdS8(0x46 << 24 | SEQ_PLAYER_BGM_MAIN << 16, -1);
+ AUDIOCMD_SEQPLAYER_SET_IO(SEQ_PLAYER_BGM_MAIN, 0, SEQ_IO_VAL_NONE);
sSariaBgmPtr = NULL;
sFanfareStartTimer = 0;
D_8016B9F3 = 1;
@@ -3921,9 +3912,9 @@ void Audio_StartNatureAmbienceSequence(u16 playerIO, u16 channelMask) {
return;
}
- SEQCMD_SET_PLAYER_IO(SEQ_PLAYER_BGM_MAIN, 0, 1);
- SEQCMD_SET_PLAYER_IO(SEQ_PLAYER_BGM_MAIN, 4, playerIO >> 8);
- SEQCMD_SET_PLAYER_IO(SEQ_PLAYER_BGM_MAIN, 5, playerIO & 0xFF);
+ SEQCMD_SET_SEQPLAYER_IO(SEQ_PLAYER_BGM_MAIN, 0, 1);
+ SEQCMD_SET_SEQPLAYER_IO(SEQ_PLAYER_BGM_MAIN, 4, playerIO >> 8);
+ SEQCMD_SET_SEQPLAYER_IO(SEQ_PLAYER_BGM_MAIN, 5, playerIO & 0xFF);
Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_BGM_MAIN, 0x7F, 1);
channelIdx = false;
@@ -3986,9 +3977,9 @@ void Audio_InitSound(void) {
void func_800F7170(void) {
Audio_StartSequence(SEQ_PLAYER_SFX, 0, 0x70, 1);
- Audio_QueueCmdS32(0xF2000000, 1);
- Audio_ScheduleProcessCmds();
- Audio_QueueCmdS32(0xF8000000, 0);
+ AUDIOCMD_GLOBAL_UNMUTE(1);
+ AudioThread_ScheduleProcessCmds();
+ AUDIOCMD_GLOBAL_STOP_AUDIOCMDS();
}
void func_800F71BC(s32 arg0) {
@@ -4002,7 +3993,7 @@ void func_800F71BC(s32 arg0) {
void func_800F7208(void) {
Audio_ResetActiveSequences();
- Audio_QueueCmdS32(0xF2000000, 1);
+ AUDIOCMD_GLOBAL_UNMUTE(1);
func_800F6C34();
Audio_ResetSfxChannelState();
Audio_StartSequence(SEQ_PLAYER_SFX, 0, 0x70, 1);
diff --git a/src/audio/lib/effects.c b/src/audio/lib/effects.c
index 8de03887e..bbfcaf61a 100644
--- a/src/audio/lib/effects.c
+++ b/src/audio/lib/effects.c
@@ -113,8 +113,8 @@ f32 Audio_GetVibratoFreqScale(VibratoState* vib) {
static f32 D_80130510 = 0.0f;
static s32 D_80130514 = 0;
f32 pitchChange;
- f32 extent;
- f32 invExtent;
+ f32 depth;
+ f32 invDepth;
f32 result;
f32 temp;
SequenceChannel* channel = vib->channel;
@@ -127,17 +127,17 @@ f32 Audio_GetVibratoFreqScale(VibratoState* vib) {
//! @bug this probably meant to compare with gAudioCtx.sequenceChannelNone.
//! -1 isn't used as a channel pointer anywhere else.
if (channel != ((SequenceChannel*)(-1))) {
- if (vib->extentChangeTimer) {
- if (vib->extentChangeTimer == 1) {
- vib->extent = (s32)channel->vibratoExtentTarget;
+ if (vib->depthChangeTimer) {
+ if (vib->depthChangeTimer == 1) {
+ vib->depth = (s32)channel->vibratoDepthTarget;
} else {
- vib->extent += ((s32)channel->vibratoExtentTarget - vib->extent) / (s32)vib->extentChangeTimer;
+ vib->depth += ((s32)channel->vibratoDepthTarget - vib->depth) / (s32)vib->depthChangeTimer;
}
- vib->extentChangeTimer--;
- } else if (channel->vibratoExtentTarget != (s32)vib->extent) {
- if ((vib->extentChangeTimer = channel->vibratoExtentChangeDelay) == 0) {
- vib->extent = (s32)channel->vibratoExtentTarget;
+ vib->depthChangeTimer--;
+ } else if (channel->vibratoDepthTarget != (s32)vib->depth) {
+ if ((vib->depthChangeTimer = channel->vibratoDepthChangeDelay) == 0) {
+ vib->depth = (s32)channel->vibratoDepthTarget;
}
}
@@ -156,16 +156,16 @@ f32 Audio_GetVibratoFreqScale(VibratoState* vib) {
}
}
- if (vib->extent == 0.0f) {
+ if (vib->depth == 0.0f) {
return 1.0f;
}
pitchChange = Audio_GetVibratoPitchChange(vib) + 32768.0f;
- temp = vib->extent / 4096.0f;
- extent = temp + 1.0f;
- invExtent = 1.0f / extent;
+ temp = vib->depth / 4096.0f;
+ depth = temp + 1.0f;
+ invDepth = 1.0f / depth;
- result = 1.0f / ((extent - invExtent) * pitchChange / 65536.0f + invExtent);
+ result = 1.0f / ((depth - invDepth) * pitchChange / 65536.0f + invDepth);
D_80130510 += result;
D_80130514++;
@@ -190,16 +190,16 @@ void Audio_NoteVibratoInit(Note* note) {
vib = &note->playbackState.vibratoState;
- vib->active = 1;
+ vib->active = true;
vib->time = 0;
+ vib->curve = gWaveSamples[2]; // gSineWaveSample[0..63]
- vib->curve = gWaveSamples[2];
vib->channel = note->playbackState.parentLayer->channel;
channel = vib->channel;
- if ((vib->extentChangeTimer = channel->vibratoExtentChangeDelay) == 0) {
- vib->extent = (s32)channel->vibratoExtentTarget;
+ if ((vib->depthChangeTimer = channel->vibratoDepthChangeDelay) == 0) {
+ vib->depth = (s32)channel->vibratoDepthTarget;
} else {
- vib->extent = (s32)channel->vibratoExtentStart;
+ vib->depth = (s32)channel->vibratoDepthStart;
}
if ((vib->rateChangeTimer = channel->vibratoRateChangeDelay) == 0) {
@@ -264,7 +264,7 @@ f32 Audio_AdsrUpdate(AdsrState* adsr) {
break;
default:
- adsr->delay *= gAudioCtx.audioBufferParameters.updatesPerFrameScaled;
+ adsr->delay *= gAudioCtx.audioBufferParameters.ticksPerUpdateScaled;
if (adsr->delay == 0) {
adsr->delay = 1;
}
diff --git a/src/audio/lib/heap.c b/src/audio/lib/heap.c
index 899cf912b..dcb027d49 100644
--- a/src/audio/lib/heap.c
+++ b/src/audio/lib/heap.c
@@ -11,12 +11,10 @@ void AudioHeap_DiscardSampleBank(s32 sampleBankId);
void AudioHeap_DiscardSampleBanks(void);
/**
- * Effectively scales `updatesPerFrameInv` by the reciprocal of `scaleInv`
- * `updatesPerFrameInvScaled` is just `updatesPerFrameInv` scaled down by a factor of 256.0f
- * i.e. (256.0f * `updatesPerFrameInvScaled`) is just `updatesPerFrameInv`
+ * Effectively scales `ticksPerUpdateInv` by the reciprocal of `scaleInv`
*/
f32 AudioHeap_CalculateAdsrDecay(f32 scaleInv) {
- return (256.0f * gAudioCtx.audioBufferParameters.updatesPerFrameInvScaled) / scaleInv;
+ return (256.0f * gAudioCtx.audioBufferParameters.ticksPerUpdateInvScaled) / scaleInv;
}
/**
@@ -96,7 +94,7 @@ void AudioHeap_ReleaseNotesForFont(s32 fontId) {
if (playbackState->fontId == fontId) {
if ((playbackState->priority != 0) && (playbackState->adsr.action.s.state == ADSR_STATE_DECAY)) {
playbackState->priority = 1;
- playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
+ playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.ticksPerUpdateInv;
playbackState->adsr.action.s.release = true;
}
}
@@ -793,7 +791,7 @@ s32 AudioHeap_ResetStep(void) {
if (gAudioCtx.notes[i].noteSubEu.bitField0.enabled &&
gAudioCtx.notes[i].playbackState.adsr.action.s.state != ADSR_STATE_DISABLED) {
gAudioCtx.notes[i].playbackState.adsr.fadeOutVel =
- gAudioCtx.audioBufferParameters.updatesPerFrameInv;
+ gAudioCtx.audioBufferParameters.ticksPerUpdateInv;
gAudioCtx.notes[i].playbackState.adsr.action.s.release = true;
}
}
@@ -853,7 +851,7 @@ void AudioHeap_Init(void) {
s32 i;
s32 j;
s32 pad2;
- AudioSpec* spec = &gAudioSpecs[gAudioCtx.audioResetSpecIdToLoad]; // Audio Specifications
+ AudioSpec* spec = &gAudioSpecs[gAudioCtx.specId]; // Audio Specifications
gAudioCtx.sampleDmaCount = 0;
@@ -865,17 +863,17 @@ void AudioHeap_Init(void) {
ALIGN16(gAudioCtx.audioBufferParameters.samplingFrequency / gAudioCtx.refreshRate);
gAudioCtx.audioBufferParameters.minAiBufferLength = gAudioCtx.audioBufferParameters.samplesPerFrameTarget - 0x10;
gAudioCtx.audioBufferParameters.maxAiBufferLength = gAudioCtx.audioBufferParameters.samplesPerFrameTarget + 0x10;
- gAudioCtx.audioBufferParameters.updatesPerFrame =
+ gAudioCtx.audioBufferParameters.ticksPerUpdate =
((gAudioCtx.audioBufferParameters.samplesPerFrameTarget + 0x10) / 0xD0) + 1;
- gAudioCtx.audioBufferParameters.samplesPerUpdate =
- (gAudioCtx.audioBufferParameters.samplesPerFrameTarget / gAudioCtx.audioBufferParameters.updatesPerFrame) & ~7;
- gAudioCtx.audioBufferParameters.samplesPerUpdateMax = gAudioCtx.audioBufferParameters.samplesPerUpdate + 8;
- gAudioCtx.audioBufferParameters.samplesPerUpdateMin = gAudioCtx.audioBufferParameters.samplesPerUpdate - 8;
+ gAudioCtx.audioBufferParameters.samplesPerTick =
+ (gAudioCtx.audioBufferParameters.samplesPerFrameTarget / gAudioCtx.audioBufferParameters.ticksPerUpdate) & ~7;
+ gAudioCtx.audioBufferParameters.samplesPerTickMax = gAudioCtx.audioBufferParameters.samplesPerTick + 8;
+ gAudioCtx.audioBufferParameters.samplesPerTickMin = gAudioCtx.audioBufferParameters.samplesPerTick - 8;
gAudioCtx.audioBufferParameters.resampleRate = 32000.0f / (s32)gAudioCtx.audioBufferParameters.samplingFrequency;
- gAudioCtx.audioBufferParameters.updatesPerFrameInvScaled =
- (1.0f / 256.0f) / gAudioCtx.audioBufferParameters.updatesPerFrame;
- gAudioCtx.audioBufferParameters.updatesPerFrameScaled = gAudioCtx.audioBufferParameters.updatesPerFrame / 4.0f;
- gAudioCtx.audioBufferParameters.updatesPerFrameInv = 1.0f / gAudioCtx.audioBufferParameters.updatesPerFrame;
+ gAudioCtx.audioBufferParameters.ticksPerUpdateInvScaled =
+ (1.0f / 256.0f) / gAudioCtx.audioBufferParameters.ticksPerUpdate;
+ gAudioCtx.audioBufferParameters.ticksPerUpdateScaled = gAudioCtx.audioBufferParameters.ticksPerUpdate / 4.0f;
+ gAudioCtx.audioBufferParameters.ticksPerUpdateInv = 1.0f / gAudioCtx.audioBufferParameters.ticksPerUpdate;
// SampleDma buffer size
gAudioCtx.sampleDmaBufSize1 = spec->sampleDmaBufSize1;
@@ -887,19 +885,22 @@ void AudioHeap_Init(void) {
gAudioCtx.audioBufferParameters.numSequencePlayers = 4;
}
gAudioCtx.unk_2 = spec->unk_14;
- gAudioCtx.tempoInternalToExternal =
- (u32)(gAudioCtx.audioBufferParameters.updatesPerFrame * 2880000.0f / gTatumsPerBeat / gAudioCtx.unk_2960);
+
+ // (ticks / min)
+ // 60 * 1000 is a conversion from milliseconds to minutes
+ gAudioCtx.maxTempo = (u32)(gAudioCtx.audioBufferParameters.ticksPerUpdate * (f32)(60 * 1000 * SEQTICKS_PER_BEAT) /
+ gTempoData.seqTicksPerBeat / gAudioCtx.maxTempoTvTypeFactors);
gAudioCtx.unk_2870 = gAudioCtx.refreshRate;
- gAudioCtx.unk_2870 *= gAudioCtx.audioBufferParameters.updatesPerFrame;
+ gAudioCtx.unk_2870 *= gAudioCtx.audioBufferParameters.ticksPerUpdate;
gAudioCtx.unk_2870 /= gAudioCtx.audioBufferParameters.aiSamplingFrequency;
- gAudioCtx.unk_2870 /= gAudioCtx.tempoInternalToExternal;
+ gAudioCtx.unk_2870 /= gAudioCtx.maxTempo;
gAudioCtx.audioBufferParameters.specUnk4 = spec->unk_04;
gAudioCtx.audioBufferParameters.samplesPerFrameTarget *= gAudioCtx.audioBufferParameters.specUnk4;
gAudioCtx.audioBufferParameters.maxAiBufferLength *= gAudioCtx.audioBufferParameters.specUnk4;
gAudioCtx.audioBufferParameters.minAiBufferLength *= gAudioCtx.audioBufferParameters.specUnk4;
- gAudioCtx.audioBufferParameters.updatesPerFrame *= gAudioCtx.audioBufferParameters.specUnk4;
+ gAudioCtx.audioBufferParameters.ticksPerUpdate *= gAudioCtx.audioBufferParameters.specUnk4;
if (gAudioCtx.audioBufferParameters.specUnk4 >= 2) {
gAudioCtx.audioBufferParameters.maxAiBufferLength -= 0x10;
@@ -907,7 +908,7 @@ void AudioHeap_Init(void) {
// Determine the length of the buffer for storing the audio command list passed to the rsp audio microcode
gAudioCtx.maxAudioCmds =
- gAudioCtx.numNotes * 0x10 * gAudioCtx.audioBufferParameters.updatesPerFrame + spec->numReverbs * 0x18 + 0x140;
+ gAudioCtx.numNotes * 0x10 * gAudioCtx.audioBufferParameters.ticksPerUpdate + spec->numReverbs * 0x18 + 0x140;
// Calculate sizes for various caches on the audio heap
persistentSize =
@@ -949,7 +950,7 @@ void AudioHeap_Init(void) {
gAudioCtx.notes = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, gAudioCtx.numNotes * sizeof(Note));
Audio_NoteInitAll();
Audio_InitNoteFreeList();
- gAudioCtx.noteSubsEu = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, gAudioCtx.audioBufferParameters.updatesPerFrame *
+ gAudioCtx.noteSubsEu = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, gAudioCtx.audioBufferParameters.ticksPerUpdate *
gAudioCtx.numNotes * sizeof(NoteSubEu));
// Initialize audio binary interface command list buffers
for (i = 0; i != 2; i++) {
@@ -1011,7 +1012,7 @@ void AudioHeap_Init(void) {
reverb->unk_34 = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(RESAMPLE_STATE));
reverb->unk_38 = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(RESAMPLE_STATE));
reverb->unk_3C = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(RESAMPLE_STATE));
- for (j = 0; j < gAudioCtx.audioBufferParameters.updatesPerFrame; j++) {
+ for (j = 0; j < gAudioCtx.audioBufferParameters.ticksPerUpdate; j++) {
ramAddr = AudioHeap_AllocZeroedAttemptExternal(&gAudioCtx.miscPool, DMEM_2CH_SIZE);
reverb->items[0][j].toDownsampleLeft = ramAddr;
reverb->items[0][j].toDownsampleRight = ramAddr + DMEM_1CH_SIZE / SAMPLE_SIZE;
diff --git a/src/audio/lib/load.c b/src/audio/lib/load.c
index b7b674a23..c542c8062 100644
--- a/src/audio/lib/load.c
+++ b/src/audio/lib/load.c
@@ -1126,7 +1126,7 @@ void AudioLoad_Init(void* heap, u32 heapSize) {
void* ramAddr;
s32 i;
- D_801755D0 = NULL;
+ gAudioCustomUpdateFunction = NULL;
gAudioCtx.resetTimer = 0;
{
@@ -1138,25 +1138,26 @@ void AudioLoad_Init(void* heap, u32 heapSize) {
}
}
+ // 1000 is a conversion from seconds to milliseconds
switch (osTvType) {
case OS_TV_PAL:
- gAudioCtx.unk_2960 = 20.03042f;
- gAudioCtx.refreshRate = 50;
+ gAudioCtx.maxTempoTvTypeFactors = 1000 * REFRESH_RATE_DEVIATION_PAL / REFRESH_RATE_PAL;
+ gAudioCtx.refreshRate = REFRESH_RATE_PAL;
break;
case OS_TV_MPAL:
- gAudioCtx.unk_2960 = 16.546f;
- gAudioCtx.refreshRate = 60;
+ gAudioCtx.maxTempoTvTypeFactors = 1000 * REFRESH_RATE_DEVIATION_MPAL / REFRESH_RATE_MPAL;
+ gAudioCtx.refreshRate = REFRESH_RATE_MPAL;
break;
case OS_TV_NTSC:
default:
- gAudioCtx.unk_2960 = 16.713f;
- gAudioCtx.refreshRate = 60;
+ gAudioCtx.maxTempoTvTypeFactors = 1000 * REFRESH_RATE_DEVIATION_NTSC / REFRESH_RATE_NTSC;
+ gAudioCtx.refreshRate = REFRESH_RATE_NTSC;
break;
}
- Audio_InitMesgQueues();
+ AudioThread_InitMesgQueues();
for (i = 0; i < 3; i++) {
gAudioCtx.aiBufLengths[i] = 0xA0;
@@ -1209,7 +1210,7 @@ void AudioLoad_Init(void* heap, u32 heapSize) {
gAudioCtx.numSequences = gAudioCtx.sequenceTable->numEntries;
- gAudioCtx.audioResetSpecIdToLoad = 0;
+ gAudioCtx.specId = 0;
gAudioCtx.resetStatus = 1; // Set reset to immediately initialize the audio heap
AudioHeap_ResetStep();
diff --git a/src/audio/lib/playback.c b/src/audio/lib/playback.c
index 87e2f792c..9c1b8126e 100644
--- a/src/audio/lib/playback.c
+++ b/src/audio/lib/playback.c
@@ -100,8 +100,8 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
sub->gain = attrs->gain;
sub->filter = attrs->filter;
- sub->unk_07 = attrs->unk_14;
- sub->unk_0E = attrs->unk_16;
+ sub->combFilterSize = attrs->combFilterSize;
+ sub->combFilterGain = attrs->combFilterGain;
sub->reverbVol = reverbVol;
}
@@ -174,7 +174,7 @@ void Audio_ProcessNotes(void) {
if (note != playbackState->parentLayer->note && playbackState->unk_04 == 0) {
playbackState->adsr.action.s.release = true;
- playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
+ playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.ticksPerUpdateInv;
playbackState->priority = 1;
playbackState->unk_04 = 2;
goto out;
@@ -256,8 +256,8 @@ void Audio_ProcessNotes(void) {
subAttrs.stereo = attrs->stereo;
subAttrs.gain = attrs->gain;
subAttrs.filter = attrs->filter;
- subAttrs.unk_14 = attrs->unk_4;
- subAttrs.unk_16 = attrs->unk_6;
+ subAttrs.combFilterSize = attrs->combFilterSize;
+ subAttrs.combFilterGain = attrs->combFilterGain;
bookOffset = noteSubEu->bitField1.bookOffset;
} else {
SequenceLayer* layer = playbackState->parentLayer;
@@ -271,11 +271,11 @@ void Audio_ProcessNotes(void) {
} else {
subAttrs.stereo = layer->stereo;
}
- subAttrs.reverbVol = channel->reverb;
+ subAttrs.reverbVol = channel->targetReverbVol;
subAttrs.gain = channel->gain;
subAttrs.filter = channel->filter;
- subAttrs.unk_14 = channel->unk_0F;
- subAttrs.unk_16 = channel->unk_20;
+ subAttrs.combFilterSize = channel->combFilterSize;
+ subAttrs.combFilterGain = channel->combFilterGain;
bookOffset = channel->bookOffset & 0x7;
if (channel->seqPlayer->muted && (channel->muteBehavior & MUTE_BEHAVIOR_3)) {
@@ -433,7 +433,7 @@ s32 Audio_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* val
void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) {
Note* note;
NoteAttributes* attrs;
- SequenceChannel* chan;
+ SequenceChannel* channel;
s32 i;
if (layer == NO_LAYER) {
@@ -456,7 +456,7 @@ void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) {
if (note->playbackState.parentLayer != layer) {
if (note->playbackState.parentLayer == NO_LAYER && note->playbackState.wantedParentLayer == NO_LAYER &&
note->playbackState.prevParentLayer == layer && target != ADSR_STATE_DECAY) {
- note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
+ note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.ticksPerUpdateInv;
note->playbackState.adsr.action.s.release = true;
}
return;
@@ -468,10 +468,10 @@ void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) {
attrs->pan = layer->notePan;
if (layer->channel != NULL) {
- chan = layer->channel;
- attrs->reverb = chan->reverb;
- attrs->gain = chan->gain;
- attrs->filter = chan->filter;
+ channel = layer->channel;
+ attrs->reverb = channel->targetReverbVol;
+ attrs->gain = channel->gain;
+ attrs->filter = channel->filter;
if (attrs->filter != NULL) {
for (i = 0; i < 8; i++) {
@@ -480,18 +480,18 @@ void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) {
attrs->filter = attrs->filterBuf;
}
- attrs->unk_6 = chan->unk_20;
- attrs->unk_4 = chan->unk_0F;
- if (chan->seqPlayer->muted && (chan->muteBehavior & MUTE_BEHAVIOR_3)) {
+ attrs->combFilterGain = channel->combFilterGain;
+ attrs->combFilterSize = channel->combFilterSize;
+ if (channel->seqPlayer->muted && (channel->muteBehavior & MUTE_BEHAVIOR_3)) {
note->noteSubEu.bitField0.finished = true;
}
if (layer->stereo.asByte == 0) {
- attrs->stereo = chan->stereo;
+ attrs->stereo = channel->stereo;
} else {
attrs->stereo = layer->stereo;
}
- note->playbackState.priority = chan->someOtherPriority;
+ note->playbackState.priority = channel->someOtherPriority;
} else {
attrs->stereo = layer->stereo;
note->playbackState.priority = 1;
@@ -500,7 +500,7 @@ void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) {
note->playbackState.prevParentLayer = note->playbackState.parentLayer;
note->playbackState.parentLayer = NO_LAYER;
if (target == ADSR_STATE_RELEASE) {
- note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
+ note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.ticksPerUpdateInv;
note->playbackState.adsr.action.s.release = true;
note->playbackState.unk_04 = 2;
} else {
@@ -805,7 +805,7 @@ void Audio_NoteReleaseAndTakeOwnership(Note* note, SequenceLayer* layer) {
note->playbackState.wantedParentLayer = layer;
note->playbackState.priority = layer->channel->notePriority;
- note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
+ note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.ticksPerUpdateInv;
note->playbackState.adsr.action.s.release = true;
}
diff --git a/src/audio/lib/seqplayer.c b/src/audio/lib/seqplayer.c
index 008bedea6..620f7a453 100644
--- a/src/audio/lib/seqplayer.c
+++ b/src/audio/lib/seqplayer.c
@@ -259,7 +259,7 @@ void AudioSeq_InitSequenceChannel(SequenceChannel* channel) {
channel->enabled = false;
channel->finished = false;
channel->stopScript = false;
- channel->stopSomething2 = false;
+ channel->muted = false;
channel->hasInstrument = false;
channel->stereoHeadsetEffects = false;
channel->transposition = 0;
@@ -274,7 +274,7 @@ void AudioSeq_InitSequenceChannel(SequenceChannel* channel) {
channel->gateTimeRandomVariance = 0;
channel->noteUnused = NULL;
channel->reverbIndex = 0;
- channel->reverb = 0;
+ channel->targetReverbVol = 0;
channel->gain = 0;
channel->notePriority = 3;
channel->someOtherPriority = 1;
@@ -284,20 +284,20 @@ void AudioSeq_InitSequenceChannel(SequenceChannel* channel) {
channel->adsr.sustain = 0;
channel->vibratoRateTarget = 0x800;
channel->vibratoRateStart = 0x800;
- channel->vibratoExtentTarget = 0;
- channel->vibratoExtentStart = 0;
+ channel->vibratoDepthTarget = 0;
+ channel->vibratoDepthStart = 0;
channel->vibratoRateChangeDelay = 0;
- channel->vibratoExtentChangeDelay = 0;
+ channel->vibratoDepthChangeDelay = 0;
channel->vibratoDelay = 0;
channel->filter = NULL;
- channel->unk_20 = 0;
- channel->unk_0F = 0;
+ channel->combFilterGain = 0;
+ channel->combFilterSize = 0;
channel->volume = 1.0f;
channel->volumeScale = 1.0f;
channel->freqScale = 1.0f;
- for (i = 0; i < ARRAY_COUNT(channel->soundScriptIO); i++) {
- channel->soundScriptIO[i] = SEQ_IO_VAL_NONE;
+ for (i = 0; i < ARRAY_COUNT(channel->seqScriptIO); i++) {
+ channel->seqScriptIO[i] = SEQ_IO_VAL_NONE;
}
channel->unused = false;
@@ -326,7 +326,7 @@ s32 AudioSeq_SeqChannelSetLayer(SequenceChannel* channel, s32 layerIndex) {
layer->adsr.decayIndex = 0;
layer->enabled = true;
layer->finished = false;
- layer->stopSomething = false;
+ layer->muted = false;
layer->continuousNotes = false;
layer->bit3 = false;
layer->ignoreDrumPan = false;
@@ -530,9 +530,9 @@ void AudioSeq_SeqLayerProcessScript(SequenceLayer* layer) {
if (layer->delay > 1) {
layer->delay--;
- if (!layer->stopSomething && layer->delay <= layer->gateDelay) {
+ if (!layer->muted && (layer->delay <= layer->gateDelay)) {
Audio_SeqLayerNoteDecay(layer);
- layer->stopSomething = true;
+ layer->muted = true;
}
return;
}
@@ -555,7 +555,7 @@ void AudioSeq_SeqLayerProcessScript(SequenceLayer* layer) {
AudioSeq_SeqLayerProcessScriptStep5(layer, cmd);
}
- if (layer->stopSomething == true) {
+ if (layer->muted == true) {
if ((layer->note != NULL) || layer->continuousNotes) {
Audio_SeqLayerNoteDecay(layer);
}
@@ -579,9 +579,9 @@ void AudioSeq_SeqLayerProcessScriptStep1(SequenceLayer* layer) {
s32 AudioSeq_SeqLayerProcessScriptStep5(SequenceLayer* layer, s32 sameTunedSample) {
Note* note;
- if (!layer->stopSomething && layer->tunedSample != NULL &&
- layer->tunedSample->sample->codec == CODEC_S16_INMEMORY && layer->tunedSample->sample->medium != MEDIUM_RAM) {
- layer->stopSomething = true;
+ if (!layer->muted && (layer->tunedSample != NULL) && (layer->tunedSample->sample->codec == CODEC_S16_INMEMORY) &&
+ (layer->tunedSample->sample->medium != MEDIUM_RAM)) {
+ layer->muted = true;
return PROCESS_SCRIPT_END;
}
@@ -812,7 +812,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
drum = Audio_GetDrum(channel->fontId, semitone);
if (drum == NULL) {
- layer->stopSomething = true;
+ layer->muted = true;
layer->delay2 = layer->delay;
return PROCESS_SCRIPT_END;
}
@@ -834,7 +834,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
soundEffect = Audio_GetSoundEffect(channel->fontId, sfxId);
if (soundEffect == NULL) {
- layer->stopSomething = true;
+ layer->muted = true;
layer->delay2 = layer->delay + 1;
return PROCESS_SCRIPT_END;
}
@@ -850,7 +850,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
layer->semitone = semitone;
if (semitone >= 0x80) {
- layer->stopSomething = true;
+ layer->muted = true;
return PROCESS_SCRIPT_END;
}
@@ -903,12 +903,12 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
portamento->extent = (freqScale2 / freqScale) - 1.0f;
if (PORTAMENTO_IS_SPECIAL(*portamento)) {
- speed = seqPlayer->tempo * 0x8000 / gAudioCtx.tempoInternalToExternal;
+ speed = seqPlayer->tempo * 0x8000 / gAudioCtx.maxTempo;
if (layer->delay != 0) {
speed = speed * 0x100 / (layer->delay * layer->portamentoTime);
}
} else {
- speed = 0x20000 / (layer->portamentoTime * gAudioCtx.audioBufferParameters.updatesPerFrame);
+ speed = 0x20000 / (layer->portamentoTime * gAudioCtx.audioBufferParameters.ticksPerUpdate);
}
if (speed >= 0x7FFF) {
@@ -964,7 +964,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
// (It's a bit unclear if 'portamento' has actually always been
// set when this is reached...)
if (PORTAMENTO_IS_SPECIAL(*portamento)) {
- speed2 = seqPlayer->tempo * 0x8000 / gAudioCtx.tempoInternalToExternal;
+ speed2 = seqPlayer->tempo * 0x8000 / gAudioCtx.maxTempo;
speed2 = speed2 * 0x100 / (layer->delay * layer->portamentoTime);
if (speed2 >= 0x7FFF) {
speed2 = 0x7FFF;
@@ -989,12 +989,12 @@ s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd) {
if (cmd == 0xC0) {
layer->delay = AudioSeq_ScriptReadCompressedU16(state);
- layer->stopSomething = true;
+ layer->muted = true;
layer->bit1 = false;
return PROCESS_SCRIPT_END;
}
- layer->stopSomething = false;
+ layer->muted = false;
if (channel->largeNotes == true) {
switch (cmd & 0xC0) {
@@ -1078,13 +1078,13 @@ s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd) {
}
if ((seqPlayer->muted && (channel->muteBehavior & (MUTE_BEHAVIOR_STOP_NOTES | MUTE_BEHAVIOR_4))) ||
- channel->stopSomething2) {
- layer->stopSomething = true;
+ channel->muted) {
+ layer->muted = true;
return PROCESS_SCRIPT_END;
}
if (seqPlayer->skipTicks != 0) {
- layer->stopSomething = true;
+ layer->muted = true;
return PROCESS_SCRIPT_END;
}
@@ -1329,9 +1329,9 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
case 0xD8:
cmd = (u8)cmdArgs[0];
- channel->vibratoExtentTarget = cmd * 8;
- channel->vibratoExtentStart = 0;
- channel->vibratoExtentChangeDelay = 0;
+ channel->vibratoDepthTarget = cmd * 8;
+ channel->vibratoDepthStart = 0;
+ channel->vibratoDepthChangeDelay = 0;
break;
case 0xD7:
@@ -1343,11 +1343,11 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
case 0xE2:
cmd = (u8)cmdArgs[0];
- channel->vibratoExtentStart = cmd * 8;
+ channel->vibratoDepthStart = cmd * 8;
cmd = (u8)cmdArgs[1];
- channel->vibratoExtentTarget = cmd * 8;
+ channel->vibratoDepthTarget = cmd * 8;
cmd = (u8)cmdArgs[2];
- channel->vibratoExtentChangeDelay = cmd * 16;
+ channel->vibratoDepthChangeDelay = cmd * 16;
break;
case 0xE1:
@@ -1366,7 +1366,7 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
case 0xD4:
cmd = (u8)cmdArgs[0];
- channel->reverb = cmd;
+ channel->targetReverbVol = cmd;
break;
case 0xC6:
@@ -1483,7 +1483,7 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
data += 4;
channel->newPan = data[-3];
channel->panChannelWeight = data[-2];
- channel->reverb = data[-1];
+ channel->targetReverbVol = data[-1];
channel->reverbIndex = data[0];
//! @bug: Not marking reverb state as changed
channel->changes.s.pan = true;
@@ -1497,16 +1497,16 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
channel->transposition = (s8)AudioSeq_ScriptReadU8(scriptState);
channel->newPan = AudioSeq_ScriptReadU8(scriptState);
channel->panChannelWeight = AudioSeq_ScriptReadU8(scriptState);
- channel->reverb = AudioSeq_ScriptReadU8(scriptState);
+ channel->targetReverbVol = AudioSeq_ScriptReadU8(scriptState);
channel->reverbIndex = AudioSeq_ScriptReadU8(scriptState);
//! @bug: Not marking reverb state as changed
channel->changes.s.pan = true;
break;
case 0xEC:
- channel->vibratoExtentTarget = 0;
- channel->vibratoExtentStart = 0;
- channel->vibratoExtentChangeDelay = 0;
+ channel->vibratoDepthTarget = 0;
+ channel->vibratoDepthStart = 0;
+ channel->vibratoDepthChangeDelay = 0;
channel->vibratoRateTarget = 0;
channel->vibratoRateStart = 0;
channel->vibratoRateChangeDelay = 0;
@@ -1515,8 +1515,8 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
channel->adsr.sustain = 0;
channel->velocityRandomVariance = 0;
channel->gateTimeRandomVariance = 0;
- channel->unk_0F = 0;
- channel->unk_20 = 0;
+ channel->combFilterSize = 0;
+ channel->combFilterGain = 0;
channel->bookOffset = 0;
channel->freqScale = 1.0f;
break;
@@ -1578,7 +1578,7 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
break;
case 0xBD:
- temp2 = Audio_NextRandom();
+ temp2 = AudioThread_NextRandom();
channel->unk_22 = (cmdArgs[0] == 0) ? (temp2 & 0xFFFF) : (temp2 % cmdArgs[0]);
channel->unk_22 += cmdArgs[1];
temp2 = (channel->unk_22 / 0x100) + 0x80;
@@ -1595,8 +1595,8 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
break;
case 0xBB:
- channel->unk_0F = cmdArgs[0];
- channel->unk_20 = cmdArgs[1];
+ channel->combFilterSize = cmdArgs[0];
+ channel->combFilterGain = cmdArgs[1];
break;
case 0xBC:
@@ -1642,7 +1642,7 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
break;
case 0x70:
- channel->soundScriptIO[lowBits] = scriptState->value;
+ channel->seqScriptIO[lowBits] = scriptState->value;
break;
case 0x78:
@@ -1664,26 +1664,26 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
case 0x10:
if (lowBits < 8) {
- channel->soundScriptIO[lowBits] = SEQ_IO_VAL_NONE;
- if (AudioLoad_SlowLoadSample(channel->fontId, scriptState->value,
- &channel->soundScriptIO[lowBits]) == -1) {}
+ channel->seqScriptIO[lowBits] = SEQ_IO_VAL_NONE;
+ if (AudioLoad_SlowLoadSample(channel->fontId, scriptState->value, &channel->seqScriptIO[lowBits]) ==
+ -1) {}
} else {
lowBits -= 8;
- channel->soundScriptIO[lowBits] = SEQ_IO_VAL_NONE;
+ channel->seqScriptIO[lowBits] = SEQ_IO_VAL_NONE;
if (AudioLoad_SlowLoadSample(channel->fontId, channel->unk_22 + 0x100,
- &channel->soundScriptIO[lowBits]) == -1) {}
+ &channel->seqScriptIO[lowBits]) == -1) {}
}
break;
case 0x60:
- scriptState->value = channel->soundScriptIO[lowBits];
+ scriptState->value = channel->seqScriptIO[lowBits];
if (lowBits < 2) {
- channel->soundScriptIO[lowBits] = SEQ_IO_VAL_NONE;
+ channel->seqScriptIO[lowBits] = SEQ_IO_VAL_NONE;
}
break;
case 0x50:
- scriptState->value -= channel->soundScriptIO[lowBits];
+ scriptState->value -= channel->seqScriptIO[lowBits];
break;
case 0x20:
@@ -1693,12 +1693,12 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
case 0x30:
cmd = AudioSeq_ScriptReadU8(scriptState);
- seqPlayer->channels[lowBits]->soundScriptIO[cmd] = scriptState->value;
+ seqPlayer->channels[lowBits]->seqScriptIO[cmd] = scriptState->value;
break;
case 0x40:
cmd = AudioSeq_ScriptReadU8(scriptState);
- scriptState->value = seqPlayer->channels[lowBits]->soundScriptIO[cmd];
+ scriptState->value = seqPlayer->channels[lowBits]->seqScriptIO[cmd];
break;
}
}
@@ -1743,14 +1743,18 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
}
seqPlayer->scriptCounter++;
- seqPlayer->tempoAcc += seqPlayer->tempo;
- seqPlayer->tempoAcc += (s16)seqPlayer->unk_0C;
- if (seqPlayer->tempoAcc < gAudioCtx.tempoInternalToExternal) {
+ // Apply the tempo by controlling the number of updates run on the .seq script.
+ // Processing the .seq script every possible update will result in a tempo = maxTempo
+ // Processing the .seq script a fraction of the updates will result in a `tempo = fraction * maxTempo`
+ // where `fraction = (tempo + tempoChange) / maxTempo`
+ // This algorithm uses `tempoAcc` to discretize `(tempo + tempoChange) / maxTempo`
+ seqPlayer->tempoAcc += seqPlayer->tempo;
+ seqPlayer->tempoAcc += (s16)seqPlayer->tempoChange;
+ if (seqPlayer->tempoAcc < gAudioCtx.maxTempo) {
return;
}
-
- seqPlayer->tempoAcc -= (u16)gAudioCtx.tempoInternalToExternal;
+ seqPlayer->tempoAcc -= (u16)gAudioCtx.maxTempo;
if (seqPlayer->stopScript == true) {
return;
@@ -1810,9 +1814,9 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
break;
case 0xDD:
- seqPlayer->tempo = AudioSeq_ScriptReadU8(seqScript) * TATUMS_PER_BEAT;
- if (seqPlayer->tempo > gAudioCtx.tempoInternalToExternal) {
- seqPlayer->tempo = (u16)gAudioCtx.tempoInternalToExternal;
+ seqPlayer->tempo = AudioSeq_ScriptReadU8(seqScript) * SEQTICKS_PER_BEAT;
+ if (seqPlayer->tempo > gAudioCtx.maxTempo) {
+ seqPlayer->tempo = (u16)gAudioCtx.maxTempo;
}
if ((s16)seqPlayer->tempo <= 0) {
@@ -1821,7 +1825,7 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
break;
case 0xDC:
- seqPlayer->unk_0C = (s8)AudioSeq_ScriptReadU8(seqScript) * TATUMS_PER_BEAT;
+ seqPlayer->tempoChange = (s8)AudioSeq_ScriptReadU8(seqScript) * SEQTICKS_PER_BEAT;
break;
case 0xDA:
@@ -1982,17 +1986,17 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
break;
case 0x50:
- seqScript->value -= seqPlayer->soundScriptIO[cmdLowBits];
+ seqScript->value -= seqPlayer->seqScriptIO[cmdLowBits];
break;
case 0x70:
- seqPlayer->soundScriptIO[cmdLowBits] = seqScript->value;
+ seqPlayer->seqScriptIO[cmdLowBits] = seqScript->value;
break;
case 0x80:
- seqScript->value = seqPlayer->soundScriptIO[cmdLowBits];
+ seqScript->value = seqPlayer->seqScriptIO[cmdLowBits];
if (cmdLowBits < 2) {
- seqPlayer->soundScriptIO[cmdLowBits] = SEQ_IO_VAL_NONE;
+ seqPlayer->seqScriptIO[cmdLowBits] = SEQ_IO_VAL_NONE;
}
break;
@@ -2014,14 +2018,14 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
cmd = AudioSeq_ScriptReadU8(seqScript);
temp = AudioSeq_ScriptReadS16(seqScript);
data2 = &seqPlayer->seqData[temp];
- AudioLoad_SlowLoadSeq(cmd, data2, &seqPlayer->soundScriptIO[cmdLowBits]);
+ AudioLoad_SlowLoadSeq(cmd, data2, &seqPlayer->seqScriptIO[cmdLowBits]);
break;
case 0x60:
cmd = AudioSeq_ScriptReadU8(seqScript);
value = cmd;
temp = AudioSeq_ScriptReadU8(seqScript);
- AudioLoad_ScriptLoad(value, temp, &seqPlayer->soundScriptIO[cmdLowBits]);
+ AudioLoad_ScriptLoad(value, temp, &seqPlayer->seqScriptIO[cmdLowBits]);
break;
}
}
@@ -2038,7 +2042,7 @@ void AudioSeq_ProcessSequences(s32 arg0) {
SequencePlayer* seqPlayer;
u32 i;
- gAudioCtx.noteSubEuOffset = (gAudioCtx.audioBufferParameters.updatesPerFrame - arg0 - 1) * gAudioCtx.numNotes;
+ gAudioCtx.noteSubEuOffset = (gAudioCtx.audioBufferParameters.ticksPerUpdate - arg0 - 1) * gAudioCtx.numNotes;
for (i = 0; i < (u32)gAudioCtx.audioBufferParameters.numSequencePlayers; i++) {
seqPlayer = &gAudioCtx.seqPlayers[i];
@@ -2069,8 +2073,8 @@ void AudioSeq_ResetSequencePlayer(SequencePlayer* seqPlayer) {
seqPlayer->fadeTimer = 0;
seqPlayer->fadeTimerUnkEu = 0;
seqPlayer->tempoAcc = 0;
- seqPlayer->tempo = 120 * TATUMS_PER_BEAT; // 120 BPM
- seqPlayer->unk_0C = 0;
+ seqPlayer->tempo = 120 * SEQTICKS_PER_BEAT; // 120 BPM
+ seqPlayer->tempoChange = 0;
seqPlayer->transposition = 0;
seqPlayer->noteAllocPolicy = 0;
seqPlayer->shortNoteVelocityTable = gDefaultShortNoteVelocityTable;
@@ -2122,8 +2126,8 @@ void AudioSeq_InitSequencePlayer(SequencePlayer* seqPlayer) {
seqPlayer->seqDmaInProgress = false;
seqPlayer->applyBend = false;
- for (j = 0; j < ARRAY_COUNT(seqPlayer->soundScriptIO); j++) {
- seqPlayer->soundScriptIO[j] = SEQ_IO_VAL_NONE;
+ for (j = 0; j < ARRAY_COUNT(seqPlayer->seqScriptIO); j++) {
+ seqPlayer->seqScriptIO[j] = SEQ_IO_VAL_NONE;
}
seqPlayer->muteBehavior = MUTE_BEHAVIOR_SOFTEN | MUTE_BEHAVIOR_STOP_NOTES;
diff --git a/src/audio/lib/synthesis.c b/src/audio/lib/synthesis.c
index 51b2c2e5a..321bd79a5 100644
--- a/src/audio/lib/synthesis.c
+++ b/src/audio/lib/synthesis.c
@@ -5,7 +5,7 @@
#define DMEM_TEMP 0x3C0
#define DMEM_UNCOMPRESSED_NOTE 0x580
#define DMEM_HAAS_TEMP 0x5C0
-#define DMEM_SCRATCH2 0x760 // = DMEM_TEMP + DMEM_2CH_SIZE + a bit more
+#define DMEM_COMB_TEMP 0x760 // = DMEM_TEMP + DMEM_2CH_SIZE + a bit more
#define DMEM_COMPRESSED_ADPCM_DATA 0x940 // = DMEM_LEFT_CH
#define DMEM_LEFT_CH 0x940
#define DMEM_RIGHT_CH 0xAE0
@@ -38,14 +38,14 @@ u32 sEnvMixerOp = _SHIFTL(A_ENVMIXER, 24, 8);
// Store the left dry channel in a temp space to be delayed to produce the haas effect
u32 sEnvMixerLeftHaasDmemDests =
- MK_CMD(DMEM_HAAS_TEMP >> 4, DMEM_RIGHT_CH >> 4, DMEM_WET_LEFT_CH >> 4, DMEM_WET_RIGHT_CH >> 4);
+ AUDIO_MK_CMD(DMEM_HAAS_TEMP >> 4, DMEM_RIGHT_CH >> 4, DMEM_WET_LEFT_CH >> 4, DMEM_WET_RIGHT_CH >> 4);
// Store the right dry channel in a temp space to be delayed to produce the haas effect
u32 sEnvMixerRightHaasDmemDests =
- MK_CMD(DMEM_LEFT_CH >> 4, DMEM_HAAS_TEMP >> 4, DMEM_WET_LEFT_CH >> 4, DMEM_WET_RIGHT_CH >> 4);
+ AUDIO_MK_CMD(DMEM_LEFT_CH >> 4, DMEM_HAAS_TEMP >> 4, DMEM_WET_LEFT_CH >> 4, DMEM_WET_RIGHT_CH >> 4);
u32 sEnvMixerDefaultDmemDests =
- MK_CMD(DMEM_LEFT_CH >> 4, DMEM_RIGHT_CH >> 4, DMEM_WET_LEFT_CH >> 4, DMEM_WET_RIGHT_CH >> 4);
+ AUDIO_MK_CMD(DMEM_LEFT_CH >> 4, DMEM_RIGHT_CH >> 4, DMEM_WET_LEFT_CH >> 4, DMEM_WET_RIGHT_CH >> 4);
u16 D_801304B0[] = {
0x7FFF, 0xD001, 0x3FFF, 0xF001, 0x5FFF, 0x9001, 0x7FFF, 0x8001,
@@ -158,32 +158,32 @@ Acmd* AudioSynth_Update(Acmd* cmdStart, s32* cmdCnt, s16* aiStart, s32 aiBufLen)
SynthesisReverb* reverb;
cmdP = cmdStart;
- for (i = gAudioCtx.audioBufferParameters.updatesPerFrame; i > 0; i--) {
+ for (i = gAudioCtx.audioBufferParameters.ticksPerUpdate; i > 0; i--) {
AudioSeq_ProcessSequences(i - 1);
- func_800DB03C(gAudioCtx.audioBufferParameters.updatesPerFrame - i);
+ func_800DB03C(gAudioCtx.audioBufferParameters.ticksPerUpdate - i);
}
aiBufP = aiStart;
gAudioCtx.curLoadedBook = NULL;
- for (i = gAudioCtx.audioBufferParameters.updatesPerFrame; i > 0; i--) {
+ for (i = gAudioCtx.audioBufferParameters.ticksPerUpdate; i > 0; i--) {
if (i == 1) {
chunkLen = aiBufLen;
- } else if ((aiBufLen / i) >= gAudioCtx.audioBufferParameters.samplesPerUpdateMax) {
- chunkLen = gAudioCtx.audioBufferParameters.samplesPerUpdateMax;
- } else if (gAudioCtx.audioBufferParameters.samplesPerUpdateMin >= (aiBufLen / i)) {
- chunkLen = gAudioCtx.audioBufferParameters.samplesPerUpdateMin;
+ } else if ((aiBufLen / i) >= gAudioCtx.audioBufferParameters.samplesPerTickMax) {
+ chunkLen = gAudioCtx.audioBufferParameters.samplesPerTickMax;
+ } else if (gAudioCtx.audioBufferParameters.samplesPerTickMin >= (aiBufLen / i)) {
+ chunkLen = gAudioCtx.audioBufferParameters.samplesPerTickMin;
} else {
- chunkLen = gAudioCtx.audioBufferParameters.samplesPerUpdate;
+ chunkLen = gAudioCtx.audioBufferParameters.samplesPerTick;
}
for (j = 0; j < gAudioCtx.numSynthesisReverbs; j++) {
if (gAudioCtx.synthesisReverbs[j].useReverb) {
- AudioSynth_InitNextRingBuf(chunkLen, gAudioCtx.audioBufferParameters.updatesPerFrame - i, j);
+ AudioSynth_InitNextRingBuf(chunkLen, gAudioCtx.audioBufferParameters.ticksPerUpdate - i, j);
}
}
- cmdP = AudioSynth_DoOneAudioUpdate(aiBufP, chunkLen, cmdP, gAudioCtx.audioBufferParameters.updatesPerFrame - i);
+ cmdP = AudioSynth_DoOneAudioUpdate(aiBufP, chunkLen, cmdP, gAudioCtx.audioBufferParameters.ticksPerUpdate - i);
aiBufLen -= chunkLen;
aiBufP += 2 * chunkLen;
}
@@ -203,7 +203,7 @@ void func_800DB2C0(s32 updateIndex, s32 noteIndex) {
NoteSubEu* noteSubEu;
s32 i;
- for (i = updateIndex + 1; i < gAudioCtx.audioBufferParameters.updatesPerFrame; i++) {
+ for (i = updateIndex + 1; i < gAudioCtx.audioBufferParameters.ticksPerUpdate; i++) {
noteSubEu = &gAudioCtx.noteSubsEu[(gAudioCtx.numNotes * i) + noteIndex];
if (!noteSubEu->bitField0.needsInit) {
noteSubEu->bitField0.enabled = false;
@@ -717,7 +717,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
s32 frameIndex;
s32 skipBytes;
s32 temp_v1_6;
- void* buf;
+ s16* combFilterState;
s32 nSamplesToDecode;
u32 sampleAddr;
u32 samplesLenFixedPoint;
@@ -740,12 +740,12 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
s32 resampledTempLen;
u16 sampleDmemBeforeResampling;
s32 sampleDataOffset;
- s32 thing;
+ s32 combFilterDmem;
s32 s5;
Note* note;
u32 numSamplesToLoad;
- u16 unk7;
- u16 unkE;
+ u16 combFilterSize;
+ u16 combFilterGain;
s16* filter;
s32 bookOffset;
s32 finished;
@@ -769,7 +769,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
synthState->prevHaasEffectRightDelaySize = 0;
synthState->reverbVol = noteSubEu->reverbVol;
synthState->numParts = 0;
- synthState->unk_1A = 1;
+ synthState->combFilterNeedsInit = true;
note->noteSubEu.bitField0.finished = false;
finished = false;
}
@@ -1089,23 +1089,26 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
AudioSynth_LoadFilterBuffer(cmd++, flags, DMEM_TEMP, synthState->synthesisBuffers->mixEnvelopeState);
}
- unk7 = noteSubEu->unk_07;
- unkE = noteSubEu->unk_0E;
- buf = synthState->synthesisBuffers->unkState;
- if (unk7 != 0 && noteSubEu->unk_0E != 0) {
- AudioSynth_DMemMove(cmd++, DMEM_TEMP, DMEM_SCRATCH2, aiBufLen * SAMPLE_SIZE);
- thing = DMEM_SCRATCH2 - unk7;
- if (synthState->unk_1A != 0) {
- AudioSynth_ClearBuffer(cmd++, thing, unk7);
- synthState->unk_1A = 0;
+ // Apply the comb filter to the mono-signal by taking the signal with a small temporal offset,
+ // and adding it back to itself
+ combFilterSize = noteSubEu->combFilterSize;
+ combFilterGain = noteSubEu->combFilterGain;
+ combFilterState = synthState->synthesisBuffers->combFilterState;
+ if ((combFilterSize != 0) && (noteSubEu->combFilterGain != 0)) {
+ AudioSynth_DMemMove(cmd++, DMEM_TEMP, DMEM_COMB_TEMP, aiBufLen * SAMPLE_SIZE);
+ combFilterDmem = DMEM_COMB_TEMP - combFilterSize;
+ if (synthState->combFilterNeedsInit) {
+ AudioSynth_ClearBuffer(cmd++, combFilterDmem, combFilterSize);
+ synthState->combFilterNeedsInit = false;
} else {
- AudioSynth_LoadBuffer(cmd++, thing, unk7, buf);
+ AudioSynth_LoadBuffer(cmd++, combFilterDmem, combFilterSize, combFilterState);
}
- AudioSynth_SaveBuffer(cmd++, DMEM_TEMP + (aiBufLen * SAMPLE_SIZE) - unk7, unk7, buf);
- AudioSynth_Mix(cmd++, (aiBufLen * (s32)SAMPLE_SIZE) >> 4, unkE, DMEM_SCRATCH2, thing);
- AudioSynth_DMemMove(cmd++, thing, DMEM_TEMP, aiBufLen * SAMPLE_SIZE);
+ AudioSynth_SaveBuffer(cmd++, DMEM_TEMP + (aiBufLen * SAMPLE_SIZE) - combFilterSize, combFilterSize,
+ combFilterState);
+ AudioSynth_Mix(cmd++, (aiBufLen * (s32)SAMPLE_SIZE) >> 4, combFilterGain, DMEM_COMB_TEMP, combFilterDmem);
+ AudioSynth_DMemMove(cmd++, combFilterDmem, DMEM_TEMP, aiBufLen * SAMPLE_SIZE);
} else {
- synthState->unk_1A = 1;
+ synthState->combFilterNeedsInit = true;
}
if ((noteSubEu->haasEffectLeftDelaySize != 0) || (synthState->prevHaasEffectLeftDelaySize != 0)) {
diff --git a/src/audio/lib/thread.c b/src/audio/lib/thread.c
index 53cd7d246..22afc33fd 100644
--- a/src/audio/lib/thread.c
+++ b/src/audio/lib/thread.c
@@ -3,42 +3,23 @@
#define SAMPLES_TO_OVERPRODUCE 0x10
#define EXTRA_BUFFERED_AI_SAMPLES_TARGET 0x80
-typedef enum {
- CHAN_UPD_UNK_0, // 0
- CHAN_UPD_VOL_SCALE, // 1
- CHAN_UPD_VOL, // 2
- CHAN_UPD_PAN_SIGNED, // 3
- CHAN_UPD_FREQ_SCALE, // 4
- CHAN_UPD_REVERB, // 5
- CHAN_UPD_SCRIPT_IO, // 6
- CHAN_UPD_PAN_UNSIGNED, // 7
- CHAN_UPD_STOP_SOMETHING2, // 8
- CHAN_UPD_MUTE_BEHAVE, // 9
- CHAN_UPD_VIBE_X8, // 10
- CHAN_UPD_VIBE_X32, // 11
- CHAN_UPD_UNK_0F, // 12
- CHAN_UPD_UNK_20, // 13
- CHAN_UPD_STEREO // 14
-} ChannelUpdateType;
-
-void func_800E6300(SequenceChannel* channel, AudioCmd* cmd);
-void func_800E59AC(s32 playerIdx, s32 fadeTimer);
-void Audio_InitMesgQueues(void);
-AudioTask* func_800E5000(void);
-void Audio_ProcessCmds(u32);
-void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd);
-void func_800E5958(s32 playerIdx, s32 fadeTimer);
-s32 func_800E66C0(s32 arg0);
+AudioTask* AudioThread_UpdateImpl(void);
+void AudioThread_SetFadeInTimer(s32 seqPlayerIndex, s32 fadeTimer);
+void AudioThread_SetFadeOutTimer(s32 seqPlayerIndex, s32 fadeTimer);
+void AudioThread_ProcessCmds(u32);
+void AudioThread_ProcessSeqPlayerCmd(SequencePlayer* seqPlayer, AudioCmd* cmd);
+void AudioThread_ProcessChannelCmd(SequenceChannel* channel, AudioCmd* cmd);
+s32 func_800E66C0(s32 flags);
// AudioMgr_Retrace
-AudioTask* func_800E4FE0(void) {
- return func_800E5000();
+AudioTask* AudioThread_Update(void) {
+ return AudioThread_UpdateImpl();
}
/**
* This is Audio_Update for the audio thread
*/
-AudioTask* func_800E5000(void) {
+AudioTask* AudioThread_UpdateImpl(void) {
static s32 sMaxAbiCmdCnt = 0x80;
static AudioTask* sWaitingAudioTask = NULL;
u32 samplesRemainingInAi;
@@ -55,8 +36,8 @@ AudioTask* func_800E5000(void) {
gAudioCtx.totalTaskCount++;
if (gAudioCtx.totalTaskCount % (gAudioCtx.audioBufferParameters.specUnk4) != 0) {
- if (D_801755D0 != NULL) {
- D_801755D0();
+ if (gAudioCustomUpdateFunction != NULL) {
+ gAudioCustomUpdateFunction();
}
if ((gAudioCtx.totalTaskCount % gAudioCtx.audioBufferParameters.specUnk4) + 1 ==
@@ -82,8 +63,8 @@ AudioTask* func_800E5000(void) {
}
}
- if (D_801755D0 != NULL) {
- D_801755D0();
+ if (gAudioCustomUpdateFunction != NULL) {
+ gAudioCustomUpdateFunction();
}
sp5C = gAudioCtx.curAudioFrameDmaCount;
@@ -114,7 +95,7 @@ AudioTask* func_800E5000(void) {
if (gAudioCtx.resetStatus != 0) {
if (AudioHeap_ResetStep() == 0) {
if (gAudioCtx.resetStatus == 0) {
- osSendMesg(gAudioCtx.audioResetQueueP, (OSMesg)(u32)gAudioCtx.audioResetSpecIdToLoad, OS_MESG_NOBLOCK);
+ osSendMesg(gAudioCtx.audioResetQueueP, (OSMesg)(u32)gAudioCtx.specId, OS_MESG_NOBLOCK);
}
sWaitingAudioTask = NULL;
@@ -151,13 +132,13 @@ AudioTask* func_800E5000(void) {
j = 0;
if (gAudioCtx.resetStatus == 0) {
// msg = 0000RREE R = read pos, E = End Pos
- while (osRecvMesg(gAudioCtx.cmdProcQueueP, (OSMesg*)&sp4C, OS_MESG_NOBLOCK) != -1) {
+ while (osRecvMesg(gAudioCtx.threadCmdProcQueueP, (OSMesg*)&sp4C, OS_MESG_NOBLOCK) != -1) {
if (1) {}
- Audio_ProcessCmds(sp4C);
+ AudioThread_ProcessCmds(sp4C);
j++;
}
- if ((j == 0) && (gAudioCtx.cmdQueueFinished)) {
- Audio_ScheduleProcessCmds();
+ if ((j == 0) && (gAudioCtx.threadCmdQueueFinished)) {
+ AudioThread_ScheduleProcessCmds();
}
}
@@ -169,9 +150,9 @@ AudioTask* func_800E5000(void) {
gAudioCtx.audioRandom = gAudioCtx.audioRandom + gAudioCtx.aiBuffers[index][gAudioCtx.totalTaskCount & 0xFF];
// gWaveSamples[8] interprets compiled assembly code as s16 samples as a way to generate sound with noise.
- // Start with the address of func_800E4FE0, and offset it by a random number between 0 - 0xFFF0
+ // Start with the address of AudioThread_Update, and offset it by a random number between 0 - 0xFFF0
// Use the resulting address as the starting address to interpret an array of samples i.e. `s16 samples[]`
- gWaveSamples[8] = (s16*)(((u8*)func_800E4FE0) + (gAudioCtx.audioRandom & 0xFFF0));
+ gWaveSamples[8] = (s16*)((u8*)AudioThread_Update + (gAudioCtx.audioRandom & 0xFFF0));
index = gAudioCtx.rspTaskIndex;
gAudioCtx.curTask->msgQueue = NULL;
@@ -208,63 +189,57 @@ AudioTask* func_800E5000(void) {
}
}
-#define ACMD_SND_MDE ((u32)0xF0000000)
-#define ACMD_MUTE ((u32)0xF1000000)
-
-void func_800E5584(AudioCmd* cmd) {
+void AudioThread_ProcessGlobalCmd(AudioCmd* cmd) {
s32 i;
- s32 pad;
- s32 pad2;
- u32 temp_a1_5;
- u32 temp_t7;
+ s32 pad[3];
+ u32 flags;
switch (cmd->op) {
- case 0x81:
+ case AUDIOCMD_OP_GLOBAL_SYNC_LOAD_SEQ_PARTS:
AudioLoad_SyncLoadSeqParts(cmd->arg1, cmd->arg2);
break;
- case 0x82:
+ case AUDIOCMD_OP_GLOBAL_INIT_SEQPLAYER:
AudioLoad_SyncInitSeqPlayer(cmd->arg0, cmd->arg1, cmd->arg2);
- func_800E59AC(cmd->arg0, cmd->asInt);
+ AudioThread_SetFadeInTimer(cmd->arg0, cmd->asInt);
break;
- case 0x85:
+ case AUDIOCMD_OP_GLOBAL_INIT_SEQPLAYER_SKIP_TICKS:
AudioLoad_SyncInitSeqPlayerSkipTicks(cmd->arg0, cmd->arg1, cmd->asInt);
break;
- case 0x83:
+ case AUDIOCMD_OP_GLOBAL_DISABLE_SEQPLAYER:
if (gAudioCtx.seqPlayers[cmd->arg0].enabled) {
if (cmd->asInt == 0) {
AudioSeq_SequencePlayerDisableAsFinished(&gAudioCtx.seqPlayers[cmd->arg0]);
} else {
- func_800E5958(cmd->arg0, cmd->asInt);
+ AudioThread_SetFadeOutTimer(cmd->arg0, cmd->asInt);
}
}
break;
- case 0xF0:
+ case AUDIOCMD_OP_GLOBAL_SET_SOUND_MODE:
gAudioCtx.soundMode = cmd->asUInt;
break;
- case 0xF1:
+ case AUDIOCMD_OP_GLOBAL_MUTE:
for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) {
SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[i];
- seqPlayer->muted = 1;
- seqPlayer->recalculateVolume = 1;
+ seqPlayer->muted = true;
+ seqPlayer->recalculateVolume = true;
}
break;
- case 0xF2:
+ case AUDIOCMD_OP_GLOBAL_UNMUTE:
if (cmd->asUInt == 1) {
for (i = 0; i < gAudioCtx.numNotes; i++) {
Note* note = &gAudioCtx.notes[i];
NoteSubEu* subEu = &note->noteSubEu;
- if (subEu->bitField0.enabled && note->playbackState.unk_04 == 0) {
- if (note->playbackState.parentLayer->channel->muteBehavior & MUTE_BEHAVIOR_3) {
- subEu->bitField0.finished = true;
- }
+ if (subEu->bitField0.enabled && (note->playbackState.unk_04 == 0) &&
+ (note->playbackState.parentLayer->channel->muteBehavior & MUTE_BEHAVIOR_3)) {
+ subEu->bitField0.finished = true;
}
}
}
@@ -272,53 +247,53 @@ void func_800E5584(AudioCmd* cmd) {
for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) {
SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[i];
- seqPlayer->muted = 0;
- seqPlayer->recalculateVolume = 1;
+ seqPlayer->muted = false;
+ seqPlayer->recalculateVolume = true;
}
break;
- case 0xF3:
+ case AUDIOCMD_OP_GLOBAL_SYNC_LOAD_INSTRUMENT:
AudioLoad_SyncLoadInstrument(cmd->arg0, cmd->arg1, cmd->arg2);
break;
- case 0xF4:
+ case AUDIOCMD_OP_GLOBAL_ASYNC_LOAD_SAMPLE_BANK:
AudioLoad_AsyncLoadSampleBank(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue);
break;
- case 0xF5:
+ case AUDIOCMD_OP_GLOBAL_ASYNC_LOAD_FONT:
AudioLoad_AsyncLoadFont(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue);
break;
- case 0xFC:
+ case AUDIOCMD_OP_GLOBAL_ASYNC_LOAD_SEQ:
AudioLoad_AsyncLoadSeq(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue);
break;
- case 0xF6:
+ case AUDIOCMD_OP_GLOBAL_DISCARD_SEQ_FONTS:
AudioLoad_DiscardSeqFonts(cmd->arg1);
break;
- case 0x90:
- gAudioCtx.unk_5BDC[cmd->arg0] = cmd->asUShort;
+ case AUDIOCMD_OP_GLOBAL_SET_CHANNEL_MASK:
+ gAudioCtx.threadCmdChannelMask[cmd->arg0] = cmd->asUShort;
break;
- case 0xF9:
+ case AUDIOCMD_OP_GLOBAL_RESET_AUDIO_HEAP:
gAudioCtx.resetStatus = 5;
- gAudioCtx.audioResetSpecIdToLoad = cmd->asUInt;
+ gAudioCtx.specId = cmd->asUInt;
break;
- case 0xFB:
- D_801755D0 = (void (*)(void))cmd->asUInt;
+ case AUDIOCMD_OP_GLOBAL_SET_CUSTOM_UPDATE_FUNCTION:
+ gAudioCustomUpdateFunction = (AudioCustomUpdateFunction)cmd->asUInt;
break;
- case 0xE0:
- case 0xE1:
- case 0xE2:
- Audio_SetFontInstrument(cmd->op - 0xE0, cmd->arg0, cmd->arg1, cmd->data);
+ case AUDIOCMD_OP_GLOBAL_SET_DRUM_FONT:
+ case AUDIOCMD_OP_GLOBAL_SET_SFX_FONT:
+ case AUDIOCMD_OP_GLOBAL_SET_INSTRUMENT_FONT:
+ Audio_SetFontInstrument(cmd->op - AUDIOCMD_OP_GLOBAL_SET_DRUM_FONT, cmd->arg0, cmd->arg1, cmd->data);
break;
- case 0xFE:
- temp_t7 = cmd->asUInt;
- if (temp_t7 == 1) {
+ case AUDIOCMD_OP_GLOBAL_DISABLE_ALL_SEQPLAYERS:
+ flags = cmd->asUInt;
+ if (flags == 1) {
for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) {
SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[i];
@@ -327,10 +302,10 @@ void func_800E5584(AudioCmd* cmd) {
}
}
}
- func_800E66C0(temp_t7);
+ func_800E66C0(flags);
break;
- case 0xE3:
+ case AUDIOCMD_OP_GLOBAL_POP_PERSISTENT_CACHE:
AudioHeap_PopPersistentCache(cmd->asInt);
break;
@@ -339,9 +314,8 @@ void func_800E5584(AudioCmd* cmd) {
}
}
-// SetFadeOutTimer
-void func_800E5958(s32 playerIdx, s32 fadeTimer) {
- SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx];
+void AudioThread_SetFadeOutTimer(s32 seqPlayerIndex, s32 fadeTimer) {
+ SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[seqPlayerIndex];
if (fadeTimer == 0) {
fadeTimer = 1;
@@ -352,12 +326,11 @@ void func_800E5958(s32 playerIdx, s32 fadeTimer) {
seqPlayer->fadeTimer = fadeTimer;
}
-// SetFadeInTimer
-void func_800E59AC(s32 playerIdx, s32 fadeTimer) {
+void AudioThread_SetFadeInTimer(s32 seqPlayerIndex, s32 fadeTimer) {
SequencePlayer* seqPlayer;
if (fadeTimer != 0) {
- seqPlayer = &gAudioCtx.seqPlayers[playerIdx];
+ seqPlayer = &gAudioCtx.seqPlayers[seqPlayerIndex];
seqPlayer->state = 1;
seqPlayer->fadeTimerUnkEu = fadeTimer;
seqPlayer->fadeTimer = fadeTimer;
@@ -366,63 +339,67 @@ void func_800E59AC(s32 playerIdx, s32 fadeTimer) {
}
}
-void Audio_InitMesgQueuesInternal(void) {
- gAudioCtx.cmdWrPos = 0;
- gAudioCtx.cmdRdPos = 0;
- gAudioCtx.cmdQueueFinished = 0;
+void AudioThread_InitMesgQueuesImpl(void) {
+ gAudioCtx.threadCmdWritePos = 0;
+ gAudioCtx.threadCmdReadPos = 0;
+ gAudioCtx.threadCmdQueueFinished = false;
+
gAudioCtx.taskStartQueueP = &gAudioCtx.taskStartQueue;
- gAudioCtx.cmdProcQueueP = &gAudioCtx.cmdProcQueue;
+ gAudioCtx.threadCmdProcQueueP = &gAudioCtx.threadCmdProcQueue;
gAudioCtx.audioResetQueueP = &gAudioCtx.audioResetQueue;
+
osCreateMesgQueue(gAudioCtx.taskStartQueueP, gAudioCtx.taskStartMsgBuf, ARRAY_COUNT(gAudioCtx.taskStartMsgBuf));
- osCreateMesgQueue(gAudioCtx.cmdProcQueueP, gAudioCtx.cmdProcMsgBuf, ARRAY_COUNT(gAudioCtx.cmdProcMsgBuf));
+ osCreateMesgQueue(gAudioCtx.threadCmdProcQueueP, gAudioCtx.threadCmdProcMsgBuf,
+ ARRAY_COUNT(gAudioCtx.threadCmdProcMsgBuf));
osCreateMesgQueue(gAudioCtx.audioResetQueueP, gAudioCtx.audioResetMsgBuf, ARRAY_COUNT(gAudioCtx.audioResetMsgBuf));
}
-void Audio_QueueCmd(u32 opArgs, void** data) {
- AudioCmd* cmd = &gAudioCtx.cmdBuf[gAudioCtx.cmdWrPos & 0xFF];
+void AudioThread_QueueCmd(u32 opArgs, void** data) {
+ AudioCmd* cmd = &gAudioCtx.threadCmdBuf[gAudioCtx.threadCmdWritePos & 0xFF];
cmd->opArgs = opArgs;
cmd->data = *data;
- gAudioCtx.cmdWrPos++;
+ gAudioCtx.threadCmdWritePos++;
- if (gAudioCtx.cmdWrPos == gAudioCtx.cmdRdPos) {
- gAudioCtx.cmdWrPos--;
+ if (gAudioCtx.threadCmdWritePos == gAudioCtx.threadCmdReadPos) {
+ gAudioCtx.threadCmdWritePos--;
}
}
-void Audio_QueueCmdF32(u32 opArgs, f32 data) {
- Audio_QueueCmd(opArgs, (void**)&data);
+void AudioThread_QueueCmdF32(u32 opArgs, f32 data) {
+ AudioThread_QueueCmd(opArgs, (void**)&data);
}
-void Audio_QueueCmdS32(u32 opArgs, s32 data) {
- Audio_QueueCmd(opArgs, (void**)&data);
+void AudioThread_QueueCmdS32(u32 opArgs, s32 data) {
+ AudioThread_QueueCmd(opArgs, (void**)&data);
}
-void Audio_QueueCmdS8(u32 opArgs, s8 data) {
+void AudioThread_QueueCmdS8(u32 opArgs, s8 data) {
u32 uData = data << 0x18;
- Audio_QueueCmd(opArgs, (void**)&uData);
+ AudioThread_QueueCmd(opArgs, (void**)&uData);
}
-void Audio_QueueCmdU16(u32 opArgs, u16 data) {
+void AudioThread_QueueCmdU16(u32 opArgs, u16 data) {
u32 uData = data << 0x10;
- Audio_QueueCmd(opArgs, (void**)&uData);
+ AudioThread_QueueCmd(opArgs, (void**)&uData);
}
-s32 Audio_ScheduleProcessCmds(void) {
+s32 AudioThread_ScheduleProcessCmds(void) {
static s32 D_801304E8 = 0;
s32 ret;
- if (D_801304E8 < (u8)((gAudioCtx.cmdWrPos - gAudioCtx.cmdRdPos) + 0x100)) {
- D_801304E8 = (u8)((gAudioCtx.cmdWrPos - gAudioCtx.cmdRdPos) + 0x100);
+ if (D_801304E8 < (u8)((gAudioCtx.threadCmdWritePos - gAudioCtx.threadCmdReadPos) + 0x100)) {
+ D_801304E8 = (u8)((gAudioCtx.threadCmdWritePos - gAudioCtx.threadCmdReadPos) + 0x100);
}
- ret = osSendMesg(gAudioCtx.cmdProcQueueP,
- (OSMesg)(((gAudioCtx.cmdRdPos & 0xFF) << 8) | (gAudioCtx.cmdWrPos & 0xFF)), OS_MESG_NOBLOCK);
+ ret = osSendMesg(gAudioCtx.threadCmdProcQueueP,
+ (OSMesg)(((gAudioCtx.threadCmdReadPos & 0xFF) << 8) | (gAudioCtx.threadCmdWritePos & 0xFF)),
+ OS_MESG_NOBLOCK);
if (ret != -1) {
- gAudioCtx.cmdRdPos = gAudioCtx.cmdWrPos;
+ gAudioCtx.threadCmdReadPos = gAudioCtx.threadCmdWritePos;
ret = 0;
} else {
return -1;
@@ -431,72 +408,72 @@ s32 Audio_ScheduleProcessCmds(void) {
return ret;
}
-void Audio_ResetCmdQueue(void) {
- gAudioCtx.cmdQueueFinished = 0;
- gAudioCtx.cmdRdPos = gAudioCtx.cmdWrPos;
+void AudioThread_ResetCmdQueue(void) {
+ gAudioCtx.threadCmdQueueFinished = false;
+ gAudioCtx.threadCmdReadPos = gAudioCtx.threadCmdWritePos;
}
-void Audio_ProcessCmd(AudioCmd* cmd) {
+void AudioThread_ProcessCmd(AudioCmd* cmd) {
SequencePlayer* seqPlayer;
- u16 phi_v0;
- s32 i;
+ u16 threadCmdChannelMask;
+ s32 channelIndex;
if ((cmd->op & 0xF0) == 0xF0) {
- func_800E5584(cmd);
+ AudioThread_ProcessGlobalCmd(cmd);
return;
}
if (cmd->arg0 < gAudioCtx.audioBufferParameters.numSequencePlayers) {
seqPlayer = &gAudioCtx.seqPlayers[cmd->arg0];
if (cmd->op & 0x80) {
- func_800E5584(cmd);
+ AudioThread_ProcessGlobalCmd(cmd);
return;
}
if (cmd->op & 0x40) {
- func_800E6128(seqPlayer, cmd);
+ AudioThread_ProcessSeqPlayerCmd(seqPlayer, cmd);
return;
}
- if (cmd->arg1 < 0x10) {
- func_800E6300(seqPlayer->channels[cmd->arg1], cmd);
+ if (cmd->arg1 < SEQ_NUM_CHANNELS) {
+ AudioThread_ProcessChannelCmd(seqPlayer->channels[cmd->arg1], cmd);
return;
}
- if (cmd->arg1 == 0xFF) {
- phi_v0 = gAudioCtx.unk_5BDC[cmd->arg0];
- for (i = 0; i < 16; i++) {
- if (phi_v0 & 1) {
- func_800E6300(seqPlayer->channels[i], cmd);
+ if (cmd->arg1 == AUDIOCMD_ALL_CHANNELS) {
+ threadCmdChannelMask = gAudioCtx.threadCmdChannelMask[cmd->arg0];
+ for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
+ if (threadCmdChannelMask & 1) {
+ AudioThread_ProcessChannelCmd(seqPlayer->channels[channelIndex], cmd);
}
- phi_v0 = phi_v0 >> 1;
+ threadCmdChannelMask = threadCmdChannelMask >> 1;
}
}
}
}
-void Audio_ProcessCmds(u32 msg) {
- static u8 curCmdRdPos = 0;
+void AudioThread_ProcessCmds(u32 msg) {
+ static u8 sCurCmdRdPos = 0;
AudioCmd* cmd;
u8 endPos;
- if (!gAudioCtx.cmdQueueFinished) {
- curCmdRdPos = msg >> 8;
+ if (!gAudioCtx.threadCmdQueueFinished) {
+ sCurCmdRdPos = msg >> 8;
}
while (true) {
endPos = msg & 0xFF;
- if (curCmdRdPos == endPos) {
- gAudioCtx.cmdQueueFinished = 0;
+ if (sCurCmdRdPos == endPos) {
+ gAudioCtx.threadCmdQueueFinished = false;
return;
}
- cmd = &gAudioCtx.cmdBuf[curCmdRdPos++ & 0xFF];
- if (cmd->op == 0xF8) {
- gAudioCtx.cmdQueueFinished = 1;
+ cmd = &gAudioCtx.threadCmdBuf[sCurCmdRdPos++ & 0xFF];
+ if (cmd->op == AUDIOCMD_OP_GLOBAL_STOP_AUDIOCMDS) {
+ gAudioCtx.threadCmdQueueFinished = true;
return;
}
- Audio_ProcessCmd(cmd);
- cmd->op = 0;
+ AudioThread_ProcessCmd(cmd);
+ cmd->op = AUDIOCMD_OP_NOOP;
}
}
@@ -511,8 +488,8 @@ u32 func_800E5E20(u32* out) {
return sp1C >> 0x18;
}
-u8* func_800E5E84(s32 arg0, u32* arg1) {
- return AudioLoad_GetFontsForSequence(arg0, arg1);
+u8* AudioThread_GetFontsForSequence(s32 seqId, u32* outNumFonts) {
+ return AudioLoad_GetFontsForSequence(seqId, outNumFonts);
}
void Audio_GetSampleBankIdsOfFont(s32 fontId, u32* sampleBankId1, u32* sampleBankId2) {
@@ -522,11 +499,11 @@ void Audio_GetSampleBankIdsOfFont(s32 fontId, u32* sampleBankId1, u32* sampleBan
s32 func_800E5EDC(void) {
s32 pad;
- s32 sp18;
+ s32 specId;
- if (osRecvMesg(gAudioCtx.audioResetQueueP, (OSMesg*)&sp18, OS_MESG_NOBLOCK) == -1) {
+ if (osRecvMesg(gAudioCtx.audioResetQueueP, (OSMesg*)&specId, OS_MESG_NOBLOCK) == -1) {
return 0;
- } else if (gAudioCtx.audioResetSpecIdToLoad != sp18) {
+ } else if (gAudioCtx.specId != specId) {
return -1;
} else {
return 1;
@@ -540,7 +517,7 @@ void func_800E5F34(void) {
// clang-format on
}
-s32 func_800E5F88(s32 resetPreloadID) {
+s32 AudioThread_ResetAudioHeap(s32 specId) {
s32 resetStatus;
OSMesg msg;
s32 pad;
@@ -548,11 +525,11 @@ s32 func_800E5F88(s32 resetPreloadID) {
func_800E5F34();
resetStatus = gAudioCtx.resetStatus;
if (resetStatus != 0) {
- Audio_ResetCmdQueue();
- if (gAudioCtx.audioResetSpecIdToLoad == resetPreloadID) {
+ AudioThread_ResetCmdQueue();
+ if (gAudioCtx.specId == specId) {
return -2;
} else if (resetStatus > 2) {
- gAudioCtx.audioResetSpecIdToLoad = resetPreloadID;
+ gAudioCtx.specId = specId;
return -3;
} else {
osRecvMesg(gAudioCtx.audioResetQueueP, &msg, OS_MESG_BLOCK);
@@ -560,81 +537,81 @@ s32 func_800E5F88(s32 resetPreloadID) {
}
func_800E5F34();
- Audio_QueueCmdS32(0xF9000000, resetPreloadID);
+ AUDIOCMD_GLOBAL_RESET_AUDIO_HEAP(specId);
- return Audio_ScheduleProcessCmds();
+ return AudioThread_ScheduleProcessCmds();
}
-void Audio_PreNMIInternal(void) {
+void AudioThread_PreNMIInternal(void) {
gAudioCtx.resetTimer = 1;
if (gAudioContextInitialized) {
- func_800E5F88(0);
+ AudioThread_ResetAudioHeap(0);
gAudioCtx.resetStatus = 0;
}
}
-s8 func_800E6070(s32 playerIdx, s32 channelIdx, s32 scriptIdx) {
- SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx];
+s8 AudioThread_GetChannelIO(s32 seqPlayerIndex, s32 channelIndex, s32 ioPort) {
+ SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[seqPlayerIndex];
SequenceChannel* channel;
if (seqPlayer->enabled) {
- channel = seqPlayer->channels[channelIdx];
- return channel->soundScriptIO[scriptIdx];
+ channel = seqPlayer->channels[channelIndex];
+ return channel->seqScriptIO[ioPort];
} else {
- return -1;
+ return SEQ_IO_VAL_NONE;
}
}
-s8 func_800E60C4(s32 playerIdx, s32 port) {
- return gAudioCtx.seqPlayers[playerIdx].soundScriptIO[port];
+s8 AudioThread_GetSeqPlayerIO(s32 seqPlayerIndex, s32 ioPort) {
+ return gAudioCtx.seqPlayers[seqPlayerIndex].seqScriptIO[ioPort];
}
-void Audio_InitExternalPool(void* ramAddr, u32 size) {
+void AudioThread_InitExternalPool(void* ramAddr, u32 size) {
AudioHeap_InitPool(&gAudioCtx.externalPool, ramAddr, size);
}
-void Audio_DestroyExternalPool(void) {
+void AudioThread_ResetExternalPool(void) {
gAudioCtx.externalPool.startRamAddr = NULL;
}
-void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) {
+void AudioThread_ProcessSeqPlayerCmd(SequencePlayer* seqPlayer, AudioCmd* cmd) {
f32 fadeVolume;
switch (cmd->op) {
- case 0x41:
+ case AUDIOCMD_OP_SEQPLAYER_FADE_VOLUME_SCALE:
if (seqPlayer->fadeVolumeScale != cmd->asFloat) {
seqPlayer->fadeVolumeScale = cmd->asFloat;
- seqPlayer->recalculateVolume = 1;
+ seqPlayer->recalculateVolume = true;
}
break;
- case 0x47:
- seqPlayer->tempo = cmd->asInt * 0x30;
+ case AUDIOCMD_OP_SEQPLAYER_SET_TEMPO:
+ seqPlayer->tempo = cmd->asInt * SEQTICKS_PER_BEAT;
break;
- case 0x49:
- seqPlayer->unk_0C = cmd->asInt * 0x30;
+ case AUDIOCMD_OP_SEQPLAYER_CHANGE_TEMPO:
+ seqPlayer->tempoChange = cmd->asInt * SEQTICKS_PER_BEAT;
break;
- case 0x4E:
- seqPlayer->unk_0C = cmd->asInt;
+ case AUDIOCMD_OP_SEQPLAYER_CHANGE_TEMPO_SEQTICKS:
+ seqPlayer->tempoChange = cmd->asInt;
break;
- case 0x48:
+ case AUDIOCMD_OP_SEQPLAYER_SET_TRANSPOSITION:
seqPlayer->transposition = cmd->asSbyte;
break;
- case 0x46:
- seqPlayer->soundScriptIO[cmd->arg2] = cmd->asSbyte;
+ case AUDIOCMD_OP_SEQPLAYER_SET_IO:
+ seqPlayer->seqScriptIO[cmd->arg2] = cmd->asSbyte;
break;
- case 0x4A:
+ case AUDIOCMD_OP_SEQPLAYER_FADE_TO_SET_VOLUME:
fadeVolume = (s32)cmd->arg1 / 127.0f;
- goto block_11;
+ goto apply_fade;
- case 0x4B:
+ case AUDIOCMD_OP_SEQPLAYER_FADE_TO_SCALED_VOLUME:
fadeVolume = ((s32)cmd->arg1 / 100.0f) * seqPlayer->fadeVolume;
- block_11:
+ apply_fade:
if (seqPlayer->state != 2) {
seqPlayer->volume = seqPlayer->fadeVolume;
if (cmd->asInt == 0) {
@@ -649,7 +626,7 @@ void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) {
}
break;
- case 0x4C:
+ case AUDIOCMD_OP_SEQPLAYER_RESET_VOLUME:
if (seqPlayer->state != 2) {
if (cmd->asInt == 0) {
seqPlayer->fadeVolume = seqPlayer->volume;
@@ -663,7 +640,7 @@ void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) {
}
break;
- case 0x4D:
+ case AUDIOCMD_OP_SEQPLAYER_SET_BEND:
seqPlayer->bend = cmd->asFloat;
if (seqPlayer->bend == 1.0f) {
seqPlayer->applyBend = false;
@@ -677,82 +654,83 @@ void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) {
}
}
-void func_800E6300(SequenceChannel* channel, AudioCmd* cmd) {
+void AudioThread_ProcessChannelCmd(SequenceChannel* channel, AudioCmd* cmd) {
switch (cmd->op) {
- case CHAN_UPD_VOL_SCALE:
+ case AUDIOCMD_OP_CHANNEL_SET_VOL_SCALE:
if (channel->volumeScale != cmd->asFloat) {
channel->volumeScale = cmd->asFloat;
- channel->changes.s.volume = 1;
+ channel->changes.s.volume = true;
}
break;
- case CHAN_UPD_VOL:
+ case AUDIOCMD_OP_CHANNEL_SET_VOL:
if (channel->volume != cmd->asFloat) {
channel->volume = cmd->asFloat;
- channel->changes.s.volume = 1;
+ channel->changes.s.volume = true;
}
break;
- case CHAN_UPD_PAN_SIGNED:
+ case AUDIOCMD_OP_CHANNEL_SET_PAN:
if (channel->newPan != cmd->asSbyte) {
channel->newPan = cmd->asSbyte;
- channel->changes.s.pan = 1;
+ channel->changes.s.pan = true;
}
break;
- case CHAN_UPD_PAN_UNSIGNED:
+ case AUDIOCMD_OP_CHANNEL_SET_PAN_WEIGHT:
+ //! @bug: Should compare `asSbyte` to `panChannelWeight`
if (channel->newPan != cmd->asSbyte) {
channel->panChannelWeight = cmd->asSbyte;
- channel->changes.s.pan = 1;
+ channel->changes.s.pan = true;
}
break;
- case CHAN_UPD_FREQ_SCALE:
+ case AUDIOCMD_OP_CHANNEL_SET_FREQ_SCALE:
if (channel->freqScale != cmd->asFloat) {
channel->freqScale = cmd->asFloat;
- channel->changes.s.freqScale = 1;
+ channel->changes.s.freqScale = true;
}
break;
- case CHAN_UPD_REVERB:
- if (channel->reverb != cmd->asSbyte) {
- channel->reverb = cmd->asSbyte;
+ case AUDIOCMD_OP_CHANNEL_SET_REVERB_VOLUME:
+ if (channel->targetReverbVol != cmd->asSbyte) {
+ channel->targetReverbVol = cmd->asSbyte;
}
break;
- case CHAN_UPD_SCRIPT_IO:
- if (cmd->arg2 < 8) {
- channel->soundScriptIO[cmd->arg2] = cmd->asSbyte;
+ case AUDIOCMD_OP_CHANNEL_SET_IO:
+ if (cmd->arg2 < ARRAY_COUNT(channel->seqScriptIO)) {
+ channel->seqScriptIO[cmd->arg2] = cmd->asSbyte;
}
break;
- case CHAN_UPD_STOP_SOMETHING2:
- channel->stopSomething2 = cmd->asSbyte;
+ case AUDIOCMD_OP_CHANNEL_SET_MUTE:
+ channel->muted = cmd->asSbyte;
break;
- case CHAN_UPD_MUTE_BEHAVE:
+ case AUDIOCMD_OP_CHANNEL_SET_MUTE_BEHAVIOR:
channel->muteBehavior = cmd->asSbyte;
break;
- case CHAN_UPD_VIBE_X8:
- channel->vibratoExtentTarget = cmd->asUbyte * 8;
- channel->vibratoExtentChangeDelay = 1;
+ case AUDIOCMD_OP_CHANNEL_SET_VIBRATO_DEPTH:
+ channel->vibratoDepthTarget = cmd->asUbyte * 8;
+ channel->vibratoDepthChangeDelay = 1;
break;
- case CHAN_UPD_VIBE_X32:
+ case AUDIOCMD_OP_CHANNEL_SET_VIBRATO_RATE:
channel->vibratoRateTarget = cmd->asUbyte * 32;
channel->vibratoRateChangeDelay = 1;
break;
- case CHAN_UPD_UNK_0F:
- channel->unk_0F = cmd->asUbyte;
+ case AUDIOCMD_OP_CHANNEL_SET_COMB_FILTER_SIZE:
+ channel->combFilterSize = cmd->asUbyte;
break;
- case CHAN_UPD_UNK_20:
- channel->unk_20 = cmd->asUShort;
+ case AUDIOCMD_OP_CHANNEL_SET_COMB_FILTER_GAIN:
+ channel->combFilterGain = cmd->asUShort;
break;
- case CHAN_UPD_STEREO:
+ case AUDIOCMD_OP_CHANNEL_SET_STEREO:
channel->stereo.asByte = cmd->asUbyte;
break;
@@ -761,24 +739,33 @@ void func_800E6300(SequenceChannel* channel, AudioCmd* cmd) {
}
}
-void func_800E64B0(s32 arg0, s32 arg1, s32 arg2) {
- Audio_QueueCmdS32(((arg0 & 0xFF) << 0x10) | 0xFA000000 | ((arg1 & 0xFF) << 8) | (arg2 & 0xFF), 1);
+/**
+ * Call an audio-thread command that has no code to process it. Unused.
+ */
+void AudioThread_Noop1Cmd(s32 arg0, s32 arg1, s32 arg2) {
+ AUDIOCMD_GLOBAL_NOOP_1(arg0, arg1, arg2, 1);
}
-void func_800E64F8(void) {
- Audio_QueueCmdS32(0xFA000000, 0);
+/**
+ * Call an audio-thread command that has no code to process it. Unused.
+ */
+void AudioThread_Noop1CmdZeroed(void) {
+ AUDIOCMD_GLOBAL_NOOP_1(0, 0, 0, 0);
}
-void func_800E651C(u32 arg0, s32 arg1) {
- Audio_QueueCmdS32((arg1 & 0xFF) | 0xFD000000, arg0);
+/**
+ * Call an audio-thread command that has no code to process it. Unused.
+ */
+void AudioThread_Noop2Cmd(u32 arg0, s32 arg1) {
+ AUDIOCMD_GLOBAL_NOOP_2(0, 0, arg1, arg0);
}
-void Audio_WaitForAudioTask(void) {
+void AudioThread_WaitForAudioTask(void) {
osRecvMesg(gAudioCtx.taskStartQueueP, NULL, OS_MESG_NOBLOCK);
osRecvMesg(gAudioCtx.taskStartQueueP, NULL, OS_MESG_BLOCK);
}
-s32 func_800E6590(s32 playerIdx, s32 arg1, s32 arg2) {
+s32 func_800E6590(s32 seqPlayerIndex, s32 channelIndex, s32 layerIndex) {
SequencePlayer* seqPlayer;
SequenceLayer* layer;
Note* note;
@@ -786,9 +773,9 @@ s32 func_800E6590(s32 playerIdx, s32 arg1, s32 arg2) {
s32 loopEnd;
s32 samplePos;
- seqPlayer = &gAudioCtx.seqPlayers[playerIdx];
- if (seqPlayer->enabled && seqPlayer->channels[arg1]->enabled) {
- layer = seqPlayer->channels[arg1]->layers[arg2];
+ seqPlayer = &gAudioCtx.seqPlayers[seqPlayerIndex];
+ if (seqPlayer->enabled && seqPlayer->channels[channelIndex]->enabled) {
+ layer = seqPlayer->channels[channelIndex]->layers[layerIndex];
if (layer == NULL) {
return 0;
}
@@ -826,7 +813,7 @@ void func_800E66A0(void) {
func_800E66C0(2);
}
-s32 func_800E66C0(s32 arg0) {
+s32 func_800E66C0(s32 flags) {
s32 phi_v1;
NotePlaybackState* playbackState;
NoteSubEu* noteSubEu;
@@ -841,7 +828,7 @@ s32 func_800E66C0(s32 arg0) {
if (note->noteSubEu.bitField0.enabled) {
noteSubEu = &note->noteSubEu;
if (playbackState->adsr.action.s.state != 0) {
- if (arg0 >= 2) {
+ if (flags >= 2) {
tunedSample = noteSubEu->tunedSample;
if (tunedSample == NULL || noteSubEu->bitField1.isSyntheticWave) {
continue;
@@ -852,8 +839,8 @@ s32 func_800E66C0(s32 arg0) {
}
phi_v1++;
- if ((arg0 & 1) == 1) {
- playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
+ if ((flags & 1) == 1) {
+ playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.ticksPerUpdateInv;
playbackState->adsr.action.s.release = 1;
}
}
@@ -862,14 +849,15 @@ s32 func_800E66C0(s32 arg0) {
return phi_v1;
}
-u32 Audio_NextRandom(void) {
- static u32 audRand = 0x12345678;
+u32 AudioThread_NextRandom(void) {
+ static u32 sAudioRandom = 0x12345678;
+
+ sAudioRandom = ((osGetCount() + 0x1234567) * (sAudioRandom + gAudioCtx.totalTaskCount));
+ sAudioRandom += gAudioCtx.audioRandom;
- audRand = ((osGetCount() + 0x1234567) * (audRand + gAudioCtx.totalTaskCount));
- audRand += gAudioCtx.audioRandom;
- return audRand;
+ return sAudioRandom;
}
-void Audio_InitMesgQueues(void) {
- Audio_InitMesgQueuesInternal();
+void AudioThread_InitMesgQueues(void) {
+ AudioThread_InitMesgQueuesImpl();
}
diff --git a/src/audio/sequence.c b/src/audio/sequence.c
index c349beeed..e04a5668a 100644
--- a/src/audio/sequence.c
+++ b/src/audio/sequence.c
@@ -7,7 +7,7 @@
* These commands are generated using `Audio_QueueSeqCmd`, and a user-friendly interface for this function
* can be found in `seqcmd.h`
*
- * These commands change sequences by generating internal audio commands `Audio_QueueCmd` which allows these
+ * These commands change sequences by generating internal audio commands `AudioThread_QueueCmd` which allows these
* sequence requests to be passed onto the audio thread. It is worth noting all functions in this file are
* called from the graph thread.
*
@@ -22,14 +22,14 @@
#include "ultra64/abi.h"
// Direct audio command (skips the queueing system)
-#define SEQCMD_SET_PLAYER_VOLUME_NOW(seqPlayerIndex, duration, volume) \
- Audio_ProcessSeqCmd((SEQCMD_OP_SET_PLAYER_VOLUME << 28) | ((u8)(seqPlayerIndex) << 24) | ((u8)(duration) << 16) | \
- ((u8)((volume)*127.0f)));
+#define SEQCMD_SET_SEQPLAYER_VOLUME_NOW(seqPlayerIndex, duration, volume) \
+ Audio_ProcessSeqCmd((SEQCMD_OP_SET_SEQPLAYER_VOLUME << 28) | ((u8)(seqPlayerIndex) << 24) | \
+ ((u8)(duration) << 16) | ((u8)((volume)*127.0f)));
typedef struct {
- u8 seqId;
- u8 priority; // higher values have higher priority
-} SeqRequest;
+ /* 0x0 */ u8 seqId;
+ /* 0x1 */ u8 priority; // higher values have higher priority
+} SeqRequest; // size = 0x2
SeqRequest sSeqRequests[4][5];
u8 sNumSeqRequests[4];
@@ -38,26 +38,26 @@ ActiveSequence gActiveSeqs[4];
void Audio_StartSequence(u8 seqPlayerIndex, u8 seqId, u8 seqArgs, u16 fadeInDuration) {
u8 channelIndex;
- u16 duration;
+ u16 skipTicks;
s32 pad;
if (!gStartSeqDisabled || (seqPlayerIndex == SEQ_PLAYER_SFX)) {
seqArgs &= 0x7F;
if (OOT_DEBUG && (seqArgs == 0x7F)) {
- // `fadeInDuration` is interpreted as skip ticks
- duration = (fadeInDuration >> 3) * 60 * gAudioCtx.audioBufferParameters.updatesPerFrame;
- Audio_QueueCmdS32(0x85000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(seqId, 8, 8), duration);
+ // `fadeInDuration` interpreted as seconds, 60 is refresh rate and does not account for PAL
+ skipTicks = (fadeInDuration >> 3) * 60 * gAudioCtx.audioBufferParameters.ticksPerUpdate;
+ AUDIOCMD_GLOBAL_INIT_SEQPLAYER_SKIP_TICKS((u32)seqPlayerIndex, (u32)seqId, skipTicks);
} else {
- // `fadeInDuration` is interpreted as number of frames at 30 fps
- Audio_QueueCmdS32(0x82000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(seqId, 8, 8),
- (fadeInDuration * (u16)gAudioCtx.audioBufferParameters.updatesPerFrame) / 4);
+ // `fadeInDuration` interpreted as 1/30th of a second, does not account for change in refresh rate for PAL
+ AUDIOCMD_GLOBAL_INIT_SEQPLAYER((u32)seqPlayerIndex, (u32)seqId,
+ (fadeInDuration * (u16)gAudioCtx.audioBufferParameters.ticksPerUpdate) / 4);
}
gActiveSeqs[seqPlayerIndex].seqId = seqId | (seqArgs << 8);
gActiveSeqs[seqPlayerIndex].prevSeqId = seqId | (seqArgs << 8);
if (gActiveSeqs[seqPlayerIndex].volCur != 1.0f) {
- Audio_QueueCmdF32(0x41000000 | _SHIFTL(seqPlayerIndex, 16, 8), gActiveSeqs[seqPlayerIndex].volCur);
+ AUDIOCMD_SEQPLAYER_FADE_VOLUME_SCALE((u32)seqPlayerIndex, gActiveSeqs[seqPlayerIndex].volCur);
}
gActiveSeqs[seqPlayerIndex].tempoTimer = 0;
@@ -77,8 +77,8 @@ void Audio_StartSequence(u8 seqPlayerIndex, u8 seqId, u8 seqArgs, u16 fadeInDura
}
void Audio_StopSequence(u8 seqPlayerIndex, u16 fadeOutDuration) {
- Audio_QueueCmdS32(0x83000000 | ((u8)seqPlayerIndex << 16),
- (fadeOutDuration * (u16)gAudioCtx.audioBufferParameters.updatesPerFrame) / 4);
+ AUDIOCMD_GLOBAL_DISABLE_SEQPLAYER(seqPlayerIndex,
+ (fadeOutDuration * (u16)gAudioCtx.audioBufferParameters.ticksPerUpdate) / 4);
gActiveSeqs[seqPlayerIndex].seqId = NA_BGM_DISABLED;
}
@@ -88,15 +88,15 @@ void Audio_ProcessSeqCmd(u32 cmd) {
u16 channelMaskDisable;
u16 fadeTimer;
u16 val;
- u8 oldSpec;
- u8 spec;
+ u8 oldSpecId;
+ u8 specId;
u8 op;
u8 subOp;
u8 seqPlayerIndex;
u8 seqId;
u8 seqArgs;
u8 found;
- u8 port;
+ u8 ioPort;
u8 duration;
u8 channelIndex;
u8 i;
@@ -104,7 +104,7 @@ void Audio_ProcessSeqCmd(u32 cmd) {
s32 pad;
#if OOT_DEBUG
- if (gAudioDebugPrintSeqCmd && (cmd & SEQCMD_OP_MASK) != (SEQCMD_OP_SET_PLAYER_IO << 28)) {
+ if (gAudioDebugPrintSeqCmd && (cmd & SEQCMD_OP_MASK) != (SEQCMD_OP_SET_SEQPLAYER_IO << 28)) {
AudioDebug_ScrPrt("SEQ H", (cmd >> 16) & 0xFFFF);
AudioDebug_ScrPrt(" L", cmd & 0xFFFF);
}
@@ -215,7 +215,7 @@ void Audio_ProcessSeqCmd(u32 cmd) {
}
break;
- case SEQCMD_OP_SET_PLAYER_VOLUME:
+ case SEQCMD_OP_SET_SEQPLAYER_VOLUME:
// Transition volume to a target volume for an entire player
duration = (cmd & 0xFF0000) >> 15;
val = cmd & 0xFF;
@@ -231,7 +231,7 @@ void Audio_ProcessSeqCmd(u32 cmd) {
}
break;
- case SEQCMD_OP_SET_PLAYER_FREQ:
+ case SEQCMD_OP_SET_SEQPLAYER_FREQ:
// Transition freq scale to a target freq for all channels
duration = (cmd & 0xFF0000) >> 15;
val = cmd & 0xFFFF;
@@ -287,29 +287,27 @@ void Audio_ProcessSeqCmd(u32 cmd) {
}
break;
- case SEQCMD_OP_SET_PLAYER_IO:
+ case SEQCMD_OP_SET_SEQPLAYER_IO:
// Set global io port
- port = (cmd & 0xFF0000) >> 16;
+ ioPort = (cmd & 0xFF0000) >> 16;
val = cmd & 0xFF;
- Audio_QueueCmdS8(0x46000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(port, 0, 8), val);
+ AUDIOCMD_SEQPLAYER_SET_IO(seqPlayerIndex, ioPort, val);
break;
case SEQCMD_OP_SET_CHANNEL_IO:
// Set io port if channel masked
channelIndex = (cmd & 0xF00) >> 8;
- port = (cmd & 0xFF0000) >> 16;
+ ioPort = (cmd & 0xFF0000) >> 16;
val = cmd & 0xFF;
if (!(gActiveSeqs[seqPlayerIndex].channelPortMask & (1 << channelIndex))) {
- Audio_QueueCmdS8(0x06000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(channelIndex, 8, 8) |
- _SHIFTL(port, 0, 8),
- val);
+ AUDIOCMD_CHANNEL_SET_IO(seqPlayerIndex, (u32)channelIndex, ioPort, val);
}
break;
case SEQCMD_OP_SET_CHANNEL_IO_DISABLE_MASK:
- // Disable channel io specifically for
- // `SEQCMD_OP_SET_CHANNEL_IO` This can be bypassed by setting channel io through `Audio_QueueCmdS8` 0x6
- // directly. This is accomplished by setting a channel mask.
+ // Disable channel io specifically for `SEQCMD_OP_SET_CHANNEL_IO`.
+ // This can be bypassed by setting channel io through using `AUDIOCMD_CHANNEL_SET_IO` directly.
+ // This is accomplished by setting a channel mask.
gActiveSeqs[seqPlayerIndex].channelPortMask = cmd & 0xFFFF;
break;
@@ -320,18 +318,18 @@ void Audio_ProcessSeqCmd(u32 cmd) {
channelMaskDisable = cmd & 0xFFFF;
if (channelMaskDisable != 0) {
// Apply channel mask `channelMaskDisable`
- Audio_QueueCmdU16(0x90000000 | _SHIFTL(seqPlayerIndex, 16, 8), channelMaskDisable);
+ AUDIOCMD_GLOBAL_SET_CHANNEL_MASK(seqPlayerIndex, channelMaskDisable);
// Disable channels
- Audio_QueueCmdS8(0x08000000 | _SHIFTL(seqPlayerIndex, 16, 8) | 0xFF00, 1);
+ AUDIOCMD_CHANNEL_SET_MUTE(seqPlayerIndex, AUDIOCMD_ALL_CHANNELS, true);
}
// Reenable channels
channelMaskEnable = (channelMaskDisable ^ 0xFFFF);
if (channelMaskEnable != 0) {
// Apply channel mask `channelMaskEnable`
- Audio_QueueCmdU16(0x90000000 | _SHIFTL(seqPlayerIndex, 16, 8), channelMaskEnable);
+ AUDIOCMD_GLOBAL_SET_CHANNEL_MASK(seqPlayerIndex, channelMaskEnable);
// Enable channels
- Audio_QueueCmdS8(0x08000000 | _SHIFTL(seqPlayerIndex, 16, 8) | 0xFF00, 0);
+ AUDIOCMD_CHANNEL_SET_MUTE(seqPlayerIndex, AUDIOCMD_ALL_CHANNELS, false);
}
break;
@@ -373,7 +371,7 @@ void Audio_ProcessSeqCmd(u32 cmd) {
switch (subOp) {
case SEQCMD_SUB_OP_GLOBAL_SET_SOUND_MODE:
// Set sound mode
- Audio_QueueCmdS32(0xF0000000, gSoundModeList[val]);
+ AUDIOCMD_GLOBAL_SET_SOUND_MODE(gSoundModeList[val]);
break;
case SEQCMD_SUB_OP_GLOBAL_DISABLE_NEW_SEQUENCES:
@@ -385,13 +383,13 @@ void Audio_ProcessSeqCmd(u32 cmd) {
case SEQCMD_OP_RESET_AUDIO_HEAP:
// Resets the audio heap based on the audio specifications and sfx channel layout
- spec = cmd & 0xFF;
+ specId = cmd & 0xFF;
gSfxChannelLayout = (cmd & 0xFF00) >> 8;
- oldSpec = gAudioSpecId;
- gAudioSpecId = spec;
- func_800E5F88(spec);
- func_800F71BC(oldSpec);
- Audio_QueueCmdS32(0xF8000000, 0);
+ oldSpecId = gAudioSpecId;
+ gAudioSpecId = specId;
+ AudioThread_ResetAudioHeap(specId);
+ func_800F71BC(oldSpecId);
+ AUDIOCMD_GLOBAL_STOP_AUDIOCMDS();
break;
}
}
@@ -435,7 +433,7 @@ void Audio_ResetSequenceRequests(u8 seqPlayerIndex) {
/**
* Check if the setup command is queued. If it is, then replace the command
- * with `SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME`.
+ * with `SEQCMD_SUB_OP_SETUP_RESTORE_SEQPLAYER_VOLUME`.
* Unused
*/
void Audio_ReplaceSeqCmdSetupOpVolRestore(u8 seqPlayerIndex, u8 setupOpDisabled) {
@@ -464,7 +462,7 @@ void Audio_SetVolumeScale(u8 seqPlayerIndex, u8 scaleIndex, u8 targetVol, u8 vol
volScale *= gActiveSeqs[seqPlayerIndex].volScales[i] / 127.0f;
}
- SEQCMD_SET_PLAYER_VOLUME_NOW(seqPlayerIndex, volFadeTimer, volScale);
+ SEQCMD_SET_SEQPLAYER_VOLUME_NOW(seqPlayerIndex, volFadeTimer, volScale);
}
}
@@ -517,7 +515,8 @@ void Audio_UpdateActiveSequences(void) {
for (j = 0; j < VOL_SCALE_INDEX_MAX; j++) {
volume *= (gActiveSeqs[seqPlayerIndex].volScales[j] / 127.0f);
}
- SEQCMD_SET_PLAYER_VOLUME(seqPlayerIndex, gActiveSeqs[seqPlayerIndex].volFadeTimer, (u8)(volume * 127.0f));
+ SEQCMD_SET_SEQPLAYER_VOLUME(seqPlayerIndex, gActiveSeqs[seqPlayerIndex].volFadeTimer,
+ (u8)(volume * 127.0f));
gActiveSeqs[seqPlayerIndex].fadeVolUpdate = false;
}
@@ -530,7 +529,7 @@ void Audio_UpdateActiveSequences(void) {
gActiveSeqs[seqPlayerIndex].volCur = gActiveSeqs[seqPlayerIndex].volTarget;
}
- Audio_QueueCmdF32(0x41000000 | _SHIFTL(seqPlayerIndex, 16, 8), gActiveSeqs[seqPlayerIndex].volCur);
+ AUDIOCMD_SEQPLAYER_FADE_VOLUME_SCALE((u32)seqPlayerIndex, gActiveSeqs[seqPlayerIndex].volCur);
}
// Process tempo
@@ -544,7 +543,7 @@ void Audio_UpdateActiveSequences(void) {
// Process tempo commands
if (gAudioCtx.seqPlayers[seqPlayerIndex].enabled) {
- tempoPrev = gAudioCtx.seqPlayers[seqPlayerIndex].tempo / TATUMS_PER_BEAT;
+ tempoPrev = gAudioCtx.seqPlayers[seqPlayerIndex].tempo / SEQTICKS_PER_BEAT;
tempoOp = (tempoCmd & 0xF000) >> 12;
switch (tempoOp) {
case SEQCMD_SUB_OP_TEMPO_SPEED_UP:
@@ -585,7 +584,7 @@ void Audio_UpdateActiveSequences(void) {
}
gActiveSeqs[seqPlayerIndex].tempoTarget = tempoTarget;
- gActiveSeqs[seqPlayerIndex].tempoCur = gAudioCtx.seqPlayers[seqPlayerIndex].tempo / TATUMS_PER_BEAT;
+ gActiveSeqs[seqPlayerIndex].tempoCur = gAudioCtx.seqPlayers[seqPlayerIndex].tempo / SEQTICKS_PER_BEAT;
gActiveSeqs[seqPlayerIndex].tempoStep =
(gActiveSeqs[seqPlayerIndex].tempoCur - gActiveSeqs[seqPlayerIndex].tempoTarget) / tempoTimer;
gActiveSeqs[seqPlayerIndex].tempoTimer = tempoTimer;
@@ -601,8 +600,8 @@ void Audio_UpdateActiveSequences(void) {
} else {
gActiveSeqs[seqPlayerIndex].tempoCur = gActiveSeqs[seqPlayerIndex].tempoTarget;
}
- // Set tempo
- Audio_QueueCmdS32(0x47000000 | _SHIFTL(seqPlayerIndex, 16, 8), gActiveSeqs[seqPlayerIndex].tempoCur);
+
+ AUDIOCMD_SEQPLAYER_SET_TEMPO((u32)seqPlayerIndex, gActiveSeqs[seqPlayerIndex].tempoCur);
}
// Update channel volumes
@@ -618,9 +617,9 @@ void Audio_UpdateActiveSequences(void) {
gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volTarget;
gActiveSeqs[seqPlayerIndex].volChannelFlags ^= (1 << channelIndex);
}
- // `CHAN_UPD_VOL_SCALE`
- Audio_QueueCmdF32(0x01000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(channelIndex, 8, 8),
- gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volCur);
+
+ AUDIOCMD_CHANNEL_SET_VOL_SCALE(seqPlayerIndex, (u32)channelIndex,
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].volCur);
}
}
}
@@ -638,9 +637,9 @@ void Audio_UpdateActiveSequences(void) {
gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleTarget;
gActiveSeqs[seqPlayerIndex].freqScaleChannelFlags ^= (1 << channelIndex);
}
- // `CHAN_UPD_FREQ_SCALE`
- Audio_QueueCmdF32(0x04000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(channelIndex, 8, 8),
- gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleCur);
+
+ AUDIOCMD_CHANNEL_SET_FREQ_SCALE(seqPlayerIndex, (u32)channelIndex,
+ gActiveSeqs[seqPlayerIndex].channelData[channelIndex].freqScaleCur);
}
}
}
@@ -672,12 +671,12 @@ void Audio_UpdateActiveSequences(void) {
setupVal1 = gActiveSeqs[seqPlayerIndex].setupCmd[j] & 0xFF;
switch (setupOp) {
- case SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME:
+ case SEQCMD_SUB_OP_SETUP_RESTORE_SEQPLAYER_VOLUME:
// Restore `targetSeqPlayerIndex` volume back to normal levels
Audio_SetVolumeScale(targetSeqPlayerIndex, VOL_SCALE_INDEX_FANFARE, 0x7F, setupVal1);
break;
- case SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME_IF_QUEUED:
+ case SEQCMD_SUB_OP_SETUP_RESTORE_SEQPLAYER_VOLUME_IF_QUEUED:
// Restore `targetSeqPlayerIndex` volume back to normal levels,
// but only if the number of sequence queue requests from `sSeqRequests`
// exactly matches the argument to the command
@@ -731,7 +730,7 @@ void Audio_UpdateActiveSequences(void) {
gActiveSeqs[seqPlayerIndex].setupFadeTimer = setupVal2;
break;
- case SEQCMD_SUB_OP_SETUP_RESTORE_VOLUME_WITH_SCALE_INDEX:
+ case SEQCMD_SUB_OP_SETUP_RESTORE_SEQPLAYER_VOLUME_WITH_SCALE_INDEX:
// Restore the volume back to default levels
// Allows a `scaleIndex` to be specified.
Audio_SetVolumeScale(targetSeqPlayerIndex, setupVal2, 0x7F, setupVal1);
@@ -740,13 +739,13 @@ void Audio_UpdateActiveSequences(void) {
case SEQCMD_SUB_OP_SETUP_POP_PERSISTENT_CACHE:
// Discard audio data by popping one more audio caches from the audio heap
if (setupVal1 & (1 << SEQUENCE_TABLE)) {
- Audio_QueueCmdS32(0xE3000000, SEQUENCE_TABLE);
+ AUDIOCMD_GLOBAL_POP_PERSISTENT_CACHE(SEQUENCE_TABLE);
}
if (setupVal1 & (1 << FONT_TABLE)) {
- Audio_QueueCmdS32(0xE3000000, FONT_TABLE);
+ AUDIOCMD_GLOBAL_POP_PERSISTENT_CACHE(FONT_TABLE);
}
if (setupVal1 & (1 << SAMPLE_TABLE)) {
- Audio_QueueCmdS32(0xE3000000, SAMPLE_TABLE);
+ AUDIOCMD_GLOBAL_POP_PERSISTENT_CACHE(SAMPLE_TABLE);
}
break;
@@ -756,9 +755,9 @@ void Audio_UpdateActiveSequences(void) {
SEQCMD_SET_CHANNEL_DISABLE_MASK(targetSeqPlayerIndex, channelMask);
break;
- case SEQCMD_SUB_OP_SETUP_SET_PLAYER_FREQ:
+ case SEQCMD_SUB_OP_SETUP_SET_SEQPLAYER_FREQ:
// Scale all channels of `targetSeqPlayerIndex`
- SEQCMD_SET_PLAYER_FREQ(targetSeqPlayerIndex, setupVal2, (setupVal1 * 10) & 0xFFFF);
+ SEQCMD_SET_SEQPLAYER_FREQ(targetSeqPlayerIndex, setupVal2, (setupVal1 * 10) & 0xFFFF);
break;
}
}
@@ -773,13 +772,13 @@ u8 func_800FAD34(void) {
if (D_80133418 == 1) {
if (func_800E5EDC() == 1) {
D_80133418 = 0;
- Audio_QueueCmdS8(0x46020000, gSfxChannelLayout);
+ AUDIOCMD_SEQPLAYER_SET_IO(SEQ_PLAYER_SFX, 0, gSfxChannelLayout);
func_800F7170();
}
} else if (D_80133418 == 2) {
while (func_800E5EDC() != 1) {}
D_80133418 = 0;
- Audio_QueueCmdS8(0x46020000, gSfxChannelLayout);
+ AUDIOCMD_SEQPLAYER_SET_IO(SEQ_PLAYER_SFX, 0, gSfxChannelLayout);
func_800F7170();
}
}
diff --git a/src/audio/session_config.c b/src/audio/session_config.c
index 56b899993..2178a12e8 100644
--- a/src/audio/session_config.c
+++ b/src/audio/session_config.c
@@ -2,12 +2,12 @@
u8 D_8016F0E0[0xA0]; // unused
AudioContext gAudioCtx;
-void (*D_801755D0)(void);
+AudioCustomUpdateFunction gAudioCustomUpdateFunction;
s32 D_801755D8[3]; // unused
-const s16 D_8014A6C0[] = {
- 0x1C00, // unused
- 0x0030, // gTatumsPerBeat
+const TempoData gTempoData = {
+ 0x1C00, // unk_00
+ SEQTICKS_PER_BEAT, // seqTicksPerBeat
};
// TODO: Extract from table?
diff --git a/src/audio/sfx.c b/src/audio/sfx.c
index 2507172b5..9f8787467 100644
--- a/src/audio/sfx.c
+++ b/src/audio/sfx.c
@@ -30,7 +30,7 @@ u8 sSfxBankListEnd[7];
u8 sSfxBankFreeListStart[7];
u8 sSfxBankUnused[7];
ActiveSfx gActiveSfx[7][3];
-u8 sCurSfxPlayerChannelIdx;
+u8 sCurSfxPlayerChannelIndex;
u8 gSfxBankMuted[7];
UnusedBankLerp sUnusedBankLerp[7];
u16 gAudioSfxSwapSource[10];
@@ -50,14 +50,14 @@ void Audio_SetSfxBanksMute(u16 muteMask) {
}
}
-void Audio_QueueSeqCmdMute(u8 channelIdx) {
- D_801333D0 |= (1 << channelIdx);
+void Audio_QueueSeqCmdMute(u8 channelIndex) {
+ D_801333D0 |= (1 << channelIndex);
Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_SFX, 0x40, 0xF);
Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, VOL_SCALE_INDEX_SFX, 0x40, 0xF);
}
-void Audio_ClearBGMMute(u8 channelIdx) {
- D_801333D0 &= ((1 << channelIdx) ^ 0xFFFF);
+void Audio_ClearBGMMute(u8 channelIndex) {
+ D_801333D0 &= ((1 << channelIndex) ^ 0xFFFF);
if (D_801333D0 == 0) {
Audio_SetVolumeScale(SEQ_PLAYER_BGM_MAIN, VOL_SCALE_INDEX_SFX, 0x7F, 0xF);
Audio_SetVolumeScale(SEQ_PLAYER_BGM_SUB, VOL_SCALE_INDEX_SFX, 0x7F, 0xF);
@@ -211,7 +211,7 @@ void Audio_ProcessSfxRequest(void) {
if ((req->sfxId & 0xC00) || (sfxParams->params & SFX_FLAG_2) || (index == evictIndex)) {
if ((gSfxBanks[bankId][index].sfxParams & SFX_FLAG_3) &&
gSfxBanks[bankId][index].state != SFX_STATE_QUEUED) {
- Audio_ClearBGMMute(gSfxBanks[bankId][index].channelIdx);
+ Audio_ClearBGMMute(gSfxBanks[bankId][index].channelIndex);
}
gSfxBanks[bankId][index].token = req->token;
gSfxBanks[bankId][index].sfxId = req->sfxId;
@@ -262,7 +262,7 @@ void Audio_RemoveSfxBankEntry(u8 bankId, u8 entryIndex) {
u8 i;
if (entry->sfxParams & SFX_FLAG_3) {
- Audio_ClearBGMMute(entry->channelIdx);
+ Audio_ClearBGMMute(entry->channelIndex);
}
if (entryIndex == sSfxBankListEnd[bankId]) {
sSfxBankListEnd[bankId] = entry->prev;
@@ -314,7 +314,7 @@ void Audio_ChooseActiveSfx(u8 bankId) {
gSfxBanks[bankId][entryIndex].freshness--;
} else if (!(gSfxBanks[bankId][entryIndex].sfxId & 0xC00) &&
(gSfxBanks[bankId][entryIndex].state == SFX_STATE_PLAYING_2)) {
- Audio_QueueCmdS8((gSfxBanks[bankId][entryIndex].channelIdx << 8) | 0x6020000, 0);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, gSfxBanks[bankId][entryIndex].channelIndex, 0, 0);
Audio_RemoveSfxBankEntry(bankId, entryIndex);
}
if (gSfxBanks[bankId][entryIndex].freshness == 0) {
@@ -346,7 +346,7 @@ void Audio_ChooseActiveSfx(u8 bankId) {
}
if (entry->dist > SQ(1e5f)) {
if (entry->state == SFX_STATE_PLAYING_1) {
- Audio_QueueCmdS8((entry->channelIdx << 8) | 0x6020000, 0);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
if (entry->sfxId & 0xC00) {
Audio_RemoveSfxBankEntry(bankId, entryIndex);
entryIndex = k;
@@ -451,45 +451,51 @@ void Audio_PlayActiveSfx(u8 bankId) {
entryIndex = gActiveSfx[bankId][i].entryIndex;
if (entryIndex != 0xFF) {
entry = &gSfxBanks[bankId][entryIndex];
- channel = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIdx];
+ channel = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIndex];
if (entry->state == SFX_STATE_READY) {
- entry->channelIdx = sCurSfxPlayerChannelIdx;
+ entry->channelIndex = sCurSfxPlayerChannelIndex;
if (entry->sfxParams & SFX_FLAG_3) {
- Audio_QueueSeqCmdMute(sCurSfxPlayerChannelIdx);
+ Audio_QueueSeqCmdMute(sCurSfxPlayerChannelIndex);
}
if ((entry->sfxParams & SFX_PARAM_67_MASK) != (0 << SFX_PARAM_67_SHIFT)) {
switch (entry->sfxParams & SFX_PARAM_67_MASK) {
case (1 << SFX_PARAM_67_SHIFT):
- entry->unk_2F = Audio_NextRandom() & 0xF;
+ entry->unk_2F = AudioThread_NextRandom() & 0xF;
break;
case (2 << SFX_PARAM_67_SHIFT):
- entry->unk_2F = Audio_NextRandom() & 0x1F;
+ entry->unk_2F = AudioThread_NextRandom() & 0x1F;
break;
case (3 << SFX_PARAM_67_SHIFT):
- entry->unk_2F = Audio_NextRandom() & 0x3F;
+ entry->unk_2F = AudioThread_NextRandom() & 0x3F;
break;
default:
entry->unk_2F = 0;
break;
}
}
- Audio_SetSfxProperties(bankId, entryIndex, sCurSfxPlayerChannelIdx);
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((sCurSfxPlayerChannelIdx & 0xFF) << 8), 1);
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((sCurSfxPlayerChannelIdx & 0xFF) << 8) | 4,
- entry->sfxId & 0xFF);
+ Audio_SetSfxProperties(bankId, entryIndex, sCurSfxPlayerChannelIndex);
+
+ // ioPort 0, enable the sfx to play in `NA_BGM_GENERAL_SFX`
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, sCurSfxPlayerChannelIndex, 0, 1);
+
+ // ioPort 4, write the lower bits sfx index for `NA_BGM_GENERAL_SFX` to find the right code to execute
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, sCurSfxPlayerChannelIndex, 4, entry->sfxId & 0xFF);
+
+ // If the sfx bank has more than 255 entries (greater than a u8 can store),
+ // then store the Id in upper and lower bits
if (gIsLargeSfxBank[bankId]) {
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((sCurSfxPlayerChannelIdx & 0xFF) << 8) | 5,
- (entry->sfxId & 0x100) >> 8);
+ // ioPort 5, write the upper bits sfx index for `NA_BGM_GENERAL_SFX`, for banks with > 0xFF entries
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, sCurSfxPlayerChannelIndex, 5, (entry->sfxId & 0x100) >> 8);
}
if (entry->sfxId & 0xC00) {
entry->state = SFX_STATE_PLAYING_1;
} else {
entry->state = SFX_STATE_PLAYING_2;
}
- } else if ((u8)channel->soundScriptIO[1] == (u8)SEQ_IO_VAL_NONE) {
+ } else if ((u8)channel->seqScriptIO[1] == (u8)SEQ_IO_VAL_NONE) {
Audio_RemoveSfxBankEntry(bankId, entryIndex);
} else if (entry->state == SFX_STATE_PLAYING_REFRESH) {
- Audio_SetSfxProperties(bankId, entryIndex, sCurSfxPlayerChannelIdx);
+ Audio_SetSfxProperties(bankId, entryIndex, sCurSfxPlayerChannelIndex);
if (entry->sfxId & 0xC00) {
entry->state = SFX_STATE_PLAYING_1;
} else {
@@ -497,7 +503,7 @@ void Audio_PlayActiveSfx(u8 bankId) {
}
}
}
- sCurSfxPlayerChannelIdx++;
+ sCurSfxPlayerChannelIndex++;
}
}
@@ -510,7 +516,7 @@ void Audio_StopSfxByBank(u8 bankId) {
while (entryIndex != 0xFF) {
entry = &gSfxBanks[bankId][entryIndex];
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((entry->channelIdx & 0xFF) << 8), 0);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
}
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSfxBankEntry(bankId, entryIndex);
@@ -530,7 +536,7 @@ void func_800F8884(u8 bankId, Vec3f* pos) {
entry = &gSfxBanks[bankId][entryIndex];
if (entry->posX == &pos->x) {
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((entry->channelIdx & 0xFF) << 8), 0);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
}
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSfxBankEntry(bankId, entryIndex);
@@ -572,7 +578,7 @@ void Audio_StopSfxByPosAndId(Vec3f* pos, u16 sfxId) {
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->posX == &pos->x && entry->sfxId == sfxId) {
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((entry->channelIdx & 0xFF) << 8), 0);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
}
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSfxBankEntry(SFX_BANK(sfxId), entryIndex);
@@ -600,7 +606,7 @@ void Audio_StopSfxByTokenAndId(u8 token, u16 sfxId) {
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->token == token && entry->sfxId == sfxId) {
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((entry->channelIdx & 0xFF) << 8), 0);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
}
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSfxBankEntry(SFX_BANK(sfxId), entryIndex);
@@ -627,7 +633,7 @@ void Audio_StopSfxById(u32 sfxId) {
entry = &gSfxBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->sfxId == sfxId) {
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
- Audio_QueueCmdS8(0x6 << 24 | SEQ_PLAYER_SFX << 16 | ((entry->channelIdx & 0xFF) << 8), 0);
+ AUDIOCMD_CHANNEL_SET_IO(SEQ_PLAYER_SFX, entry->channelIndex, 0, 0);
}
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSfxBankEntry(SFX_BANK(sfxId), entryIndex);
@@ -672,7 +678,7 @@ void func_800F8F88(void) {
u8 bankId;
if (IS_SEQUENCE_CHANNEL_VALID(gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[0])) {
- sCurSfxPlayerChannelIdx = 0;
+ sCurSfxPlayerChannelIndex = 0;
for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) {
Audio_ChooseActiveSfx(bankId);
Audio_PlayActiveSfx(bankId);
diff --git a/src/code/audio_thread_manager.c b/src/code/audio_thread_manager.c
index 04f20a8f5..bbec08dea 100644
--- a/src/code/audio_thread_manager.c
+++ b/src/code/audio_thread_manager.c
@@ -51,7 +51,7 @@ void AudioMgr_HandleRetrace(AudioMgr* audioMgr) {
// Skip update, no rsp task produced
rspTask = NULL;
} else {
- rspTask = func_800E4FE0();
+ rspTask = AudioThread_Update();
}
gAudioThreadUpdateTimeAcc += osGetTime() - gAudioThreadUpdateTimeStart;
diff --git a/src/code/game.c b/src/code/game.c
index 2b60c66dd..2bc179d68 100644
--- a/src/code/game.c
+++ b/src/code/game.c
@@ -456,7 +456,7 @@ void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* g
void GameState_Destroy(GameState* gameState) {
PRINTF("game デストラクタ開始\n"); // "game destructor start"
AudioMgr_StopAllSfx();
- func_800F3054();
+ Audio_Update();
osRecvMesg(&gameState->gfxCtx->queue, NULL, OS_MESG_BLOCK);
LOG_UTILS_CHECK_NULL_POINTER("this->cleanup", gameState->destroy, "../game.c", 1139);
if (gameState->destroy != NULL) {
diff --git a/src/code/graph.c b/src/code/graph.c
index b25612ccc..c6f165b74 100644
--- a/src/code/graph.c
+++ b/src/code/graph.c
@@ -373,7 +373,7 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
gfxCtx->fbIdx++;
}
- func_800F3054();
+ Audio_Update();
{
OSTime timeNow = osGetTime();
diff --git a/src/code/speed_meter.c b/src/code/speed_meter.c
index 086c3ea70..dff46d91e 100644
--- a/src/code/speed_meter.c
+++ b/src/code/speed_meter.c
@@ -2,8 +2,8 @@
#include "terminal.h"
/**
- * How much time the audio update on the audio thread (`func_800E4FE0`) took in total, between scheduling the last two
- * graphics tasks.
+ * How much time the audio update on the audio thread (`AudioThread_Update`) took in total, between scheduling the last
+ * two graphics tasks.
*/
volatile OSTime gAudioThreadUpdateTimeTotalPerGfxTask;