Skip to main content
Version: 20 Mar 2024

Buffering

Module: Audio / Audio Definitions / Audio Output / Audio Input

More...

Functions

Name
MLResultMLAudioGetBufferedInputDefaults(uint32_t channel_count, uint32_t samples_per_second, MLAudioBufferFormat out_format, uint32_t out_recommended_size_in_bytes, uint32_t * out_min_size_in_bytes)
Queries the minimum and recommended settings for buffered sound inputs.
MLResultMLAudioGetBufferedInputLatency(MLHandle handle, float * out_latency_in_msec)
Queries the latency for a sound input.
MLResultMLAudioGetInputBuffer(MLHandle handle, MLAudioBuffer * out_buf)
Retrieves a full buffer of audio data from a sound input.
MLResultMLAudioReleaseInputBuffer(MLHandle handle)
Releases an input buffer once it has been consumed.

Detailed Description

BUFFERING.


Functions Documentation

MLAudioGetBufferedInputDefaults

MLResult MLAudioGetBufferedInputDefaults(
uint32_t channel_count,
uint32_t samples_per_second,
MLAudioBufferFormat * out_format,
uint32_t * out_recommended_size_in_bytes,
uint32_t * out_min_size_in_bytes
)

Queries the minimum and recommended settings for buffered sound inputs.

Parameters

uint32_tchannel_countNumber of audio channels.
uint32_tsamples_per_secondSample rate for the buffered input.
MLAudioBufferFormat *out_formatMLAudioBufferFormat struct to be filled with recommended format properties.
uint32_t *out_recommended_size_in_bytesRetrieved recommended size.
uint32_t *out_min_size_in_bytesRetrieved minimum allowable size.

Returns

MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully retrieved the properties.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_InvalidChannelCountFailed due to an invalid channel count.
MLResultMLAudioResult_InvalidSampleRateFailed due to an invalid sample rate.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.

Required Permissions:

  • None

This function is typically called before one of the MLAudioCreateInput... calls. It queries the minimum and recommended buffer sizes for the specified settings of channel count and sample rate.

API Level:

  • 7

MLAudioGetBufferedInputLatency

MLResult MLAudioGetBufferedInputLatency(
MLHandle handle,
float * out_latency_in_msec
)

Queries the latency for a sound input.

Parameters

MLHandlehandleMLHandle of the sound input.
float *out_latency_in_msecRetrieved latency in milliseconds.

Returns

MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully retrieved the value.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.
MLResultMLAudioResult_OperationUnavailableFailed because operation is unavailable.

Required Permissions:

  • None

The latency for a sound input is the time between when a sound is picked up at the microphone and when the corresponding audio becomes available via a call to MLAudioGetInputBuffer.

API Level:

  • 7

MLAudioGetInputBuffer

MLResult MLAudioGetInputBuffer(
MLHandle handle,
MLAudioBuffer * out_buf
)

Retrieves a full buffer of audio data from a sound input.

Parameters

MLHandlehandleMLHandle of the sound input.
MLAudioBuffer *out_bufRetrieved MLAudioBuffer struct pointer to buffer for reading audio data.

Returns

MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully retrieved the buffer.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_BufferNotReadyFailed because buffer was not ready.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_InternalConfigErrorFailed due to an internal configuration error.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.
MLResultMLAudioResult_OperationUnavailableFailed because operation is unavailable.

Required Permissions:

  • None

Standard usage is to call this function by polling or within a callback of type MLAudioBufferCallback registered with one of the MLAudioCreateInput... calls. This call returns MLAudioResult_BufferNotReady if a buffer is not available for reading audio data, informing the caller to wait. Once consumed, the buffer must be released by calling MLAudioReleaseInputBuffer.

API Level:

  • 7

MLAudioReleaseInputBuffer

MLResult MLAudioReleaseInputBuffer(
MLHandle handle
)

Releases an input buffer once it has been consumed.

Parameters

MLHandlehandleMLHandle of the sound input.

Returns

MLResultMLResult_OkSuccessfully released the buffer.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_BufferNotReadyFailed because buffer was not ready.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_InternalConfigErrorFailed due to an internal configuration error.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.
MLResultMLAudioResult_OperationUnavailableFailed because operation is unavailable.

Required Permissions:

  • None

After consuming a buffer retrieved by MLAudioGetInputBuffer, the buffer must be released using this function in order to indicate that the buffer has been consumed and can now be refilled.

API Level:

  • 7