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

Match Audio_ProcessSoundRequest (#935)

Co-authored-by: zelda2774 <zelda2774@invalid>
This commit is contained in:
zelda2774 2021-08-31 15:22:56 +02:00 committed by GitHub
parent 1117783731
commit 6ef1f3ea3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 106 additions and 444 deletions

View file

@ -1275,7 +1275,7 @@ void AudioDebug_Draw(GfxPrint* printer) {
while (i != 0xFF) {
GfxPrint_SetPos(printer, 3, 7 + j++);
GfxPrint_Printf(printer, "%02x %04x %02x %08x", i, gSoundBanks[ind][i].unk_28,
GfxPrint_Printf(printer, "%02x %04x %02x %08x", i, gSoundBanks[ind][i].sfxId,
gSoundBanks[ind][i].unk_2A, gSoundBanks[ind][i].unk_20);
i = gSoundBanks[ind][i].next;
}
@ -1341,7 +1341,7 @@ void AudioDebug_Draw(GfxPrint* printer) {
if ((entryIndex != 0xFF) && ((entry->unk_2A == 4) || (entry->unk_2A == 5))) {
GfxPrint_Printf(printer, "%2X %5d %5d %5d %02X %04X %04X", entryIndex, (s32)*entry->posX,
(s32)*entry->posY, (s32)*entry->posZ, entry->unk_24, entry->unk_26,
entry->unk_28);
entry->sfxId);
} else {
GfxPrint_Printf(printer, "FF ----- ----- ----- -- ---- ----");
}
@ -1349,7 +1349,7 @@ void AudioDebug_Draw(GfxPrint* printer) {
if ((entryIndex != 0xFF) && ((entry->unk_2A == 4) || (entry->unk_2A == 5))) {
GfxPrint_Printf(printer, "%2X %5d %5d %5d %3d %3d %04X", entryIndex, (s32)*entry->posX,
(s32)*entry->posY, (s32)*entry->posZ, (s32)(chan->volume * 127.1f),
chan->newPan, entry->unk_28);
chan->newPan, entry->sfxId);
} else {
GfxPrint_Printf(printer, "FF ----- ----- ----- --- --- ----");
}
@ -1357,13 +1357,13 @@ void AudioDebug_Draw(GfxPrint* printer) {
if ((entryIndex != 0xFF) && ((entry->unk_2A == 4) || (entry->unk_2A == 5))) {
GfxPrint_Printf(printer, "%2X %5d %5d %5d %3d %3d %04X", entryIndex, (s32)*entry->posX,
(s32)*entry->posY, (s32)*entry->posZ, (s32)(chan->freqScale * 100.0f),
chan->reverb, entry->unk_28);
chan->reverb, entry->sfxId);
} else {
GfxPrint_Printf(printer, "FF ----- ----- ----- --- --- ----");
}
} else if (sAudioIntInfoBankPage[k] == 4) {
if ((entryIndex != 0xFF) && ((entry->unk_2A == 4) || (entry->unk_2A == 5))) {
GfxPrint_Printf(printer, "%2X %04X", entryIndex, entry->unk_28);
GfxPrint_Printf(printer, "%2X %04X", entryIndex, entry->sfxId);
} else {
GfxPrint_Printf(printer, "FF ----");
}
@ -2581,7 +2581,7 @@ s8 Audio_ComputeSoundReverb(u8 bankIdx, u8 entryIdx, u8 channelIdx) {
}
reverb = *entry->reverbAdd + distAdd + scriptAdd;
if ((bankIdx != BANK_OCARINA) || !((entry->unk_28 & 0x1FF) < 2)) {
if ((bankIdx != BANK_OCARINA) || !((entry->sfxId & 0x1FF) < 2)) {
reverb += sAudioEnvReverb + sAudioCodeReverb + sSpecReverb;
}
@ -3160,7 +3160,7 @@ void func_800F4C58(Vec3f* pos, u16 sfxId, u8 arg2) {
}
for (i = 0; i < D_80130578[D_801333CC][bank]; i++) {
if ((D_8016E1B8[bank][i].unk_4 != 0xFF) && (sfxId == gSoundBanks[bank][D_8016E1B8[bank][i].unk_4].unk_28)) {
if ((D_8016E1B8[bank][i].unk_4 != 0xFF) && (sfxId == gSoundBanks[bank][D_8016E1B8[bank][i].unk_4].sfxId)) {
Audio_QueueCmdS8(_SHIFTL(6, 24, 8) | _SHIFTL(2, 16, 8) | _SHIFTL(phi_s1, 8, 8) | _SHIFTL(6, 0, 8), arg2);
}
phi_s1++;

View file

@ -155,12 +155,12 @@ void Audio_RemoveMatchingSoundRequests(u8 aspect, SoundBankEntry* cmp) {
req = &sSoundRequests[i];
switch (aspect) {
case 0:
if (SFX_BANK_MASK(req->sfxId) == SFX_BANK_MASK(cmp->unk_28)) {
if (SFX_BANK_MASK(req->sfxId) == SFX_BANK_MASK(cmp->sfxId)) {
remove = true;
}
break;
case 1:
if (SFX_BANK_MASK(req->sfxId) == SFX_BANK_MASK(cmp->unk_28) && (&req->pos->x == cmp->posX)) {
if (SFX_BANK_MASK(req->sfxId) == SFX_BANK_MASK(cmp->sfxId) && (&req->pos->x == cmp->posX)) {
remove = true;
}
break;
@ -170,17 +170,17 @@ void Audio_RemoveMatchingSoundRequests(u8 aspect, SoundBankEntry* cmp) {
}
break;
case 3:
if (&req->pos->x == cmp->posX && req->sfxId == cmp->unk_28) {
if (&req->pos->x == cmp->posX && req->sfxId == cmp->sfxId) {
remove = true;
}
break;
case 4:
if (req->unk_8 == cmp->unk_C && req->sfxId == cmp->unk_28) {
if (req->unk_8 == cmp->unk_C && req->sfxId == cmp->sfxId) {
remove = true;
}
break;
case 5:
if (req->sfxId == cmp->unk_28) {
if (req->sfxId == cmp->sfxId) {
remove = true;
}
break;
@ -191,113 +191,104 @@ void Audio_RemoveMatchingSoundRequests(u8 aspect, SoundBankEntry* cmp) {
}
}
#ifdef NON_MATCHING
// Down to a/v regalloc and some stuff where the compiler gets confused about reusing values. There's some fake matching
// stuff to improve regalloc enough to verify equivalence.
void Audio_ProcessSoundRequest(void) {
u16 flag1;
u8 sp55;
u8 phi_a1;
SoundRequest* req; // sp50
SoundBankEntry* temp_v0;
u16 sfxId;
u8 count;
u8 index;
SoundRequest* req;
SoundBankEntry* entry;
Struct_8013331C* sp48;
s32 phi_s5;
u8 sp43;
u8 phi_s1;
u16 flag2;
s32 bankId;
u8 bestValue;
u8 bestIndex;
req = &sSoundRequests[sSoundRequestReadIndex];
phi_s1 = 0x80;
bestIndex = 0x80;
if (req->sfxId == 0) {
return;
}
phi_s5 = SFX_BANK(req->sfxId);
if ((1 << phi_s5) & D_801333F0) {
bankId = SFX_BANK(req->sfxId);
if ((1 << bankId) & D_801333F0) {
AudioDebug_ScrPrt((const s8*)D_80133340, req->sfxId);
phi_s5 = SFX_BANK(req->sfxId);
bankId = SFX_BANK(req->sfxId);
}
sp55 = 0;
phi_a1 = gSoundBanks[phi_s5][0].next;
while (phi_a1 != 0xFF && phi_a1 != 0) {
if (gSoundBanks[phi_s5][phi_a1].posX == &req->pos->x) {
sp48 = &D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)];
if (!(!(sp48->unk_2 & 0x20) || sp48->unk_0 != gSoundBanks[phi_s5][phi_a1].unk_24)) {
count = 0;
index = gSoundBanks[bankId][0].next;
while (index != 0xFF && index != 0) {
if (gSoundBanks[bankId][index].posX == &req->pos->x) {
if ((D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].unk_2 & 0x20) &&
D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].unk_0 ==
gSoundBanks[bankId][index].unk_24) {
return;
}
if (gSoundBanks[phi_s5][phi_a1].unk_28 == req->sfxId) {
sp55 = D_80130594[D_801333CC][phi_s5];
if (gSoundBanks[bankId][index].sfxId == req->sfxId) {
count = D_80130594[D_801333CC][bankId];
} else {
//! @bug possibly uninitialized sp43 ? confirm when matching
if (sp55 == 0) {
phi_s1 = phi_a1;
flag1 = gSoundBanks[phi_s5][phi_a1].unk_28 & 0xFFFF;
sp43 = D_8013331C[SFX_BANK_SHIFT(flag1)][SFX_INDEX(flag1)].unk_0;
} else if (gSoundBanks[phi_s5][phi_a1].unk_24 < sp43) {
phi_s1 = phi_a1;
flag1 = gSoundBanks[phi_s5][phi_a1].unk_28 & 0xFFFF;
sp43 = D_8013331C[SFX_BANK_SHIFT(flag1)][SFX_INDEX(flag1)].unk_0;
if (count == 0) {
bestIndex = index;
sfxId = gSoundBanks[bankId][index].sfxId & 0xFFFF;
bestValue = D_8013331C[SFX_BANK_SHIFT(sfxId)][SFX_INDEX(sfxId)].unk_0;
} else if (gSoundBanks[bankId][index].unk_24 < bestValue) {
bestIndex = index;
sfxId = gSoundBanks[bankId][index].sfxId & 0xFFFF;
bestValue = D_8013331C[SFX_BANK_SHIFT(sfxId)][SFX_INDEX(sfxId)].unk_0;
}
sp55++;
if (sp55 == D_80130594[D_801333CC][phi_s5]) {
phi_a1 = (sp48->unk_0 >= sp43) ? phi_s1 : 0;
count++;
if (count == D_80130594[D_801333CC][bankId]) {
index = (D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].unk_0 >= bestValue)
? bestIndex
: 0;
}
}
if (D_80130594[D_801333CC][phi_s5] == sp55) {
flag2 = req->sfxId & 0xC00; // Problem is around here
if (count == D_80130594[D_801333CC][bankId]) {
sp48 = &D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)];
if ((flag2) || (D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].unk_2 & 4) ||
(phi_a1 == phi_s1)) {
if ((gSoundBanks[phi_s5][phi_a1].unk_26 & 8) && gSoundBanks[phi_s5][phi_a1].unk_2A != 1) {
Audio_ClearBGMMute(gSoundBanks[phi_s5][phi_a1].unk_2E);
if ((req->sfxId & 0xC00) || (sp48->unk_2 & 4) || (index == bestIndex)) {
if ((gSoundBanks[bankId][index].unk_26 & 8) && gSoundBanks[bankId][index].unk_2A != 1) {
Audio_ClearBGMMute(gSoundBanks[bankId][index].unk_2E);
}
gSoundBanks[phi_s5][phi_a1].unk_C = req->unk_8;
gSoundBanks[phi_s5][phi_a1].unk_28 = req->sfxId;
gSoundBanks[phi_s5][phi_a1].unk_2A = 1;
gSoundBanks[phi_s5][phi_a1].unk_2B = 2;
gSoundBanks[phi_s5][phi_a1].freqScale = req->freqScale;
gSoundBanks[phi_s5][phi_a1].unk_14 = req->unk_10;
gSoundBanks[phi_s5][phi_a1].reverbAdd = req->reverbAdd;
gSoundBanks[phi_s5][phi_a1].unk_26 = sp48->unk_2;
gSoundBanks[phi_s5][phi_a1].unk_24 = sp48->unk_0;
if (!sp48->unk_2) {}
} else if (gSoundBanks[phi_s5][phi_a1].unk_2A == 5) {
gSoundBanks[phi_s5][phi_a1].unk_2A = 4;
gSoundBanks[bankId][index].unk_C = req->unk_8;
gSoundBanks[bankId][index].sfxId = req->sfxId;
gSoundBanks[bankId][index].unk_2A = 1;
gSoundBanks[bankId][index].unk_2B = 2;
gSoundBanks[bankId][index].freqScale = req->freqScale;
gSoundBanks[bankId][index].unk_14 = req->unk_10;
gSoundBanks[bankId][index].reverbAdd = req->reverbAdd;
gSoundBanks[bankId][index].unk_26 = sp48->unk_2;
gSoundBanks[bankId][index].unk_24 = sp48->unk_0;
} else if (gSoundBanks[bankId][index].unk_2A == 5) {
gSoundBanks[bankId][index].unk_2A = 4;
}
phi_a1 = 0;
index = 0;
}
}
if (phi_a1 != 0) {
phi_a1 = gSoundBanks[phi_s5][phi_a1].next;
if (index != 0) {
index = gSoundBanks[bankId][index].next;
}
}
if (gSoundBanks[phi_s5][D_8016E1A8[phi_s5]].next != 0xFF && phi_a1 != 0) {
phi_a1 = D_8016E1A8[phi_s5];
temp_v0 = &gSoundBanks[phi_s5][phi_a1];
temp_v0->posX = &req->pos->x;
temp_v0->posY = &req->pos->y;
temp_v0->posZ = &req->pos->z;
temp_v0->unk_C = req->unk_8;
temp_v0->freqScale = req->freqScale;
temp_v0->unk_14 = req->unk_10;
temp_v0->reverbAdd = req->reverbAdd;
if (gSoundBanks[bankId][D_8016E1A8[bankId]].next != 0xFF && index != 0) {
index = D_8016E1A8[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->freqScale = req->freqScale;
entry->unk_14 = req->unk_10;
entry->reverbAdd = req->reverbAdd;
sp48 = &D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)];
temp_v0->unk_26 = sp48->unk_2;
temp_v0->unk_24 = sp48->unk_0;
temp_v0->unk_28 = req->sfxId;
temp_v0->unk_2A = 1;
temp_v0->unk_2B = 2;
temp_v0->prev = D_8016E1A0[phi_s5];
gSoundBanks[phi_s5][D_8016E1A0[phi_s5]].next = D_8016E1A8[phi_s5];
D_8016E1A0[phi_s5] = D_8016E1A8[phi_s5];
D_8016E1A8[phi_s5] = gSoundBanks[phi_s5][D_8016E1A8[phi_s5]].next;
gSoundBanks[phi_s5][D_8016E1A8[phi_s5]].prev = 0xFF;
temp_v0->next = 0xFF;
entry->unk_26 = sp48->unk_2;
entry->unk_24 = sp48->unk_0;
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->next = 0xFF;
}
}
#else
void Audio_ProcessSoundRequest(void);
#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F7260/Audio_ProcessSoundRequest.s")
#endif
void func_800F7B54(u8 bankId, u8 bankIndex) {
SoundBankEntry* entry = &gSoundBanks[bankId][bankIndex];
@ -351,9 +342,9 @@ void func_800F7CEC(u8 arg0) {
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].unk_28 & 0xC00)) {
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].unk_28 & 0xC00) && (gSoundBanks[arg0][phi_s4].unk_2A == 5)) {
} 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);
}
@ -374,10 +365,10 @@ void func_800F7CEC(u8 arg0) {
} else {
if (entry->dist > 0x7FFFFFD0) {
entry->dist = 0x70000008;
osSyncPrintf(D_80133344, entry->unk_28, entry->posX, entry->posZ, *entry->posX,
*entry->posY, *entry->posZ);
osSyncPrintf(D_80133344, entry->sfxId, entry->posX, entry->posZ, *entry->posX, *entry->posY,
*entry->posZ);
}
temp3 = entry->unk_28;
temp3 = entry->sfxId;
entry->unk_20 = (u32)entry->dist + (SQ(0xFF - spA9) * 0x1690) + temp3 - temp3;
if (*entry->posZ < 0.0f) {
entry->unk_20 += (s32)(-*entry->posZ * 6.0f);
@ -386,7 +377,7 @@ void func_800F7CEC(u8 arg0) {
if (entry->dist > SQ(1e5f)) {
if (entry->unk_2A == 4) {
Audio_QueueCmdS8((entry->unk_2E << 8) | 0x6020000, 0);
if (entry->unk_28 & 0xC00) {
if (entry->sfxId & 0xC00) {
func_800F7B54(arg0, phi_s4);
phi_s4 = phi_s0;
}
@ -431,7 +422,7 @@ void func_800F7CEC(u8 arg0) {
} else {
entry = &gSoundBanks[arg0][temp_s4_3[0].unk_4];
if (entry->unk_2A == 4) {
if (entry->unk_28 & 0xC00) {
if (entry->sfxId & 0xC00) {
func_800F7B54(arg0, temp_s4_3->unk_4);
} else {
entry->unk_2A = 1;
@ -512,11 +503,11 @@ void func_800F8480(u8 bankId) {
}
Audio_SetSoundProperties(bankId, bankIndex, D_8016E260);
Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8), 1);
Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 4, entry->unk_28 & 0xFF);
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->unk_28 & 0x100) >> 8);
Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 5, (entry->sfxId & 0x100) >> 8);
}
if (entry->unk_28 & 0xC00) {
if (entry->sfxId & 0xC00) {
entry->unk_2A = 4;
} else {
entry->unk_2A = 5;
@ -525,7 +516,7 @@ void func_800F8480(u8 bankId) {
func_800F7B54(bankId, bankIndex);
} else if (entry->unk_2A == 3) {
Audio_SetSoundProperties(bankId, bankIndex, D_8016E260);
if (entry->unk_28 & 0xC00) {
if (entry->sfxId & 0xC00) {
entry->unk_2A = 4;
} else {
entry->unk_2A = 5;
@ -552,7 +543,7 @@ void func_800F87A0(u8 bankId) {
}
bankIndex = gSoundBanks[bankId][0].next;
}
cmp.unk_28 = bankId << 12;
cmp.sfxId = bankId << 12;
Audio_RemoveMatchingSoundRequests(0, &cmp);
}
@ -581,7 +572,7 @@ void func_800F89A0(u8 bankId, Vec3f* pos) {
SoundBankEntry cmp;
func_800F8884(bankId, pos);
cmp.unk_28 = bankId << 12;
cmp.sfxId = bankId << 12;
cmp.posX = &pos->x;
Audio_RemoveMatchingSoundRequests(1, &cmp);
}
@ -605,7 +596,7 @@ void func_800F8A44(Vec3f* pos, u16 sfxId) {
while (bankIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex];
if (entry->posX == &pos->x && entry->unk_28 == sfxId) {
if (entry->posX == &pos->x && entry->sfxId == sfxId) {
if (entry->unk_2A >= 3) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0);
}
@ -621,7 +612,7 @@ void func_800F8A44(Vec3f* pos, u16 sfxId) {
}
}
cmp.posX = &pos->x;
cmp.unk_28 = sfxId;
cmp.sfxId = sfxId;
Audio_RemoveMatchingSoundRequests(3, &cmp);
}
@ -633,7 +624,7 @@ void func_800F8BA0(u8 arg0, u16 sfxId) {
while (bankIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex];
if (entry->unk_C == arg0 && entry->unk_28 == sfxId) {
if (entry->unk_C == arg0 && entry->sfxId == sfxId) {
if (entry->unk_2A >= 3) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0);
}
@ -648,7 +639,7 @@ void func_800F8BA0(u8 arg0, u16 sfxId) {
}
}
cmp.unk_C = arg0;
cmp.unk_28 = sfxId;
cmp.sfxId = sfxId;
Audio_RemoveMatchingSoundRequests(4, &cmp);
}
@ -660,7 +651,7 @@ void Audio_StopSfx(u32 sfxId) {
while (bankIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex];
if (entry->unk_28 == sfxId) {
if (entry->sfxId == sfxId) {
if (entry->unk_2A >= 3) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0);
}
@ -672,7 +663,7 @@ void Audio_StopSfx(u32 sfxId) {
}
bankIndex = gSoundBanks[SFX_BANK(sfxId)][bankIndex2].next;
}
cmp.unk_28 = sfxId;
cmp.sfxId = sfxId;
Audio_RemoveMatchingSoundRequests(5, &cmp);
}
@ -722,7 +713,7 @@ u8 Audio_IsSfxPlaying(u32 sfxId) {
while (bankIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex];
if (entry->unk_28 == sfxId) {
if (entry->sfxId == sfxId) {
return true;
}
bankIndex = entry->next;