1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-04 15:04:31 +00:00

Document parts of audio (#1000)

* Minor labelling

* progress

* play percentage -> delay

* duration -> gatetime

* more

* more

* more

* seqIdx -> playerIdx

* more

* more

* more

* more

* format

* fix comment

* filters

* more

* media

* confusion

* Sync load is actually slow load

* AudioHeap prefix

* more

* more

* reformat

* more

* more

* AudioLoad

* more

* more

* seq banks

* more consistent

* more

* name last function in audio_load

* More audio_synthesis

* clean up audio tables

* minor

* slow/fast load ramAddr

* format

* remove unused

* Remove union

* remove padding

* audio bank -> sound font

* seqLayer -> layer

* stuff

* seqChannel -> channel

* ChannelLayer -> Layer

* remove define, add bug comment

* format

* more

* cache enum

* more

* AudioSeq function prefix

* naming

* bankIdx -> bankId

* more

* format

* review

* more

* fixes

* avoid hardcoded sfxid's

* SE -> Sfx

Co-authored-by: zelda2774 <zelda2774@invalid>
This commit is contained in:
zelda2774 2021-11-07 17:58:50 +01:00 committed by GitHub
parent 823a3c0754
commit 5ad7cf9dbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 3493 additions and 3508 deletions

View file

@ -55,9 +55,9 @@ void AudioMgr_ThreadEntry(void* arg0) {
s16* msg = NULL;
osSyncPrintf("オーディオマネージャスレッド実行開始\n"); // "Start running audio manager thread"
func_800F70F8();
func_800E301C(DmaMgr_DmaCallback0);
func_800F711C();
Audio_Init();
AudioLoad_SetDmaHandler(DmaMgr_DmaHandler);
Audio_InitSound();
osSendMesg(&audioMgr->unk_C8, NULL, OS_MESG_BLOCK);
IrqMgr_AddClient(audioMgr->irqMgr, &irqClient, &audioMgr->unk_74);

View file

@ -1,51 +1,51 @@
#include "ultra64.h"
#include "global.h"
void Audio_SequenceChannelProcessSound(SequenceChannel* seqChannel, s32 recalculateVolume, s32 b) {
void Audio_SequenceChannelProcessSound(SequenceChannel* channel, s32 recalculateVolume, s32 b) {
f32 channelVolume;
f32 chanFreqScale;
s32 i;
if (seqChannel->changes.s.volume || recalculateVolume) {
channelVolume = seqChannel->volume * seqChannel->volumeScale * seqChannel->seqPlayer->appliedFadeVolume;
if (seqChannel->seqPlayer->muted && (seqChannel->muteBehavior & 0x20)) {
channelVolume = seqChannel->seqPlayer->muteVolumeScale * channelVolume;
if (channel->changes.s.volume || recalculateVolume) {
channelVolume = channel->volume * channel->volumeScale * channel->seqPlayer->appliedFadeVolume;
if (channel->seqPlayer->muted && (channel->muteBehavior & 0x20)) {
channelVolume = channel->seqPlayer->muteVolumeScale * channelVolume;
}
seqChannel->appliedVolume = channelVolume * channelVolume;
channel->appliedVolume = channelVolume * channelVolume;
}
if (seqChannel->changes.s.pan) {
seqChannel->pan = seqChannel->newPan * seqChannel->panChannelWeight;
if (channel->changes.s.pan) {
channel->pan = channel->newPan * channel->panChannelWeight;
}
chanFreqScale = seqChannel->freqScale;
chanFreqScale = channel->freqScale;
if (b != 0) {
chanFreqScale *= seqChannel->seqPlayer->unk_34;
seqChannel->changes.s.freqScale = true;
chanFreqScale *= channel->seqPlayer->unk_34;
channel->changes.s.freqScale = true;
}
for (i = 0; i < 4; i++) {
SequenceChannelLayer* layer = seqChannel->layers[i];
SequenceLayer* layer = channel->layers[i];
if (layer != NULL && layer->enabled && layer->note != NULL) {
if (layer->notePropertiesNeedInit) {
layer->noteFreqScale = layer->freqScale * chanFreqScale;
layer->noteVelocity = layer->velocitySquare2 * seqChannel->appliedVolume;
layer->notePan = (seqChannel->pan + layer->pan * (0x80 - seqChannel->panChannelWeight)) >> 7;
layer->noteVelocity = layer->velocitySquare2 * channel->appliedVolume;
layer->notePan = (channel->pan + layer->pan * (0x80 - channel->panChannelWeight)) >> 7;
layer->notePropertiesNeedInit = false;
} else {
if (seqChannel->changes.s.freqScale) {
if (channel->changes.s.freqScale) {
layer->noteFreqScale = layer->freqScale * chanFreqScale;
}
if (seqChannel->changes.s.volume || recalculateVolume) {
layer->noteVelocity = layer->velocitySquare2 * seqChannel->appliedVolume;
if (channel->changes.s.volume || recalculateVolume) {
layer->noteVelocity = layer->velocitySquare2 * channel->appliedVolume;
}
if (seqChannel->changes.s.pan) {
layer->notePan = (seqChannel->pan + layer->pan * (0x80 - seqChannel->panChannelWeight)) >> 7;
if (channel->changes.s.pan) {
layer->notePan = (channel->pan + layer->pan * (0x80 - channel->panChannelWeight)) >> 7;
}
}
}
}
seqChannel->changes.asByte = 0;
channel->changes.asByte = 0;
}
void Audio_SequencePlayerProcessSound(SequencePlayer* seqPlayer) {
@ -63,7 +63,7 @@ void Audio_SequencePlayerProcessSound(SequencePlayer* seqPlayer) {
}
if (--seqPlayer->fadeTimer == 0 && seqPlayer->state == 2) {
Audio_SequencePlayerDisable(seqPlayer);
AudioSeq_SequencePlayerDisable(seqPlayer);
return;
}
}
@ -112,14 +112,16 @@ f32 Audio_GetVibratoFreqScale(VibratoState* vib) {
f32 temp;
f32 twoToThe16th = 65536.0f;
s32 one = 1;
SequenceChannel* channel = vib->seqChannel;
SequenceChannel* channel = vib->channel;
if (vib->delay != 0) {
vib->delay--;
return 1;
}
if (channel != NO_CHANNEL) {
//! @bug this probably meant to compare with gAudioContext.sequenceChannelNone.
//! -1 isn't used as a channel pointer anywhere else.
if (channel != ((SequenceChannel*)(-1))) {
if (vib->extentChangeTimer) {
if (vib->extentChangeTimer == 1) {
vib->extent = (s32)channel->vibratoExtentTarget;
@ -179,7 +181,7 @@ void Audio_NoteVibratoUpdate(Note* note) {
void Audio_NoteVibratoInit(Note* note) {
VibratoState* vib;
SequenceChannel* seqChannel;
SequenceChannel* channel;
note->playbackState.vibratoFreqScale = 1.0f;
@ -189,20 +191,20 @@ void Audio_NoteVibratoInit(Note* note) {
vib->time = 0;
vib->curve = gWaveSamples[2];
vib->seqChannel = note->playbackState.parentLayer->seqChannel;
seqChannel = vib->seqChannel;
if ((vib->extentChangeTimer = seqChannel->vibratoExtentChangeDelay) == 0) {
vib->extent = (s32)seqChannel->vibratoExtentTarget;
vib->channel = note->playbackState.parentLayer->channel;
channel = vib->channel;
if ((vib->extentChangeTimer = channel->vibratoExtentChangeDelay) == 0) {
vib->extent = (s32)channel->vibratoExtentTarget;
} else {
vib->extent = (s32)seqChannel->vibratoExtentStart;
vib->extent = (s32)channel->vibratoExtentStart;
}
if ((vib->rateChangeTimer = seqChannel->vibratoRateChangeDelay) == 0) {
vib->rate = (s32)seqChannel->vibratoRateTarget;
if ((vib->rateChangeTimer = channel->vibratoRateChangeDelay) == 0) {
vib->rate = (s32)channel->vibratoRateTarget;
} else {
vib->rate = (s32)seqChannel->vibratoRateStart;
vib->rate = (s32)channel->vibratoRateStart;
}
vib->delay = seqChannel->vibratoDelay;
vib->delay = channel->vibratoDelay;
}
void Audio_NotePortamentoInit(Note* note) {

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
#include "global.h"
const s16 D_8014A6C0[] = {
0x1C00,
0x0030,
0x1C00, // unused
0x0030, // gTatumsPerBeat
};
const AudioContextInitSizes D_8014A6C4 = { 0x37F00, 0xE0E0, 0xBCE0 };

File diff suppressed because it is too large Load diff

View file

@ -17,8 +17,8 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
reverbVol = attrs->reverbVol;
sp24 = attrs->stereo.s;
sub->bitField0.s = note->noteSubEu.bitField0.s;
sub->bitField1.s = note->noteSubEu.bitField1.s;
sub->bitField0 = note->noteSubEu.bitField0;
sub->bitField1 = note->noteSubEu.bitField1;
sub->sound.samples = note->noteSubEu.sound.samples;
sub->unk_06 = note->noteSubEu.unk_06;
@ -26,10 +26,10 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
pan &= 0x7F;
sub->bitField0.s.stereoStrongRight = false;
sub->bitField0.s.stereoStrongLeft = false;
sub->bitField0.s.stereoHeadsetEffects = sp24.stereoHeadsetEffects;
sub->bitField0.s.usesHeadsetPanEffects = sp24.usesHeadsetPanEffects;
sub->bitField0.stereoStrongRight = false;
sub->bitField0.stereoStrongLeft = false;
sub->bitField0.stereoHeadsetEffects = sp24.stereoHeadsetEffects;
sub->bitField0.usesHeadsetPanEffects = sp24.usesHeadsetPanEffects;
if (stereoHeadsetEffects && gAudioContext.soundMode == 1) {
smallPanIndex = pan >> 1;
if (smallPanIndex > 0x3F) {
@ -38,7 +38,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
sub->headsetPanLeft = gHeadsetPanQuantization[smallPanIndex];
sub->headsetPanRight = gHeadsetPanQuantization[0x3F - smallPanIndex];
sub->bitField1.s.usesHeadsetPanEffects2 = true;
sub->bitField1.usesHeadsetPanEffects2 = true;
volLeft = gHeadsetPanVolume[pan];
volRight = gHeadsetPanVolume[0x7F - pan];
@ -46,7 +46,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
strongLeft = strongRight = 0;
sub->headsetPanRight = 0;
sub->headsetPanLeft = 0;
sub->bitField1.s.usesHeadsetPanEffects2 = false;
sub->bitField1.usesHeadsetPanEffects2 = false;
volLeft = gStereoPanVolume[pan];
volRight = gStereoPanVolume[0x7F - pan];
@ -56,34 +56,34 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
strongRight = 1;
}
sub->bitField0.s.stereoStrongRight = strongRight;
sub->bitField0.s.stereoStrongLeft = strongLeft;
sub->bitField0.stereoStrongRight = strongRight;
sub->bitField0.stereoStrongLeft = strongLeft;
switch (sp24.bit2) {
case 0:
break;
case 1:
sub->bitField0.s.stereoStrongRight = sp24.strongRight;
sub->bitField0.s.stereoStrongLeft = sp24.strongLeft;
sub->bitField0.stereoStrongRight = sp24.strongRight;
sub->bitField0.stereoStrongLeft = sp24.strongLeft;
break;
case 2:
sub->bitField0.s.stereoStrongRight = sp24.strongRight | strongRight;
sub->bitField0.s.stereoStrongLeft = sp24.strongLeft | strongLeft;
sub->bitField0.stereoStrongRight = sp24.strongRight | strongRight;
sub->bitField0.stereoStrongLeft = sp24.strongLeft | strongLeft;
break;
case 3:
sub->bitField0.s.stereoStrongRight = sp24.strongRight ^ strongRight;
sub->bitField0.s.stereoStrongLeft = sp24.strongLeft ^ strongLeft;
sub->bitField0.stereoStrongRight = sp24.strongRight ^ strongRight;
sub->bitField0.stereoStrongLeft = sp24.strongLeft ^ strongLeft;
break;
}
} else if (gAudioContext.soundMode == 3) {
sub->bitField0.s.stereoHeadsetEffects = false;
sub->bitField0.s.usesHeadsetPanEffects = false;
sub->bitField0.stereoHeadsetEffects = false;
sub->bitField0.usesHeadsetPanEffects = false;
volLeft = 0.707f; // approx 1/sqrt(2)
volRight = 0.707f;
} else {
sub->bitField0.s.stereoStrongRight = sp24.strongRight;
sub->bitField0.s.stereoStrongLeft = sp24.strongLeft;
sub->bitField0.stereoStrongRight = sp24.strongRight;
sub->bitField0.stereoStrongLeft = sp24.strongLeft;
volLeft = gDefaultPanVolume[pan];
volRight = gDefaultPanVolume[0x7F - pan];
}
@ -105,7 +105,7 @@ void Audio_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput)
f32 resamplingRate = 0.0f;
if (resamplingRateInput < 2.0f) {
noteSubEu->bitField1.s.hasTwoAdpcmParts = false;
noteSubEu->bitField1.hasTwoParts = false;
if (1.99998f < resamplingRateInput) {
resamplingRate = 1.99998f;
@ -114,7 +114,7 @@ void Audio_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput)
}
} else {
noteSubEu->bitField1.s.hasTwoAdpcmParts = true;
noteSubEu->bitField1.hasTwoParts = true;
if (3.99996f < resamplingRateInput) {
resamplingRate = 1.99998f;
} else {
@ -126,11 +126,11 @@ void Audio_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput)
void Audio_NoteInit(Note* note) {
if (note->playbackState.parentLayer->adsr.releaseRate == 0) {
Audio_AdsrInit(&note->playbackState.adsr, note->playbackState.parentLayer->seqChannel->adsr.envelope,
&note->playbackState.adsrVolScale);
Audio_AdsrInit(&note->playbackState.adsr, note->playbackState.parentLayer->channel->adsr.envelope,
&note->playbackState.adsrVolScaleUnused);
} else {
Audio_AdsrInit(&note->playbackState.adsr, note->playbackState.parentLayer->adsr.envelope,
&note->playbackState.adsrVolScale);
&note->playbackState.adsrVolScaleUnused);
}
note->playbackState.unk_04 = 0;
@ -139,13 +139,13 @@ void Audio_NoteInit(Note* note) {
}
void Audio_NoteDisable(Note* note) {
if (note->noteSubEu.bitField0.s.needsInit == true) {
note->noteSubEu.bitField0.s.needsInit = false;
if (note->noteSubEu.bitField0.needsInit == true) {
note->noteSubEu.bitField0.needsInit = false;
}
note->playbackState.priority = 0;
note->noteSubEu.bitField0.s.enabled = false;
note->noteSubEu.bitField0.enabled = false;
note->playbackState.unk_04 = 0;
note->noteSubEu.bitField0.s.finished = false;
note->noteSubEu.bitField0.finished = false;
note->playbackState.parentLayer = NO_LAYER;
note->playbackState.prevParentLayer = NO_LAYER;
note->playbackState.adsr.action.s.state = ADSR_STATE_DISABLED;
@ -164,7 +164,7 @@ void Audio_ProcessNotes(void) {
f32 scale;
s32 i;
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) {
for (i = 0; i < gAudioContext.numNotes; i++) {
note = &gAudioContext.notes[i];
noteSubEu2 = &gAudioContext.noteSubsEu[gAudioContext.noteSubEuOffset + i];
playbackState = &note->playbackState;
@ -182,19 +182,19 @@ void Audio_ProcessNotes(void) {
} else if (!playbackState->parentLayer->enabled && playbackState->unk_04 == 0 &&
playbackState->priority >= 1) {
// do nothing
} else if (playbackState->parentLayer->seqChannel->seqPlayer == NULL) {
Audio_SequenceChannelDisable(playbackState->parentLayer->seqChannel);
} else if (playbackState->parentLayer->channel->seqPlayer == NULL) {
AudioSeq_SequenceChannelDisable(playbackState->parentLayer->channel);
playbackState->priority = 1;
playbackState->unk_04 = 1;
continue;
} else if (playbackState->parentLayer->seqChannel->seqPlayer->muted &&
(playbackState->parentLayer->seqChannel->muteBehavior & 0x40)) {
} else if (playbackState->parentLayer->channel->seqPlayer->muted &&
(playbackState->parentLayer->channel->muteBehavior & 0x40)) {
// do nothing
} else {
goto out;
}
Audio_SeqChanLayerNoteRelease(playbackState->parentLayer);
Audio_SeqLayerNoteRelease(playbackState->parentLayer);
Audio_AudioListRemove(&note->listItem);
Audio_AudioListPushFront(&note->listItem.pool->decaying, &note->listItem);
playbackState->priority = 1;
@ -207,22 +207,22 @@ void Audio_ProcessNotes(void) {
if (playbackState->priority != 0) {
if (1) {}
noteSubEu = &note->noteSubEu;
if (playbackState->unk_04 >= 1 || noteSubEu->bitField0.s.finished) {
if (playbackState->adsr.action.s.state == ADSR_STATE_DISABLED || noteSubEu->bitField0.s.finished) {
if (playbackState->unk_04 >= 1 || noteSubEu->bitField0.finished) {
if (playbackState->adsr.action.s.state == ADSR_STATE_DISABLED || noteSubEu->bitField0.finished) {
if (playbackState->wantedParentLayer != NO_LAYER) {
Audio_NoteDisable(note);
if (playbackState->wantedParentLayer->seqChannel != NULL) {
if (playbackState->wantedParentLayer->channel != NULL) {
Audio_NoteInitForLayer(note, playbackState->wantedParentLayer);
Audio_NoteVibratoInit(note);
Audio_NotePortamentoInit(note);
Audio_AudioListRemove(&note->listItem);
Audio_AudioListPushBack(&note->listItem.pool->active, &note->listItem);
AudioSeq_AudioListPushBack(&note->listItem.pool->active, &note->listItem);
playbackState->wantedParentLayer = NO_LAYER;
// don't skip
} else {
Audio_NoteDisable(note);
Audio_AudioListRemove(&note->listItem);
Audio_AudioListPushBack(&note->listItem.pool->disabled, &note->listItem);
AudioSeq_AudioListPushBack(&note->listItem.pool->disabled, &note->listItem);
playbackState->wantedParentLayer = NO_LAYER;
goto skip;
}
@ -232,7 +232,7 @@ void Audio_ProcessNotes(void) {
}
Audio_NoteDisable(note);
Audio_AudioListRemove(&note->listItem);
Audio_AudioListPushBack(&note->listItem.pool->disabled, &note->listItem);
AudioSeq_AudioListPushBack(&note->listItem.pool->disabled, &note->listItem);
continue;
}
}
@ -242,7 +242,7 @@ void Audio_ProcessNotes(void) {
}
Audio_NoteDisable(note);
Audio_AudioListRemove(&note->listItem);
Audio_AudioListPushBack(&note->listItem.pool->disabled, &note->listItem);
AudioSeq_AudioListPushBack(&note->listItem.pool->disabled, &note->listItem);
continue;
}
@ -259,10 +259,10 @@ void Audio_ProcessNotes(void) {
subAttrs.filter = attrs->filter;
subAttrs.unk_14 = attrs->unk_4;
subAttrs.unk_16 = attrs->unk_6;
bookOffset = noteSubEu->bitField1.s.bookOffset;
bookOffset = noteSubEu->bitField1.bookOffset;
} else {
SequenceChannelLayer* layer = playbackState->parentLayer;
SequenceChannel* channel = layer->seqChannel;
SequenceLayer* layer = playbackState->parentLayer;
SequenceChannel* channel = layer->channel;
subAttrs.frequency = layer->noteFreqScale;
subAttrs.velocity = layer->noteVelocity;
@ -289,14 +289,14 @@ void Audio_ProcessNotes(void) {
subAttrs.frequency *= gAudioContext.audioBufferParameters.resampleRate;
subAttrs.velocity *= scale;
Audio_InitNoteSub(note, noteSubEu2, &subAttrs);
noteSubEu->bitField1.s.bookOffset = bookOffset;
noteSubEu->bitField1.bookOffset = bookOffset;
skip:;
}
}
}
AudioBankSound* Audio_InstrumentGetAudioBankSound(Instrument* instrument, s32 semitone) {
AudioBankSound* sound;
SoundFontSound* Audio_InstrumentGetSound(Instrument* instrument, s32 semitone) {
SoundFontSound* sound;
if (semitone < instrument->normalRangeLo) {
sound = &instrument->lowNotesSound;
} else if (semitone <= instrument->normalRangeHi) {
@ -307,85 +307,85 @@ AudioBankSound* Audio_InstrumentGetAudioBankSound(Instrument* instrument, s32 se
return sound;
}
Instrument* Audio_GetInstrumentInner(s32 bankId, s32 instId) {
Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) {
Instrument* inst;
if (bankId == 0xFF) {
if (fontId == 0xFF) {
return NULL;
}
if (!Audio_IsBankLoadComplete(bankId)) {
gAudioContext.audioErrorFlags = bankId + 0x10000000;
if (!AudioLoad_IsFontLoadComplete(fontId)) {
gAudioContext.audioErrorFlags = fontId + 0x10000000;
return NULL;
}
if (instId >= gAudioContext.ctlEntries[bankId].numInstruments) {
gAudioContext.audioErrorFlags = ((bankId << 8) + instId) + 0x3000000;
if (instId >= gAudioContext.soundFonts[fontId].numInstruments) {
gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000;
return NULL;
}
inst = gAudioContext.ctlEntries[bankId].instruments[instId];
inst = gAudioContext.soundFonts[fontId].instruments[instId];
if (inst == NULL) {
gAudioContext.audioErrorFlags = ((bankId << 8) + instId) + 0x1000000;
gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000;
return inst;
}
return inst;
}
Drum* Audio_GetDrum(s32 bankId, s32 drumId) {
Drum* Audio_GetDrum(s32 fontId, s32 drumId) {
Drum* drum;
if (bankId == 0xFF) {
if (fontId == 0xFF) {
return NULL;
}
if (!Audio_IsBankLoadComplete(bankId)) {
gAudioContext.audioErrorFlags = bankId + 0x10000000;
if (!AudioLoad_IsFontLoadComplete(fontId)) {
gAudioContext.audioErrorFlags = fontId + 0x10000000;
return NULL;
}
if (drumId >= gAudioContext.ctlEntries[bankId].numDrums) {
gAudioContext.audioErrorFlags = ((bankId << 8) + drumId) + 0x4000000;
if (drumId >= gAudioContext.soundFonts[fontId].numDrums) {
gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000;
return NULL;
}
if ((u32)gAudioContext.ctlEntries[bankId].drums < 0x80000000) {
if ((u32)gAudioContext.soundFonts[fontId].drums < 0x80000000) {
return NULL;
}
drum = gAudioContext.ctlEntries[bankId].drums[drumId];
drum = gAudioContext.soundFonts[fontId].drums[drumId];
if (drum == NULL) {
gAudioContext.audioErrorFlags = ((bankId << 8) + drumId) + 0x5000000;
gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000;
}
return drum;
}
AudioBankSound* Audio_GetSfx(s32 bankId, s32 sfxId) {
AudioBankSound* sfx;
SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId) {
SoundFontSound* sfx;
if (bankId == 0xFF) {
if (fontId == 0xFF) {
return NULL;
}
if (!Audio_IsBankLoadComplete(bankId)) {
gAudioContext.audioErrorFlags = bankId + 0x10000000;
if (!AudioLoad_IsFontLoadComplete(fontId)) {
gAudioContext.audioErrorFlags = fontId + 0x10000000;
return NULL;
}
if (sfxId >= gAudioContext.ctlEntries[bankId].numSfx) {
gAudioContext.audioErrorFlags = ((bankId << 8) + sfxId) + 0x4000000;
if (sfxId >= gAudioContext.soundFonts[fontId].numSfx) {
gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000;
return NULL;
}
if ((u32)gAudioContext.ctlEntries[bankId].soundEffects < 0x80000000) {
if ((u32)gAudioContext.soundFonts[fontId].soundEffects < 0x80000000) {
return NULL;
}
sfx = &gAudioContext.ctlEntries[bankId].soundEffects[sfxId];
sfx = &gAudioContext.soundFonts[fontId].soundEffects[sfxId];
if (sfx == NULL) {
gAudioContext.audioErrorFlags = ((bankId << 8) + sfxId) + 0x5000000;
gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000;
}
if (sfx->sample == NULL) {
@ -395,67 +395,67 @@ AudioBankSound* Audio_GetSfx(s32 bankId, s32 sfxId) {
return sfx;
}
s32 func_800E7744(s32 instrument, s32 bankId, s32 instId, void* arg3) {
if (bankId == 0xFF) {
s32 Audio_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* value) {
if (fontId == 0xFF) {
return -1;
}
if (!Audio_IsBankLoadComplete(bankId)) {
if (!AudioLoad_IsFontLoadComplete(fontId)) {
return -2;
}
switch (instrument) {
switch (instrumentType) {
case 0:
if (instId >= gAudioContext.ctlEntries[bankId].numDrums) {
if (index >= gAudioContext.soundFonts[fontId].numDrums) {
return -3;
}
gAudioContext.ctlEntries[bankId].drums[instId] = arg3;
gAudioContext.soundFonts[fontId].drums[index] = value;
break;
case 1:
if (instId >= gAudioContext.ctlEntries[bankId].numSfx) {
if (index >= gAudioContext.soundFonts[fontId].numSfx) {
return -3;
}
gAudioContext.ctlEntries[bankId].soundEffects[instId] = *(AudioBankSound*)arg3;
gAudioContext.soundFonts[fontId].soundEffects[index] = *(SoundFontSound*)value;
break;
default:
if (instId >= gAudioContext.ctlEntries[bankId].numInstruments) {
if (index >= gAudioContext.soundFonts[fontId].numInstruments) {
return -3;
}
gAudioContext.ctlEntries[bankId].instruments[instId] = arg3;
gAudioContext.soundFonts[fontId].instruments[index] = value;
break;
}
return 0;
}
void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target) {
void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) {
Note* note;
NoteAttributes* attrs;
SequenceChannel* chan;
s32 i;
if (seqLayer == NO_LAYER) {
if (layer == NO_LAYER) {
return;
}
seqLayer->bit3 = false;
layer->bit3 = false;
if (seqLayer->note == NULL) {
if (layer->note == NULL) {
return;
}
note = seqLayer->note;
note = layer->note;
attrs = &note->playbackState.attributes;
if (note->playbackState.wantedParentLayer == seqLayer) {
if (note->playbackState.wantedParentLayer == layer) {
note->playbackState.wantedParentLayer = NO_LAYER;
}
if (note->playbackState.parentLayer != seqLayer) {
if (note->playbackState.parentLayer != layer) {
if (note->playbackState.parentLayer == NO_LAYER && note->playbackState.wantedParentLayer == NO_LAYER &&
note->playbackState.prevParentLayer == seqLayer && target != ADSR_STATE_DECAY) {
note->playbackState.prevParentLayer == layer && target != ADSR_STATE_DECAY) {
note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv;
note->playbackState.adsr.action.s.release = true;
}
@ -463,12 +463,12 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target)
}
if (note->playbackState.adsr.action.s.state != ADSR_STATE_DECAY) {
attrs->freqScale = seqLayer->noteFreqScale;
attrs->velocity = seqLayer->noteVelocity;
attrs->pan = seqLayer->notePan;
attrs->freqScale = layer->noteFreqScale;
attrs->velocity = layer->noteVelocity;
attrs->pan = layer->notePan;
if (seqLayer->seqChannel != NULL) {
chan = seqLayer->seqChannel;
if (layer->channel != NULL) {
chan = layer->channel;
attrs->reverb = chan->reverb;
attrs->unk_1 = chan->unk_0C;
attrs->filter = chan->filter;
@ -483,17 +483,17 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target)
attrs->unk_6 = chan->unk_20;
attrs->unk_4 = chan->unk_0F;
if (chan->seqPlayer->muted && (chan->muteBehavior & 8)) {
note->noteSubEu.bitField0.s.finished = true;
note->noteSubEu.bitField0.finished = true;
}
if (seqLayer->stereo.asByte == 0) {
if (layer->stereo.asByte == 0) {
attrs->stereo = chan->stereo;
} else {
attrs->stereo = seqLayer->stereo;
attrs->stereo = layer->stereo;
}
note->playbackState.priority = chan->someOtherPriority;
} else {
attrs->stereo = seqLayer->stereo;
attrs->stereo = layer->stereo;
note->playbackState.priority = 1;
}
@ -506,13 +506,13 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target)
} else {
note->playbackState.unk_04 = 1;
note->playbackState.adsr.action.s.decay = true;
if (seqLayer->adsr.releaseRate == 0) {
note->playbackState.adsr.fadeOutVel = gAudioContext.unk_3520[seqLayer->seqChannel->adsr.releaseRate];
if (layer->adsr.releaseRate == 0) {
note->playbackState.adsr.fadeOutVel = gAudioContext.unk_3520[layer->channel->adsr.releaseRate];
} else {
note->playbackState.adsr.fadeOutVel = gAudioContext.unk_3520[seqLayer->adsr.releaseRate];
note->playbackState.adsr.fadeOutVel = gAudioContext.unk_3520[layer->adsr.releaseRate];
}
note->playbackState.adsr.sustain =
((f32)(s32)(seqLayer->seqChannel->adsr.sustain) * note->playbackState.adsr.current) / 256.0f;
((f32)(s32)(layer->channel->adsr.sustain) * note->playbackState.adsr.current) / 256.0f;
}
}
@ -522,15 +522,15 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target)
}
}
void Audio_SeqChanLayerNoteDecay(SequenceChannelLayer* seqLayer) {
Audio_SeqChanLayerDecayRelease(seqLayer, ADSR_STATE_DECAY);
void Audio_SeqLayerNoteDecay(SequenceLayer* layer) {
Audio_SeqLayerDecayRelease(layer, ADSR_STATE_DECAY);
}
void Audio_SeqChanLayerNoteRelease(SequenceChannelLayer* seqLayer) {
Audio_SeqChanLayerDecayRelease(seqLayer, ADSR_STATE_RELEASE);
void Audio_SeqLayerNoteRelease(SequenceLayer* layer) {
Audio_SeqLayerDecayRelease(layer, ADSR_STATE_RELEASE);
}
s32 Audio_BuildSyntheticWave(Note* note, SequenceChannelLayer* seqLayer, s32 waveId) {
s32 Audio_BuildSyntheticWave(Note* note, SequenceLayer* layer, s32 waveId) {
f32 freqScale;
f32 ratio;
u8 sampleCountIndex;
@ -539,9 +539,9 @@ s32 Audio_BuildSyntheticWave(Note* note, SequenceChannelLayer* seqLayer, s32 wav
waveId = 128;
}
freqScale = seqLayer->freqScale;
if (seqLayer->portamento.mode != 0 && 0.0f < seqLayer->portamento.extent) {
freqScale *= (seqLayer->portamento.extent + 1.0f);
freqScale = layer->freqScale;
if (layer->portamento.mode != 0 && 0.0f < layer->portamento.extent) {
freqScale *= (layer->portamento.extent + 1.0f);
}
if (freqScale < 0.99999f) {
sampleCountIndex = 0;
@ -556,7 +556,7 @@ s32 Audio_BuildSyntheticWave(Note* note, SequenceChannelLayer* seqLayer, s32 wav
sampleCountIndex = 3;
ratio = 0.13081f;
}
seqLayer->freqScale *= ratio;
layer->freqScale *= ratio;
note->playbackState.waveId = waveId;
note->playbackState.sampleCountIndex = sampleCountIndex;
@ -565,17 +565,17 @@ s32 Audio_BuildSyntheticWave(Note* note, SequenceChannelLayer* seqLayer, s32 wav
return sampleCountIndex;
}
void Audio_InitSyntheticWave(Note* note, SequenceChannelLayer* seqLayer) {
void Audio_InitSyntheticWave(Note* note, SequenceLayer* layer) {
s32 sampleCountIndex;
s32 waveSampleCountIndex;
s32 waveId = seqLayer->instOrWave;
s32 waveId = layer->instOrWave;
if (waveId == 0xFF) {
waveId = seqLayer->seqChannel->instOrWave;
waveId = layer->channel->instOrWave;
}
sampleCountIndex = note->playbackState.sampleCountIndex;
waveSampleCountIndex = Audio_BuildSyntheticWave(note, seqLayer, waveId);
waveSampleCountIndex = Audio_BuildSyntheticWave(note, layer, waveId);
if (waveSampleCountIndex != sampleCountIndex) {
note->noteSubEu.unk_06 = waveSampleCountIndex * 4 + sampleCountIndex;
@ -603,10 +603,10 @@ void Audio_InitNoteFreeList(void) {
s32 i;
Audio_InitNoteLists(&gAudioContext.noteFreeLists);
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) {
for (i = 0; i < gAudioContext.numNotes; i++) {
gAudioContext.notes[i].listItem.u.value = &gAudioContext.notes[i];
gAudioContext.notes[i].listItem.prev = NULL;
Audio_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, &gAudioContext.notes[i].listItem);
AudioSeq_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, &gAudioContext.notes[i].listItem);
}
}
@ -645,7 +645,7 @@ void Audio_NotePoolClear(NotePool* pool) {
break;
}
Audio_AudioListRemove(cur);
Audio_AudioListPushBack(dest, cur);
AudioSeq_AudioListPushBack(dest, cur);
}
}
}
@ -687,11 +687,11 @@ void Audio_NotePoolFill(NotePool* pool, s32 count) {
}
while (j < count) {
note = Audio_AudioListPopBack(source);
note = AudioSeq_AudioListPopBack(source);
if (note == NULL) {
break;
}
Audio_AudioListPushBack(dest, &note->listItem);
AudioSeq_AudioListPushBack(dest, &note->listItem);
j++;
}
}
@ -718,7 +718,7 @@ void Audio_AudioListRemove(AudioListItem* item) {
}
}
Note* Audio_PopNodeWithValueLessEqual(AudioListItem* list, s32 limit) {
Note* Audio_FindNodeWithPrioLessThan(AudioListItem* list, s32 limit) {
AudioListItem* cur = list->next;
AudioListItem* best;
@ -743,89 +743,90 @@ Note* Audio_PopNodeWithValueLessEqual(AudioListItem* list, s32 limit) {
return best->u.value;
}
void Audio_NoteInitForLayer(Note* note, SequenceChannelLayer* seqLayer) {
void Audio_NoteInitForLayer(Note* note, SequenceLayer* layer) {
s32 pad[3];
s16 instId;
NotePlaybackState* playback = &note->playbackState;
NoteSubEu* sub = &note->noteSubEu;
note->playbackState.prevParentLayer = NO_LAYER;
note->playbackState.parentLayer = seqLayer;
playback->priority = seqLayer->seqChannel->notePriority;
seqLayer->notePropertiesNeedInit = true;
seqLayer->bit3 = true;
seqLayer->note = note;
seqLayer->seqChannel->noteUnused = note;
seqLayer->seqChannel->layerUnused = seqLayer;
seqLayer->noteVelocity = 0.0f;
note->playbackState.parentLayer = layer;
playback->priority = layer->channel->notePriority;
layer->notePropertiesNeedInit = true;
layer->bit3 = true;
layer->note = note;
layer->channel->noteUnused = note;
layer->channel->layerUnused = layer;
layer->noteVelocity = 0.0f;
Audio_NoteInit(note);
instId = seqLayer->instOrWave;
instId = layer->instOrWave;
if (instId == 0xFF) {
instId = seqLayer->seqChannel->instOrWave;
instId = layer->channel->instOrWave;
}
sub->sound.audioBankSound = seqLayer->sound;
sub->sound.soundFontSound = layer->sound;
if (instId >= 0x80 && instId < 0xC0) {
sub->bitField1.s.isSyntheticWave = true;
sub->bitField1.isSyntheticWave = true;
} else {
sub->bitField1.s.isSyntheticWave = false;
sub->bitField1.isSyntheticWave = false;
}
if (sub->bitField1.s.isSyntheticWave) {
Audio_BuildSyntheticWave(note, seqLayer, instId);
if (sub->bitField1.isSyntheticWave) {
Audio_BuildSyntheticWave(note, layer, instId);
}
playback->bankId = seqLayer->seqChannel->bankId;
playback->stereoHeadsetEffects = seqLayer->seqChannel->stereoHeadsetEffects;
sub->bitField1.s.reverbIndex = seqLayer->seqChannel->reverbIndex & 3;
playback->fontId = layer->channel->fontId;
playback->stereoHeadsetEffects = layer->channel->stereoHeadsetEffects;
sub->bitField1.reverbIndex = layer->channel->reverbIndex & 3;
}
void func_800E82C0(Note* note, SequenceChannelLayer* seqLayer) {
Audio_SeqChanLayerNoteRelease(note->playbackState.parentLayer);
note->playbackState.wantedParentLayer = seqLayer;
void func_800E82C0(Note* note, SequenceLayer* layer) {
// similar to Audio_NoteReleaseAndTakeOwnership, hard to say what the difference is
Audio_SeqLayerNoteRelease(note->playbackState.parentLayer);
note->playbackState.wantedParentLayer = layer;
}
void Audio_NoteReleaseAndTakeOwnership(Note* note, SequenceChannelLayer* seqLayer) {
note->playbackState.wantedParentLayer = seqLayer;
note->playbackState.priority = seqLayer->seqChannel->notePriority;
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.action.s.release = true;
}
Note* Audio_AllocNoteFromDisabled(NotePool* pool, SequenceChannelLayer* seqLayer) {
Note* note = Audio_AudioListPopBack(&pool->disabled);
Note* Audio_AllocNoteFromDisabled(NotePool* pool, SequenceLayer* layer) {
Note* note = AudioSeq_AudioListPopBack(&pool->disabled);
if (note != NULL) {
Audio_NoteInitForLayer(note, seqLayer);
Audio_NoteInitForLayer(note, layer);
Audio_AudioListPushFront(&pool->active, &note->listItem);
}
return note;
}
Note* Audio_AllocNoteFromDecaying(NotePool* pool, SequenceChannelLayer* seqLayer) {
Note* note = Audio_AudioListPopBack(&pool->decaying);
Note* Audio_AllocNoteFromDecaying(NotePool* pool, SequenceLayer* layer) {
Note* note = AudioSeq_AudioListPopBack(&pool->decaying);
if (note != NULL) {
Audio_NoteReleaseAndTakeOwnership(note, seqLayer);
Audio_AudioListPushBack(&pool->releasing, &note->listItem);
Audio_NoteReleaseAndTakeOwnership(note, layer);
AudioSeq_AudioListPushBack(&pool->releasing, &note->listItem);
}
return note;
}
Note* Audio_AllocNoteFromActive(NotePool* pool, SequenceChannelLayer* seqLayer) {
Note* Audio_AllocNoteFromActive(NotePool* pool, SequenceLayer* layer) {
Note* rNote;
Note* aNote;
s32 rPriority;
s32 aPriority;
rPriority = aPriority = 0x10;
rNote = Audio_PopNodeWithValueLessEqual(&pool->releasing, seqLayer->seqChannel->notePriority);
rNote = Audio_FindNodeWithPrioLessThan(&pool->releasing, layer->channel->notePriority);
if (rNote != NULL) {
rPriority = rNote->playbackState.priority;
}
aNote = Audio_PopNodeWithValueLessEqual(&pool->active, seqLayer->seqChannel->notePriority);
aNote = Audio_FindNodeWithPrioLessThan(&pool->active, layer->channel->notePriority);
if (aNote != NULL) {
aPriority = aNote->playbackState.priority;
@ -837,76 +838,76 @@ Note* Audio_AllocNoteFromActive(NotePool* pool, SequenceChannelLayer* seqLayer)
if (aPriority < rPriority) {
Audio_AudioListRemove(&aNote->listItem);
func_800E82C0(aNote, seqLayer);
Audio_AudioListPushBack(&pool->releasing, &aNote->listItem);
aNote->playbackState.priority = seqLayer->seqChannel->notePriority;
func_800E82C0(aNote, layer);
AudioSeq_AudioListPushBack(&pool->releasing, &aNote->listItem);
aNote->playbackState.priority = layer->channel->notePriority;
return aNote;
}
rNote->playbackState.wantedParentLayer = seqLayer;
rNote->playbackState.priority = seqLayer->seqChannel->notePriority;
rNote->playbackState.wantedParentLayer = layer;
rNote->playbackState.priority = layer->channel->notePriority;
return rNote;
}
Note* Audio_AllocNote(SequenceChannelLayer* seqLayer) {
Note* Audio_AllocNote(SequenceLayer* layer) {
Note* ret;
u32 policy = seqLayer->seqChannel->noteAllocPolicy;
u32 policy = layer->channel->noteAllocPolicy;
if (policy & 1) {
ret = seqLayer->note;
if (ret != NULL && ret->playbackState.prevParentLayer == seqLayer &&
ret = layer->note;
if (ret != NULL && ret->playbackState.prevParentLayer == layer &&
ret->playbackState.wantedParentLayer == NO_LAYER) {
Audio_NoteReleaseAndTakeOwnership(ret, seqLayer);
Audio_NoteReleaseAndTakeOwnership(ret, layer);
Audio_AudioListRemove(&ret->listItem);
Audio_AudioListPushBack(&ret->listItem.pool->releasing, &ret->listItem);
AudioSeq_AudioListPushBack(&ret->listItem.pool->releasing, &ret->listItem);
return ret;
}
}
if (policy & 2) {
if (!(ret = Audio_AllocNoteFromDisabled(&seqLayer->seqChannel->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromDecaying(&seqLayer->seqChannel->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromActive(&seqLayer->seqChannel->notePool, seqLayer))) {
if (!(ret = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromActive(&layer->channel->notePool, layer))) {
goto null_return;
}
return ret;
}
if (policy & 4) {
if (!(ret = Audio_AllocNoteFromDisabled(&seqLayer->seqChannel->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromDisabled(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromDecaying(&seqLayer->seqChannel->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromDecaying(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromActive(&seqLayer->seqChannel->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromActive(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer))) {
if (!(ret = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) &&
!(ret = Audio_AllocNoteFromActive(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer))) {
goto null_return;
}
return ret;
}
if (policy & 8) {
if (!(ret = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, seqLayer)) &&
!(ret = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, seqLayer)) &&
!(ret = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, seqLayer))) {
if (!(ret = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) &&
!(ret = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) {
goto null_return;
}
return ret;
}
if (!(ret = Audio_AllocNoteFromDisabled(&seqLayer->seqChannel->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromDisabled(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, seqLayer)) &&
!(ret = Audio_AllocNoteFromDecaying(&seqLayer->seqChannel->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromDecaying(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, seqLayer)) &&
!(ret = Audio_AllocNoteFromActive(&seqLayer->seqChannel->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromActive(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) &&
!(ret = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, seqLayer))) {
if (!(ret = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) &&
!(ret = Audio_AllocNoteFromActive(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer)) &&
!(ret = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) {
goto null_return;
}
return ret;
null_return:
seqLayer->bit3 = true;
layer->bit3 = true;
return NULL;
}
@ -914,7 +915,7 @@ void Audio_NoteInitAll(void) {
Note* note;
s32 i;
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) {
for (i = 0; i < gAudioContext.numNotes; i++) {
note = &gAudioContext.notes[i];
note->noteSubEu = gZeroNoteSub;
note->playbackState.priority = 0;
@ -924,13 +925,13 @@ void Audio_NoteInitAll(void) {
note->playbackState.prevParentLayer = NO_LAYER;
note->playbackState.waveId = 0;
note->playbackState.attributes.velocity = 0.0f;
note->playbackState.adsrVolScale = 0;
note->playbackState.adsrVolScaleUnused = 0;
note->playbackState.adsr.action.asByte = 0;
note->vibratoState.active = 0;
note->portamento.cur = 0;
note->portamento.speed = 0;
note->playbackState.stereoHeadsetEffects = false;
note->unk_BC = 0;
note->synthesisState.synthesisBuffers = Audio_AllocDmaMemory(&gAudioContext.notesAndBuffersPool, 0x1E0);
note->synthesisState.synthesisBuffers = AudioHeap_AllocDmaMemory(&gAudioContext.notesAndBuffersPool, 0x1E0);
}
}

File diff suppressed because it is too large Load diff

View file

@ -112,14 +112,14 @@ void func_800DB03C(s32 arg0) {
s32 baseIndex;
s32 i;
baseIndex = gAudioContext.maxSimultaneousNotes * arg0;
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) {
baseIndex = gAudioContext.numNotes * arg0;
for (i = 0; i < gAudioContext.numNotes; i++) {
subEu = &gAudioContext.notes[i].noteSubEu;
subEu2 = &gAudioContext.noteSubsEu[baseIndex + i];
if (subEu->bitField0.s.enabled) {
subEu->bitField0.s.needsInit = false;
if (subEu->bitField0.enabled) {
subEu->bitField0.needsInit = false;
} else {
subEu2->bitField0.s.enabled = false;
subEu2->bitField0.enabled = false;
}
subEu->unk_06 = 0;
@ -136,7 +136,7 @@ Acmd* AudioSynth_Update(Acmd* cmdStart, s32* cmdCnt, s16* aiStart, s32 aiBufLen)
cmdP = cmdStart;
for (i = gAudioContext.audioBufferParameters.updatesPerFrame; i > 0; i--) {
Audio_ProcessSequences(i - 1);
AudioSeq_ProcessSequences(i - 1);
func_800DB03C(gAudioContext.audioBufferParameters.updatesPerFrame - i);
}
@ -181,9 +181,9 @@ void func_800DB2C0(s32 updateIndexStart, s32 noteIndex) {
s32 i;
for (i = updateIndexStart + 1; i < gAudioContext.audioBufferParameters.updatesPerFrame; i++) {
temp_v1 = &gAudioContext.noteSubsEu[(gAudioContext.maxSimultaneousNotes * i) + noteIndex];
if (!temp_v1->bitField0.s.needsInit) {
temp_v1->bitField0.s.enabled = 0;
temp_v1 = &gAudioContext.noteSubsEu[(gAudioContext.numNotes * i) + noteIndex];
if (!temp_v1->bitField0.needsInit) {
temp_v1->bitField0.enabled = 0;
} else {
break;
}
@ -442,11 +442,11 @@ void func_800DBE64(void) {
void func_800DBE6C(void) {
}
void AudioSynth_SetFilter(Acmd* cmd, s32 flags, s32 countOrBuf, s32 addr) {
void AudioSynth_LoadFilter(Acmd* cmd, s32 flags, s32 countOrBuf, s32 addr) {
aFilter(cmd, flags, countOrBuf, addr);
}
void AudioSynth_SetFilterCount(Acmd* cmd, s32 count, s32 addr) {
void AudioSynth_LoadFilterCount(Acmd* cmd, s32 count, s32 addr) {
aFilter(cmd, 2, count, addr);
}
@ -563,28 +563,27 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat
NoteSubEu* noteSubEu2;
s32 unk14;
t = gAudioContext.maxSimultaneousNotes * updateIndex;
t = gAudioContext.numNotes * updateIndex;
count = 0;
if (gAudioContext.numSynthesisReverbs == 0) {
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) {
if (gAudioContext.noteSubsEu[t + i].bitField0.s.enabled) {
for (i = 0; i < gAudioContext.numNotes; i++) {
if (gAudioContext.noteSubsEu[t + i].bitField0.enabled) {
noteIndices[count++] = i;
}
}
} else {
for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) {
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) {
for (i = 0; i < gAudioContext.numNotes; i++) {
noteSubEu = &gAudioContext.noteSubsEu[t + i];
if (noteSubEu->bitField0.s.enabled && noteSubEu->bitField1.s.reverbIndex == reverbIndex) {
if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex == reverbIndex) {
noteIndices[count++] = i;
}
}
}
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) {
for (i = 0; i < gAudioContext.numNotes; i++) {
noteSubEu = &gAudioContext.noteSubsEu[t + i];
if (noteSubEu->bitField0.s.enabled &&
noteSubEu->bitField1.s.reverbIndex >= gAudioContext.numSynthesisReverbs) {
if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex >= gAudioContext.numSynthesisReverbs) {
noteIndices[count++] = i;
}
}
@ -620,7 +619,7 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat
while (i < count) {
noteSubEu2 = &gAudioContext.noteSubsEu[noteIndices[i] + t];
if (noteSubEu2->bitField1.s.reverbIndex == reverbIndex) {
if (noteSubEu2->bitField1.reverbIndex == reverbIndex) {
cmd = AudioSynth_ProcessNote(noteIndices[i], noteSubEu2,
&gAudioContext.notes[noteIndices[i]].synthesisState, aiBuf, aiBufLen, cmd,
updateIndex);
@ -662,43 +661,43 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat
Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s16* aiBuf,
s32 aiBufLen, Acmd* cmd, s32 updateIndex) {
s32 pad1[3];
AudioBankSample* audioBankSample;
SoundFontSample* audioFontSample;
AdpcmLoop* loopInfo;
s32 samplesRemaining;
s32 nSamplesUntilLoopEnd;
s32 nSamplesInThisIteration;
s32 noteFinished;
s32 restart;
s32 flags;
u16 resamplingRateFixedPoint;
s32 phi_s6;
s32 phi_s7;
s32 nSamplesInFirstFrame;
s32 nTrailingSamplesToIgnore;
s32 phi_a1_2;
s32 temp_v1_5;
s32 sp120;
s32 frameIndex;
s32 skipBytes;
s32 temp_v1_6;
void* buf;
s32 phi_s0;
s32 sampleAddr;
s32 nSamplesToDecode;
u32 sampleAddr;
u32 samplesLenFixedPoint;
s32 samplesLenAdjusted;
s32 nAdpcmSamplesProcessed;
s32 endPos;
s32 nSamplesProcessed;
s32 loopEndPos;
s32 nSamplesToProcess;
s32 phi_s4;
s32 phi_s3;
s32 nFirstFrameSamplesToIgnore;
s32 pad2[7];
s32 spD4;
s32 phi_s1;
s32 spCC;
s32 spC8;
u8* phi_a1;
s32 frameSize;
s32 nFramesToDecode;
s32 skipInitialSamples;
s32 sampleDataStart;
u8* sampleData;
s32 nParts;
s32 curPart;
s32 phi_t0;
s32 sampleDataStartPad;
s32 side;
s32 resampledTempLen;
u16 noteSamplesDmemAddrBeforeResampling;
s32 temp_mult;
s32 sampleDataOffset;
s32 thing;
s32 s5;
Note* note;
@ -712,12 +711,12 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
s16 addr;
u16 unused;
bookOffset = noteSubEu->bitField1.s.bookOffset;
finished = noteSubEu->bitField0.s.finished;
bookOffset = noteSubEu->bitField1.bookOffset;
finished = noteSubEu->bitField0.finished;
note = &gAudioContext.notes[noteIndex];
flags = A_CONTINUE;
if (noteSubEu->bitField0.s.needsInit == true) {
if (noteSubEu->bitField0.needsInit == true) {
flags = A_INIT;
synthState->restart = 0;
synthState->samplePosInt = note->unk_BC;
@ -727,42 +726,40 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
synthState->prevHeadsetPanRight = 0;
synthState->prevHeadsetPanLeft = 0;
synthState->reverbVol = noteSubEu->reverbVol;
synthState->numAdpcmParts = 0;
synthState->numParts = 0;
synthState->unk_1A = 1;
note->noteSubEu.bitField0.s.finished = false;
note->noteSubEu.bitField0.finished = false;
finished = false;
}
resamplingRateFixedPoint = noteSubEu->resamplingRateFixedPoint;
nParts = noteSubEu->bitField1.s.hasTwoAdpcmParts + 1;
nParts = noteSubEu->bitField1.hasTwoParts + 1;
samplesLenFixedPoint = (resamplingRateFixedPoint * aiBufLen * 2) + synthState->samplePosFrac;
nSamplesToLoad = samplesLenFixedPoint >> 16;
synthState->samplePosFrac = samplesLenFixedPoint & 0xFFFF;
// Partially-optimized out no-op ifs required for matching. SM64 decomp
// makes it clear that this is how it should look.
if (synthState->numAdpcmParts == 1 && nParts == 2) {
} else if (synthState->numAdpcmParts == 2 && nParts == 1) {
if (synthState->numParts == 1 && nParts == 2) {
} else if (synthState->numParts == 2 && nParts == 1) {
} else {
}
synthState->numAdpcmParts = nParts;
synthState->numParts = nParts;
if (noteSubEu->bitField1.s.isSyntheticWave) {
if (noteSubEu->bitField1.isSyntheticWave) {
cmd = AudioSynth_LoadWaveSamples(cmd, noteSubEu, synthState, nSamplesToLoad);
noteSamplesDmemAddrBeforeResampling = DMEM_UNCOMPRESSED_NOTE + (synthState->samplePosInt * 2);
synthState->samplePosInt += nSamplesToLoad;
} else {
// ADPCM note
audioBankSample = noteSubEu->sound.audioBankSound->sample;
loopInfo = audioBankSample->loop;
endPos = loopInfo->end;
sampleAddr = audioBankSample->sampleAddr;
audioFontSample = noteSubEu->sound.soundFontSound->sample;
loopInfo = audioFontSample->loop;
loopEndPos = loopInfo->end;
sampleAddr = audioFontSample->sampleAddr;
resampledTempLen = 0;
for (curPart = 0; curPart < nParts; curPart++) {
// reordering in the loop prelude
nAdpcmSamplesProcessed = 0;
nSamplesProcessed = 0;
s5 = 0;
if (nParts == 1) {
@ -773,8 +770,8 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
samplesLenAdjusted = nSamplesToLoad;
}
if (audioBankSample->codec == 0 || audioBankSample->codec == 3) {
if (gAudioContext.curLoadedBook != (*audioBankSample->book).book) {
if (audioFontSample->codec == CODEC_ADPCM || audioFontSample->codec == CODEC_SMALL_ADPCM) {
if (gAudioContext.curLoadedBook != audioFontSample->book->book) {
u32 nEntries;
switch (bookOffset) {
case 1:
@ -783,43 +780,43 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
case 2:
case 3:
default:
gAudioContext.curLoadedBook = (*audioBankSample->book).book;
gAudioContext.curLoadedBook = audioFontSample->book->book;
break;
}
if (1) {}
if (1) {}
if (1) {}
nEntries = 16 * audioBankSample->book->order * audioBankSample->book->npredictors;
nEntries = 16 * audioFontSample->book->order * audioFontSample->book->npredictors;
aLoadADPCM(cmd++, nEntries, gAudioContext.curLoadedBook);
}
}
while (nAdpcmSamplesProcessed != samplesLenAdjusted) {
while (nSamplesProcessed != samplesLenAdjusted) {
noteFinished = false;
restart = false;
phi_s4 = 0;
phi_s3 = synthState->samplePosInt & 0xF;
samplesRemaining = endPos - synthState->samplePosInt;
nSamplesToProcess = samplesLenAdjusted - nAdpcmSamplesProcessed;
nFirstFrameSamplesToIgnore = synthState->samplePosInt & 0xF;
nSamplesUntilLoopEnd = loopEndPos - synthState->samplePosInt;
nSamplesToProcess = samplesLenAdjusted - nSamplesProcessed;
if (phi_s3 == 0 && synthState->restart == false) {
phi_s3 = 16;
if (nFirstFrameSamplesToIgnore == 0 && !synthState->restart) {
nFirstFrameSamplesToIgnore = 16;
}
phi_s6 = 16 - phi_s3;
nSamplesInFirstFrame = 16 - nFirstFrameSamplesToIgnore;
if (nSamplesToProcess < samplesRemaining) {
phi_s1 = (s32)(nSamplesToProcess - phi_s6 + 15) / 16;
phi_s0 = phi_s1 * 16;
phi_s7 = phi_s6 + phi_s0 - nSamplesToProcess;
if (nSamplesToProcess < nSamplesUntilLoopEnd) {
nFramesToDecode = (s32)(nSamplesToProcess - nSamplesInFirstFrame + 15) / 16;
nSamplesToDecode = nFramesToDecode * 16;
nTrailingSamplesToIgnore = nSamplesInFirstFrame + nSamplesToDecode - nSamplesToProcess;
} else {
phi_s0 = samplesRemaining - phi_s6;
phi_s7 = 0;
if (phi_s0 <= 0) {
phi_s0 = 0;
phi_s6 = samplesRemaining;
nSamplesToDecode = nSamplesUntilLoopEnd - nSamplesInFirstFrame;
nTrailingSamplesToIgnore = 0;
if (nSamplesToDecode <= 0) {
nSamplesToDecode = 0;
nSamplesInFirstFrame = nSamplesUntilLoopEnd;
}
phi_s1 = (phi_s0 + 15) / 16;
nFramesToDecode = (nSamplesToDecode + 15) / 16;
if (loopInfo->count != 0) {
// Loop around and restart
restart = true;
@ -828,111 +825,114 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
}
}
switch (audioBankSample->codec) {
switch (audioFontSample->codec) {
case CODEC_ADPCM:
spD4 = 9;
spCC = 0x10;
spC8 = 0;
frameSize = 9;
skipInitialSamples = 16;
sampleDataStart = 0;
break;
case 3:
spD4 = 5;
spCC = 0x10;
spC8 = 0;
case CODEC_SMALL_ADPCM:
frameSize = 5;
skipInitialSamples = 16;
sampleDataStart = 0;
break;
case CODEC_S8:
spD4 = 0x10;
spCC = 0x10;
spC8 = 0;
frameSize = 16;
skipInitialSamples = 16;
sampleDataStart = 0;
break;
case 2:
case CODEC_S16_INMEMORY:
AudioSynth_ClearBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE, (samplesLenAdjusted * 2) + 0x20);
flags = A_CONTINUE;
sp120 = 0;
nAdpcmSamplesProcessed = samplesLenAdjusted;
skipBytes = 0;
nSamplesProcessed = samplesLenAdjusted;
s5 = samplesLenAdjusted;
goto skip;
case 5:
case CODEC_S16:
AudioSynth_ClearBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE, (samplesLenAdjusted * 2) + 0x20);
flags = A_CONTINUE;
sp120 = 0;
nAdpcmSamplesProcessed = samplesLenAdjusted;
skipBytes = 0;
nSamplesProcessed = samplesLenAdjusted;
s5 = samplesLenAdjusted;
goto skip;
case 4:
case CODEC_REVERB:
break;
}
if (phi_s1 != 0) {
temp_v1_5 = (synthState->samplePosInt + spCC - phi_s3) / 16;
temp_mult = (temp_v1_5 * spD4);
if (audioBankSample->medium == 0) {
phi_a1 = spC8 + temp_mult + sampleAddr;
} else if (audioBankSample->medium == 1) {
if (nFramesToDecode != 0) {
frameIndex = (synthState->samplePosInt + skipInitialSamples - nFirstFrameSamplesToIgnore) / 16;
sampleDataOffset = frameIndex * frameSize;
if (audioFontSample->medium == MEDIUM_RAM) {
sampleData = (u8*)(sampleDataStart + sampleDataOffset + sampleAddr);
} else if (audioFontSample->medium == MEDIUM_UNK) {
return cmd;
} else {
phi_a1 =
Audio_DmaSampleData((u32)(spC8 + temp_mult + sampleAddr), ALIGN16((phi_s1 * spD4) + 0x10),
flags, &synthState->sampleDmaIndex, audioBankSample->medium);
sampleData = AudioLoad_DmaSampleData(sampleDataStart + sampleDataOffset + sampleAddr,
ALIGN16((nFramesToDecode * frameSize) + 0x10), flags,
&synthState->sampleDmaIndex, audioFontSample->medium);
}
if (phi_a1 == NULL) {
if (sampleData == NULL) {
return cmd;
}
phi_t0 = (u32)phi_a1 & 0xF;
aligned = ALIGN16((phi_s1 * spD4) + 16);
sampleDataStartPad = (u32)sampleData & 0xF;
aligned = ALIGN16((nFramesToDecode * frameSize) + 16);
addr = DMEM_COMPRESSED_ADPCM_DATA - aligned;
aLoadBuffer(cmd++, phi_a1 - phi_t0, addr, aligned);
aLoadBuffer(cmd++, sampleData - sampleDataStartPad, addr, aligned);
} else {
phi_s0 = 0;
phi_t0 = 0;
nSamplesToDecode = 0;
sampleDataStartPad = 0;
}
if (synthState->restart) {
aSetLoop(cmd++, audioBankSample->loop->state);
aSetLoop(cmd++, audioFontSample->loop->state);
flags = A_LOOP;
synthState->restart = false;
}
nSamplesInThisIteration = phi_s0 + phi_s6 - phi_s7;
if (nAdpcmSamplesProcessed == 0) {
nSamplesInThisIteration = nSamplesToDecode + nSamplesInFirstFrame - nTrailingSamplesToIgnore;
if (nSamplesProcessed == 0) {
if (1) {}
sp120 = phi_s3 * 2;
skipBytes = nFirstFrameSamplesToIgnore * 2;
} else {
phi_s4 = ALIGN16(s5 + 16);
}
switch (audioBankSample->codec) {
switch (audioFontSample->codec) {
case CODEC_ADPCM:
aligned = ALIGN16((phi_s1 * spD4) + 0x10);
aligned = ALIGN16((nFramesToDecode * frameSize) + 0x10);
addr = DMEM_COMPRESSED_ADPCM_DATA - aligned;
aSetBuffer(cmd++, 0, addr + phi_t0, DMEM_UNCOMPRESSED_NOTE + phi_s4, phi_s0 * 2);
aSetBuffer(cmd++, 0, addr + sampleDataStartPad, DMEM_UNCOMPRESSED_NOTE + phi_s4,
nSamplesToDecode * 2);
aADPCMdec(cmd++, flags, synthState->synthesisBuffers->adpcmdecState);
break;
case 3:
aligned = ALIGN16((phi_s1 * spD4) + 0x10);
case CODEC_SMALL_ADPCM:
aligned = ALIGN16((nFramesToDecode * frameSize) + 0x10);
addr = DMEM_COMPRESSED_ADPCM_DATA - aligned;
aSetBuffer(cmd++, 0, addr + phi_t0, DMEM_UNCOMPRESSED_NOTE + phi_s4, phi_s0 * 2);
aSetBuffer(cmd++, 0, addr + sampleDataStartPad, DMEM_UNCOMPRESSED_NOTE + phi_s4,
nSamplesToDecode * 2);
aADPCMdec(cmd++, flags | 4, synthState->synthesisBuffers->adpcmdecState);
break;
case CODEC_S8:
aligned = ALIGN16((phi_s1 * spD4) + 0x10);
aligned = ALIGN16((nFramesToDecode * frameSize) + 0x10);
addr = DMEM_COMPRESSED_ADPCM_DATA - aligned;
AudioSynth_SetBuffer(cmd++, 0, addr + phi_t0, DMEM_UNCOMPRESSED_NOTE + phi_s4, phi_s0 * 2);
AudioSynth_SetBuffer(cmd++, 0, addr + sampleDataStartPad, DMEM_UNCOMPRESSED_NOTE + phi_s4,
nSamplesToDecode * 2);
AudioSynth_S8Dec(cmd++, flags, synthState->synthesisBuffers->adpcmdecState);
break;
}
if (nAdpcmSamplesProcessed != 0) {
aDMEMMove(cmd++, DMEM_UNCOMPRESSED_NOTE + phi_s4 + (phi_s3 * 2), DMEM_UNCOMPRESSED_NOTE + s5,
nSamplesInThisIteration * 2);
if (nSamplesProcessed != 0) {
aDMEMMove(cmd++, DMEM_UNCOMPRESSED_NOTE + phi_s4 + (nFirstFrameSamplesToIgnore * 2),
DMEM_UNCOMPRESSED_NOTE + s5, nSamplesInThisIteration * 2);
}
nAdpcmSamplesProcessed += nSamplesInThisIteration;
nSamplesProcessed += nSamplesInThisIteration;
switch (flags) {
case A_INIT:
sp120 = 0x20;
s5 = (phi_s0 + 0x10) * 2;
skipBytes = 0x20;
s5 = (nSamplesToDecode + 0x10) * 2;
break;
case A_LOOP:
s5 = nSamplesInThisIteration * 2 + s5;
@ -941,7 +941,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
if (s5 != 0) {
s5 = nSamplesInThisIteration * 2 + s5;
} else {
s5 = (phi_s3 + nSamplesInThisIteration) * 2;
s5 = (nFirstFrameSamplesToIgnore + nSamplesInThisIteration) * 2;
}
break;
}
@ -951,9 +951,9 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
skip:
if (noteFinished) {
AudioSynth_ClearBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE + s5,
(samplesLenAdjusted - nAdpcmSamplesProcessed) * 2);
(samplesLenAdjusted - nSamplesProcessed) * 2);
finished = true;
note->noteSubEu.bitField0.s.finished = true;
note->noteSubEu.bitField0.finished = true;
func_800DB2C0(updateIndex, noteIndex);
break;
} else {
@ -968,12 +968,12 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
switch (nParts) {
case 1:
noteSamplesDmemAddrBeforeResampling = DMEM_UNCOMPRESSED_NOTE + sp120;
noteSamplesDmemAddrBeforeResampling = DMEM_UNCOMPRESSED_NOTE + skipBytes;
break;
case 2:
switch (curPart) {
case 0:
AudioSynth_InterL(cmd++, DMEM_UNCOMPRESSED_NOTE + sp120, DMEM_TEMP + 0x20,
AudioSynth_InterL(cmd++, DMEM_UNCOMPRESSED_NOTE + skipBytes, DMEM_TEMP + 0x20,
((samplesLenAdjusted / 2) + 7) & ~7);
resampledTempLen = samplesLenAdjusted;
noteSamplesDmemAddrBeforeResampling = DMEM_TEMP + 0x20;
@ -983,7 +983,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
}
break;
case 1:
AudioSynth_InterL(cmd++, DMEM_UNCOMPRESSED_NOTE + sp120,
AudioSynth_InterL(cmd++, DMEM_UNCOMPRESSED_NOTE + skipBytes,
DMEM_TEMP + 0x20 + resampledTempLen, ((samplesLenAdjusted / 2) + 7) & ~7);
break;
}
@ -995,8 +995,8 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
}
flags = A_CONTINUE;
if (noteSubEu->bitField0.s.needsInit == true) {
noteSubEu->bitField0.s.needsInit = false;
if (noteSubEu->bitField0.needsInit == true) {
noteSubEu->bitField0.needsInit = false;
flags = A_INIT;
}
@ -1020,8 +1020,8 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
filter = noteSubEu->filter;
if (filter != 0) {
AudioSynth_SetFilterCount(cmd++, aiBufLen * 2, filter);
AudioSynth_SetFilter(cmd++, flags, DMEM_TEMP, synthState->synthesisBuffers->mixEnvelopeState);
AudioSynth_LoadFilterCount(cmd++, aiBufLen * 2, filter);
AudioSynth_LoadFilter(cmd++, flags, DMEM_TEMP, synthState->synthesisBuffers->mixEnvelopeState);
}
unk7 = noteSubEu->unk_07;
@ -1051,7 +1051,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
side = 0;
}
cmd = AudioSynth_ProcessEnvelope(cmd, noteSubEu, synthState, aiBufLen, DMEM_TEMP, side, flags);
if (noteSubEu->bitField1.s.usesHeadsetPanEffects2) {
if (noteSubEu->bitField1.usesHeadsetPanEffects2) {
if (!(flags & A_INIT)) {
flags = A_CONTINUE;
}
@ -1118,7 +1118,7 @@ Acmd* AudioSynth_ProcessEnvelope(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisS
synthState->curVolLeft = curVolLeft + (rampLeft * (aiBufLen >> 3));
synthState->curVolRight = curVolRight + (rampRight * (aiBufLen >> 3));
if (noteSubEu->bitField1.s.usesHeadsetPanEffects2) {
if (noteSubEu->bitField1.usesHeadsetPanEffects2) {
AudioSynth_ClearBuffer(cmd++, DMEM_NOTE_PAN_TEMP, DEFAULT_LEN_1CH);
AudioSynth_EnvSetup1(cmd++, phi_t1 * 2, rampReverb, rampLeft, rampRight);
AudioSynth_EnvSetup2(cmd++, curVolLeft, curVolRight);
@ -1139,9 +1139,9 @@ Acmd* AudioSynth_ProcessEnvelope(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisS
phi_a1 = D_801304AC;
}
aEnvMixer(cmd++, inBuf, aiBufLen, (sourceReverbVol & 0x80) >> 7, noteSubEu->bitField0.s.stereoHeadsetEffects,
noteSubEu->bitField0.s.usesHeadsetPanEffects, noteSubEu->bitField0.s.stereoStrongRight,
noteSubEu->bitField0.s.stereoStrongLeft, phi_a1, D_801304A0);
aEnvMixer(cmd++, inBuf, aiBufLen, (sourceReverbVol & 0x80) >> 7, noteSubEu->bitField0.stereoHeadsetEffects,
noteSubEu->bitField0.usesHeadsetPanEffects, noteSubEu->bitField0.stereoStrongRight,
noteSubEu->bitField0.stereoStrongLeft, phi_a1, D_801304A0);
return cmd;
}
@ -1151,7 +1151,7 @@ Acmd* AudioSynth_LoadWaveSamples(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisS
s32 samplePosInt = synthState->samplePosInt;
s32 repeats;
if (noteSubEu->bitField1.s.bookOffset != 0) {
if (noteSubEu->bitField1.bookOffset != 0) {
AudioSynth_LoadBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE, ALIGN16(nSamplesToLoad * 2), gWaveSamples[8]);
gWaveSamples[8] += nSamplesToLoad * 2;
return cmd;

View file

@ -16,7 +16,7 @@ void func_8006BA30(GlobalContext* globalCtx) {
for (i = 0; i < ARRAY_COUNT(globalCtx->soundSources); i++) {
if (source->countdown != 0) {
if (DECR(source->countdown) == 0) {
func_800F89E8(&source->relativePos);
Audio_StopSfxByPos(&source->relativePos);
} else {
SkinMatrix_Vec3fMtxFMultXYZ(&globalCtx->mf_11D60, &source->originPos, &source->relativePos);
}
@ -49,7 +49,7 @@ void Audio_PlaySoundAtPosition(GlobalContext* globalCtx, Vec3f* pos, s32 duratio
if (i >= ARRAY_COUNT(globalCtx->soundSources)) {
source = backupSource;
func_800F89E8(&source->relativePos);
Audio_StopSfxByPos(&source->relativePos);
}
source->originPos = *pos;

View file

@ -8,6 +8,6 @@ void func_800C3C20(void) {
s32 i;
for (i = 0; (i < ARRAY_COUNT(D_8012D200)) & 0xFFFFFFFF; i++) {
func_800F87A0(D_8012D200[i]);
Audio_StopSfxByBank(D_8012D200[i]);
}
}

View file

@ -107,12 +107,12 @@ AudioTask* func_800E5000(void) {
}
gAudioContext.curAudioFrameDmaCount = 0;
func_800E11F0();
Audio_ProcessLoads(gAudioContext.resetStatus);
func_800E4F58();
AudioLoad_DecreaseSampleDmaTtls();
AudioLoad_ProcessLoads(gAudioContext.resetStatus);
AudioLoad_ProcessScriptLoads();
if (gAudioContext.resetStatus != 0) {
if (Audio_ResetStep() == 0) {
if (AudioHeap_ResetStep() == 0) {
if (gAudioContext.resetStatus == 0) {
osSendMesg(gAudioContext.audioResetQueueP, gAudioContext.audioResetSpecIdToLoad, OS_MESG_NOBLOCK);
}
@ -217,19 +217,19 @@ void func_800E5584(AudioCmd* cmd) {
switch (cmd->op) {
case 0x81:
func_800E1C18(cmd->arg1, cmd->arg2);
AudioLoad_SyncLoadSeqParts(cmd->arg1, cmd->arg2);
return;
case 0x82:
func_800E20D4(cmd->arg0, cmd->arg1, cmd->arg2);
AudioLoad_SyncInitSeqPlayer(cmd->arg0, cmd->arg1, cmd->arg2);
func_800E59AC(cmd->arg0, cmd->data);
return;
case 0x85:
func_800E2124(cmd->arg0, cmd->arg1, cmd->data);
AudioLoad_SyncInitSeqPlayerSkipTicks(cmd->arg0, cmd->arg1, cmd->data);
return;
case 0x83:
if (gAudioContext.seqPlayers[cmd->arg0].enabled) {
if (cmd->asInt == 0) {
Audio_SequencePlayerDisableAsFinished(&gAudioContext.seqPlayers[cmd->arg0]);
AudioSeq_SequencePlayerDisableAsFinished(&gAudioContext.seqPlayers[cmd->arg0]);
} else {
func_800E5958(cmd->arg0, cmd->asInt);
}
@ -247,12 +247,12 @@ void func_800E5584(AudioCmd* cmd) {
return;
case 0xF2:
if (cmd->asUInt == 1) {
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) {
for (i = 0; i < gAudioContext.numNotes; i++) {
Note* note = &gAudioContext.notes[i];
NoteSubEu* subEu = &note->noteSubEu;
if (subEu->bitField0.s.enabled && note->playbackState.unk_04 == 0) {
if (note->playbackState.parentLayer->seqChannel->muteBehavior & 8) {
subEu->bitField0.s.finished = 1;
if (subEu->bitField0.enabled && note->playbackState.unk_04 == 0) {
if (note->playbackState.parentLayer->channel->muteBehavior & 8) {
subEu->bitField0.finished = 1;
}
}
}
@ -266,19 +266,19 @@ void func_800E5584(AudioCmd* cmd) {
return;
case 0xF3:
func_800E1D64(cmd->arg0, cmd->arg1, cmd->arg2);
AudioLoad_SyncLoadInstrument(cmd->arg0, cmd->arg1, cmd->arg2);
return;
case 0xF4:
Audio_AudioTableAsyncLoad(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.unk_1E20);
AudioLoad_AsyncLoadSampleBank(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue);
return;
case 0xF5:
Audio_AudioBankAsyncLoad(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.unk_1E20);
AudioLoad_AsyncLoadFont(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue);
return;
case 0xFC:
Audio_AudioSeqAsyncLoad(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.unk_1E20);
AudioLoad_AsyncLoadSeq(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue);
return;
case 0xF6:
func_800E1F7C(cmd->arg1);
AudioLoad_DiscardSeqFonts(cmd->arg1);
return;
case 0x90:
gAudioContext.unk_5BDC[cmd->arg0] = cmd->asUShort;
@ -293,7 +293,7 @@ void func_800E5584(AudioCmd* cmd) {
case 0xE0:
case 0xE1:
case 0xE2:
func_800E7744(cmd->op - 0xE0, cmd->arg0, cmd->arg1, cmd->data);
Audio_SetFontInstrument(cmd->op - 0xE0, cmd->arg0, cmd->arg1, cmd->data);
return;
case 0xFE:
temp_t7 = cmd->asUInt;
@ -301,14 +301,14 @@ void func_800E5584(AudioCmd* cmd) {
for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) {
SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i];
if (seqPlayer->enabled) {
Audio_SequencePlayerDisableAsFinished(seqPlayer);
AudioSeq_SequencePlayerDisableAsFinished(seqPlayer);
}
}
}
func_800E66C0(temp_t7);
return;
case 0xE3:
func_800DE4B0(cmd->asInt);
AudioHeap_PopCache(cmd->asInt);
return;
default:
return;
@ -478,24 +478,24 @@ void Audio_ProcessCmds(u32 msg) {
}
}
u32 func_800E5E20(u32* arg0) {
u32 func_800E5E20(u32* out) {
u32 sp1C;
if (osRecvMesg(&gAudioContext.unk_1E20, (OSMesg*)&sp1C, OS_MESG_NOBLOCK) == -1) {
*arg0 = 0;
if (osRecvMesg(&gAudioContext.externalLoadQueue, (OSMesg*)&sp1C, OS_MESG_NOBLOCK) == -1) {
*out = 0;
return 0;
}
*arg0 = sp1C & 0xFFFFFF;
*out = sp1C & 0xFFFFFF;
return sp1C >> 0x18;
}
u8* func_800E5E84(s32 arg0, u32* arg1) {
return func_800E1F38(arg0, arg1);
return AudioLoad_GetFontsForSequence(arg0, arg1);
}
void func_800E5EA4(s32 arg0, u32* arg1, u32* arg2) {
*arg1 = gAudioContext.ctlEntries[arg0].unk_02;
*arg2 = gAudioContext.ctlEntries[arg0].unk_03;
*arg1 = gAudioContext.soundFonts[arg0].sampleBankId1;
*arg2 = gAudioContext.soundFonts[arg0].sampleBankId2;
}
s32 func_800E5EDC(void) {
@ -563,15 +563,15 @@ s8 func_800E6070(s32 playerIdx, s32 channelIdx, s32 scriptIdx) {
}
s8 func_800E60C4(s32 arg0, s32 arg1) {
return gAudioContext.seqPlayers[arg0].unk_158[arg1];
return gAudioContext.seqPlayers[arg0].soundScriptIO[arg1];
}
void func_800E60EC(void* memAddr, u32 size) {
Audio_SoundAllocPoolInit(&gAudioContext.unkPool, memAddr, size);
void Audio_InitExternalPool(void* mem, u32 size) {
AudioHeap_AllocPoolInit(&gAudioContext.externalPool, mem, size);
}
void func_800E611C(void) {
gAudioContext.unkPool.start = NULL;
void Audio_DestroyExternalPool(void) {
gAudioContext.externalPool.start = NULL;
}
void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) {
@ -596,7 +596,7 @@ void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) {
seqPlayer->transposition = cmd->asSbyte;
return;
case 0x46:
seqPlayer->unk_158[cmd->arg2] = cmd->asSbyte;
seqPlayer->soundScriptIO[cmd->arg2] = cmd->asSbyte;
return;
case 0x4A:
fadeVolume = (s32)cmd->arg1 / 127.0f;
@ -725,9 +725,9 @@ void Audio_WaitForAudioTask(void) {
s32 func_800E6590(s32 arg0, s32 arg1, s32 arg2) {
SequencePlayer* seqPlayer;
SequenceChannelLayer* layer;
SequenceLayer* layer;
Note* note;
AudioBankSound* sound;
SoundFontSound* sound;
s32 loopEnd;
s32 samplePos;
@ -749,7 +749,7 @@ s32 func_800E6590(s32 arg0, s32 arg1, s32 arg2) {
note = layer->note;
if (layer == note->playbackState.parentLayer) {
sound = note->noteSubEu.sound.audioBankSound;
sound = note->noteSubEu.sound.soundFontSound;
if (sound == NULL) {
return 0;
}
@ -777,21 +777,21 @@ s32 func_800E66C0(s32 arg0) {
NoteSubEu* temp_a3;
s32 i;
Note* note;
AudioBankSound* sound;
SoundFontSound* sound;
phi_v1 = 0;
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) {
for (i = 0; i < gAudioContext.numNotes; i++) {
note = &gAudioContext.notes[i];
temp_a2 = &note->playbackState;
if (note->noteSubEu.bitField0.s.enabled) {
if (note->noteSubEu.bitField0.enabled) {
temp_a3 = &note->noteSubEu;
if (temp_a2->adsr.action.s.state != 0) {
if (arg0 >= 2) {
sound = temp_a3->sound.audioBankSound;
if (sound == NULL || temp_a3->bitField1.s.isSyntheticWave) {
sound = temp_a3->sound.soundFontSound;
if (sound == NULL || temp_a3->bitField1.isSyntheticWave) {
continue;
}
if (sound->sample->medium == 0) {
if (sound->sample->medium == MEDIUM_RAM) {
continue;
}
}

File diff suppressed because it is too large Load diff

View file

@ -5,24 +5,24 @@
typedef struct {
/* 0x00 */ u16 sfxId;
/* 0x04 */ Vec3f* pos;
/* 0x08 */ u8 unk_8;
/* 0x08 */ u8 token;
/* 0x0C */ f32* freqScale;
/* 0x10 */ f32* unk_10;
/* 0x10 */ f32* vol;
/* 0x14 */ s8* reverbAdd;
} SoundRequest; // size = 0x18
typedef struct {
/* 0x00 */ f32 unk_0;
/* 0x04 */ f32 unk_4;
/* 0x08 */ f32 unk_8;
/* 0x0C */ u16 unk_C;
} Struct_800F8EA0; // size = 0x10
/* 0x00 */ f32 value;
/* 0x04 */ f32 target;
/* 0x08 */ f32 step;
/* 0x0C */ u16 remainingFrames;
} UnusedBankLerp; // size = 0x10
// rodata for Audio_ProcessSoundRequest (this file)
// (probably moved to .data due to -use_readwrite_const)
char D_80133340[] = "SE";
// rodata for func_800F7CEC (this file)
// rodata for Audio_ChooseActiveSounds (this file)
char D_80133344[] = VT_COL(RED, WHITE) "<INAGAKI CHECK> dist over! flag:%04X ptr:%08X pos:%f-%f-%f" VT_RST "\n";
// file padding
@ -32,6 +32,21 @@ s32 D_8013338C = 0;
char D_80133390[] = "SEQ H";
char D_80133398[] = " L";
// bss
extern SoundRequest sSoundRequests[0x100];
extern SoundBankEntry D_8016BAD0[9];
extern SoundBankEntry D_8016BC80[12];
extern SoundBankEntry D_8016BEC0[22];
extern SoundBankEntry D_8016C2E0[20];
extern SoundBankEntry D_8016C6A0[8];
extern SoundBankEntry D_8016C820[3];
extern SoundBankEntry D_8016C8B0[5];
extern u8 sSoundBankListEnd[7];
extern u8 sSoundBankFreeListStart[7];
extern u8 sSoundBankUnused[7];
extern u8 sCurSfxPlayerChannelIdx;
extern UnusedBankLerp sUnusedBankLerp[7];
// data
// sSoundRequests ring buffer endpoints. read index <= write index, wrapping around mod 256.
@ -58,7 +73,7 @@ u8 sBankSizes[ARRAY_COUNT(gSoundBanks)] = {
ARRAY_COUNT(D_8016C6A0), ARRAY_COUNT(D_8016C820), ARRAY_COUNT(D_8016C8B0),
};
u8 D_801333CC = 0;
u8 gSfxChannelLayout = 0;
u16 D_801333D0 = 0;
@ -74,13 +89,10 @@ s32 D_801333EC = 0; // unused
u8 D_801333F0 = 0;
u8 gAudioSEFlagSwapOff = 0;
u8 gAudioSfxSwapOff = 0;
u8 D_801333F8 = 0;
extern SoundRequest sSoundRequests[0x100];
extern Struct_800F8EA0 D_8016E270[7];
void Audio_SetSoundBanksMute(u16 muteMask) {
u8 bankId;
@ -94,38 +106,37 @@ void Audio_SetSoundBanksMute(u16 muteMask) {
}
}
void Audio_QueueSeqCmdMute(u8 arg0) {
D_801333D0 |= (1 << arg0);
void Audio_QueueSeqCmdMute(u8 channelIdx) {
D_801333D0 |= (1 << channelIdx);
Audio_SetVolScale(0, 2, 0x40, 0xF);
Audio_SetVolScale(3, 2, 0x40, 0xF);
}
void Audio_ClearBGMMute(u8 arg0) {
D_801333D0 &= ((1 << arg0) ^ 0xFFFF);
void Audio_ClearBGMMute(u8 channelIdx) {
D_801333D0 &= ((1 << channelIdx) ^ 0xFFFF);
if (D_801333D0 == 0) {
Audio_SetVolScale(0, 2, 0x7F, 0xF);
Audio_SetVolScale(3, 2, 0x7F, 0xF);
}
}
// a4 is often the same as freqScale. (u8)(*a4 * 127.0f) is sent to script on IO port 2
void Audio_PlaySoundGeneral(u16 sfxId, Vec3f* pos, u8 a2, f32* freqScale, f32* a4, s8* reverbAdd) {
void Audio_PlaySoundGeneral(u16 sfxId, Vec3f* pos, u8 token, f32* freqScale, f32* vol, s8* reverbAdd) {
u8 i;
SoundRequest* req;
if (!gSoundBankMuted[SFX_BANK_SHIFT(sfxId)]) {
req = &sSoundRequests[sSoundRequestWriteIndex];
if (!gAudioSEFlagSwapOff) {
if (!gAudioSfxSwapOff) {
for (i = 0; i < 10; i++) {
if (sfxId == gAudioSEFlagSwapSource[i]) {
if (gAudioSEFlagSwapMode[i] == 0) { // "SWAP"
sfxId = gAudioSEFlagSwapTarget[i];
if (sfxId == gAudioSfxSwapSource[i]) {
if (gAudioSfxSwapMode[i] == 0) { // "SWAP"
sfxId = gAudioSfxSwapTarget[i];
} else { // "ADD"
req->sfxId = gAudioSEFlagSwapTarget[i];
req->sfxId = gAudioSfxSwapTarget[i];
req->pos = pos;
req->unk_8 = a2;
req->token = token;
req->freqScale = freqScale;
req->unk_10 = a4;
req->vol = vol;
req->reverbAdd = reverbAdd;
sSoundRequestWriteIndex++;
req = &sSoundRequests[sSoundRequestWriteIndex];
@ -136,9 +147,9 @@ void Audio_PlaySoundGeneral(u16 sfxId, Vec3f* pos, u8 a2, f32* freqScale, f32* a
}
req->sfxId = sfxId;
req->pos = pos;
req->unk_8 = a2;
req->token = token;
req->freqScale = freqScale;
req->unk_10 = a4;
req->vol = vol;
req->reverbAdd = reverbAdd;
sSoundRequestWriteIndex++;
}
@ -174,7 +185,7 @@ void Audio_RemoveMatchingSoundRequests(u8 aspect, SoundBankEntry* cmp) {
}
break;
case 4:
if (req->unk_8 == cmp->unk_C && req->sfxId == cmp->sfxId) {
if (req->token == cmp->token && req->sfxId == cmp->sfxId) {
remove = true;
}
break;
@ -221,7 +232,7 @@ void Audio_ProcessSoundRequest(void) {
return;
}
if (gSoundBanks[bankId][index].sfxId == req->sfxId) {
count = D_80130594[D_801333CC][bankId];
count = gUsedChannelsPerBank[gSfxChannelLayout][bankId];
} else {
if (count == 0) {
evictIndex = index;
@ -233,7 +244,7 @@ void Audio_ProcessSoundRequest(void) {
evictImportance = gSoundParams[SFX_BANK_SHIFT(sfxId)][SFX_INDEX(sfxId)].importance;
}
count++;
if (count == D_80130594[D_801333CC][bankId]) {
if (count == gUsedChannelsPerBank[gSfxChannelLayout][bankId]) {
if (gSoundParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].importance >= evictImportance) {
index = evictIndex;
} else {
@ -241,23 +252,24 @@ void Audio_ProcessSoundRequest(void) {
}
}
}
if (count == D_80130594[D_801333CC][bankId]) {
if (count == gUsedChannelsPerBank[gSfxChannelLayout][bankId]) {
soundParams = &gSoundParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)];
if ((req->sfxId & 0xC00) || (soundParams->params & 4) || (index == evictIndex)) {
if ((gSoundBanks[bankId][index].sfxParams & 8) && gSoundBanks[bankId][index].unk_2A != 1) {
Audio_ClearBGMMute(gSoundBanks[bankId][index].unk_2E);
if ((gSoundBanks[bankId][index].sfxParams & 8) &&
gSoundBanks[bankId][index].state != SFX_STATE_QUEUED) {
Audio_ClearBGMMute(gSoundBanks[bankId][index].channelIdx);
}
gSoundBanks[bankId][index].unk_C = req->unk_8;
gSoundBanks[bankId][index].token = req->token;
gSoundBanks[bankId][index].sfxId = req->sfxId;
gSoundBanks[bankId][index].unk_2A = 1;
gSoundBanks[bankId][index].unk_2B = 2;
gSoundBanks[bankId][index].state = SFX_STATE_QUEUED;
gSoundBanks[bankId][index].freshness = 2;
gSoundBanks[bankId][index].freqScale = req->freqScale;
gSoundBanks[bankId][index].unk_14 = req->unk_10;
gSoundBanks[bankId][index].vol = req->vol;
gSoundBanks[bankId][index].reverbAdd = req->reverbAdd;
gSoundBanks[bankId][index].sfxParams = soundParams->params;
gSoundBanks[bankId][index].sfxImportance = soundParams->importance;
} else if (gSoundBanks[bankId][index].unk_2A == 5) {
gSoundBanks[bankId][index].unk_2A = 4;
} else if (gSoundBanks[bankId][index].state == SFX_STATE_PLAYING_2) {
gSoundBanks[bankId][index].state = SFX_STATE_PLAYING_1;
}
index = 0;
}
@ -266,93 +278,95 @@ void Audio_ProcessSoundRequest(void) {
index = gSoundBanks[bankId][index].next;
}
}
if (gSoundBanks[bankId][D_8016E1A8[bankId]].next != 0xFF && index != 0) {
index = D_8016E1A8[bankId];
if (gSoundBanks[bankId][sSoundBankFreeListStart[bankId]].next != 0xFF && index != 0) {
index = sSoundBankFreeListStart[bankId];
entry = &gSoundBanks[bankId][index];
entry->posX = &req->pos->x;
entry->posY = &req->pos->y;
entry->posZ = &req->pos->z;
entry->unk_C = req->unk_8;
entry->token = req->token;
entry->freqScale = req->freqScale;
entry->unk_14 = req->unk_10;
entry->vol = req->vol;
entry->reverbAdd = req->reverbAdd;
soundParams = &gSoundParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)];
entry->sfxParams = soundParams->params;
entry->sfxImportance = soundParams->importance;
entry->sfxId = req->sfxId;
entry->unk_2A = 1;
entry->unk_2B = 2;
entry->prev = D_8016E1A0[bankId];
gSoundBanks[bankId][D_8016E1A0[bankId]].next = D_8016E1A8[bankId];
D_8016E1A0[bankId] = D_8016E1A8[bankId];
D_8016E1A8[bankId] = gSoundBanks[bankId][D_8016E1A8[bankId]].next;
gSoundBanks[bankId][D_8016E1A8[bankId]].prev = 0xFF;
entry->state = SFX_STATE_QUEUED;
entry->freshness = 2;
entry->prev = sSoundBankListEnd[bankId];
gSoundBanks[bankId][sSoundBankListEnd[bankId]].next = sSoundBankFreeListStart[bankId];
sSoundBankListEnd[bankId] = sSoundBankFreeListStart[bankId];
sSoundBankFreeListStart[bankId] = gSoundBanks[bankId][sSoundBankFreeListStart[bankId]].next;
gSoundBanks[bankId][sSoundBankFreeListStart[bankId]].prev = 0xFF;
entry->next = 0xFF;
}
}
void func_800F7B54(u8 bankId, u8 bankIndex) {
SoundBankEntry* entry = &gSoundBanks[bankId][bankIndex];
void Audio_RemoveSoundBankEntry(u8 bankId, u8 entryIndex) {
SoundBankEntry* entry = &gSoundBanks[bankId][entryIndex];
u8 i;
if (entry->sfxParams & 8) {
Audio_ClearBGMMute(entry->unk_2E);
Audio_ClearBGMMute(entry->channelIdx);
}
if (bankIndex == D_8016E1A0[bankId]) {
D_8016E1A0[bankId] = entry->prev;
if (entryIndex == sSoundBankListEnd[bankId]) {
sSoundBankListEnd[bankId] = entry->prev;
} else {
gSoundBanks[bankId][entry->next].prev = entry->prev;
}
gSoundBanks[bankId][entry->prev].next = entry->next;
entry->next = D_8016E1A8[bankId];
entry->next = sSoundBankFreeListStart[bankId];
entry->prev = 0xFF;
gSoundBanks[bankId][D_8016E1A8[bankId]].prev = bankIndex;
D_8016E1A8[bankId] = bankIndex;
entry->unk_2A = 0;
gSoundBanks[bankId][sSoundBankFreeListStart[bankId]].prev = entryIndex;
sSoundBankFreeListStart[bankId] = entryIndex;
entry->state = SFX_STATE_EMPTY;
for (i = 0; i < D_80130578[D_801333CC][bankId]; i++) {
if (D_8016E1B8[bankId][i].unk_4 == bankIndex) {
D_8016E1B8[bankId][i].unk_4 = 0xFF;
i = D_80130578[D_801333CC][bankId];
for (i = 0; i < gChannelsPerBank[gSfxChannelLayout][bankId]; i++) {
if (gActiveSounds[bankId][i].entryIndex == entryIndex) {
gActiveSounds[bankId][i].entryIndex = 0xFF;
i = gChannelsPerBank[gSfxChannelLayout][bankId];
}
}
}
void func_800F7CEC(u8 arg0) {
u8 phi_s3;
u8 spAE;
u8 phi_s4;
void Audio_ChooseActiveSounds(u8 bankId) {
u8 numChosenSounds;
u8 numChannels;
u8 entryIndex;
u8 i;
u8 j;
u8 phi_s0;
u8 k;
u8 sfxImportance;
u8 phi_v1_5;
u8 temp2;
u8 needNewSound;
u8 chosenEntryIndex;
u16 temp3;
f32 tempf1;
SoundBankEntry* entry;
Struct_800F7CEC sp84[3];
Struct_800F7CEC* temp_s4_3;
ActiveSound chosenSounds[MAX_CHANNELS_PER_BANK];
ActiveSound* activeSound;
s32 pad;
phi_s3 = 0;
for (i = 0; i < 3; i++) {
sp84[i].priority = 0x7FFFFFFF;
sp84[i].unk_4 = 0xFF;
numChosenSounds = 0;
for (i = 0; i < MAX_CHANNELS_PER_BANK; i++) {
chosenSounds[i].priority = 0x7FFFFFFF;
chosenSounds[i].entryIndex = 0xFF;
}
phi_s4 = gSoundBanks[arg0][0].next;
phi_s0 = 0;
while (phi_s4 != 0xFF) {
if ((1 == gSoundBanks[arg0][phi_s4].unk_2A) && (gSoundBanks[arg0][phi_s4].sfxId & 0xC00)) {
gSoundBanks[arg0][phi_s4].unk_2B--;
} else if (!(gSoundBanks[arg0][phi_s4].sfxId & 0xC00) && (gSoundBanks[arg0][phi_s4].unk_2A == 5)) {
Audio_QueueCmdS8((gSoundBanks[arg0][phi_s4].unk_2E << 8) | 0x6020000, 0);
func_800F7B54(arg0, phi_s4);
entryIndex = gSoundBanks[bankId][0].next;
k = 0;
while (entryIndex != 0xFF) {
if ((gSoundBanks[bankId][entryIndex].state == SFX_STATE_QUEUED) &&
(gSoundBanks[bankId][entryIndex].sfxId & 0xC00)) {
gSoundBanks[bankId][entryIndex].freshness--;
} else if (!(gSoundBanks[bankId][entryIndex].sfxId & 0xC00) &&
(gSoundBanks[bankId][entryIndex].state == SFX_STATE_PLAYING_2)) {
Audio_QueueCmdS8((gSoundBanks[bankId][entryIndex].channelIdx << 8) | 0x6020000, 0);
Audio_RemoveSoundBankEntry(bankId, entryIndex);
}
if (gSoundBanks[arg0][phi_s4].unk_2B == 0) {
func_800F7B54(arg0, phi_s4);
} else if (gSoundBanks[arg0][phi_s4].unk_2A != 0) {
entry = &gSoundBanks[arg0][phi_s4];
if (gSoundBanks[bankId][entryIndex].freshness == 0) {
Audio_RemoveSoundBankEntry(bankId, entryIndex);
} else if (gSoundBanks[bankId][entryIndex].state != SFX_STATE_EMPTY) {
entry = &gSoundBanks[bankId][entryIndex];
if (&D_801333D4.x == entry[0].posX) {
entry->dist = 0.0f;
@ -369,122 +383,124 @@ void func_800F7CEC(u8 arg0) {
osSyncPrintf(D_80133344, entry->sfxId, entry->posX, entry->posZ, *entry->posX, *entry->posY,
*entry->posZ);
}
temp3 = entry->sfxId;
temp3 = entry->sfxId; // fake
entry->priority = (u32)entry->dist + (SQ(0xFF - sfxImportance) * SQ(76)) + temp3 - temp3;
if (*entry->posZ < 0.0f) {
entry->priority += (s32)(-*entry->posZ * 6.0f);
}
}
if (entry->dist > SQ(1e5f)) {
if (entry->unk_2A == 4) {
Audio_QueueCmdS8((entry->unk_2E << 8) | 0x6020000, 0);
if (entry->state == SFX_STATE_PLAYING_1) {
Audio_QueueCmdS8((entry->channelIdx << 8) | 0x6020000, 0);
if (entry->sfxId & 0xC00) {
func_800F7B54(arg0, phi_s4);
phi_s4 = phi_s0;
Audio_RemoveSoundBankEntry(bankId, entryIndex);
entryIndex = k;
}
}
} else {
spAE = D_80130578[D_801333CC][arg0];
for (i = 0; i < spAE; i++) {
if (sp84[i].priority >= entry->priority) {
if (phi_s3 < D_80130578[D_801333CC][arg0]) {
phi_s3++;
numChannels = gChannelsPerBank[gSfxChannelLayout][bankId];
for (i = 0; i < numChannels; i++) {
if (chosenSounds[i].priority >= entry->priority) {
if (numChosenSounds < gChannelsPerBank[gSfxChannelLayout][bankId]) {
numChosenSounds++;
}
for (j = spAE - 1; j > i; j--) {
sp84[j].priority = sp84[j - 1].priority;
sp84[j].unk_4 = sp84[j - 1].unk_4;
for (j = numChannels - 1; j > i; j--) {
chosenSounds[j].priority = chosenSounds[j - 1].priority;
chosenSounds[j].entryIndex = chosenSounds[j - 1].entryIndex;
}
sp84[i].priority = entry->priority;
sp84[i].unk_4 = phi_s4;
i = spAE; // "break;"
chosenSounds[i].priority = entry->priority;
chosenSounds[i].entryIndex = entryIndex;
i = numChannels; // "break;"
}
}
}
phi_s0 = phi_s4;
k = entryIndex;
}
phi_s4 = gSoundBanks[arg0][phi_s0].next;
entryIndex = gSoundBanks[bankId][k].next;
}
for (i = 0; i < phi_s3; i++) {
entry = &gSoundBanks[arg0][sp84[i].unk_4];
if (entry->unk_2A == 1) {
entry->unk_2A = 2;
} else if (entry->unk_2A == 4) {
entry->unk_2A = 3;
for (i = 0; i < numChosenSounds; i++) {
entry = &gSoundBanks[bankId][chosenSounds[i].entryIndex];
if (entry->state == SFX_STATE_QUEUED) {
entry->state = SFX_STATE_READY;
} else if (entry->state == SFX_STATE_PLAYING_1) {
entry->state = SFX_STATE_PLAYING_REFRESH;
}
}
spAE = D_80130578[D_801333CC][arg0];
for (i = 0; i < spAE; i++) {
phi_v1_5 = 0;
temp_s4_3 = &D_8016E1B8[arg0][i];
// Pick something to play for all channels.
numChannels = gChannelsPerBank[gSfxChannelLayout][bankId];
for (i = 0; i < numChannels; i++) {
needNewSound = false;
activeSound = &gActiveSounds[bankId][i];
if (temp_s4_3->unk_4 == 0xFF) {
phi_v1_5 = 1;
if (activeSound->entryIndex == 0xFF) {
needNewSound = true;
} else {
entry = &gSoundBanks[arg0][temp_s4_3[0].unk_4];
if (entry->unk_2A == 4) {
entry = &gSoundBanks[bankId][activeSound[0].entryIndex];
if (entry->state == SFX_STATE_PLAYING_1) {
if (entry->sfxId & 0xC00) {
func_800F7B54(arg0, temp_s4_3->unk_4);
Audio_RemoveSoundBankEntry(bankId, activeSound->entryIndex);
} else {
entry->unk_2A = 1;
entry->state = SFX_STATE_QUEUED;
}
phi_v1_5 = 1;
} else if (entry->unk_2A == 0) {
temp_s4_3->unk_4 = 0xFF;
phi_v1_5 = 1;
needNewSound = true;
} else if (entry->state == SFX_STATE_EMPTY) {
activeSound->entryIndex = 0xFF;
needNewSound = true;
} else {
for (j = 0; j < spAE; j++) {
if (temp_s4_3->unk_4 == sp84[j].unk_4) {
sp84[j].unk_4 = 0xFF;
j = spAE;
// Sound is already playing as it should, nothing to do.
for (j = 0; j < numChannels; j++) {
if (activeSound->entryIndex == chosenSounds[j].entryIndex) {
chosenSounds[j].entryIndex = 0xFF;
j = numChannels;
}
}
phi_s3--;
numChosenSounds--;
}
}
if (phi_v1_5 == 1) {
for (j = 0; j < spAE; j++) {
temp2 = sp84[j].unk_4;
if ((temp2 != 0xFF) && (gSoundBanks[arg0][temp2].unk_2A != 3)) {
for (phi_s0 = 0; phi_s0 < spAE; phi_s0++) {
if (temp2 == D_8016E1B8[arg0][phi_s0].unk_4) {
phi_v1_5 = 0;
phi_s0 = spAE;
if (needNewSound == true) {
for (j = 0; j < numChannels; j++) {
chosenEntryIndex = chosenSounds[j].entryIndex;
if ((chosenEntryIndex != 0xFF) &&
(gSoundBanks[bankId][chosenEntryIndex].state != SFX_STATE_PLAYING_REFRESH)) {
for (k = 0; k < numChannels; k++) {
if (chosenEntryIndex == gActiveSounds[bankId][k].entryIndex) {
needNewSound = false;
k = numChannels; // "break;"
}
}
if (phi_v1_5 == 1) {
temp_s4_3->unk_4 = temp2;
sp84[j].unk_4 = 0xFF;
j = spAE + 1;
phi_s3--;
if (needNewSound == true) {
activeSound->entryIndex = chosenEntryIndex;
chosenSounds[j].entryIndex = 0xFF;
j = numChannels + 1;
numChosenSounds--;
}
}
}
if (j == spAE) {
temp_s4_3->unk_4 = 0xFF;
if (j == numChannels) {
// nothing found
activeSound->entryIndex = 0xFF;
}
}
}
}
void func_800F8480(u8 bankId) {
u8 bankIndex;
SequenceChannel* seqChannel;
void Audio_PlayActiveSounds(u8 bankId) {
u8 entryIndex;
SequenceChannel* channel;
SoundBankEntry* entry;
u8 i;
for (i = 0; i < D_80130578[D_801333CC][bankId]; i++) {
bankIndex = D_8016E1B8[bankId][i].unk_4;
if (bankIndex != 0xFF) {
entry = &gSoundBanks[bankId][bankIndex];
seqChannel = gAudioContext.seqPlayers[2].channels[D_8016E260];
if (entry->unk_2A == 2) {
entry->unk_2E = D_8016E260;
for (i = 0; i < gChannelsPerBank[gSfxChannelLayout][bankId]; i++) {
entryIndex = gActiveSounds[bankId][i].entryIndex;
if (entryIndex != 0xFF) {
entry = &gSoundBanks[bankId][entryIndex];
channel = gAudioContext.seqPlayers[2].channels[sCurSfxPlayerChannelIdx];
if (entry->state == SFX_STATE_READY) {
entry->channelIdx = sCurSfxPlayerChannelIdx;
if (entry->sfxParams & 8) {
Audio_QueueSeqCmdMute(D_8016E260);
Audio_QueueSeqCmdMute(sCurSfxPlayerChannelIdx);
}
if (entry->sfxParams & 0xC0) {
switch (entry->sfxParams & 0xC0) {
@ -502,47 +518,48 @@ void func_800F8480(u8 bankId) {
break;
}
}
Audio_SetSoundProperties(bankId, bankIndex, D_8016E260);
Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8), 1);
Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 4, entry->sfxId & 0xFF);
if (D_80130570[bankId] != 0) {
Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 5, (entry->sfxId & 0x100) >> 8);
Audio_SetSoundProperties(bankId, entryIndex, sCurSfxPlayerChannelIdx);
Audio_QueueCmdS8(0x06020000 | ((sCurSfxPlayerChannelIdx & 0xFF) << 8), 1);
Audio_QueueCmdS8(0x06020000 | ((sCurSfxPlayerChannelIdx & 0xFF) << 8) | 4, entry->sfxId & 0xFF);
if (gIsLargeSoundBank[bankId]) {
Audio_QueueCmdS8(0x06020000 | ((sCurSfxPlayerChannelIdx & 0xFF) << 8) | 5,
(entry->sfxId & 0x100) >> 8);
}
if (entry->sfxId & 0xC00) {
entry->unk_2A = 4;
entry->state = SFX_STATE_PLAYING_1;
} else {
entry->unk_2A = 5;
entry->state = SFX_STATE_PLAYING_2;
}
} else if ((u8)seqChannel->soundScriptIO[1] == 0xFF) {
func_800F7B54(bankId, bankIndex);
} else if (entry->unk_2A == 3) {
Audio_SetSoundProperties(bankId, bankIndex, D_8016E260);
} else if ((u8)channel->soundScriptIO[1] == 0xFF) {
Audio_RemoveSoundBankEntry(bankId, entryIndex);
} else if (entry->state == SFX_STATE_PLAYING_REFRESH) {
Audio_SetSoundProperties(bankId, entryIndex, sCurSfxPlayerChannelIdx);
if (entry->sfxId & 0xC00) {
entry->unk_2A = 4;
entry->state = SFX_STATE_PLAYING_1;
} else {
entry->unk_2A = 5;
entry->state = SFX_STATE_PLAYING_2;
}
}
}
D_8016E260++;
sCurSfxPlayerChannelIdx++;
}
}
void func_800F87A0(u8 bankId) {
void Audio_StopSfxByBank(u8 bankId) {
SoundBankEntry* entry;
s32 pad;
SoundBankEntry cmp;
u8 bankIndex = gSoundBanks[bankId][0].next;
u8 entryIndex = gSoundBanks[bankId][0].next;
while (bankIndex != 0xFF) {
entry = &gSoundBanks[bankId][bankIndex];
if (entry->unk_2A >= 3) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0);
while (entryIndex != 0xFF) {
entry = &gSoundBanks[bankId][entryIndex];
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x06020000 | ((entry->channelIdx & 0xFF) << 8), 0);
}
if (entry->unk_2A != 0) {
func_800F7B54(bankId, bankIndex);
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSoundBankEntry(bankId, entryIndex);
}
bankIndex = gSoundBanks[bankId][0].next;
entryIndex = gSoundBanks[bankId][0].next;
}
cmp.sfxId = bankId << 12;
Audio_RemoveMatchingSoundRequests(0, &cmp);
@ -550,26 +567,26 @@ void func_800F87A0(u8 bankId) {
void func_800F8884(u8 bankId, Vec3f* pos) {
SoundBankEntry* entry;
u8 bankIndex = gSoundBanks[bankId][0].next;
u8 bankIndex2 = 0;
u8 entryIndex = gSoundBanks[bankId][0].next;
u8 prevEntryIndex = 0;
while (bankIndex != 0xFF) {
entry = &gSoundBanks[bankId][bankIndex];
while (entryIndex != 0xFF) {
entry = &gSoundBanks[bankId][entryIndex];
if (entry->posX == &pos->x) {
if (entry->unk_2A >= 3) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0);
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x06020000 | ((entry->channelIdx & 0xFF) << 8), 0);
}
if (entry->unk_2A != 0) {
func_800F7B54(bankId, bankIndex);
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSoundBankEntry(bankId, entryIndex);
}
} else {
bankIndex2 = bankIndex;
prevEntryIndex = entryIndex;
}
bankIndex = gSoundBanks[bankId][bankIndex2].next;
entryIndex = gSoundBanks[bankId][prevEntryIndex].next;
}
}
void func_800F89A0(u8 bankId, Vec3f* pos) {
void Audio_StopSfxByPosAndBank(u8 bankId, Vec3f* pos) {
SoundBankEntry cmp;
func_800F8884(bankId, pos);
@ -578,7 +595,7 @@ void func_800F89A0(u8 bankId, Vec3f* pos) {
Audio_RemoveMatchingSoundRequests(1, &cmp);
}
void func_800F89E8(Vec3f* pos) {
void Audio_StopSfxByPos(Vec3f* pos) {
u8 i;
SoundBankEntry cmp;
@ -589,27 +606,27 @@ void func_800F89E8(Vec3f* pos) {
Audio_RemoveMatchingSoundRequests(2, &cmp);
}
void func_800F8A44(Vec3f* pos, u16 sfxId) {
void Audio_StopSfxByPosAndId(Vec3f* pos, u16 sfxId) {
SoundBankEntry* entry;
u8 bankIndex = gSoundBanks[SFX_BANK(sfxId)][0].next;
u8 bankIndex2 = 0;
u8 entryIndex = gSoundBanks[SFX_BANK(sfxId)][0].next;
u8 prevEntryIndex = 0;
SoundBankEntry cmp;
while (bankIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex];
while (entryIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->posX == &pos->x && entry->sfxId == sfxId) {
if (entry->unk_2A >= 3) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0);
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x06020000 | ((entry->channelIdx & 0xFF) << 8), 0);
}
if (entry->unk_2A != 0) {
func_800F7B54(SFX_BANK(sfxId), bankIndex);
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSoundBankEntry(SFX_BANK(sfxId), entryIndex);
}
bankIndex = 0xFF;
entryIndex = 0xFF;
} else {
bankIndex2 = bankIndex;
prevEntryIndex = entryIndex;
}
if (bankIndex != 0xFF) {
bankIndex = gSoundBanks[SFX_BANK(sfxId)][bankIndex2].next;
if (entryIndex != 0xFF) {
entryIndex = gSoundBanks[SFX_BANK(sfxId)][prevEntryIndex].next;
}
}
cmp.posX = &pos->x;
@ -617,52 +634,52 @@ void func_800F8A44(Vec3f* pos, u16 sfxId) {
Audio_RemoveMatchingSoundRequests(3, &cmp);
}
void func_800F8BA0(u8 arg0, u16 sfxId) {
void Audio_StopSfxByTokenAndId(u8 token, u16 sfxId) {
SoundBankEntry* entry;
u8 bankIndex = gSoundBanks[SFX_BANK(sfxId)][0].next;
u8 bankIndex2 = 0;
u8 entryIndex = gSoundBanks[SFX_BANK(sfxId)][0].next;
u8 prevEntryIndex = 0;
SoundBankEntry cmp;
while (bankIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex];
if (entry->unk_C == arg0 && entry->sfxId == sfxId) {
if (entry->unk_2A >= 3) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0);
while (entryIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->token == token && entry->sfxId == sfxId) {
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x06020000 | ((entry->channelIdx & 0xFF) << 8), 0);
}
if (entry->unk_2A != 0) {
func_800F7B54(SFX_BANK(sfxId), bankIndex);
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSoundBankEntry(SFX_BANK(sfxId), entryIndex);
}
} else {
bankIndex2 = bankIndex;
prevEntryIndex = entryIndex;
}
if (bankIndex != 0xFF) {
bankIndex = gSoundBanks[SFX_BANK(sfxId)][bankIndex2].next;
if (entryIndex != 0xFF) {
entryIndex = gSoundBanks[SFX_BANK(sfxId)][prevEntryIndex].next;
}
}
cmp.unk_C = arg0;
cmp.token = token;
cmp.sfxId = sfxId;
Audio_RemoveMatchingSoundRequests(4, &cmp);
}
void Audio_StopSfx(u32 sfxId) {
void Audio_StopSfxById(u32 sfxId) {
SoundBankEntry* entry;
u8 bankIndex = gSoundBanks[SFX_BANK(sfxId)][0].next;
u8 bankIndex2 = 0;
u8 entryIndex = gSoundBanks[SFX_BANK(sfxId)][0].next;
u8 prevEntryIndex = 0;
SoundBankEntry cmp;
while (bankIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex];
while (entryIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->sfxId == sfxId) {
if (entry->unk_2A >= 3) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0);
if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x06020000 | ((entry->channelIdx & 0xFF) << 8), 0);
}
if (entry->unk_2A != 0) {
func_800F7B54(SFX_BANK(sfxId), bankIndex);
if (entry->state != SFX_STATE_EMPTY) {
Audio_RemoveSoundBankEntry(SFX_BANK(sfxId), entryIndex);
}
} else {
bankIndex2 = bankIndex;
prevEntryIndex = entryIndex;
}
bankIndex = gSoundBanks[SFX_BANK(sfxId)][bankIndex2].next;
entryIndex = gSoundBanks[SFX_BANK(sfxId)][prevEntryIndex].next;
}
cmp.sfxId = sfxId;
Audio_RemoveMatchingSoundRequests(5, &cmp);
@ -675,72 +692,72 @@ void Audio_ProcessSoundRequests(void) {
}
}
void func_800F8EA0(u8 arg0, u8 arg1, u16 arg2) {
if (arg2 == 0) {
arg2++;
void Audio_SetUnusedBankLerp(u8 bankId, u8 target, u16 delay) {
if (delay == 0) {
delay++;
}
D_8016E270[arg0].unk_4 = arg1 / 127.0f;
D_8016E270[arg0].unk_C = arg2;
D_8016E270[arg0].unk_8 = ((D_8016E270[arg0].unk_0 - D_8016E270[arg0].unk_4) / arg2);
sUnusedBankLerp[bankId].target = target / 127.0f;
sUnusedBankLerp[bankId].remainingFrames = delay;
sUnusedBankLerp[bankId].step = ((sUnusedBankLerp[bankId].value - sUnusedBankLerp[bankId].target) / delay);
}
void func_800F8F34(u8 arg0) {
if (D_8016E270[arg0].unk_C != 0) {
D_8016E270[arg0].unk_C--;
if (D_8016E270[arg0].unk_C != 0) {
D_8016E270[arg0].unk_0 -= D_8016E270[arg0].unk_8;
void Audio_StepUnusedBankLerp(u8 bankId) {
if (sUnusedBankLerp[bankId].remainingFrames != 0) {
sUnusedBankLerp[bankId].remainingFrames--;
if (sUnusedBankLerp[bankId].remainingFrames != 0) {
sUnusedBankLerp[bankId].value -= sUnusedBankLerp[bankId].step;
} else {
D_8016E270[arg0].unk_0 = D_8016E270[arg0].unk_4;
sUnusedBankLerp[bankId].value = sUnusedBankLerp[bankId].target;
}
}
}
void func_800F8F88(void) {
u8 i;
u8 bankId;
if (IS_SEQUENCE_CHANNEL_VALID(gAudioContext.seqPlayers[2].channels[0])) {
D_8016E260 = 0;
for (i = 0; i < ARRAY_COUNT(gSoundBanks); i++) {
func_800F7CEC(i);
func_800F8480(i);
func_800F8F34(i);
sCurSfxPlayerChannelIdx = 0;
for (bankId = 0; bankId < ARRAY_COUNT(gSoundBanks); bankId++) {
Audio_ChooseActiveSounds(bankId);
Audio_PlayActiveSounds(bankId);
Audio_StepUnusedBankLerp(bankId);
}
}
}
u8 Audio_IsSfxPlaying(u32 sfxId) {
SoundBankEntry* entry;
u8 bankIndex = gSoundBanks[SFX_BANK(sfxId)][0].next;
u8 entryIndex = gSoundBanks[SFX_BANK(sfxId)][0].next;
while (bankIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex];
while (entryIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->sfxId == sfxId) {
return true;
}
bankIndex = entry->next;
entryIndex = entry->next;
}
return false;
}
void func_800F905C(void) {
void Audio_ResetSounds(void) {
u8 bankId;
u8 i;
u8 bankIndex;
u8 entryIndex;
sSoundRequestWriteIndex = 0;
sSoundRequestReadIndex = 0;
D_801333D0 = 0;
for (bankId = 0; bankId < ARRAY_COUNT(gSoundBanks); bankId++) {
D_8016E1A0[bankId] = 0;
D_8016E1A8[bankId] = 1;
D_8016E1B0[bankId] = 0;
sSoundBankListEnd[bankId] = 0;
sSoundBankFreeListStart[bankId] = 1;
sSoundBankUnused[bankId] = 0;
gSoundBankMuted[bankId] = false;
D_8016E270[bankId].unk_0 = 1.0f;
D_8016E270[bankId].unk_C = 0;
sUnusedBankLerp[bankId].value = 1.0f;
sUnusedBankLerp[bankId].remainingFrames = 0;
}
for (bankId = 0; bankId < ARRAY_COUNT(gSoundBanks); bankId++) {
for (i = 0; i < 3; i++) {
D_8016E1B8[bankId][i].unk_4 = 0xFF;
for (i = 0; i < MAX_CHANNELS_PER_BANK; i++) {
gActiveSounds[bankId][i].entryIndex = 0xFF;
}
}
for (bankId = 0; bankId < ARRAY_COUNT(gSoundBanks); bankId++) {
@ -755,9 +772,9 @@ void func_800F905C(void) {
}
if (D_801333F8 == 0) {
for (bankId = 0; bankId < 10; bankId++) {
gAudioSEFlagSwapSource[bankId] = 0;
gAudioSEFlagSwapTarget[bankId] = 0;
gAudioSEFlagSwapMode[bankId] = 0;
gAudioSfxSwapSource[bankId] = 0;
gAudioSfxSwapTarget[bankId] = 0;
gAudioSfxSwapMode[bankId] = 0;
}
D_801333F8++;
}

View file

@ -9,56 +9,55 @@ extern u8 sSeqCmdRdPos;
extern u8 sSeqCmdWrPos;
extern u8 D_80133408;
extern u8 D_80133418;
extern u8 D_801333CC;
extern u8 D_80133410[];
// TODO: clean up these macros. They are similar to ones in code_800EC960.c but without casts.
#define Audio_StartSeq(seqIdx, fadeTimer, seqId) \
Audio_QueueSeqCmd(0x00000000 | ((seqIdx) << 24) | ((fadeTimer) << 16) | (seqId))
#define Audio_SeqCmdA(seqIdx, a) Audio_QueueSeqCmd(0xA0000000 | ((seqIdx) << 24) | (a))
#define Audio_SeqCmdB30(seqIdx, a, b) Audio_QueueSeqCmd(0xB0003000 | ((seqIdx) << 24) | ((a) << 16) | (b))
#define Audio_SeqCmdB40(seqIdx, a, b) Audio_QueueSeqCmd(0xB0004000 | ((seqIdx) << 24) | ((a) << 16) | (b))
#define Audio_SeqCmd3(seqIdx, a) Audio_QueueSeqCmd(0x30000000 | ((seqIdx) << 24) | (a))
#define Audio_SeqCmd5(seqIdx, a, b) Audio_QueueSeqCmd(0x50000000 | ((seqIdx) << 24) | ((a) << 16) | (b))
#define Audio_SeqCmd4(seqIdx, a, b) Audio_QueueSeqCmd(0x40000000 | ((seqIdx) << 24) | ((a) << 16) | (b))
#define Audio_SetVolScaleNow(seqIdx, volFadeTimer, volScale) \
Audio_ProcessSeqCmd(0x40000000 | ((u8)seqIdx << 24) | ((u8)volFadeTimer << 16) | ((u8)(volScale * 127.0f)));
#define Audio_StartSeq(playerIdx, fadeTimer, seqId) \
Audio_QueueSeqCmd(0x00000000 | ((playerIdx) << 24) | ((fadeTimer) << 16) | (seqId))
#define Audio_SeqCmdA(playerIdx, a) Audio_QueueSeqCmd(0xA0000000 | ((playerIdx) << 24) | (a))
#define Audio_SeqCmdB30(playerIdx, a, b) Audio_QueueSeqCmd(0xB0003000 | ((playerIdx) << 24) | ((a) << 16) | (b))
#define Audio_SeqCmdB40(playerIdx, a, b) Audio_QueueSeqCmd(0xB0004000 | ((playerIdx) << 24) | ((a) << 16) | (b))
#define Audio_SeqCmd3(playerIdx, a) Audio_QueueSeqCmd(0x30000000 | ((playerIdx) << 24) | (a))
#define Audio_SeqCmd5(playerIdx, a, b) Audio_QueueSeqCmd(0x50000000 | ((playerIdx) << 24) | ((a) << 16) | (b))
#define Audio_SeqCmd4(playerIdx, a, b) Audio_QueueSeqCmd(0x40000000 | ((playerIdx) << 24) | ((a) << 16) | (b))
#define Audio_SetVolScaleNow(playerIdx, volFadeTimer, volScale) \
Audio_ProcessSeqCmd(0x40000000 | ((u8)playerIdx << 24) | ((u8)volFadeTimer << 16) | ((u8)(volScale * 127.0f)));
void func_800F9280(u8 seqIdx, u8 seqId, u8 arg2, u16 fadeTimer) {
void func_800F9280(u8 playerIdx, u8 seqId, u8 arg2, u16 fadeTimer) {
u8 i;
u16 dur;
s32 pad;
if (D_80133408 == 0 || seqIdx == 2) {
if (D_80133408 == 0 || playerIdx == 2) {
arg2 &= 0x7F;
if (arg2 == 0x7F) {
dur = (fadeTimer >> 3) * 60 * gAudioContext.audioBufferParameters.updatesPerFrame;
Audio_QueueCmdS32(0x85000000 | _SHIFTL(seqIdx, 16, 8) | _SHIFTL(seqId, 8, 8), dur);
Audio_QueueCmdS32(0x85000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(seqId, 8, 8), dur);
} else {
Audio_QueueCmdS32(0x82000000 | _SHIFTL(seqIdx, 16, 8) | _SHIFTL(seqId, 8, 8),
Audio_QueueCmdS32(0x82000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(seqId, 8, 8),
(fadeTimer * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4);
}
D_8016E750[seqIdx].unk_254 = seqId | (arg2 << 8);
D_8016E750[seqIdx].unk_256 = seqId | (arg2 << 8);
D_8016E750[playerIdx].unk_254 = seqId | (arg2 << 8);
D_8016E750[playerIdx].unk_256 = seqId | (arg2 << 8);
if (D_8016E750[seqIdx].volCur != 1.0f) {
Audio_QueueCmdF32(0x41000000 | _SHIFTL(seqIdx, 16, 8), D_8016E750[seqIdx].volCur);
if (D_8016E750[playerIdx].volCur != 1.0f) {
Audio_QueueCmdF32(0x41000000 | _SHIFTL(playerIdx, 16, 8), D_8016E750[playerIdx].volCur);
}
D_8016E750[seqIdx].unk_28 = 0;
D_8016E750[seqIdx].unk_18 = 0;
D_8016E750[seqIdx].unk_14 = 0;
D_8016E750[playerIdx].unk_28 = 0;
D_8016E750[playerIdx].unk_18 = 0;
D_8016E750[playerIdx].unk_14 = 0;
for (i = 0; i < 0x10; i++) {
D_8016E750[seqIdx].unk_50[i].unk_00 = 1.0f;
D_8016E750[seqIdx].unk_50[i].unk_0C = 0;
D_8016E750[seqIdx].unk_50[i].unk_10 = 1.0f;
D_8016E750[seqIdx].unk_50[i].unk_1C = 0;
D_8016E750[playerIdx].unk_50[i].unk_00 = 1.0f;
D_8016E750[playerIdx].unk_50[i].unk_0C = 0;
D_8016E750[playerIdx].unk_50[i].unk_10 = 1.0f;
D_8016E750[playerIdx].unk_50[i].unk_1C = 0;
}
D_8016E750[seqIdx].unk_250 = 0;
D_8016E750[seqIdx].unk_252 = 0;
D_8016E750[playerIdx].unk_250 = 0;
D_8016E750[playerIdx].unk_252 = 0;
}
}
@ -102,7 +101,7 @@ void Audio_ProcessSeqCmd(u32 cmd) {
u8 spec;
u8 op;
u8 subOp;
u8 seqIdx;
u8 playerIdx;
u8 seqId;
u8 seqArgs;
u8 found;
@ -119,7 +118,7 @@ void Audio_ProcessSeqCmd(u32 cmd) {
}
op = cmd >> 28;
seqIdx = (cmd & 0xF000000) >> 24;
playerIdx = (cmd & 0xF000000) >> 24;
switch (op) {
case 0x0:
@ -127,15 +126,15 @@ void Audio_ProcessSeqCmd(u32 cmd) {
seqId = cmd & 0xFF;
seqArgs = (cmd & 0xFF00) >> 8;
fadeTimer = (cmd & 0xFF0000) >> 13;
if ((D_8016E750[seqIdx].unk_260 == 0) && (seqArgs < 0x80)) {
func_800F9280(seqIdx, seqId, seqArgs, fadeTimer);
if ((D_8016E750[playerIdx].unk_260 == 0) && (seqArgs < 0x80)) {
func_800F9280(playerIdx, seqId, seqArgs, fadeTimer);
}
break;
case 0x1:
// disable seq player
fadeTimer = (cmd & 0xFF0000) >> 13;
func_800F9474(seqIdx, fadeTimer);
func_800F9474(playerIdx, fadeTimer);
break;
case 0x2:
@ -144,35 +143,35 @@ void Audio_ProcessSeqCmd(u32 cmd) {
seqArgs = (cmd & 0xFF00) >> 8;
fadeTimer = (cmd & 0xFF0000) >> 13;
new_var = seqArgs;
for (i = 0; i < D_8016E348[seqIdx]; i++) {
if (D_8016E320[seqIdx][i].unk_0 == seqId) {
for (i = 0; i < D_8016E348[playerIdx]; i++) {
if (D_8016E320[playerIdx][i].unk_0 == seqId) {
if (i == 0) {
func_800F9280(seqIdx, seqId, seqArgs, fadeTimer);
func_800F9280(playerIdx, seqId, seqArgs, fadeTimer);
}
return;
}
}
found = D_8016E348[seqIdx];
for (i = 0; i < D_8016E348[seqIdx]; i++) {
if (D_8016E320[seqIdx][i].unk_1 <= new_var) {
found = D_8016E348[playerIdx];
for (i = 0; i < D_8016E348[playerIdx]; i++) {
if (D_8016E320[playerIdx][i].unk_1 <= new_var) {
found = i;
i = D_8016E348[seqIdx]; // "break;"
i = D_8016E348[playerIdx]; // "break;"
}
}
if (D_8016E348[seqIdx] < 5) {
D_8016E348[seqIdx]++;
if (D_8016E348[playerIdx] < 5) {
D_8016E348[playerIdx]++;
}
for (i = D_8016E348[seqIdx] - 1; i != found; i--) {
D_8016E320[seqIdx][i].unk_1 = D_8016E320[seqIdx][i - 1].unk_1;
D_8016E320[seqIdx][i].unk_0 = D_8016E320[seqIdx][i - 1].unk_0;
for (i = D_8016E348[playerIdx] - 1; i != found; i--) {
D_8016E320[playerIdx][i].unk_1 = D_8016E320[playerIdx][i - 1].unk_1;
D_8016E320[playerIdx][i].unk_0 = D_8016E320[playerIdx][i - 1].unk_0;
}
D_8016E320[seqIdx][found].unk_1 = seqArgs;
D_8016E320[seqIdx][found].unk_0 = seqId;
D_8016E320[playerIdx][found].unk_1 = seqArgs;
D_8016E320[playerIdx][found].unk_0 = seqId;
if (found == 0) {
func_800F9280(seqIdx, seqId, seqArgs, fadeTimer);
func_800F9280(playerIdx, seqId, seqArgs, fadeTimer);
}
break;
@ -181,26 +180,26 @@ void Audio_ProcessSeqCmd(u32 cmd) {
seqId = cmd & 0xFF;
fadeTimer = (cmd & 0xFF0000) >> 13;
found = D_8016E348[seqIdx];
for (i = 0; i < D_8016E348[seqIdx]; i++) {
if (D_8016E320[seqIdx][i].unk_0 == seqId) {
found = D_8016E348[playerIdx];
for (i = 0; i < D_8016E348[playerIdx]; i++) {
if (D_8016E320[playerIdx][i].unk_0 == seqId) {
found = i;
i = D_8016E348[seqIdx]; // "break;"
i = D_8016E348[playerIdx]; // "break;"
}
}
if (found != D_8016E348[seqIdx]) {
for (i = found; i < D_8016E348[seqIdx] - 1; i++) {
D_8016E320[seqIdx][i].unk_1 = D_8016E320[seqIdx][i + 1].unk_1;
D_8016E320[seqIdx][i].unk_0 = D_8016E320[seqIdx][i + 1].unk_0;
if (found != D_8016E348[playerIdx]) {
for (i = found; i < D_8016E348[playerIdx] - 1; i++) {
D_8016E320[playerIdx][i].unk_1 = D_8016E320[playerIdx][i + 1].unk_1;
D_8016E320[playerIdx][i].unk_0 = D_8016E320[playerIdx][i + 1].unk_0;
}
D_8016E348[seqIdx]--;
D_8016E348[playerIdx]--;
}
if (found == 0) {
func_800F9474(seqIdx, fadeTimer);
if (D_8016E348[seqIdx] != 0) {
func_800F9280(seqIdx, D_8016E320[seqIdx][0].unk_0, D_8016E320[seqIdx][0].unk_1, fadeTimer);
func_800F9474(playerIdx, fadeTimer);
if (D_8016E348[playerIdx] != 0) {
func_800F9280(playerIdx, D_8016E320[playerIdx][0].unk_0, D_8016E320[playerIdx][0].unk_1, fadeTimer);
}
}
break;
@ -212,10 +211,11 @@ void Audio_ProcessSeqCmd(u32 cmd) {
if (duration == 0) {
duration++;
}
D_8016E750[seqIdx].volTarget = (f32)val / 127.0f;
if (D_8016E750[seqIdx].volCur != D_8016E750[seqIdx].volTarget) {
D_8016E750[seqIdx].unk_08 = (D_8016E750[seqIdx].volCur - D_8016E750[seqIdx].volTarget) / (f32)duration;
D_8016E750[seqIdx].unk_0C = duration;
D_8016E750[playerIdx].volTarget = (f32)val / 127.0f;
if (D_8016E750[playerIdx].volCur != D_8016E750[playerIdx].volTarget) {
D_8016E750[playerIdx].unk_08 =
(D_8016E750[playerIdx].volCur - D_8016E750[playerIdx].volTarget) / (f32)duration;
D_8016E750[playerIdx].unk_0C = duration;
}
break;
@ -228,11 +228,12 @@ void Audio_ProcessSeqCmd(u32 cmd) {
}
freqScale = (f32)val / 1000.0f;
for (i = 0; i < 16; i++) {
D_8016E750[seqIdx].unk_50[i].unk_14 = freqScale;
D_8016E750[seqIdx].unk_50[i].unk_1C = duration;
D_8016E750[seqIdx].unk_50[i].unk_18 = (D_8016E750[seqIdx].unk_50[i].unk_10 - freqScale) / (f32)duration;
D_8016E750[playerIdx].unk_50[i].unk_14 = freqScale;
D_8016E750[playerIdx].unk_50[i].unk_1C = duration;
D_8016E750[playerIdx].unk_50[i].unk_18 =
(D_8016E750[playerIdx].unk_50[i].unk_10 - freqScale) / (f32)duration;
}
D_8016E750[seqIdx].unk_250 = 0xFFFF;
D_8016E750[playerIdx].unk_250 = 0xFFFF;
break;
case 0xD:
@ -244,11 +245,11 @@ void Audio_ProcessSeqCmd(u32 cmd) {
duration++;
}
freqScale = (f32)val / 1000.0f;
D_8016E750[seqIdx].unk_50[chanIdx].unk_14 = freqScale;
D_8016E750[seqIdx].unk_50[chanIdx].unk_18 =
(D_8016E750[seqIdx].unk_50[chanIdx].unk_10 - freqScale) / (f32)duration;
D_8016E750[seqIdx].unk_50[chanIdx].unk_1C = duration;
D_8016E750[seqIdx].unk_250 |= 1 << chanIdx;
D_8016E750[playerIdx].unk_50[chanIdx].unk_14 = freqScale;
D_8016E750[playerIdx].unk_50[chanIdx].unk_18 =
(D_8016E750[playerIdx].unk_50[chanIdx].unk_10 - freqScale) / (f32)duration;
D_8016E750[playerIdx].unk_50[chanIdx].unk_1C = duration;
D_8016E750[playerIdx].unk_250 |= 1 << chanIdx;
break;
case 0x6:
@ -259,13 +260,13 @@ void Audio_ProcessSeqCmd(u32 cmd) {
if (duration == 0) {
duration++;
}
D_8016E750[seqIdx].unk_50[chanIdx].unk_04 = (f32)val / 127.0f;
if (D_8016E750[seqIdx].unk_50[chanIdx].unk_00 != D_8016E750[seqIdx].unk_50[chanIdx].unk_04) {
D_8016E750[seqIdx].unk_50[chanIdx].unk_08 =
(D_8016E750[seqIdx].unk_50[chanIdx].unk_00 - D_8016E750[seqIdx].unk_50[chanIdx].unk_04) /
D_8016E750[playerIdx].unk_50[chanIdx].unk_04 = (f32)val / 127.0f;
if (D_8016E750[playerIdx].unk_50[chanIdx].unk_00 != D_8016E750[playerIdx].unk_50[chanIdx].unk_04) {
D_8016E750[playerIdx].unk_50[chanIdx].unk_08 =
(D_8016E750[playerIdx].unk_50[chanIdx].unk_00 - D_8016E750[playerIdx].unk_50[chanIdx].unk_04) /
(f32)duration;
D_8016E750[seqIdx].unk_50[chanIdx].unk_0C = duration;
D_8016E750[seqIdx].unk_252 |= 1 << chanIdx;
D_8016E750[playerIdx].unk_50[chanIdx].unk_0C = duration;
D_8016E750[playerIdx].unk_252 |= 1 << chanIdx;
}
break;
@ -273,7 +274,7 @@ void Audio_ProcessSeqCmd(u32 cmd) {
// set global io port
port = (cmd & 0xFF0000) >> 16;
val = cmd & 0xFF;
Audio_QueueCmdS8(0x46000000 | _SHIFTL(seqIdx, 16, 8) | _SHIFTL(port, 0, 8), val);
Audio_QueueCmdS8(0x46000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(port, 0, 8), val);
break;
case 0x8:
@ -281,15 +282,15 @@ void Audio_ProcessSeqCmd(u32 cmd) {
chanIdx = (cmd & 0xF00) >> 8;
port = (cmd & 0xFF0000) >> 16;
val = cmd & 0xFF;
if ((D_8016E750[seqIdx].unk_258 & (1 << chanIdx)) == 0) {
Audio_QueueCmdS8(0x06000000 | _SHIFTL(seqIdx, 16, 8) | _SHIFTL(chanIdx, 8, 8) | _SHIFTL(port, 0, 8),
if ((D_8016E750[playerIdx].unk_258 & (1 << chanIdx)) == 0) {
Audio_QueueCmdS8(0x06000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(chanIdx, 8, 8) | _SHIFTL(port, 0, 8),
val);
}
break;
case 0x9:
// set channel mask for command 0x8
D_8016E750[seqIdx].unk_258 = cmd & 0xFFFF;
D_8016E750[playerIdx].unk_258 = cmd & 0xFFFF;
break;
case 0xA:
@ -297,36 +298,36 @@ void Audio_ProcessSeqCmd(u32 cmd) {
channelMask = cmd & 0xFFFF;
if (channelMask != 0) {
// with channel mask channelMask...
Audio_QueueCmdU16(0x90000000 | _SHIFTL(seqIdx, 16, 8), channelMask);
Audio_QueueCmdU16(0x90000000 | _SHIFTL(playerIdx, 16, 8), channelMask);
// stop channels
Audio_QueueCmdS8(0x08000000 | _SHIFTL(seqIdx, 16, 8) | 0xFF00, 1);
Audio_QueueCmdS8(0x08000000 | _SHIFTL(playerIdx, 16, 8) | 0xFF00, 1);
}
if ((channelMask ^ 0xFFFF) != 0) {
// with channel mask ~channelMask...
Audio_QueueCmdU16(0x90000000 | _SHIFTL(seqIdx, 16, 8), (channelMask ^ 0xFFFF));
Audio_QueueCmdU16(0x90000000 | _SHIFTL(playerIdx, 16, 8), (channelMask ^ 0xFFFF));
// unstop channels
Audio_QueueCmdS8(0x08000000 | _SHIFTL(seqIdx, 16, 8) | 0xFF00, 0);
Audio_QueueCmdS8(0x08000000 | _SHIFTL(playerIdx, 16, 8) | 0xFF00, 0);
}
break;
case 0xB:
// update tempo
D_8016E750[seqIdx].unk_14 = cmd;
D_8016E750[playerIdx].unk_14 = cmd;
break;
case 0xC:
// start sequence with setup commands
subOp = (cmd & 0xF00000) >> 20;
if (subOp != 0xF) {
if (D_8016E750[seqIdx].unk_4D < 7) {
found = D_8016E750[seqIdx].unk_4D++;
if (D_8016E750[playerIdx].unk_4D < 7) {
found = D_8016E750[playerIdx].unk_4D++;
if (found < 8) {
D_8016E750[seqIdx].unk_2C[found] = cmd;
D_8016E750[seqIdx].unk_4C = 2;
D_8016E750[playerIdx].unk_2C[found] = cmd;
D_8016E750[playerIdx].unk_4C = 2;
}
}
} else {
D_8016E750[seqIdx].unk_4D = 0;
D_8016E750[playerIdx].unk_4D = 0;
}
break;
@ -348,7 +349,7 @@ void Audio_ProcessSeqCmd(u32 cmd) {
case 0xF:
// change spec
spec = cmd & 0xFF;
D_801333CC = (cmd & 0xFF00) >> 8;
gSfxChannelLayout = (cmd & 0xFF00) >> 8;
oldSpec = gAudioSpecId;
gAudioSpecId = spec;
func_800E5F88(spec);
@ -403,21 +404,21 @@ void func_800FA18C(u8 arg0, u8 arg1) {
}
}
void Audio_SetVolScale(u8 seqIdx, u8 scaleIdx, u8 targetVol, u8 volFadeTimer) {
void Audio_SetVolScale(u8 playerIdx, u8 scaleIdx, u8 targetVol, u8 volFadeTimer) {
f32 volScale;
u8 i;
D_8016E750[seqIdx].volScales[scaleIdx] = targetVol & 0x7F;
D_8016E750[playerIdx].volScales[scaleIdx] = targetVol & 0x7F;
if (volFadeTimer != 0) {
D_8016E750[seqIdx].fadeVolUpdate = 1;
D_8016E750[seqIdx].volFadeTimer = volFadeTimer;
D_8016E750[playerIdx].fadeVolUpdate = 1;
D_8016E750[playerIdx].volFadeTimer = volFadeTimer;
} else {
for (i = 0, volScale = 1.0f; i < 4; i++) {
volScale *= D_8016E750[seqIdx].volScales[i] / 127.0f;
volScale *= D_8016E750[playerIdx].volScales[i] / 127.0f;
}
Audio_SetVolScaleNow(seqIdx, volFadeTimer, volScale);
Audio_SetVolScaleNow(playerIdx, volFadeTimer, volScale);
}
}
@ -432,7 +433,7 @@ void func_800FA3DC(void) {
u8 temp_s0_3;
u8 temp_a3_3;
s32 pad[3];
u32 sp70;
u32 dummy;
f32 phi_f0;
u8 phi_t0;
u8 i;
@ -441,7 +442,7 @@ void func_800FA3DC(void) {
for (i = 0; i < 4; i++) {
if (D_8016E750[i].unk_260 != 0) {
switch (func_800E5E20(&sp70)) {
switch (func_800E5E20(&dummy)) {
case 1:
case 2:
case 3:
@ -624,13 +625,13 @@ void func_800FA3DC(void) {
break;
case 14:
if (temp_a3_3 & 1) {
Audio_QueueCmdS32(0xE3000000, 0);
Audio_QueueCmdS32(0xE3000000, SEQUENCE_TABLE);
}
if (temp_a3_3 & 2) {
Audio_QueueCmdS32(0xE3000000, 1);
Audio_QueueCmdS32(0xE3000000, FONT_TABLE);
}
if (temp_a3_3 & 4) {
Audio_QueueCmdS32(0xE3000000, 2);
Audio_QueueCmdS32(0xE3000000, SAMPLE_TABLE);
}
break;
case 9:
@ -653,13 +654,13 @@ u8 func_800FAD34(void) {
if (D_80133418 == 1) {
if (func_800E5EDC() == 1) {
D_80133418 = 0;
Audio_QueueCmdS8(0x46020000, D_801333CC);
Audio_QueueCmdS8(0x46020000, gSfxChannelLayout);
func_800F7170();
}
} else if (D_80133418 == 2) {
while (func_800E5EDC() != 1) {}
D_80133418 = 0;
Audio_QueueCmdS8(0x46020000, D_801333CC);
Audio_QueueCmdS8(0x46020000, gSfxChannelLayout);
func_800F7170();
}
}

View file

@ -51,7 +51,7 @@ void Fault_ClientProcessThread(void* arg) {
}
if (ctx->queue != NULL) {
osSendMesg(ctx->queue, ctx->msg, 1);
osSendMesg(ctx->queue, ctx->msg, OS_MESG_BLOCK);
}
}
@ -81,7 +81,7 @@ void Fault_ProcessClientContext(FaultClientContext* ctx) {
while (true) {
osSetTimer(&timer, OS_USEC_TO_CYCLES(1000000), 0, &queue, (OSMesg)timerMsgVal);
osRecvMesg(&queue, &recMsg, 1);
osRecvMesg(&queue, &recMsg, OS_MESG_BLOCK);
if (recMsg != (OSMesg)666) {
break;
@ -957,7 +957,7 @@ void Fault_ThreadEntry(void* arg) {
while (true) {
do {
osRecvMesg(&sFaultStructPtr->queue, &msg, 1);
osRecvMesg(&sFaultStructPtr->queue, &msg, OS_MESG_BLOCK);
if (msg == (OSMesg)1) {
sFaultStructPtr->msgId = 1;

View file

@ -87,7 +87,7 @@ void Sched_HandleReset(SchedContext* sc) {
if (sc->curRDPTask != NULL) {
LOG_TIME("(((u64)(now - rdp_start_time)*(1000000LL/15625LL))/((62500000LL*3/4)/15625LL))",
OS_CYCLES_TO_USEC(now - sRDPStartTime), "../sched.c", 431);
osSendMesg(&sc->interruptQ, RDP_DONE_MSG, 0);
osSendMesg(&sc->interruptQ, RDP_DONE_MSG, OS_MESG_NOBLOCK);
}
}
}

View file

@ -2837,7 +2837,7 @@ Actor* Actor_Delete(ActorContext* actorCtx, Actor* actor, GlobalContext* globalC
actorCtx->targetCtx.unk_90 = NULL;
}
func_800F89E8(&actor->projectedPos);
Audio_StopSfxByPos(&actor->projectedPos);
Actor_Destroy(actor, globalCtx);
newHead = Actor_RemoveFromCategory(globalCtx, actorCtx, actor);

View file

@ -7129,7 +7129,7 @@ s32 Camera_CheckWater(Camera* camera) {
camera->unk_150 = 0x50;
}
func_800F6828(0x20);
Audio_SetExtraFilter(0x20);
if (PREG(81)) {
Quake_RemoveFromIdx(*quakeId);
@ -7164,7 +7164,7 @@ s32 Camera_CheckWater(Camera* camera) {
camera->unk_150 = 0;
camera->unk_152 = 0;
}
func_800F6828(0);
Audio_SetExtraFilter(0);
}
//! @bug: doesn't always return a value, but sometimes does.
}

View file

@ -62,11 +62,11 @@ void EffectSs_ClearAll(GlobalContext* globalCtx) {
void EffectSs_Delete(EffectSs* effectSs) {
if (effectSs->flags & 2) {
func_800F89E8(&effectSs->pos);
Audio_StopSfxByPos(&effectSs->pos);
}
if (effectSs->flags & 4) {
func_800F89E8(&effectSs->vec);
Audio_StopSfxByPos(&effectSs->vec);
}
EffectSs_Reset(effectSs);

View file

@ -205,7 +205,7 @@ void Gameplay_Init(GameState* thisx) {
GameState_Realloc(&globalCtx->state, 0x1D4790);
KaleidoManager_Init(globalCtx);
View_Init(&globalCtx->view, gfxCtx);
func_800F6828(0);
Audio_SetExtraFilter(0);
Quake_Init();
for (i = 0; i < 4; i++) {
@ -402,7 +402,7 @@ void Gameplay_Init(GameState* thisx) {
if (dREG(95) != 0) {
D_8012D1F0 = D_801614D0;
osSyncPrintf("\nkawauso_data=[%x]", D_8012D1F0);
DmaMgr_DMARomToRam(0x03FEB000, (u32)D_8012D1F0, sizeof(D_801614D0));
DmaMgr_DmaRomToRam(0x03FEB000, (u32)D_8012D1F0, sizeof(D_801614D0));
}
}