From c5a96c6fc112a0b224dbafa4f17fd43b66385415 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F." Date: Sat, 2 Nov 2024 00:45:56 +0100 Subject: [PATCH] Implemented only storage of signal range in PPM struct as well --- src/rt/ppm.rs | 22 ++++++++++------------ src/rt/simpleclip.rs | 8 +++----- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/rt/ppm.rs b/src/rt/ppm.rs index f4af49f..cff9aa4 100644 --- a/src/rt/ppm.rs +++ b/src/rt/ppm.rs @@ -13,7 +13,7 @@ use std::time::{Duration, Instant}; /// When the level reaches ALMOST_CLIPPED_REL_AMP in amplitude, w.r.t. to the /// full scale, we mark a channel as almost clipped. -const ALMOST_CLIPPED_REL_AMP: Flt = 0.98; +pub const ALMOST_CLIPPED_REL_AMP: Flt = 0.98; /// If clipping occured, this is the time it keeps saying 'signal is clipped' const CLIP_INDICATOR_WAIT_S: Duration = Duration::from_secs(2); @@ -66,7 +66,7 @@ impl PPM { rayon::spawn(move || { let mut slms: Vec = vec![]; - let mut streammeta: Option> = None; + let mut ranges: Vec<(Flt, Flt)> = vec![]; let resetall = |slms: &mut Vec| { let mut status = status.lock(); @@ -82,13 +82,11 @@ impl PPM { InStreamMsg::InStreamData(d) => { let mut status = status.lock(); let floatdata = d.getFloatData(); - let meta = streammeta.as_ref().expect("Stream metadata not available"); - let channels = &meta.channelInfo; - 'channel: for (chno, ((slm, ppmstatus), ch)) in slms + 'channel: for (chno, ((slm, ppmstatus), range)) in slms .iter_mut() .zip(status.iter_mut()) - .zip(channels) + .zip(ranges.iter()) .enumerate() { let chdata = floatdata.slice(s![.., chno]); @@ -116,13 +114,13 @@ impl PPM { continue 'channel; } - let clip = min_val <= ALMOST_CLIPPED_REL_AMP * ch.range.0 - || max_val >= ALMOST_CLIPPED_REL_AMP * ch.range.1; + let clip = min_val <= ALMOST_CLIPPED_REL_AMP * range.0 + || max_val >= ALMOST_CLIPPED_REL_AMP * range.1; - let abs_range = if ch.range.0.abs() > ch.range.1.abs() { - ch.range.0.abs() + let abs_range = if range.0.abs() > range.1.abs() { + range.0.abs() } else { - ch.range.1.abs() + range.1.abs() }; let high_level_threshold = level(abs_range) + LEVEL_THRESHOLD_FOR_HIGH_LEVEL; @@ -175,7 +173,7 @@ impl PPM { clip_time: None, }); }); - streammeta = Some(meta); + ranges = meta.channelInfo.iter().map(|ch| ch.range).collect(); } InStreamMsg::StreamStopped => {} } diff --git a/src/rt/simpleclip.rs b/src/rt/simpleclip.rs index cc3db2a..fae6ed5 100644 --- a/src/rt/simpleclip.rs +++ b/src/rt/simpleclip.rs @@ -13,9 +13,7 @@ use std::{ time::Duration, }; -/// If signal is below / above the range times the value below, we indicate that -/// the signal has clipped. -const CLIP_REL_LIMIT: Flt = 0.99; +use super::ppm::ALMOST_CLIPPED_REL_AMP; /// Very simple clip detector. Used to detect cliping in a recording. Stores one /// clip value if just something happened between time of new and moment of drop(). @@ -70,8 +68,8 @@ impl SimpleClipDetector { // Compare minima and maxima against clip limits maxs.iter().zip(mins.iter()).zip(ranges.iter()).for_each( |((max, min), range)| { - let min_for_clip = CLIP_REL_LIMIT * range.0; - let max_for_clip = CLIP_REL_LIMIT * range.1; + let min_for_clip = ALMOST_CLIPPED_REL_AMP * range.0; + let max_for_clip = ALMOST_CLIPPED_REL_AMP * range.1; if *max >= max_for_clip { clipstate.store(true, Relaxed); // We do not have to do anything anymore. The signal