Implemented only storage of signal range in PPM struct as well

This commit is contained in:
Anne de Jong 2024-11-02 00:45:56 +01:00
parent 26515b9ee0
commit c5a96c6fc1
2 changed files with 13 additions and 17 deletions

View File

@ -13,7 +13,7 @@ use std::time::{Duration, Instant};
/// When the level reaches ALMOST_CLIPPED_REL_AMP in amplitude, w.r.t. to the /// When the level reaches ALMOST_CLIPPED_REL_AMP in amplitude, w.r.t. to the
/// full scale, we mark a channel as almost clipped. /// 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' /// If clipping occured, this is the time it keeps saying 'signal is clipped'
const CLIP_INDICATOR_WAIT_S: Duration = Duration::from_secs(2); const CLIP_INDICATOR_WAIT_S: Duration = Duration::from_secs(2);
@ -66,7 +66,7 @@ impl PPM {
rayon::spawn(move || { rayon::spawn(move || {
let mut slms: Vec<SLM> = vec![]; let mut slms: Vec<SLM> = vec![];
let mut streammeta: Option<Arc<StreamMetaData>> = None; let mut ranges: Vec<(Flt, Flt)> = vec![];
let resetall = |slms: &mut Vec<SLM>| { let resetall = |slms: &mut Vec<SLM>| {
let mut status = status.lock(); let mut status = status.lock();
@ -82,13 +82,11 @@ impl PPM {
InStreamMsg::InStreamData(d) => { InStreamMsg::InStreamData(d) => {
let mut status = status.lock(); let mut status = status.lock();
let floatdata = d.getFloatData(); 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() .iter_mut()
.zip(status.iter_mut()) .zip(status.iter_mut())
.zip(channels) .zip(ranges.iter())
.enumerate() .enumerate()
{ {
let chdata = floatdata.slice(s![.., chno]); let chdata = floatdata.slice(s![.., chno]);
@ -116,13 +114,13 @@ impl PPM {
continue 'channel; continue 'channel;
} }
let clip = min_val <= ALMOST_CLIPPED_REL_AMP * ch.range.0 let clip = min_val <= ALMOST_CLIPPED_REL_AMP * range.0
|| max_val >= ALMOST_CLIPPED_REL_AMP * ch.range.1; || max_val >= ALMOST_CLIPPED_REL_AMP * range.1;
let abs_range = if ch.range.0.abs() > ch.range.1.abs() { let abs_range = if range.0.abs() > range.1.abs() {
ch.range.0.abs() range.0.abs()
} else { } else {
ch.range.1.abs() range.1.abs()
}; };
let high_level_threshold = let high_level_threshold =
level(abs_range) + LEVEL_THRESHOLD_FOR_HIGH_LEVEL; level(abs_range) + LEVEL_THRESHOLD_FOR_HIGH_LEVEL;
@ -175,7 +173,7 @@ impl PPM {
clip_time: None, clip_time: None,
}); });
}); });
streammeta = Some(meta); ranges = meta.channelInfo.iter().map(|ch| ch.range).collect();
} }
InStreamMsg::StreamStopped => {} InStreamMsg::StreamStopped => {}
} }

View File

@ -13,9 +13,7 @@ use std::{
time::Duration, time::Duration,
}; };
/// If signal is below / above the range times the value below, we indicate that use super::ppm::ALMOST_CLIPPED_REL_AMP;
/// the signal has clipped.
const CLIP_REL_LIMIT: Flt = 0.99;
/// Very simple clip detector. Used to detect cliping in a recording. Stores one /// 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(). /// 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 // Compare minima and maxima against clip limits
maxs.iter().zip(mins.iter()).zip(ranges.iter()).for_each( maxs.iter().zip(mins.iter()).zip(ranges.iter()).for_each(
|((max, min), range)| { |((max, min), range)| {
let min_for_clip = CLIP_REL_LIMIT * range.0; let min_for_clip = ALMOST_CLIPPED_REL_AMP * range.0;
let max_for_clip = CLIP_REL_LIMIT * range.1; let max_for_clip = ALMOST_CLIPPED_REL_AMP * range.1;
if *max >= max_for_clip { if *max >= max_for_clip {
clipstate.store(true, Relaxed); clipstate.store(true, Relaxed);
// We do not have to do anything anymore. The signal // We do not have to do anything anymore. The signal