1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-27 07:07:09 +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 u8 gAudioSfxSwapMode[10];
extern ActiveSequence gActiveSeqs[4];
extern AudioContext gAudioContext;
extern AudioContext gAudioCtx;
extern void(*D_801755D0)(void);
extern u32 __osMalloc_FreeBlockTest_Enable;

View file

@ -7,7 +7,7 @@
#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 MAX_CHANNELS_PER_BANK 3

View file

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

File diff suppressed because it is too large Load diff

View file

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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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