libretro.drivers.microphone.generator

MicrophoneDriver implementation that returns samples produced by a generator function.

See also

MicrophoneDriver

The protocol this driver implements.

Classes

GeneratorMicrophone

A Microphone that returns samples produced by a generator or iterable.

GeneratorMicrophoneDriver

A MicrophoneDriver that opens GeneratorMicrophone instances on demand.

class GeneratorMicrophone[source]

Bases: Microphone

A Microphone that returns samples produced by a generator or iterable.

Use this to feed scripted or recorded audio into a core under test without needing a real microphone.

See also

Microphone

The protocol this class implements.

__init__(generator, params)[source]

Initialize the microphone with a sample source and capture parameters.

Parameters:
Raises:

TypeError – If generator is neither a callable, an iterable, nor None.

close()[source]

Close this microphone and release any underlying resources.

Subsequent calls to read() should return None.

Return type:

None

property params

The capture parameters (sample rate, channel layout) negotiated for this microphone.

None if the microphone is closed or no parameters have been negotiated.

See also

retro_microphone_params

The C struct describing the negotiated capture format.

property state

Whether this microphone is currently capturing.

Parameters:

stateTrue to start capturing, False to pause it.

read(frames)[source]

Read up to frames audio frames from this microphone.

Parameters:

frames (int) – Maximum number of mono signed 16-bit frames to read.

Return type:

array[int] | None

Returns:

An array.array of signed 16-bit samples holding the frames actually read, or None if the microphone is closed or no samples are available.

property handle

The opaque retro_microphone handle exposed to the core.

classmethod __new__(*args, **kwargs)
poll()

Advance any per-frame internal state (e.g. refilling the capture buffer).

Default implementation is a no-op; drivers that need per-frame work override this.

Return type:

None

class GeneratorMicrophoneDriver[source]

Bases: MicrophoneDriver

A MicrophoneDriver that opens GeneratorMicrophone instances on demand.

Each microphone the core opens is backed by the same source supplied at construction.

See also

MicrophoneDriver

The protocol this class implements.

__init__(generator=None)[source]

Initialize the driver with a default sample source.

Parameters:

generator (Callable[[], Iterator[int | Sequence[int] | None]] | Iterable[int | Sequence[int] | None] | None) – The audio source used for every microphone opened by the core, or None to default to silence. See GeneratorMicrophone for accepted forms.

property version

The version of the microphone interface this driver implements.

open_mic(params)[source]

Open a new microphone capture stream.

Parameters:

params (retro_microphone_params | None) – Requested capture parameters, or None to let the driver pick its defaults.

Return type:

retro_microphone | None

Returns:

A handle to the opened microphone, or None if no microphone could be opened.

close_mic(mic)[source]

Close a microphone previously returned by open_mic().

Parameters:

mic (retro_microphone) – The microphone handle to close.

Return type:

None

get_mic_params(mic)[source]

Return the negotiated capture parameters for mic.

Parameters:

mic (retro_microphone) – The microphone handle to query.

Return type:

retro_microphone_params | None

Returns:

The negotiated parameters, or None if the microphone has none.

classmethod __new__(*args, **kwargs)
get_mic_state(mic)[source]

Return whether mic is currently capturing.

Parameters:

mic (retro_microphone) – The microphone handle to query.

Return type:

bool

Returns:

True if the microphone is capturing.

set_mic_state(mic, state)[source]

Start or pause capture on mic.

Parameters:
Return type:

None

read_mic(mic, frames)[source]

Read up to frames audio frames from mic.

Parameters:
  • mic (retro_microphone) – The microphone handle to read from.

  • frames (int) – Maximum number of mono signed 16-bit frames to read.

Return type:

array[int] | None

Returns:

An array.array of signed 16-bit samples holding the frames actually read, or None if the microphone is closed or no samples are available.

property microphones

All microphones currently open through this driver.