From 2b2ecdda4109ac5308a660d476d782cddffb9d85 Mon Sep 17 00:00:00 2001 From: ThatOneFBIAgent <93457345+ThatOneFBIAgent@users.noreply.github.com> Date: Sun, 3 May 2026 20:23:48 -0600 Subject: [PATCH 1/2] Fix callback handling and flag initialization --- src/sounddevice.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sounddevice.py b/src/sounddevice.py index 00fc6f8..dcbdf63 100644 --- a/src/sounddevice.py +++ b/src/sounddevice.py @@ -1927,7 +1927,7 @@ class CallbackFlags: __slots__ = '_flags' def __init__(self, flags=0x0): - self._flags = flags + self._flags = int(flags) def __repr__(self): flags = str(self) @@ -2770,18 +2770,18 @@ def _get_stream_parameters(kind, device, channels, dtype, latency, return parameters, dtype, samplesize, samplerate -def _wrap_callback(callback, *args): +def _wrap_callback(callback, data, frames, time, status): """Invoke callback function and check for custom exceptions.""" - args = args[:-1] + (CallbackFlags(args[-1]),) + cf = CallbackFlags.__new__(CallbackFlags) + cf._flags = int(status) try: - callback(*args) + callback(data, frames, time, cf) except CallbackStop: return _lib.paComplete except CallbackAbort: return _lib.paAbort return _lib.paContinue - def _buffer(ptr, frames, channels, samplesize): """Create a buffer object from a pointer to some memory.""" return _ffi.buffer(ptr, frames * channels * samplesize) From 9796c093fe9f2676b3715855e14b43eaf5e1fe40 Mon Sep 17 00:00:00 2001 From: ThatOneFBIAgent <93457345+ThatOneFBIAgent@users.noreply.github.com> Date: Mon, 4 May 2026 14:54:03 -0600 Subject: [PATCH 2/2] Refactor _wrap_callback to accept variable arguments from duplex --- src/sounddevice.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sounddevice.py b/src/sounddevice.py index dcbdf63..86a6f03 100644 --- a/src/sounddevice.py +++ b/src/sounddevice.py @@ -2770,12 +2770,13 @@ def _get_stream_parameters(kind, device, channels, dtype, latency, return parameters, dtype, samplesize, samplerate -def _wrap_callback(callback, data, frames, time, status): +def _wrap_callback(callback, *args): """Invoke callback function and check for custom exceptions.""" cf = CallbackFlags.__new__(CallbackFlags) - cf._flags = int(status) + cf._flags = int(args[-1]) + args = args[:-1] + (cf,) try: - callback(data, frames, time, cf) + callback(*args) except CallbackStop: return _lib.paComplete except CallbackAbort: