mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Audio dbfs support
This commit is contained in:
parent
bf31ca5891
commit
f044b64ace
3 changed files with 10 additions and 6 deletions
|
@ -34,7 +34,10 @@ export function stateDispatcher(data) {
|
||||||
stateStore.channel_busy = data["channel_busy"];
|
stateStore.channel_busy = data["channel_busy"];
|
||||||
stateStore.is_codec2_traffic = data["is_codec2_traffic"];
|
stateStore.is_codec2_traffic = data["is_codec2_traffic"];
|
||||||
stateStore.is_modem_running = data["is_modem_running"];
|
stateStore.is_modem_running = data["is_modem_running"];
|
||||||
stateStore.dbfs_level = data["audio_dbfs"];
|
stateStore.dbfs_level = Math.round(data["audio_dbfs"]);
|
||||||
|
stateStore.dbfs_level_percent = Math.round(
|
||||||
|
Math.pow(10, data["audio_dbfs"] / 20) * 100,
|
||||||
|
);
|
||||||
stateStore.channel_busy_slot = data["channel_busy_slot"];
|
stateStore.channel_busy_slot = data["channel_busy_slot"];
|
||||||
stateStore.beacon_state = data["is_beacon_running"];
|
stateStore.beacon_state = data["is_beacon_running"];
|
||||||
stateStore.radio_status = data["radio_status"];
|
stateStore.radio_status = data["radio_status"];
|
||||||
|
|
|
@ -115,6 +115,7 @@ class RF:
|
||||||
# https://github.com/DJ2LS/FreeDATA/issues/127
|
# https://github.com/DJ2LS/FreeDATA/issues/127
|
||||||
# https://github.com/DJ2LS/FreeDATA/issues/99
|
# https://github.com/DJ2LS/FreeDATA/issues/99
|
||||||
self.mod_out_locked = True
|
self.mod_out_locked = True
|
||||||
|
self.rms_counter = 0
|
||||||
|
|
||||||
# Make sure our resampler will work
|
# Make sure our resampler will work
|
||||||
assert (self.AUDIO_SAMPLE_RATE_RX / self.MODEM_SAMPLE_RATE) == codec2.api.FDMDV_OS_48 # type: ignore
|
assert (self.AUDIO_SAMPLE_RATE_RX / self.MODEM_SAMPLE_RATE) == codec2.api.FDMDV_OS_48 # type: ignore
|
||||||
|
@ -1330,7 +1331,7 @@ class RF:
|
||||||
whether the channel is "busy."
|
whether the channel is "busy."
|
||||||
"""
|
"""
|
||||||
# Initialize dbfs counter
|
# Initialize dbfs counter
|
||||||
rms_counter = 0
|
# rms_counter = 0
|
||||||
|
|
||||||
# https://gist.github.com/ZWMiller/53232427efc5088007cab6feee7c6e4c
|
# https://gist.github.com/ZWMiller/53232427efc5088007cab6feee7c6e4c
|
||||||
# Fast Fourier Transform, 10*log10(abs) is to scale it to dB
|
# Fast Fourier Transform, 10*log10(abs) is to scale it to dB
|
||||||
|
@ -1357,8 +1358,8 @@ class RF:
|
||||||
# Calculate audio dbfs
|
# Calculate audio dbfs
|
||||||
# https://stackoverflow.com/a/9763652
|
# https://stackoverflow.com/a/9763652
|
||||||
# calculate dbfs every 50 cycles for reducing CPU load
|
# calculate dbfs every 50 cycles for reducing CPU load
|
||||||
rms_counter += 1
|
self.rms_counter += 1
|
||||||
if rms_counter > 50:
|
if self.rms_counter > 5:
|
||||||
d = np.frombuffer(data, np.int16).astype(np.float32)
|
d = np.frombuffer(data, np.int16).astype(np.float32)
|
||||||
# calculate RMS and then dBFS
|
# calculate RMS and then dBFS
|
||||||
# https://dsp.stackexchange.com/questions/8785/how-to-compute-dbfs
|
# https://dsp.stackexchange.com/questions/8785/how-to-compute-dbfs
|
||||||
|
@ -1372,8 +1373,7 @@ class RF:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.states.set("audio_dbfs", -100)
|
self.states.set("audio_dbfs", -100)
|
||||||
|
|
||||||
|
self.rms_counter = 0
|
||||||
rms_counter = 0
|
|
||||||
|
|
||||||
# Convert data to int to decrease size
|
# Convert data to int to decrease size
|
||||||
dfft = dfft.astype(int)
|
dfft = dfft.astype(int)
|
||||||
|
|
|
@ -91,6 +91,7 @@ class StateManager:
|
||||||
"radio_frequency": self.radio_frequency,
|
"radio_frequency": self.radio_frequency,
|
||||||
"radio_mode": self.radio_mode,
|
"radio_mode": self.radio_mode,
|
||||||
"channel_busy_slot": self.channel_busy_slot,
|
"channel_busy_slot": self.channel_busy_slot,
|
||||||
|
"audio_dbfs": self.audio_dbfs,
|
||||||
}
|
}
|
||||||
|
|
||||||
# .wait() blocks until the event is set
|
# .wait() blocks until the event is set
|
||||||
|
|
Loading…
Reference in a new issue