Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsValid methods for AudioEmitter and AudioListener #465

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions Audio/SoundCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,33 @@ namespace

return true;
}

inline bool IsValid(const X3DAUDIO_DISTANCE_CURVE& curve) noexcept
{
// These match the validation ranges in X3DAudio.
if (!curve.pPoints)
return false;

if (curve.PointCount < 2)
return false;

if (curve.pPoints[0].Distance != 0.f)
return false;

if (curve.pPoints[curve.PointCount - 1].Distance != 1.f)
return false;

for (uint32_t j = 0; j < curve.PointCount; ++j)
{
if (curve.pPoints[j].Distance < 0.f || curve.pPoints[j].Distance > 1.f)
return false;

if (!std::isfinite(curve.pPoints[j].DSPSetting))
return false;
}

return true;
}
}

void AudioListener::SetCone(const X3DAUDIO_CONE& listenerCone)
Expand All @@ -880,6 +907,44 @@ void AudioListener::SetCone(const X3DAUDIO_CONE& listenerCone)
pCone = &ListenerCone;
}

bool AudioListener::IsValid() const
{
if (!std::isfinite(OrientFront.x))
return false;
if (!std::isfinite(OrientFront.y))
return false;
if (!std::isfinite(OrientFront.z))
return false;

if (!std::isfinite(OrientTop.x))
return false;
if (!std::isfinite(OrientTop.y))
return false;
if (!std::isfinite(OrientTop.z))
return false;

if (!std::isfinite(Position.x))
return false;
if (!std::isfinite(Position.y))
return false;
if (!std::isfinite(Position.z))

if (!std::isfinite(Velocity.x))
return false;
if (!std::isfinite(Velocity.y))
return false;
if (!std::isfinite(Velocity.z))
return false;

if (pCone)
{
if (!::IsValid(*pCone))
return false;
}

return true;
}

void AudioEmitter::SetCone(const X3DAUDIO_CONE& emitterCone)
{
if (!::IsValid(emitterCone))
Expand All @@ -889,6 +954,101 @@ void AudioEmitter::SetCone(const X3DAUDIO_CONE& emitterCone)
pCone = &EmitterCone;
}

bool AudioEmitter::IsValid() const
{
if (!std::isfinite(OrientFront.x))
return false;
if (!std::isfinite(OrientFront.y))
return false;
if (!std::isfinite(OrientFront.z))
return false;

if (!std::isfinite(OrientTop.x))
return false;
if (!std::isfinite(OrientTop.y))
return false;
if (!std::isfinite(OrientTop.z))
return false;

if (!std::isfinite(Position.x))
return false;
if (!std::isfinite(Position.y))
return false;
if (!std::isfinite(Position.z))

if (!std::isfinite(Velocity.x))
return false;
if (!std::isfinite(Velocity.y))
return false;
if (!std::isfinite(Velocity.z))
return false;

if (pCone)
{
if (!::IsValid(*pCone))
return false;
}

if (!std::isfinite(InnerRadius))
return false;
if (!std::isfinite(InnerRadiusAngle))
return false;

if (ChannelCount == 0 || ChannelCount > XAUDIO2_MAX_AUDIO_CHANNELS)
return false;

if (ChannelCount > 1)
{
if (!pChannelAzimuths)
return false;

for (uint32_t j = 0; j < ChannelCount; ++j)
{
if (pChannelAzimuths[j] < 0.f || pChannelAzimuths[j] > X3DAUDIO_2PI)
return false;
}
}

if (!std::isfinite(ChannelRadius))
return false;
if (!std::isfinite(CurveDistanceScaler))
return false;
if (!std::isfinite(DopplerScaler))
return false;

if (pVolumeCurve)
{
if (!::IsValid(*pVolumeCurve))
return false;
}

if (pLFECurve)
{
if (!::IsValid(*pLFECurve))
return false;
}

if (pLPFDirectCurve)
{
if (!::IsValid(*pLPFDirectCurve))
return false;
}

if (pLPFReverbCurve)
{
if (!::IsValid(*pLPFReverbCurve))
return false;
}

if (pReverbCurve)
{
if (!::IsValid(*pReverbCurve))
return false;
}

return true;
}

namespace
{
// **Note these constants came from xact3d3.h in the legacy DirectX SDK**
Expand Down
4 changes: 4 additions & 0 deletions Inc/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ namespace DirectX
}

void __cdecl SetCone(const X3DAUDIO_CONE& listenerCone);

bool __cdecl IsValid() const;
};


Expand Down Expand Up @@ -666,6 +668,8 @@ namespace DirectX
pLPFReverbCurve = nullptr;
pReverbCurve = nullptr;
}

bool __cdecl IsValid() const;
};


Expand Down
Loading