Skip to content

Commit af0b51a

Browse files
committed
Add explicit sample format for WASAPI
1 parent 3adb6eb commit af0b51a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

sounddevice.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,7 +2448,7 @@ def __init__(self, channel_map=None, change_device_parameters=False,
24482448

24492449
class WasapiSettings:
24502450

2451-
def __init__(self, exclusive=False, auto_convert=False):
2451+
def __init__(self, exclusive=False, auto_convert=False, explicit_sample_format=False):
24522452
"""WASAPI-specific input/output settings.
24532453
24542454
Objects of this class can be used as *extra_settings* argument
@@ -2470,6 +2470,13 @@ def __init__(self, exclusive=False, auto_convert=False):
24702470
system mixer sample rate. This only applies in *shared
24712471
mode* and has no effect when *exclusive* is set to ``True``.
24722472
2473+
explicit_sample_format : bool
2474+
Force explicit sample format and do not allow PortAudio to
2475+
select suitable working format. API will fail if provided
2476+
sample format is not supported by audio hardware in Exclusive
2477+
mode or system mixer in Shared mode. This is required for
2478+
accurate native format detection.
2479+
24732480
Examples
24742481
--------
24752482
Setting exclusive mode when calling `play()`:
@@ -2487,8 +2494,10 @@ def __init__(self, exclusive=False, auto_convert=False):
24872494
flags = 0x0
24882495
if exclusive:
24892496
flags |= _lib.paWinWasapiExclusive
2490-
elif auto_convert:
2497+
if auto_convert:
24912498
flags |= _lib.paWinWasapiAutoConvert
2499+
if explicit_sample_format:
2500+
flags |= _lib.paWinWasapiExplicitSampleFormat
24922501
self._streaminfo = _ffi.new('PaWasapiStreamInfo*', dict(
24932502
size=_ffi.sizeof('PaWasapiStreamInfo'),
24942503
hostApiType=_lib.paWASAPI,

sounddevice_build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@
255255
paWinWasapiUseChannelMask = 4,
256256
paWinWasapiPolling = 8,
257257
paWinWasapiThreadPriority = 16,
258+
paWinWasapiExplicitSampleFormat = 32,
258259
paWinWasapiAutoConvert = 64
259260
} PaWasapiFlags;
260261

0 commit comments

Comments
 (0)