mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Use audio device name crc as the id. Detect and match crc to find the correct device.
This commit is contained in:
parent
61636fe473
commit
045fcb1e4b
|
@ -49,15 +49,10 @@ def get_audio_devices():
|
||||||
|
|
||||||
|
|
||||||
def device_crc(device) -> str:
|
def device_crc(device) -> str:
|
||||||
|
|
||||||
crc_hwid = crc_algorithm(bytes(f"{device}", encoding="utf-8"))
|
crc_hwid = crc_algorithm(bytes(f"{device}", encoding="utf-8"))
|
||||||
crc_hwid = crc_hwid.to_bytes(2, byteorder="big")
|
crc_hwid = crc_hwid.to_bytes(2, byteorder="big")
|
||||||
crc_hwid = crc_hwid.hex()
|
crc_hwid = crc_hwid.hex()
|
||||||
|
return crc_hwid
|
||||||
hostapi_name = sd.query_hostapis(device['hostapi'])['name']
|
|
||||||
|
|
||||||
return f"{device['name']} [{hostapi_name}] [{crc_hwid}]"
|
|
||||||
|
|
||||||
|
|
||||||
def fetch_audio_devices(input_devices, output_devices):
|
def fetch_audio_devices(input_devices, output_devices):
|
||||||
"""
|
"""
|
||||||
|
@ -91,13 +86,39 @@ def fetch_audio_devices(input_devices, output_devices):
|
||||||
max_output_channels = 0
|
max_output_channels = 0
|
||||||
|
|
||||||
if max_input_channels > 0:
|
if max_input_channels > 0:
|
||||||
new_input_device = {"id": index, "name": device_crc(device)}
|
hostapi_name = sd.query_hostapis(device['hostapi'])['name']
|
||||||
|
|
||||||
|
new_input_device = {"id": device_crc(device),
|
||||||
|
"name": device['name'],
|
||||||
|
"api": hostapi_name}
|
||||||
# check if device not in device list
|
# check if device not in device list
|
||||||
if new_input_device not in input_devices:
|
if new_input_device not in input_devices:
|
||||||
input_devices.append(new_input_device)
|
input_devices.append(new_input_device)
|
||||||
|
|
||||||
if max_output_channels > 0:
|
if max_output_channels > 0:
|
||||||
new_output_device = {"id": index, "name": device_crc(device)}
|
new_output_device = {"id": device_crc(device),
|
||||||
|
"name": device['name'],
|
||||||
|
"api": hostapi_name}
|
||||||
# check if device not in device list
|
# check if device not in device list
|
||||||
if new_output_device not in output_devices:
|
if new_output_device not in output_devices:
|
||||||
output_devices.append(new_output_device)
|
output_devices.append(new_output_device)
|
||||||
|
|
||||||
|
# FreeData uses the crc as id inside the configuration
|
||||||
|
# SD lib uses a numerical id which is essentially an
|
||||||
|
# index of the device within the list
|
||||||
|
def get_device_index_from_crc(crc, isInput: bool):
|
||||||
|
in_devices = []
|
||||||
|
out_devices = []
|
||||||
|
|
||||||
|
fetch_audio_devices(in_devices, out_devices)
|
||||||
|
|
||||||
|
if isInput:
|
||||||
|
detected_devices = in_devices
|
||||||
|
else:
|
||||||
|
detected_devices = out_devices
|
||||||
|
|
||||||
|
for i, dev in enumerate(detected_devices):
|
||||||
|
if dev['id'] == crc:
|
||||||
|
return i
|
||||||
|
|
||||||
|
raise Exception("Audio device %s not detected." % crc)
|
||||||
|
|
|
@ -29,6 +29,7 @@ import tci
|
||||||
import cw
|
import cw
|
||||||
from queues import DATA_QUEUE_RECEIVED, MODEM_RECEIVED_QUEUE, MODEM_TRANSMIT_QUEUE, RIGCTLD_COMMAND_QUEUE, \
|
from queues import DATA_QUEUE_RECEIVED, MODEM_RECEIVED_QUEUE, MODEM_TRANSMIT_QUEUE, RIGCTLD_COMMAND_QUEUE, \
|
||||||
AUDIO_RECEIVED_QUEUE, AUDIO_TRANSMIT_QUEUE, MESH_RECEIVED_QUEUE
|
AUDIO_RECEIVED_QUEUE, AUDIO_TRANSMIT_QUEUE, MESH_RECEIVED_QUEUE
|
||||||
|
import audio
|
||||||
|
|
||||||
TESTMODE = False
|
TESTMODE = False
|
||||||
RXCHANNEL = ""
|
RXCHANNEL = ""
|
||||||
|
@ -68,6 +69,7 @@ class RF:
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
|
# these are crc ids now
|
||||||
self.audio_input_device = config['AUDIO']['rx']
|
self.audio_input_device = config['AUDIO']['rx']
|
||||||
self.audio_output_device = config['AUDIO']['tx']
|
self.audio_output_device = config['AUDIO']['tx']
|
||||||
|
|
||||||
|
@ -189,11 +191,14 @@ class RF:
|
||||||
# --------------------------------------------CREATE PORTAUDIO INSTANCE
|
# --------------------------------------------CREATE PORTAUDIO INSTANCE
|
||||||
if not TESTMODE and not HamlibParam.hamlib_radiocontrol in ["tci"]:
|
if not TESTMODE and not HamlibParam.hamlib_radiocontrol in ["tci"]:
|
||||||
try:
|
try:
|
||||||
|
in_dev_index = audio.get_device_index_from_crc(self.audio_input_device, True)
|
||||||
|
out_dev_index = audio.get_device_index_from_crc(self.audio_output_device, False)
|
||||||
|
|
||||||
self.stream = sd.RawStream(
|
self.stream = sd.RawStream(
|
||||||
channels=1,
|
channels=1,
|
||||||
dtype="int16",
|
dtype="int16",
|
||||||
callback=self.callback,
|
callback=self.callback,
|
||||||
device=(self.audio_input_device, self.audio_output_device),
|
device=(in_dev_index, out_dev_index),
|
||||||
samplerate=self.AUDIO_SAMPLE_RATE_RX,
|
samplerate=self.AUDIO_SAMPLE_RATE_RX,
|
||||||
blocksize=4800,
|
blocksize=4800,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue