libretro.api.microphone

Microphone audio capture interface types.

Corresponds to retro_microphone_interface in libretro.h. Allows cores to capture audio input from the host device.

Module Attributes

RETRO_MICROPHONE_INTERFACE_VERSION

The current version of the microphone interface.

INTERFACE_VERSION

Alias for RETRO_MICROPHONE_INTERFACE_VERSION.

retro_open_mic_t

Open a new microphone for capture.

retro_close_mic_t

Close an open microphone and release its resources.

retro_get_mic_params_t

Retrieve the configured parameters of an open microphone.

retro_set_mic_state_t

Enable or disable an open microphone.

retro_get_mic_state_t

Return whether an open microphone is currently enabled.

retro_read_mic_t

Read captured audio samples from an open microphone.

Classes

retro_microphone

Opaque handle for an open microphone.

retro_microphone_interface

Corresponds to retro_microphone_interface in libretro.h.

retro_microphone_params

Parameters for opening a microphone.

RETRO_MICROPHONE_INTERFACE_VERSION = 1

The current version of the microphone interface.

INTERFACE_VERSION = 1

Alias for RETRO_MICROPHONE_INTERFACE_VERSION.

class retro_microphone[source]

Bases: Structure

Opaque handle for an open microphone.

Corresponds to retro_microphone in libretro.h.

Note

Unlike most other ctypes-wrapped structs in libretro.py, the fields in this class are not part of libretro.h. They are provided as a convenience for MicrophoneDriver implementations.

Cores should treat instances of this class as opaque handles and _not_ access or modify its fields directly.

id

Opaque identifier for this microphone handle.

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
class retro_microphone_params[source]

Bases: Structure

Parameters for opening a microphone.

Corresponds to retro_microphone_params in libretro.h.

>>> from libretro.api.microphone import retro_microphone_params
>>> p = retro_microphone_params()
>>> p.rate
0
rate

Requested sample rate in Hz.

__deepcopy__(_)[source]

Return a shallow copy.

>>> import copy
>>> from libretro.api.microphone import retro_microphone_params
>>> copy.deepcopy(retro_microphone_params()).rate
0
__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
retro_open_mic_t

Open a new microphone for capture.

Registered by the frontend and called by the core.

Parameters:

params – Pointer to a retro_microphone_params describing the desired configuration, or None to use the frontend’s defaults.

Returns:

A c_void_ptr to a retro_microphone handle on success, or None if a microphone could not be opened.

Note

Microphones are inactive by default; a returned handle must be enabled with retro_set_mic_state_t before it will yield samples.

Corresponds to retro_open_mic_t in libretro.h.

retro_close_mic_t

Close an open microphone and release its resources.

Registered by the frontend and called by the core. After this returns, the handle must not be used again.

Parameters:

microphone – Pointer to the retro_microphone handle to close. If None, this function does nothing.

Corresponds to retro_close_mic_t in libretro.h.

retro_get_mic_params_t

Retrieve the configured parameters of an open microphone.

Registered by the frontend and called by the core. The returned parameters may differ from those originally requested depending on driver and device support.

Parameters:
Returns:

True on success, False if either argument is invalid.

Corresponds to retro_get_mic_params_t in libretro.h.

retro_set_mic_state_t

Enable or disable an open microphone.

Registered by the frontend and called by the core. A disabled microphone will not produce samples and has minimal performance impact.

Parameters:
  • microphone – Pointer to the retro_microphone whose state will change.

  • stateTrue to enable the microphone, False to pause it.

Returns:

True if the state was successfully set, False if microphone is invalid or there was an error.

Corresponds to retro_set_mic_state_t in libretro.h.

retro_get_mic_state_t

Return whether an open microphone is currently enabled.

Registered by the frontend and called by the core.

Parameters:

microphone – Pointer to the retro_microphone to query.

Returns:

True if microphone is valid and active, False otherwise.

Corresponds to retro_get_mic_state_t in libretro.h.

retro_read_mic_t

Read captured audio samples from an open microphone.

Registered by the frontend and called by the core, which must do so every frame while the microphone is enabled.

Parameters:
  • microphone – Pointer to the retro_microphone to read from.

  • samples – Pointer to a buffer of signed 16-bit mono samples that will be filled.

  • num_samples – Capacity of samples, in samples (not bytes).

Returns:

The number of samples actually written to samples, or -1 if the microphone is disabled, the audio driver is paused, or there was an error.

Corresponds to retro_read_mic_t in libretro.h.

class retro_microphone_interface[source]

Bases: Structure

Corresponds to retro_microphone_interface in libretro.h.

Provides functions for managing microphone input.

>>> from libretro.api.microphone import retro_microphone_interface, INTERFACE_VERSION
>>> mic = retro_microphone_interface(INTERFACE_VERSION)
>>> mic.open_mic is None
True
classmethod __new__(*args, **kwargs)
__init__(interface_version, open_mic=None, close_mic=None, get_params=None, set_mic_state=None, get_mic_state=None, read_mic=None)[source]

Initialize the interface with a required version number.

Parameters:

interface_version (int) – Must match INTERFACE_VERSION.

interface_version

Version of the microphone interface.

open_mic

Opens a microphone with the given parameters.

close_mic

Closes an open microphone.

get_params

Retrieves the effective parameters of an open microphone.

set_mic_state

Enables or disables an open microphone.

get_mic_state

Returns whether an open microphone is currently enabled.

read_mic

Reads audio samples from an open microphone.

__deepcopy__(_)[source]

Return a shallow copy.

>>> import copy
>>> from libretro.api.microphone import retro_microphone_interface, INTERFACE_VERSION
>>> copy.deepcopy(retro_microphone_interface(INTERFACE_VERSION)).open_mic is None
True