jdxi_editor.audio.audio_source ============================== .. py:module:: jdxi_editor.audio.audio_source .. autoapi-nested-parse:: An input device, copied into the ring and nothing else. Opening the device is the only place PortAudio is touched. The callback copies into storage the source already owns. Classes ------- .. autoapisummary:: jdxi_editor.audio.audio_source.InputDeviceSource Functions --------- .. autoapisummary:: jdxi_editor.audio.audio_source._sounddevice jdxi_editor.audio.audio_source.copy_input jdxi_editor.audio.audio_source.describe_open_error Module Contents --------------- .. py:function:: _sounddevice() The sounddevice module, or None when the extra is not installed. .. py:function:: copy_input(indata: numpy.ndarray, scratch: numpy.ndarray, ring: jdxi_editor.audio.audio_buffer.SampleRing) -> None Copy one callback buffer into the ring. A mono buffer is written to both channels. Nothing is allocated: the scratch array belongs to the source and is reused on every callback. :param indata: np.ndarray ``(frames, channels)`` from the device :param scratch: np.ndarray stereo scratch, at least as long as a block :param ring: SampleRing :return: None .. py:function:: describe_open_error(error: Optional[Exception]) -> str A message for the status line when no rate or channel count opened. PortAudio reports a device that PipeWire or PulseAudio already holds as "Device unavailable" (-9985); that is the usual failure for a raw ALSA ``hw:`` device on a desktop Linux, and the fix is to choose the ``pipewire``, ``default`` or PulseAudio input instead. :param error: Optional[Exception] the last failure :return: str .. py:class:: InputDeviceSource(ring: jdxi_editor.audio.audio_buffer.SampleRing, sample_rate: int = SAMPLE_RATE, block: int = BLOCK_SIZE) Captures one input device into a :class:`SampleRing`. .. py:attribute:: ring .. py:attribute:: preferred_rate :value: 48000 .. py:attribute:: sample_rate :value: 48000 .. py:attribute:: block :value: 1024 .. py:attribute:: _scratch .. py:attribute:: _hold :type: Optional[int] :value: None .. py:attribute:: _stream :value: None .. py:method:: available() -> bool :staticmethod: Whether sounddevice imported. :return: bool .. py:method:: input_devices() -> list[tuple[str, int]] :staticmethod: Input devices as ``(name, index)``. :return: list .. py:method:: start(device: Optional[int] = None) -> int Open the input and start copying. The monitor's own rate is tried first, then the device's default rate: a raw ALSA ``hw:`` device does no rate conversion, and the JD-Xi's USB audio input refuses 48 kHz. At each rate stereo is tried first; a mono device is opened with one channel and duplicated in the callback. :attr:`sample_rate` is set to the rate that opened. :param device: Optional[int] sounddevice index; None is the default :return: int the sample rate the stream opened at, Hz .. py:method:: _rates_to_try(module, device: Optional[int]) -> list[int] The preferred rate, then the device's default if it differs. :param module: the sounddevice module :param device: Optional[int] sounddevice index; None is the default :return: list[int] Hz .. py:method:: stop() -> None Close the stream. :return: None