Skip to content

Commit 6989362

Browse files
committed
Allow input/output parameter pairs in all constructors
1 parent 532765c commit 6989362

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

sounddevice.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,19 +2688,23 @@ def _get_stream_parameters(kind, device, channels, dtype, latency,
26882688
"""Get parameters for one direction (input or output) of a stream."""
26892689
assert kind in ('input', 'output')
26902690
if device is None:
2691-
device = default.device[kind]
2691+
device = default.device
2692+
device = _get_device_id(device, kind, raise_on_error=True)
26922693
if channels is None:
2693-
channels = default.channels[kind]
2694+
channels = default.channels
2695+
channels = _select_input_or_output(channels, kind)
26942696
if dtype is None:
2695-
dtype = default.dtype[kind]
2697+
dtype = default.dtype
2698+
dtype = _select_input_or_output(dtype, kind)
26962699
if latency is None:
2697-
latency = default.latency[kind]
2700+
latency = default.latency
2701+
latency = _select_input_or_output(latency, kind)
26982702
if extra_settings is None:
2699-
extra_settings = default.extra_settings[kind]
2703+
extra_settings = default.extra_settings
2704+
extra_settings = _select_input_or_output(extra_settings, kind)
27002705
if samplerate is None:
27012706
samplerate = default.samplerate
27022707

2703-
device = _get_device_id(device, kind, raise_on_error=True)
27042708
info = query_devices(device)
27052709
if channels is None:
27062710
channels = info['max_' + kind + '_channels']
@@ -2792,6 +2796,16 @@ def _check(err, msg=''):
27922796
raise PortAudioError(errormsg, err)
27932797

27942798

2799+
def _select_input_or_output(value_or_pair, kind):
2800+
"""Given a pair (or a single value for both), select input or output."""
2801+
ivalue, ovalue = _split(value_or_pair)
2802+
if kind == 'input':
2803+
return ivalue
2804+
elif kind == 'output':
2805+
return ovalue
2806+
assert False
2807+
2808+
27952809
def _get_device_id(id_or_query_string, kind, raise_on_error=False):
27962810
"""Return device ID given space-separated substrings."""
27972811
assert kind in ('input', 'output', None)

0 commit comments

Comments
 (0)