Match and link CScriptRoomAcoustics

Former-commit-id: b9e7123f3e
This commit is contained in:
Henrique Gemignani Passos Lima 2022-11-04 16:58:34 +02:00
parent 2bbe0fcd20
commit 0307bd0bd5
7 changed files with 312 additions and 18 deletions

View File

@ -10842,7 +10842,7 @@ lbl_800CEC80:
/* 800CEEB8 000CBE18 93 C1 00 48 */ stw r30, 0x48(r1)
/* 800CEEBC 000CBE1C 93 E1 00 4C */ stw r31, 0x4c(r1)
/* 800CEEC0 000CBE20 91 C1 00 50 */ stw r14, 0x50(r1)
/* 800CEEC4 000CBE24 48 0C F1 49 */ bl "__ct__20CScriptRoomAcousticsF9TUniqueIdRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>RC11CEntityInfobbbfffffffbfffbbfffffbiiiiiiiii"
/* 800CEEC4 000CBE24 48 0C F1 49 */ bl "__ct__20CScriptRoomAcousticsF9TUniqueIdRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>RC11CEntityInfobUibbffffffbfffbbfffffbiiiiiiiii"
/* 800CEEC8 000CBE28 7C 6F 1B 78 */ mr r15, r3
lbl_800CEECC:
/* 800CEECC 000CBE2C 38 61 00 68 */ addi r3, r1, 0x68

View File

