Rename audio context (#1114)

This commit is contained in:
engineer124 2022-10-13 16:17:27 -04:00 committed by GitHub
parent f3db029936
commit 7204b08498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 756 additions and 778 deletions

View File

@ -1186,7 +1186,7 @@ extern f32 gDefaultPanVolume[];
// extern UNK_TYPE1 D_801D5FD4;
extern UNK_PTR D_801D5FE0;
// extern UNK_TYPE1 D_801D5FE4;
extern s32 gAudioContextInitalized;
extern s32 gAudioCtxInitalized;
// extern UNK_TYPE4 D_801D5FEC;
// extern UNK_TYPE4 D_801D5FF0;
// extern UNK_TYPE4 D_801D5FF4;
@ -3081,7 +3081,7 @@ extern ActiveSequence gActiveSeqs[];
// extern UNK_TYPE1 D_80200BCC;
// extern UNK_TYPE1 D_80200BCE;
// extern UNK_TYPE1 D_80200BD0;
extern AudioContext gAudioContext; // at 0x80200C70
extern AudioContext gAudioCtx; // at 0x80200C70
extern void (*gCustomAudioUpdateFunction)(void);
extern u32 (*gCustomAudioSeqFunction)(s8 value, SequenceChannel* channel);
extern s32 (*gCustomAudioReverbFunction)(Sample*, s32, s8, s32);

View File

@ -7,7 +7,7 @@
#define TATUMS_PER_BEAT 48
#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((uintptr_t)(ptr) != (uintptr_t)&gAudioContext.sequenceChannelNone)
#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((uintptr_t)(ptr) != (uintptr_t)&gAudioCtx.sequenceChannelNone)
#define SEQ_NUM_CHANNELS 16
#define SEQ_IO_VAL_NONE -1

View File

@ -268,7 +268,7 @@ f32 AudioEffects_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

@ -14,7 +14,7 @@ const s16 gAudioTatumInit[] = {
#define SOUNDFONT_2_SIZE 0xCE0
// 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))
// 0x19BD0

File diff suppressed because it is too large Load Diff

View File

@ -35,7 +35,7 @@ void AudioPlayback_InitSampleState(Note* note, NoteSampleState* sampleState, Not
sampleState->bitField0.strongLeft = false;
sampleState->bitField0.strongReverbRight = stereoData.strongReverbRight;
sampleState->bitField0.strongReverbLeft = stereoData.strongReverbLeft;
if (stereoHeadsetEffects && (gAudioContext.soundMode == SOUNDMODE_HEADSET)) {
if (stereoHeadsetEffects && (gAudioCtx.soundMode == SOUNDMODE_HEADSET)) {
halfPanIndex = pan >> 1;
if (halfPanIndex > 0x3F) {
halfPanIndex = 0x3F;
@ -47,7 +47,7 @@ void AudioPlayback_InitSampleState(Note* note, NoteSampleState* sampleState, Not
volLeft = gHeadsetPanVolume[pan];
volRight = gHeadsetPanVolume[0x7F - pan];
} else if (stereoHeadsetEffects && (gAudioContext.soundMode == SOUNDMODE_STEREO)) {
} else if (stereoHeadsetEffects && (gAudioCtx.soundMode == SOUNDMODE_STEREO)) {
strongLeft = strongRight = false;
sampleState->haasEffectLeftDelaySize = 0;
sampleState->haasEffectRightDelaySize = 0;
@ -85,7 +85,7 @@ void AudioPlayback_InitSampleState(Note* note, NoteSampleState* sampleState, Not
break;
}
} else if (gAudioContext.soundMode == SOUNDMODE_MONO) {
} else if (gAudioCtx.soundMode == SOUNDMODE_MONO) {
sampleState->bitField0.strongReverbRight = false;
sampleState->bitField0.strongReverbLeft = false;
volLeft = 0.707f; // approx 1/sqrt(2)
@ -170,9 +170,9 @@ void AudioPlayback_ProcessNotes(void) {
f32 scale;
s32 i;
for (i = 0; i < gAudioContext.numNotes; i++) {
note = &gAudioContext.notes[i];
sampleState = &gAudioContext.sampleStateList[gAudioContext.sampleStateOffset + i];
for (i = 0; i < gAudioCtx.numNotes; i++) {
note = &gAudioCtx.notes[i];
sampleState = &gAudioCtx.sampleStateList[gAudioCtx.sampleStateOffset + i];
playbackState = &note->playbackState;
if (playbackState->parentLayer != NO_LAYER) {
if ((u32)playbackState->parentLayer < 0x7FFFFFFF) {
@ -181,7 +181,7 @@ void AudioPlayback_ProcessNotes(void) {
if ((note != playbackState->parentLayer->note) && (playbackState->status == PLAYBACK_STATUS_0)) {
playbackState->adsr.action.s.release = true;
playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv;
playbackState->adsr.fadeOutVel = gAudioCtx.audioBufferParameters.updatesPerFrameInv;
playbackState->priority = 1;
playbackState->status = PLAYBACK_STATUS_2;
goto out;
@ -316,7 +316,7 @@ void AudioPlayback_ProcessNotes(void) {
}
subAttrs.frequency *= playbackState->vibratoFreqScale * playbackState->portamentoFreqScale;
subAttrs.frequency *= gAudioContext.audioBufferParameters.resampleRate;
subAttrs.frequency *= gAudioCtx.audioBufferParameters.resampleRate;
subAttrs.velocity *= scale;
AudioPlayback_InitSampleState(note, sampleState, &subAttrs);
noteSampleState->bitField1.bookOffset = bookOffset;
@ -347,18 +347,18 @@ Instrument* AudioPlayback_GetInstrumentInner(s32 fontId, s32 instId) {
}
if (!AudioLoad_IsFontLoadComplete(fontId)) {
gAudioContext.audioErrorFlags = AUDIO_ERROR(0, fontId, AUDIO_ERROR_FONT_NOT_LOADED);
gAudioCtx.audioErrorFlags = AUDIO_ERROR(0, fontId, AUDIO_ERROR_FONT_NOT_LOADED);
return NULL;
}
if (instId >= gAudioContext.soundFontList[fontId].numInstruments) {
gAudioContext.audioErrorFlags = AUDIO_ERROR(fontId, instId, AUDIO_ERROR_INVALID_INST_ID);
if (instId >= gAudioCtx.soundFontList[fontId].numInstruments) {
gAudioCtx.audioErrorFlags = AUDIO_ERROR(fontId, instId, AUDIO_ERROR_INVALID_INST_ID);
return NULL;
}
inst = gAudioContext.soundFontList[fontId].instruments[instId];
inst = gAudioCtx.soundFontList[fontId].instruments[instId];
if (inst == NULL) {
gAudioContext.audioErrorFlags = AUDIO_ERROR(fontId, instId, AUDIO_ERROR_NO_INST);
gAudioCtx.audioErrorFlags = AUDIO_ERROR(fontId, instId, AUDIO_ERROR_NO_INST);
return inst;
}
@ -373,21 +373,21 @@ Drum* AudioPlayback_GetDrum(s32 fontId, s32 drumId) {
}
if (!AudioLoad_IsFontLoadComplete(fontId)) {
gAudioContext.audioErrorFlags = AUDIO_ERROR(0, fontId, AUDIO_ERROR_FONT_NOT_LOADED);
gAudioCtx.audioErrorFlags = AUDIO_ERROR(0, fontId, AUDIO_ERROR_FONT_NOT_LOADED);
return NULL;
}
if (drumId >= gAudioContext.soundFontList[fontId].numDrums) {
gAudioContext.audioErrorFlags = AUDIO_ERROR(fontId, drumId, AUDIO_ERROR_INVALID_DRUM_SFX_ID);
if (drumId >= gAudioCtx.soundFontList[fontId].numDrums) {
gAudioCtx.audioErrorFlags = AUDIO_ERROR(fontId, drumId, AUDIO_ERROR_INVALID_DRUM_SFX_ID);
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 = AUDIO_ERROR(fontId, drumId, AUDIO_ERROR_NO_DRUM_SFX);
gAudioCtx.audioErrorFlags = AUDIO_ERROR(fontId, drumId, AUDIO_ERROR_NO_DRUM_SFX);
}
return drum;
@ -401,23 +401,23 @@ SoundEffect* AudioPlayback_GetSoundEffect(s32 fontId, s32 sfxId) {
}
if (!AudioLoad_IsFontLoadComplete(fontId)) {
gAudioContext.audioErrorFlags = AUDIO_ERROR(0, fontId, AUDIO_ERROR_FONT_NOT_LOADED);
gAudioCtx.audioErrorFlags = AUDIO_ERROR(0, fontId, AUDIO_ERROR_FONT_NOT_LOADED);
return NULL;
}
if (sfxId >= gAudioContext.soundFontList[fontId].numSfx) {
gAudioContext.audioErrorFlags = AUDIO_ERROR(fontId, sfxId, AUDIO_ERROR_INVALID_DRUM_SFX_ID);
if (sfxId >= gAudioCtx.soundFontList[fontId].numSfx) {
gAudioCtx.audioErrorFlags = AUDIO_ERROR(fontId, sfxId, AUDIO_ERROR_INVALID_DRUM_SFX_ID);
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 = AUDIO_ERROR(fontId, sfxId, AUDIO_ERROR_NO_DRUM_SFX);
gAudioCtx.audioErrorFlags = AUDIO_ERROR(fontId, sfxId, AUDIO_ERROR_NO_DRUM_SFX);
}
if (soundEffect->tunedSample.sample == NULL) {
@ -438,24 +438,24 @@ s32 AudioPlayback_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, v
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;
}
@ -488,7 +488,7 @@ void AudioPlayback_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;
@ -549,16 +549,16 @@ void AudioPlayback_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.status = PLAYBACK_STATUS_2;
} else {
note->playbackState.status = PLAYBACK_STATUS_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;
@ -665,11 +665,11 @@ void AudioPlayback_InitNoteLists(NotePool* pool) {
void AudioPlayback_InitNoteFreeList(void) {
s32 i;
AudioPlayback_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);
AudioPlayback_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);
}
}
@ -683,22 +683,22 @@ void AudioPlayback_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;
}
@ -729,22 +729,22 @@ void AudioPlayback_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;
}
@ -862,7 +862,7 @@ void AudioPlayback_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;
}
@ -958,9 +958,9 @@ Note* AudioPlayback_AllocNote(SequenceLayer* layer) {
}
if (policy & 8) {
if (!(note = AudioPlayback_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) &&
!(note = AudioPlayback_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) &&
!(note = AudioPlayback_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) {
if (!(note = AudioPlayback_AllocNoteFromDisabled(&gAudioCtx.noteFreeLists, layer)) &&
!(note = AudioPlayback_AllocNoteFromDecaying(&gAudioCtx.noteFreeLists, layer)) &&
!(note = AudioPlayback_AllocNoteFromActive(&gAudioCtx.noteFreeLists, layer))) {
goto null_return;
}
return note;
@ -968,13 +968,13 @@ Note* AudioPlayback_AllocNote(SequenceLayer* layer) {
if (!(note = AudioPlayback_AllocNoteFromDisabled(&layer->channel->notePool, layer)) &&
!(note = AudioPlayback_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) &&
!(note = AudioPlayback_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) &&
!(note = AudioPlayback_AllocNoteFromDisabled(&gAudioCtx.noteFreeLists, layer)) &&
!(note = AudioPlayback_AllocNoteFromDecaying(&layer->channel->notePool, layer)) &&
!(note = AudioPlayback_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) &&
!(note = AudioPlayback_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) &&
!(note = AudioPlayback_AllocNoteFromDecaying(&gAudioCtx.noteFreeLists, layer)) &&
!(note = AudioPlayback_AllocNoteFromActive(&layer->channel->notePool, layer)) &&
!(note = AudioPlayback_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer)) &&
!(note = AudioPlayback_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) {
!(note = AudioPlayback_AllocNoteFromActive(&gAudioCtx.noteFreeLists, layer))) {
goto null_return;
}
return note;
@ -988,8 +988,8 @@ void AudioPlayback_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->sampleState = gZeroedSampleState;
note->playbackState.priority = 0;
note->playbackState.status = PLAYBACK_STATUS_0;
@ -1006,7 +1006,7 @@ void AudioPlayback_NoteInitAll(void) {
note->playbackState.stereoHeadsetEffects = false;
note->playbackState.startSamplePos = 0;
note->synthesisState.synthesisBuffers =
AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, sizeof(NoteSynthesisBuffers));
note->playbackState.attributes.filterBuf = AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, FILTER_SIZE);
AudioHeap_AllocDmaMemory(&gAudioCtx.miscPool, sizeof(NoteSynthesisBuffers));
note->playbackState.attributes.filterBuf = AudioHeap_AllocDmaMemory(&gAudioCtx.miscPool, FILTER_SIZE);
}
}

View File

@ -269,7 +269,7 @@ s32 AudioSeq_HandleScriptFlowControl(SequencePlayer* seqPlayer, SeqScriptState*
void AudioSeq_InitSequenceChannel(SequenceChannel* channel) {
s32 i;
if (channel == &gAudioContext.sequenceChannelNone) {
if (channel == &gAudioCtx.sequenceChannelNone) {
return;
}
@ -330,7 +330,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;
@ -384,7 +384,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 == true)) {
if ((layer->channel != &gAudioCtx.sequenceChannelNone) && (layer->channel->seqPlayer->finished == true)) {
AudioPlayback_SeqLayerNoteRelease(layer);
} else {
AudioPlayback_SeqLayerNoteDecay(layer);
@ -398,7 +398,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;
}
@ -484,10 +484,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 = 1;
} else if (seqPlayer->defaultFont == gAudioContext.fontCache.temporary.entries[1].id) {
gAudioContext.fontCache.temporary.nextSide = 0;
if (seqPlayer->defaultFont == gAudioCtx.fontCache.temporary.entries[0].id) {
gAudioCtx.fontCache.temporary.nextSide = 1;
} else if (seqPlayer->defaultFont == gAudioCtx.fontCache.temporary.entries[1].id) {
gAudioCtx.fontCache.temporary.nextSide = 0;
}
}
@ -520,15 +520,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);
}
}
@ -918,7 +918,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;
}
}
@ -948,12 +948,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) {
@ -980,7 +980,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;
@ -996,7 +996,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;
//! FAKE:
if (1) {}
@ -1011,7 +1011,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;
@ -1090,8 +1090,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;
}
@ -1111,8 +1111,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;
}
@ -1297,9 +1297,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)) {
@ -1426,9 +1426,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)) {
@ -1625,13 +1625,13 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
break;
case 0xB7: // channel: random large
channel->unk_22 = (cmdArgs[0] == 0) ? (gAudioContext.audioRandom & 0xFFFF)
: (gAudioContext.audioRandom % cmdArgs[0]);
channel->unk_22 =
(cmdArgs[0] == 0) ? (gAudioCtx.audioRandom & 0xFFFF) : (gAudioCtx.audioRandom % cmdArgs[0]);
break;
case 0xB8: // channel: random value
scriptState->value = (cmdArgs[0] == 0) ? (gAudioContext.audioRandom & 0xFFFF)
: (gAudioContext.audioRandom % cmdArgs[0]);
scriptState->value =
(cmdArgs[0] == 0) ? (gAudioCtx.audioRandom & 0xFFFF) : (gAudioCtx.audioRandom % cmdArgs[0]);
break;
case 0xA8: // channel: random range large (only cmd that differs from OoT)
@ -1667,8 +1667,8 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
case 0xBE: // channel:
if (cmdArgs[0] < 5) {
if (1) {}
if (gAudioContext.unk_29A8[cmdArgs[0]] != NULL) {
gCustomAudioSeqFunction = gAudioContext.unk_29A8[cmdArgs[0]];
if (gAudioCtx.unk_29A8[cmdArgs[0]] != NULL) {
gCustomAudioSeqFunction = gAudioCtx.unk_29A8[cmdArgs[0]];
scriptState->value = gCustomAudioSeqFunction(scriptState->value, channel);
}
}
@ -1880,17 +1880,17 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
seqPlayer->scriptCounter++;
tempoChange = seqPlayer->tempo + seqPlayer->unk_0C;
if (tempoChange > gAudioContext.tempoInternalToExternal) {
tempoChange = gAudioContext.tempoInternalToExternal;
if (tempoChange > gAudioCtx.tempoInternalToExternal) {
tempoChange = gAudioCtx.tempoInternalToExternal;
}
seqPlayer->tempoAcc += tempoChange;
if (seqPlayer->tempoAcc < gAudioContext.tempoInternalToExternal) {
if (seqPlayer->tempoAcc < gAudioCtx.tempoInternalToExternal) {
return;
}
seqPlayer->tempoAcc -= (u16)gAudioContext.tempoInternalToExternal;
seqPlayer->tempoAcc -= (u16)gAudioCtx.tempoInternalToExternal;
seqPlayer->unk_16++;
if (seqPlayer->stopScript == true) {
@ -1943,8 +1943,8 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
case 0xDD: // seqPlayer: set tempo
seqPlayer->tempo = AudioSeq_ScriptReadU8(seqScript) * TATUMS_PER_BEAT;
if (seqPlayer->tempo > gAudioContext.tempoInternalToExternal) {
seqPlayer->tempo = gAudioContext.tempoInternalToExternal;
if (seqPlayer->tempo > gAudioCtx.tempoInternalToExternal) {
seqPlayer->tempo = gAudioCtx.tempoInternalToExternal;
}
if ((s16)seqPlayer->tempo <= 0) {
@ -2041,9 +2041,9 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
case 0xCE: // seqPlayer: random value
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;
@ -2198,11 +2198,10 @@ void AudioSeq_ProcessSequences(s32 arg0) {
SequencePlayer* seqPlayer;
u32 i;
gAudioContext.sampleStateOffset =
(gAudioContext.audioBufferParameters.updatesPerFrame - arg0 - 1) * gAudioContext.numNotes;
gAudioCtx.sampleStateOffset = (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);
AudioEffects_SequencePlayerProcessSound(seqPlayer);
@ -2250,14 +2249,14 @@ void AudioSeq_ResetSequencePlayer(SequencePlayer* seqPlayer) {
void AudioSeq_InitSequencePlayerChannels(s32 playerIndex) {
SequenceChannel* channel;
SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[playerIndex];
SequencePlayer* seqPlayer = &gAudioCtx.seqPlayers[playerIndex];
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;
@ -2277,7 +2276,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;
@ -2303,12 +2302,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

@ -80,13 +80,13 @@ void AudioSynth_AddReverbBufferEntry(s32 numSamples, s32 updateIndex, s32 reverb
s32 count2;
s32 nextReverbSubBufPos;
reverb = &gAudioContext.synthesisReverbs[reverbIndex];
reverb = &gAudioCtx.synthesisReverbs[reverbIndex];
entry = &reverb->bufEntry[reverb->curFrame][updateIndex];
numSamplesAfterDownsampling = numSamples / gAudioContext.synthesisReverbs[reverbIndex].downsampleRate;
numSamplesAfterDownsampling = numSamples / gAudioCtx.synthesisReverbs[reverbIndex].downsampleRate;
// Apply resampling effect
if (gAudioContext.synthesisReverbs[reverbIndex].resampleEffectOn) {
if (gAudioCtx.synthesisReverbs[reverbIndex].resampleEffectOn) {
if (reverb->downsampleRate == 1) {
count1 = 0;
count2 = 0;
@ -199,10 +199,10 @@ void AudioSynth_SyncSampleStates(s32 updateIndex) {
s32 sampleStateBaseIndex;
s32 i;
sampleStateBaseIndex = gAudioContext.numNotes * updateIndex;
for (i = 0; i < gAudioContext.numNotes; i++) {
noteSampleState = &gAudioContext.notes[i].sampleState;
sampleState = &gAudioContext.sampleStateList[sampleStateBaseIndex + i];
sampleStateBaseIndex = gAudioCtx.numNotes * updateIndex;
for (i = 0; i < gAudioCtx.numNotes; i++) {
noteSampleState = &gAudioCtx.notes[i].sampleState;
sampleState = &gAudioCtx.sampleStateList[sampleStateBaseIndex + i];
if (noteSampleState->bitField0.enabled) {
noteSampleState->bitField0.needsInit = false;
} else {
@ -221,51 +221,51 @@ Acmd* AudioSynth_Update(Acmd* abiCmdStart, s32* numAbiCmds, s16* aiBufStart, s32
s32 reverbIndex;
SynthesisReverb* reverb;
for (reverseUpdateIndex = gAudioContext.audioBufferParameters.updatesPerFrame; reverseUpdateIndex > 0;
for (reverseUpdateIndex = gAudioCtx.audioBufferParameters.updatesPerFrame; reverseUpdateIndex > 0;
reverseUpdateIndex--) {
AudioSeq_ProcessSequences(reverseUpdateIndex - 1);
AudioSynth_SyncSampleStates(gAudioContext.audioBufferParameters.updatesPerFrame - reverseUpdateIndex);
AudioSynth_SyncSampleStates(gAudioCtx.audioBufferParameters.updatesPerFrame - reverseUpdateIndex);
}
curAiBufPos = aiBufStart;
gAudioContext.adpcmCodeBook = NULL;
gAudioCtx.adpcmCodeBook = NULL;
// Process/Update all samples multiple times in a single frame
for (reverseUpdateIndex = gAudioContext.audioBufferParameters.updatesPerFrame; reverseUpdateIndex > 0;
for (reverseUpdateIndex = gAudioCtx.audioBufferParameters.updatesPerFrame; reverseUpdateIndex > 0;
reverseUpdateIndex--) {
if (reverseUpdateIndex == 1) {
// Final Update
numSamplesPerUpdate = numSamplesPerFrame;
} else if ((numSamplesPerFrame / reverseUpdateIndex) >=
gAudioContext.audioBufferParameters.numSamplesPerUpdateMax) {
numSamplesPerUpdate = gAudioContext.audioBufferParameters.numSamplesPerUpdateMax;
gAudioCtx.audioBufferParameters.numSamplesPerUpdateMax) {
numSamplesPerUpdate = gAudioCtx.audioBufferParameters.numSamplesPerUpdateMax;
} else if ((numSamplesPerFrame / reverseUpdateIndex) <=
gAudioContext.audioBufferParameters.numSamplesPerUpdateMin) {
numSamplesPerUpdate = gAudioContext.audioBufferParameters.numSamplesPerUpdateMin;
gAudioCtx.audioBufferParameters.numSamplesPerUpdateMin) {
numSamplesPerUpdate = gAudioCtx.audioBufferParameters.numSamplesPerUpdateMin;
} else {
numSamplesPerUpdate = gAudioContext.audioBufferParameters.numSamplesPerUpdate;
numSamplesPerUpdate = gAudioCtx.audioBufferParameters.numSamplesPerUpdate;
}
for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) {
if (gAudioContext.synthesisReverbs[reverbIndex].useReverb) {
AudioSynth_AddReverbBufferEntry(
numSamplesPerUpdate, gAudioContext.audioBufferParameters.updatesPerFrame - reverseUpdateIndex,
reverbIndex);
for (reverbIndex = 0; reverbIndex < gAudioCtx.numSynthesisReverbs; reverbIndex++) {
if (gAudioCtx.synthesisReverbs[reverbIndex].useReverb) {
AudioSynth_AddReverbBufferEntry(numSamplesPerUpdate,
gAudioCtx.audioBufferParameters.updatesPerFrame - reverseUpdateIndex,
reverbIndex);
}
}
curCmd = AudioSynth_ProcessSamples(curAiBufPos, numSamplesPerUpdate, curCmd,
gAudioContext.audioBufferParameters.updatesPerFrame - reverseUpdateIndex);
gAudioCtx.audioBufferParameters.updatesPerFrame - reverseUpdateIndex);
numSamplesPerFrame -= numSamplesPerUpdate;
curAiBufPos += numSamplesPerUpdate * SAMPLE_SIZE;
}
// Update reverb frame info
for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) {
if (gAudioContext.synthesisReverbs[reverbIndex].framesToIgnore != 0) {
gAudioContext.synthesisReverbs[reverbIndex].framesToIgnore--;
for (reverbIndex = 0; reverbIndex < gAudioCtx.numSynthesisReverbs; reverbIndex++) {
if (gAudioCtx.synthesisReverbs[reverbIndex].framesToIgnore != 0) {
gAudioCtx.synthesisReverbs[reverbIndex].framesToIgnore--;
}
gAudioContext.synthesisReverbs[reverbIndex].curFrame ^= 1;
gAudioCtx.synthesisReverbs[reverbIndex].curFrame ^= 1;
}
*numAbiCmds = curCmd - abiCmdStart;
@ -276,8 +276,8 @@ void AudioSynth_DisableSampleStates(s32 updateIndex, s32 noteIndex) {
NoteSampleState* sampleState;
s32 i;
for (i = updateIndex + 1; i < gAudioContext.audioBufferParameters.updatesPerFrame; i++) {
sampleState = &gAudioContext.sampleStateList[(gAudioContext.numNotes * i) + noteIndex];
for (i = updateIndex + 1; i < gAudioCtx.audioBufferParameters.updatesPerFrame; i++) {
sampleState = &gAudioCtx.sampleStateList[(gAudioCtx.numNotes * i) + noteIndex];
if (sampleState->bitField0.needsInit) {
break;
}
@ -572,11 +572,11 @@ Acmd* AudioSynth_FilterReverb(Acmd* cmd, s32 size, SynthesisReverb* reverb) {
Acmd* AudioSynth_MixOtherReverbIndex(Acmd* cmd, SynthesisReverb* reverb, s32 updateIndex) {
SynthesisReverb* mixReverb;
if (reverb->mixReverbIndex >= gAudioContext.numSynthesisReverbs) {
if (reverb->mixReverbIndex >= gAudioCtx.numSynthesisReverbs) {
return cmd;
}
mixReverb = &gAudioContext.synthesisReverbs[reverb->mixReverbIndex];
mixReverb = &gAudioCtx.synthesisReverbs[reverb->mixReverbIndex];
if (mixReverb->downsampleRate == 1) {
cmd = AudioSynth_LoadMixedReverbSamples(cmd, mixReverb, updateIndex);
aMix(cmd++, DMEM_2CH_SIZE >> 4, reverb->mixReverbStrength, DMEM_WET_LEFT_CH, DMEM_WET_TEMP);
@ -758,31 +758,31 @@ Acmd* AudioSynth_ProcessSamples(s16* aiBuf, s32 numSamplesPerUpdate, Acmd* cmd,
s16 reverbIndex;
SynthesisReverb* reverb;
s32 useReverb;
s32 sampleStateOffset = gAudioContext.numNotes * updateIndex;
s32 sampleStateOffset = gAudioCtx.numNotes * updateIndex;
s32 i;
if (gAudioContext.numSynthesisReverbs == 0) {
for (i = 0; i < gAudioContext.numNotes; i++) {
if (gAudioContext.sampleStateList[sampleStateOffset + i].bitField0.enabled) {
if (gAudioCtx.numSynthesisReverbs == 0) {
for (i = 0; i < gAudioCtx.numNotes; i++) {
if (gAudioCtx.sampleStateList[sampleStateOffset + i].bitField0.enabled) {
noteIndices[noteCount++] = i;
}
}
} else {
NoteSampleState* sampleState;
for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) {
for (i = 0; i < gAudioContext.numNotes; i++) {
sampleState = &gAudioContext.sampleStateList[sampleStateOffset + i];
for (reverbIndex = 0; reverbIndex < gAudioCtx.numSynthesisReverbs; reverbIndex++) {
for (i = 0; i < gAudioCtx.numNotes; i++) {
sampleState = &gAudioCtx.sampleStateList[sampleStateOffset + i];
if (sampleState->bitField0.enabled && (sampleState->bitField1.reverbIndex == reverbIndex)) {
noteIndices[noteCount++] = i;
}
}
}
for (i = 0; i < gAudioContext.numNotes; i++) {
sampleState = &gAudioContext.sampleStateList[sampleStateOffset + i];
for (i = 0; i < gAudioCtx.numNotes; i++) {
sampleState = &gAudioCtx.sampleStateList[sampleStateOffset + i];
if (sampleState->bitField0.enabled &&
(sampleState->bitField1.reverbIndex >= gAudioContext.numSynthesisReverbs)) {
(sampleState->bitField1.reverbIndex >= gAudioCtx.numSynthesisReverbs)) {
noteIndices[noteCount++] = i;
}
}
@ -791,11 +791,11 @@ Acmd* AudioSynth_ProcessSamples(s16* aiBuf, s32 numSamplesPerUpdate, Acmd* cmd,
aClearBuffer(cmd++, DMEM_LEFT_CH, DMEM_2CH_SIZE);
i = 0;
for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) {
for (reverbIndex = 0; reverbIndex < gAudioCtx.numSynthesisReverbs; reverbIndex++) {
s32 subDelay;
NoteSampleState* sampleState;
reverb = &gAudioContext.synthesisReverbs[reverbIndex];
reverb = &gAudioCtx.synthesisReverbs[reverbIndex];
useReverb = reverb->useReverb;
if (useReverb) {
@ -815,7 +815,7 @@ Acmd* AudioSynth_ProcessSamples(s16* aiBuf, s32 numSamplesPerUpdate, Acmd* cmd,
// Decays reverb over time. The (+ 0x8000) here is -100%
aMix(cmd++, DMEM_2CH_SIZE >> 4, reverb->decayRatio + 0x8000, DMEM_WET_LEFT_CH, DMEM_WET_LEFT_CH);
if (((reverb->leakRtl != 0) || (reverb->leakLtr != 0)) && (gAudioContext.soundMode != SOUNDMODE_MONO)) {
if (((reverb->leakRtl != 0) || (reverb->leakLtr != 0)) && (gAudioCtx.soundMode != SOUNDMODE_MONO)) {
cmd = AudioSynth_LeakReverb(cmd, reverb);
}
@ -830,13 +830,12 @@ Acmd* AudioSynth_ProcessSamples(s16* aiBuf, s32 numSamplesPerUpdate, Acmd* cmd,
}
while (i < noteCount) {
sampleState = &gAudioContext.sampleStateList[sampleStateOffset + noteIndices[i]];
sampleState = &gAudioCtx.sampleStateList[sampleStateOffset + noteIndices[i]];
if (sampleState->bitField1.reverbIndex != reverbIndex) {
break;
}
cmd = AudioSynth_ProcessSample(noteIndices[i], sampleState,
&gAudioContext.notes[noteIndices[i]].synthesisState, aiBuf,
numSamplesPerUpdate, cmd, updateIndex);
cmd = AudioSynth_ProcessSample(noteIndices[i], sampleState, &gAudioCtx.notes[noteIndices[i]].synthesisState,
aiBuf, numSamplesPerUpdate, cmd, updateIndex);
i++;
}
@ -858,9 +857,9 @@ Acmd* AudioSynth_ProcessSamples(s16* aiBuf, s32 numSamplesPerUpdate, Acmd* cmd,
}
while (i < noteCount) {
cmd = AudioSynth_ProcessSample(
noteIndices[i], &gAudioContext.sampleStateList[sampleStateOffset + noteIndices[i]],
&gAudioContext.notes[noteIndices[i]].synthesisState, aiBuf, numSamplesPerUpdate, cmd, updateIndex);
cmd = AudioSynth_ProcessSample(noteIndices[i], &gAudioCtx.sampleStateList[sampleStateOffset + noteIndices[i]],
&gAudioCtx.notes[noteIndices[i]].synthesisState, aiBuf, numSamplesPerUpdate, cmd,
updateIndex);
i++;
}
@ -928,7 +927,7 @@ Acmd* AudioSynth_ProcessSample(s32 noteIndex, NoteSampleState* sampleState, Note
s32 sampleDataChunkSize;
s16 sampleDataDmemAddr;
note = &gAudioContext.notes[noteIndex];
note = &gAudioCtx.notes[noteIndex];
flags = A_CONTINUE;
// Initialize the synthesis state
@ -1013,23 +1012,23 @@ Acmd* AudioSynth_ProcessSample(s32 noteIndex, NoteSampleState* sampleState, Note
// Load the ADPCM codeBook
if ((sample->codec == CODEC_ADPCM) || (sample->codec == CODEC_SMALL_ADPCM)) {
if (gAudioContext.adpcmCodeBook != sample->book->codeBook) {
if (gAudioCtx.adpcmCodeBook != sample->book->codeBook) {
u32 numEntries;
switch (bookOffset) {
case 1:
gAudioContext.adpcmCodeBook = &gInvalidAdpcmCodeBook[1];
gAudioCtx.adpcmCodeBook = &gInvalidAdpcmCodeBook[1];
break;
case 2:
case 3:
default:
gAudioContext.adpcmCodeBook = sample->book->codeBook;
gAudioCtx.adpcmCodeBook = sample->book->codeBook;
break;
}
numEntries = SAMPLES_PER_FRAME * sample->book->order * sample->book->numPredictors;
aLoadADPCM(cmd++, numEntries, gAudioContext.adpcmCodeBook);
aLoadADPCM(cmd++, numEntries, gAudioCtx.adpcmCodeBook);
}
}
@ -1163,7 +1162,7 @@ Acmd* AudioSynth_ProcessSample(s32 noteIndex, NoteSampleState* sampleState, Note
if (sample->medium == MEDIUM_RAM) {
// Sample is already loaded into ram
samplesToLoadAddr = sampleAddr + (zeroOffset + sampleAddrOffset);
} else if (gAudioContext.unk_29B8) { // always false
} else if (gAudioCtx.unk_29B8) { // always false
return cmd;
} else if (sample->medium == MEDIUM_UNK) {
// This medium is unsupported so terminate processing this note
@ -1405,7 +1404,7 @@ Acmd* AudioSynth_ProcessSample(s32 noteIndex, NoteSampleState* sampleState, Note
}
// Apply an unknown effect based on the surround sound-mode
if (gAudioContext.soundMode == SOUNDMODE_SURROUND) {
if (gAudioCtx.soundMode == SOUNDMODE_SURROUND) {
sampleState->targetVolLeft = sampleState->targetVolLeft >> 1;
sampleState->targetVolRight = sampleState->targetVolRight >> 1;
if (sampleState->surroundEffectIndex != 0xFF) {
@ -1512,7 +1511,7 @@ Acmd* AudioSynth_ProcessEnvelope(Acmd* cmd, NoteSampleState* sampleState, NoteSy
targetVolRight = sampleState->targetVolRight;
targetVolRight <<= 4;
if ((gAudioContext.soundMode == SOUNDMODE_SURROUND) && (sampleState->surroundEffectIndex != 0xFF)) {
if ((gAudioCtx.soundMode == SOUNDMODE_SURROUND) && (sampleState->surroundEffectIndex != 0xFF)) {
defaultPanVolume = gDefaultPanVolume[sampleState->surroundEffectIndex];
targetVolLeft *= defaultPanVolume;
targetVolRight *= defaultPanVolume;

View File

@ -3311,7 +3311,7 @@ s32 AudioOcarina_MemoryGameNextNote(void) {
#undef OCARINA_SONG_MEMORY_GAME
void AudioOcarina_Update(void) {
sOcarinaUpdateTaskStart = gAudioContext.totalTaskCount;
sOcarinaUpdateTaskStart = gAudioCtx.totalTaskCount;
if (sOcarinaInstrumentId != OCARINA_INSTRUMENT_OFF) {
if (sIsOcarinaInputEnabled == true) {
AudioOcarina_ReadControllerInput();
@ -3399,9 +3399,9 @@ u8 sRequestCustomSequence = false;
void AudioOcarina_SetCustomSequence(void) {
// Never passes true as sRequestCustomSequence is never set true
if (sRequestCustomSequence && gAudioContext.seqPlayers[SEQ_PLAYER_FANFARE].enabled &&
((u8)gAudioContext.seqPlayers[SEQ_PLAYER_FANFARE].soundScriptIO[0] == (u8)SEQ_IO_VAL_NONE)) {
gAudioContext.seqPlayers[SEQ_PLAYER_FANFARE].seqData = sCustomSequenceScript;
if (sRequestCustomSequence && gAudioCtx.seqPlayers[SEQ_PLAYER_FANFARE].enabled &&
((u8)gAudioCtx.seqPlayers[SEQ_PLAYER_FANFARE].soundScriptIO[0] == (u8)SEQ_IO_VAL_NONE)) {
gAudioCtx.seqPlayers[SEQ_PLAYER_FANFARE].seqData = sCustomSequenceScript;
sRequestCustomSequence = false;
}
}
@ -3753,9 +3753,9 @@ s8 AudioSfx_ComputeReverb(u8 bankId, u8 entryIndex, u8 channelIndex) {
}
}
if (IS_SEQUENCE_CHANNEL_VALID(gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[channelIndex])) {
scriptAdd = gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[1];
if (gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[1] <= SEQ_IO_VAL_NONE) {
if (IS_SEQUENCE_CHANNEL_VALID(gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIndex])) {
scriptAdd = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[1];
if (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[1] <= SEQ_IO_VAL_NONE) {
scriptAdd = 0;
}
}
@ -3815,7 +3815,7 @@ f32 AudioSfx_ComputeFreqScale(u8 bankId, u8 entryIndex) {
f32 freq = 1.0f;
if (entry->sfxParams & SFX_PARAM_RAND_FREQ_LOWER) {
freq = 1.0f - ((gAudioContext.audioRandom & 0xF) / 192.0f);
freq = 1.0f - ((gAudioCtx.audioRandom & 0xF) / 192.0f);
}
switch (bankId) {
@ -3850,7 +3850,7 @@ f32 AudioSfx_ComputeFreqScale(u8 bankId, u8 entryIndex) {
}
if ((applyRandScaling == true) && !(entry->sfxParams & SFX_PARAM_RAND_FREQ_SCALE)) {
freq *= 1.0293 - ((gAudioContext.audioRandom & 0xF) / 144.0f);
freq *= 1.0293 - ((gAudioCtx.audioRandom & 0xF) / 144.0f);
}
dist = entry->dist;
@ -4356,18 +4356,16 @@ s32 Audio_SetGanonsTowerBgmVolume(u8 targetVolume) {
(u8)(lowPassFilterCutoff));
// Sets the reverb
for (channelIndex = 0; channelIndex < ARRAY_COUNT(gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels);
for (channelIndex = 0; channelIndex < ARRAY_COUNT(gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels);
channelIndex++) {
if (&gAudioContext.sequenceChannelNone !=
gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]) {
if (&gAudioCtx.sequenceChannelNone != gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]) {
// soundScriptIO[5] was set to 0x40 in channels 0, 1, and 4 (BGM no longer in OoT)
if ((u8)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]->soundScriptIO[5] !=
if ((u8)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]->soundScriptIO[5] !=
(u8)SEQ_IO_VAL_NONE) {
// Higher volume leads to lower reverb
reverb =
(((u16)gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]->soundScriptIO[5] -
targetVolume) +
0x7F);
reverb = (((u16)gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].channels[channelIndex]->soundScriptIO[5] -
targetVolume) +
0x7F);
if (reverb > 0x7F) {
reverb = 0x7F;
@ -4556,7 +4554,7 @@ void Audio_SplitBgmChannels(s8 volumeSplit) {
channelBits = 0;
for (channelIndex = 0; channelIndex < SEQ_NUM_CHANNELS; channelIndex++) {
if (gAudioContext.seqPlayers[sBgmPlayers[i]].channels[channelIndex]->notePriority < notePriority) {
if (gAudioCtx.seqPlayers[sBgmPlayers[i]].channels[channelIndex]->notePriority < 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
@ -4723,7 +4721,7 @@ void Audio_UpdateSceneSequenceResumePoint(void) {
if ((seqId != NA_BGM_DISABLED) && (sSeqFlags[seqId & 0xFF & 0xFF] & SEQ_FLAG_RESUME)) {
if (sSeqResumePoint != SEQ_RESUME_POINT_NONE) {
// Get the current point to resume from
sSeqResumePoint = gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3];
sSeqResumePoint = gAudioCtx.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3];
} else {
// Initialize the point to resume from to the start of the sequence
sSeqResumePoint = 0;
@ -5139,13 +5137,13 @@ void Audio_PlayAmbience(u8 ambienceId) {
u32 Audio_SetAmbienceRandomBend(u8 seqScriptValIn, SequenceChannel* channel) {
u32 seqScriptValOut = seqScriptValIn;
gAudioContext.seqPlayers[SEQ_PLAYER_AMBIENCE].applyBend = true;
gAudioCtx.seqPlayers[SEQ_PLAYER_AMBIENCE].applyBend = true;
if ((seqScriptValIn == 0) || (seqScriptValIn == 0xFF)) {
gAudioContext.seqPlayers[SEQ_PLAYER_AMBIENCE].bend = 1.0f;
gAudioCtx.seqPlayers[SEQ_PLAYER_AMBIENCE].bend = 1.0f;
} else {
seqScriptValOut = AudioThread_NextRandom();
gAudioContext.seqPlayers[SEQ_PLAYER_AMBIENCE].bend = 1.0293 - ((gAudioContext.audioRandom & 0xF) / 144.0f);
gAudioCtx.seqPlayers[SEQ_PLAYER_AMBIENCE].bend = 1.0293 - ((gAudioCtx.audioRandom & 0xF) / 144.0f);
return seqScriptValOut;
}

View File

@ -599,7 +599,7 @@ void AudioSfx_PlayActiveSfx(u8 bankId) {
// If entry is not empty
if (entryIndex != 0xFF) {
entry = &gSfxBanks[bankId][entryIndex];
channel = gAudioContext.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIndex];
channel = gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].channels[sCurSfxPlayerChannelIndex];
if (entry->state == SFX_STATE_READY) {
// Initialize a sfx (new sfx request)
@ -847,7 +847,7 @@ void AudioSfx_StopById(u32 sfxId) {
}
void AudioSfx_ProcessRequests(void) {
if (gAudioContext.seqPlayers[SEQ_PLAYER_SFX].enabled) {
if (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].enabled) {
while (sSfxRequestWriteIndex != sSfxRequestReadIndex) {
AudioSfx_ProcessRequest();
sSfxRequestReadIndex++;
@ -886,7 +886,7 @@ void AudioSfx_StepBankLerp(u8 bankId) {
void AudioSfx_ProcessActiveSfx(void) {
u8 bankId;
if (gAudioContext.seqPlayers[SEQ_PLAYER_SFX].enabled) {
if (gAudioCtx.seqPlayers[SEQ_PLAYER_SFX].enabled) {
sCurSfxPlayerChannelIndex = 0;
for (bankId = 0; bankId < ARRAY_COUNT(gSfxBanks); bankId++) {

View File

@ -2249,7 +2249,7 @@
0x801D5FD4:("D_801D5FD4","UNK_TYPE1","",0x1),
0x801D5FE0:("D_801D5FE0","UNK_PTR","",0x4),
0x801D5FE4:("D_801D5FE4","UNK_TYPE1","",0x1),
0x801D5FE8:("gAudioContextInitalized","UNK_TYPE4","",0x4),
0x801D5FE8:("gAudioCtxInitalized","UNK_TYPE4","",0x4),
0x801D5FEC:("D_801D5FEC","UNK_TYPE4","",0x4),
0x801D5FF0:("D_801D5FF0","UNK_TYPE4","",0x4),
0x801D5FF4:("D_801D5FF4","UNK_TYPE4","",0x4),
@ -4353,7 +4353,7 @@
0x80200BCC:("D_80200BCC","UNK_TYPE1","",0x1),
0x80200BCE:("D_80200BCE","UNK_TYPE1","",0x1),
0x80200BD0:("D_80200BD0","UNK_TYPE1","",0x1),
0x80200C70:("gAudioContext","AudioContext","",0x81F8),
0x80200C70:("gAudioCtx","AudioContext","",0x81F8),
0x80208E68:("gCustomAudioUpdateFunction","UNK_TYPE4","",0x4),
0x80208E6C:("gCustomAudioSeqFunction","UNK_TYPE4","",0x4),
0x80208E70:("gCustomAudioReverbFunction","UNK_TYPE4","",0x4),