Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow input/output parameter pairs in all constructors #563

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions sounddevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2688,19 +2688,23 @@ def _get_stream_parameters(kind, device, channels, dtype, latency,
"""Get parameters for one direction (input or output) of a stream."""
assert kind in ('input', 'output')
if device is None:
device = default.device[kind]
device = default.device
device = _get_device_id(device, kind, raise_on_error=True)
if channels is None:
channels = default.channels[kind]
channels = default.channels
channels = _select_input_or_output(channels, kind)
if dtype is None:
dtype = default.dtype[kind]
dtype = default.dtype
dtype = _select_input_or_output(dtype, kind)
if latency is None:
latency = default.latency[kind]
latency = default.latency
latency = _select_input_or_output(latency, kind)
if extra_settings is None:
extra_settings = default.extra_settings[kind]
extra_settings = default.extra_settings
extra_settings = _select_input_or_output(extra_settings, kind)
if samplerate is None:
samplerate = default.samplerate

device = _get_device_id(device, kind, raise_on_error=True)
info = query_devices(device)
if channels is None:
channels = info['max_' + kind + '_channels']
Expand Down Expand Up @@ -2792,6 +2796,16 @@ def _check(err, msg=''):
raise PortAudioError(errormsg, err)


def _select_input_or_output(value_or_pair, kind):
"""Given a pair (or a single value for both), select input or output."""
ivalue, ovalue = _split(value_or_pair)
if kind == 'input':
return ivalue
elif kind == 'output':
return ovalue
assert False


def _get_device_id(id_or_query_string, kind, raise_on_error=False):
"""Return device ID given space-separated substrings."""
assert kind in ('input', 'output', None)
Expand Down