@ -7,8 +7,8 @@ lbl_ctor:
.section .data
.balign 8
.global lbl_803E4708
lbl_803E4708:
.global __vt__20CScriptRoomAcoustics
__vt__20CScriptRoomAcoustics:
# ROM: 0x3E1708
.4byte 0
.4byte 0
@ -22,8 +22,8 @@ lbl_803E4708:
.section .sbss, "wa"
.balign 8
.global lbl_805A9048
lbl_805A9048:
.global s_ActiveAcousticsAreaId
s_ActiveAcousticsAreaId:
.skip 0x8
.section .text, "ax"
@ -38,9 +38,9 @@ __dt__20CScriptRoomAcousticsFv:
/* 8019DD18 0019AC78 93 C1 00 08 */ stw r30, 8(r1)
/* 8019DD1C 0019AC7C 7C 7E 1B 79 */ or. r30, r3, r3
/* 8019DD20 0019AC80 41 82 00 28 */ beq lbl_8019DD48
/* 8019DD24 0019AC84 3C A0 80 3E */ lis r5, lbl_803E4708@ha
/* 8019DD24 0019AC84 3C A0 80 3E */ lis r5, __vt__20CScriptRoomAcoustics@ha
/* 8019DD28 0019AC88 38 80 00 00 */ li r4, 0
/* 8019DD2C 0019AC8C 38 05 47 08 */ addi r0, r5, lbl_803E4708@l
/* 8019DD2C 0019AC8C 38 05 47 08 */ addi r0, r5, __vt__20CScriptRoomAcoustics@l
/* 8019DD30 0019AC90 90 1E 00 00 */ stw r0, 0(r30)
/* 8019DD34 0019AC94 4B EB 35 41 */ bl __dt__7CEntityFv
/* 8019DD38 0019AC98 7F E0 07 35 */ extsh. r0, r31
@ -63,7 +63,7 @@ DisableAuxCallbacks__20CScriptRoomAcousticsFv:
/* 8019DD6C 0019ACCC 90 01 00 14 */ stw r0, 0x14(r1)
/* 8019DD70 0019ACD0 48 14 A6 C9 */ bl DisableAuxProcessing__11CSfxManagerFv
/* 8019DD74 0019ACD4 80 0D A3 90 */ lwz r0, kInvalidAreaId@sda21(r13)
/* 8019DD78 0019ACD8 90 0D A4 88 */ stw r0, lbl_805A9048@sda21(r13)
/* 8019DD78 0019ACD8 90 0D A4 88 */ stw r0, s_ActiveAcousticsAreaId@sda21(r13)
/* 8019DD7C 0019ACDC 48 1A CA 81 */ bl GetDefaultVolumeScale__9CAudioSysFv
/* 8019DD80 0019ACE0 48 1A CA 8D */ bl SetVolumeScale__9CAudioSysFs
/* 8019DD84 0019ACE4 80 01 00 14 */ lwz r0, 0x14(r1)
@ -177,7 +177,7 @@ lbl_8019DF08:
/* 8019DF18 0019AE78 48 1A C8 F5 */ bl SetVolumeScale__9CAudioSysFs
lbl_8019DF1C:
/* 8019DF1C 0019AE7C 80 1F 00 04 */ lwz r0, 4(r31)
/* 8019DF20 0019AE80 90 0D A4 88 */ stw r0, lbl_805A9048@sda21(r13)
/* 8019DF20 0019AE80 90 0D A4 88 */ stw r0, s_ActiveAcousticsAreaId@sda21(r13)
lbl_8019DF24:
/* 8019DF24 0019AE84 80 01 04 44 */ lwz r0, 0x444(r1)
/* 8019DF28 0019AE88 83 E1 04 3C */ lwz r31, 0x43c(r1)
@ -216,13 +216,13 @@ lbl_8019DF8C:
/* 8019DF90 0019AEF0 4B FF FE 05 */ bl EnableAuxCallbacks__20CScriptRoomAcousticsFv
/* 8019DF94 0019AEF4 48 00 00 28 */ b lbl_8019DFBC
lbl_8019DF98:
/* 8019DF98 0019AEF8 80 6D A4 88 */ lwz r3, lbl_805A9048@sda21(r13)
/* 8019DF98 0019AEF8 80 6D A4 88 */ lwz r3, s_ActiveAcousticsAreaId@sda21(r13)
/* 8019DF9C 0019AEFC 80 1E 00 04 */ lwz r0, 4(r30)
/* 8019DFA0 0019AF00 7C 03 00 00 */ cmpw r3, r0
/* 8019DFA4 0019AF04 40 82 00 18 */ bne lbl_8019DFBC
/* 8019DFA8 0019AF08 48 14 A4 91 */ bl DisableAuxProcessing__11CSfxManagerFv
/* 8019DFAC 0019AF0C 80 0D A3 90 */ lwz r0, kInvalidAreaId@sda21(r13)
/* 8019DFB0 0019AF10 90 0D A4 88 */ stw r0, lbl_805A9048@sda21(r13)
/* 8019DFB0 0019AF10 90 0D A4 88 */ stw r0, s_ActiveAcousticsAreaId@sda21(r13)
/* 8019DFB4 0019AF14 48 1A C8 49 */ bl GetDefaultVolumeScale__9CAudioSysFv
/* 8019DFB8 0019AF18 48 1A C8 55 */ bl SetVolumeScale__9CAudioSysFs
lbl_8019DFBC:
@ -250,8 +250,8 @@ Accept__20CScriptRoomAcousticsFR8IVisitor:
/* 8019E004 0019AF64 38 21 00 10 */ addi r1, r1, 0x10
/* 8019E008 0019AF68 4E 80 00 20 */ blr
.global "__ct__20CScriptRoomAcousticsF9TUniqueIdRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>RC11CEntityInfobbbfffffffbfffbbfffffbiiiiiiiii"
"__ct__20CScriptRoomAcousticsF9TUniqueIdRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>RC11CEntityInfobbbfffffffbfffbbfffffbiiiiiiiii":
.global "__ct__20CScriptRoomAcousticsF9TUniqueIdRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>RC11CEntityInfobUibbffffffbfffbbfffffbiiiiiiiii"
"__ct__20CScriptRoomAcousticsF9TUniqueIdRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>RC11CEntityInfobUibbffffffbfffbbfffffbiiiiiiiii":
/* 8019E00C 0019AF6C 94 21 FE C0 */ stwu r1, -0x140(r1)
/* 8019E010 0019AF70 7C 08 02 A6 */ mflr r0
/* 8019E014 0019AF74 90 01 01 44 */ stw r0, 0x144(r1)
@ -323,9 +323,9 @@ Accept__20CScriptRoomAcousticsFR8IVisitor:
/* 8019E11C 0019B07C 83 01 01 8C */ lwz r24, 0x18c(r1)
/* 8019E120 0019B080 81 E1 01 90 */ lwz r15, 0x190(r1)
/* 8019E124 0019B084 4B EB 32 01 */ bl "__ct__7CEntityF9TUniqueIdRC11CEntityInfobRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>"
/* 8019E128 0019B088 3C 80 80 3E */ lis r4, lbl_803E4708@ha
/* 8019E128 0019B088 3C 80 80 3E */ lis r4, __vt__20CScriptRoomAcoustics@ha
/* 8019E12C 0019B08C 7F 23 CB 78 */ mr r3, r25
/* 8019E130 0019B090 38 04 47 08 */ addi r0, r4, lbl_803E4708@l
/* 8019E130 0019B090 38 04 47 08 */ addi r0, r4, __vt__20CScriptRoomAcoustics@l
/* 8019E134 0019B094 90 19 00 00 */ stw r0, 0(r25)
/* 8019E138 0019B098 93 59 00 34 */ stw r26, 0x34(r25)
/* 8019E13C 0019B09C 9B 79 00 38 */ stb r27, 0x38(r25)
@ -394,5 +394,5 @@ Accept__20CScriptRoomAcousticsFR8IVisitor:
.global __sinit_CScriptRoomAcoustics_cpp
__sinit_CScriptRoomAcoustics_cpp:
/* 8019E234 0019B194 80 0D A3 90 */ lwz r0, kInvalidAreaId@sda21(r13)
/* 8019E238 0019B198 90 0D A4 88 */ stw r0, lbl_805A9048@sda21(r13)
/* 8019E238 0019B198 90 0D A4 88 */ stw r0, s_ActiveAcousticsAreaId@sda21(r13)
/* 8019E23C 0019B19C 4E 80 00 20 */ blr

