Audio/AudioSource: Add GetSampleOffsetAndLatency
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user