1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-27 23:36:22 +00:00

rename audio context (#1388)

This commit is contained in:
engineer124 2022-10-07 13:43:17 -04:00 committed by GitHub
parent 062f4d8e15
commit 2fb27e6605
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 900 additions and 928 deletions

View file

@ -218,7 +218,7 @@ extern u16 gAudioSfxSwapSource[10];
extern u16 gAudioSfxSwapTarget[10]; extern u16 gAudioSfxSwapTarget[10];
extern u8 gAudioSfxSwapMode[10]; extern u8 gAudioSfxSwapMode[10];
extern ActiveSequence gActiveSeqs[4]; extern ActiveSequence gActiveSeqs[4];
extern AudioContext gAudioContext; extern AudioContext gAudioCtx;
extern void(*D_801755D0)(void); extern void(*D_801755D0)(void);
extern u32 __osMalloc_FreeBlockTest_Enable; extern u32 __osMalloc_FreeBlockTest_Enable;

View file

@ -7,7 +7,7 @@
#define TATUMS_PER_BEAT 48 #define TATUMS_PER_BEAT 48
#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((u32)(ptr) != (u32)&gAudioContext.sequenceChannelNone) #define IS_SEQUENCE_CHANNEL_VALID(ptr) ((u32)(ptr) != (u32)&gAudioCtx.sequenceChannelNone)
#define SEQ_NUM_CHANNELS 16 #define SEQ_NUM_CHANNELS 16
#define MAX_CHANNELS_PER_BANK 3 #define MAX_CHANNELS_PER_BANK 3

View file

@ -124,7 +124,7 @@ f32 Audio_GetVibratoFreqScale(VibratoState* vib) {
return 1.0f; return 1.0f;
} }
//! @bug this probably meant to compare with gAudioContext.sequenceChannelNone. //! @bug this probably meant to compare with gAudioCtx.sequenceChannelNone.
//! -1 isn't used as a channel pointer anywhere else. //! -1 isn't used as a channel pointer anywhere else.
if (channel != ((SequenceChannel*)(-1))) { if (channel != ((SequenceChannel*)(-1))) {
if (vib->extentChangeTimer) { if (vib->extentChangeTimer) {
@ -264,7 +264,7 @@ f32 Audio_AdsrUpdate(AdsrState* adsr) {
break; break;
default: default:
adsr->delay *= gAudioContext.audioBufferParameters.updatesPerFrameScaled; adsr->delay *= gAudioCtx.audioBufferParameters.updatesPerFrameScaled;
if (adsr->delay == 0) { if (adsr->delay == 0) {
adsr->delay = 1; adsr->delay = 1;
} }

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
#include "global.h" #include "global.h"
u8 D_8016F0E0[0xA0]; // unused u8 D_8016F0E0[0xA0]; // unused
AudioContext gAudioContext; AudioContext gAudioCtx;
void (*D_801755D0)(void); void (*D_801755D0)(void);
s32 D_801755D8[3]; // unused s32 D_801755D8[3]; // unused
@ -17,7 +17,7 @@ const s16 D_8014A6C0[] = {
#define SFX_SOUNDFONT_2_SIZE 0x17B0 #define SFX_SOUNDFONT_2_SIZE 0x17B0
// Sizes of everything on the init pool // Sizes of everything on the init pool
#define AI_BUFFERS_SIZE (AIBUF_SIZE * ARRAY_COUNT(gAudioContext.aiBuffers)) #define AI_BUFFERS_SIZE (AIBUF_SIZE * ARRAY_COUNT(gAudioCtx.aiBuffers))
#define SOUNDFONT_LIST_SIZE (NUM_SOUNDFONTS * sizeof(SoundFont)) #define SOUNDFONT_LIST_SIZE (NUM_SOUNDFONTS * sizeof(SoundFont))
#define PERMANENT_POOL_SIZE (SFX_SEQ_SIZE + SFX_SOUNDFONT_1_SIZE + SFX_SOUNDFONT_2_SIZE) #define PERMANENT_POOL_SIZE (SFX_SEQ_SIZE + SFX_SOUNDFONT_1_SIZE + SFX_SOUNDFONT_2_SIZE)

File diff suppressed because it is too large Load diff

View file

@ -31,7 +31,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
sub->bitField0.stereoStrongLeft = false; sub->bitField0.stereoStrongLeft = false;
sub->bitField0.stereoHeadsetEffects = stereoData.stereoHeadsetEffects; sub->bitField0.stereoHeadsetEffects = stereoData.stereoHeadsetEffects;
sub->bitField0.usesHeadsetPanEffects = stereoData.usesHeadsetPanEffects; sub->bitField0.usesHeadsetPanEffects = stereoData.usesHeadsetPanEffects;
if (stereoHeadsetEffects && (gAudioContext.soundMode == SOUNDMODE_HEADSET)) { if (stereoHeadsetEffects && (gAudioCtx.soundMode == SOUNDMODE_HEADSET)) {
halfPanIndex = pan >> 1; halfPanIndex = pan >> 1;
if (halfPanIndex > 0x3F) { if (halfPanIndex > 0x3F) {
halfPanIndex = 0x3F; halfPanIndex = 0x3F;
@ -43,7 +43,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
volLeft = gHeadsetPanVolume[pan]; volLeft = gHeadsetPanVolume[pan];
volRight = gHeadsetPanVolume[0x7F - pan]; volRight = gHeadsetPanVolume[0x7F - pan];
} else if (stereoHeadsetEffects && (gAudioContext.soundMode == SOUNDMODE_STEREO)) { } else if (stereoHeadsetEffects && (gAudioCtx.soundMode == SOUNDMODE_STEREO)) {
strongLeft = strongRight = 0; strongLeft = strongRight = 0;
sub->haasEffectLeftDelaySize = 0; sub->haasEffectLeftDelaySize = 0;
sub->haasEffectRightDelaySize = 0; sub->haasEffectRightDelaySize = 0;
@ -80,7 +80,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
break; break;
} }
} else if (gAudioContext.soundMode == SOUNDMODE_MONO) { } else if (gAudioCtx.soundMode == SOUNDMODE_MONO) {
sub->bitField0.stereoHeadsetEffects = false; sub->bitField0.stereoHeadsetEffects = false;
sub->bitField0.usesHeadsetPanEffects = false; sub->bitField0.usesHeadsetPanEffects = false;
volLeft = 0.707f; // approx 1/sqrt(2) volLeft = 0.707f; // approx 1/sqrt(2)
@ -163,9 +163,9 @@ void Audio_ProcessNotes(void) {
f32 scale; f32 scale;
s32 i; s32 i;
for (i = 0; i < gAudioContext.numNotes; i++) { for (i = 0; i < gAudioCtx.numNotes; i++) {
note = &gAudioContext.notes[i]; note = &gAudioCtx.notes[i];
noteSubEu2 = &gAudioContext.noteSubsEu[gAudioContext.noteSubEuOffset + i]; noteSubEu2 = &gAudioCtx.noteSubsEu[gAudioCtx.noteSubEuOffset + i];
playbackState = &note->playbackState; playbackState = &note->playbackState;
if (playbackState->parentLayer != NO_LAYER) { if (playbackState->parentLayer != NO_LAYER) {
if ((u32)playbackState->parentLayer < 0x7FFFFFFF) { if ((u32)playbackState->parentLayer < 0x7FFFFFFF) {
@ -174,7 +174,7 @@ void Audio_ProcessNotes(void) {
if (note != playbackState->parentLayer->note && playbackState->unk_04 == 0) { if (note != playbackState->parentLayer->note && playbackState->unk_04 == 0) {
playbackState->adsr.action.s.release = true; playbackState->adsr.action.s.release = true;
playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
playbackState->priority = 1; playbackState->priority = 1;
playbackState->unk_04 = 2; playbackState->unk_04 = 2;
goto out; goto out;
@ -285,7 +285,7 @@ void Audio_ProcessNotes(void) {
} }
subAttrs.frequency *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale; subAttrs.frequency *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale;
subAttrs.frequency *= gAudioContext.audioBufferParameters.resampleRate; subAttrs.frequency *= gAudioCtx.audioBufferParameters.resampleRate;
subAttrs.velocity *= scale; subAttrs.velocity *= scale;
Audio_InitNoteSub(note, noteSubEu2, &subAttrs); Audio_InitNoteSub(note, noteSubEu2, &subAttrs);
noteSubEu->bitField1.bookOffset = bookOffset; noteSubEu->bitField1.bookOffset = bookOffset;
@ -315,18 +315,18 @@ Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) {
} }
if (!AudioLoad_IsFontLoadComplete(fontId)) { if (!AudioLoad_IsFontLoadComplete(fontId)) {
gAudioContext.audioErrorFlags = fontId + 0x10000000; gAudioCtx.audioErrorFlags = fontId + 0x10000000;
return NULL; return NULL;
} }
if (instId >= gAudioContext.soundFontList[fontId].numInstruments) { if (instId >= gAudioCtx.soundFontList[fontId].numInstruments) {
gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000; gAudioCtx.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000;
return NULL; return NULL;
} }
inst = gAudioContext.soundFontList[fontId].instruments[instId]; inst = gAudioCtx.soundFontList[fontId].instruments[instId];
if (inst == NULL) { if (inst == NULL) {
gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000; gAudioCtx.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000;
return inst; return inst;
} }
@ -341,21 +341,21 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) {
} }
if (!AudioLoad_IsFontLoadComplete(fontId)) { if (!AudioLoad_IsFontLoadComplete(fontId)) {
gAudioContext.audioErrorFlags = fontId + 0x10000000; gAudioCtx.audioErrorFlags = fontId + 0x10000000;
return NULL; return NULL;
} }
if (drumId >= gAudioContext.soundFontList[fontId].numDrums) { if (drumId >= gAudioCtx.soundFontList[fontId].numDrums) {
gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000; gAudioCtx.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000;
return NULL; return NULL;
} }
if ((u32)gAudioContext.soundFontList[fontId].drums < AUDIO_RELOCATED_ADDRESS_START) { if ((u32)gAudioCtx.soundFontList[fontId].drums < AUDIO_RELOCATED_ADDRESS_START) {
return NULL; return NULL;
} }
drum = gAudioContext.soundFontList[fontId].drums[drumId]; drum = gAudioCtx.soundFontList[fontId].drums[drumId];
if (drum == NULL) { if (drum == NULL) {
gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000; gAudioCtx.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000;
} }
return drum; return drum;
@ -369,23 +369,23 @@ SoundEffect* Audio_GetSoundEffect(s32 fontId, s32 sfxId) {
} }
if (!AudioLoad_IsFontLoadComplete(fontId)) { if (!AudioLoad_IsFontLoadComplete(fontId)) {
gAudioContext.audioErrorFlags = fontId + 0x10000000; gAudioCtx.audioErrorFlags = fontId + 0x10000000;
return NULL; return NULL;
} }
if (sfxId >= gAudioContext.soundFontList[fontId].numSfx) { if (sfxId >= gAudioCtx.soundFontList[fontId].numSfx) {
gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000; gAudioCtx.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000;
return NULL; return NULL;
} }
if ((u32)gAudioContext.soundFontList[fontId].soundEffects < AUDIO_RELOCATED_ADDRESS_START) { if ((u32)gAudioCtx.soundFontList[fontId].soundEffects < AUDIO_RELOCATED_ADDRESS_START) {
return NULL; return NULL;
} }
soundEffect = &gAudioContext.soundFontList[fontId].soundEffects[sfxId]; soundEffect = &gAudioCtx.soundFontList[fontId].soundEffects[sfxId];
if (soundEffect == NULL) { if (soundEffect == NULL) {
gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000; gAudioCtx.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000;
} }
if (soundEffect->tunedSample.sample == NULL) { if (soundEffect->tunedSample.sample == NULL) {
@ -406,24 +406,24 @@ s32 Audio_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* val
switch (instrumentType) { switch (instrumentType) {
case 0: case 0:
if (index >= gAudioContext.soundFontList[fontId].numDrums) { if (index >= gAudioCtx.soundFontList[fontId].numDrums) {
return -3; return -3;
} }
gAudioContext.soundFontList[fontId].drums[index] = value; gAudioCtx.soundFontList[fontId].drums[index] = value;
break; break;
case 1: case 1:
if (index >= gAudioContext.soundFontList[fontId].numSfx) { if (index >= gAudioCtx.soundFontList[fontId].numSfx) {
return -3; return -3;
} }
gAudioContext.soundFontList[fontId].soundEffects[index] = *(SoundEffect*)value; gAudioCtx.soundFontList[fontId].soundEffects[index] = *(SoundEffect*)value;
break; break;
default: default:
if (index >= gAudioContext.soundFontList[fontId].numInstruments) { if (index >= gAudioCtx.soundFontList[fontId].numInstruments) {
return -3; return -3;
} }
gAudioContext.soundFontList[fontId].instruments[index] = value; gAudioCtx.soundFontList[fontId].instruments[index] = value;
break; break;
} }
@ -456,7 +456,7 @@ void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) {
if (note->playbackState.parentLayer != layer) { if (note->playbackState.parentLayer != layer) {
if (note->playbackState.parentLayer == NO_LAYER && note->playbackState.wantedParentLayer == NO_LAYER && if (note->playbackState.parentLayer == NO_LAYER && note->playbackState.wantedParentLayer == NO_LAYER &&
note->playbackState.prevParentLayer == layer && target != ADSR_STATE_DECAY) { note->playbackState.prevParentLayer == layer && target != ADSR_STATE_DECAY) {
note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
note->playbackState.adsr.action.s.release = true; note->playbackState.adsr.action.s.release = true;
} }
return; return;
@ -500,16 +500,16 @@ void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) {
note->playbackState.prevParentLayer = note->playbackState.parentLayer; note->playbackState.prevParentLayer = note->playbackState.parentLayer;
note->playbackState.parentLayer = NO_LAYER; note->playbackState.parentLayer = NO_LAYER;
if (target == ADSR_STATE_RELEASE) { if (target == ADSR_STATE_RELEASE) {
note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
note->playbackState.adsr.action.s.release = true; note->playbackState.adsr.action.s.release = true;
note->playbackState.unk_04 = 2; note->playbackState.unk_04 = 2;
} else { } else {
note->playbackState.unk_04 = 1; note->playbackState.unk_04 = 1;
note->playbackState.adsr.action.s.decay = true; note->playbackState.adsr.action.s.decay = true;
if (layer->adsr.decayIndex == 0) { if (layer->adsr.decayIndex == 0) {
note->playbackState.adsr.fadeOutVel = gAudioContext.adsrDecayTable[layer->channel->adsr.decayIndex]; note->playbackState.adsr.fadeOutVel = gAudioCtx.adsrDecayTable[layer->channel->adsr.decayIndex];
} else { } else {
note->playbackState.adsr.fadeOutVel = gAudioContext.adsrDecayTable[layer->adsr.decayIndex]; note->playbackState.adsr.fadeOutVel = gAudioCtx.adsrDecayTable[layer->adsr.decayIndex];
} }
note->playbackState.adsr.sustain = note->playbackState.adsr.sustain =
((f32)(s32)(layer->channel->adsr.sustain) * note->playbackState.adsr.current) / 256.0f; ((f32)(s32)(layer->channel->adsr.sustain) * note->playbackState.adsr.current) / 256.0f;
@ -616,11 +616,11 @@ void Audio_InitNoteLists(NotePool* pool) {
void Audio_InitNoteFreeList(void) { void Audio_InitNoteFreeList(void) {
s32 i; s32 i;
Audio_InitNoteLists(&gAudioContext.noteFreeLists); Audio_InitNoteLists(&gAudioCtx.noteFreeLists);
for (i = 0; i < gAudioContext.numNotes; i++) { for (i = 0; i < gAudioCtx.numNotes; i++) {
gAudioContext.notes[i].listItem.u.value = &gAudioContext.notes[i]; gAudioCtx.notes[i].listItem.u.value = &gAudioCtx.notes[i];
gAudioContext.notes[i].listItem.prev = NULL; gAudioCtx.notes[i].listItem.prev = NULL;
AudioSeq_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, &gAudioContext.notes[i].listItem); AudioSeq_AudioListPushBack(&gAudioCtx.noteFreeLists.disabled, &gAudioCtx.notes[i].listItem);
} }
} }
@ -634,22 +634,22 @@ void Audio_NotePoolClear(NotePool* pool) {
switch (i) { switch (i) {
case 0: case 0:
source = &pool->disabled; source = &pool->disabled;
dest = &gAudioContext.noteFreeLists.disabled; dest = &gAudioCtx.noteFreeLists.disabled;
break; break;
case 1: case 1:
source = &pool->decaying; source = &pool->decaying;
dest = &gAudioContext.noteFreeLists.decaying; dest = &gAudioCtx.noteFreeLists.decaying;
break; break;
case 2: case 2:
source = &pool->releasing; source = &pool->releasing;
dest = &gAudioContext.noteFreeLists.releasing; dest = &gAudioCtx.noteFreeLists.releasing;
break; break;
case 3: case 3:
source = &pool->active; source = &pool->active;
dest = &gAudioContext.noteFreeLists.active; dest = &gAudioCtx.noteFreeLists.active;
break; break;
} }
@ -680,22 +680,22 @@ void Audio_NotePoolFill(NotePool* pool, s32 count) {
switch (i) { switch (i) {
case 0: case 0:
source = &gAudioContext.noteFreeLists.disabled; source = &gAudioCtx.noteFreeLists.disabled;
dest = &pool->disabled; dest = &pool->disabled;
break; break;
case 1: case 1:
source = &gAudioContext.noteFreeLists.decaying; source = &gAudioCtx.noteFreeLists.decaying;
dest = &pool->decaying; dest = &pool->decaying;
break; break;
case 2: case 2:
source = &gAudioContext.noteFreeLists.releasing; source = &gAudioCtx.noteFreeLists.releasing;
dest = &pool->releasing; dest = &pool->releasing;
break; break;
case 3: case 3:
source = &gAudioContext.noteFreeLists.active; source = &gAudioCtx.noteFreeLists.active;
dest = &pool->active; dest = &pool->active;
break; break;
} }
@ -805,7 +805,7 @@ void Audio_NoteReleaseAndTakeOwnership(Note* note, SequenceLayer* layer) {
note->playbackState.wantedParentLayer = layer; note->playbackState.wantedParentLayer = layer;
note->playbackState.priority = layer->channel->notePriority; note->playbackState.priority = layer->channel->notePriority;
note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
note->playbackState.adsr.action.s.release = true; note->playbackState.adsr.action.s.release = true;
} }
@ -899,9 +899,9 @@ Note* Audio_AllocNote(SequenceLayer* layer) {
} }
if (policy & 8) { if (policy & 8) {
if (!(note = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) && if (!(note = Audio_AllocNoteFromDisabled(&gAudioCtx.noteFreeLists, layer)) &&
!(note = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) && !(note = Audio_AllocNoteFromDecaying(&gAudioCtx.noteFreeLists, layer)) &&
!(note = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) { !(note = Audio_AllocNoteFromActive(&gAudioCtx.noteFreeLists, layer))) {
goto null_return; goto null_return;
} }
return note; return note;
@ -909,13 +909,13 @@ Note* Audio_AllocNote(SequenceLayer* layer) {
if (!(note = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) && if (!(note = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) &&
!(note = Audio_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) && !(note = Audio_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) &&
!(note = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) && !(note = Audio_AllocNoteFromDisabled(&gAudioCtx.noteFreeLists, layer)) &&
!(note = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) && !(note = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) &&
!(note = Audio_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) && !(note = Audio_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) &&
!(note = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) && !(note = Audio_AllocNoteFromDecaying(&gAudioCtx.noteFreeLists, layer)) &&
!(note = Audio_AllocNoteFromActive(&layer->channel->notePool, layer)) && !(note = Audio_AllocNoteFromActive(&layer->channel->notePool, layer)) &&
!(note = Audio_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer)) && !(note = Audio_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer)) &&
!(note = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) { !(note = Audio_AllocNoteFromActive(&gAudioCtx.noteFreeLists, layer))) {
goto null_return; goto null_return;
} }
return note; return note;
@ -929,8 +929,8 @@ void Audio_NoteInitAll(void) {
Note* note; Note* note;
s32 i; s32 i;
for (i = 0; i < gAudioContext.numNotes; i++) { for (i = 0; i < gAudioCtx.numNotes; i++) {
note = &gAudioContext.notes[i]; note = &gAudioCtx.notes[i];
note->noteSubEu = gZeroNoteSub; note->noteSubEu = gZeroNoteSub;
note->playbackState.priority = 0; note->playbackState.priority = 0;
note->playbackState.unk_04 = 0; note->playbackState.unk_04 = 0;
@ -947,6 +947,6 @@ void Audio_NoteInitAll(void) {
note->playbackState.stereoHeadsetEffects = false; note->playbackState.stereoHeadsetEffects = false;
note->startSamplePos = 0; note->startSamplePos = 0;
note->synthesisState.synthesisBuffers = note->synthesisState.synthesisBuffers =
AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, sizeof(NoteSynthesisBuffers)); AudioHeap_AllocDmaMemory(&gAudioCtx.miscPool, sizeof(NoteSynthesisBuffers));
} }
} }

View file

@ -252,7 +252,7 @@ s32 AudioSeq_HandleScriptFlowControl(SequencePlayer* seqPlayer, SeqScriptState*
void AudioSeq_InitSequenceChannel(SequenceChannel* channel) { void AudioSeq_InitSequenceChannel(SequenceChannel* channel) {
s32 i; s32 i;
if (channel == &gAudioContext.sequenceChannelNone) { if (channel == &gAudioCtx.sequenceChannelNone) {
return; return;
} }
@ -309,7 +309,7 @@ s32 AudioSeq_SeqChannelSetLayer(SequenceChannel* channel, s32 layerIndex) {
s32 pad; s32 pad;
if (channel->layers[layerIndex] == NULL) { if (channel->layers[layerIndex] == NULL) {
layer = AudioSeq_AudioListPopBack(&gAudioContext.layerFreeList); layer = AudioSeq_AudioListPopBack(&gAudioCtx.layerFreeList);
channel->layers[layerIndex] = layer; channel->layers[layerIndex] = layer;
if (layer == NULL) { if (layer == NULL) {
channel->layers[layerIndex] = NULL; channel->layers[layerIndex] = NULL;
@ -353,7 +353,7 @@ s32 AudioSeq_SeqChannelSetLayer(SequenceChannel* channel, s32 layerIndex) {
void AudioSeq_SeqLayerDisable(SequenceLayer* layer) { void AudioSeq_SeqLayerDisable(SequenceLayer* layer) {
if (layer != NULL) { if (layer != NULL) {
if (layer->channel != &gAudioContext.sequenceChannelNone && layer->channel->seqPlayer->finished == 1) { if (layer->channel != &gAudioCtx.sequenceChannelNone && layer->channel->seqPlayer->finished == 1) {
Audio_SeqLayerNoteRelease(layer); Audio_SeqLayerNoteRelease(layer);
} else { } else {
Audio_SeqLayerNoteDecay(layer); Audio_SeqLayerNoteDecay(layer);
@ -367,7 +367,7 @@ void AudioSeq_SeqLayerFree(SequenceChannel* channel, s32 layerIndex) {
SequenceLayer* layer = channel->layers[layerIndex]; SequenceLayer* layer = channel->layers[layerIndex];
if (layer != NULL) { if (layer != NULL) {
AudioSeq_AudioListPushBack(&gAudioContext.layerFreeList, &layer->listItem); AudioSeq_AudioListPushBack(&gAudioCtx.layerFreeList, &layer->listItem);
AudioSeq_SeqLayerDisable(layer); AudioSeq_SeqLayerDisable(layer);
channel->layers[layerIndex] = NULL; channel->layers[layerIndex] = NULL;
} }
@ -452,10 +452,10 @@ void AudioSeq_SequencePlayerDisable(SequencePlayer* seqPlayer) {
AudioLoad_SetFontLoadStatus(seqPlayer->defaultFont, LOAD_STATUS_MAYBE_DISCARDABLE); AudioLoad_SetFontLoadStatus(seqPlayer->defaultFont, LOAD_STATUS_MAYBE_DISCARDABLE);
} }
if (seqPlayer->defaultFont == gAudioContext.fontCache.temporary.entries[0].id) { if (seqPlayer->defaultFont == gAudioCtx.fontCache.temporary.entries[0].id) {
gAudioContext.fontCache.temporary.nextSide = 0; gAudioCtx.fontCache.temporary.nextSide = 0;
} else if (seqPlayer->defaultFont == gAudioContext.fontCache.temporary.entries[1].id) { } else if (seqPlayer->defaultFont == gAudioCtx.fontCache.temporary.entries[1].id) {
gAudioContext.fontCache.temporary.nextSide = 1; gAudioCtx.fontCache.temporary.nextSide = 1;
} }
} }
@ -488,15 +488,15 @@ void* AudioSeq_AudioListPopBack(AudioListItem* list) {
void AudioSeq_InitLayerFreelist(void) { void AudioSeq_InitLayerFreelist(void) {
s32 i; s32 i;
gAudioContext.layerFreeList.prev = &gAudioContext.layerFreeList; gAudioCtx.layerFreeList.prev = &gAudioCtx.layerFreeList;
gAudioContext.layerFreeList.next = &gAudioContext.layerFreeList; gAudioCtx.layerFreeList.next = &gAudioCtx.layerFreeList;
gAudioContext.layerFreeList.u.count = 0; gAudioCtx.layerFreeList.u.count = 0;
gAudioContext.layerFreeList.pool = NULL; gAudioCtx.layerFreeList.pool = NULL;
for (i = 0; i < ARRAY_COUNT(gAudioContext.sequenceLayers); i++) { for (i = 0; i < ARRAY_COUNT(gAudioCtx.sequenceLayers); i++) {
gAudioContext.sequenceLayers[i].listItem.u.value = &gAudioContext.sequenceLayers[i]; gAudioCtx.sequenceLayers[i].listItem.u.value = &gAudioCtx.sequenceLayers[i];
gAudioContext.sequenceLayers[i].listItem.prev = NULL; gAudioCtx.sequenceLayers[i].listItem.prev = NULL;
AudioSeq_AudioListPushBack(&gAudioContext.layerFreeList, &gAudioContext.sequenceLayers[i].listItem); AudioSeq_AudioListPushBack(&gAudioCtx.layerFreeList, &gAudioCtx.sequenceLayers[i].listItem);
} }
} }
@ -873,7 +873,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
layer->tunedSample = NULL; layer->tunedSample = NULL;
tuning = 1.0f; tuning = 1.0f;
if (instOrWave >= 0xC0) { if (instOrWave >= 0xC0) {
layer->tunedSample = &gAudioContext.synthesisReverbs[instOrWave - 0xC0].tunedSample; layer->tunedSample = &gAudioCtx.synthesisReverbs[instOrWave - 0xC0].tunedSample;
} }
} }
@ -903,12 +903,12 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
portamento->extent = (freqScale2 / freqScale) - 1.0f; portamento->extent = (freqScale2 / freqScale) - 1.0f;
if (PORTAMENTO_IS_SPECIAL(*portamento)) { if (PORTAMENTO_IS_SPECIAL(*portamento)) {
speed = seqPlayer->tempo * 0x8000 / gAudioContext.tempoInternalToExternal; speed = seqPlayer->tempo * 0x8000 / gAudioCtx.tempoInternalToExternal;
if (layer->delay != 0) { if (layer->delay != 0) {
speed = speed * 0x100 / (layer->delay * layer->portamentoTime); speed = speed * 0x100 / (layer->delay * layer->portamentoTime);
} }
} else { } else {
speed = 0x20000 / (layer->portamentoTime * gAudioContext.audioBufferParameters.updatesPerFrame); speed = 0x20000 / (layer->portamentoTime * gAudioCtx.audioBufferParameters.updatesPerFrame);
} }
if (speed >= 0x7FFF) { if (speed >= 0x7FFF) {
@ -935,7 +935,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
layer->tunedSample = NULL; layer->tunedSample = NULL;
layer->freqScale = gPitchFrequencies[semitone2]; layer->freqScale = gPitchFrequencies[semitone2];
if (instOrWave >= 0xC0) { if (instOrWave >= 0xC0) {
layer->tunedSample = &gAudioContext.synthesisReverbs[instOrWave - 0xC0].tunedSample; layer->tunedSample = &gAudioCtx.synthesisReverbs[instOrWave - 0xC0].tunedSample;
} }
} }
break; break;
@ -951,7 +951,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
time = 0.0f; time = 0.0f;
} }
time *= seqPlayer->tempo; time *= seqPlayer->tempo;
time *= gAudioContext.unk_2870; time *= gAudioCtx.unk_2870;
time /= layer->freqScale; time /= layer->freqScale;
if (time > 0x7FFE) { if (time > 0x7FFE) {
time = 0x7FFE; time = 0x7FFE;
@ -964,7 +964,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
// (It's a bit unclear if 'portamento' has actually always been // (It's a bit unclear if 'portamento' has actually always been
// set when this is reached...) // set when this is reached...)
if (PORTAMENTO_IS_SPECIAL(*portamento)) { if (PORTAMENTO_IS_SPECIAL(*portamento)) {
speed2 = seqPlayer->tempo * 0x8000 / gAudioContext.tempoInternalToExternal; speed2 = seqPlayer->tempo * 0x8000 / gAudioCtx.tempoInternalToExternal;
speed2 = speed2 * 0x100 / (layer->delay * layer->portamentoTime); speed2 = speed2 * 0x100 / (layer->delay * layer->portamentoTime);
if (speed2 >= 0x7FFF) { if (speed2 >= 0x7FFF) {
speed2 = 0x7FFF; speed2 = 0x7FFF;
@ -1043,8 +1043,8 @@ s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd) {
} }
if (channel->velocityRandomVariance != 0) { if (channel->velocityRandomVariance != 0) {
floatDelta = layer->velocitySquare * (gAudioContext.audioRandom % channel->velocityRandomVariance) / 100.0f; floatDelta = layer->velocitySquare * (gAudioCtx.audioRandom % channel->velocityRandomVariance) / 100.0f;
if ((gAudioContext.audioRandom & 0x8000) != 0) { if ((gAudioCtx.audioRandom & 0x8000) != 0) {
floatDelta = -floatDelta; floatDelta = -floatDelta;
} }
@ -1064,8 +1064,8 @@ s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd) {
if (channel->gateTimeRandomVariance != 0) { if (channel->gateTimeRandomVariance != 0) {
//! @bug should probably be gateTimeRandomVariance //! @bug should probably be gateTimeRandomVariance
intDelta = (layer->gateDelay * (gAudioContext.audioRandom % channel->velocityRandomVariance)) / 100; intDelta = (layer->gateDelay * (gAudioCtx.audioRandom % channel->velocityRandomVariance)) / 100;
if ((gAudioContext.audioRandom & 0x4000) != 0) { if ((gAudioCtx.audioRandom & 0x4000) != 0) {
intDelta = -intDelta; intDelta = -intDelta;
} }
@ -1244,9 +1244,9 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
cmd = (u8)cmdArgs[0]; cmd = (u8)cmdArgs[0];
if (seqPlayer->defaultFont != 0xFF) { if (seqPlayer->defaultFont != 0xFF) {
cmdArgU16 = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId]; cmdArgU16 = ((u16*)gAudioCtx.sequenceFontTable)[seqPlayer->seqId];
lowBits = gAudioContext.sequenceFontTable[cmdArgU16]; lowBits = gAudioCtx.sequenceFontTable[cmdArgU16];
cmd = gAudioContext.sequenceFontTable[cmdArgU16 + lowBits - cmd]; cmd = gAudioCtx.sequenceFontTable[cmdArgU16 + lowBits - cmd];
} }
if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, cmd)) { if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, cmd)) {
@ -1373,9 +1373,9 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
cmd = (u8)cmdArgs[0]; cmd = (u8)cmdArgs[0];
if (seqPlayer->defaultFont != 0xFF) { if (seqPlayer->defaultFont != 0xFF) {
cmdArgU16 = ((u16*)gAudioContext.sequenceFontTable)[seqPlayer->seqId]; cmdArgU16 = ((u16*)gAudioCtx.sequenceFontTable)[seqPlayer->seqId];
lowBits = gAudioContext.sequenceFontTable[cmdArgU16]; lowBits = gAudioCtx.sequenceFontTable[cmdArgU16];
cmd = gAudioContext.sequenceFontTable[cmdArgU16 + lowBits - cmd]; cmd = gAudioCtx.sequenceFontTable[cmdArgU16 + lowBits - cmd];
} }
if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, cmd)) { if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, cmd)) {
@ -1569,12 +1569,12 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
case 0xB7: case 0xB7:
channel->unk_22 = channel->unk_22 =
(cmdArgs[0] == 0) ? gAudioContext.audioRandom & 0xFFFF : gAudioContext.audioRandom % cmdArgs[0]; (cmdArgs[0] == 0) ? gAudioCtx.audioRandom & 0xFFFF : gAudioCtx.audioRandom % cmdArgs[0];
break; break;
case 0xB8: case 0xB8:
scriptState->value = scriptState->value =
(cmdArgs[0] == 0) ? gAudioContext.audioRandom & 0xFFFF : gAudioContext.audioRandom % cmdArgs[0]; (cmdArgs[0] == 0) ? gAudioCtx.audioRandom & 0xFFFF : gAudioCtx.audioRandom % cmdArgs[0];
break; break;
case 0xBD: case 0xBD:
@ -1746,11 +1746,11 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
seqPlayer->tempoAcc += seqPlayer->tempo; seqPlayer->tempoAcc += seqPlayer->tempo;
seqPlayer->tempoAcc += (s16)seqPlayer->unk_0C; seqPlayer->tempoAcc += (s16)seqPlayer->unk_0C;
if (seqPlayer->tempoAcc < gAudioContext.tempoInternalToExternal) { if (seqPlayer->tempoAcc < gAudioCtx.tempoInternalToExternal) {
return; return;
} }
seqPlayer->tempoAcc -= (u16)gAudioContext.tempoInternalToExternal; seqPlayer->tempoAcc -= (u16)gAudioCtx.tempoInternalToExternal;
if (seqPlayer->stopScript == true) { if (seqPlayer->stopScript == true) {
return; return;
@ -1811,8 +1811,8 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
case 0xDD: case 0xDD:
seqPlayer->tempo = AudioSeq_ScriptReadU8(seqScript) * TATUMS_PER_BEAT; seqPlayer->tempo = AudioSeq_ScriptReadU8(seqScript) * TATUMS_PER_BEAT;
if (seqPlayer->tempo > gAudioContext.tempoInternalToExternal) { if (seqPlayer->tempo > gAudioCtx.tempoInternalToExternal) {
seqPlayer->tempo = (u16)gAudioContext.tempoInternalToExternal; seqPlayer->tempo = (u16)gAudioCtx.tempoInternalToExternal;
} }
if ((s16)seqPlayer->tempo <= 0) { if ((s16)seqPlayer->tempo <= 0) {
@ -1909,9 +1909,9 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
case 0xCE: case 0xCE:
cmd = AudioSeq_ScriptReadU8(seqScript); cmd = AudioSeq_ScriptReadU8(seqScript);
if (cmd == 0) { if (cmd == 0) {
seqScript->value = (gAudioContext.audioRandom >> 2) & 0xFF; seqScript->value = (gAudioCtx.audioRandom >> 2) & 0xFF;
} else { } else {
seqScript->value = (gAudioContext.audioRandom >> 2) % cmd; seqScript->value = (gAudioCtx.audioRandom >> 2) % cmd;
} }
break; break;
@ -2038,11 +2038,10 @@ void AudioSeq_ProcessSequences(s32 arg0) {
SequencePlayer* seqPlayer; SequencePlayer* seqPlayer;
u32 i; u32 i;
gAudioContext.noteSubEuOffset = gAudioCtx.noteSubEuOffset = (gAudioCtx.audioBufferParameters.updatesPerFrame - arg0 - 1) * gAudioCtx.numNotes;
(gAudioContext.audioBufferParameters.updatesPerFrame - arg0 - 1) * gAudioContext.numNotes;
for (i = 0; i < (u32)gAudioContext.audioBufferParameters.numSequencePlayers; i++) { for (i = 0; i < (u32)gAudioCtx.audioBufferParameters.numSequencePlayers; i++) {
seqPlayer = &gAudioContext.seqPlayers[i]; seqPlayer = &gAudioCtx.seqPlayers[i];
if (seqPlayer->enabled == true) { if (seqPlayer->enabled == true) {
AudioSeq_SequencePlayerProcessSequence(seqPlayer); AudioSeq_SequencePlayerProcessSequence(seqPlayer);
Audio_SequencePlayerProcessSound(seqPlayer); Audio_SequencePlayerProcessSound(seqPlayer);
@ -2089,14 +2088,14 @@ void AudioSeq_ResetSequencePlayer(SequencePlayer* seqPlayer) {
void AudioSeq_InitSequencePlayerChannels(s32 playerIdx) { void AudioSeq_InitSequencePlayerChannels(s32 playerIdx) {
SequenceChannel* channel; SequenceChannel* channel;
SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx];
s32 i; s32 i;
s32 j; s32 j;
for (i = 0; i < SEQ_NUM_CHANNELS; i++) { for (i = 0; i < SEQ_NUM_CHANNELS; i++) {
seqPlayer->channels[i] = AudioHeap_AllocZeroed(&gAudioContext.miscPool, sizeof(SequenceChannel)); seqPlayer->channels[i] = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, sizeof(SequenceChannel));
if (seqPlayer->channels[i] == NULL) { if (seqPlayer->channels[i] == NULL) {
seqPlayer->channels[i] = &gAudioContext.sequenceChannelNone; seqPlayer->channels[i] = &gAudioCtx.sequenceChannelNone;
} else { } else {
channel = seqPlayer->channels[i]; channel = seqPlayer->channels[i];
channel->seqPlayer = seqPlayer; channel->seqPlayer = seqPlayer;
@ -2114,7 +2113,7 @@ void AudioSeq_InitSequencePlayer(SequencePlayer* seqPlayer) {
s32 j; s32 j;
for (i = 0; i < SEQ_NUM_CHANNELS; i++) { for (i = 0; i < SEQ_NUM_CHANNELS; i++) {
seqPlayer->channels[i] = &gAudioContext.sequenceChannelNone; seqPlayer->channels[i] = &gAudioCtx.sequenceChannelNone;
} }
seqPlayer->enabled = false; seqPlayer->enabled = false;
@ -2139,12 +2138,12 @@ void AudioSeq_InitSequencePlayers(void) {
AudioSeq_InitLayerFreelist(); AudioSeq_InitLayerFreelist();
for (i = 0; i < ARRAY_COUNT(gAudioContext.sequenceLayers); i++) { for (i = 0; i < ARRAY_COUNT(gAudioCtx.sequenceLayers); i++) {
gAudioContext.sequenceLayers[i].channel = NULL; gAudioCtx.sequenceLayers[i].channel = NULL;
gAudioContext.sequenceLayers[i].enabled = false; gAudioCtx.sequenceLayers[i].enabled = false;
} }
for (i = 0; i < ARRAY_COUNT(gAudioContext.seqPlayers); i++) { for (i = 0; i < ARRAY_COUNT(gAudioCtx.seqPlayers); i++) {
AudioSeq_InitSequencePlayer(&gAudioContext.seqPlayers[i]); AudioSeq_InitSequencePlayer(&gAudioCtx.seqPlayers[i]);
} }
} }

View file

@ -61,7 +61,7 @@ u8 sNumSamplesPerWavePeriod[] = {
void AudioSynth_InitNextRingBuf(s32 chunkLen, s32 updateIndex, s32 reverbIndex) { void AudioSynth_InitNextRingBuf(s32 chunkLen, s32 updateIndex, s32 reverbIndex) {
ReverbRingBufferItem* bufItem; ReverbRingBufferItem* bufItem;
s32 pad[3]; s32 pad[3];
SynthesisReverb* reverb = &gAudioContext.synthesisReverbs[reverbIndex]; SynthesisReverb* reverb = &gAudioCtx.synthesisReverbs[reverbIndex];
s32 temp_a0_2; s32 temp_a0_2;
s32 temp_a0_4; s32 temp_a0_4;
s32 numSamples; s32 numSamples;
@ -135,10 +135,10 @@ void func_800DB03C(s32 updateIndex) {
s32 baseIndex; s32 baseIndex;
s32 i; s32 i;
baseIndex = gAudioContext.numNotes * updateIndex; baseIndex = gAudioCtx.numNotes * updateIndex;
for (i = 0; i < gAudioContext.numNotes; i++) { for (i = 0; i < gAudioCtx.numNotes; i++) {
subEu = &gAudioContext.notes[i].noteSubEu; subEu = &gAudioCtx.notes[i].noteSubEu;
subEu2 = &gAudioContext.noteSubsEu[baseIndex + i]; subEu2 = &gAudioCtx.noteSubsEu[baseIndex + i];
if (subEu->bitField0.enabled) { if (subEu->bitField0.enabled) {
subEu->bitField0.needsInit = false; subEu->bitField0.needsInit = false;
} else { } else {
@ -158,42 +158,41 @@ Acmd* AudioSynth_Update(Acmd* cmdStart, s32* cmdCnt, s16* aiStart, s32 aiBufLen)
SynthesisReverb* reverb; SynthesisReverb* reverb;
cmdP = cmdStart; cmdP = cmdStart;
for (i = gAudioContext.audioBufferParameters.updatesPerFrame; i > 0; i--) { for (i = gAudioCtx.audioBufferParameters.updatesPerFrame; i > 0; i--) {
AudioSeq_ProcessSequences(i - 1); AudioSeq_ProcessSequences(i - 1);
func_800DB03C(gAudioContext.audioBufferParameters.updatesPerFrame - i); func_800DB03C(gAudioCtx.audioBufferParameters.updatesPerFrame - i);
} }
aiBufP = aiStart; aiBufP = aiStart;
gAudioContext.curLoadedBook = NULL; gAudioCtx.curLoadedBook = NULL;
for (i = gAudioContext.audioBufferParameters.updatesPerFrame; i > 0; i--) { for (i = gAudioCtx.audioBufferParameters.updatesPerFrame; i > 0; i--) {
if (i == 1) { if (i == 1) {
chunkLen = aiBufLen; chunkLen = aiBufLen;
} else if ((aiBufLen / i) >= gAudioContext.audioBufferParameters.samplesPerUpdateMax) { } else if ((aiBufLen / i) >= gAudioCtx.audioBufferParameters.samplesPerUpdateMax) {
chunkLen = gAudioContext.audioBufferParameters.samplesPerUpdateMax; chunkLen = gAudioCtx.audioBufferParameters.samplesPerUpdateMax;
} else if (gAudioContext.audioBufferParameters.samplesPerUpdateMin >= (aiBufLen / i)) { } else if (gAudioCtx.audioBufferParameters.samplesPerUpdateMin >= (aiBufLen / i)) {
chunkLen = gAudioContext.audioBufferParameters.samplesPerUpdateMin; chunkLen = gAudioCtx.audioBufferParameters.samplesPerUpdateMin;
} else { } else {
chunkLen = gAudioContext.audioBufferParameters.samplesPerUpdate; chunkLen = gAudioCtx.audioBufferParameters.samplesPerUpdate;
} }
for (j = 0; j < gAudioContext.numSynthesisReverbs; j++) { for (j = 0; j < gAudioCtx.numSynthesisReverbs; j++) {
if (gAudioContext.synthesisReverbs[j].useReverb) { if (gAudioCtx.synthesisReverbs[j].useReverb) {
AudioSynth_InitNextRingBuf(chunkLen, gAudioContext.audioBufferParameters.updatesPerFrame - i, j); AudioSynth_InitNextRingBuf(chunkLen, gAudioCtx.audioBufferParameters.updatesPerFrame - i, j);
} }
} }
cmdP = AudioSynth_DoOneAudioUpdate(aiBufP, chunkLen, cmdP, cmdP = AudioSynth_DoOneAudioUpdate(aiBufP, chunkLen, cmdP, gAudioCtx.audioBufferParameters.updatesPerFrame - i);
gAudioContext.audioBufferParameters.updatesPerFrame - i);
aiBufLen -= chunkLen; aiBufLen -= chunkLen;
aiBufP += 2 * chunkLen; aiBufP += 2 * chunkLen;
} }
for (j = 0; j < gAudioContext.numSynthesisReverbs; j++) { for (j = 0; j < gAudioCtx.numSynthesisReverbs; j++) {
if (gAudioContext.synthesisReverbs[j].framesToIgnore != 0) { if (gAudioCtx.synthesisReverbs[j].framesToIgnore != 0) {
gAudioContext.synthesisReverbs[j].framesToIgnore--; gAudioCtx.synthesisReverbs[j].framesToIgnore--;
} }
gAudioContext.synthesisReverbs[j].curFrame ^= 1; gAudioCtx.synthesisReverbs[j].curFrame ^= 1;
} }
*cmdCnt = cmdP - cmdStart; *cmdCnt = cmdP - cmdStart;
@ -204,8 +203,8 @@ void func_800DB2C0(s32 updateIndex, s32 noteIndex) {
NoteSubEu* noteSubEu; NoteSubEu* noteSubEu;
s32 i; s32 i;
for (i = updateIndex + 1; i < gAudioContext.audioBufferParameters.updatesPerFrame; i++) { for (i = updateIndex + 1; i < gAudioCtx.audioBufferParameters.updatesPerFrame; i++) {
noteSubEu = &gAudioContext.noteSubsEu[(gAudioContext.numNotes * i) + noteIndex]; noteSubEu = &gAudioCtx.noteSubsEu[(gAudioCtx.numNotes * i) + noteIndex];
if (!noteSubEu->bitField0.needsInit) { if (!noteSubEu->bitField0.needsInit) {
noteSubEu->bitField0.enabled = false; noteSubEu->bitField0.enabled = false;
} else { } else {
@ -332,7 +331,7 @@ Acmd* AudioSynth_FilterReverb(Acmd* cmd, s32 size, SynthesisReverb* reverb) {
Acmd* AudioSynth_MaybeMixRingBuffer1(Acmd* cmd, SynthesisReverb* reverb, s32 updateIndex) { Acmd* AudioSynth_MaybeMixRingBuffer1(Acmd* cmd, SynthesisReverb* reverb, s32 updateIndex) {
SynthesisReverb* temp_a3; SynthesisReverb* temp_a3;
temp_a3 = &gAudioContext.synthesisReverbs[reverb->unk_05]; temp_a3 = &gAudioCtx.synthesisReverbs[reverb->unk_05];
if (temp_a3->downsampleRate == 1) { if (temp_a3->downsampleRate == 1) {
cmd = AudioSynth_LoadRingBuffer1AtTemp(cmd, temp_a3, updateIndex); cmd = AudioSynth_LoadRingBuffer1AtTemp(cmd, temp_a3, updateIndex);
aMix(cmd++, DMEM_2CH_SIZE >> 4, reverb->unk_08, DMEM_WET_LEFT_CH, DMEM_WET_TEMP); aMix(cmd++, DMEM_2CH_SIZE >> 4, reverb->unk_08, DMEM_WET_LEFT_CH, DMEM_WET_TEMP);
@ -593,27 +592,27 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat
NoteSubEu* noteSubEu2; NoteSubEu* noteSubEu2;
s32 unk14; s32 unk14;
t = gAudioContext.numNotes * updateIndex; t = gAudioCtx.numNotes * updateIndex;
count = 0; count = 0;
if (gAudioContext.numSynthesisReverbs == 0) { if (gAudioCtx.numSynthesisReverbs == 0) {
for (i = 0; i < gAudioContext.numNotes; i++) { for (i = 0; i < gAudioCtx.numNotes; i++) {
if (gAudioContext.noteSubsEu[t + i].bitField0.enabled) { if (gAudioCtx.noteSubsEu[t + i].bitField0.enabled) {
noteIndices[count++] = i; noteIndices[count++] = i;
} }
} }
} else { } else {
for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) { for (reverbIndex = 0; reverbIndex < gAudioCtx.numSynthesisReverbs; reverbIndex++) {
for (i = 0; i < gAudioContext.numNotes; i++) { for (i = 0; i < gAudioCtx.numNotes; i++) {
noteSubEu = &gAudioContext.noteSubsEu[t + i]; noteSubEu = &gAudioCtx.noteSubsEu[t + i];
if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex == reverbIndex) { if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex == reverbIndex) {
noteIndices[count++] = i; noteIndices[count++] = i;
} }
} }
} }
for (i = 0; i < gAudioContext.numNotes; i++) { for (i = 0; i < gAudioCtx.numNotes; i++) {
noteSubEu = &gAudioContext.noteSubsEu[t + i]; noteSubEu = &gAudioCtx.noteSubsEu[t + i];
if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex >= gAudioContext.numSynthesisReverbs) { if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex >= gAudioCtx.numSynthesisReverbs) {
noteIndices[count++] = i; noteIndices[count++] = i;
} }
} }
@ -622,8 +621,8 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat
aClearBuffer(cmd++, DMEM_LEFT_CH, DMEM_2CH_SIZE); aClearBuffer(cmd++, DMEM_LEFT_CH, DMEM_2CH_SIZE);
i = 0; i = 0;
for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) { for (reverbIndex = 0; reverbIndex < gAudioCtx.numSynthesisReverbs; reverbIndex++) {
reverb = &gAudioContext.synthesisReverbs[reverbIndex]; reverb = &gAudioCtx.synthesisReverbs[reverbIndex];
useReverb = reverb->useReverb; useReverb = reverb->useReverb;
if (useReverb) { if (useReverb) {
@ -660,11 +659,11 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat
} }
while (i < count) { while (i < count) {
noteSubEu2 = &gAudioContext.noteSubsEu[noteIndices[i] + t]; noteSubEu2 = &gAudioCtx.noteSubsEu[noteIndices[i] + t];
if (noteSubEu2->bitField1.reverbIndex == reverbIndex) { if (noteSubEu2->bitField1.reverbIndex == reverbIndex) {
cmd = AudioSynth_ProcessNote(noteIndices[i], noteSubEu2, cmd =
&gAudioContext.notes[noteIndices[i]].synthesisState, aiBuf, aiBufLen, cmd, AudioSynth_ProcessNote(noteIndices[i], noteSubEu2, &gAudioCtx.notes[noteIndices[i]].synthesisState,
updateIndex); aiBuf, aiBufLen, cmd, updateIndex);
} else { } else {
break; break;
} }
@ -689,9 +688,9 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat
} }
while (i < count) { while (i < count) {
cmd = AudioSynth_ProcessNote(noteIndices[i], &gAudioContext.noteSubsEu[t + noteIndices[i]], cmd =
&gAudioContext.notes[noteIndices[i]].synthesisState, aiBuf, aiBufLen, cmd, AudioSynth_ProcessNote(noteIndices[i], &gAudioCtx.noteSubsEu[t + noteIndices[i]],
updateIndex); &gAudioCtx.notes[noteIndices[i]].synthesisState, aiBuf, aiBufLen, cmd, updateIndex);
i++; i++;
} }
@ -756,7 +755,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
bookOffset = noteSubEu->bitField1.bookOffset; bookOffset = noteSubEu->bitField1.bookOffset;
finished = noteSubEu->bitField0.finished; finished = noteSubEu->bitField0.finished;
note = &gAudioContext.notes[noteIndex]; note = &gAudioCtx.notes[noteIndex];
flags = A_CONTINUE; flags = A_CONTINUE;
if (noteSubEu->bitField0.needsInit == true) { if (noteSubEu->bitField0.needsInit == true) {
@ -814,24 +813,24 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
} }
if (sample->codec == CODEC_ADPCM || sample->codec == CODEC_SMALL_ADPCM) { if (sample->codec == CODEC_ADPCM || sample->codec == CODEC_SMALL_ADPCM) {
if (gAudioContext.curLoadedBook != sample->book->book) { if (gAudioCtx.curLoadedBook != sample->book->book) {
u32 nEntries; u32 nEntries;
switch (bookOffset) { switch (bookOffset) {
case 1: case 1:
gAudioContext.curLoadedBook = &D_8012FBA8[1]; gAudioCtx.curLoadedBook = &D_8012FBA8[1];
break; break;
case 2: case 2:
case 3: case 3:
default: default:
gAudioContext.curLoadedBook = sample->book->book; gAudioCtx.curLoadedBook = sample->book->book;
break; break;
} }
if (1) {} if (1) {}
if (1) {} if (1) {}
if (1) {} if (1) {}
nEntries = SAMPLES_PER_FRAME * sample->book->order * sample->book->numPredictors; nEntries = SAMPLES_PER_FRAME * sample->book->order * sample->book->numPredictors;
aLoadADPCM(cmd++, nEntries, gAudioContext.curLoadedBook); aLoadADPCM(cmd++, nEntries, gAudioCtx.curLoadedBook);
} }
} }

View file

@ -53,32 +53,32 @@ AudioTask* func_800E5000(void) {
s32 sp48; s32 sp48;
s32 i; s32 i;
gAudioContext.totalTaskCount++; gAudioCtx.totalTaskCount++;
if (gAudioContext.totalTaskCount % (gAudioContext.audioBufferParameters.specUnk4) != 0) { if (gAudioCtx.totalTaskCount % (gAudioCtx.audioBufferParameters.specUnk4) != 0) {
if (D_801755D0 != NULL) { if (D_801755D0 != NULL) {
D_801755D0(); D_801755D0();
} }
if ((gAudioContext.totalTaskCount % gAudioContext.audioBufferParameters.specUnk4) + 1 == if ((gAudioCtx.totalTaskCount % gAudioCtx.audioBufferParameters.specUnk4) + 1 ==
gAudioContext.audioBufferParameters.specUnk4) { gAudioCtx.audioBufferParameters.specUnk4) {
return sWaitingAudioTask; return sWaitingAudioTask;
} else { } else {
return NULL; return NULL;
} }
} }
osSendMesg(gAudioContext.taskStartQueueP, (OSMesg)gAudioContext.totalTaskCount, OS_MESG_NOBLOCK); osSendMesg(gAudioCtx.taskStartQueueP, (OSMesg)gAudioCtx.totalTaskCount, OS_MESG_NOBLOCK);
gAudioContext.rspTaskIndex ^= 1; gAudioCtx.rspTaskIndex ^= 1;
gAudioContext.curAiBufIndex++; gAudioCtx.curAiBufIndex++;
gAudioContext.curAiBufIndex %= 3; gAudioCtx.curAiBufIndex %= 3;
index = (gAudioContext.curAiBufIndex - 2 + 3) % 3; index = (gAudioCtx.curAiBufIndex - 2 + 3) % 3;
samplesRemainingInAi = osAiGetLength() / 4; samplesRemainingInAi = osAiGetLength() / 4;
if (gAudioContext.resetTimer < 16) { if (gAudioCtx.resetTimer < 16) {
if (gAudioContext.aiBufLengths[index] != 0) { if (gAudioCtx.aiBufLengths[index] != 0) {
osAiSetNextBuffer(gAudioContext.aiBuffers[index], gAudioContext.aiBufLengths[index] * 4); osAiSetNextBuffer(gAudioCtx.aiBuffers[index], gAudioCtx.aiBufLengths[index] * 4);
if (gAudioContext.aiBuffers[index]) {} if (gAudioCtx.aiBuffers[index]) {}
if (gAudioContext.aiBufLengths[index]) {} if (gAudioCtx.aiBufLengths[index]) {}
} }
} }
@ -86,36 +86,35 @@ AudioTask* func_800E5000(void) {
D_801755D0(); D_801755D0();
} }
sp5C = gAudioContext.curAudioFrameDmaCount; sp5C = gAudioCtx.curAudioFrameDmaCount;
for (i = 0; i < gAudioContext.curAudioFrameDmaCount; i++) { for (i = 0; i < gAudioCtx.curAudioFrameDmaCount; i++) {
if (osRecvMesg(&gAudioContext.currAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK) == 0) { if (osRecvMesg(&gAudioCtx.currAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK) == 0) {
sp5C--; sp5C--;
} }
} }
if (sp5C != 0) { if (sp5C != 0) {
for (i = 0; i < sp5C; i++) { for (i = 0; i < sp5C; i++) {
osRecvMesg(&gAudioContext.currAudioFrameDmaQueue, NULL, OS_MESG_BLOCK); osRecvMesg(&gAudioCtx.currAudioFrameDmaQueue, NULL, OS_MESG_BLOCK);
} }
} }
sp48 = MQ_GET_COUNT(&gAudioContext.currAudioFrameDmaQueue); sp48 = MQ_GET_COUNT(&gAudioCtx.currAudioFrameDmaQueue);
if (sp48 != 0) { if (sp48 != 0) {
for (i = 0; i < sp48; i++) { for (i = 0; i < sp48; i++) {
osRecvMesg(&gAudioContext.currAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK); osRecvMesg(&gAudioCtx.currAudioFrameDmaQueue, NULL, OS_MESG_NOBLOCK);
} }
} }
gAudioContext.curAudioFrameDmaCount = 0; gAudioCtx.curAudioFrameDmaCount = 0;
AudioLoad_DecreaseSampleDmaTtls(); AudioLoad_DecreaseSampleDmaTtls();
AudioLoad_ProcessLoads(gAudioContext.resetStatus); AudioLoad_ProcessLoads(gAudioCtx.resetStatus);
AudioLoad_ProcessScriptLoads(); AudioLoad_ProcessScriptLoads();
if (gAudioContext.resetStatus != 0) { if (gAudioCtx.resetStatus != 0) {
if (AudioHeap_ResetStep() == 0) { if (AudioHeap_ResetStep() == 0) {
if (gAudioContext.resetStatus == 0) { if (gAudioCtx.resetStatus == 0) {
osSendMesg(gAudioContext.audioResetQueueP, (OSMesg)(u32)gAudioContext.audioResetSpecIdToLoad, osSendMesg(gAudioCtx.audioResetQueueP, (OSMesg)(u32)gAudioCtx.audioResetSpecIdToLoad, OS_MESG_NOBLOCK);
OS_MESG_NOBLOCK);
} }
sWaitingAudioTask = NULL; sWaitingAudioTask = NULL;
@ -123,63 +122,62 @@ AudioTask* func_800E5000(void) {
} }
} }
if (gAudioContext.resetTimer > 16) { if (gAudioCtx.resetTimer > 16) {
return NULL; return NULL;
} }
if (gAudioContext.resetTimer != 0) { if (gAudioCtx.resetTimer != 0) {
gAudioContext.resetTimer++; gAudioCtx.resetTimer++;
} }
gAudioContext.curTask = &gAudioContext.rspTask[gAudioContext.rspTaskIndex]; gAudioCtx.curTask = &gAudioCtx.rspTask[gAudioCtx.rspTaskIndex];
gAudioContext.curAbiCmdBuf = gAudioContext.abiCmdBufs[gAudioContext.rspTaskIndex]; gAudioCtx.curAbiCmdBuf = gAudioCtx.abiCmdBufs[gAudioCtx.rspTaskIndex];
index = gAudioContext.curAiBufIndex; index = gAudioCtx.curAiBufIndex;
currAiBuffer = gAudioContext.aiBuffers[index]; currAiBuffer = gAudioCtx.aiBuffers[index];
gAudioContext.aiBufLengths[index] = gAudioCtx.aiBufLengths[index] =
(s16)((((gAudioContext.audioBufferParameters.samplesPerFrameTarget - samplesRemainingInAi) + (s16)((((gAudioCtx.audioBufferParameters.samplesPerFrameTarget - samplesRemainingInAi) +
EXTRA_BUFFERED_AI_SAMPLES_TARGET) & EXTRA_BUFFERED_AI_SAMPLES_TARGET) &
~0xF) + ~0xF) +
SAMPLES_TO_OVERPRODUCE); SAMPLES_TO_OVERPRODUCE);
if (gAudioContext.aiBufLengths[index] < gAudioContext.audioBufferParameters.minAiBufferLength) { if (gAudioCtx.aiBufLengths[index] < gAudioCtx.audioBufferParameters.minAiBufferLength) {
gAudioContext.aiBufLengths[index] = gAudioContext.audioBufferParameters.minAiBufferLength; gAudioCtx.aiBufLengths[index] = gAudioCtx.audioBufferParameters.minAiBufferLength;
} }
if (gAudioContext.aiBufLengths[index] > gAudioContext.audioBufferParameters.maxAiBufferLength) { if (gAudioCtx.aiBufLengths[index] > gAudioCtx.audioBufferParameters.maxAiBufferLength) {
gAudioContext.aiBufLengths[index] = gAudioContext.audioBufferParameters.maxAiBufferLength; gAudioCtx.aiBufLengths[index] = gAudioCtx.audioBufferParameters.maxAiBufferLength;
} }
j = 0; j = 0;
if (gAudioContext.resetStatus == 0) { if (gAudioCtx.resetStatus == 0) {
// msg = 0000RREE R = read pos, E = End Pos // msg = 0000RREE R = read pos, E = End Pos
while (osRecvMesg(gAudioContext.cmdProcQueueP, (OSMesg*)&sp4C, OS_MESG_NOBLOCK) != -1) { while (osRecvMesg(gAudioCtx.cmdProcQueueP, (OSMesg*)&sp4C, OS_MESG_NOBLOCK) != -1) {
if (1) {} if (1) {}
Audio_ProcessCmds(sp4C); Audio_ProcessCmds(sp4C);
j++; j++;
} }
if ((j == 0) && (gAudioContext.cmdQueueFinished)) { if ((j == 0) && (gAudioCtx.cmdQueueFinished)) {
Audio_ScheduleProcessCmds(); Audio_ScheduleProcessCmds();
} }
} }
gAudioContext.curAbiCmdBuf = gAudioCtx.curAbiCmdBuf =
AudioSynth_Update(gAudioContext.curAbiCmdBuf, &abiCmdCnt, currAiBuffer, gAudioContext.aiBufLengths[index]); AudioSynth_Update(gAudioCtx.curAbiCmdBuf, &abiCmdCnt, currAiBuffer, gAudioCtx.aiBufLengths[index]);
// Update audioRandom to the next random number // Update audioRandom to the next random number
gAudioContext.audioRandom = (gAudioContext.audioRandom + gAudioContext.totalTaskCount) * osGetCount(); gAudioCtx.audioRandom = (gAudioCtx.audioRandom + gAudioCtx.totalTaskCount) * osGetCount();
gAudioContext.audioRandom = gAudioCtx.audioRandom = gAudioCtx.audioRandom + gAudioCtx.aiBuffers[index][gAudioCtx.totalTaskCount & 0xFF];
gAudioContext.audioRandom + gAudioContext.aiBuffers[index][gAudioContext.totalTaskCount & 0xFF];
// gWaveSamples[8] interprets compiled assembly code as s16 samples as a way to generate sound with noise. // 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 func_800E4FE0, and offset it by a random number between 0 - 0xFFF0
// Use the resulting address as the starting address to interpret an array of samples i.e. `s16 samples[]` // Use the resulting address as the starting address to interpret an array of samples i.e. `s16 samples[]`
gWaveSamples[8] = (s16*)(((u8*)func_800E4FE0) + (gAudioContext.audioRandom & 0xFFF0)); gWaveSamples[8] = (s16*)(((u8*)func_800E4FE0) + (gAudioCtx.audioRandom & 0xFFF0));
index = gAudioContext.rspTaskIndex; index = gAudioCtx.rspTaskIndex;
gAudioContext.curTask->msgQueue = NULL; gAudioCtx.curTask->msgQueue = NULL;
gAudioContext.curTask->unk_44 = NULL; gAudioCtx.curTask->unk_44 = NULL;
task = &gAudioContext.curTask->task.t; task = &gAudioCtx.curTask->task.t;
task->type = M_AUDTASK; task->type = M_AUDTASK;
task->flags = 0; task->flags = 0;
task->ucode_boot = aspMainTextStart; task->ucode_boot = aspMainTextStart;
@ -193,7 +191,7 @@ AudioTask* func_800E5000(void) {
task->output_buff = NULL; task->output_buff = NULL;
task->output_buff_size = NULL; task->output_buff_size = NULL;
if (1) {} if (1) {}
task->data_ptr = (u64*)gAudioContext.abiCmdBufs[index]; task->data_ptr = (u64*)gAudioCtx.abiCmdBufs[index];
task->data_size = abiCmdCnt * sizeof(Acmd); task->data_size = abiCmdCnt * sizeof(Acmd);
task->yield_data_ptr = NULL; task->yield_data_ptr = NULL;
task->yield_data_size = 0; task->yield_data_size = 0;
@ -202,10 +200,10 @@ AudioTask* func_800E5000(void) {
sMaxAbiCmdCnt = abiCmdCnt; sMaxAbiCmdCnt = abiCmdCnt;
} }
if (gAudioContext.audioBufferParameters.specUnk4 == 1) { if (gAudioCtx.audioBufferParameters.specUnk4 == 1) {
return gAudioContext.curTask; return gAudioCtx.curTask;
} else { } else {
sWaitingAudioTask = gAudioContext.curTask; sWaitingAudioTask = gAudioCtx.curTask;
return NULL; return NULL;
} }
} }
@ -235,9 +233,9 @@ void func_800E5584(AudioCmd* cmd) {
break; break;
case 0x83: case 0x83:
if (gAudioContext.seqPlayers[cmd->arg0].enabled) { if (gAudioCtx.seqPlayers[cmd->arg0].enabled) {
if (cmd->asInt == 0) { if (cmd->asInt == 0) {
AudioSeq_SequencePlayerDisableAsFinished(&gAudioContext.seqPlayers[cmd->arg0]); AudioSeq_SequencePlayerDisableAsFinished(&gAudioCtx.seqPlayers[cmd->arg0]);
} else { } else {
func_800E5958(cmd->arg0, cmd->asInt); func_800E5958(cmd->arg0, cmd->asInt);
} }
@ -245,12 +243,12 @@ void func_800E5584(AudioCmd* cmd) {
break; break;
case 0xF0: case 0xF0:
gAudioContext.soundMode = cmd->asUInt; gAudioCtx.soundMode = cmd->asUInt;
break; break;
case 0xF1: case 0xF1:
for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) {
SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[i];
seqPlayer->muted = 1; seqPlayer->muted = 1;
seqPlayer->recalculateVolume = 1; seqPlayer->recalculateVolume = 1;
@ -259,8 +257,8 @@ void func_800E5584(AudioCmd* cmd) {
case 0xF2: case 0xF2:
if (cmd->asUInt == 1) { if (cmd->asUInt == 1) {
for (i = 0; i < gAudioContext.numNotes; i++) { for (i = 0; i < gAudioCtx.numNotes; i++) {
Note* note = &gAudioContext.notes[i]; Note* note = &gAudioCtx.notes[i];
NoteSubEu* subEu = &note->noteSubEu; NoteSubEu* subEu = &note->noteSubEu;
if (subEu->bitField0.enabled && note->playbackState.unk_04 == 0) { if (subEu->bitField0.enabled && note->playbackState.unk_04 == 0) {
@ -271,8 +269,8 @@ void func_800E5584(AudioCmd* cmd) {
} }
} }
for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) {
SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[i];
seqPlayer->muted = 0; seqPlayer->muted = 0;
seqPlayer->recalculateVolume = 1; seqPlayer->recalculateVolume = 1;
@ -284,15 +282,15 @@ void func_800E5584(AudioCmd* cmd) {
break; break;
case 0xF4: case 0xF4:
AudioLoad_AsyncLoadSampleBank(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue); AudioLoad_AsyncLoadSampleBank(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue);
break; break;
case 0xF5: case 0xF5:
AudioLoad_AsyncLoadFont(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue); AudioLoad_AsyncLoadFont(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue);
break; break;
case 0xFC: case 0xFC:
AudioLoad_AsyncLoadSeq(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue); AudioLoad_AsyncLoadSeq(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioCtx.externalLoadQueue);
break; break;
case 0xF6: case 0xF6:
@ -300,12 +298,12 @@ void func_800E5584(AudioCmd* cmd) {
break; break;
case 0x90: case 0x90:
gAudioContext.unk_5BDC[cmd->arg0] = cmd->asUShort; gAudioCtx.unk_5BDC[cmd->arg0] = cmd->asUShort;
break; break;
case 0xF9: case 0xF9:
gAudioContext.resetStatus = 5; gAudioCtx.resetStatus = 5;
gAudioContext.audioResetSpecIdToLoad = cmd->asUInt; gAudioCtx.audioResetSpecIdToLoad = cmd->asUInt;
break; break;
case 0xFB: case 0xFB:
@ -321,8 +319,8 @@ void func_800E5584(AudioCmd* cmd) {
case 0xFE: case 0xFE:
temp_t7 = cmd->asUInt; temp_t7 = cmd->asUInt;
if (temp_t7 == 1) { if (temp_t7 == 1) {
for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { for (i = 0; i < gAudioCtx.audioBufferParameters.numSequencePlayers; i++) {
SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[i];
if (seqPlayer->enabled) { if (seqPlayer->enabled) {
AudioSeq_SequencePlayerDisableAsFinished(seqPlayer); AudioSeq_SequencePlayerDisableAsFinished(seqPlayer);
@ -343,7 +341,7 @@ void func_800E5584(AudioCmd* cmd) {
// SetFadeOutTimer // SetFadeOutTimer
void func_800E5958(s32 playerIdx, s32 fadeTimer) { void func_800E5958(s32 playerIdx, s32 fadeTimer) {
SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx];
if (fadeTimer == 0) { if (fadeTimer == 0) {
fadeTimer = 1; fadeTimer = 1;
@ -359,7 +357,7 @@ void func_800E59AC(s32 playerIdx, s32 fadeTimer) {
SequencePlayer* seqPlayer; SequencePlayer* seqPlayer;
if (fadeTimer != 0) { if (fadeTimer != 0) {
seqPlayer = &gAudioContext.seqPlayers[playerIdx]; seqPlayer = &gAudioCtx.seqPlayers[playerIdx];
seqPlayer->state = 1; seqPlayer->state = 1;
seqPlayer->fadeTimerUnkEu = fadeTimer; seqPlayer->fadeTimerUnkEu = fadeTimer;
seqPlayer->fadeTimer = fadeTimer; seqPlayer->fadeTimer = fadeTimer;
@ -369,30 +367,27 @@ void func_800E59AC(s32 playerIdx, s32 fadeTimer) {
} }
void Audio_InitMesgQueuesInternal(void) { void Audio_InitMesgQueuesInternal(void) {
gAudioContext.cmdWrPos = 0; gAudioCtx.cmdWrPos = 0;
gAudioContext.cmdRdPos = 0; gAudioCtx.cmdRdPos = 0;
gAudioContext.cmdQueueFinished = 0; gAudioCtx.cmdQueueFinished = 0;
gAudioContext.taskStartQueueP = &gAudioContext.taskStartQueue; gAudioCtx.taskStartQueueP = &gAudioCtx.taskStartQueue;
gAudioContext.cmdProcQueueP = &gAudioContext.cmdProcQueue; gAudioCtx.cmdProcQueueP = &gAudioCtx.cmdProcQueue;
gAudioContext.audioResetQueueP = &gAudioContext.audioResetQueue; gAudioCtx.audioResetQueueP = &gAudioCtx.audioResetQueue;
osCreateMesgQueue(gAudioContext.taskStartQueueP, gAudioContext.taskStartMsgBuf, osCreateMesgQueue(gAudioCtx.taskStartQueueP, gAudioCtx.taskStartMsgBuf, ARRAY_COUNT(gAudioCtx.taskStartMsgBuf));
ARRAY_COUNT(gAudioContext.taskStartMsgBuf)); osCreateMesgQueue(gAudioCtx.cmdProcQueueP, gAudioCtx.cmdProcMsgBuf, ARRAY_COUNT(gAudioCtx.cmdProcMsgBuf));
osCreateMesgQueue(gAudioContext.cmdProcQueueP, gAudioContext.cmdProcMsgBuf, osCreateMesgQueue(gAudioCtx.audioResetQueueP, gAudioCtx.audioResetMsgBuf, ARRAY_COUNT(gAudioCtx.audioResetMsgBuf));
ARRAY_COUNT(gAudioContext.cmdProcMsgBuf));
osCreateMesgQueue(gAudioContext.audioResetQueueP, gAudioContext.audioResetMsgBuf,
ARRAY_COUNT(gAudioContext.audioResetMsgBuf));
} }
void Audio_QueueCmd(u32 opArgs, void** data) { void Audio_QueueCmd(u32 opArgs, void** data) {
AudioCmd* cmd = &gAudioContext.cmdBuf[gAudioContext.cmdWrPos & 0xFF]; AudioCmd* cmd = &gAudioCtx.cmdBuf[gAudioCtx.cmdWrPos & 0xFF];
cmd->opArgs = opArgs; cmd->opArgs = opArgs;
cmd->data = *data; cmd->data = *data;
gAudioContext.cmdWrPos++; gAudioCtx.cmdWrPos++;
if (gAudioContext.cmdWrPos == gAudioContext.cmdRdPos) { if (gAudioCtx.cmdWrPos == gAudioCtx.cmdRdPos) {
gAudioContext.cmdWrPos--; gAudioCtx.cmdWrPos--;
} }
} }
@ -420,15 +415,14 @@ s32 Audio_ScheduleProcessCmds(void) {
static s32 D_801304E8 = 0; static s32 D_801304E8 = 0;
s32 ret; s32 ret;
if (D_801304E8 < (u8)((gAudioContext.cmdWrPos - gAudioContext.cmdRdPos) + 0x100)) { if (D_801304E8 < (u8)((gAudioCtx.cmdWrPos - gAudioCtx.cmdRdPos) + 0x100)) {
D_801304E8 = (u8)((gAudioContext.cmdWrPos - gAudioContext.cmdRdPos) + 0x100); D_801304E8 = (u8)((gAudioCtx.cmdWrPos - gAudioCtx.cmdRdPos) + 0x100);
} }
ret = ret = osSendMesg(gAudioCtx.cmdProcQueueP,
osSendMesg(gAudioContext.cmdProcQueueP, (OSMesg)(((gAudioCtx.cmdRdPos & 0xFF) << 8) | (gAudioCtx.cmdWrPos & 0xFF)), OS_MESG_NOBLOCK);
(OSMesg)(((gAudioContext.cmdRdPos & 0xFF) << 8) | (gAudioContext.cmdWrPos & 0xFF)), OS_MESG_NOBLOCK);
if (ret != -1) { if (ret != -1) {
gAudioContext.cmdRdPos = gAudioContext.cmdWrPos; gAudioCtx.cmdRdPos = gAudioCtx.cmdWrPos;
ret = 0; ret = 0;
} else { } else {
return -1; return -1;
@ -438,8 +432,8 @@ s32 Audio_ScheduleProcessCmds(void) {
} }
void Audio_ResetCmdQueue(void) { void Audio_ResetCmdQueue(void) {
gAudioContext.cmdQueueFinished = 0; gAudioCtx.cmdQueueFinished = 0;
gAudioContext.cmdRdPos = gAudioContext.cmdWrPos; gAudioCtx.cmdRdPos = gAudioCtx.cmdWrPos;
} }
void Audio_ProcessCmd(AudioCmd* cmd) { void Audio_ProcessCmd(AudioCmd* cmd) {
@ -452,8 +446,8 @@ void Audio_ProcessCmd(AudioCmd* cmd) {
return; return;
} }
if (cmd->arg0 < gAudioContext.audioBufferParameters.numSequencePlayers) { if (cmd->arg0 < gAudioCtx.audioBufferParameters.numSequencePlayers) {
seqPlayer = &gAudioContext.seqPlayers[cmd->arg0]; seqPlayer = &gAudioCtx.seqPlayers[cmd->arg0];
if (cmd->op & 0x80) { if (cmd->op & 0x80) {
func_800E5584(cmd); func_800E5584(cmd);
return; return;
@ -468,7 +462,7 @@ void Audio_ProcessCmd(AudioCmd* cmd) {
return; return;
} }
if (cmd->arg1 == 0xFF) { if (cmd->arg1 == 0xFF) {
phi_v0 = gAudioContext.unk_5BDC[cmd->arg0]; phi_v0 = gAudioCtx.unk_5BDC[cmd->arg0];
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
if (phi_v0 & 1) { if (phi_v0 & 1) {
func_800E6300(seqPlayer->channels[i], cmd); func_800E6300(seqPlayer->channels[i], cmd);
@ -484,20 +478,20 @@ void Audio_ProcessCmds(u32 msg) {
AudioCmd* cmd; AudioCmd* cmd;
u8 endPos; u8 endPos;
if (!gAudioContext.cmdQueueFinished) { if (!gAudioCtx.cmdQueueFinished) {
curCmdRdPos = msg >> 8; curCmdRdPos = msg >> 8;
} }
while (true) { while (true) {
endPos = msg & 0xFF; endPos = msg & 0xFF;
if (curCmdRdPos == endPos) { if (curCmdRdPos == endPos) {
gAudioContext.cmdQueueFinished = 0; gAudioCtx.cmdQueueFinished = 0;
return; return;
} }
cmd = &gAudioContext.cmdBuf[curCmdRdPos++ & 0xFF]; cmd = &gAudioCtx.cmdBuf[curCmdRdPos++ & 0xFF];
if (cmd->op == 0xF8) { if (cmd->op == 0xF8) {
gAudioContext.cmdQueueFinished = 1; gAudioCtx.cmdQueueFinished = 1;
return; return;
} }
@ -509,7 +503,7 @@ void Audio_ProcessCmds(u32 msg) {
u32 func_800E5E20(u32* out) { u32 func_800E5E20(u32* out) {
u32 sp1C; u32 sp1C;
if (osRecvMesg(&gAudioContext.externalLoadQueue, (OSMesg*)&sp1C, OS_MESG_NOBLOCK) == -1) { if (osRecvMesg(&gAudioCtx.externalLoadQueue, (OSMesg*)&sp1C, OS_MESG_NOBLOCK) == -1) {
*out = 0; *out = 0;
return 0; return 0;
} }
@ -522,17 +516,17 @@ u8* func_800E5E84(s32 arg0, u32* arg1) {
} }
void Audio_GetSampleBankIdsOfFont(s32 fontId, u32* sampleBankId1, u32* sampleBankId2) { void Audio_GetSampleBankIdsOfFont(s32 fontId, u32* sampleBankId1, u32* sampleBankId2) {
*sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; *sampleBankId1 = gAudioCtx.soundFontList[fontId].sampleBankId1;
*sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; *sampleBankId2 = gAudioCtx.soundFontList[fontId].sampleBankId2;
} }
s32 func_800E5EDC(void) { s32 func_800E5EDC(void) {
s32 pad; s32 pad;
s32 sp18; s32 sp18;
if (osRecvMesg(gAudioContext.audioResetQueueP, (OSMesg*)&sp18, OS_MESG_NOBLOCK) == -1) { if (osRecvMesg(gAudioCtx.audioResetQueueP, (OSMesg*)&sp18, OS_MESG_NOBLOCK) == -1) {
return 0; return 0;
} else if (gAudioContext.audioResetSpecIdToLoad != sp18) { } else if (gAudioCtx.audioResetSpecIdToLoad != sp18) {
return -1; return -1;
} else { } else {
return 1; return 1;
@ -542,7 +536,7 @@ s32 func_800E5EDC(void) {
void func_800E5F34(void) { void func_800E5F34(void) {
// macro? // macro?
// clang-format off // clang-format off
s32 chk = -1; OSMesg msg; do {} while (osRecvMesg(gAudioContext.audioResetQueueP, &msg, OS_MESG_NOBLOCK) != chk); s32 chk = -1; OSMesg msg; do {} while (osRecvMesg(gAudioCtx.audioResetQueueP, &msg, OS_MESG_NOBLOCK) != chk);
// clang-format on // clang-format on
} }
@ -552,16 +546,16 @@ s32 func_800E5F88(s32 resetPreloadID) {
s32 pad; s32 pad;
func_800E5F34(); func_800E5F34();
resetStatus = gAudioContext.resetStatus; resetStatus = gAudioCtx.resetStatus;
if (resetStatus != 0) { if (resetStatus != 0) {
Audio_ResetCmdQueue(); Audio_ResetCmdQueue();
if (gAudioContext.audioResetSpecIdToLoad == resetPreloadID) { if (gAudioCtx.audioResetSpecIdToLoad == resetPreloadID) {
return -2; return -2;
} else if (resetStatus > 2) { } else if (resetStatus > 2) {
gAudioContext.audioResetSpecIdToLoad = resetPreloadID; gAudioCtx.audioResetSpecIdToLoad = resetPreloadID;
return -3; return -3;
} else { } else {
osRecvMesg(gAudioContext.audioResetQueueP, &msg, OS_MESG_BLOCK); osRecvMesg(gAudioCtx.audioResetQueueP, &msg, OS_MESG_BLOCK);
} }
} }
@ -572,15 +566,15 @@ s32 func_800E5F88(s32 resetPreloadID) {
} }
void Audio_PreNMIInternal(void) { void Audio_PreNMIInternal(void) {
gAudioContext.resetTimer = 1; gAudioCtx.resetTimer = 1;
if (gAudioContextInitialized) { if (gAudioContextInitialized) {
func_800E5F88(0); func_800E5F88(0);
gAudioContext.resetStatus = 0; gAudioCtx.resetStatus = 0;
} }
} }
s8 func_800E6070(s32 playerIdx, s32 channelIdx, s32 scriptIdx) { s8 func_800E6070(s32 playerIdx, s32 channelIdx, s32 scriptIdx) {
SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIdx]; SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIdx];
SequenceChannel* channel; SequenceChannel* channel;
if (seqPlayer->enabled) { if (seqPlayer->enabled) {
@ -592,15 +586,15 @@ s8 func_800E6070(s32 playerIdx, s32 channelIdx, s32 scriptIdx) {
} }
s8 func_800E60C4(s32 playerIdx, s32 port) { s8 func_800E60C4(s32 playerIdx, s32 port) {
return gAudioContext.seqPlayers[playerIdx].soundScriptIO[port]; return gAudioCtx.seqPlayers[playerIdx].soundScriptIO[port];
} }
void Audio_InitExternalPool(void* ramAddr, u32 size) { void Audio_InitExternalPool(void* ramAddr, u32 size) {
AudioHeap_InitPool(&gAudioContext.externalPool, ramAddr, size); AudioHeap_InitPool(&gAudioCtx.externalPool, ramAddr, size);
} }
void Audio_DestroyExternalPool(void) { void Audio_DestroyExternalPool(void) {
gAudioContext.externalPool.startRamAddr = NULL; gAudioCtx.externalPool.startRamAddr = NULL;
} }
void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) { void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) {
@ -780,8 +774,8 @@ void func_800E651C(u32 arg0, s32 arg1) {
} }
void Audio_WaitForAudioTask(void) { void Audio_WaitForAudioTask(void) {
osRecvMesg(gAudioContext.taskStartQueueP, NULL, OS_MESG_NOBLOCK); osRecvMesg(gAudioCtx.taskStartQueueP, NULL, OS_MESG_NOBLOCK);
osRecvMesg(gAudioContext.taskStartQueueP, NULL, OS_MESG_BLOCK); osRecvMesg(gAudioCtx.taskStartQueueP, NULL, OS_MESG_BLOCK);
} }
s32 func_800E6590(s32 playerIdx, s32 arg1, s32 arg2) { s32 func_800E6590(s32 playerIdx, s32 arg1, s32 arg2) {
@ -792,7 +786,7 @@ s32 func_800E6590(s32 playerIdx, s32 arg1, s32 arg2) {
s32 loopEnd; s32 loopEnd;
s32 samplePos; s32 samplePos;
seqPlayer = &gAudioContext.seqPlayers[playerIdx]; seqPlayer = &gAudioCtx.seqPlayers[playerIdx];
if (seqPlayer->enabled && seqPlayer->channels[arg1]->enabled) { if (seqPlayer->enabled && seqPlayer->channels[arg1]->enabled) {
layer = seqPlayer->channels[arg1]->layers[arg2]; layer = seqPlayer->channels[arg1]->layers[arg2];
if (layer == NULL) { if (layer == NULL) {
@ -841,8 +835,8 @@ s32 func_800E66C0(s32 arg0) {
TunedSample* tunedSample; TunedSample* tunedSample;
phi_v1 = 0; phi_v1 = 0;
for (i = 0; i < gAudioContext.numNotes; i++) { for (i = 0; i < gAudioCtx.numNotes; i++) {
note = &gAudioContext.notes[i]; note = &gAudioCtx.notes[i];
playbackState = &note->playbackState; playbackState = &note->playbackState;
if (note->noteSubEu.bitField0.enabled) { if (note->noteSubEu.bitField0.enabled) {
noteSubEu = &note->noteSubEu; noteSubEu = &note->noteSubEu;
@ -859,7 +853,7 @@ s32 func_800E66C0(s32 arg0) {
phi_v1++; phi_v1++;
if ((arg0 & 1) == 1) { if ((arg0 & 1) == 1) {
playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
playbackState->adsr.action.s.release = 1; playbackState->adsr.action.s.release = 1;
} }
} }
@ -871,8 +865,8 @@ s32 func_800E66C0(s32 arg0) {
u32 Audio_NextRandom(void) { u32 Audio_NextRandom(void) {
static u32 audRand = 0x12345678; static u32 audRand = 0x12345678;
audRand = ((osGetCount() + 0x1234567) * (audRand + gAudioContext.totalTaskCount)); audRand = ((osGetCount() + 0x1234567) * (audRand + gAudioCtx.totalTaskCount));
audRand += gAudioContext.audioRandom; audRand += gAudioCtx.audioRandom;
return audRand; return audRand;
} }

View file

@ -2200,7 +2200,7 @@ s32 AudioOcarina_MemoryGameNextNote(void) {
} }
void AudioOcarina_Update(void) { void AudioOcarina_Update(void) {
sOcarinaUpdateTaskStart = gAudioContext.totalTaskCount; sOcarinaUpdateTaskStart = gAudioCtx.totalTaskCount;
if (sOcarinaInstrumentId != OCARINA_INSTRUMENT_OFF) { if (sOcarinaInstrumentId != OCARINA_INSTRUMENT_OFF) {
if (sIsOcarinaInputEnabled == true) { if (sIsOcarinaInputEnabled == true) {
AudioOcarina_ReadControllerInput(); AudioOcarina_ReadControllerInput();
@ -2404,7 +2404,7 @@ void AudioDebug_Draw(GfxPrint* printer) {
GfxPrint_Printf(printer, "- %s -", sAudioDebugPageNames[sAudioDebugPage]); GfxPrint_Printf(printer, "- %s -", sAudioDebugPageNames[sAudioDebugPage]);
for (i = 0; i < gAudioSpecs[gAudioSpecId].numNotes; i++) { for (i = 0; i < gAudioSpecs[gAudioSpecId].numNotes; i++) {
if (gAudioContext.notes[i].noteSubEu.bitField0.enabled == 1) { if (gAudioCtx.notes[i].noteSubEu.bitField0.enabled == 1) {
numEnabledNotes++; numEnabledNotes++;
} }
} }
@ -2529,7 +2529,7 @@ void AudioDebug_Draw(GfxPrint* printer) {
for (k2 = 0; k2 < gChannelsPerBank[gSfxChannelLayout][k]; k2++) { for (k2 = 0; k2 < gChannelsPerBank[gSfxChannelLayout][k]; k2++) {
#define entryIndex (gActiveSfx[k][k2].entryIndex) #define entryIndex (gActiveSfx[k][k2].entryIndex)
#define entry (&gSfxBanks[k][entryIndex]) #define entry (&gSfxBanks[k][entryIndex])
#define chan (gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[entry->channelIdx]) #define chan (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[entry->channelIdx])
GfxPrint_SetPos(printer, 2 + sAudioIntInfoX, 5 + ind + sAudioIntInfoY); GfxPrint_SetPos(printer, 2 + sAudioIntInfoX, 5 + ind + sAudioIntInfoY);
if (sAudioIntInfoBankPage[k] == 1) { if (sAudioIntInfoBankPage[k] == 1) {
if ((entryIndex != 0xFF) && if ((entryIndex != 0xFF) &&
@ -2692,14 +2692,14 @@ void AudioDebug_Draw(GfxPrint* printer) {
GfxPrint_Printf(printer, "%1X", i); GfxPrint_Printf(printer, "%1X", i);
GfxPrint_SetPos(printer, 15 + i, 7); GfxPrint_SetPos(printer, 15 + i, 7);
if (gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->enabled) { if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->enabled) {
GfxPrint_Printf(printer, "O"); GfxPrint_Printf(printer, "O");
} else { } else {
GfxPrint_Printf(printer, "X"); GfxPrint_Printf(printer, "X");
} }
GfxPrint_SetPos(printer, 15 + i, 8); GfxPrint_SetPos(printer, 15 + i, 8);
if (gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->stopSomething2) { if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->stopSomething2) {
GfxPrint_Printf(printer, "O"); GfxPrint_Printf(printer, "O");
} else { } else {
GfxPrint_Printf(printer, "X"); GfxPrint_Printf(printer, "X");
@ -2708,7 +2708,7 @@ void AudioDebug_Draw(GfxPrint* printer) {
GfxPrint_SetPos(printer, 15 + i, 9); GfxPrint_SetPos(printer, 15 + i, 9);
ctr = 0; ctr = 0;
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
if (gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->layers[j] != NULL) { if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[i]->layers[j] != NULL) {
ctr++; ctr++;
} }
} }
@ -2763,33 +2763,32 @@ void AudioDebug_Draw(GfxPrint* printer) {
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
GfxPrint_SetPos(printer, 15 + 3 * i, 22); GfxPrint_SetPos(printer, 15 + 3 * i, 22);
GfxPrint_Printf(printer, "%02X ", GfxPrint_Printf(printer, "%02X ",
(u8)gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] (u8)gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel]
.channels[sAudioSubTrackInfoChannelSel] .channels[sAudioSubTrackInfoChannelSel]
->soundScriptIO[i]); ->soundScriptIO[i]);
} }
if (gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->enabled) { if (gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->enabled) {
GfxPrint_SetPos(printer, 15, 11); GfxPrint_SetPos(printer, 15, 11);
GfxPrint_Printf(printer, "%d", GfxPrint_Printf(printer, "%d",
(u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel]
.channels[sAudioSubTrackInfoChannelSel] .channels[sAudioSubTrackInfoChannelSel]
->volume * ->volume *
127.1)); 127.1));
GfxPrint_SetPos(printer, 15, 12); GfxPrint_SetPos(printer, 15, 12);
GfxPrint_Printf(printer, "%d", GfxPrint_Printf(printer, "%d",
(u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel]
.channels[sAudioSubTrackInfoChannelSel] .channels[sAudioSubTrackInfoChannelSel]
->volumeScale * ->volumeScale *
127.1)); 127.1));
GfxPrint_SetPos(printer, 15, 13); GfxPrint_SetPos(printer, 15, 13);
GfxPrint_Printf(printer, "%X", GfxPrint_Printf(
gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] printer, "%X",
.channels[sAudioSubTrackInfoChannelSel] gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->fontId);
->fontId);
ctr = (u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] ctr = (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel]
.channels[sAudioSubTrackInfoChannelSel] .channels[sAudioSubTrackInfoChannelSel]
->instOrWave); ->instOrWave);
@ -2805,46 +2804,44 @@ void AudioDebug_Draw(GfxPrint* printer) {
GfxPrint_Printf(printer, "%d", ctr2); GfxPrint_Printf(printer, "%d", ctr2);
GfxPrint_SetPos(printer, 15, 15); GfxPrint_SetPos(printer, 15, 15);
GfxPrint_Printf(printer, "%d", GfxPrint_Printf(
gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] printer, "%d",
.channels[sAudioSubTrackInfoChannelSel] gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->newPan);
->newPan);
GfxPrint_SetPos(printer, 15, 16); GfxPrint_SetPos(printer, 15, 16);
GfxPrint_Printf(printer, "%d", GfxPrint_Printf(printer, "%d",
gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel]
.channels[sAudioSubTrackInfoChannelSel] .channels[sAudioSubTrackInfoChannelSel]
->panChannelWeight); ->panChannelWeight);
GfxPrint_SetPos(printer, 15, 17); GfxPrint_SetPos(printer, 15, 17);
GfxPrint_Printf(printer, "%d", GfxPrint_Printf(
gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] printer, "%d",
.channels[sAudioSubTrackInfoChannelSel] gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel].channels[sAudioSubTrackInfoChannelSel]->reverb);
->reverb);
GfxPrint_SetPos(printer, 15, 18); GfxPrint_SetPos(printer, 15, 18);
GfxPrint_Printf(printer, "%d", GfxPrint_Printf(printer, "%d",
gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel]
.channels[sAudioSubTrackInfoChannelSel] .channels[sAudioSubTrackInfoChannelSel]
->notePriority); ->notePriority);
GfxPrint_SetPos(printer, 15, 19); GfxPrint_SetPos(printer, 15, 19);
GfxPrint_Printf(printer, "%d", GfxPrint_Printf(printer, "%d",
(u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel]
.channels[sAudioSubTrackInfoChannelSel] .channels[sAudioSubTrackInfoChannelSel]
->vibratoRateTarget / ->vibratoRateTarget /
32)); 32));
GfxPrint_SetPos(printer, 15, 20); GfxPrint_SetPos(printer, 15, 20);
GfxPrint_Printf(printer, "%d", GfxPrint_Printf(printer, "%d",
(u8)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] (u8)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel]
.channels[sAudioSubTrackInfoChannelSel] .channels[sAudioSubTrackInfoChannelSel]
->vibratoExtentTarget / ->vibratoExtentTarget /
8)); 8));
GfxPrint_SetPos(printer, 15, 21); GfxPrint_SetPos(printer, 15, 21);
GfxPrint_Printf(printer, "%d", GfxPrint_Printf(printer, "%d",
(u16)(gAudioContext.seqPlayers[sAudioSubTrackInfoPlayerSel] (u16)(gAudioCtx.seqPlayers[sAudioSubTrackInfoPlayerSel]
.channels[sAudioSubTrackInfoChannelSel] .channels[sAudioSubTrackInfoChannelSel]
->freqScale * ->freqScale *
100)); 100));
@ -2858,47 +2855,46 @@ void AudioDebug_Draw(GfxPrint* printer) {
GfxPrint_SetPos(printer, 3, 5); GfxPrint_SetPos(printer, 3, 5);
GfxPrint_Printf(printer, "DRIVER %05X / %05X", GfxPrint_Printf(printer, "DRIVER %05X / %05X",
gAudioContext.miscPool.curRamAddr - gAudioContext.miscPool.startRamAddr, gAudioCtx.miscPool.curRamAddr - gAudioCtx.miscPool.startRamAddr, gAudioCtx.miscPool.size);
gAudioContext.miscPool.size);
GfxPrint_SetPos(printer, 3, 6); GfxPrint_SetPos(printer, 3, 6);
GfxPrint_Printf( GfxPrint_Printf(
printer, "AT-SEQ %02X-%02X (%05X-%05X / %05X)", (u8)gAudioContext.seqCache.temporary.entries[0].id, printer, "AT-SEQ %02X-%02X (%05X-%05X / %05X)", (u8)gAudioCtx.seqCache.temporary.entries[0].id,
(u8)gAudioContext.seqCache.temporary.entries[1].id, gAudioContext.seqCache.temporary.entries[0].size, (u8)gAudioCtx.seqCache.temporary.entries[1].id, gAudioCtx.seqCache.temporary.entries[0].size,
gAudioContext.seqCache.temporary.entries[1].size, gAudioContext.seqCache.temporary.pool.size); gAudioCtx.seqCache.temporary.entries[1].size, gAudioCtx.seqCache.temporary.pool.size);
GfxPrint_SetPos(printer, 3, 7); GfxPrint_SetPos(printer, 3, 7);
GfxPrint_Printf( GfxPrint_Printf(
printer, "AT-BNK %02X-%02X (%05X-%05X / %05X)", (u8)gAudioContext.fontCache.temporary.entries[0].id, printer, "AT-BNK %02X-%02X (%05X-%05X / %05X)", (u8)gAudioCtx.fontCache.temporary.entries[0].id,
(u8)gAudioContext.fontCache.temporary.entries[1].id, gAudioContext.fontCache.temporary.entries[0].size, (u8)gAudioCtx.fontCache.temporary.entries[1].id, gAudioCtx.fontCache.temporary.entries[0].size,
gAudioContext.fontCache.temporary.entries[1].size, gAudioContext.fontCache.temporary.pool.size); gAudioCtx.fontCache.temporary.entries[1].size, gAudioCtx.fontCache.temporary.pool.size);
GfxPrint_SetPos(printer, 3, 8); GfxPrint_SetPos(printer, 3, 8);
GfxPrint_Printf(printer, "ST-SEQ %02Xseqs (%05X / %06X)", gAudioContext.seqCache.persistent.numEntries, GfxPrint_Printf(printer, "ST-SEQ %02Xseqs (%05X / %06X)", gAudioCtx.seqCache.persistent.numEntries,
gAudioContext.seqCache.persistent.pool.curRamAddr - gAudioCtx.seqCache.persistent.pool.curRamAddr -
gAudioContext.seqCache.persistent.pool.startRamAddr, gAudioCtx.seqCache.persistent.pool.startRamAddr,
gAudioContext.seqCache.persistent.pool.size); gAudioCtx.seqCache.persistent.pool.size);
for (k = 0; (u32)k < gAudioContext.seqCache.persistent.numEntries; k++) { for (k = 0; (u32)k < gAudioCtx.seqCache.persistent.numEntries; k++) {
GfxPrint_SetPos(printer, 3 + 3 * k, 9); GfxPrint_SetPos(printer, 3 + 3 * k, 9);
GfxPrint_Printf(printer, "%02x", gAudioContext.seqCache.persistent.entries[k].id); GfxPrint_Printf(printer, "%02x", gAudioCtx.seqCache.persistent.entries[k].id);
} }
GfxPrint_SetPos(printer, 3, 10); GfxPrint_SetPos(printer, 3, 10);
GfxPrint_Printf(printer, "ST-BNK %02Xbanks (%05X / %06X)", gAudioContext.fontCache.persistent.numEntries, GfxPrint_Printf(printer, "ST-BNK %02Xbanks (%05X / %06X)", gAudioCtx.fontCache.persistent.numEntries,
gAudioContext.fontCache.persistent.pool.curRamAddr - gAudioCtx.fontCache.persistent.pool.curRamAddr -
gAudioContext.fontCache.persistent.pool.startRamAddr, gAudioCtx.fontCache.persistent.pool.startRamAddr,
gAudioContext.fontCache.persistent.pool.size); gAudioCtx.fontCache.persistent.pool.size);
for (k = 0; (u32)k < gAudioContext.fontCache.persistent.numEntries; k++) { for (k = 0; (u32)k < gAudioCtx.fontCache.persistent.numEntries; k++) {
GfxPrint_SetPos(printer, 3 + 3 * k, 11); GfxPrint_SetPos(printer, 3 + 3 * k, 11);
GfxPrint_Printf(printer, "%02x", gAudioContext.fontCache.persistent.entries[k].id); GfxPrint_Printf(printer, "%02x", gAudioCtx.fontCache.persistent.entries[k].id);
} }
GfxPrint_SetPos(printer, 3, 12); GfxPrint_SetPos(printer, 3, 12);
GfxPrint_Printf(printer, "E-MEM %05X / %05X", GfxPrint_Printf(printer, "E-MEM %05X / %05X",
gAudioContext.permanentPool.curRamAddr - gAudioContext.permanentPool.startRamAddr, gAudioCtx.permanentPool.curRamAddr - gAudioCtx.permanentPool.startRamAddr,
gAudioContext.permanentPool.size); gAudioCtx.permanentPool.size);
break; break;
case PAGE_BLOCK_CHANGE_BGM: case PAGE_BLOCK_CHANGE_BGM:
@ -2917,34 +2913,34 @@ void AudioDebug_Draw(GfxPrint* printer) {
SETCOL(255, 255, 255); SETCOL(255, 255, 255);
GfxPrint_SetPos(printer, 3, 7); GfxPrint_SetPos(printer, 3, 7);
GfxPrint_Printf(printer, "NEXT SCENE %02X %s", GfxPrint_Printf(printer, "NEXT SCENE %02X %s",
(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2], (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2],
sAudioSceneNames[(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2]]); sAudioSceneNames[(u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2]]);
GfxPrint_SetPos(printer, 3, 8); GfxPrint_SetPos(printer, 3, 8);
GfxPrint_Printf(printer, "NOW SCENE %02X %s", GfxPrint_Printf(printer, "NOW SCENE %02X %s",
(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4], (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4],
sAudioSceneNames[(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4]]); sAudioSceneNames[(u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4]]);
GfxPrint_SetPos(printer, 3, 9); GfxPrint_SetPos(printer, 3, 9);
GfxPrint_Printf(printer, "NOW BLOCK %02X", GfxPrint_Printf(printer, "NOW BLOCK %02X",
(gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5] + 1) & 0xFF); (gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5] + 1) & 0xFF);
GfxPrint_SetPos(printer, 3, 11); GfxPrint_SetPos(printer, 3, 11);
GfxPrint_Printf(printer, "PORT"); GfxPrint_Printf(printer, "PORT");
GfxPrint_SetPos(printer, 3, 12); GfxPrint_SetPos(printer, 3, 12);
GfxPrint_Printf(printer, "%02X %02X %02X %02X", GfxPrint_Printf(printer, "%02X %02X %02X %02X",
(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[0], (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[0],
(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[1], (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[1],
(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2], (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[2],
(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]); (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]);
GfxPrint_SetPos(printer, 3, 13); GfxPrint_SetPos(printer, 3, 13);
GfxPrint_Printf(printer, "%02X %02X %02X %02X", GfxPrint_Printf(printer, "%02X %02X %02X %02X",
(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4], (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[4],
(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5], (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[5],
(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[6], (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[6],
(u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[7]); (u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[7]);
break; break;
case PAGE_OCARINA_TEST: case PAGE_OCARINA_TEST:
@ -3682,7 +3678,7 @@ void func_800F5CF8(void);
*/ */
void func_800F3054(void) { void func_800F3054(void) {
if (func_800FAD34() == 0) { if (func_800FAD34() == 0) {
sAudioUpdateTaskStart = gAudioContext.totalTaskCount; sAudioUpdateTaskStart = gAudioCtx.totalTaskCount;
sAudioUpdateStartTime = osGetTime(); sAudioUpdateStartTime = osGetTime();
AudioOcarina_Update(); AudioOcarina_Update();
Audio_StepFreqLerp(&sRiverFreqScaleLerp); Audio_StepFreqLerp(&sRiverFreqScaleLerp);
@ -3700,7 +3696,7 @@ void func_800F3054(void) {
AudioDebug_SetInput(); AudioDebug_SetInput();
AudioDebug_ProcessInput(); AudioDebug_ProcessInput();
Audio_ScheduleProcessCmds(); Audio_ScheduleProcessCmds();
sAudioUpdateTaskEnd = gAudioContext.totalTaskCount; sAudioUpdateTaskEnd = gAudioCtx.totalTaskCount;
sAudioUpdateEndTime = osGetTime(); sAudioUpdateEndTime = osGetTime();
} }
} }
@ -3774,9 +3770,9 @@ s8 Audio_ComputeSfxReverb(u8 bankId, u8 entryIdx, u8 channelIdx) {
} }
} }
if (IS_SEQUENCE_CHANNEL_VALID(gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx])) { if (IS_SEQUENCE_CHANNEL_VALID(gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx])) {
scriptAdd = gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1]; scriptAdd = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1];
if (gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1] < 0) { if (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIdx]->soundScriptIO[1] < 0) {
scriptAdd = 0; scriptAdd = 0;
} }
} }
@ -3843,7 +3839,7 @@ f32 Audio_ComputeSfxFreqScale(u8 bankId, u8 entryIdx) {
f32 freq = 1.0f; f32 freq = 1.0f;
if (entry->sfxParams & SFX_FLAG_14) { if (entry->sfxParams & SFX_FLAG_14) {
freq = 1.0f - ((gAudioContext.audioRandom & 0xF) / 192.0f); freq = 1.0f - ((gAudioCtx.audioRandom & 0xF) / 192.0f);
} }
switch (bankId) { switch (bankId) {
@ -3867,7 +3863,7 @@ f32 Audio_ComputeSfxFreqScale(u8 bankId, u8 entryIdx) {
if (phi_v0 == 1) { if (phi_v0 == 1) {
if (!(entry->sfxParams & SFX_FLAG_11)) { if (!(entry->sfxParams & SFX_FLAG_11)) {
freq *= (1.0293 - ((gAudioContext.audioRandom & 0xF) / 144.0f)); freq *= (1.0293 - ((gAudioCtx.audioRandom & 0xF) / 144.0f));
} }
} }
@ -4109,7 +4105,7 @@ void func_800F4010(Vec3f* pos, u16 sfxId, f32 arg2) {
sp24 = 1.0f; sp24 = 1.0f;
} else { } else {
phi_f0 = 1.1f; phi_f0 = 1.1f;
phi_v0 = gAudioContext.audioRandom % 2; phi_v0 = gAudioCtx.audioRandom % 2;
} }
if ((phi_f0 < arg2) && (phi_v0 != 0)) { if ((phi_f0 < arg2) && (phi_v0 != 0)) {
@ -4311,15 +4307,13 @@ s32 Audio_SetGanonsTowerBgmVolume(u8 targetVol) {
// Sets the reverb // Sets the reverb
for (channelIdx = 0; channelIdx < 16; channelIdx++) { for (channelIdx = 0; channelIdx < 16; channelIdx++) {
if (gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx] != if (gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx] != &gAudioCtx.sequenceChannelNone) {
&gAudioContext.sequenceChannelNone) {
// soundScriptIO[5] is set to 0x40 in channels 0, 1, and 4 // soundScriptIO[5] is set to 0x40 in channels 0, 1, and 4
if ((u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] != 0xFF) { if ((u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] != 0xFF) {
// Higher volume leads to lower reverb // Higher volume leads to lower reverb
reverb = reverb = ((u16)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] -
((u16)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIdx]->soundScriptIO[5] - targetVol) +
targetVol) + 0x7F;
0x7F;
if (reverb > 0x7F) { if (reverb > 0x7F) {
reverb = 0x7F; reverb = 0x7F;
} }
@ -4495,7 +4489,7 @@ void Audio_SplitBgmChannels(s8 volSplit) {
channelBits = 0; channelBits = 0;
for (channelIdx = 0; channelIdx < 16; channelIdx++) { for (channelIdx = 0; channelIdx < 16; channelIdx++) {
if (notePriority > gAudioContext.seqPlayers[bgmPlayers[i]].channels[channelIdx]->notePriority) { if (notePriority > gAudioCtx.seqPlayers[bgmPlayers[i]].channels[channelIdx]->notePriority) {
// If the note currently playing in the channel is a high enough priority, // If the note currently playing in the channel is a high enough priority,
// then keep the channel on by setting a channelBit // then keep the channel on by setting a channelBit
// If this condition fails, then the channel will be shut off // If this condition fails, then the channel will be shut off
@ -4601,7 +4595,7 @@ void func_800F56A8(void) {
bvar = temp_v0 & 0xFF; bvar = temp_v0 & 0xFF;
if ((temp_v0 != NA_BGM_DISABLED) && (sSeqFlags[bvar] & SEQ_FLAG_4)) { if ((temp_v0 != NA_BGM_DISABLED) && (sSeqFlags[bvar] & SEQ_FLAG_4)) {
if (D_8013062C != 0xC0) { if (D_8013062C != 0xC0) {
D_8013062C = gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]; D_8013062C = gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3];
} else { } else {
D_8013062C = 0; D_8013062C = 0;
} }

View file

@ -441,7 +441,7 @@ void Audio_PlayActiveSfx(u8 bankId) {
entryIndex = gActiveSfx[bankId][i].entryIndex; entryIndex = gActiveSfx[bankId][i].entryIndex;
if (entryIndex != 0xFF) { if (entryIndex != 0xFF) {
entry = &gSfxBanks[bankId][entryIndex]; entry = &gSfxBanks[bankId][entryIndex];
channel = gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIdx]; channel = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIdx];
if (entry->state == SFX_STATE_READY) { if (entry->state == SFX_STATE_READY) {
entry->channelIdx = sCurSfxPlayerChannelIdx; entry->channelIdx = sCurSfxPlayerChannelIdx;
if (entry->sfxParams & SFX_FLAG_3) { if (entry->sfxParams & SFX_FLAG_3) {
@ -661,7 +661,7 @@ void Audio_StepUnusedBankLerp(u8 bankId) {
void func_800F8F88(void) { void func_800F8F88(void) {
u8 bankId; u8 bankId;
if (IS_SEQUENCE_CHANNEL_VALID(gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[0])) { if (IS_SEQUENCE_CHANNEL_VALID(gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[0])) {
sCurSfxPlayerChannelIdx = 0; sCurSfxPlayerChannelIdx = 0;
for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) { for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) {
Audio_ChooseActiveSfx(bankId); Audio_ChooseActiveSfx(bankId);

View file

@ -45,12 +45,12 @@ void Audio_StartSequence(u8 seqPlayerIndex, u8 seqId, u8 seqArgs, u16 fadeInDura
seqArgs &= 0x7F; seqArgs &= 0x7F;
if (seqArgs == 0x7F) { if (seqArgs == 0x7F) {
// `fadeInDuration` is interpreted as skip ticks // `fadeInDuration` is interpreted as skip ticks
duration = (fadeInDuration >> 3) * 60 * gAudioContext.audioBufferParameters.updatesPerFrame; duration = (fadeInDuration >> 3) * 60 * gAudioCtx.audioBufferParameters.updatesPerFrame;
Audio_QueueCmdS32(0x85000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(seqId, 8, 8), duration); Audio_QueueCmdS32(0x85000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(seqId, 8, 8), duration);
} else { } else {
// `fadeInDuration` is interpreted as number of frames at 30 fps // `fadeInDuration` is interpreted as number of frames at 30 fps
Audio_QueueCmdS32(0x82000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(seqId, 8, 8), Audio_QueueCmdS32(0x82000000 | _SHIFTL(seqPlayerIndex, 16, 8) | _SHIFTL(seqId, 8, 8),
(fadeInDuration * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4); (fadeInDuration * (u16)gAudioCtx.audioBufferParameters.updatesPerFrame) / 4);
} }
gActiveSeqs[seqPlayerIndex].seqId = seqId | (seqArgs << 8); gActiveSeqs[seqPlayerIndex].seqId = seqId | (seqArgs << 8);
@ -78,7 +78,7 @@ void Audio_StartSequence(u8 seqPlayerIndex, u8 seqId, u8 seqArgs, u16 fadeInDura
void Audio_StopSequence(u8 seqPlayerIndex, u16 fadeOutDuration) { void Audio_StopSequence(u8 seqPlayerIndex, u16 fadeOutDuration) {
Audio_QueueCmdS32(0x83000000 | ((u8)seqPlayerIndex << 16), Audio_QueueCmdS32(0x83000000 | ((u8)seqPlayerIndex << 16),
(fadeOutDuration * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4); (fadeOutDuration * (u16)gAudioCtx.audioBufferParameters.updatesPerFrame) / 4);
gActiveSeqs[seqPlayerIndex].seqId = NA_BGM_DISABLED; gActiveSeqs[seqPlayerIndex].seqId = NA_BGM_DISABLED;
} }
@ -408,7 +408,7 @@ void Audio_ProcessSeqCmds(void) {
} }
u16 Audio_GetActiveSeqId(u8 seqPlayerIndex) { u16 Audio_GetActiveSeqId(u8 seqPlayerIndex) {
if (!gAudioContext.seqPlayers[seqPlayerIndex].enabled) { if (!gAudioCtx.seqPlayers[seqPlayerIndex].enabled) {
return NA_BGM_DISABLED; return NA_BGM_DISABLED;
} }
return gActiveSeqs[seqPlayerIndex].seqId; return gActiveSeqs[seqPlayerIndex].seqId;
@ -541,8 +541,8 @@ void Audio_UpdateActiveSequences(void) {
} }
// Process tempo commands // Process tempo commands
if (gAudioContext.seqPlayers[seqPlayerIndex].enabled) { if (gAudioCtx.seqPlayers[seqPlayerIndex].enabled) {
tempoPrev = gAudioContext.seqPlayers[seqPlayerIndex].tempo / TATUMS_PER_BEAT; tempoPrev = gAudioCtx.seqPlayers[seqPlayerIndex].tempo / TATUMS_PER_BEAT;
tempoOp = (tempoCmd & 0xF000) >> 12; tempoOp = (tempoCmd & 0xF000) >> 12;
switch (tempoOp) { switch (tempoOp) {
case SEQCMD_SUB_OP_TEMPO_SPEED_UP: case SEQCMD_SUB_OP_TEMPO_SPEED_UP:
@ -583,7 +583,7 @@ void Audio_UpdateActiveSequences(void) {
} }
gActiveSeqs[seqPlayerIndex].tempoTarget = tempoTarget; gActiveSeqs[seqPlayerIndex].tempoTarget = tempoTarget;
gActiveSeqs[seqPlayerIndex].tempoCur = gAudioContext.seqPlayers[seqPlayerIndex].tempo / TATUMS_PER_BEAT; gActiveSeqs[seqPlayerIndex].tempoCur = gAudioCtx.seqPlayers[seqPlayerIndex].tempo / TATUMS_PER_BEAT;
gActiveSeqs[seqPlayerIndex].tempoStep = gActiveSeqs[seqPlayerIndex].tempoStep =
(gActiveSeqs[seqPlayerIndex].tempoCur - gActiveSeqs[seqPlayerIndex].tempoTarget) / tempoTimer; (gActiveSeqs[seqPlayerIndex].tempoCur - gActiveSeqs[seqPlayerIndex].tempoTarget) / tempoTimer;
gActiveSeqs[seqPlayerIndex].tempoTimer = tempoTimer; gActiveSeqs[seqPlayerIndex].tempoTimer = tempoTimer;
@ -659,7 +659,7 @@ void Audio_UpdateActiveSequences(void) {
// Only process setup commands if `seqPlayerIndex` if no longer playing // Only process setup commands if `seqPlayerIndex` if no longer playing
// i.e. the `seqPlayer` is no longer enabled // i.e. the `seqPlayer` is no longer enabled
if (gAudioContext.seqPlayers[seqPlayerIndex].enabled) { if (gAudioCtx.seqPlayers[seqPlayerIndex].enabled) {
continue; continue;
} }