Table of Contents

Class SampleBuffer<T>

Namespace
Coherence.Interpolation
Assembly
Coherence.Interpolation.dll

SampleBuffer stores sample points in a circular buffer. The buffer is backed by an array that currently cannot be resized. The buffer is guaranteed to be ever increasing, i.e. this[n].Time > this[n-1].

public class SampleBuffer<T>

Type Parameters

T

The sample type (e.g., float, int, Vector3) corresponding to the value type of the binding.

Inheritance
SampleBuffer<T>

Constructors

SampleBuffer()

Creates an empty SampleBuffer.

public SampleBuffer()

Properties

Capacity

The maximum number of samples in the buffer.

public int Capacity { get; }

Property Value

int

Count

The current number of samples in the buffer.

public int Count { get; }

Property Value

int

this[int]

public Sample<T> this[int index] { get; set; }

Parameters

index int

Property Value

Sample<T>

Last

public Sample<T>? Last { get; }

Property Value

Sample<T>?

Methods

GetAdjacentSamples(double)

Searches the buffer for the two samples adjacent to the given time. Returns (default, default, -1) if the buffer is empty. Returns (sample[0], sample[0], 0) if the buffer contains less than two samples - or if time pre-dates the first sample. Otherwise, it returns the sample before (or equal to) the given time, and the next sample in the buffer. IsLastSample is true if the second returned sample is the last sample in the buffer.

public SampleBuffer<T>.AdjecentSamplesResult GetAdjacentSamples(double time)

Parameters

time double

The time used to compare with sample times in the buffer.

Returns

SampleBuffer<T>.AdjecentSamplesResult

GetEnumerator()

public IEnumerator<Sample<T>> GetEnumerator()

Returns

IEnumerator<Sample<T>>

PopBack()

Removes the oldest sample in the buffer.

public Sample<T>? PopBack()

Returns

Sample<T>?

The sample that was removed.

PushFront(Sample<T>)

Adds a new sample to the front of the buffer. If the buffer Capacity has already been reached, the oldest sample is removed. Samples should always be added with increasing timestamps. If multiple samples with identical timestamps are added, only the first sample is added and the rest are discarded. This ensures that buffer times are always incrementing.

public void PushFront(Sample<T> sample)

Parameters

sample Sample<T>

The new sample to add to the buffer.

Exceptions

ArgumentException

Throws an ArgumentException if the new sample time is older than the latest sample in the buffer.

RemoveOutdatedSamples(double, int)

Removes outdated samples from the samples buffer. A sample is considered outdated if its timestamp is equal to or older than the given time. The number of samples left guarantees that both interpolation and extrapolation can happen.

public void RemoveOutdatedSamples(double time, int numberOfSamplesToStayBehind)

Parameters

time double

The current time used to determine which samples are outdated. Usually Time.

numberOfSamplesToStayBehind int

The NumberOfSamplesToStayBehind of the Interpolator used for this binding.

SetLast(Sample<T>)

public void SetLast(Sample<T> value)

Parameters

value Sample<T>

TryMeasureMaxSampleDuration(out double)

Calculates the maximum duration between two samples frames in the last Coherence.Interpolation.SampleBuffer`1.sampleCountForMeasuringDuration samples. It also stops measuring when it reaches a stopped sample. Used for measuring real SampleRate.

public bool TryMeasureMaxSampleDuration(out double measuredSampleDuration)

Parameters

measuredSampleDuration double

Returns

bool

True if there are enough samples to measure the duration, with measuredSampleDuration set to maximum duration between two adjecent samples.