Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Get a list of capture devices and some details about them"""
capture_infos = ffi.new("ma_device_info**")
capture_count = ffi.new("ma_uint32*")
result = lib.ma_context_get_devices(self._context, ffi.NULL, ffi.NULL, capture_infos, capture_count)
if result != lib.MA_SUCCESS:
raise MiniaudioError("cannot get device infos", result)
devs = []
for i in range(capture_count[0]):
ma_device_info = capture_infos[0][i]
dev_id = ffi.new("ma_device_id *", ma_device_info.id) # copy the id memory
info = {
"name": ffi.string(ma_device_info.name).decode(),
"type": DeviceType.CAPTURE,
"id": dev_id
}
info.update(self._get_info(DeviceType.CAPTURE, ma_device_info))
devs.append(info)
return devs
"""Get a list of playback devices and some details about them"""
playback_infos = ffi.new("ma_device_info**")
playback_count = ffi.new("ma_uint32*")
result = lib.ma_context_get_devices(self._context, playback_infos, playback_count, ffi.NULL, ffi.NULL)
if result != lib.MA_SUCCESS:
raise MiniaudioError("cannot get device infos", result)
devs = []
for i in range(playback_count[0]):
ma_device_info = playback_infos[0][i]
dev_id = ffi.new("ma_device_id *", ma_device_info.id) # copy the id memory
info = {
"name": ffi.string(ma_device_info.name).decode(),
"type": DeviceType.PLAYBACK,
"id": dev_id
}
info.update(self._get_info(DeviceType.PLAYBACK, ma_device_info))
devs.append(info)
return devs
def ma_query_device_details(self, device: Optional[Union[int, str]] = None, kind: Optional[str] = None) -> Any:
devices = miniaudio.Devices()
if kind == miniaudio.DeviceType.PLAYBACK:
devs = devices.get_playbacks()
elif kind == miniaudio.DeviceType.CAPTURE:
devs = devices.get_playbacks()
else:
devs = devices.get_playbacks() + devices.get_captures()
id_buf = miniaudio.ffi.buffer(device)
for d in devs:
if miniaudio.ffi.buffer(d["id"]) == id_buf:
return d
raise LookupError("device not found")
def ma_query_device_details(self, device: Optional[Union[int, str]] = None, kind: Optional[str] = None) -> Any:
devices = miniaudio.Devices()
if kind == miniaudio.DeviceType.PLAYBACK:
devs = devices.get_playbacks()
elif kind == miniaudio.DeviceType.CAPTURE:
devs = devices.get_playbacks()
else:
devs = devices.get_playbacks() + devices.get_captures()
id_buf = miniaudio.ffi.buffer(device)
for d in devs:
if miniaudio.ffi.buffer(d["id"]) == id_buf:
return d
raise LookupError("device not found")