More AudioEmitter / AudioListener methods (#330)

This commit is contained in:
Chuck Walbourn 2022-08-24 14:36:53 -07:00 коммит произвёл GitHub
Родитель 2c9dc8930d
Коммит 0d721ee17a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 99 добавлений и 9 удалений

Просмотреть файл

@ -822,9 +822,63 @@ void SoundEffectInstanceBase::Apply3D(const X3DAUDIO_LISTENER& listener, const X
//======================================================================================
// AudioEmitter helper
// AudioListener/Emitter helpers
//======================================================================================
namespace
{
inline bool IsValid(const X3DAUDIO_CONE& cone) noexcept
{
// These match the validation ranges in X3DAudio.
if (cone.InnerAngle < 0.f || cone.InnerAngle > X3DAUDIO_2PI)
return false;
if (cone.OuterAngle < 0.f || cone.OuterAngle > X3DAUDIO_2PI)
return false;
if (cone.InnerAngle > cone.OuterAngle)
return false;
if (cone.InnerVolume < 0.f || cone.InnerVolume > 2.f)
return false;
if (cone.OuterVolume < 0.f || cone.OuterVolume > 2.f)
return false;
if (cone.InnerLPF < 0.f || cone.InnerLPF > 1.f)
return false;
if (cone.OuterLPF < 0.f || cone.OuterLPF > 1.f)
return false;
if (cone.InnerReverb < 0.f || cone.InnerReverb > 2.f)
return false;
if (cone.OuterReverb < 0.f || cone.OuterReverb > 2.f)
return false;
return true;
}
}
void AudioListener::SetCone(const X3DAUDIO_CONE& listenerCone)
{
if (!::IsValid(listenerCone))
throw std::invalid_argument("X3DAUDIO_CONE values out of range");
ListenerCone = listenerCone;
pCone = &ListenerCone;
}
void AudioEmitter::SetCone(const X3DAUDIO_CONE& emitterCone)
{
if (!::IsValid(emitterCone))
throw std::invalid_argument("X3DAUDIO_CONE values out of range");
EmitterCone = emitterCone;
pCone = &EmitterCone;
}
namespace
{
// **Note these constants came from xact3d3.h in the legacy DirectX SDK**
@ -891,3 +945,17 @@ void AudioEmitter::EnableDefaultMultiChannel(unsigned int channels, float radius
memset(EmitterAzimuths, 0, sizeof(float) * size_t(channels));
}
}
namespace
{
// **Note these match the defaults from xact3d3.h in the legacy DirectX SDK**
constexpr X3DAUDIO_DISTANCE_CURVE_POINT c_defaultCurvePoints[2] = { { 0.0f, 1.0f }, { 1.0f, 1.0f } };
constexpr X3DAUDIO_DISTANCE_CURVE c_defaultCurve = { const_cast<X3DAUDIO_DISTANCE_CURVE_POINT*>(c_defaultCurvePoints), 2 };
}
void AudioEmitter::EnableDefaultCurves() noexcept
{
pVolumeCurve = const_cast<X3DAUDIO_DISTANCE_CURVE*>(&c_defaultCurve);
pLFECurve = const_cast<X3DAUDIO_DISTANCE_CURVE*>(&c_defaultCurve);
pLPFDirectCurve = pLPFReverbCurve = pReverbCurve = nullptr;
}

Просмотреть файл

@ -434,10 +434,12 @@ namespace DirectX
//----------------------------------------------------------------------------------
struct AudioListener : public X3DAUDIO_LISTENER
{
AudioListener() noexcept
{
memset(this, 0, sizeof(X3DAUDIO_LISTENER));
X3DAUDIO_CONE ListenerCone;
AudioListener() noexcept :
X3DAUDIO_LISTENER{},
ListenerCone{}
{
OrientFront.z = -1.f;
OrientTop.y = 1.f;
@ -486,8 +488,8 @@ namespace DirectX
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientTop), up);
}
// Updates velocity and orientation by tracking changes in position over time.
void XM_CALLCONV Update(FXMVECTOR newPos, XMVECTOR upDir, float dt) noexcept
// Updates velocity and orientation by tracking changes in position over time...
{
if (dt > 0.f)
{
@ -511,19 +513,27 @@ namespace DirectX
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&Position), newPos);
}
}
void __cdecl SetOmnidirectional() noexcept
{
pCone = nullptr;
}
void __cdecl SetCone(const X3DAUDIO_CONE& listenerCone);
};
//----------------------------------------------------------------------------------
struct AudioEmitter : public X3DAUDIO_EMITTER
{
float EmitterAzimuths[XAUDIO2_MAX_AUDIO_CHANNELS];
X3DAUDIO_CONE EmitterCone;
float EmitterAzimuths[XAUDIO2_MAX_AUDIO_CHANNELS];
AudioEmitter() noexcept :
X3DAUDIO_EMITTER{},
EmitterCone{},
EmitterAzimuths{}
{
memset(this, 0, sizeof(X3DAUDIO_EMITTER));
OrientFront.z = -1.f;
OrientTop.y =
@ -580,8 +590,8 @@ namespace DirectX
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientTop), up);
}
// Updates velocity and orientation by tracking changes in position over time.
void XM_CALLCONV Update(FXMVECTOR newPos, XMVECTOR upDir, float dt) noexcept
// Updates velocity and orientation by tracking changes in position over time...
{
if (dt > 0.f)
{
@ -606,7 +616,19 @@ namespace DirectX
}
}
void __cdecl SetOmnidirectional() noexcept
{
pCone = nullptr;
}
// Only used for single-channel emitters.
void __cdecl SetCone(const X3DAUDIO_CONE& emitterCone);
// Set multi-channel emitter azimuths based on speaker configuration geometry.
void __cdecl EnableDefaultMultiChannel(unsigned int channels, float radius = 1.f);
// Set default volume, LFE, LPF, and reverb curves.
void __cdecl EnableDefaultCurves() noexcept;
};