audio: add debug flag for PortAudio API

This commit is contained in:
Roman Zeyde
2015-01-08 18:06:50 +02:00
parent 750eb5428f
commit c2c1b89a0e
2 changed files with 9 additions and 3 deletions

View File

@@ -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)

View File

@@ -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