Skip to main content
Version: 20 Mar 2024

Resources

Module: Audio / Audio Definitions / Audio Output

More...

Functions

Name
MLResultMLAudioCreateLoadedResource(int file, bool dynamic_decode, MLAudioResourceDiscardedCallback callback, void context, MLHandle out_resource)
Creates a new Loaded Resource that references a loaded audio file.
MLResultMLAudioCreateStreamedResource(int file, MLAudioResourceDiscardedCallback callback, void context, MLHandle out_resource)
Creates a new audio resource that references a streamed audio file.
MLResultMLAudioCheckResource(MLHandle resource, bool * out_is_ready)
Queries whether a Loaded or Streamed Resource has been discarded due to system limits.
MLResultMLAudioGetResourceSize(MLHandle resource, uint32_t * out_size_in_bytes)
Queries the size of the memory footprint for a Loaded Resource.
MLResultMLAudioRefreshResource(MLHandle resource, int file)
Refreshes a resource whose data was discarded due to system limits.
MLResultMLAudioDestroyResource(MLHandle resource)
Destroys a previously created audio resource.
MLResultMLAudioCreateSoundWithLoadedResource(MLHandle resource, bool auto_destroy, MLHandle * out_handle)
Creates a sound output referencing a Loaded Audio Resource.
MLResultMLAudioCreateSoundWithStreamedResource(MLHandle resource, bool auto_destroy, MLHandle * out_handle)
Creates a sound output referencing a Streamed Audio Resource.

Detailed Description

RESOURCES.


Functions Documentation

MLAudioCreateLoadedResource

MLResult MLAudioCreateLoadedResource(
int file,
bool dynamic_decode,
MLAudioResourceDiscardedCallback callback,
void * context,
MLHandle * out_resource
)

Creates a new Loaded Resource that references a loaded audio file.

Parameters

intfileFile descriptor specifying the audio file.
booldynamic_decodeNot currently implemented.
MLAudioResourceDiscardedCallbackcallbackCallback function pointer.
void *contextGeneric data pointer passed back through the callback.
MLHandle *out_resourceMLHandle to be used in subsequent calls.

Returns

MLResultMLResult_AllocFailedFailed due to memory allocation failure.
MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully created resource.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_FileNotRecognizedFailed because file was not recognized.
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_NotImplementedFailed because feature has not been implemented yet.

Required Permissions:

  • None

Loaded Audio Resources provide the ability to preload audio files that stay in memory, so a single audio file can be played by multiple sound outputs. The resource can be used to create a sound output by passing the resource ID (MLHandle) provided by this function via out_resource to MLAudioCreateSoundWithLoadedResource. 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.

The audio data for a Loaded Resource can be discarded by the system due to memory limits. Resources that are not being referenced by a sound output will be discarded prior to resources that are being referenced. Resources that are being played by a sound output will not be discarded. If a resource has been discarded, it must be refreshed prior to use by calling MLAudioRefreshResource. MLAudioResourceDiscardedCallback is an optional argument to this function that will result in a callback to inform the client if the audio data for this Loaded Resource has been discarded due to system limits.


MLAudioCreateStreamedResource

MLResult MLAudioCreateStreamedResource(
int file,
MLAudioResourceDiscardedCallback callback,
void * context,
MLHandle * out_resource
)

Creates a new audio resource that references a streamed audio file.

Parameters

intfileFile descriptor specifying the audio file.
MLAudioResourceDiscardedCallbackcallbackCallback function pointer.
void *contextGeneric data pointer passed back through the callback.
MLHandle *out_resourceMLHandle to be used in subsequent calls.

Returns

MLResultMLResult_AllocFailedFailed due to memory allocation failure.
MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully created resource.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.

Required Permissions:

  • None

Streamed Audio Resources provide the ability to pre-establish a persistent reference to an audio file (in the form of a file descriptor), so a single audio file can be streamed by multiple sound outputs, with audio data streamed from flash memory into main memory in chunks during playback. The resource can be used to create a sound output by passing the resource ID (MLHandle) provided by this function via out_resource to MLAudioCreateSoundWithStreamedResource. 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.

The File Descriptor for a Streamed Resource can be discarded by the system due to a limited number of available File Descriptors. Resources that are not being referenced by a sound output will be discarded prior to resources that are being referenced. Resources that are being played by a sound output will not be discarded. If a resource has been discarded, it must be refreshed prior to use by calling MLAudioRefreshResource. MLAudioResourceDiscardedCallback is an optional argument to this function that will result in a callback to inform the client if the File Descriptor for this Streamed Resource has been discarded due to system limits.


