From 23fe65685a9662f1047726c8cf83ec757234b0ce Mon Sep 17 00:00:00 2001 From: robojumper Date: Wed, 28 May 2025 00:25:36 +0200 Subject: [PATCH] snd_Sound3DListener OK --- config/SOUE01/symbols.txt | 8 ++-- configure.py | 2 +- include/nw4r/snd/snd_Sound3DEngine.h | 34 ++++++++++++++ include/nw4r/snd/snd_Sound3DListener.h | 36 +++++++++------ include/nw4r/snd/snd_Sound3DManager.h | 29 ++++++------ src/nw4r/snd/snd_Sound3DEngine.cpp | 35 ++++++++++++++- src/nw4r/snd/snd_Sound3DListener.cpp | 61 ++++++++++++++++++++++++++ src/nw4r/snd/snd_Sound3DManager.cpp | 26 ++++++----- 8 files changed, 188 insertions(+), 43 deletions(-) create mode 100644 include/nw4r/snd/snd_Sound3DEngine.h diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index a42c2e35..d23c8247 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -19875,7 +19875,7 @@ fn_8035BB50 = .text:0x8035BB50; // type:function size:0x8 fn_8035BB60 = .text:0x8035BB60; // type:function size:0x8 fn_8035BB70 = .text:0x8035BB70; // type:function size:0x8 fn_8035BB80 = .text:0x8035BB80; // type:function size:0x3C -fn_8035BBC0 = .text:0x8035BBC0; // type:function size:0x40 +__dt__Q34nw4r3snd13Sound3DEngineFv = .text:0x8035BBC0; // type:function size:0x40 fn_8035BC00 = .text:0x8035BC00; // type:function size:0x428 fn_8035C030 = .text:0x8035C030; // type:function size:0x188 fn_8035C1C0 = .text:0x8035C1C0; // type:function size:0xDC @@ -49738,9 +49738,9 @@ lbl_8057F104 = .sdata2:0x8057F104; // type:object size:0x4 align:4 data:float lbl_8057F108 = .sdata2:0x8057F108; // type:object size:0x4 align:4 data:float lbl_8057F10C = .sdata2:0x8057F10C; // type:object size:0x4 align:4 data:float lbl_8057F110 = .sdata2:0x8057F110; // type:object size:0x4 align:4 data:float -lbl_8057F118 = .sdata2:0x8057F118; // type:object size:0x4 align:4 data:float -lbl_8057F11C = .sdata2:0x8057F11C; // type:object size:0x4 align:4 data:float -lbl_8057F120 = .sdata2:0x8057F120; // type:object size:0x4 align:4 data:float +@1266 = .sdata2:0x8057F118; // type:object size:0x4 scope:local align:4 data:float +@1267 = .sdata2:0x8057F11C; // type:object size:0x4 scope:local align:4 data:float +@1268 = .sdata2:0x8057F120; // type:object size:0x4 scope:local align:4 data:float lbl_8057F128 = .sdata2:0x8057F128; // type:object size:0x4 align:4 data:float lbl_8057F12C = .sdata2:0x8057F12C; // type:object size:0x4 align:4 data:float @3454 = .sdata2:0x8057F130; // type:object size:0x4 scope:local align:4 data:float diff --git a/configure.py b/configure.py index 7c129f6d..72596482 100644 --- a/configure.py +++ b/configure.py @@ -1055,7 +1055,7 @@ config.libs = [ Object(NonMatching, "nw4r/snd/snd_Sound3DActor.cpp"), Object(NonMatching, "nw4r/snd/snd_Sound3DCalculator.cpp"), Object(NonMatching, "nw4r/snd/snd_Sound3DEngine.cpp"), - Object(NonMatching, "nw4r/snd/snd_Sound3DListener.cpp"), + Object(Matching, "nw4r/snd/snd_Sound3DListener.cpp"), Object(NonMatching, "nw4r/snd/snd_Sound3DManager.cpp"), Object(Matching, "nw4r/snd/snd_SoundActor.cpp"), Object(Matching, "nw4r/snd/snd_SoundArchive.cpp"), diff --git a/include/nw4r/snd/snd_Sound3DEngine.h b/include/nw4r/snd/snd_Sound3DEngine.h new file mode 100644 index 00000000..3cfd4168 --- /dev/null +++ b/include/nw4r/snd/snd_Sound3DEngine.h @@ -0,0 +1,34 @@ +#ifndef NW4R_SND_SOUND_3D_ENGINE_H +#define NW4R_SND_SOUND_3D_ENGINE_H + +#include "nw4r/math.h" +#include "nw4r/types_nw4r.h" +#include "nw4r/snd/snd_Sound3DManager.h" + + +namespace nw4r { +namespace snd { + +class Sound3DManager; + +class Sound3DEngine { +public: + Sound3DEngine(); + virtual ~Sound3DEngine() {} + + virtual void UpdateAmbientParam(const Sound3DManager*, const Sound3DParam*, u32, int, SoundAmbientParam*); + virtual void GetAmbientPriority(const Sound3DManager*, const Sound3DParam*, u32); + virtual s32 GetRequiredVoiceOutCount(const Sound3DManager*, const Sound3DParam*, u32); + virtual void UpdateAmbientParam(const Sound3DManager*, const Sound3DParam*, u32, u32, SoundAmbientParam*); + +private: + f32 mSpeakerAngleStereo; // at 0x04 + f32 mFrontSpeakerAngleDpl2; // at 0x08 + f32 mRearSpeakerAngleDpl2; // at 0x0C + f32 mInitPan; // at 0x10 +}; + +} // namespace snd +} // namespace nw4r + +#endif diff --git a/include/nw4r/snd/snd_Sound3DListener.h b/include/nw4r/snd/snd_Sound3DListener.h index 911279ac..414343e7 100644 --- a/include/nw4r/snd/snd_Sound3DListener.h +++ b/include/nw4r/snd/snd_Sound3DListener.h @@ -1,8 +1,9 @@ #ifndef NW4R_SND_SOUND_3D_LISTENER_H #define NW4R_SND_SOUND_3D_LISTENER_H -#include "nw4r/math.h" +#include "common.h" #include "nw4r/types_nw4r.h" +#include "nw4r/math.h" namespace nw4r { namespace snd { @@ -15,32 +16,39 @@ public: return mMtx; } + void SetMatrix(const math::MTX34 &mtx); + f32 GetInteriorSize() const { return mInteriorSize; } - void SetInteriorSize(f32 size) { - mInteriorSize = size; - } + void SetInteriorSize(f32 size); f32 GetMaxVolumeDistance() const { return mMaxVolumeDistance; } - void SetMaxVolumeDistance(f32 distance) { - mMaxVolumeDistance = distance; - } + void SetMaxVolumeDistance(f32 distance); f32 GetUnitDistance() const { return mUnitDistance; } - void SetUnitDistance(f32 distance) { - mUnitDistance = distance; - } + void SetUnitDistance(f32 distance); + + void SetUnitBiquadFilterValue(f32 value); + void SetUnitBiquadFilterMax(f32 value); private: - math::MTX34 mMtx; // at 0x0 - f32 mInteriorSize; // at 0x30 - f32 mMaxVolumeDistance; // at 0x34 - f32 mUnitDistance; // at 0x38 + math::MTX34 mMtx; // at 0x0 + math::VEC3 mPosition; // at 0x30 + math::VEC3 mVelocity; // at 0x3C + f32 mInteriorSize; // at 0x48 + f32 mMaxVolumeDistance; // at 0x4C + f32 mUnitDistance; // at 0x50 + UNKWORD field_0x54; // at 0x54 + u8 mSkipVelocityUpdate; // at 0x58 + f32 mUnitBiquadFilterValue; // at 0x5C + f32 mUnitBiquadFilterMax; // at 0x60 + UNKWORD field_0x64; // at 0x64 + UNKWORD field_0x68; // at 0x68 }; } // namespace snd diff --git a/include/nw4r/snd/snd_Sound3DManager.h b/include/nw4r/snd/snd_Sound3DManager.h index 2ec2204c..8609b453 100644 --- a/include/nw4r/snd/snd_Sound3DManager.h +++ b/include/nw4r/snd/snd_Sound3DManager.h @@ -10,6 +10,19 @@ namespace nw4r { namespace snd { +struct Sound3DParam +{ + /* 0x00 */ u8 _0x00[0x18]; + /* 0x18 */ UNKWORD field_0x18; + /* 0x1C */ u8 field_0x1C; + /* 0x1D */ u8 field_0x1D; + /* 0x1E */ u8 field_0x1E; + /* 0x20 */ UNKWORD field_0x20; + /* 0x24 */ UNKWORD field_0x24; + + Sound3DParam(); +}; + class Sound3DManager : public detail::BasicSound::AmbientInfo::AmbientParamUpdateCallback, public detail::BasicSound::AmbientInfo::AmbientArgAllocaterCallback { public: @@ -51,10 +64,6 @@ public: mMaxPriorityReduction = max; } - f32 GetPanRange() const { - return mPanRange; - } - private: enum ParamDecayCurve { DECAY_CURVE_NONE, @@ -63,16 +72,10 @@ private: }; private: - detail::InstancePool mParamPool; // at 0x8 + detail::InstancePool mParamPool; // at 0x8 Sound3DListener *mListener; // at 0xC - s32 mMaxPriorityReduction; // at 0x10 - - f32 mSpeakerAngleStereo; // at 0x14 - f32 mFrontSpeakerAngleDpl2; // at 0x18 - f32 mRearSpeakerAngleDpl2; // at 0x1C - - f32 mInitPan; // at 0x20 - f32 mPanRange; // at 0x24 + u8 _0x10[0x1C - 0x10]; + s32 mMaxPriorityReduction; // at 0x1C }; } // namespace snd diff --git a/src/nw4r/snd/snd_Sound3DEngine.cpp b/src/nw4r/snd/snd_Sound3DEngine.cpp index e6ddfd4d..f398c5a4 100644 --- a/src/nw4r/snd/snd_Sound3DEngine.cpp +++ b/src/nw4r/snd/snd_Sound3DEngine.cpp @@ -1 +1,34 @@ -// #include "nw4r/snd/snd_Sound3DEngine.h" +#include "nw4r/snd/snd_Sound3DEngine.h" + +namespace nw4r { namespace snd { + +Sound3DEngine::Sound3DEngine() + : mSpeakerAngleStereo(NW4R_MATH_PI / 4), + mFrontSpeakerAngleDpl2(NW4R_MATH_PI / 6), + mRearSpeakerAngleDpl2(2 * NW4R_MATH_PI / 3), + mInitPan(0.0f) {} + +void Sound3DEngine::UpdateAmbientParam( + const Sound3DManager *mgr, const Sound3DParam *pParam, u32, u32 flags, SoundAmbientParam *pAmbientParam +) { + if (flags & 1) + pAmbientParam->volume = 0.0f; + + if (flags & 8) + pAmbientParam->priority = - mgr->GetMaxPriorityReduction(); +} + +void Sound3DEngine::UpdateAmbientParam(const Sound3DManager* mgr, const Sound3DParam* param, u32, int, SoundAmbientParam*) { + +} + +void Sound3DEngine::GetAmbientPriority(const Sound3DManager*, const Sound3DParam*, u32) { + +} + +s32 Sound3DEngine::GetRequiredVoiceOutCount(const Sound3DManager*, const Sound3DParam*, u32) { + return 1; +} + + +}} diff --git a/src/nw4r/snd/snd_Sound3DListener.cpp b/src/nw4r/snd/snd_Sound3DListener.cpp index 9d6a9533..08d64440 100644 --- a/src/nw4r/snd/snd_Sound3DListener.cpp +++ b/src/nw4r/snd/snd_Sound3DListener.cpp @@ -1 +1,62 @@ #include "nw4r/snd/snd_Sound3DListener.h" + +namespace nw4r { +namespace snd { + +Sound3DListener::Sound3DListener() { + mPosition.x = 0.0f; + mPosition.y = 0.0f; + mPosition.z = 0.0f; + mVelocity.x = 0.0f; + mVelocity.y = 0.0f; + mVelocity.z = 0.0f; + mInteriorSize = 1.0f; + mMaxVolumeDistance = 1.0f; + mUnitDistance = 1.0f; + field_0x54 = 0; + mSkipVelocityUpdate = 1; + mUnitBiquadFilterValue = 0.5f; + mUnitBiquadFilterMax = 1.0f; + field_0x64 = 0; + field_0x68 = 0; + math::MTX34Zero(&mMtx); +} + +void Sound3DListener::SetMatrix(const math::MTX34 &mtx) { + math::VEC3 prevPosition = mPosition; + + mPosition.x = -(mtx._00 * mtx._03 + mtx._10 * mtx._13 + mtx._20 * mtx._23); + mPosition.y = -(mtx._01 * mtx._03 + mtx._11 * mtx._13 + mtx._21 * mtx._23); + mPosition.z = -(mtx._02 * mtx._03 + mtx._12 * mtx._13 + mtx._22 * mtx._23); + + if (mSkipVelocityUpdate) { + mMtx = mtx; + mSkipVelocityUpdate = 0; + } else { + mMtx = mtx; + VEC3Sub(&mVelocity, &mPosition, &prevPosition); + } +} + +void Sound3DListener::SetInteriorSize(f32 size) { + mInteriorSize = size; +} + +void Sound3DListener::SetMaxVolumeDistance(f32 distance) { + mMaxVolumeDistance = distance; +} + +void Sound3DListener::SetUnitDistance(f32 distance) { + mUnitDistance = distance; +} + +void Sound3DListener::SetUnitBiquadFilterValue(f32 value) { + mUnitBiquadFilterValue = value; +} + +void Sound3DListener::SetUnitBiquadFilterMax(f32 value) { + mUnitBiquadFilterMax = value; +} + +} // namespace snd +} // namespace nw4r diff --git a/src/nw4r/snd/snd_Sound3DManager.cpp b/src/nw4r/snd/snd_Sound3DManager.cpp index 8a75b573..9fe22d6d 100644 --- a/src/nw4r/snd/snd_Sound3DManager.cpp +++ b/src/nw4r/snd/snd_Sound3DManager.cpp @@ -36,12 +36,7 @@ inline f32 SolveLinerFunction(f32 x, f32 dAngle, f32 cAngle, f32 dFactor, } // namespace Sound3DManager::Sound3DManager() - : mMaxPriorityReduction(32), - mSpeakerAngleStereo(NW4R_MATH_PI / 4), - mFrontSpeakerAngleDpl2(NW4R_MATH_PI / 6), - mRearSpeakerAngleDpl2(2 * NW4R_MATH_PI / 3), - mInitPan(0.0f), - mPanRange(0.9f) {} + {} u32 Sound3DManager::GetRequiredMemSize(const SoundArchive* pArchive) { u32 numParam = 0; @@ -53,7 +48,7 @@ u32 Sound3DManager::GetRequiredMemSize(const SoundArchive* pArchive) { numParam += playerInfo.waveSoundCount; } - return numParam * sizeof(Sound3DActorParam); + return numParam * sizeof(Sound3DParam); } bool Sound3DManager::Setup(const SoundArchive* pArchive, void* pBuffer, @@ -83,7 +78,7 @@ void Sound3DManager::Update(SoundParam* pParam, u32 id, SoundHandle* pHandle, f32 angle; f32 panLR, panFR; f32 pan, surroundPan; - +#if 0 const Sound3DActorParam* pActorParam = static_cast(pArg); @@ -267,10 +262,11 @@ void Sound3DManager::Update(SoundParam* pParam, u32 id, SoundHandle* pHandle, pParam->priority = -static_cast((1.0f - volume) * GetMaxPriorityReduction()); } +#endif } void* Sound3DManager::detail_AllocAmbientArg(u32 size) { - if (size != sizeof(Sound3DActorParam)) { + if (size != sizeof(Sound3DParam)) { return NULL; } @@ -281,7 +277,17 @@ void Sound3DManager::detail_FreeAmbientArg(void* pArg, const detail::BasicSound* pSound) { #pragma unused(pSound) - mParamPool.Free(static_cast(pArg)); + mParamPool.Free(static_cast(pArg)); +} + +Sound3DParam::Sound3DParam() +{ + field_0x18 = 0; + field_0x1C = 1; + field_0x1D = 0x80; + field_0x1E = 0; + field_0x20 = 0; + field_0x24 = 0; } Sound3DManager::Sound3DActorParam::Sound3DActorParam() : userParam(-1) {