Merge pull request #680 from DJ2LS/dev-audio-debugging

This commit is contained in:
DJ2LS 2024-03-09 05:26:22 -08:00 committed by GitHub
commit ec6b16b672
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 31 deletions

View file

@ -27,7 +27,7 @@ class Demodulator():
'decoding_thread': None 'decoding_thread': None
} }
def __init__(self, config, audio_rx_q, modem_rx_q, data_q_rx, states, event_manager, fft_queue): def __init__(self, config, audio_rx_q, data_q_rx, states, event_manager, fft_queue):
self.log = structlog.get_logger("Demodulator") self.log = structlog.get_logger("Demodulator")
self.rx_audio_level = config['AUDIO']['rx_audio_level'] self.rx_audio_level = config['AUDIO']['rx_audio_level']
@ -38,7 +38,6 @@ class Demodulator():
self.is_codec2_traffic_cooldown = 5 self.is_codec2_traffic_cooldown = 5
self.audio_received_queue = audio_rx_q self.audio_received_queue = audio_rx_q
self.modem_received_queue = modem_rx_q
self.data_queue_received = data_q_rx self.data_queue_received = data_q_rx
self.states = states self.states = states
@ -127,6 +126,9 @@ class Demodulator():
self.MODE_DICT[mode]['decoding_thread'].start() self.MODE_DICT[mode]['decoding_thread'].start()
def sd_input_audio_callback(self, indata: np.ndarray, frames: int, time, status) -> None: def sd_input_audio_callback(self, indata: np.ndarray, frames: int, time, status) -> None:
if status:
self.log.warning("[AUDIO STATUS]", status=status)
audio_48k = np.frombuffer(indata, dtype=np.int16) audio_48k = np.frombuffer(indata, dtype=np.int16)
audio_8k = self.resampler.resample48_to_8(audio_48k) audio_8k = self.resampler.resample48_to_8(audio_48k)
@ -149,27 +151,6 @@ class Demodulator():
elif decode: elif decode:
audiobuffer.push(audio_8k_level_adjusted) audiobuffer.push(audio_8k_level_adjusted)
def worker_received(self) -> None:
"""Worker for FIFO queue for processing received frames"""
while True:
data = self.modem_received_queue.get()
self.log.debug("[MDM] worker_received: received data!")
# data[0] = bytes_out
# data[1] = freedv session
# data[2] = bytes_per_frame
# data[3] = snr
item = {
'payload': data[0],
'freedv': data[1],
'bytes_per_frame': data[2],
'snr': data[3],
'frequency_offset': self.get_frequency_offset(data[1]),
}
self.data_queue_received.put(item)
self.modem_received_queue.task_done()
def get_frequency_offset(self, freedv: ctypes.c_void_p) -> float: def get_frequency_offset(self, freedv: ctypes.c_void_p) -> float:
""" """
Ask codec2 for the calculated (audio) frequency offset of the received signal. Ask codec2 for the calculated (audio) frequency offset of the received signal.
@ -238,7 +219,16 @@ class Demodulator():
snr = self.calculate_snr(freedv) snr = self.calculate_snr(freedv)
self.get_scatter(freedv) self.get_scatter(freedv)
self.modem_received_queue.put([bytes_out, freedv, bytes_per_frame, snr]) item = {
'payload': bytes_out,
'freedv': freedv,
'bytes_per_frame': bytes_per_frame,
'snr': snr,
'frequency_offset': self.get_frequency_offset(freedv),
}
self.data_queue_received.put(item)
state_buffer = [] state_buffer = []
except Exception as e: except Exception as e:
error_message = str(e) error_message = str(e)
@ -248,6 +238,7 @@ class Demodulator():
self.log.debug( self.log.debug(
"[MDM] [demod_audio] demod loop ended", mode=mode_name, e=e "[MDM] [demod_audio] demod loop ended", mode=mode_name, e=e
) )
def tci_rx_callback(self) -> None: def tci_rx_callback(self) -> None:
""" """
Callback for TCI RX Callback for TCI RX
@ -288,6 +279,7 @@ class Demodulator():
frames_per_burst = min(frames_per_burst, 1) frames_per_burst = min(frames_per_burst, 1)
frames_per_burst = max(frames_per_burst, 5) frames_per_burst = max(frames_per_burst, 5)
# FIXME
frames_per_burst = 1 frames_per_burst = 1
codec2.api.freedv_set_frames_per_burst(self.dat0_datac1_freedv, frames_per_burst) codec2.api.freedv_set_frames_per_burst(self.dat0_datac1_freedv, frames_per_burst)

View file

@ -74,14 +74,12 @@ class RF:
# Make sure our resampler will work # Make sure our resampler will work
assert (self.AUDIO_SAMPLE_RATE / self.MODEM_SAMPLE_RATE) == codec2.api.FDMDV_OS_48 # type: ignore assert (self.AUDIO_SAMPLE_RATE / self.MODEM_SAMPLE_RATE) == codec2.api.FDMDV_OS_48 # type: ignore
self.modem_received_queue = queue.Queue()
self.audio_received_queue = queue.Queue() self.audio_received_queue = queue.Queue()
self.data_queue_received = queue.Queue() self.data_queue_received = queue.Queue()
self.fft_queue = fft_queue self.fft_queue = fft_queue
self.demodulator = demodulator.Demodulator(self.config, self.demodulator = demodulator.Demodulator(self.config,
self.audio_received_queue, self.audio_received_queue,
self.modem_received_queue,
self.data_queue_received, self.data_queue_received,
self.states, self.states,
self.event_manager, self.event_manager,
@ -405,11 +403,6 @@ class RF:
self.freedv_datac4_tx = codec2.open_instance(codec2.FREEDV_MODE.datac4.value) self.freedv_datac4_tx = codec2.open_instance(codec2.FREEDV_MODE.datac4.value)
self.freedv_datac13_tx = codec2.open_instance(codec2.FREEDV_MODE.datac13.value) self.freedv_datac13_tx = codec2.open_instance(codec2.FREEDV_MODE.datac13.value)
def init_data_threads(self):
worker_received = threading.Thread(
target=self.demodulator.worker_received, name="WORKER_THREAD", daemon=True
)
worker_received.start()
# Low level modem audio transmit # Low level modem audio transmit
def transmit_audio(self, audio_48k) -> None: def transmit_audio(self, audio_48k) -> None: