Skip to main content
Version: 20 Mar 2024

Allocation

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

More...

Functions

Name
MLResultMLAudioCreateInputFromMicCapture(MLAudioMicCaptureType mic_capture_type, const MLAudioBufferFormat format, uint32_t buffer_size_in_bytes, MLAudioBufferCallback callback, void context, MLHandle * out_handle)
Creates a new sound input that provides audio from the wearable microphones.
MLResultMLAudioCreateInputFromVirtualCapture(const MLAudioBufferFormat format, uint32_t buffer_size, MLAudioBufferCallback callback, void context, MLHandle * out_handle)
Creates a new sound input that provides a virtual capture stream.
MLResultMLAudioCreateInputFromMixedCapture(const MLAudioBufferFormat format, uint32_t buffer_size, MLAudioBufferCallback callback, void context, MLHandle * out_handle)
Creates a new sound input that provides a mixed capture stream.
MLResultMLAudioDestroyInput(MLHandle handle)
Destroys a sound input.

Detailed Description

ALLOCATION.


Functions Documentation

MLAudioCreateInputFromMicCapture

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

Creates a new sound input that provides audio from the wearable microphones.

Parameters

MLAudioMicCaptureTypemic_capture_typeMLAudioMicCaptureType enum specifying the type of mic capture created.
const MLAudioBufferFormat *formatMLAudioBufferFormat struct specifying the format properties.
uint32_tbuffer_sizeRequested size in bytes for each of the two stream 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 a sound input.
MLResultMLResult_PermissionDeniedFailed due to lack of permission.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_InternalConfigErrorFailed due to an internal configuration error.
MLResultMLAudioResult_InvalidBitsPerSampleFailed due to an 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 an invalid valid bits per sample.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.

Required Permissions:

  • android.permission.RECORD_AUDIO (protection level: dangerous)

The various mic capture streams represent different configurations of the input from the wearable microphones, intended for different purposes. The 'format' argument must be populated with the correct settings for the mic capture type being requested:

MLAudioMicCaptureType_VoiceComm is intended for remote communications, and uses a channel count of 1 and a sample rate of 16,000.

MLAudioMicCaptureType_VoiceCapture is intended for device-local applications involving user voice, and uses a channel count of 1 and a sample rate of 48,000.

MLAudioMicCaptureType_WorldCapture provides a stereo capture of the user's physical environment, and uses a channel count of 2 and a sample rate of 48,000.

MLAudioMicCaptureType_RawMicsAndAECRef provides a 6-channel capture comprising all 4 mics (unprocessed) plus the AEC reference signal from the amplifier, and uses a channel count of 6 and a sample rate of 48,000.

After creation, the input is started by calling MLAudioStartInput. After the input has been started, the next available full buffer is retrieved by calling MLAudioGetInputBuffer. This can be done on a polling basis, or a callback can be set using the 'callback' argument of the present function to notify when a buffer is available. After retrieving and consuming the next available buffer, MLAudioReleaseInputBuffer must be called to indicate that the buffer has been consumed and is ready to be refilled. MLAudioGetInputBuffer and MLAudioReleaseInputBuffer are valid to call within the callback. The 'buffer_size' argument will use the recommended size if 0 is passed in.

API Level:

  • 20

MLAudioCreateInputFromVirtualCapture

MLResult MLAudioCreateInputFromVirtualCapture(
const MLAudioBufferFormat * format,
uint32_t buffer_size,
MLAudioBufferCallback callback,
void * context,
MLHandle * out_handle
)

Creates a new sound input that provides a virtual capture stream.

Parameters

const MLAudioBufferFormat *formatMLAudioBufferFormat struct specifying the format properties.
uint32_tbuffer_sizeRequested size in bytes of the 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 input.
MLResultMLResult_PermissionDeniedFailed due to lack of permission.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_InternalConfigErrorFailed due to an internal configuration error.
MLResultMLAudioResult_InvalidBitsPerSampleFailed due to an 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 an invalid valid bits per sample.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.

Required Permissions:

  • android.permission.RECORD_AUDIO (protection level: dangerous)

The Virtual Capture stream is a stereo stream capturing the combined audio output mix of the capture-eligible sounds (typically app-generated) currently being played by the audio rendering engine. The 'format' argument must be populated with the correct settings for virtual capture, which uses a channel count of 2 and a sample rate of 48,000.

After creation, the input is started by calling MLAudioStartInput. After the input has been started, the next available full buffer is retrieved by calling MLAudioGetInputBuffer. This can be done on a polling basis, or a callback can be set using the 'callback' argument of the present function to notify when a buffer is available. After retrieving and consuming the next available buffer, MLAudioReleaseInputBuffer must be called to indicate that the buffer has been consumed and is ready to be refilled. MLAudioGetInputBuffer and MLAudioReleaseInputBuffer are valid to call within the callback. The 'buffer_size' argument will use the recommended size if 0 is passed in.


MLAudioCreateInputFromMixedCapture

MLResult MLAudioCreateInputFromMixedCapture(
const MLAudioBufferFormat * format,
uint32_t buffer_size,
MLAudioBufferCallback callback,
void * context,
MLHandle * out_handle
)

Creates a new sound input that provides a mixed capture stream.

Parameters

const MLAudioBufferFormat *formatMLAudioBufferFormat struct specifying the format properties.
uint32_tbuffer_sizeRequested size in bytes of the 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 input.
MLResultMLResult_PermissionDeniedFailed due to lack of permission.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_InternalConfigErrorFailed due to an internal configuration error.
MLResultMLAudioResult_InvalidBitsPerSampleFailed due to an 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 an invalid valid bits per sample.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.

Required Permissions:

  • android.permission.RECORD_AUDIO (protection level: dangerous)

The Mixed Capture stream is intended for capturing the audible user experience, including both sounds from the physical environment and sounds produced by the device. The stream includes a mix of the 'Virtual Capture' stream, the MLAudioMicCaptureType_VoiceCapture stream, and the MLAudioMicCaptureType_WorldCapture stream. By default the World Capture stream is silent and the other two streams are full volume. These levels can be adjusted by calling MLAudioSetMixedCaptureMix. Independent of the specified MixedCaptureMix, the Voice Capture and World Capture mic signals are scaled on a curve based on the current setting of Master Volume to keep the real and virtual signals in good balance. The Mixed Capture stream uses a channel count of 2 and a sample rate of 48,000.

After creation, the input is started by calling MLAudioStartInput. After the input has been started, the next available full buffer is retrieved by calling MLAudioGetInputBuffer. This can be done on a polling basis, or a callback can be set using the 'callback' argument of the present function to notify when a buffer is available. After retrieving and consuming the next available buffer, MLAudioReleaseInputBuffer must be called to indicate that the buffer has been consumed and is ready to be refilled. MLAudioGetInputBuffer and MLAudioReleaseInputBuffer are valid to call within the callback. The 'buffer_size' argument will use the recommended size if 0 is passed in.


MLAudioDestroyInput

MLResult MLAudioDestroyInput(
MLHandle handle
)

Destroys a sound input.

Parameters

MLHandlehandleMLHandle of the sound input.

Returns

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

Required Permissions:

  • None