mirror of
https://github.com/romanz/amodem.git
synced 2026-03-17 15:16:00 +08:00
audio: add debug flag for PortAudio API
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user