DataCallback

Type Alias DataCallback 

Source
pub type DataCallback = Option<unsafe extern "C" fn(stream: *mut AAudioStream, user_data: *mut c_void, audio_data: *mut c_void, num_frames: i32) -> i32>;
Expand description

Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback().

For an output stream, this function should render and write numFrames of data in the streams 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 AAudioStream_read() or AAudioStream_write() on the stream that is making the callback.

Note that numFrames can vary unless AAudioStreamBuilder_setFramesPerDataCallback() 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
  • stop or close the stream
  • AAudioStream_read()
  • AAudioStream_write()

The following are OK to call from the data callback:

  • AAudioStream_get*()
  • AAudio_convertResultToText()

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.

  • stream - reference provided by AAudioStreamBuilder_openStream()
  • user_data - the same address that was passed to AAudioStreamBuilder_setCallback()
  • audio_data - a pointer to the audio data
  • num_frames - the number of frames to be processed, which can vary

Returns CallbackResult (Continue = 0, Stop = 1)

Aliased Type§

pub enum DataCallback {
    None,
    Some(unsafe extern "C" fn(*mut AAudioStream, *mut c_void, *mut c_void, i32) -> i32),
}

Variants§

§1.0.0

None

No value.

§1.0.0

Some(unsafe extern "C" fn(*mut AAudioStream, *mut c_void, *mut c_void, i32) -> i32)

Some value of type T.