snd_Sound3DEngine OK

This commit is contained in:
robojumper
2025-05-28 01:18:53 +02:00
parent 23fe65685a
commit 7dde7fec51
9 changed files with 178 additions and 54 deletions
+1 -1
View File
@@ -1 +1 @@
// #include "nw4r/snd/snd_Sound3DCalculator.h"
#include "nw4r/snd/snd_Sound3DCalculator.h"
+91 -15
View File
@@ -1,34 +1,110 @@
#include "nw4r/snd/snd_Sound3DEngine.h"
namespace nw4r { namespace snd {
#include "nw4r/snd/snd_Sound3DCalculator.h"
#include "nw4r/snd/snd_Sound3DListener.h"
#include "nw4r/snd/snd_Sound3DManager.h"
#include "nw4r/snd/snd_global.h"
Sound3DEngine::Sound3DEngine()
: mSpeakerAngleStereo(NW4R_MATH_PI / 4),
mFrontSpeakerAngleDpl2(NW4R_MATH_PI / 6),
mRearSpeakerAngleDpl2(2 * NW4R_MATH_PI / 3),
mInitPan(0.0f) {}
namespace nw4r {
namespace snd {
Sound3DEngine::Sound3DEngine() {}
void Sound3DEngine::UpdateAmbientParam(
const Sound3DManager *mgr, const Sound3DParam *pParam, u32, u32 flags, SoundAmbientParam *pAmbientParam
) {
if (flags & 1)
if (flags & 1) {
pAmbientParam->volume = 0.0f;
}
if (flags & 8)
pAmbientParam->priority = - mgr->GetMaxPriorityReduction();
if (flags & 8) {
pAmbientParam->priority = -mgr->GetMaxPriorityReduction();
}
if (mgr->GetListenerList().GetSize() > 1) {
flags &= -0x17;
}
NW4R_RANGE_FOR(it, mgr->GetListenerList()) {
const Sound3DListener &listener = *it;
if (flags & 9) {
f32 volume;
int priority;
Sound3DCalculator::CalcVolumeAndPriority(*mgr, listener, *pParam, &volume, &priority);
if (flags & 1) {
pAmbientParam->volume = ut::Max(volume, pAmbientParam->volume);
}
if (flags & 8) {
pAmbientParam->priority = ut::Max(priority, pAmbientParam->priority);
}
}
if (flags & 6) {
f32 pan, surroundPan;
Sound3DCalculator::CalcPan(*mgr, listener, *pParam, mPanParam, &pan, &surroundPan);
if (flags & 2) {
pAmbientParam->pan = pan;
}
if (flags & 4) {
pAmbientParam->surroundPan = surroundPan;
}
}
if (flags & 0x10) {
f32 pitch;
Sound3DCalculator::CalcPitch(*mgr, listener, *pParam, &pitch);
pAmbientParam->pitch = pitch;
}
if (flags & 0x20) {
f32 biquadFilterValue;
Sound3DCalculator::CalcBiquadFilterValue(*mgr, listener, *pParam, &biquadFilterValue);
pAmbientParam->biquadFilterType = mgr->GetBiquadFilterType();
pAmbientParam->biquadFilterValue = ut::Min(biquadFilterValue, pAmbientParam->biquadFilterValue);
}
}
}
void Sound3DEngine::UpdateAmbientParam(const Sound3DManager* mgr, const Sound3DParam* param, u32, int, SoundAmbientParam*) {
void Sound3DEngine::UpdateAmbientParam(
const Sound3DManager *mgr, const Sound3DParam *param, u32 unused1, int unused2, SoundAmbientParam *pAmbientParam
) {
u32 flags = 0x1F;
if (param->field_0x18 & 1) {
flags &= ~1;
}
if (param->field_0x18 & 2) {
flags &= ~2;
}
if (param->field_0x18 & 4) {
flags &= ~4;
}
if (param->field_0x18 & 8) {
flags &= ~8;
}
if (!param->field_0x1E) {
flags &= ~0x10;
}
if (param->field_0x18 & 0x10) {
flags |= 0x20;
}
UpdateAmbientParam(mgr, param, unused1, flags, pAmbientParam);
}
void Sound3DEngine::GetAmbientPriority(const Sound3DManager*, const Sound3DParam*, u32) {
s32 Sound3DEngine::GetAmbientPriority(const Sound3DManager *mgr, const Sound3DParam *param, u32 arg) {
u32 flags = 0x1000008;
if (param->field_0x18 & 8) {
flags &= ~8;
}
SoundAmbientParam ambientParam;
UpdateAmbientParam(mgr, param, arg, flags, &ambientParam);
return ambientParam.priority;
}
s32 Sound3DEngine::GetRequiredVoiceOutCount(const Sound3DManager*, const Sound3DParam*, u32) {
s32 Sound3DEngine::GetRequiredVoiceOutCount(const Sound3DManager *, const Sound3DParam *, u32) {
return 1;
}
}}
} // namespace snd
} // namespace nw4r
+10 -16
View File
@@ -3,22 +3,16 @@
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;
Sound3DListener::Sound3DListener()
: mPosition(0.0f, 0.0f, 0.0f),
mVelocity(0.0f, 0.0f, 0.0f),
mInteriorSize(1.0f),
mMaxVolumeDistance(1.0f),
mUnitDistance(1.0f),
field_0x54(0),
mSkipVelocityUpdate(1),
mUnitBiquadFilterValue(0.5f),
mUnitBiquadFilterMax(1.0f) {
math::MTX34Zero(&mMtx);
}