// AL_SOFT_source_latency / ALC_SOFT_device_clock source-side queries, dispatched through the
// extension d/i64 entry points rather than the core f/i ones.
//
// Hand-written rather than generated because the registry can't supply the docs (al.xml has no
// prose for these enums) and misdescribes their shape (the *_OFFSET_CLOCK_SOFT params are declared
// scalar though openal-soft fills two slots).
//
// The pair types are record structs, not vectors: each native result is a 2-element array whose
// slots hold DIFFERENT quantities (an offset paired with a latency or clock reading), co-sampled
// in one call. A math vector would offer meaningless arithmetic across the two.
namespace Brutal.OpenAlApi;
/// A source's playback sample offset paired with its output latency. Provided by AL_SOFT_source_latency.
/// 32.32 fixed-point sample offset (high 32 bits: whole samples).
/// Nanoseconds until the sample at the offset is audible.
public readonly record struct AlSampleOffsetLatency(long SampleOffset, long Latency)
{
/// The whole-sample part of (its high 32 bits).
public int WholeSamples => (int)(SampleOffset >> 32);
}
/// A source's playback sample offset paired with the device clock. Provided by ALC_SOFT_device_clock.
/// 32.32 fixed-point sample offset (high 32 bits: whole samples).
/// The device clock, in nanoseconds, at which the offset was sampled.
public readonly record struct AlSampleOffsetClock(long SampleOffset, long ClockTime)
{
/// The whole-sample part of (its high 32 bits).
public int WholeSamples => (int)(SampleOffset >> 32);
}
/// A source's playback offset in seconds paired with its output latency. Provided by AL_SOFT_source_latency.
/// Playback offset, in seconds.
/// Seconds until the sample at the offset is audible.
public readonly record struct AlSecOffsetLatency(double SecOffset, double Latency);
/// A source's playback offset in seconds paired with the device clock. Provided by ALC_SOFT_device_clock.
/// Playback offset, in seconds.
/// The device clock, in seconds, at which the offset was sampled.
public readonly record struct AlSecOffsetClock(double SecOffset, double ClockTime);
public readonly partial struct AlSource
{
///
/// The playback offset and the output latency, in seconds, read atomically
/// (AL_SEC_OFFSET_LATENCY_SOFT). Provided by AL_SOFT_source_latency.
///
public AlSecOffsetLatency SecOffsetLatency
{
get
{
var (offset, latency) = Al.GetSourcedv2SOFT(Name, Al.Constants.AL_SEC_OFFSET_LATENCY_SOFT);
return new AlSecOffsetLatency(offset, latency);
}
}
///
/// The playback sample offset and output latency, read atomically
/// (AL_SAMPLE_OFFSET_LATENCY_SOFT). Provided by AL_SOFT_source_latency.
///
public AlSampleOffsetLatency SampleOffsetLatency
{
get
{
var (offset, latency) = Al.GetSourcei64v2SOFT(Name, Al.Constants.AL_SAMPLE_OFFSET_LATENCY_SOFT);
return new AlSampleOffsetLatency(offset, latency);
}
}
///
/// The playback offset and the device clock, in seconds, read atomically
/// (AL_SEC_OFFSET_CLOCK_SOFT). Provided by ALC_SOFT_device_clock.
///
public AlSecOffsetClock SecOffsetClock
{
get
{
var (offset, clock) = Al.GetSourcedv2SOFT(Name, Al.Constants.AL_SEC_OFFSET_CLOCK_SOFT);
return new AlSecOffsetClock(offset, clock);
}
}
///
/// The playback sample offset and the device clock, read atomically
/// (AL_SAMPLE_OFFSET_CLOCK_SOFT). Provided by ALC_SOFT_device_clock.
///
public AlSampleOffsetClock SampleOffsetClock
{
get
{
var (offset, clock) = Al.GetSourcei64v2SOFT(Name, Al.Constants.AL_SAMPLE_OFFSET_CLOCK_SOFT);
return new AlSampleOffsetClock(offset, clock);
}
}
///
/// Schedules playback to start at a device-clock time (alSourcePlayAtTimeSOFT). See
/// for the clock this is measured against. Provided by
/// AL_SOFT_source_start_delay.
///
/// The device clock time, in nanoseconds, at which to start playback.
public void PlayAt(long deviceClockTime) => Al.PInvoke.SourcePlayAtTimeSOFT(Name, deviceClockTime);
}