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

View File

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