Defines functions for microphone creation, control, audio data fetching, and destruction. This module supports multiple calls to
SbMicrophoneClose, and the implementation should handle multiple calls to one of those functions on the same microphone. For example, your implementation should handle cases where
SbMicrophoneOpen is called twice on the same microphone without a call to
SbMicrophoneClose in between.
This API is not thread-safe and must be called from a single thread.
How to use this API:
SbMicrophoneGetAvailableInfos to get a list of available microphone information.
Create a supported microphone, using
SbMicrophoneCreate, with enough buffer size and sample rate. Use
SbMicrophoneIsSampleRateSupported to verify the sample rate.
SbMicrophoneOpen to open the microphone port and start recording audio data.
Periodically read out the data from microphone with
SbMicrophoneClose to close the microphone port and stop recording audio data.
Destroy the microphone with
Well-defined value for an invalid microphone ID handle.
Well-defined value for an invalid microphone handle.
All possible microphone types.
Built-in microphone in camera.
Microphone in the headset that can be a wired or wireless USB headset.
Microphone in the VR headset.
Microphone in the analog headset.
Unknown microphone type. The microphone could be different than the other enum descriptions or could fall under one of those descriptions.
An opaque handle to an implementation-private structure that represents a microphone.
typedef struct SbMicrophonePrivate* SbMicrophone
An opaque handle to an implementation-private structure that represents a microphone ID.
typedef struct SbMicrophoneIdPrivate* SbMicrophoneId
The microphone's maximum supported sampling rate.
The minimum read size required for each read from microphone.
Name of the microphone. Can be empty. This should indicate the friendly name of the microphone type. For example, “Headset Microphone”. The string must be null terminated.
Closes the microphone port, stops recording audio on
microphone, and clears the unread buffer if it is not empty. If the microphone has already been stopped, this call is ignored. The return value indicates whether the microphone is closed.
microphone: The microphone to close.
bool SbMicrophoneClose(SbMicrophone microphone)
Creates a microphone with the specified ID, audio sample rate, and cached audio buffer size. Starboard only requires support for creating one microphone at a time, and implementations may return an error if a second microphone is created before the first is destroyed.
The function returns the newly created SbMicrophone object. However, if you try to create a microphone that has already been initialized, if the sample rate is unavailable, or if the buffer size is invalid, the function should return
id: The ID that will be assigned to the newly created SbMicrophone.
sample_rate_in_hz: The new microphone's audio sample rate in Hz.
buffer_size_bytes: The size of the buffer where signed 16-bit integer audio data is temporarily cached to during the capturing. The audio data is removed from the audio buffer if it has been read, and new audio data can be read from this buffer in smaller chunks than this size. This parameter must be set to a value greater than zero and the ideal size is
SbMicrophone SbMicrophoneCreate(SbMicrophoneId id, int sample_rate_in_hz, int buffer_size_bytes)
Destroys a microphone. If the microphone is in started state, it is first stopped and then destroyed. Any data that has been recorded and not read is thrown away.
void SbMicrophoneDestroy(SbMicrophone microphone)
Retrieves all currently available microphone information and stores it in
out_info_array. The return value is the number of the available microphones. If the number of available microphones is larger than
out_info_array is filled up with as many available microphones as possible and the actual number of available microphones is returned. A negative return value indicates that an internal error occurred.
out_info_array: All currently available information about the microphone is placed into this output parameter.
info_array_size: The size of
int SbMicrophoneGetAvailable(SbMicrophoneInfo *out_info_array, int info_array_size)
Indicates whether the given microphone ID is valid.
static bool SbMicrophoneIdIsValid(SbMicrophoneId id)
Indicates whether the microphone supports the sample rate.
bool SbMicrophoneIsSampleRateSupported(SbMicrophoneId id, int sample_rate_in_hz)
Indicates whether the given microphone is valid.
static bool SbMicrophoneIsValid(SbMicrophone microphone)
Opens the microphone port and starts recording audio on
Once started, the client needs to periodically call
SbMicrophoneRead to receive the audio data. If the microphone has already been started, this call clears the unread buffer. The return value indicates whether the microphone is open.
microphone: The microphone that will be opened and will start recording audio.
bool SbMicrophoneOpen(SbMicrophone microphone)
Retrieves the recorded audio data from the microphone and writes that data to
The return value is zero or the positive number of bytes that were read. Neither the return value nor
audio_data_size exceeds the buffer size. A negative return value indicates that an error occurred.
This function should be called frequently. Otherwise, the microphone only buffers
buffer_size bytes as configured in
SbMicrophoneCreate and the new audio data is thrown out. No audio data is read from a stopped microphone.
microphone: The microphone from which to retrieve recorded audio data.
out_audio_data: The buffer to which the retrieved data will be written.
audio_data_size: The number of requested bytes. If
audio_data_size is smaller than
SbMicrophoneInfo, the extra audio data that has already been read from the device is discarded.
int SbMicrophoneRead(SbMicrophone microphone, void *out_audio_data, int audio_data_size)