mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Add CRC to audio device names
This commit is contained in:
parent
2f84a1b235
commit
3e704d5015
13
tnc/audio.py
13
tnc/audio.py
|
@ -4,6 +4,7 @@ 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
|
import structlog
|
||||||
|
|
||||||
|
@ -43,6 +44,14 @@ def get_audio_devices():
|
||||||
return list(proxy_input_devices), list(proxy_output_devices)
|
return list(proxy_input_devices), list(proxy_output_devices)
|
||||||
|
|
||||||
|
|
||||||
|
def device_crc(dev_name: str) -> str:
|
||||||
|
crc_algorithm = crcengine.new("crc16-ccitt-false") # load crc8 library
|
||||||
|
crc_hwid = crc_algorithm(bytes(dev_name, encoding="utf-8"))
|
||||||
|
crc_hwid = crc_hwid.to_bytes(2, byteorder="big")
|
||||||
|
crc_hwid = crc_hwid.hex()
|
||||||
|
return f"{dev_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
|
||||||
|
@ -77,9 +86,9 @@ def fetch_audio_devices(input_devices, output_devices):
|
||||||
name = ""
|
name = ""
|
||||||
|
|
||||||
if max_input_channels > 0:
|
if max_input_channels > 0:
|
||||||
input_devs.add(name)
|
input_devs.add(device_crc(name))
|
||||||
if max_output_channels > 0:
|
if max_output_channels > 0:
|
||||||
output_devs.add(name)
|
output_devs.add(device_crc(name))
|
||||||
|
|
||||||
for index, item in enumerate(input_devs):
|
for index, item in enumerate(input_devs):
|
||||||
input_devices.append({"id": index, "name": item})
|
input_devices.append({"id": index, "name": item})
|
||||||
|
|
Loading…
Reference in a new issue