Audio/AudioSource: Add GetSampleOffsetAndLatency

This commit is contained in:
Lynix
2022-05-08 15:44:41 +02:00
parent 41712a3f18
commit 17b1c2407d
5 changed files with 37 additions and 7 deletions

View File

@@ -68,6 +68,15 @@ namespace Nz
return SafeCast<UInt32>(sampleOffset);
}
auto DummyAudioSource::GetSampleOffsetAndLatency() const -> OffsetWithLatency
{
OffsetWithLatency info;
info.sampleOffset = GetSampleOffset() * 1000;
info.sourceLatency = 0;
return info;
}
Vector3f DummyAudioSource::GetVelocity() const
{
return m_velocity;

View File

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