MLAudioCheckResource

MLResult MLAudioCheckResource(
MLHandle resource,
bool * out_is_ready
)

Queries whether a Loaded or Streamed Resource has been discarded due to system limits.

Parameters

MLHandleresourceMLHandle of the resource.
bool *out_is_readyIf true, the resource is ready to use.

Returns

MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully reported the value.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.
MLResultMLAudioResult_ResourceNotFoundFailed because resource was not found.

Required Permissions:

  • None

The audio data for a Loaded Resource can be discarded by the system due to memory limits. The File Descriptor for a Streamed Resource can be discarded by the system due to a limited number of available File Descriptors. Resources that are not being referenced by a sound output will be discarded prior to resources that are being referenced. Resources that are being played by a sound output will not be discarded. If a resource has been discarded, it must be refreshed prior to use by calling MLAudioRefreshResource.


MLAudioGetResourceSize

MLResult MLAudioGetResourceSize(
MLHandle resource,
uint32_t * out_size_in_bytes
)

Queries the size of the memory footprint for a Loaded Resource.

Parameters

MLHandleresourceMLHandle of the resource.
uint32_t *out_size_in_bytesThe retrieved size of the memory footprint.

Returns

MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully retrieved the value.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_NotImplementedFailed because Streamed Resource was queried.
MLResultMLAudioResult_ResourceNotFoundFailed because resource was not found.

Required Permissions:

  • None

For Loaded Resources using compressed file formats, the data is decompressed when loaded, and the size of the decompressed data is reported. For Streamed Resources, this call will fail with MLAudioResult_NotImplemented.

API Level:

  • 7

MLAudioRefreshResource

MLResult MLAudioRefreshResource(
MLHandle resource,
int file
)

Refreshes a resource whose data was discarded due to system limits.

Parameters

MLHandleresourceMLHandle of the resource.
intfileFile descriptor specifying the audio file.

Returns

MLResultMLResult_AllocFailedFailed due to memory allocation failure.
MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully refreshed resource.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_FileNotRecognizedFailed because file was not recognized.
MLResultMLAudioResult_InternalConfigErrorFailed due to an internal configuration error.
MLResultMLAudioResult_InvalidBitsPerSampleFailed due to invalid bits per sample.
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.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.
MLResultMLAudioResult_OperationUnavailableFailed because operation is unavailable.
MLResultMLAudioResult_ResourceNotFoundFailed because resource was not found.

Required Permissions:

  • None

The audio data for a Loaded Resource can be discarded by the system due to memory limits. The File Descriptor for a Streamed Resource can be discarded by the system due to a limited number of available File Descriptors. Resources that are not being referenced by a sound output will be discarded prior to resources that are being referenced. Resources that are being played by a sound output will not be discarded. If a resource has been discarded, it must be refreshed prior to use by calling this function.


MLAudioDestroyResource

MLResult MLAudioDestroyResource(
MLHandle resource
)

Destroys a previously created audio resource.

Parameters

MLHandleresourceMLHandle of the resource.

Returns

MLResultMLResult_OkSuccessfully destroyed resource.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.
MLResultMLAudioResult_ResourceNotFoundFailed because resource was not found.

Required Permissions:

  • None

Even if a resource is currently in use it will be destroyed immediately. If a sound output is playing the resource, the sound will be stopped and a corresponding Sound Event callback of type MLAudioSoundEvent_ResourceDestroyed will be issued.


MLAudioCreateSoundWithLoadedResource

MLResult MLAudioCreateSoundWithLoadedResource(
MLHandle resource,
bool auto_destroy,
MLHandle * out_handle
)

Creates a sound output referencing a Loaded Audio Resource.

Parameters

MLHandleresourceMLHandle of the Loaded Resource.
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 input.
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_ResourceNotFoundFailed because resource was not found.

Required Permissions:

  • None

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.


MLAudioCreateSoundWithStreamedResource

MLResult MLAudioCreateSoundWithStreamedResource(
MLHandle resource,
bool auto_destroy,
MLHandle * out_handle
)

Creates a sound output referencing a Streamed Audio Resource.

Parameters

MLHandleresourceMLHandle of the streamed audio resource.
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_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_InternalConfigErrorFailed due to an internal configuration error.
MLResultMLAudioResult_InvalidBufferSizeFailed due to an invalid buffer size.
MLResultMLAudioResult_ResourceDiscardedFailed because file was closed.
MLResultMLAudioResult_ResourceNotFoundFailed because resource was not found.

Required Permissions:

  • None

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.