snd_Sound3DActor OK

This commit is contained in:
robojumper
2025-05-29 00:59:18 +02:00
parent 2374b07ba4
commit 05fe105f5d
11 changed files with 164 additions and 35 deletions
+7 -7
View File
@@ -19872,7 +19872,7 @@ fn_8035BB20 = .text:0x8035BB20; // type:function size:0x8
fn_8035BB30 = .text:0x8035BB30; // type:function size:0x8
fn_8035BB40 = .text:0x8035BB40; // type:function size:0x8
fn_8035BB50 = .text:0x8035BB50; // type:function size:0x8
fn_8035BB60 = .text:0x8035BB60; // type:function size:0x8
@84@at_0x0c__Q34nw4r3snd12Sound3DActorFPvPQ44nw4r3snd6detail10BasicSound = .text:0x8035BB60; // type:function size:0x8
fn_8035BB70 = .text:0x8035BB70; // type:function size:0x8
fn_8035BB80 = .text:0x8035BB80; // type:function size:0x3C
__dt__Q34nw4r3snd13Sound3DEngineFv = .text:0x8035BBC0; // type:function size:0x40
@@ -25437,9 +25437,9 @@ NoteOn__Q44nw4r3snd6detail8SeqTrackFiilb = .text:0x80474410; // type:function si
__ct__Q34nw4r3snd12Sound3DActorFRQ34nw4r3snd18SoundArchivePlayerRQ34nw4r3snd14Sound3DManager = .text:0x80474820; // type:function size:0x90
__dt__Q34nw4r3snd12Sound3DActorFv = .text:0x804748B0; // type:function size:0xD4
SetupSound__Q34nw4r3snd12Sound3DActorFPQ34nw4r3snd11SoundHandleUlPCQ44nw4r3snd14SoundStartable9StartInfoPv = .text:0x80474990; // type:function size:0x1A8
SetPosition_nw4r_snd_Sound3DActor = .text:0x80474B40; // type:function size:0x50
FUN_80474b90 = .text:0x80474B90; // type:function size:0x3C
@84@__dt__Q34nw4r3snd12Sound3DActorFv = .text:0x80474BD0; // type:function size:0x8
SetPosition__Q34nw4r3snd12Sound3DActorFRCQ34nw4r4math4VEC3 = .text:0x80474B40; // type:function size:0x50
at_0x0c__Q34nw4r3snd12Sound3DActorFPvPQ44nw4r3snd6detail10BasicSound = .text:0x80474B90; // type:function size:0x3C
@84@__dt__Q34nw4r3snd12Sound3DActorFv = .text:0x80474BD0; // type:function size:0x8 scope:weak
CalcVolumeAndPriority__Q34nw4r3snd17Sound3DCalculatorFRCQ34nw4r3snd14Sound3DManagerRCQ34nw4r3snd15Sound3DListenerRCQ34nw4r3snd12Sound3DParamPfPi = .text:0x80474BE0; // type:function size:0x13C
CalcPan__Q34nw4r3snd17Sound3DCalculatorFRCQ34nw4r3snd14Sound3DManagerRCQ34nw4r3snd15Sound3DListenerRCQ34nw4r3snd12Sound3DParamRCQ44nw4r3snd17Sound3DCalculator12CalcPanParamPfPf = .text:0x80474D20; // type:function size:0x160
CalcPitch__Q34nw4r3snd17Sound3DCalculatorFRCQ34nw4r3snd14Sound3DManagerRCQ34nw4r3snd15Sound3DListenerRCQ34nw4r3snd12Sound3DParamPf = .text:0x80474E80; // type:function size:0x1B0
@@ -29158,7 +29158,7 @@ DecibelSquareTable__Q44nw4r3snd6detail12EnvGenerator = .rodata:0x804F8FB8; // ty
@LOCAL@SetAttack__Q44nw4r3snd6detail12EnvGeneratorFi@attackTable = .rodata:0x804F90B8; // type:object size:0x200 scope:weak
@LOCAL@GetSinIdx__Q44nw4r3snd6detail3LfoFi@sinTable = .rodata:0x804F92B8; // type:object size:0x21 scope:weak
@2213 = .rodata:0x804F92E0; // type:object size:0x24 scope:local data:4byte
lbl_804F9308 = .rodata:0x804F9308; // type:object size:0x18 data:4byte
@4458 = .rodata:0x804F9308; // type:object size:0x14 scope:local data:4byte
NoteTable__Q44nw4r3snd6detail4Util = .rodata:0x804F9320; // type:object size:0x30
PitchTable__Q44nw4r3snd6detail4Util = .rodata:0x804F9350; // type:object size:0x400
Decibel2RatioTable__Q44nw4r3snd6detail4Util = .rodata:0x804F9750; // type:object size:0xF14
@@ -38609,7 +38609,7 @@ __vt__Q44nw4r3snd6detail9SeqPlayer = .data:0x8056E024; // type:object size:0x64
__vt__Q44nw4r3snd6detail8SeqSound = .data:0x8056E088; // type:object size:0x38
__vt__Q54nw4r3snd6detail8SeqSound11SeqLoadTask = .data:0x8056E0C0; // type:object size:0x18
__vt__Q44nw4r3snd6detail8SeqTrack = .data:0x8056E0D8; // type:object size:0x10
lbl_8056E0E8 = .data:0x8056E0E8; // type:object size:0x30
__vt__Q34nw4r3snd12Sound3DActor = .data:0x8056E0E8; // type:object size:0x30
__vt__Q34nw4r3snd13Sound3DEngine = .data:0x8056E118; // type:object size:0x1C
__vt__Q34nw4r3snd14Sound3DManager = .data:0x8056E138; // type:object size:0x34
__vt__Q34nw4r3snd10SoundActor = .data:0x8056E170; // type:object size:0x1C
@@ -49717,7 +49717,7 @@ VOLUME_INIT__Q44nw4r3snd6detail12EnvGenerator = .sdata2:0x8057EFD0; // type:obje
@3315 = .sdata2:0x8057F098; // type:object size:0x4 scope:local align:4 data:float
@3319 = .sdata2:0x8057F0A0; // type:object size:0x8 scope:local align:8 data:double
@3320 = .sdata2:0x8057F0A8; // type:object size:0x8 scope:local align:8 data:double
lbl_8057F0B0 = .sdata2:0x8057F0B0; // type:object size:0x4 align:4 data:float
@4796 = .sdata2:0x8057F0B0; // type:object size:0x4 scope:local align:4 data:float
@2828 = .sdata2:0x8057F0B8; // type:object size:0x4 scope:local align:4 data:float
@2829 = .sdata2:0x8057F0BC; // type:object size:0x4 scope:local align:4 data:float
@2830 = .sdata2:0x8057F0C0; // type:object size:0x4 scope:local align:4 data:float
+8 -8
View File
@@ -1024,17 +1024,17 @@ config.libs = [
Object(Matching, "nw4r/snd/snd_BiquadFilterPreset.cpp"),
Object(Matching, "nw4r/snd/snd_Channel.cpp"),
Object(Matching, "nw4r/snd/snd_DisposeCallbackManager.cpp"),
Object(NonMatching, "nw4r/snd/snd_debug.cpp"),
# Object(NonMatching, "nw4r/snd/snd_debug.cpp"),
Object(Matching, "nw4r/snd/snd_DvdSoundArchive.cpp"),
Object(Matching, "nw4r/snd/snd_EnvGenerator.cpp"),
Object(Matching, "nw4r/snd/snd_ExternalSoundPlayer.cpp"),
Object(Matching, "nw4r/snd/snd_FrameHeap.cpp"),
Object(NonMatching, "nw4r/snd/snd_FxBase.cpp"),
Object(NonMatching, "nw4r/snd/snd_FxChorus.cpp"),
Object(NonMatching, "nw4r/snd/snd_FxDelay.cpp"),
Object(NonMatching, "nw4r/snd/snd_FxReverbHi.cpp"),
Object(NonMatching, "nw4r/snd/snd_FxReverbHiDpl2.cpp"),
Object(NonMatching, "nw4r/snd/snd_FxReverbStd.cpp"),
# Object(NonMatching, "nw4r/snd/snd_FxBase.cpp"),
# Object(NonMatching, "nw4r/snd/snd_FxChorus.cpp"),
# Object(NonMatching, "nw4r/snd/snd_FxDelay.cpp"),
# Object(NonMatching, "nw4r/snd/snd_FxReverbHi.cpp"),
# Object(NonMatching, "nw4r/snd/snd_FxReverbHiDpl2.cpp"),
# Object(NonMatching, "nw4r/snd/snd_FxReverbStd.cpp"),
Object(Matching, "nw4r/snd/snd_FxReverbStdDpl2.cpp"),
Object(Matching, "nw4r/snd/snd_InstancePool.cpp"),
Object(Matching, "nw4r/snd/snd_Lfo.cpp"),
@@ -1052,7 +1052,7 @@ config.libs = [
Object(Matching, "nw4r/snd/snd_SeqSound.cpp"),
Object(Matching, "nw4r/snd/snd_SeqSoundHandle.cpp"),
Object(Matching, "nw4r/snd/snd_SeqTrack.cpp"),
Object(NonMatching, "nw4r/snd/snd_Sound3DActor.cpp"),
Object(Matching, "nw4r/snd/snd_Sound3DActor.cpp"),
Object(Matching, "nw4r/snd/snd_Sound3DCalculator.cpp"),
Object(Matching, "nw4r/snd/snd_Sound3DEngine.cpp"),
Object(Matching, "nw4r/snd/snd_Sound3DListener.cpp"),
+6 -2
View File
@@ -186,8 +186,8 @@ namespace nw4r { namespace snd { namespace detail
public:
// virtual function ordering
// vtable AmbientArgUpdateCallback
virtual void at_0x08();
virtual void at_0x0c(void *, void *);
virtual ~AmbientArgUpdateCallback() {}
virtual void at_0x0c(void *, BasicSound *);
// members
private:
@@ -299,6 +299,10 @@ namespace nw4r { namespace snd { namespace detail
PRIORITY_MAX);
}
void ClearAmbientArgUpdateCallback() {
mAmbientInfo.argUpdateCallback = NULL;
}
static int GetAmbientPriority(AmbientInfo const &ambientInfo,
u32 soundId);
@@ -6,6 +6,8 @@
*/
#include "nw4r/snd/snd_BasicSound.h"
#include "nw4r/snd/snd_SoundHandle.h"
#include "nw4r/snd/snd_global.h"
/*******************************************************************************
* classes and functions
@@ -35,6 +37,34 @@ namespace nw4r { namespace snd { namespace detail
bool detail_CanPlaySound(int startPriority);
template <typename TForEachFunc>
TForEachFunc ForEachSound(TForEachFunc pFunc, bool reverse) {
if (reverse) {
detail::BasicSound::ExtSoundPlayerPlayLinkList::ReverseIterator it = mSoundList.GetBeginReverseIter();
while (it != mSoundList.GetEndReverseIter()) {
detail::BasicSound::ExtSoundPlayerPlayLinkList::ReverseIterator curr = it;
SoundHandle handle;
handle.detail_AttachSoundAsTempHandle(&*curr);
pFunc(handle);
if (handle.IsAttachedSound()) {
++it;
}
}
} else {
NW4R_RANGE_FOR_NO_AUTO_INC(it, mSoundList) {
decltype(it) curItr = it++;
SoundHandle handle;
handle.detail_AttachSoundAsTempHandle(&*curItr);
pFunc(handle);
}
}
return pFunc;
}
private:
BasicSound *GetLowestPrioritySound();
+11 -13
View File
@@ -2,11 +2,11 @@
#ifndef NW4R_SND_SOUND_3D_ACTOR_H
#define NW4R_SND_SOUND_3D_ACTOR_H
#include "nw4r/math.h"
#include "nw4r/snd/snd_BasicSound.h"
#include "nw4r/snd/snd_SoundActor.h"
#include "nw4r/types_nw4r.h"
#include "nw4r/math.h"
namespace nw4r {
namespace snd {
@@ -14,16 +14,12 @@ namespace snd {
class Sound3DActor : public SoundActor, public detail::BasicSound::AmbientInfo::AmbientArgUpdateCallback {
public:
Sound3DActor(SoundArchivePlayer &rPlayer, Sound3DManager &rManager);
virtual ~Sound3DActor(); // at 0x8
virtual ~Sound3DActor();
virtual StartResult detail_SetupSound(
SoundHandle *pHandle, u32 id, detail::BasicSound::AmbientInfo *pArgInfo,
detail::ExternalSoundPlayer *pPlayer, bool hold,
const StartInfo *pStartInfo
); // at 0xC
virtual StartResult SetupSound(SoundHandle *pHandle, u32 soundId, const StartInfo *pStartInfo, void *) override;
virtual void detail_Update(void *pArg,
const detail::BasicSound *pSound); // at 0xC
// AmbientArgUpdateCallback
virtual void at_0x0c(void *arg, detail::BasicSound* sound) override;
void SetPosition(const math::VEC3 &rPosition);
@@ -31,10 +27,12 @@ private:
static void ClearUpdateCallback(SoundHandle &rHandle);
private:
Sound3DManager &m3DManager; // at 0xAC
SoundArchivePlayer &mSoundArchivePlayer; // at 0xB0
u32 mUserParam; // at 0xB4
math::VEC3 mPosition; // at 0xB8
Sound3DManager &m3DManager; // at 0x58
SoundArchivePlayer *mSoundArchivePlayer; // at 0x5C
u32 mUserParam; // at 0x60
math::VEC3 mPosition; // at 0x64
math::VEC3 mVelocity; // at 0x70
bool mSkipVelocityUpdate; // at 0x7C
};
} // namespace snd
+2 -2
View File
@@ -14,12 +14,12 @@ namespace snd {
struct Sound3DParam {
/* 0x00 */ math::VEC3 position;
/* 0x0C */ math::VEC3 field_0x0C;
/* 0x0C */ math::VEC3 velocity;
/* 0x18 */ UNKWORD field_0x18;
/* 0x1C */ u8 decayCurve;
/* 0x1D */ u8 decayRatio;
/* 0x1E */ u8 field_0x1E;
/* 0x20 */ UNKWORD field_0x20;
/* 0x20 */ u32 userParam;
/* 0x24 */ UNKWORD field_0x24;
Sound3DParam();
+10
View File
@@ -50,6 +50,16 @@ namespace nw4r { namespace snd
return &mActorPlayer[actorPlayerId];
}
template <typename TForEachFunc>
TForEachFunc ForEachSound(TForEachFunc pFunc, bool reverse) {
for (int i = 0; i < ACTOR_PLAYER_COUNT; i++) {
mActorPlayer[i].ForEachSound(pFunc, reverse);
}
return pFunc;
}
detail::SoundActorParam const &detail_GetActorParam() const
{
return mActorParam;
+1
View File
@@ -123,6 +123,7 @@ namespace nw4r { namespace snd
u32 flags; // at 0x0
u8 decayCurve; // at 0x4
u8 decayRatio; // at 0x5
u8 field_0x06; // at 0x6
};
// [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x256dc
+86
View File
@@ -1 +1,87 @@
#include "nw4r/snd/snd_Sound3DActor.h"
#include "nw4r/snd/snd_BasicSound.h"
#include "nw4r/snd/snd_ExternalSoundPlayer.h"
#include "nw4r/snd/snd_Sound3DManager.h"
#include "nw4r/snd/snd_SoundArchive.h"
#include "nw4r/snd/snd_SoundArchivePlayer.h"
#include "nw4r/snd/snd_SoundHandle.h"
#include "nw4r/snd/snd_SoundStartable.h"
#include "nw4r/snd/snd_global.h"
namespace nw4r {
namespace snd {
Sound3DActor::Sound3DActor(SoundArchivePlayer &rPlayer, Sound3DManager &rManager)
: SoundActor(rPlayer),
m3DManager(rManager),
mSoundArchivePlayer(&rPlayer),
mUserParam(0),
mPosition(0.0f, 0.0f, 0.0f),
mVelocity(0.0f, 0.0f, 0.0f),
mSkipVelocityUpdate(true) {}
Sound3DActor::~Sound3DActor() {
ForEachSound(ClearUpdateCallback, false);
}
SoundStartable::StartResult
Sound3DActor::SetupSound(SoundHandle *pHandle, u32 soundId, const StartInfo *pStartInfo, void *pArg) {
Sound3DParam param;
param.position = mPosition;
param.velocity = mVelocity;
param.userParam = mUserParam;
if (mSoundArchivePlayer != NULL) {
const SoundArchive &archive = mSoundArchivePlayer->GetSoundArchive();
nw4r::snd::SoundArchive::Sound3DParam arParam;
if (archive.detail_ReadSound3DParam(soundId, &arParam)) {
param.field_0x18 = arParam.flags;
param.decayRatio = arParam.decayRatio;
param.field_0x1E = arParam.field_0x06;
switch (arParam.decayCurve) {
case 1: param.decayCurve = 1; break;
case 2: param.decayCurve = 2; break;
default: param.decayCurve = 1; break;
}
}
param.field_0x24 = archive.GetSoundUserParam(soundId);
}
detail::BasicSound::AmbientInfo info = {
&m3DManager, this, &m3DManager, &param, sizeof(Sound3DParam),
};
SoundStartable::StartResult result =
SoundActor::detail_SetupSoundWithAmbientInfo(pHandle, soundId, pStartInfo, &info, pArg);
if (pHandle->detail_GetAttachedSound() != NULL) {
pHandle->detail_GetAttachedSound()->SetPanCurve(PAN_CURVE_SINCOS);
}
return result;
}
void Sound3DActor::SetPosition(const math::VEC3 &position) {
if (!mSkipVelocityUpdate) {
VEC3Sub(&mVelocity, &position, &mPosition);
}
mPosition = position;
mSkipVelocityUpdate = 0;
}
void Sound3DActor::at_0x0c(void *arg, detail::BasicSound *sound) {
Sound3DParam *p = static_cast<Sound3DParam *>(arg);
p->position = mPosition;
p->velocity = mVelocity;
p->userParam = mUserParam;
}
void Sound3DActor::ClearUpdateCallback(SoundHandle& rHandle) {
if (rHandle.IsAttachedSound()) {
rHandle.detail_GetAttachedSound()->ClearAmbientArgUpdateCallback();
}
}
} // namespace snd
} // namespace nw4r
+2 -2
View File
@@ -131,10 +131,10 @@ void Sound3DCalculator::CalcPitch(
f32 f3 = param.field_0x1E / 32.0f;
f32 f1, f2;
if (distance > 0.0f) {
f1 = -math::VEC3Dot(&relativePos, &param.field_0x0C);
f1 = -math::VEC3Dot(&relativePos, &param.velocity);
f2 = -math::VEC3Dot(&relativePos, &listener.GetVelocity());
} else {
f1 = -math::VEC3Len(&param.field_0x0C);
f1 = -math::VEC3Len(&param.velocity);
f2 = math::VEC3Len(&listener.GetVelocity());
}
f32 pitch;
+1 -1
View File
@@ -94,7 +94,7 @@ Sound3DParam::Sound3DParam() {
decayCurve = Sound3DManager::DECAY_CURVE_LOGARITHMIC;
decayRatio = 128;
field_0x1E = 0;
field_0x20 = 0;
userParam = 0;
field_0x24 = 0;
}