View File

@ -255,7 +255,7 @@ LIBS = [
"MetroidPrime/Weapons/CBeamProjectile",
"MetroidPrime/CFluidPlaneCPU",
"MetroidPrime/CFluidPlaneDoor",
"MetroidPrime/ScriptObjects/CScriptRoomAcoustics",
["MetroidPrime/ScriptObjects/CScriptRoomAcoustics", True],
"MetroidPrime/Enemies/CIceSheegoth",
["MetroidPrime/CCollisionActorManager", False],
"MetroidPrime/CCollisionActor",

View File

@ -5,6 +5,65 @@
#include "Kyoto/Audio/CSfxHandle.hpp"
struct _SND_REVSTD_DELAYLINE {
int inPoint;
int outPoint;
int length;
float* inputs;
float lastOutput;
};
struct _SND_REVSTD_WORK {
struct _SND_REVSTD_DELAYLINE AP[6];
struct _SND_REVSTD_DELAYLINE C[6];
float allPassCoef;
float combCoef[6];
float lpLastout[3];
float level;
float damping;
int preDelayTime;
float* preDelayLine[3];
float* preDelayPtr[3];
};
struct SND_AUX_REVERBHI {
uchar pad0[0x1c4];
bool hiDis;
float damping;
float crosstalk;
float coloration;
float time;
float mix;
float preDelay;
};
struct SND_AUX_CHORUS {
uchar pad[144];
uint baseDelay;
uint variation;
uint period;
};
struct SND_AUX_REVERBSTD {
_SND_REVSTD_WORK rv;
bool tempDisableFX;
float damping;
float preDelay;
float coloration;
float time;
float mix;
};
struct SND_AUX_DELAY {
uint currentSize[3];
uint currentPos[3];
uint currentFeedback[3];
uint currentOutput[3];
uint* left;
uint* right;
uint* sur;
uint delay[3]; // delay buffer length in ms per channel
uint feedback[3]; // feedback volume in % per channel
uint output[3]; // output volume in % per channel
};
class CVector3f;
class CSfxManager {
public:
@ -38,6 +97,14 @@ public:
static void KillAll(ESfxChannels);
static void TurnOnChannel(ESfxChannels);
static void TurnOffChannel(ESfxChannels);
static void DisableAuxCallback();
static void EnableAuxCallback();
static void PrepareDelayCallback(const SND_AUX_DELAY& info);
static void PrepareReverbStdCallback(const SND_AUX_REVERBSTD& info);
static void PrepareChorusCallback(const SND_AUX_CHORUS& info);
static void PrepareReverbHiCallback(const SND_AUX_REVERBHI& info);
static void DisableAuxProcessing();
};
#endif // _CSFXMANAGER

View File

@ -0,0 +1,105 @@
#ifndef _CSCRIPTROOMACOUSTICS
#define _CSCRIPTROOMACOUSTICS
#include "MetroidPrime/CEntity.hpp"
#include "Kyoto/Audio/CSfxManager.hpp"
struct EffectReverbHiInfo {
float coloration; /**< [0.0, 1.0] influences filter coefficients to define surface characteristics
of a room */
float mix; /**< [0.0, 1.0] dry/wet mix factor of reverb effect */
float time; /**< [0.01, 10.0] time in seconds for reflection decay */
float damping; /**< [0.0, 1.0] damping factor influencing low-pass filter of reflections */
float preDelay; /**< [0.0, 0.1] time in seconds before initial reflection heard */
float crosstalk; /**< [0.0, 1.0] factor defining how much reflections are allowed to bleed to
other channels */
EffectReverbHiInfo(float coloration, float mix, float time, float damping, float preDelay,
float crosstalk)
: coloration(coloration)
, mix(mix)
, time(time)
, damping(damping)
, preDelay(preDelay)
, crosstalk(crosstalk) {}
};
struct EffectChorusInfo {
float baseDelay;
float variation;
float period;
EffectChorusInfo(float baseDelay, float variation, float period)
: baseDelay(baseDelay), variation(variation), period(period) {}
};
struct EffectReverbStdInfo {
float coloration; /**< [0.0, 1.0] influences filter coefficients to define surface characteristics
of a room */
float mix; /**< [0.0, 1.0] dry/wet mix factor of reverb effect */
float time; /**< [0.01, 10.0] time in seconds for reflection decay */
float damping; /**< [0.0, 1.0] damping factor influencing low-pass filter of reflections */
float preDelay; /**< [0.0, 0.1] time in seconds before initial reflection heard */
EffectReverbStdInfo(float coloration, float mix, float time, float damping, float preDelay)
: coloration(coloration), mix(mix), time(time), damping(damping), preDelay(preDelay) {}
};
struct EffectDelayInfo {
int delayL;
int delayR;
int delayS;
int feedbackL;
int feedbackR;
int feedbackS;
int outputL;
int outputR;
int outputS;
EffectDelayInfo(int delayL, int delayR, int delayS, int feedbackL, int feedbackR, int feedbackS,
int outputL, int outputR, int outputS)
: delayL(delayL)
, delayR(delayR)
, delayS(delayS)
, feedbackL(feedbackL)
, feedbackR(feedbackR)
, feedbackS(feedbackS)
, outputL(outputL)
, outputR(outputR)
, outputS(outputS) {}
};
class CScriptRoomAcoustics : public CEntity {
public:
CScriptRoomAcoustics(TUniqueId uid, const rstl::string& name, const CEntityInfo& info,
bool active, uint volScale, bool revHi, bool revHiDis, float revHiColoration,
float revHiMix, float revHiTime, float revHiDamping, float revHiPreDelay,
float revHiCrosstalk, bool chorus, float baseDelay, float variation,
float period, bool revStd, bool revStdDis, float revStdColoration,
float revStdMix, float revStdTime, float revStdDamping, float revStdPreDelay,
bool delay, int delayL, int delayR, int delayS, int feedbackL, int feedbackR,
int feedbackS, int outputL, int outputR, int outputS);
virtual ~CScriptRoomAcoustics();
void Think(float dt, CStateManager& stateMgr) override;
void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) override;
void Accept(IVisitor& visitor) override;
void EnableAuxCallbacks();
static void DisableAuxCallbacks();
private:
uint x34_volumeScale;
bool x38_revHi, x39_revHiDis;
EffectReverbHiInfo x3c_revHiInfo;
bool x54_chorus;
EffectChorusInfo x58_chorusInfo;
bool x64_revStd, x65_revStdDis;
EffectReverbStdInfo x68_revStdInfo;
bool x7c_delay;
EffectDelayInfo x80_delayInfo;
};
#endif // _CSCRIPTROOMACOUSTICS

