another attempt with rms

This commit is contained in:
dj2ls 2022-10-12 11:32:09 +02:00
parent b41430fc43
commit 7d2168a0e7
2 changed files with 12 additions and 5 deletions

View file

@ -746,11 +746,11 @@
<div class="card-body p-2">
<div class="progress mb-0" style="height: 15px;">
<div class="progress-bar progress-bar-striped bg-primary" id="rms_level" role="progressbar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
<p class="justify-content-center d-flex position-absolute w-100">RX AUDIO LEVEL - not implemented yet</p>
<p class="justify-content-center d-flex position-absolute w-100">RX AUDIO LEVEL</p>
</div>
<div class="progress mb-0" style="height: 5px;">
<div class="progress-bar progress-bar-striped bg-warning" role="progressbar" style="width: 10%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar bg-success" role="progressbar" style="width: 80%" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar progress-bar-striped bg-warning" role="progressbar" style="width: 1%" aria-valuenow="1" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar bg-success" role="progressbar" style="width: 89%" aria-valuenow="89" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar progress-bar-striped bg-danger" role="progressbar" style="width: 10%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>

View file

@ -843,6 +843,9 @@ class RF:
# Initialize channel_busy_delay counter
channel_busy_delay = 0
# Initialize rms counter
rms_counter = 0
while True:
# time.sleep(0.01)
threading.Event().wait(0.01)
@ -874,8 +877,12 @@ class RF:
# Calculate audio RMS
# https://stackoverflow.com/a/9763652
d = np.frombuffer(self.fft_data, np.int16).astype(np.float)
static.AUDIO_RMS = int(np.sqrt((d * d).sum() / len(d)))
# calculate RMS every 150 cycles for reducing CPU load
rms_counter += 1
if rms_counter > 150:
d = np.frombuffer(self.fft_data, np.int16).astype(np.float)
static.AUDIO_RMS = int(np.sqrt((d * d).sum() / len(d)))
rms_counter = 0
# Check for signals higher than average by checking for "100"
# If we have a signal, increment our channel_busy delay counter