Added some derive debugs. Added some comments. Changed default high level threshold to -10 dBFS

This commit is contained in:
Anne de Jong 2024-10-03 20:18:55 +02:00
parent 89677a8320
commit 94e478d372
2 changed files with 19 additions and 15 deletions

View File

@ -23,7 +23,7 @@ const CLIP_INDICATOR_WAIT_S: Duration = Duration::from_secs(4);
const LEVEL_THRESHOLD_FOR_LOW_LEVEL: Flt = -50.; const LEVEL_THRESHOLD_FOR_LOW_LEVEL: Flt = -50.;
/// If the signal level falls below this value, we indicate that the signal level is low. /// If the signal level falls below this value, we indicate that the signal level is low.
const LEVEL_THRESHOLD_FOR_HIGH_LEVEL: Flt = -5.; const LEVEL_THRESHOLD_FOR_HIGH_LEVEL: Flt = -10.;
type SharedPPMStatus = Arc<Mutex<Vec<PPMChannelStatus>>>; type SharedPPMStatus = Arc<Mutex<Vec<PPMChannelStatus>>>;
@ -39,26 +39,28 @@ pub struct PPM {
impl PPM { impl PPM {
/// Initialize a new PPM meter. /// Initialize a new PPM meter.
///
/// Args
///
/// - `mgr`: Stream manager instance.
pub fn new(mgr: &mut StreamMgr) -> Self { pub fn new(mgr: &mut StreamMgr) -> Self {
let (sender, rxmsg) = unbounded(); let (sender, rxmsg) = unbounded();
let (tx, rxstream) = unbounded();
// Add queue sender part of queue to stream manager
mgr.addInQueue(tx);
// Shared status object // Shared status object
let status: SharedPPMStatus = Arc::new(Mutex::new(vec![])); let status: SharedPPMStatus = Arc::new(Mutex::new(vec![]));
// Start the thread that calculates PPM and clip values // Start the thread that calculates PPM and clip values
Self::startThread(status.clone(), rxstream, rxmsg); Self::startThread(status.clone(), mgr, rxmsg);
PPM { status, sender } PPM { status, sender }
} }
fn startThread( fn startThread(status: SharedPPMStatus, mgr: &mut StreamMgr, rxmsg: Receiver<PPMMessage>) {
status: SharedPPMStatus, // Obtain messages from stream manager
rxstream: Receiver<InStreamMsg>, let (tx, rxstream) = unbounded();
rxmsg: Receiver<PPMMessage>,
) { // Add queue sender part of queue to stream manager
mgr.addInQueue(tx);
rayon::spawn(move || { rayon::spawn(move || {
let mut slms: Vec<SLM> = vec![]; let mut slms: Vec<SLM> = vec![];
@ -108,7 +110,7 @@ impl PPM {
} else if last_level > LEVEL_THRESHOLD_FOR_HIGH_LEVEL { } else if last_level > LEVEL_THRESHOLD_FOR_HIGH_LEVEL {
ClipState::HighLevel ClipState::HighLevel
} else if last_level < LEVEL_THRESHOLD_FOR_LOW_LEVEL { } else if last_level < LEVEL_THRESHOLD_FOR_LOW_LEVEL {
ClipState::LowLevels ClipState::LowLevel
} else { } else {
ClipState::LevelFine ClipState::LevelFine
} }
@ -144,7 +146,7 @@ impl PPM {
// Initialize levels at -300 dB, and clip state // Initialize levels at -300 dB, and clip state
// at low levels // at low levels
s.push(PPMChannelStatus { s.push(PPMChannelStatus {
clip: ClipState::LowLevels, clip: ClipState::LowLevel,
level: -300., level: -300.,
clip_time: None, clip_time: None,
}); });
@ -158,7 +160,7 @@ impl PPM {
// Loop over any messages coming in from main thread // Loop over any messages coming in from main thread
for msg in rxmsg.try_iter() { for msg in rxmsg.try_iter() {
match msg { match msg {
PPMMessage::ResetClip {} => { PPMMessage::ResetClip => {
// Reset clip state to not clipped. // Reset clip state to not clipped.
let mut s = status.lock(); let mut s = status.lock();
s.iter_mut().for_each(|c| c.clip = ClipState::LevelFine); s.iter_mut().for_each(|c| c.clip = ClipState::LevelFine);
@ -201,7 +203,7 @@ impl Drop for PPM {
pub enum ClipState { pub enum ClipState {
/// Level is rather low /// Level is rather low
#[default] #[default]
LowLevels, LowLevel,
/// Default state, fine levels /// Default state, fine levels
LevelFine, LevelFine,
/// High levels: warning! /// High levels: warning!

View File

@ -1,4 +1,5 @@
use std::ops::Deref; use std::ops::Deref;
use crate::config::*;
use std::thread::{self, JoinHandle}; use std::thread::{self, JoinHandle};
use crate::daq::{InStreamMsg, StreamHandler, StreamMetaData, StreamMgr}; use crate::daq::{InStreamMsg, StreamHandler, StreamMetaData, StreamMgr};
@ -10,6 +11,7 @@ use parking_lot::Mutex;
use rayon::ThreadPool; use rayon::ThreadPool;
use std::sync::Arc; use std::sync::Arc;
#[derive(Debug)]
enum RtApsComm { enum RtApsComm {
CommStopThread, CommStopThread,
NewResult(CPSResult), NewResult(CPSResult),