various Z2Audio / JAudio debug cleanup (#2876)

* some JAudio work

* audio cleanup checkpoint

* checkpoint more audio cleanup

* fix symbols

* more z2 cleanup

* fix regression

* fix build

* some fixes
This commit is contained in:
TakaRikka
2025-11-27 21:19:33 -08:00
committed by GitHub
parent 767caeecc3
commit 6f96e66518
113 changed files with 6425 additions and 5542 deletions
+171 -147
View File
@@ -1,7 +1,3 @@
//
// Translation Unit: Z2SoundMgr
//
#include "Z2AudioLib/Z2SoundMgr.h"
#include "Z2AudioLib/Z2Param.h"
#include "Z2AudioLib/Z2SceneMgr.h"
@@ -9,19 +5,17 @@
#include "Z2AudioLib/Z2SeqMgr.h"
#include "Z2AudioLib/Z2SeMgr.h"
#include "Z2AudioLib/Z2SoundInfo.h"
#include "Z2AudioLib/Z2AudioCS.h"
#include "JSystem/JAudio2/JASCalc.h"
#include "JSystem/JAudio2/JASDriverIF.h"
#include "JSystem/JAudio2/JAUSectionHeap.h"
void dComIfGs_staffroll_next_go();
#include "d/d_com_inf_game.h"
/* 802A9BC8-802A9E80 2A4508 02B8+00 1/0 1/1 0/0 .text seqCallback__FP8JASTrackUs */
u16 seqCallback(JASTrack* i_track, u16 param_1) {
JSUList<JAISe>* list;
switch (param_1) {
u16 seqCallback(JASTrack* track, u16 command) {
switch (command) {
case 0x1000:
Z2GetSeqMgr()->setChildTrackVolume(Z2GetSeqMgr()->getSubBgmHandle(),
3, 1.0f, 0, -1.0f, -1.0f);
Z2GetSeqMgr()->setChildTrackVolume(Z2GetSeqMgr()->getSubBgmHandle(), 3, 1.0f, 0, -1.0f, -1.0f);
Z2GetSoundMgr()->getSeqMgr()->calc();
Z2GetSoundMgr()->getSeqMgr()->mixOut();
break;
@@ -41,28 +35,32 @@ u16 seqCallback(JASTrack* i_track, u16 param_1) {
Z2GetSeqMgr()->onVariantBgmJumpEnd(false);
break;
case 0x1006:
list = Z2GetSoundMgr()->getSeMgr()->getCategory(5)->getSeList();
for (JSULink<JAISe>* link = list->getFirst(); link != NULL; link = link->getNext()) {
switch (link->getObject()->getID()) {
case Z2SE_GRO_MV_SINGING:
case Z2SE_GRR_MV_SINGING:
case Z2SE_CLERK_MV_SONG_HO:
case Z2SE_WAD_A_MV_DANCE:
case Z2SE_MCN_A_V_DANCE:
case Z2SE_WCN_A_V_DANCE:
link->getObject()->getTrack()->writePort(14, 1);
break;
for (JSULink<JAISe>* link = Z2GetSoundMgr()->getSeMgr()->getCategory(5)->getSeList()->getFirst(); link != NULL; link = link->getNext()) {
JAISe* se = link->getObject();
switch (se->getID()) {
case Z2SE_GRO_MV_SINGING:
case Z2SE_GRR_MV_SINGING:
case Z2SE_CLERK_MV_SONG_HO:
case Z2SE_WAD_A_MV_DANCE:
case Z2SE_MCN_A_V_DANCE:
case Z2SE_WCN_A_V_DANCE:
JASTrack* track = se->getTrack();
JUT_ASSERT(94, track);
track->writePort(14, 1);
break;
}
}
break;
case 0x1015:
list = Z2GetSoundMgr()->getSeMgr()->getCategory(5)->getSeList();
for (JSULink<JAISe>* link = list->getFirst(); link != NULL; link = link->getNext()) {
switch (link->getObject()->getID()) {
case Z2SE_MCN_A_V_DANCE:
case Z2SE_WCN_A_V_DANCE:
link->getObject()->getTrack()->writePort(14, 1);
break;
for (JSULink<JAISe>* link = Z2GetSoundMgr()->getSeMgr()->getCategory(5)->getSeList()->getFirst(); link != NULL; link = link->getNext()) {
JAISe* se = link->getObject();
switch (se->getID()) {
case Z2SE_MCN_A_V_DANCE:
case Z2SE_WCN_A_V_DANCE:
JASTrack* track = se->getTrack();
JUT_ASSERT(113, track);
track->writePort(14, 1);
break;
}
}
break;
@@ -76,123 +74,144 @@ u16 seqCallback(JASTrack* i_track, u16 param_1) {
dComIfGs_staffroll_next_go();
break;
}
if (param_1 >= 0x1009 && param_1 <= 0x1013) {
if (command >= 0x1009 && command <= 0x1013) {
JAISoundID sound_id = Z2SE_CSL_TOWN_BAND_VOCAL;
if (param_1 <= 0x100a) {
if (command <= 0x100a) {
sound_id = Z2SE_CSL_TOWN_BAND_GT_1;
} else if (param_1 <= 0x100c) {
} else if (command <= 0x100c) {
sound_id = Z2SE_CSL_TOWN_BAND_GT_2;
} else if (param_1 <= 0x100f) {
} else if (command <= 0x100f) {
sound_id = Z2SE_CSL_TOWN_BAND_GT_3;
} else if (param_1 <= 0x1011) {
} else if (command <= 0x1011) {
sound_id = Z2SE_CSL_TOWN_BAND_FLUTE;
}
list = Z2GetSoundMgr()->getSeMgr()->getCategory(6)->getSeList();
for (JSULink<JAISe>* link = list->getFirst(); link != NULL; link = link->getNext()) {
if (link->getObject()->getID() == sound_id) {
link->getObject()->getTrack()->writePort(14, param_1);
for (JSULink<JAISe>* link = Z2GetSoundMgr()->getSeMgr()->getCategory(6)->getSeList()->getFirst(); link != NULL; link = link->getNext()) {
JAISe* se = link->getObject();
if (se->getID() == sound_id) {
JASTrack* track = se->getTrack();
JUT_ASSERT(159, track);
track->writePort(14, command);
break;
}
}
}
return 0;
}
/* 802A9E80-802A9EE8 2A47C0 0068+00 0/0 1/1 0/0 .text __ct__10Z2SoundMgrFv */
Z2SoundMgr::Z2SoundMgr() :
JASGlobalInstance<Z2SoundMgr>(this),
mSeMgr(true),
mSeqMgr(true),
mStreamMgr(true)
JASGlobalInstance<Z2SoundMgr>(true),
seMgr_(true),
seqMgr_(true),
streamMgr_(true)
{
mSoundID.setAnonymous();
soundID_.setAnonymous();
}
/* 802A9EE8-802AA1B0 2A4828 02C8+00 1/0 0/0 0/0 .text
* startSound__10Z2SoundMgrF10JAISoundIDP14JAISoundHandlePCQ29JGeometry8TVec3<f> */
bool Z2SoundMgr::startSound(JAISoundID i_soundID, JAISoundHandle* i_handle,
JGeometry::TVec3<f32> const* i_pos) {
switch (Z2GetSoundInfo()->getSoundType(i_soundID)) {
case 0:
if (Z2GetSoundInfo()->getSwBit(i_soundID) & 8) {
bool Z2SoundMgr::startSound(JAISoundID soundID, JAISoundHandle* handle, const JGeometry::TVec3<f32>* posPtr) {
int soundType = Z2GetSoundInfo()->getSoundType(soundID);
switch (soundType) {
case 0: {
if (Z2GetSoundInfo()->getSwBit(soundID) & 8) {
OS_REPORT("[Z2SoundMgr::startSound] se seq Mute! id = %08x\n", *(u32*)&soundID);
Z2GetSeqMgr()->bgmAllMute(3, 0.3f);
mSoundID = i_soundID;
soundID_ = soundID;
}
return mSeMgr.startSound(i_soundID, i_handle, i_pos);
#if PLATFORM_WII || PLATFORM_SHIELD
if ((u32)soundID == 12) {
Z2AudioCS::start(0, 0);
} else if ((u32)soundID == 13) {
Z2AudioCS::start(0x66, 0);
}
#endif
bool result = seMgr_.startSound(soundID, handle, posPtr);
return result;
}
case 1:
if (i_soundID == Z2BGM_LUTERA_DEMO) {
if (soundID == Z2BGM_LUTERA_DEMO) {
Z2GetSeqMgr()->bgmStart(Z2BGM_LUTERA2, 0, 0);
Z2GetSeqMgr()->unMuteSceneBgm(0);
Z2GetSeqMgr()->changeBgmStatus(0);
return mSeMgr.startSound(Z2SE_NO_SOUND, i_handle, i_pos);
return seMgr_.startSound(Z2SE_NO_SOUND, handle, posPtr);
} else {
bool loaded = false;
JAUSectionHeap* heap = JASGlobalInstance<JAUSectionHeap>::getInstance();
JAUSeqDataBlocks const& loaded_blocks =
heap->getSectionHeapData().seqDataBlocks.getLoadedBlocks();
JSULink<JAUSeqDataBlock>* link;
for (link = loaded_blocks.getFirst(); link != NULL; link = link->getNext()) {
if (link->getObject()->field_0x10 == i_soundID) {
JAUSectionHeap* sectionHeap = JASGlobalInstance<JAUSectionHeap>::getInstance();
JUT_ASSERT(228, sectionHeap);
for (JSULink<JAUSeqDataBlock>* link = sectionHeap->getSectionHeapData().seqDataBlocks.getLoadedBlocks().getFirst(); link != NULL; link = link->getNext()) {
if (link->getObject()->field_0x10 == soundID) {
loaded = true;
break;
}
}
if (!loaded) {
heap->releaseIdleDynamicSeqDataBlock();
if (!heap->loadDynamicSeq(i_soundID, true)) {
JAUSeqDataBlocks const& free_blocks =
heap->getSectionHeapData().seqDataBlocks.getFreeBlocks();
for (link = free_blocks.getFirst(); link != NULL; link = link->getNext()) {
u32 sp2C = sectionHeap->releaseIdleDynamicSeqDataBlock();
if (!sectionHeap->loadDynamicSeq(soundID, true)) {
OS_REPORT("[Z2SoundMgr::startSound] FAILED!!! LOAD SEQ_DATA id: %08x\n", *(u32*)&soundID);
for (JSULink<JAUSeqDataBlock>* link = sectionHeap->getSectionHeapData().seqDataBlocks.getFreeBlocks().getFirst(); link != NULL; link = link->getNext()) {
OS_REPORT(" freeSeqBlock: %d\n", link->getObject()->field_0x14.size);
}
}
}
return mSeqMgr.startSound(i_soundID, i_handle, i_pos);
return seqMgr_.startSound(soundID, handle, posPtr);
}
case 2:
if (i_soundID == 0x2000001 || i_soundID == 0x200004d) {
mStreamMgr.stop(180);
return mSeMgr.startSound(Z2SE_NO_SOUND, i_handle, i_pos);
if (soundID == 0x2000001 || soundID == 0x200004d) {
streamMgr_.stop(180);
return seMgr_.startSound(Z2SE_NO_SOUND, handle, posPtr);
}
if (i_soundID == 0x2000005) {
mSeMgr.getCategory(9)->pause(false);
mSeMgr.getCategory(9)->getParams()->moveVolume(1.0f, 45);
if (soundID == 0x2000005) {
seMgr_.getCategory(9)->pause(false);
seMgr_.getCategory(9)->getParams()->moveVolume(1.0f, 45);
}
return mStreamMgr.startSound(i_soundID, i_handle, i_pos);
return streamMgr_.startSound(soundID, handle, posPtr);
default:
char error[32];
sprintf(error, "Unknown Sound-Type id :%08x\n", (u32)i_soundID);
return false;
sprintf(error, "Unknown Sound-Type id :%08x\n", *(u32*)&soundID);
JUT_WARN(277, "%s", error);
}
}
return false;
}
/* 802AA1B0-802AA270 2A4AF0 00C0+00 2/2 0/0 0/0 .text calc__10Z2SoundMgrFv */
void Z2SoundMgr::calc() {
mSeMgr.calc();
if (!mSoundID.isAnonymous() && !isPlayingSoundID(mSoundID)) {
seMgr_.calc();
if (!soundID_.isAnonymous() && !isPlayingSoundID(soundID_)) {
if (Z2GetSceneMgr()->isSceneExist()) {
Z2GetSeqMgr()->bgmAllUnMute(3);
}
mSoundID.setAnonymous();
soundID_.setAnonymous();
}
mSeqMgr.calc();
mStreamMgr.calc();
seqMgr_.calc();
streamMgr_.calc();
}
/* 802AA270-802AA33C 2A4BB0 00CC+00 1/1 2/2 0/0 .text setIIR__10Z2SoundMgrFP8JAISoundPCs
*/
void Z2SoundMgr::setIIR(JAISound* param_0, s16 const* param_1) {
if (param_0 != NULL) {
JASTrack* track = param_0->getTrack();
void Z2SoundMgr::setIIR(JAISound* sound, const s16* iir) {
if (sound != NULL) {
JASTrack* track = sound->getTrack();
JUT_ASSERT(340, track);
for (u32 i = 0; i < 4; i++) {
JASTrack* child = track->getChild(i);
if (child != NULL && child->getStatus() == 1) {
child->setIIR(param_1);
child->setIIR(iir);
for (u32 j = 0; j < 4; j++) {
JASTrack* child2 = child->getChild(j);
if (child2 != NULL && child2->getStatus() == 1) {
child2->setIIR(param_1);
child2->setIIR(iir);
}
}
}
@@ -206,9 +225,10 @@ static s16 const cResetFilterTable[8] = {
};
/* 802AA33C-802AA430 2A4C7C 00F4+00 1/1 0/0 0/0 .text setFilterOff__10Z2SoundMgrFP8JAISound */
void Z2SoundMgr::setFilterOff(JAISound* param_0) {
if (param_0 != NULL) {
JASTrack* track = param_0->getTrack();
void Z2SoundMgr::setFilterOff(JAISound* sound) {
if (sound != NULL) {
JASTrack* track = sound->getTrack();
JUT_ASSERT(403, track);
for (u32 i = 0; i < 4; i++) {
JASTrack* child = track->getChild(i);
if (child != NULL && child->getStatus() == 1) {
@@ -229,16 +249,17 @@ void Z2SoundMgr::setFilterOff(JAISound* param_0) {
/* 802AA430-802AA528 2A4D70 00F8+00 0/0 1/1 0/0 .text resetFilterAll__10Z2SoundMgrFv */
void Z2SoundMgr::resetFilterAll() {
int i = 1;
if (struct_80451342 != 0) {
if (Z2Param::SYSTEM_SE_USE_DARK_SE_SETTING) {
i = 0;
}
for (; i < 9; i++) {
JAISeCategoryMgr* category = mSeMgr.getCategory(i);
JAISeCategoryMgr* category = seMgr_.getCategory(i);
int se_count = category->getMaxActiveSe();
if (se_count > 0) {
for (JSULink<JAISe>* link = category->getSeList()->getFirst();
link != NULL && se_count > 0 && !link->getObject()->isFarAway();
link = link->getNext(), se_count--)
link = link->getNext(), --se_count)
{
setFilterOff(link->getObject());
}
@@ -255,34 +276,36 @@ void Z2SoundMgr::resetFilterAll() {
/* 802AA528-802AA67C 2A4E68 0154+00 2/2 0/0 0/0 .text mixOut__10Z2SoundMgrFv */
void Z2SoundMgr::mixOut() {
if (struct_80451340 != 0 && Z2GetSceneMgr()->isInDarkness()) {
if (Z2Param::DARK_SE_FILTER_ON && Z2GetSceneMgr()->isInDarkness()) {
int i = 1;
if (struct_80451342 != 0) {
if (Z2Param::SYSTEM_SE_USE_DARK_SE_SETTING) {
i = 0;
}
for (; i < 9; i++) {
JAISeCategoryMgr* category = mSeMgr.getCategory(i);
JAISeCategoryMgr* category = seMgr_.getCategory(i);
int se_count = category->getMaxActiveSe();
if (se_count > 0) {
for (JSULink<JAISe>* link = category->getSeList()->getFirst();
link != NULL && se_count > 0 && !link->getObject()->isFarAway();
link = link->getNext(), se_count--)
link = link->getNext(), --se_count)
{
setIIR(link->getObject(), JASCalc::CUTOFF_TO_IIR_TABLE[struct_80451341]);
setIIR(link->getObject(), JASCalc::CUTOFF_TO_IIR_TABLE[Z2Param::DARK_SE_LOW_PASS_FILTER_SETTING]);
}
} else {
for (JSULink<JAISe>* link = category->getSeList()->getFirst();
link != NULL && !link->getObject()->isFarAway();
link = link->getNext())
{
setIIR(link->getObject(), JASCalc::CUTOFF_TO_IIR_TABLE[struct_80451341]);
setIIR(link->getObject(), JASCalc::CUTOFF_TO_IIR_TABLE[Z2Param::DARK_SE_LOW_PASS_FILTER_SETTING]);
}
}
}
}
mSeMgr.mixOut();
mSeqMgr.mixOut();
mStreamMgr.mixOut();
seMgr_.mixOut();
seqMgr_.mixOut();
streamMgr_.mixOut();
}
/* 802AA67C-802AA6B0 2A4FBC 0034+00 0/0 1/1 0/0 .text framework__10Z2SoundMgrFv */
@@ -293,45 +316,44 @@ void Z2SoundMgr::framework() {
/* 802AA6B0-802AA7DC 2A4FF0 012C+00 0/0 1/1 0/0 .text pauseAllGameSound__10Z2SoundMgrFb
*/
void Z2SoundMgr::pauseAllGameSound(bool i_pause) {
mSeMgr.getCategory(0)->pause(i_pause);
mSeMgr.getCategory(1)->pause(i_pause);
mSeMgr.getCategory(2)->pause(i_pause);
mSeMgr.getCategory(3)->pause(i_pause);
mSeMgr.getCategory(4)->pause(i_pause);
mSeMgr.getCategory(5)->pause(i_pause);
mSeMgr.getCategory(6)->pause(i_pause);
mSeMgr.getCategory(7)->pause(i_pause);
mSeMgr.getCategory(8)->pause(i_pause);
mSeMgr.getCategory(9)->pause(i_pause);
mSeqMgr.pause(i_pause);
mStreamMgr.pause(i_pause);
if (i_pause) {
void Z2SoundMgr::pauseAllGameSound(bool paused) {
seMgr_.getCategory(0)->pause(paused);
seMgr_.getCategory(1)->pause(paused);
seMgr_.getCategory(2)->pause(paused);
seMgr_.getCategory(3)->pause(paused);
seMgr_.getCategory(4)->pause(paused);
seMgr_.getCategory(5)->pause(paused);
seMgr_.getCategory(6)->pause(paused);
seMgr_.getCategory(7)->pause(paused);
seMgr_.getCategory(8)->pause(paused);
seMgr_.getCategory(9)->pause(paused);
seqMgr_.pause(paused);
streamMgr_.pause(paused);
if (paused) {
Z2GetSeMgr()->seMoveVolumeAll(0.0f, 10);
mSeqMgr.getParams()->moveVolume(0.0f, 10);
mStreamMgr.getParams()->moveVolume(0.0f, 10);
}
else {
seqMgr_.getParams()->moveVolume(0.0f, 10);
streamMgr_.getParams()->moveVolume(0.0f, 10);
} else {
Z2GetSeMgr()->seMoveVolumeAll(1.0f, 10);
mSeqMgr.getParams()->moveVolume(1.0f, 10);
mStreamMgr.getParams()->moveVolume(1.0f, 10);
seqMgr_.getParams()->moveVolume(1.0f, 10);
streamMgr_.getParams()->moveVolume(1.0f, 10);
}
}
/* 802AA7DC-802AA84C 2A511C 0070+00 0/0 1/1 0/0 .text stopSoundID__10Z2SoundMgrF10JAISoundID */
void Z2SoundMgr::stopSoundID(JAISoundID i_soundID) {
mSeMgr.stopSoundID(i_soundID);
mSeqMgr.stopSoundID(i_soundID);
mStreamMgr.stopSoundID(i_soundID);
void Z2SoundMgr::stopSoundID(JAISoundID soundID) {
seMgr_.stopSoundID(soundID);
seqMgr_.stopSoundID(soundID);
streamMgr_.stopSoundID(soundID);
}
/* 802AA84C-802AA8C8 2A518C 007C+00 0/0 1/1 0/0 .text stopSync__10Z2SoundMgrFv */
void Z2SoundMgr::stopSync() {
stop();
while (mSeMgr.getNumActiveSe() > 0 || mSeqMgr.getNumActiveSeqs() > 0) {
while (seMgr_.getNumActiveSe() > 0 || seqMgr_.getNumActiveSeqs() > 0) {
calc();
if (mSeMgr.getNumActiveSe() == 0 && mSeqMgr.getNumActiveSeqs() == 0) {
if (seMgr_.getNumActiveSe() == 0 && seqMgr_.getNumActiveSeqs() == 0) {
break;
}
mixOut();
@@ -341,28 +363,29 @@ void Z2SoundMgr::stopSync() {
/* 802AA8C8-802AA908 2A5208 0040+00 1/1 0/0 0/0 .text stop__10Z2SoundMgrFv */
void Z2SoundMgr::stop() {
mSeMgr.stop();
mSeqMgr.stop();
mStreamMgr.stop();
seMgr_.stop();
seqMgr_.stop();
streamMgr_.stop();
}
/* 802AA908-802AA9E8 2A5248 00E0+00 0/0 1/1 0/0 .text initParams__10Z2SoundMgrFv */
void Z2SoundMgr::initParams() {
mSeMgr.initParams();
mSeqMgr.getParams()->init();
mStreamMgr.getParams()->init();
}
JUT_ASSERT(613, ! seMgr_.isActive());
JUT_ASSERT(614, ! seqMgr_.isActive());
seMgr_.initParams();
seqMgr_.getParams()->init();
streamMgr_.getParams()->init();
}
/* 802AA9E8-802AAAC4 2A5328 00DC+00 0/0 1/1 0/0 .text
* multiVolumeSoundID__10Z2SoundMgrF10JAISoundIDf */
void Z2SoundMgr::multiVolumeSoundID(JAISoundID i_soundID, f32 i_multi) {
if (!i_soundID.isAnonymous() && Z2GetSoundInfo()->getSoundType(i_soundID) == 0) {
JSUList<JAISe>* list =
mSeMgr.getCategory(Z2GetSoundInfo()->getCategory(i_soundID))->getSeList();
for (JSULink<JAISe>* link = list->getFirst(); link != NULL; link = link->getNext()) {
if (link->getObject()->getID() == i_soundID) {
link->getObject()->getAuxiliary().mParams.mVolume *= i_multi;
void Z2SoundMgr::multiVolumeSoundID(JAISoundID soundID, f32 volume) {
if (!soundID.isAnonymous() && Z2GetSoundInfo()->getSoundType(soundID) == 0) {
int category = Z2GetSoundInfo()->getCategory(soundID);
for (JSULink<JAISe>* link = seMgr_.getCategory(category)->getSeList()->getFirst(); link != NULL; link = link->getNext()) {
if (link->getObject()->getID() == soundID) {
link->getObject()->getAuxiliary().params_.mVolume *= volume;
}
}
}
@@ -370,18 +393,19 @@ void Z2SoundMgr::multiVolumeSoundID(JAISoundID i_soundID, f32 i_multi) {
/* 802AAAC4-802AAB94 2A5404 00D0+00 1/1 0/0 0/0 .text isPlayingSoundID__10Z2SoundMgrF10JAISoundID
*/
bool Z2SoundMgr::isPlayingSoundID(JAISoundID i_soundID) {
if (i_soundID.isAnonymous()) {
bool Z2SoundMgr::isPlayingSoundID(JAISoundID soundID) {
if (soundID.isAnonymous()) {
return false;
}
if (Z2GetSoundInfo()->getSoundType(i_soundID) == 0) {
JSUList<JAISe>* list =
mSeMgr.getCategory(Z2GetSoundInfo()->getCategory(i_soundID))->getSeList();
for (JSULink<JAISe>* link = list->getFirst(); link != NULL; link = link->getNext()) {
if (link->getObject()->getID() == i_soundID) {
if (Z2GetSoundInfo()->getSoundType(soundID) == 0) {
int category = Z2GetSoundInfo()->getCategory(soundID);
for (JSULink<JAISe>* link = seMgr_.getCategory(category)->getSeList()->getFirst(); link != NULL; link = link->getNext()) {
if (link->getObject()->getID() == soundID) {
return true;
}
}
}
return false;
}