carb::audio::estimateVideoLatency

Defined in carb/audio/AudioUtils.h

inline int64_t carb::audio::estimateVideoLatency(double fps, double framesInFlight, int64_t perceptibleDelay = kImperceptibleDelay)

Calculates an estimate of the current level of video latency.

Remark

This is used to calculate an estimate of the current video latency level. This value can be used to set the ContextParams2::videoLatency value based on the current performance of the video rendering system. This value is used by the audio engine to delay the queuing of new voices by a given amount of time.

Parameters
  • fps[in] The current video frame rate in frames per second. The caller is responsible for accurately retrieving and calculating this.

  • framesInFlight[in] The current number of video frames currently in flight. This is the number of frames that have been produced by the renderer but have not been displayed to the user yet (or has been presented but not realized on screen yet). The frame being produced would represent the simulation time (where a synchronized sound is expected to start playing), and the other buffered frames are ones that go back further in time (ie: older frames as far as the simulation is concerned). This may need to be an estimate the caller can retrieve from the renderer.

  • perceptibleDelay[in] A limit below which a zero latency will be calculated. If the total calculated latency is less than this threshold, the latency will be zeroed out. If total calculated latency is larger than this limit, a delay estimate will be calculated. This value is given in microseconds. This defaults to 200,000 microseconds.

Returns

The calculated latency estimate in microseconds.