Skip to main content
Version: 20 Mar 2024

Allocation

Module: Audio / Audio Definitions / Audio Output

More...

Functions

Name
MLResultMLAudioCreateSoundWithLoadedFile(int file, bool auto_destroy, bool dynamic_decode, MLHandle * out_handle)
Creates a sound output that uses audio data loaded from a file descriptor into memory.
MLResultMLAudioCreateSoundWithStreamedFile(int file, bool auto_destroy, MLHandle * out_handle)
Creates a sound output that streams audio data from flash memory via a file descriptor.
MLResultMLAudioCreateSoundWithBufferedOutput(const MLAudioBufferFormat format, uint32_t buffer_size_in_bytes, MLAudioBufferCallback callback, void context, MLHandle * out_handle)
Creates a sound output that plays a client-provided stream of buffered audio data.
MLResultMLAudioDestroySound(MLHandle handle)
Destroys a previously created sound output.

Detailed Description

ALLOCATION.


Functions Documentation

MLAudioCreateSoundWithLoadedFile

MLResult MLAudioCreateSoundWithLoadedFile(
int file,
bool auto_destroy,
bool dynamic_decode,
MLHandle * out_handle
)

Creates a sound output that uses audio data loaded from a file descriptor into memory.

Parameters

intfileFile descriptor specifying the audio file.
boolauto_destroyIf true, the sound output is destroyed when playback reaches end of file.
booldynamic_decodeNot currently implemented.
MLHandle *out_handleMLHandle to be used in subsequent calls.

Returns

MLResultMLResult_AllocFailedFailed due to memory allocation failure.
MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully created sound output.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_FileNotRecognizedFailed because file was not recognized.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_InternalConfigErrorFailed due to an internal configuration error.
MLResultMLAudioResult_InvalidBitsPerSampleFailed due to invalid bits per sample.
MLResultMLAudioResult_InvalidChannelCountFailed due to an invalid channel count.
MLResultMLAudioResult_InvalidSampleRateFailed due to an invalid sample rate.
MLResultMLAudioResult_InvalidValidBitsFailed due to invalid valid bits.
MLResultMLAudioResult_ResourceNotFoundFailed because resource was not found.

Required Permissions:

  • None

Once created, the sound output can be configured and controlled by calling other MLAudio API calls, passing the sound ID (MLHandle) provided by this function via out_handle. Playback can be started by calling MLAudioStartSound. Files can be of type WAV, FLAC, MP3 and OGG, can be stereo or mono, can have 16kHz to 48kHz sample rate, and can be represented as 16-bit, 24-bit, and 32-bit integers or 32-bit floats.


MLAudioCreateSoundWithStreamedFile

MLResult MLAudioCreateSoundWithStreamedFile(
int file,
bool auto_destroy,
MLHandle * out_handle
)

Creates a sound output that streams audio data from flash memory via a file descriptor.

Parameters

intfileFile descriptor specifying the audio file.
boolauto_destroyIf true, the sound output is destroyed when playback reaches end of file.
MLHandle *out_handleMLHandle to be used in subsequent calls.

Returns

MLResultMLResult_AllocFailedFailed due to memory allocation failure.
MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully created sound output.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_FileNotFoundFailed because file was missing.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_InternalConfigErrorFailed due to an internal configuration error.
MLResultMLAudioResult_ResourceDiscardedFailed because file was closed.
MLResultMLAudioResult_ResourceNotFoundFailed because resource was not found.

Required Permissions:

  • None

Once created, the sound output can be configured and controlled by calling other MLAudio API calls, passing the sound ID (MLHandle) provided by this function via out_handle. Playback can be started by calling MLAudioStartSound. Files can be of type WAV, FLAC, MP3 and OGG, can be stereo or mono, can have 16kHz to 48kHz sample rate, and can be represented as 16-bit, 24-bit, and 32-bit integers or 32-bit floats.


MLAudioCreateSoundWithBufferedOutput

MLResult MLAudioCreateSoundWithBufferedOutput(
const MLAudioBufferFormat * format,
uint32_t buffer_size_in_bytes,
MLAudioBufferCallback callback,
void * context,
MLHandle * out_handle
)

Creates a sound output that plays a client-provided stream of buffered audio data.

Parameters

const MLAudioBufferFormat *formatMLAudioBufferFormat struct specifying the format properties.
uint32_tbuffer_size_in_bytesRequested size in bytes for each of the output buffers.
MLAudioBufferCallbackcallbackCallback function pointer.
void *contextGeneric data pointer passed back through the callback.
MLHandle *out_handleMLHandle to be used in subsequent calls.

Returns

MLResultMLResult_AllocFailedFailed due to memory allocation failure.
MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully created sound output.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_InternalConfigErrorFailed due to an internal configuration error.
MLResultMLAudioResult_InvalidSampleRateFailed due to an invalid sample rate.
MLResultMLAudioResult_InvalidBufferSizeFailed due to an invalid buffer size.
MLResultMLAudioResult_InvalidChannelCountFailed due to an invalid channel count.
MLResultMLAudioResult_InvalidSampleFormatFailed due to an invalid sample format.
MLResultMLAudioResult_InvalidSampleRateFailed due to an invalid sample rate.
MLResultMLAudioResult_InvalidValidBitsFailed due to invalid valid bits.

Required Permissions:

  • None

The sound output allocates a double buffer that the caller is responsible for continuously filling with audio data. This can be done within a callback of type MLAudioBufferCallback that is set via the 'callback' argument or by polling MLAudioGetOutputBuffer if no callback is set. When polling, a return value of MLAudioResult_BufferNotReady indicates the sound output is not ready and the caller must wait. Setting the 'buffer_size_in_bytes' argument to 0 will utilize the system-preferred buffer size. Double-buffers can optionally be pre-filled prior to starting the sound. Once created, a sound output can be configured and controlled by calling other MLAudio API calls, passing the sound ID (MLHandle) provided by this function via out_handle. Playback can be started by calling MLAudioStartSound. Audio data can be mono, stereo, 4-channel (ambisonics), 6-channel (5.1), 8-channel (7.1), or 12-channel (7.1.4). It can have 16kHz to 48kHz sample rate, and must be 16-bit integer.

API Level:

  • 7

MLAudioDestroySound

MLResult MLAudioDestroySound(
MLHandle handle
)

Destroys a previously created sound output.

Parameters

MLHandlehandleMLHandle of the sound output.

Returns

MLResultMLResult_OkSuccessfully destroyed sound output.
MLResultMLResult_UnspecifiedFailureFailed to destroy sound output due to an unknown error.
MLResultMLAudioResult_HandleNotFoundFailed to destroy sound output due to a missing handle.
MLResultMLAudioResult_NotImplementedFailed to destroy sound output because feature has not been implemented yet.

Required Permissions:

  • None