diff options
| author | Matthias Geier <Matthias.Geier@gmail.com> | 2015-12-24 12:33:10 +0100 |
|---|---|---|
| committer | Matthias Geier <Matthias.Geier@gmail.com> | 2015-12-24 12:33:10 +0100 |
| commit | f79dba1a5da68f5baa006cc0dc16e6447f783d00 (patch) | |
| tree | 6cb0ad671cf948e84a9ef9a8a3264169324877f9 | |
| parent | d1f0d0d913f8857b5390b8e17e96892525f87895 (diff) | |
Add check_input_settings() and check_output_settings()
| -rw-r--r-- | sounddevice.py | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/sounddevice.py b/sounddevice.py index 5cdaab9..7121be0 100644 --- a/sounddevice.py +++ b/sounddevice.py @@ -150,7 +150,9 @@ typedef struct PaStreamParameters void *hostApiSpecificStreamInfo; } PaStreamParameters; /* not implemented: paFormatIsSupported */ -/* not implemented: Pa_IsFormatSupported */ +PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters, + const PaStreamParameters *outputParameters, + double sampleRate ); typedef void PaStream; #define paFramesPerBufferUnspecified 0 typedef unsigned long PaStreamFlags; @@ -677,6 +679,46 @@ def query_hostapis(index=None): } +def check_input_settings(device=None, channels=None, dtype=None, + samplerate=None): + """Check if given input device settings are supported. + + All parameters are optional, :obj:`default` settings are used for + any unspecified parameters. If the settings are supported, the + function does nothing; if not, an exception is raised. + + Parameters + ---------- + device : int or str, optional + Device ID or device name substring, see :attr:`default.device`. + channels : int, optional + Number of input channels, see :attr:`default.channels`. + dtype : str or numpy.dtype, optional + Data type for input samples, see :attr:`default.dtype`. + samplerate : float, optional + Sampling frequency, see :attr:`default.samplerate`. + + """ + parameters, dtype, samplesize, samplerate = _get_stream_parameters( + 'input', device=device, channels=channels, dtype=dtype, latency=None, + samplerate=samplerate) + _check(_lib.Pa_IsFormatSupported(parameters, _ffi.NULL, samplerate)) + + +def check_output_settings(device=None, channels=None, dtype=None, + samplerate=None): + """Check if given output device settings are supported. + + Same as :func:`check_input_settings`, just for output device + settings. + + """ + parameters, dtype, samplesize, samplerate = _get_stream_parameters( + 'output', device=device, channels=channels, dtype=dtype, latency=None, + samplerate=samplerate) + _check(_lib.Pa_IsFormatSupported(_ffi.NULL, parameters, samplerate)) + + def sleep(msec): """Put the caller to sleep for at least `msec` milliseconds. |
