Oboe 1.2 A library for creating real-time audio apps on Android

Public Member Functions | List of all members
oboe::StabilizedCallback Class Reference
Inheritance diagram for oboe::StabilizedCallback:

## Public Member Functions
| StabilizedCallback (AudioStreamCallback *callback)
DataCallbackResult | onAudioReady (AudioStream *oboeStream, void *audioData, int32_t numFrames) override
void | onErrorBeforeClose (AudioStream *oboeStream, Result error) override
void | onErrorAfterClose (AudioStream *oboeStream, Result error) override

## Member Function Documentation

## ◆ onAudioReady()

DataCallbackResult oboe::StabilizedCallback::onAudioReady | ( | AudioStream * | oboeStream,
|  | void * | audioData,
|  | int32_t | numFrames
| ) |  |
| override virtual

A buffer is ready for processing.

For an output stream, this function should render and write numFrames of data in the stream's current data format to the audioData buffer.

For an input stream, this function should read and process numFrames of data from the audioData buffer.

The audio data is passed through the buffer. So do NOT call read() or write() on the stream that is making the callback.

Note that numFrames can vary unless AudioStreamBuilder::setFramesPerCallback() is called.

Also note that this callback function should be considered a "real-time" function. It must not do anything that could cause an unbounded delay because that can cause the audio to glitch or pop.

These are things the function should NOT do:

- allocate memory using, for example, malloc() or new
- any file operations such as opening, closing, reading or writing
- any network operations such as streaming
- use any mutexes or other synchronization primitives
- sleep
- oboeStream->stop(), pause(), flush() or close()
- oboeStream->read()
- oboeStream->write()

The following are OK to call from the data callback:

- oboeStream->get*()
- oboe::convertToText()
- oboeStream->setBufferSizeInFrames()

If you need to move data, eg. MIDI commands, in or out of the callback function then we recommend the use of non-blocking techniques such as an atomic FIFO.

Parameters

  oboeStream | pointer to the associated stream
  audioData | buffer containing input data or a place to put output data
  numFrames | number of frames to be processed

Returns
  DataCallbackResult::Continue or DataCallbackResult::Stop

Implements oboe::AudioStreamCallback.

## ◆ onErrorAfterClose()

void oboe::StabilizedCallback::onErrorAfterClose | ( | AudioStream * | ,
|  | Result |
| ) |  |
| inline override virtual

This will be called when an error occurs on a stream or when the stream is disconnected. The underlying AAudio or OpenSL ES stream will already be stopped AND closed by Oboe. So the underlying stream cannot be referenced. But you can still query most parameters.

This callback could be used to reopen a new stream on another device. You can safely delete the old AudioStream in this method.

Parameters

  oboeStream | pointer to the associated stream
  error |

Reimplemented from oboe::AudioStreamCallback.

## ◆ onErrorBeforeClose()

void oboe::StabilizedCallback::onErrorBeforeClose | ( | AudioStream * | ,
|  | Result |
| ) |  |
| inline override virtual

This will be called when an error occurs on a stream or when the stream is disconnected.

Note that this will be called on a different thread than the onAudioReady() thread. This thread will be created by Oboe.

The underlying stream will already be stopped by Oboe but not yet closed. So the stream can be queried.

Do not close or delete the stream in this method because it will be closed after this method returns.

Parameters

  oboeStream | pointer to the associated stream
  error |

Reimplemented from oboe::AudioStreamCallback.

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

- include/oboe/StabilizedCallback.h