Audio/AudioSource: Add GetSampleOffsetAndLatency
This commit is contained in:
parent
41712a3f18
commit
17b1c2407d
|
|
@ -20,6 +20,8 @@ namespace Nz
|
||||||
class NAZARA_AUDIO_API AudioSource
|
class NAZARA_AUDIO_API AudioSource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
struct OffsetWithLatency;
|
||||||
|
|
||||||
inline AudioSource(std::shared_ptr<AudioDevice> device);
|
inline AudioSource(std::shared_ptr<AudioDevice> device);
|
||||||
AudioSource(const AudioSource&) = delete;
|
AudioSource(const AudioSource&) = delete;
|
||||||
AudioSource(AudioSource&&) = delete;
|
AudioSource(AudioSource&&) = delete;
|
||||||
|
|
@ -34,6 +36,7 @@ namespace Nz
|
||||||
virtual float GetPitch() const = 0;
|
virtual float GetPitch() const = 0;
|
||||||
virtual Vector3f GetPosition() const = 0;
|
virtual Vector3f GetPosition() const = 0;
|
||||||
virtual UInt32 GetSampleOffset() const = 0;
|
virtual UInt32 GetSampleOffset() const = 0;
|
||||||
|
virtual OffsetWithLatency GetSampleOffsetAndLatency() const = 0;
|
||||||
virtual Vector3f GetVelocity() const = 0;
|
virtual Vector3f GetVelocity() const = 0;
|
||||||
virtual SoundStatus GetStatus() const = 0;
|
virtual SoundStatus GetStatus() const = 0;
|
||||||
virtual float GetVolume() const = 0;
|
virtual float GetVolume() const = 0;
|
||||||
|
|
@ -64,6 +67,12 @@ namespace Nz
|
||||||
AudioSource& operator=(const AudioSource&) = delete;
|
AudioSource& operator=(const AudioSource&) = delete;
|
||||||
AudioSource& operator=(AudioSource&&) = delete;
|
AudioSource& operator=(AudioSource&&) = delete;
|
||||||
|
|
||||||
|
struct OffsetWithLatency
|
||||||
|
{
|
||||||
|
UInt64 sampleOffset;
|
||||||
|
UInt64 sourceLatency;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<AudioDevice> m_device;
|
std::shared_ptr<AudioDevice> m_device;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ namespace Nz
|
||||||
float GetPitch() const override;
|
float GetPitch() const override;
|
||||||
Vector3f GetPosition() const override;
|
Vector3f GetPosition() const override;
|
||||||
UInt32 GetSampleOffset() const override;
|
UInt32 GetSampleOffset() const override;
|
||||||
|
OffsetWithLatency GetSampleOffsetAndLatency() const override;
|
||||||
Vector3f GetVelocity() const override;
|
Vector3f GetVelocity() const override;
|
||||||
SoundStatus GetStatus() const override;
|
SoundStatus GetStatus() const override;
|
||||||
float GetVolume() const override;
|
float GetVolume() const override;
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ namespace Nz
|
||||||
float GetPitch() const override;
|
float GetPitch() const override;
|
||||||
Vector3f GetPosition() const override;
|
Vector3f GetPosition() const override;
|
||||||
UInt32 GetSampleOffset() const override;
|
UInt32 GetSampleOffset() const override;
|
||||||
|
OffsetWithLatency GetSampleOffsetAndLatency() const override;
|
||||||
Vector3f GetVelocity() const override;
|
Vector3f GetVelocity() const override;
|
||||||
SoundStatus GetStatus() const override;
|
SoundStatus GetStatus() const override;
|
||||||
float GetVolume() const override;
|
float GetVolume() const override;
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,15 @@ namespace Nz
|
||||||
return SafeCast<UInt32>(sampleOffset);
|
return SafeCast<UInt32>(sampleOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto DummyAudioSource::GetSampleOffsetAndLatency() const -> OffsetWithLatency
|
||||||
|
{
|
||||||
|
OffsetWithLatency info;
|
||||||
|
info.sampleOffset = GetSampleOffset() * 1000;
|
||||||
|
info.sourceLatency = 0;
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
Vector3f DummyAudioSource::GetVelocity() const
|
Vector3f DummyAudioSource::GetVelocity() const
|
||||||
{
|
{
|
||||||
return m_velocity;
|
return m_velocity;
|
||||||
|
|
|
||||||
|
|
@ -75,23 +75,33 @@ namespace Nz
|
||||||
{
|
{
|
||||||
GetDevice().MakeContextCurrent();
|
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))
|
if (GetDevice().IsExtensionSupported(OpenALExtension::SourceLatency))
|
||||||
{
|
{
|
||||||
|
GetDevice().MakeContextCurrent();
|
||||||
|
|
||||||
std::array<ALint64SOFT, 2> values;
|
std::array<ALint64SOFT, 2> values;
|
||||||
m_library.alGetSourcei64vSOFT(m_sourceId, AL_SAMPLE_OFFSET_LATENCY_SOFT, values.data());
|
m_library.alGetSourcei64vSOFT(m_sourceId, AL_SAMPLE_OFFSET_LATENCY_SOFT, values.data());
|
||||||
|
|
||||||
ALint64SOFT sampleOffset = (values[0] & 0xFFFFFFFF00000000) >> 32;
|
offsetWithLatency.sampleOffset = ((values[0] & 0xFFFFFFFF00000000) >> 32) * 1'000;
|
||||||
ALint64SOFT latency = values[1] / 1'000'000;
|
offsetWithLatency.sourceLatency = values[1] / 1'000;
|
||||||
|
|
||||||
return SafeCast<UInt32>(sampleOffset + latency);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ALint samples = 0;
|
offsetWithLatency.sampleOffset = GetSampleOffset() * 1'000;
|
||||||
m_library.alGetSourcei(m_sourceId, AL_SAMPLE_OFFSET, &samples);
|
offsetWithLatency.sourceLatency = 0;
|
||||||
|
|
||||||
return SafeCast<UInt32>(samples);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return offsetWithLatency;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3f OpenALSource::GetVelocity() const
|
Vector3f OpenALSource::GetVelocity() const
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue