diff --git a/amodem/audio.py b/amodem/audio.py index f9972b1..bf91aa5 100644 --- a/amodem/audio.py +++ b/amodem/audio.py @@ -5,7 +5,8 @@ log = logging.getLogger(__name__) class Interface(object): - def __init__(self, name, config): + def __init__(self, name, config, debug=False): + self.debug = bool(debug) self.lib = ctypes.CDLL(name) self.config = config self.streams = [] @@ -15,7 +16,10 @@ class Interface(object): return self.call('GetErrorText', code, restype=ctypes.c_char_p) def call(self, name, *args, **kwargs): - func = getattr(self.lib, 'Pa_{0}'.format(name)) + func_name = 'Pa_{0}'.format(name) + if self.debug: + log.debug('API: %s%s', name, args) + func = getattr(self.lib, func_name) func.restype = kwargs.get('restype', self._error_check) return func(*args) diff --git a/tests/test_audio.py b/tests/test_audio.py index c0d54a1..1372365 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -13,7 +13,9 @@ def test(): lib.Pa_GetDefaultInputDevice.return_value = 1 lib.Pa_OpenStream.return_value = 0 cdll.return_value = lib - interface = audio.Interface(name='portaudio', config=config.fastest()) + interface = audio.Interface( + name='portaudio', config=config.fastest(), debug=True + ) with interface: s = interface.player() s.stream = 1 # simulate non-zero output stream handle