mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Merge pull request #231 from DJ2LS/issue_174_fix
This commit is contained in:
commit
52e1af908b
1
.github/workflows/build_multiplatform.yml
vendored
1
.github/workflows/build_multiplatform.yml
vendored
|
@ -223,7 +223,6 @@ jobs:
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: DJ2LS/FreeDATA
|
repository: DJ2LS/FreeDATA
|
||||||
ref: main
|
|
||||||
|
|
||||||
- name: Set up Python 3.9
|
- name: Set up Python 3.9
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
|
|
33
tnc/audio.py
33
tnc/audio.py
|
@ -4,10 +4,14 @@ Gather information about audio devices.
|
||||||
import atexit
|
import atexit
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
|
||||||
|
import crcengine
|
||||||
import sounddevice as sd
|
import sounddevice as sd
|
||||||
|
import structlog
|
||||||
|
|
||||||
atexit.register(sd._terminate)
|
atexit.register(sd._terminate)
|
||||||
|
|
||||||
|
log = structlog.get_logger("audio")
|
||||||
|
|
||||||
|
|
||||||
def get_audio_devices():
|
def get_audio_devices():
|
||||||
"""
|
"""
|
||||||
|
@ -24,6 +28,7 @@ def get_audio_devices():
|
||||||
sd._terminate()
|
sd._terminate()
|
||||||
sd._initialize()
|
sd._initialize()
|
||||||
|
|
||||||
|
log.error("[AUD] get_audio_devices")
|
||||||
with multiprocessing.Manager() as manager:
|
with multiprocessing.Manager() as manager:
|
||||||
proxy_input_devices = manager.list()
|
proxy_input_devices = manager.list()
|
||||||
proxy_output_devices = manager.list()
|
proxy_output_devices = manager.list()
|
||||||
|
@ -34,9 +39,19 @@ def get_audio_devices():
|
||||||
proc.start()
|
proc.start()
|
||||||
proc.join()
|
proc.join()
|
||||||
|
|
||||||
|
log.error(f"[AUD] get_audio_devices: input_devices: {proxy_input_devices}")
|
||||||
|
log.error(f"[AUD] get_audio_devices: output_devices: {proxy_output_devices}")
|
||||||
return list(proxy_input_devices), list(proxy_output_devices)
|
return list(proxy_input_devices), list(proxy_output_devices)
|
||||||
|
|
||||||
|
|
||||||
|
def device_crc(device) -> str:
|
||||||
|
crc_algorithm = crcengine.new("crc16-ccitt-false") # load crc8 library
|
||||||
|
crc_hwid = crc_algorithm(bytes(f"{device}", encoding="utf-8"))
|
||||||
|
crc_hwid = crc_hwid.to_bytes(2, byteorder="big")
|
||||||
|
crc_hwid = crc_hwid.hex()
|
||||||
|
return f"{device['name']} [{crc_hwid}]"
|
||||||
|
|
||||||
|
|
||||||
def fetch_audio_devices(input_devices, output_devices):
|
def fetch_audio_devices(input_devices, output_devices):
|
||||||
"""
|
"""
|
||||||
get audio devices from portaudio
|
get audio devices from portaudio
|
||||||
|
@ -49,7 +64,12 @@ def fetch_audio_devices(input_devices, output_devices):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
devices = sd.query_devices(device=None, kind=None)
|
devices = sd.query_devices(device=None, kind=None)
|
||||||
for index, device in enumerate(devices):
|
|
||||||
|
# The use of set forces the list to contain only unique entries.
|
||||||
|
input_devs = set()
|
||||||
|
output_devs = set()
|
||||||
|
|
||||||
|
for device in devices:
|
||||||
# Use a try/except block because Windows doesn't have an audio device range
|
# Use a try/except block because Windows doesn't have an audio device range
|
||||||
try:
|
try:
|
||||||
name = device["name"]
|
name = device["name"]
|
||||||
|
@ -57,6 +77,8 @@ def fetch_audio_devices(input_devices, output_devices):
|
||||||
max_output_channels = device["max_output_channels"]
|
max_output_channels = device["max_output_channels"]
|
||||||
max_input_channels = device["max_input_channels"]
|
max_input_channels = device["max_input_channels"]
|
||||||
|
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(err)
|
print(err)
|
||||||
max_input_channels = 0
|
max_input_channels = 0
|
||||||
|
@ -64,6 +86,11 @@ def fetch_audio_devices(input_devices, output_devices):
|
||||||
name = ""
|
name = ""
|
||||||
|
|
||||||
if max_input_channels > 0:
|
if max_input_channels > 0:
|
||||||
input_devices.append({"id": index, "name": name})
|
input_devs.add(device_crc(device))
|
||||||
if max_output_channels > 0:
|
if max_output_channels > 0:
|
||||||
output_devices.append({"id": index, "name": name})
|
output_devs.add(device_crc(device))
|
||||||
|
|
||||||
|
for index, item in enumerate(input_devs):
|
||||||
|
input_devices.append({"id": index, "name": item})
|
||||||
|
for index, item in enumerate(output_devs):
|
||||||
|
output_devices.append({"id": index, "name": item})
|
||||||
|
|
Loading…
Reference in a new issue