Oboe  1.5
A library for creating real-time audio apps on Android
Public Member Functions | List of all members
oboe::LatencyTuner Class Reference

#include <LatencyTuner.h>

Public Member Functions

 LatencyTuner (AudioStream &stream)
 LatencyTuner (AudioStream &stream, int32_t maximumBufferSize)
Result tune ()
void requestReset ()
bool isAtMaximumBufferSize ()
void setMinimumBufferSize (int32_t bufferSize)
int32_t getMinimumBufferSize () const
void setBufferSizeIncrement (int32_t sizeIncrement)
int32_t getBufferSizeIncrement () const

Detailed Description

LatencyTuner can be used to dynamically tune the latency of an output stream. It adjusts the stream's bufferSize by monitoring the number of underruns.

This only affects the latency associated with the first level of buffering that is closest to the application. It does not affect low latency in the HAL, or touch latency in the UI.

Call tune() right before returning from your data callback function if using callbacks. Call tune() right before calling write() if using blocking writes.

If you want to see the ongoing results of this tuning process then call stream->getBufferSize() periodically.

Constructor & Destructor Documentation

◆ LatencyTuner() [1/2]

oboe::LatencyTuner::LatencyTuner ( AudioStream stream)

Construct a new LatencyTuner object which will act on the given audio stream

streamthe stream who's latency will be tuned

◆ LatencyTuner() [2/2]

oboe::LatencyTuner::LatencyTuner ( AudioStream stream,
int32_t  maximumBufferSize 

Construct a new LatencyTuner object which will act on the given audio stream.

streamthe stream who's latency will be tuned
themaximum buffer size which the tune() operation will set the buffer size to

Member Function Documentation

◆ isAtMaximumBufferSize()

bool oboe::LatencyTuner::isAtMaximumBufferSize ( )
true if the audio stream's buffer size is at the maximum value. If no maximum value was specified when constructing the LatencyTuner then the value of stream->getBufferCapacityInFrames is used

◆ requestReset()

void oboe::LatencyTuner::requestReset ( )

This may be called from another thread. Then tune() will call reset(), which will lower the latency to the minimum and then allow it to rise back up if there are glitches.

This is typically called in response to a user decision to minimize latency. In other words, call this from a button handler.

◆ setBufferSizeIncrement()

void oboe::LatencyTuner::setBufferSizeIncrement ( int32_t  sizeIncrement)

Set the amount the bufferSize will be incremented while tuning. By default, this will be one burst.

Note that AAudio will quantize the buffer size to a multiple of the burstSize. So the final buffer sizes may not be a multiple of this increment.


◆ setMinimumBufferSize()

void oboe::LatencyTuner::setMinimumBufferSize ( int32_t  bufferSize)

Set the minimum bufferSize in frames that is used when the tuner is reset. You may wish to call requestReset() after calling this.


◆ tune()

Result oboe::LatencyTuner::tune ( )

Adjust the bufferSizeInFrames to optimize latency. It will start with a low latency and then raise it if an underrun occurs.

Latency tuning is only supported for AAudio.

OK or negative error, ErrorUnimplemented for OpenSL ES

The documentation for this class was generated from the following file: