jdxi_editor.audio.audio_source

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

InputDeviceSource

Captures one input device into a SampleRing.

Functions

_sounddevice()

The sounddevice module, or None when the extra is not installed.

copy_input(indata, scratch, ring) → None

Copy one callback buffer into the ring.

describe_open_error(error) → str

A message for the status line when no rate or channel count opened.

Module Contents

jdxi_editor.audio.audio_source._sounddevice()[source]

The sounddevice module, or None when the extra is not installed.

jdxi_editor.audio.audio_source.copy_input(indata: numpy.ndarray, scratch: numpy.ndarray, ring: jdxi_editor.audio.audio_buffer.SampleRing) → None[source]

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.

Parameters:
  • indata – np.ndarray (frames, channels) from the device

  • scratch – np.ndarray stereo scratch, at least as long as a block

  • ring – SampleRing

Returns:

None

jdxi_editor.audio.audio_source.describe_open_error(error: Exception | None) → str[source]

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.

Parameters:

error – Optional[Exception] the last failure

Returns:

str

class jdxi_editor.audio.audio_source.InputDeviceSource(ring: jdxi_editor.audio.audio_buffer.SampleRing, sample_rate: int = SAMPLE_RATE, block: int = BLOCK_SIZE)[source]

Captures one input device into a SampleRing.

ring[source]
preferred_rate = 48000[source]
sample_rate = 48000[source]
block = 1024[source]
_scratch[source]
_hold: int | None = None[source]
_stream = None[source]
static available() → bool[source]

Whether sounddevice imported.

Returns:

bool

static input_devices() → list[tuple[str, int]][source]

Input devices as (name, index).

Returns:

list

start(device: int | None = None) → int[source]

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. sample_rate is set to the rate that opened.

Parameters:

device – Optional[int] sounddevice index; None is the default

Returns:

int the sample rate the stream opened at, Hz

_rates_to_try(module, device: int | None) → list[int][source]

The preferred rate, then the device’s default if it differs.

Parameters:
  • module – the sounddevice module

  • device – Optional[int] sounddevice index; None is the default

Returns:

list[int] Hz

stop() → None[source]

Close the stream.

Returns:

None