2828import atexit as _atexit
2929from cffi import FFI as _FFI
3030import sys as _sys
31- import logging as _logging
3231
3332_ffi = _FFI ()
3433_ffi .cdef ("""
@@ -440,6 +439,10 @@ def wait():
440439 If at least one buffer over-/underrun happened during the last
441440 playback/recording, a :class:`CallbackFlags` object is returned.
442441
442+ See Also
443+ --------
444+ get_status
445+
443446 """
444447 global _last_callback
445448 if _last_callback :
@@ -460,6 +463,26 @@ def stop(ignore_errors=True):
460463 _last_callback .stream .close (ignore_errors )
461464
462465
466+ def get_status ():
467+ """Get information about over-/underflows in play()/rec()/playrec().
468+
469+ Returns
470+ -------
471+ CallbackFlags
472+ A :class:`CallbackFlags` object that holds information about the
473+ last invocation of :func:`play`, :func:`rec` or :func:`playrec`.
474+
475+ See Also
476+ --------
477+ wait
478+
479+ """
480+ if _last_callback :
481+ return _last_callback .status
482+ else :
483+ raise RuntimeError ("play()/rec()/playrec() was not called yet" )
484+
485+
463486def print_devices ():
464487 """Show information about all available audio devices.
465488
@@ -1749,12 +1772,15 @@ def __init__(self, flags=0x0):
17491772 self ._flags = flags
17501773
17511774 def __repr__ (self ):
1752- flags = ", " .join (name for name in dir (self )
1753- if not name .startswith ('_' ) and getattr (self , name ))
1775+ flags = str (self )
17541776 if not flags :
17551777 flags = "no flags set"
17561778 return "<sounddevice.CallbackFlags: {0}>" .format (flags )
17571779
1780+ def __str__ (self ):
1781+ return ", " .join (name .replace ('_' , ' ' ) for name in dir (self )
1782+ if not name .startswith ('_' ) and getattr (self , name ))
1783+
17581784 def __bool__ (self ):
17591785 return bool (self ._flags )
17601786
@@ -2091,7 +2117,6 @@ def __init__(self):
20912117 raise ImportError (
20922118 "NumPy must be installed for play()/rec()/playrec()" )
20932119 self .event = threading .Event ()
2094- self .logger = _logging .getLogger (__name__ )
20952120 self .status = CallbackFlags ()
20962121
20972122 def check_data (self , data , mapping ):
@@ -2180,14 +2205,6 @@ def callback_exit(self):
21802205 self .frame += self .blocksize
21812206
21822207 def finished_callback (self ):
2183- if self .status .input_underflow :
2184- self .logger .warning ("input underflowed" )
2185- if self .status .input_overflow :
2186- self .logger .warning ("input overflowed" )
2187- if self .status .output_underflow :
2188- self .logger .warning ("output underflowed" )
2189- if self .status .output_overflow :
2190- self .logger .warning ("output overflowed" )
21912208 self .event .set ()
21922209
21932210 def start_stream (self , StreamClass , samplerate , channels , dtype , callback ,
0 commit comments