snd_Sound3DListener OK

This commit is contained in:
robojumper
2025-05-28 00:25:36 +02:00
parent e95b03506b
commit 23fe65685a
8 changed files with 188 additions and 43 deletions
+34 -1
View File
@@ -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;
}
}}
+61
View File
@@ -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
+16 -10
View File
@@ -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<const Sound3DActorParam*>(pArg);
@@ -267,10 +262,11 @@ void Sound3DManager::Update(SoundParam* pParam, u32 id, SoundHandle* pHandle,
pParam->priority =
-static_cast<int>((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<Sound3DActorParam*>(pArg));
mParamPool.Free(static_cast<Sound3DParam*>(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) {