libretro.drivers.microphone.generator¶
MicrophoneDriver implementation that returns samples produced by a generator function.
See also
MicrophoneDriverThe protocol this driver implements.
Classes
A |
|
A |
- class GeneratorMicrophone[source]¶
Bases:
MicrophoneA
Microphonethat 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
MicrophoneThe protocol this class implements.
- __init__(generator, params)[source]¶
Initialize the microphone with a sample source and capture parameters.
- Parameters:
generator (
Iterable[int|Sequence[int] |None] |Callable[[],Iterator[int|Sequence[int] |None]] |None) – The audio source. A generator function is called once to obtain its iterator; an iterable is used directly.Noneproduces an infinite stream of silence.params (
retro_microphone_params|None) – The capture parameters to advertise, orNoneto default to 44.1 kHz mono.
- Raises:
TypeError – If
generatoris neither a callable, an iterable, norNone.
- close()[source]¶
Close this microphone and release any underlying resources.
Subsequent calls to
read()should returnNone.- Return type:
- property params¶
The capture parameters (sample rate, channel layout) negotiated for this microphone.
Noneif the microphone is closed or no parameters have been negotiated.See also
retro_microphone_paramsThe C struct describing the negotiated capture format.
- property state¶
Whether this microphone is currently capturing.
- property handle¶
The opaque
retro_microphonehandle exposed to the core.
- classmethod __new__(*args, **kwargs)¶
- class GeneratorMicrophoneDriver[source]¶
Bases:
MicrophoneDriverA
MicrophoneDriverthat opensGeneratorMicrophoneinstances on demand.Each microphone the core opens is backed by the same source supplied at construction.
See also
MicrophoneDriverThe protocol this class implements.
- 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, orNoneto let the driver pick its defaults.- Return type:
- Returns:
A handle to the opened microphone, or
Noneif 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:
- get_mic_params(mic)[source]¶
Return the negotiated capture parameters for
mic.- Parameters:
mic (
retro_microphone) – The microphone handle to query.- Return type:
- Returns:
The negotiated parameters, or
Noneif the microphone has none.
- classmethod __new__(*args, **kwargs)¶
- get_mic_state(mic)[source]¶
Return whether
micis currently capturing.- Parameters:
mic (
retro_microphone) – The microphone handle to query.- Return type:
- Returns:
Trueif the microphone is capturing.
- set_mic_state(mic, state)[source]¶
Start or pause capture on
mic.- Parameters:
mic (
retro_microphone) – The microphone handle to update.
- Return type:
- read_mic(mic, frames)[source]¶
Read up to
framesaudio frames frommic.- Parameters:
mic (
retro_microphone) – The microphone handle to read from.frames (
int) – Maximum number of mono signed 16-bit frames to read.
- Return type:
- Returns:
An
array.arrayof signed 16-bit samples holding the frames actually read, orNoneif the microphone is closed or no samples are available.
- property microphones¶
All microphones currently open through this driver.