From 7e2cf84a889f58697dc42663d9cf504db64af0d2 Mon Sep 17 00:00:00 2001 From: Jcw87 Date: Thu, 20 Jul 2023 02:43:10 -0700 Subject: [PATCH] JAISeq --- include/JSystem/JAudio2/JAISeq.h | 47 +++ include/JSystem/JAudio2/JAISeqMgr.h | 8 +- include/JSystem/JAudio2/JAISound.h | 9 +- include/JSystem/JAudio2/JAISoundChild.h | 2 + include/JSystem/JAudio2/JASHeapCtrl.h | 115 ++++++- include/JSystem/JAudio2/JASTrack.h | 5 +- libs/JSystem/JAudio2/JAISeMgr.cpp | 11 - libs/JSystem/JAudio2/JAISeq.cpp | 398 +++++++++++++++--------- libs/JSystem/JAudio2/JASHeapCtrl.cpp | 32 +- libs/Z2AudioLib/Z2AudioMgr.cpp | 19 -- libs/Z2AudioLib/Z2SceneMgr.cpp | 2 - 11 files changed, 433 insertions(+), 215 deletions(-) diff --git a/include/JSystem/JAudio2/JAISeq.h b/include/JSystem/JAudio2/JAISeq.h index 411125cf466..14e3d1ee806 100644 --- a/include/JSystem/JAudio2/JAISeq.h +++ b/include/JSystem/JAudio2/JAISeq.h @@ -1,8 +1,55 @@ #ifndef JAISEQ_H #define JAISEQ_H +#include "JSystem/JAudio2/JAISeqDataMgr.h" #include "JSystem/JAudio2/JAISound.h" +#include "JSystem/JAudio2/JASHeapCtrl.h" #include "JSystem/JAudio2/JASTrack.h" #include "JSystem/JSupport/JSUList.h" +class JAISeqMgr; +class JAISoundChild; + +class JAISeq : public JAISound, JSULink { +public: + class TInner { + public: + TInner() : mSeqData(NULL, 0) {} + + /* 0x000 */ JASTrack outputTrack; + /* 0x248 */ JASPoolAllocObject* mSoundChild[32]; + /* 0x2C8 */ JAITempoMgr mTempoMgr; + /* 0x2D8 */ JASSoundParams mSoundParams; + /* 0x2EC */ JAISeqData mSeqData; + /* 0x2F4 */ s32 field_0x39c; + /* 0x2F8 */ JAISeqMgr* seqMgr; + /* 0x2FC */ JAISoundStrategyMgr* strategyMgr; + }; + + /* 802A1570 */ virtual s32 getNumChild() const; + /* 802A1578 */ virtual JAISoundChild* getChild(int); + /* 802A165C */ virtual void releaseChild(int); + /* 802A1768 */ virtual JAISeq* asSeq(); + /* 802A1728 */ virtual JASTrack* getTrack(); + /* 802A1730 */ virtual JASTrack* getChildTrack(int); + /* 802A176C */ virtual JAITempoMgr* getTempoMgr(); + /* 802A12BC */ virtual bool JAISound_tryDie_(); + + /* 802A0A8C */ JAISeq(JAISeqMgr*, JAISoundStrategyMgr*); + /* 802A0B64 */ void JAISeqMgr_startID_(JAISoundID, JGeometry::TVec3 const*, JAIAudience*, + int, int); + /* 802A0C04 */ void playSeqData_(JASSoundParams const&, JAISoundActivity); + /* 802A0CA4 */ void reserveChildTracks_(int); + /* 802A0E48 */ void releaseChildTracks_(); + /* 802A0EDC */ bool prepare_getSeqData_(); + /* 802A0F90 */ bool prepare_(JASSoundParams const&, JAISoundActivity); + /* 802A108C */ void JAISeqMgr_calc_(); + /* 802A1180 */ void die_(); + /* 802A1348 */ void mixOut_(JASSoundParams const&, JAISoundActivity); + /* 802A14FC */ void JAISeqMgr_mixOut_(JASSoundParams const&, JAISoundActivity); + + /* 0x0a8 */ TInner inner_; + /* 0x3A8 */ JAISoundStrategyMgr__unknown* field_0x3a8; +}; + #endif /* JAISEQ_H */ diff --git a/include/JSystem/JAudio2/JAISeqMgr.h b/include/JSystem/JAudio2/JAISeqMgr.h index 4d87772f52f..db7ef079043 100644 --- a/include/JSystem/JAudio2/JAISeqMgr.h +++ b/include/JSystem/JAudio2/JAISeqMgr.h @@ -27,11 +27,13 @@ public: /* 802A1804 */ virtual bool isUsingSeqData(JAISeqDataRegion const&); /* 802A1870 */ virtual int releaseSeqData(JAISeqDataRegion const&); + JAISeqDataMgr* getSeqDataMgr() { return seqDataMgr_; } + private: /* 0x04 */ JAISoundActivity mActivity; - /* 0x08 */ void* field_0x8; - /* 0x0C */ JAIAudience* mAudience; - /* 0x10 */ JAISeqDataMgr* seqDataMgr_; + /* 0x08 */ JAIAudience* mAudience; + /* 0x0C */ JAISeqDataMgr* seqDataMgr_; + /* 0x10 */ void* field_0x10; /* 0x14 */ JAISoundParamsMove mMove; /* 0x64 */ JSUList mSeqList; /* 0x70 */ int field_0x70; diff --git a/include/JSystem/JAudio2/JAISound.h b/include/JSystem/JAudio2/JAISound.h index bc6fc490ea9..8752faca66a 100644 --- a/include/JSystem/JAudio2/JAISound.h +++ b/include/JSystem/JAudio2/JAISound.h @@ -185,6 +185,7 @@ class JAIAudible; class JAIAudience; class JAISe; class JAISeq; +class JAISoundChild; class JAIStream; class JAITempoMgr; class JAISound { @@ -203,14 +204,14 @@ public: /* 802A26B8 */ bool calc_JAISound_(); /* 802A29DC */ void initTrack_JAISound_(JASTrack*); - virtual void getNumChild() = 0; - virtual void getChild() = 0; - virtual void releaseChild() = 0; + virtual s32 getNumChild() const = 0; + virtual JAISoundChild* getChild(int) = 0; + virtual void releaseChild(int) = 0; /* 802A25D8 */ virtual JAISe* asSe(); /* 802A25E0 */ virtual JAISeq* asSeq(); /* 802A25E8 */ virtual JAIStream* asStream(); virtual JASTrack* getTrack() = 0; - virtual JASTrack* getChildTrack() = 0; + virtual JASTrack* getChildTrack(int) = 0; virtual JAITempoMgr* getTempoMgr() = 0; virtual bool JAISound_tryDie_() = 0; diff --git a/include/JSystem/JAudio2/JAISoundChild.h b/include/JSystem/JAudio2/JAISoundChild.h index b3ac7d6942e..df8ad962248 100644 --- a/include/JSystem/JAudio2/JAISoundChild.h +++ b/include/JSystem/JAudio2/JAISoundChild.h @@ -11,6 +11,8 @@ struct JAISoundChild { /* 802A2B28 */ void mixOut(JASTrack*); /* 802A2B7C */ void calc(); + JAISoundChild() { init(); } + /* 0x00 */ JAISoundParamsMove mMove; /* 0x50 */ JASSoundParams mParams; }; // Size: 0x64 diff --git a/include/JSystem/JAudio2/JASHeapCtrl.h b/include/JSystem/JAudio2/JASHeapCtrl.h index 139fcbb4f6a..78e9cbb69e0 100644 --- a/include/JSystem/JAudio2/JASHeapCtrl.h +++ b/include/JSystem/JAudio2/JASHeapCtrl.h @@ -1,14 +1,125 @@ #ifndef JASHEAPCTRL_H #define JASHEAPCTRL_H -#include "dolphin/types.h" +#include "JSystem/JSupport/JSUList.h" +#include "dolphin/os/OSInterrupt.h" +#include "dolphin/os/OSMutex.h" + +class JASDisposer; + +class JASHeap { + /* 80290140 */ JASHeap(JASDisposer*); + /* 802901AC */ void initRootHeap(void*, u32); + /* 8029021C */ void alloc(JASHeap*, u32); + /* 802903F4 */ void allocTail(JASHeap*, u32); + /* 802904E4 */ void free(); + /* 80290608 */ void insertChild(JASHeap*, JASHeap*, void*, u32, bool); + /* 802906F0 */ void getTailHeap(); + /* 8029077C */ void getTailOffset(); + /* 802907E0 */ void getCurOffset(); + /* 80290B54 */ ~JASHeap(); + + /* 0x00 */ JSUTree mTree; + /* 0x1C */ OSMutex mMutex; + /* 0x34 */ JASDisposer* mDisposer; + /* 0x38 */ int field_0x38; + /* 0x3c */ int field_0x3c; + /* 0x40 */ void* field_0x40; +}; struct JASGenericMemPool { /* 80290848 */ JASGenericMemPool(); /* 80290860 */ ~JASGenericMemPool(); /* 802908C8 */ void newMemPool(u32, int); - /* 80290948 */ void alloc(u32); + /* 80290948 */ void* alloc(u32); /* 80290994 */ void free(void*, u32); + + /* 0x00 */ void* field_0x0; + /* 0x04 */ int freeMemCount; + /* 0x08 */ int totalMemCount; + /* 0x0C */ int field_0xc; + +}; + +namespace JASThreadingModel { + template + struct InterruptsDisable { + struct Lock { + Lock(const A0& param_0) { field_0x0 = OSDisableInterrupts(); } + ~Lock() { OSRestoreInterrupts(field_0x0); } + + BOOL field_0x0; + }; + }; +}; + +template +class JASMemPool : public JASGenericMemPool { +public: + void newMemPool(int param_0) { JASGenericMemPool::newMemPool(sizeof(T), param_0); } + void* alloc(u32 n) { return JASGenericMemPool::alloc(n); } + void free(void* ptr, u32 n) { JASGenericMemPool::free(ptr, n); } +}; + +template +class JASPoolAllocObject : public T { +public: + static void* operator new(size_t n) { + JASMemPool* memPool = getMemPool(); + return memPool->alloc(n); + } + static void operator delete(void* ptr, size_t n) { + JASMemPool* memPool_ = getMemPool(); + memPool_->free(ptr, n); + } + static void newMemPool(int param_0) { + JASMemPool* memPool_ = getMemPool(); + memPool_->newMemPool(param_0); + } + +private: + static JASMemPool* getMemPool() { + static JASMemPool memPool_; + return &memPool_; + } +}; + +template +class JASMemPool_MultiThreaded : public JASGenericMemPool { +public: + void newMemPool(int param_0) { + JASThreadingModel::InterruptsDisable >::Lock lock(*this); + JASGenericMemPool::newMemPool(sizeof(T), param_0); + } + + void* alloc(size_t count) { + JASThreadingModel::InterruptsDisable >::Lock lock(*this); + return JASGenericMemPool::alloc(count); + } + + void free(void* ptr, u32 param_1) { + JASThreadingModel::InterruptsDisable >::Lock lock(*this); + JASGenericMemPool::free(ptr, param_1); + } +}; + +template +class JASPoolAllocObject_MultiThreaded : public T { +public: + static void* operator new(size_t n) { + JASMemPool_MultiThreaded* memPool_ = getMemPool(); + return memPool_->alloc(n); + } + static void operator delete(void* ptr, size_t n) { + JASMemPool_MultiThreaded* memPool_ = getMemPool(); + memPool_->free(ptr, n); + } + +private: + static JASMemPool_MultiThreaded* getMemPool() { + static JASMemPool_MultiThreaded memPool_; + return &memPool_; + } }; #endif /* JASHEAPCTRL_H */ diff --git a/include/JSystem/JAudio2/JASTrack.h b/include/JSystem/JAudio2/JASTrack.h index 9347a193a25..bc5879bdf9f 100644 --- a/include/JSystem/JAudio2/JASTrack.h +++ b/include/JSystem/JAudio2/JASTrack.h @@ -125,7 +125,10 @@ struct JASTrack { int getChannelMgrCount() { return channelMgrCount; } u8 getStatus() const { return mStatus; } - JASTrack* getChild(int index) { return field_0x130[index]; } + JASTrack* getChild(u32 index) { return field_0x130[index]; } + void setAutoDelete(bool param_0) { + field_0x216 = (param_0 << 4) | field_0x216 & ~0x10; + } /* 0x000 */ u8 field_0x0[0x5c]; // JASSeqCtrl /* 0x05C */ u8 field_0x5c[0x24]; // JASTrackPort diff --git a/libs/JSystem/JAudio2/JAISeMgr.cpp b/libs/JSystem/JAudio2/JAISeMgr.cpp index 8f02a6fb9aa..538c8820d5e 100644 --- a/libs/JSystem/JAudio2/JAISeMgr.cpp +++ b/libs/JSystem/JAudio2/JAISeMgr.cpp @@ -10,17 +10,6 @@ #include "dol2asm.h" #include "dolphin/types.h" -// -// Types: -// - -template -struct JASMemPool {}; -/* JASMemPool */ -struct JASMemPool__template0 { - /* 8029FC34 */ void func_8029FC34(void* _this); -}; - // // Forward References: // diff --git a/libs/JSystem/JAudio2/JAISeq.cpp b/libs/JSystem/JAudio2/JAISeq.cpp index a6986d8f599..2bd948131d2 100644 --- a/libs/JSystem/JAudio2/JAISeq.cpp +++ b/libs/JSystem/JAudio2/JAISeq.cpp @@ -4,72 +4,17 @@ // #include "JSystem/JAudio2/JAISeq.h" +#include "JSystem/JAudio2/JAIAudience.h" +#include "JSystem/JAudio2/JAISeqMgr.h" +#include "JSystem/JAudio2/JAISoundChild.h" +#include "JSystem/JAudio2/JASAudioReseter.h" // JASCriticalSection #include "dol2asm.h" -#include "dolphin/types.h" - -// -// Types: -// - -template -struct JASMemPool_MultiThreaded {}; -/* JASMemPool_MultiThreaded */ -struct JASMemPool_MultiThreaded__template0 { - /* 802932E0 */ void func_802932E0(void* _this); -}; - -template -struct JASMemPool {}; -/* JASMemPool */ -struct JASMemPool__template1 { - /* 802A1268 */ void func_802A1268(void* _this); -}; - -struct JASGenericMemPool { - /* 80290848 */ JASGenericMemPool(); - /* 80290860 */ ~JASGenericMemPool(); - /* 80290948 */ void alloc(u32); - /* 80290994 */ void free(void*, u32); -}; - -struct JAISoundChild { - /* 802A2AB0 */ void init(); - /* 802A2B28 */ void mixOut(JASTrack*); - /* 802A2B7C */ void calc(); -}; - -struct JAIAudience {}; - -struct JAISeqMgr {}; - -struct JAISeq { - /* 802A0A8C */ JAISeq(JAISeqMgr*, JAISoundStrategyMgr*); - /* 802A0B64 */ void JAISeqMgr_startID_(JAISoundID, JGeometry::TVec3 const*, JAIAudience*, - int, int); - /* 802A0C04 */ void playSeqData_(JASSoundParams const&, JAISoundActivity); - /* 802A0CA4 */ void reserveChildTracks_(int); - /* 802A0E48 */ void releaseChildTracks_(); - /* 802A0EDC */ void prepare_getSeqData_(); - /* 802A0F90 */ void prepare_(JASSoundParams const&, JAISoundActivity); - /* 802A108C */ void JAISeqMgr_calc_(); - /* 802A1180 */ void die_(); - /* 802A12BC */ void JAISound_tryDie_(); - /* 802A1348 */ void mixOut_(JASSoundParams const&, JAISoundActivity); - /* 802A14FC */ void JAISeqMgr_mixOut_(JASSoundParams const&, JAISoundActivity); - /* 802A1570 */ s32 getNumChild() const; - /* 802A1578 */ void getChild(int); - /* 802A165C */ void releaseChild(int); - /* 802A1728 */ JASTrack* getTrack(); - /* 802A1730 */ JASTrack* getChildTrack(int); - /* 802A1768 */ JAISeq* asSeq(); - /* 802A176C */ JAITempoMgr* getTempoMgr(); -}; // // Forward References: // -extern "C" static void func_802A0A6C(); +extern "C" static bool func_802A0A6C(JASTrack*); extern "C" void func_802A0A8C(); extern "C" void func_802A0B64(); extern "C" void playSeqData___6JAISeqFRC14JASSoundParams16JAISoundActivity(); @@ -125,8 +70,6 @@ extern "C" void mixOut__13JAISoundChildFP8JASTrack(); extern "C" void calc__13JAISoundChildFv(); extern "C" void __dl__FPv(); extern "C" void __ct__10JSUPtrLinkFPv(); -extern "C" void OSDisableInterrupts(); -extern "C" void OSRestoreInterrupts(); extern "C" void __register_global_object(); extern "C" void _savegpr_24(); extern "C" void _savegpr_26(); @@ -148,26 +91,22 @@ extern "C" extern u8 data_80451318[8]; /* 802A0A6C-802A0A8C 29B3AC 0020+00 1/1 0/0 0/0 .text * JASTrack_isFreeOrStopped__20@unnamed@JAISeq_cpp@FP8JASTrack */ +// instruction order +#ifdef NONMATCHING +static bool func_802A0A6C(JASTrack* track) { + u8 status = track->getStatus(); + return status == 0 || status == 2; +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -static asm void func_802A0A6C() { +static asm bool func_802A0A6C(JASTrack*) { nofralloc #include "asm/JSystem/JAudio2/JAISeq/func_802A0A6C.s" } #pragma pop - -/* ############################################################################################## */ -/* 803C98D8-803C98F4 -00001 001C+00 1/1 0/0 0/0 .data @852 */ -SECTION_DATA static void* lit_852[7] = { - (void*)(((char*)prepare___6JAISeqFRC14JASSoundParams16JAISoundActivity) + 0x68), - (void*)(((char*)prepare___6JAISeqFRC14JASSoundParams16JAISoundActivity) + 0x9C), - (void*)(((char*)prepare___6JAISeqFRC14JASSoundParams16JAISoundActivity) + 0x44), - (void*)(((char*)prepare___6JAISeqFRC14JASSoundParams16JAISoundActivity) + 0xE0), - (void*)(((char*)prepare___6JAISeqFRC14JASSoundParams16JAISoundActivity) + 0xB8), - (void*)(((char*)prepare___6JAISeqFRC14JASSoundParams16JAISoundActivity) + 0xD8), - (void*)(((char*)prepare___6JAISeqFRC14JASSoundParams16JAISoundActivity) + 0xE0), -}; +#endif /* 803C98F4-803C9928 026A14 0030+04 1/1 2/2 0/0 .data __vt__6JAISeq */ SECTION_DATA extern void* __vt__6JAISeq[12 + 1 /* padding */] = { @@ -183,8 +122,6 @@ SECTION_DATA extern void* __vt__6JAISeq[12 + 1 /* padding */] = { (void*)getChildTrack__6JAISeqFi, (void*)getTempoMgr__6JAISeqFv, (void*)JAISound_tryDie___6JAISeqFv, - /* padding */ - NULL, }; /* 80455798-8045579C 003D98 0004+00 3/3 0/0 0/0 .sdata2 @642 */ @@ -207,6 +144,17 @@ SECTION_SDATA2 static f32 lit_644[1 + 1 /* padding */] = { /* 802A0A8C-802A0B64 29B3CC 00D8+00 0/0 2/1 0/0 .text * __ct__6JAISeqFP9JAISeqMgrP28JAISoundStrategyMgr<6JAISeq> */ +// matches with literals +#ifdef NONMATCHING +JAISeq::JAISeq(JAISeqMgr* param_0, JAISoundStrategyMgr* param_1) : JSULink(this) { + inner_.seqMgr = param_0; + inner_.strategyMgr = param_1; + inner_.mSoundParams.init(); + for (int i = 0; i < 32; i++) { + inner_.mSoundChild[i] = NULL; + } +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -215,35 +163,62 @@ asm JAISeq::JAISeq(JAISeqMgr* param_0, JAISoundStrategyMgr* param_1) { #include "asm/JSystem/JAudio2/JAISeq/func_802A0A8C.s" } #pragma pop +#endif /* 802A0B64-802A0C04 29B4A4 00A0+00 0/0 1/1 0/0 .text * JAISeqMgr_startID___6JAISeqF10JAISoundIDPCQ29JGeometry8TVec3P11JAIAudienceii */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void JAISeq::JAISeqMgr_startID_(JAISoundID param_0, JGeometry::TVec3 const* param_1, - JAIAudience* param_2, int param_3, int param_4) { - nofralloc -#include "asm/JSystem/JAudio2/JAISeq/func_802A0B64.s" +void JAISeq::JAISeqMgr_startID_(JAISoundID param_0, JGeometry::TVec3 const* param_1, JAIAudience* param_2, int param_3, int param_4) { + inner_.field_0x39c = param_3; + reserveChildTracks_(param_4); + start_JAISound_(param_0, param_1, param_2); + if (inner_.strategyMgr) { + field_0x3a8 = inner_.strategyMgr->virtual3(param_0); + } else { + field_0x3a8 = NULL; + } } -#pragma pop /* 802A0C04-802A0CA4 29B544 00A0+00 1/1 0/0 0/0 .text * playSeqData___6JAISeqFRC14JASSoundParams16JAISoundActivity */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void JAISeq::playSeqData_(JASSoundParams const& param_0, JAISoundActivity param_1) { - nofralloc -#include "asm/JSystem/JAudio2/JAISeq/playSeqData___6JAISeqFRC14JASSoundParams16JAISoundActivity.s" +void JAISeq::playSeqData_(JASSoundParams const& param_0, JAISoundActivity param_1) { + inner_.outputTrack.setSeqData(inner_.mSeqData.field_0x0, inner_.mSeqData.field_0x4); + if (audible_) { + initTrack_JAISound_(&inner_.outputTrack); + } else { + inner_.outputTrack.setChannelMgrCount(1); + inner_.outputTrack.assignExtBuffer(0, &inner_.mSoundParams); + } + mixOut_(param_0, param_1); + inner_.outputTrack.startSeq(); } -#pragma pop /* ############################################################################################## */ /* 80434098-804340A4 060DB8 000C+00 1/1 0/0 0/0 .bss @716 */ static u8 lit_716[12]; /* 802A0CA4-802A0E48 29B5E4 01A4+00 1/1 0/0 0/0 .text reserveChildTracks___6JAISeqFi */ +// setAutoDelete inline, operator new? +#ifdef NONMATCHING +void JAISeq::reserveChildTracks_(int param_0) { + for (int i = 0; i < 2; i++) { + JASTrack* track = new JASPoolAllocObject_MultiThreaded(); + if (track) { + track->setAutoDelete(true); + inner_.outputTrack.connectChild(i, track); + for (int j = 0; j < 16; j++) { + if (i * 16 + j >= param_0) { + continue; + } + JASTrack* track2 = new JASPoolAllocObject_MultiThreaded(); + if (track2) { + track2->setAutoDelete(true); + track->connectChild(j, track2); + } + } + } + } +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -252,39 +227,96 @@ asm void JAISeq::reserveChildTracks_(int param_0) { #include "asm/JSystem/JAudio2/JAISeq/reserveChildTracks___6JAISeqFi.s" } #pragma pop +#endif /* 802A0E48-802A0EDC 29B788 0094+00 1/1 0/0 0/0 .text releaseChildTracks___6JAISeqFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void JAISeq::releaseChildTracks_() { - nofralloc -#include "asm/JSystem/JAudio2/JAISeq/releaseChildTracks___6JAISeqFv.s" +void JAISeq::releaseChildTracks_() { + for (u32 i = 0; i < 2; i++) { + JASTrack* track = inner_.outputTrack.getChild(i); + if (track) { + for (u32 j = 0; j < 16; j++) { + JASTrack* track2 = track->getChild(j); + if (track2) { + delete track2; + } + } + delete track; + } + } } -#pragma pop /* 802A0EDC-802A0F90 29B81C 00B4+00 1/1 0/0 0/0 .text prepare_getSeqData___6JAISeqFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void JAISeq::prepare_getSeqData_() { - nofralloc -#include "asm/JSystem/JAudio2/JAISeq/prepare_getSeqData___6JAISeqFv.s" +bool JAISeq::prepare_getSeqData_() { + JAISoundID id(soundID); + if (id.isAnonymous()) { + return true; + } + JAISeqDataMgr* seqDataMgr = inner_.seqMgr->getSeqDataMgr(); + switch (seqDataMgr->getSeqData(id, &inner_.mSeqData)) { + case 0: + status_.state.unk = 2; + break; + case 1: + increasePrepareCount_JAISound_(); + return false; + case 2: + return true; + } + return false; } -#pragma pop /* 802A0F90-802A108C 29B8D0 00FC+00 2/1 0/0 0/0 .text * prepare___6JAISeqFRC14JASSoundParams16JAISoundActivity */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void JAISeq::prepare_(JASSoundParams const& param_0, JAISoundActivity param_1) { - nofralloc -#include "asm/JSystem/JAudio2/JAISeq/prepare___6JAISeqFRC14JASSoundParams16JAISoundActivity.s" +bool JAISeq::prepare_(JASSoundParams const& param_0, JAISoundActivity param_1) { + switch (status_.state.unk) { + case 6: + break; + case 2: + stop_JAISound_(); + break; + case 0: + if (prepare_getSeqData_()) { + status_.state.unk = 5; + playSeqData_(param_0, param_1); + return true; + } + break; + case 1: + if (prepare_getSeqData_()) { + status_.state.unk = 3; + } + return false; + case 4: + status_.state.unk = 5; + playSeqData_(param_0, param_1); + return true; + case 5: + return true; + } + return false; } -#pragma pop /* 802A108C-802A1180 29B9CC 00F4+00 0/0 1/1 0/0 .text JAISeqMgr_calc___6JAISeqFv */ +// missing instruction +#ifdef NONMATCHING +void JAISeq::JAISeqMgr_calc_() { + if (inner_.outputTrack.getStatus() == 2 || (inner_.outputTrack.getStatus() == 0 && status_.state.unk == 2)) { + die_(); + return; + } + if (calc_JAISound_()) { + inner_.mTempoMgr.calc(); + for (int i = 0; i < 32; i++) { + if (inner_.mSoundChild[i]) { + inner_.mSoundChild[i]->calc(); + } + } + if (field_0x3a8) { + field_0x3a8->virtual3(this); + } + } +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -293,6 +325,7 @@ asm void JAISeq::JAISeqMgr_calc_() { #include "asm/JSystem/JAudio2/JAISeq/JAISeqMgr_calc___6JAISeqFv.s" } #pragma pop +#endif /* ############################################################################################## */ /* 804340A4-804340B0 060DC4 000C+00 3/3 0/0 0/0 .bss @896 */ @@ -304,6 +337,23 @@ extern u8 data_804340B0[16]; u8 data_804340B0[16]; /* 802A1180-802A1268 29BAC0 00E8+00 2/2 0/0 0/0 .text die___6JAISeqFv */ +// matches with literals +#ifdef NONMATCHING +void JAISeq::die_() { + for (int i = 0; i < 32; i++) { + if (inner_.mSoundChild[i]) { + delete inner_.mSoundChild[i]; + inner_.mSoundChild[i] = NULL; + } + } + if (field_0x3a8) { + inner_.strategyMgr->virtual4(field_0x3a8); + field_0x3a8 = NULL; + } + releaseChildTracks_(); + die_JAISound_(); +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -312,6 +362,7 @@ asm void JAISeq::die_() { #include "asm/JSystem/JAudio2/JAISeq/die___6JAISeqFv.s" } #pragma pop +#endif /* 802A1268-802A12BC 29BBA8 0054+00 3/3 4/4 0/0 .text __dt__27JASMemPool<13JAISoundChild>Fv */ #pragma push @@ -324,17 +375,61 @@ extern "C" asm void func_802A1268(void* _this) { #pragma pop /* 802A12BC-802A1348 29BBFC 008C+00 1/0 0/0 0/0 .text JAISound_tryDie___6JAISeqFv */ +// matches with literals +#ifdef NONMATCHING +bool JAISeq::JAISound_tryDie_() { + if (func_802A0A6C(&inner_.outputTrack)) { + die_(); + return true; + } + fader.forceOut(); + status_.state.flags.flag1 = 1; + JASCriticalSection cs; + inner_.outputTrack.stopSeq(); + return false; +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void JAISeq::JAISound_tryDie_() { +asm bool JAISeq::JAISound_tryDie_() { nofralloc #include "asm/JSystem/JAudio2/JAISeq/JAISound_tryDie___6JAISeqFv.s" } #pragma pop +#endif /* 802A1348-802A14FC 29BC88 01B4+00 2/2 0/0 0/0 .text * mixOut___6JAISeqFRC14JASSoundParams16JAISoundActivity */ +// matches with literals +#ifdef NONMATCHING +void JAISeq::mixOut_(JASSoundParams const& param_0, JAISoundActivity param_1) { + inner_.outputTrack.setTempoRate(inner_.mTempoMgr.getTempo()); + inner_.outputTrack.mute(param_1.field_0x0.flags.flag1 || status_.isMute()); + inner_.outputTrack.pause(param_1.field_0x0.flags.flag2 || status_.isPaused()); + JASSoundParams stackParams; + params.mixOutAll(param_0, &stackParams, fader.getIntensity()); + if (field_0x3a8) { + field_0x3a8->virtual4(this, stackParams); + } + if (audible_) { + int maxChannels = audience_->getMaxChannels(); + for (int i = 0; i < maxChannels; i++) { + audience_->mixChannelOut(stackParams, audible_, i); + } + } else { + inner_.mSoundParams = stackParams; + for (int i = 0; i < 32; i++) { + if (inner_.mSoundChild[i]) { + JASTrack* track = JAISeq::getChildTrack(i); + if (track) { + inner_.mSoundChild[i]->mixOut(track); + } + } + } + } +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -343,17 +438,15 @@ asm void JAISeq::mixOut_(JASSoundParams const& param_0, JAISoundActivity param_1 #include "asm/JSystem/JAudio2/JAISeq/mixOut___6JAISeqFRC14JASSoundParams16JAISoundActivity.s" } #pragma pop +#endif /* 802A14FC-802A1570 29BE3C 0074+00 0/0 1/1 0/0 .text * JAISeqMgr_mixOut___6JAISeqFRC14JASSoundParams16JAISoundActivity */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void JAISeq::JAISeqMgr_mixOut_(JASSoundParams const& param_0, JAISoundActivity param_1) { - nofralloc -#include "asm/JSystem/JAudio2/JAISeq/JAISeqMgr_mixOut___6JAISeqFRC14JASSoundParams16JAISoundActivity.s" +void JAISeq::JAISeqMgr_mixOut_(JASSoundParams const& param_0, JAISoundActivity param_1) { + if (prepare_(param_0, param_1) && inner_.outputTrack.getStatus() == 1) { + mixOut_(param_0, param_1); + } } -#pragma pop /* 802A1570-802A1578 29BEB0 0008+00 1/0 0/0 0/0 .text getNumChild__6JAISeqCFv */ s32 JAISeq::getNumChild() const { @@ -361,16 +454,43 @@ s32 JAISeq::getNumChild() const { } /* 802A1578-802A165C 29BEB8 00E4+00 1/0 0/0 0/0 .text getChild__6JAISeqFi */ +// matches with literals +#ifdef NONMATCHING +JAISoundChild* JAISeq::getChild(int index) { + if (inner_.mSoundChild[index]) { + return inner_.mSoundChild[index]; + } + inner_.mSoundChild[index] = new JASPoolAllocObject(); + if (!inner_.mSoundChild[index]) { + return NULL; + } + return inner_.mSoundChild[index]; +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void JAISeq::getChild(int param_0) { +asm JAISoundChild* JAISeq::getChild(int param_0) { nofralloc #include "asm/JSystem/JAudio2/JAISeq/getChild__6JAISeqFi.s" } #pragma pop +#endif /* 802A165C-802A1728 29BF9C 00CC+00 1/0 0/0 0/0 .text releaseChild__6JAISeqFi */ +// matches with literals +#ifdef NONMATCHING +void JAISeq::releaseChild(int param_0) { + if (inner_.outputTrack.getStatus() == 1 && inner_.mSoundChild[param_0]) { + JASTrack* track = getChildTrack(param_0); + if (track) { + track->assignExtBuffer(0, NULL); + } + delete inner_.mSoundChild[param_0]; + inner_.mSoundChild[param_0] = NULL; + } +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -379,26 +499,23 @@ asm void JAISeq::releaseChild(int param_0) { #include "asm/JSystem/JAudio2/JAISeq/releaseChild__6JAISeqFi.s" } #pragma pop +#endif /* 802A1728-802A1730 29C068 0008+00 1/0 0/0 0/0 .text getTrack__6JAISeqFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm JASTrack* JAISeq::getTrack() { - nofralloc -#include "asm/JSystem/JAudio2/JAISeq/getTrack__6JAISeqFv.s" +JASTrack* JAISeq::getTrack() { + return &inner_.outputTrack; } -#pragma pop /* 802A1730-802A1768 29C070 0038+00 2/1 0/0 0/0 .text getChildTrack__6JAISeqFi */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm JASTrack* JAISeq::getChildTrack(int param_0) { - nofralloc -#include "asm/JSystem/JAudio2/JAISeq/getChildTrack__6JAISeqFi.s" +JASTrack* JAISeq::getChildTrack(int param_0) { + u32 tmp = u32(param_0) >> 4; + JASTrack* track = inner_.outputTrack.getChild(tmp); + if (track) { + JASTrack* track2 = track->getChild(param_0 - (tmp << 4)); + return track2; + } + return NULL; } -#pragma pop /* 802A1768-802A176C 29C0A8 0004+00 1/0 0/0 0/0 .text asSeq__6JAISeqFv */ JAISeq* JAISeq::asSeq() { @@ -406,11 +523,6 @@ JAISeq* JAISeq::asSeq() { } /* 802A176C-802A1774 29C0AC 0008+00 1/0 0/0 0/0 .text getTempoMgr__6JAISeqFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm JAITempoMgr* JAISeq::getTempoMgr() { - nofralloc -#include "asm/JSystem/JAudio2/JAISeq/getTempoMgr__6JAISeqFv.s" +JAITempoMgr* JAISeq::getTempoMgr() { + return &inner_.mTempoMgr; } -#pragma pop diff --git a/libs/JSystem/JAudio2/JASHeapCtrl.cpp b/libs/JSystem/JAudio2/JASHeapCtrl.cpp index caeb493e464..fbaef9a02c3 100644 --- a/libs/JSystem/JAudio2/JASHeapCtrl.cpp +++ b/libs/JSystem/JAudio2/JASHeapCtrl.cpp @@ -11,18 +11,6 @@ // Types: // -struct JSUPtrLink { - /* 802DBDFC */ JSUPtrLink(void*); - /* 802DBE14 */ ~JSUPtrLink(); -}; - -struct JSUPtrList { - /* 802DBEAC */ ~JSUPtrList(); - /* 802DBF14 */ void initiate(); - /* 802DC094 */ void insert(JSUPtrLink*, JSUPtrLink*); - /* 802DC15C */ void remove(JSUPtrLink*); -}; - struct JKRSolidHeap {}; struct JKRHeap { @@ -50,19 +38,6 @@ struct JASDisposer { /* 80290BCC */ void onDispose(); }; -struct JASHeap { - /* 80290140 */ JASHeap(JASDisposer*); - /* 802901AC */ void initRootHeap(void*, u32); - /* 8029021C */ void alloc(JASHeap*, u32); - /* 802903F4 */ void allocTail(JASHeap*, u32); - /* 802904E4 */ void free(); - /* 80290608 */ void insertChild(JASHeap*, JASHeap*, void*, u32, bool); - /* 802906F0 */ void getTailHeap(); - /* 8029077C */ void getTailOffset(); - /* 802907E0 */ void getCurOffset(); - /* 80290B54 */ ~JASHeap(); -}; - // // Forward References: // @@ -109,9 +84,6 @@ extern "C" void __dt__10JSUPtrListFv(); extern "C" void initiate__10JSUPtrListFv(); extern "C" void insert__10JSUPtrListFP10JSUPtrLinkP10JSUPtrLink(); extern "C" void remove__10JSUPtrListFP10JSUPtrLink(); -extern "C" void OSInitMutex(); -extern "C" void OSLockMutex(); -extern "C" void OSUnlockMutex(); extern "C" void __register_global_object(); extern "C" void _savegpr_26(); extern "C" void _savegpr_27(); @@ -131,7 +103,7 @@ extern "C" u8 sSystemHeap__7JKRHeap[4]; #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm JASHeap::JASHeap(JASDisposer* param_0) { +asm JASHeap::JASHeap(JASDisposer* param_0) : mTree(this) { nofralloc #include "asm/JSystem/JAudio2/JASHeapCtrl/__ct__7JASHeapFP11JASDisposer.s" } @@ -259,7 +231,7 @@ asm void JASGenericMemPool::newMemPool(u32 param_0, int param_1) { #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void JASGenericMemPool::alloc(u32 param_0) { +asm void* JASGenericMemPool::alloc(u32 param_0) { nofralloc #include "asm/JSystem/JAudio2/JASHeapCtrl/alloc__17JASGenericMemPoolFUl.s" } diff --git a/libs/Z2AudioLib/Z2AudioMgr.cpp b/libs/Z2AudioLib/Z2AudioMgr.cpp index e953c601551..0a1606b0869 100644 --- a/libs/Z2AudioLib/Z2AudioMgr.cpp +++ b/libs/Z2AudioLib/Z2AudioMgr.cpp @@ -82,29 +82,10 @@ struct JASResArcLoader { /* 80290C04 */ void getResMaxSize(JKRArchive const*); }; -template -struct JASMemPool {}; -/* JASMemPool */ -struct JASMemPool__template4 { - /* 802AB200 */ void func_802AB200(void* _this); -}; - -/* JASMemPool */ -struct JASMemPool__template5 { - /* 802BD288 */ void func_802BD288(void* _this); -}; - struct JASKernel { /* 80290B08 */ void getAramHeap(); }; -struct JASHeap { - /* 8029021C */ void alloc(JASHeap*, u32); - /* 802904E4 */ void free(); - /* 80290B54 */ ~JASHeap(); - /* 802A4A5C */ void __defctor(); -}; - struct JASAramStream { static u8 sBlockSize[4]; }; diff --git a/libs/Z2AudioLib/Z2SceneMgr.cpp b/libs/Z2AudioLib/Z2SceneMgr.cpp index bad0c63461a..98d15480367 100644 --- a/libs/Z2AudioLib/Z2SceneMgr.cpp +++ b/libs/Z2AudioLib/Z2SceneMgr.cpp @@ -51,8 +51,6 @@ struct JAUSoundTable { /* 802A7160 */ void getTypeID(JAISoundID) const; }; -struct JASHeap {}; - struct JASWaveArc { /* 8029A4C0 */ void load(JASHeap*); /* 8029A580 */ void loadTail(JASHeap*);