Skip to content

Commit f79dba1

Browse files
committed
Add check_input_settings() and check_output_settings()
1 parent d1f0d0d commit f79dba1

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

sounddevice.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@
150150
void *hostApiSpecificStreamInfo;
151151
} PaStreamParameters;
152152
/* not implemented: paFormatIsSupported */
153-
/* not implemented: Pa_IsFormatSupported */
153+
PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters,
154+
const PaStreamParameters *outputParameters,
155+
double sampleRate );
154156
typedef void PaStream;
155157
#define paFramesPerBufferUnspecified 0
156158
typedef unsigned long PaStreamFlags;
@@ -677,6 +679,46 @@ def query_hostapis(index=None):
677679
}
678680

679681

682+
def check_input_settings(device=None, channels=None, dtype=None,
683+
samplerate=None):
684+
"""Check if given input device settings are supported.
685+
686+
All parameters are optional, :obj:`default` settings are used for
687+
any unspecified parameters. If the settings are supported, the
688+
function does nothing; if not, an exception is raised.
689+
690+
Parameters
691+
----------
692+
device : int or str, optional
693+
Device ID or device name substring, see :attr:`default.device`.
694+
channels : int, optional
695+
Number of input channels, see :attr:`default.channels`.
696+
dtype : str or numpy.dtype, optional
697+
Data type for input samples, see :attr:`default.dtype`.
698+
samplerate : float, optional
699+
Sampling frequency, see :attr:`default.samplerate`.
700+
701+
"""
702+
parameters, dtype, samplesize, samplerate = _get_stream_parameters(
703+
'input', device=device, channels=channels, dtype=dtype, latency=None,
704+
samplerate=samplerate)
705+
_check(_lib.Pa_IsFormatSupported(parameters, _ffi.NULL, samplerate))
706+
707+
708+
def check_output_settings(device=None, channels=None, dtype=None,
709+
samplerate=None):
710+
"""Check if given output device settings are supported.
711+
712+
Same as :func:`check_input_settings`, just for output device
713+
settings.
714+
715+
"""
716+
parameters, dtype, samplesize, samplerate = _get_stream_parameters(
717+
'output', device=device, channels=channels, dtype=dtype, latency=None,
718+
samplerate=samplerate)
719+
_check(_lib.Pa_IsFormatSupported(_ffi.NULL, parameters, samplerate))
720+
721+
680722
def sleep(msec):
681723
"""Put the caller to sleep for at least `msec` milliseconds.
682724

0 commit comments

Comments
 (0)