View File

@ -220,7 +220,7 @@ METROIDPRIME :=\
$(BUILD_DIR)/asm/MetroidPrime/Weapons/CBeamProjectile.o\
$(BUILD_DIR)/asm/MetroidPrime/CFluidPlaneCPU.o\
$(BUILD_DIR)/asm/MetroidPrime/CFluidPlaneDoor.o\
$(BUILD_DIR)/asm/MetroidPrime/ScriptObjects/CScriptRoomAcoustics.o\
$(BUILD_DIR)/src/MetroidPrime/ScriptObjects/CScriptRoomAcoustics.o\
$(BUILD_DIR)/asm/MetroidPrime/Enemies/CIceSheegoth.o\
$(BUILD_DIR)/asm/MetroidPrime/CCollisionActorManager.o\
$(BUILD_DIR)/asm/MetroidPrime/CCollisionActor.o\

View File

@ -0,0 +1,122 @@
#include "MetroidPrime/ScriptObjects/CScriptRoomAcoustics.hpp"
#include "Kyoto/Audio/CAudioSys.hpp"
static TAreaId s_ActiveAcousticsAreaId = kInvalidAreaId;
CScriptRoomAcoustics::CScriptRoomAcoustics(
TUniqueId uid, const rstl::string& name, const CEntityInfo& info, bool active, uint volScale,
bool revHi, bool revHiDis, float revHiColoration, float revHiMix, float revHiTime,
float revHiDamping, float revHiPreDelay, float revHiCrosstalk, bool chorus, float baseDelay,
float variation, float period, bool revStd, bool revStdDis, float revStdColoration,
float revStdMix, float revStdTime, float revStdDamping, float revStdPreDelay, bool delay,
int delayL, int delayR, int delayS, int feedbackL, int feedbackR, int feedbackS, int outputL,
int outputR, int outputS)
: CEntity(uid, info, active, name)
, x34_volumeScale(volScale)
, x38_revHi(revHi)
, x39_revHiDis(revHiDis)
, x3c_revHiInfo(revHiColoration, revHiMix, revHiTime, revHiDamping, revHiPreDelay, revHiCrosstalk)
, x54_chorus(chorus)
, x58_chorusInfo(baseDelay, variation, period)
, x64_revStd(revStd)
, x65_revStdDis(revStdDis)
, x68_revStdInfo(revStdColoration, revStdMix, revStdTime, revStdDamping, revStdPreDelay)
, x7c_delay(delay)
, x80_delayInfo(delayL, delayR, delayS, feedbackL, feedbackR, feedbackS, outputL, outputR,
outputS) {}
void CScriptRoomAcoustics::Accept(IVisitor& visitor) { visitor.Visit(*this); }
void CScriptRoomAcoustics::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId,
CStateManager& stateMgr) {
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
switch (msg) {
case kSM_Activate:
EnableAuxCallbacks();
break;
case kSM_Deactivate:
if (s_ActiveAcousticsAreaId == GetCurrentAreaId()) {
CSfxManager::DisableAuxProcessing();
s_ActiveAcousticsAreaId = kInvalidAreaId;
CAudioSys::SetVolumeScale(CAudioSys::GetDefaultVolumeScale());
}
break;
default:
break;
}
}
void CScriptRoomAcoustics::Think(float dt, CStateManager& stateMgr) {
if (!GetActive()) {
return;
}
}
void CScriptRoomAcoustics::EnableAuxCallbacks() {
if (!GetActive()) {
return;
}
int applied = 0;
if (x38_revHi && applied <= 0) {
SND_AUX_REVERBHI reverb;
reverb.hiDis = x39_revHiDis;
reverb.coloration = x3c_revHiInfo.coloration;
reverb.mix = x3c_revHiInfo.mix;
reverb.time = x3c_revHiInfo.time;
reverb.damping = x3c_revHiInfo.damping;
reverb.preDelay = x3c_revHiInfo.preDelay;
reverb.crosstalk = x3c_revHiInfo.crosstalk;
applied++;
CSfxManager::PrepareReverbHiCallback(reverb);
}
if (x54_chorus && applied < 1) {
SND_AUX_CHORUS chorus;
chorus.baseDelay = x58_chorusInfo.baseDelay;
chorus.variation = x58_chorusInfo.variation;
chorus.period = x58_chorusInfo.period;
applied++;
CSfxManager::PrepareChorusCallback(chorus);
}
if (x64_revStd && applied < 1) {
SND_AUX_REVERBSTD reverbStd;
reverbStd.tempDisableFX = x65_revStdDis;
reverbStd.coloration = x68_revStdInfo.coloration;
reverbStd.mix = x68_revStdInfo.mix;
reverbStd.time = x68_revStdInfo.time;
reverbStd.damping = x68_revStdInfo.damping;
reverbStd.preDelay = x68_revStdInfo.preDelay;
applied++;
CSfxManager::PrepareReverbStdCallback(reverbStd);
}
if (x7c_delay && applied < 1) {
SND_AUX_DELAY delay;
delay.delay[0] = x80_delayInfo.delayL;
delay.delay[1] = x80_delayInfo.delayR;
delay.delay[2] = x80_delayInfo.delayS;
delay.feedback[0] = x80_delayInfo.feedbackL;
delay.feedback[1] = x80_delayInfo.feedbackR;
delay.feedback[2] = x80_delayInfo.feedbackS;
delay.output[0] = x80_delayInfo.outputL;
delay.output[1] = x80_delayInfo.outputR;
delay.output[2] = x80_delayInfo.outputS;
applied++;
CSfxManager::PrepareDelayCallback(delay);
}
if (applied > 0) {
CAudioSys::SetVolumeScale(x34_volumeScale);
}
s_ActiveAcousticsAreaId = GetCurrentAreaId();
}
void CScriptRoomAcoustics::DisableAuxCallbacks() {
CSfxManager::DisableAuxProcessing();
s_ActiveAcousticsAreaId = kInvalidAreaId;
CAudioSys::SetVolumeScale(CAudioSys::GetDefaultVolumeScale());
}
CScriptRoomAcoustics::~CScriptRoomAcoustics() {}