Audio: Add support for AL_SOFT_source_latency

This commit is contained in:
SirLynix
2022-05-08 13:20:55 +02:00
parent b8b0057ca3
commit 4794073b73
7 changed files with 68 additions and 14 deletions

View File

@@ -47,6 +47,10 @@ namespace Nz
else if (library.alIsExtensionPresent("AL_LOKI_quadriphonic"))
m_audioFormatValues[UnderlyingCast(AudioFormat::I16_Quad)] = m_library.alGetEnumValue("AL_FORMAT_QUAD16_LOKI");
m_extensionStatus.fill(false);
if (library.alIsExtensionPresent("AL_SOFT_source_latency"))
m_extensionStatus[UnderlyingCast(OpenALExtension::SourceLatency)] = true;
SetListenerDirection(Vector3f::Forward());
}

View File

@@ -50,7 +50,7 @@ namespace Nz
if (!m_library.Load(libname))
continue;
auto LoadSymbol = [this](const char* name)
auto LoadSymbol = [this](const char* name, bool optional)
{
DynLibFunc funcPtr = m_library.GetSymbol(name);
if (!funcPtr)
@@ -61,10 +61,12 @@ namespace Nz
try
{
#define NAZARA_AUDIO_FUNC(name, sig) name = reinterpret_cast<sig>(LoadSymbol(#name));
NAZARA_AUDIO_FOREACH_AL_FUNC(NAZARA_AUDIO_FUNC)
NAZARA_AUDIO_FOREACH_ALC_FUNC(NAZARA_AUDIO_FUNC)
#define NAZARA_AUDIO_FUNC(name, sig) name = reinterpret_cast<sig>(LoadSymbol(#name, false));
#define NAZARA_AUDIO_EXT_FUNC(name, sig) name = reinterpret_cast<sig>(LoadSymbol(#name, true));
NAZARA_AUDIO_FOREACH_AL_FUNC(NAZARA_AUDIO_FUNC, NAZARA_AUDIO_EXT_FUNC)
NAZARA_AUDIO_FOREACH_ALC_FUNC(NAZARA_AUDIO_FUNC, NAZARA_AUDIO_EXT_FUNC)
#undef NAZARA_AUDIO_FUNC
#undef NAZARA_AUDIO_EXT_FUNC
}
catch (const std::exception& e)
{
@@ -110,8 +112,8 @@ namespace Nz
return;
#define NAZARA_AUDIO_FUNC(name, sig) name = nullptr;
NAZARA_AUDIO_FOREACH_AL_FUNC(NAZARA_AUDIO_FUNC)
NAZARA_AUDIO_FOREACH_ALC_FUNC(NAZARA_AUDIO_FUNC)
NAZARA_AUDIO_FOREACH_AL_FUNC(NAZARA_AUDIO_FUNC, NAZARA_AUDIO_FUNC)
NAZARA_AUDIO_FOREACH_ALC_FUNC(NAZARA_AUDIO_FUNC, NAZARA_AUDIO_FUNC)
#undef NAZARA_AUDIO_FUNC
m_library.Unload();

View File

@@ -75,10 +75,23 @@ namespace Nz
{
GetDevice().MakeContextCurrent();
ALint samples = 0;
m_library.alGetSourcei(m_sourceId, AL_SAMPLE_OFFSET, &samples);
if (GetDevice().IsExtensionSupported(OpenALExtension::SourceLatency))
{
std::array<ALint64SOFT, 2> values;
m_library.alGetSourcei64vSOFT(m_sourceId, AL_SAMPLE_OFFSET_LATENCY_SOFT, values.data());
return SafeCast<UInt32>(samples);
ALint64SOFT sampleOffset = (values[0] & 0xFFFFFFFF00000000) >> 32;
ALint64SOFT latency = values[1] / 1'000'000;
return SafeCast<UInt32>(sampleOffset + latency);
}
else
{
ALint samples = 0;
m_library.alGetSourcei(m_sourceId, AL_SAMPLE_OFFSET, &samples);
return SafeCast<UInt32>(samples);
}
}
Vector3f OpenALSource::GetVelocity() const