Re-implemented simpleclip, debugged
This commit is contained in:
parent
f58c6f8839
commit
36de394a2e
@ -5,7 +5,7 @@ use crate::math::max;
|
||||
use crate::math::maxabs;
|
||||
use crate::math::min;
|
||||
use crate::Flt;
|
||||
use crossbeam::channel::bounded;
|
||||
use crossbeam::channel::unbounded;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::atomic::Ordering::Relaxed;
|
||||
use std::{
|
||||
@ -15,7 +15,7 @@ use std::{
|
||||
|
||||
/// If signal is below / above the range times the value below, we indicate that
|
||||
/// the signal has clipped.
|
||||
const CLIP_REL_LIMIT: Flt = 0.999;
|
||||
const CLIP_REL_LIMIT: Flt = 0.99;
|
||||
|
||||
/// 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().
|
||||
@ -32,7 +32,7 @@ impl SimpleClipDetector {
|
||||
///
|
||||
/// - `smgr` - see [StreamMgr]
|
||||
pub fn new(smgr: &mut StreamMgr) -> Self {
|
||||
let (tx, rx) = bounded(0);
|
||||
let (tx, rx) = unbounded();
|
||||
|
||||
let clipstate = Arc::new(AtomicBool::new(false));
|
||||
let stopThread = Arc::new(AtomicBool::new(false));
|
||||
@ -41,12 +41,18 @@ impl SimpleClipDetector {
|
||||
let stopThread2 = stopThread.clone();
|
||||
|
||||
smgr.addInQueue(tx);
|
||||
rayon::spawn(move || loop {
|
||||
rayon::spawn(
|
||||
move || {
|
||||
let mut streammeta: Option<Arc<StreamMetaData>> = None;
|
||||
loop {
|
||||
if let Ok(msg) = rx.recv_timeout(Duration::from_millis(1500)) {
|
||||
match msg {
|
||||
InStreamMsg::StreamStarted(meta) => {
|
||||
streammeta = Some(meta);
|
||||
}
|
||||
InStreamMsg::InStreamData(dat) => {
|
||||
let meta = streammeta
|
||||
.as_ref()
|
||||
.expect("If we are here, stream metadata should be available");
|
||||
let flt = dat.getFloatData();
|
||||
let maxs = flt
|
||||
@ -60,39 +66,37 @@ impl SimpleClipDetector {
|
||||
.map(|col| min(col))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut clip = false;
|
||||
|
||||
maxs.into_iter().zip(mins).zip(&meta.channelInfo).for_each(
|
||||
|((max, min), ch)| {
|
||||
let min_for_clip = CLIP_REL_LIMIT * ch.range.0;
|
||||
let max_for_clip = CLIP_REL_LIMIT * ch.range.1;
|
||||
if max >= max_for_clip {
|
||||
clip = true;
|
||||
}
|
||||
if min <= min_for_clip {
|
||||
clip = true;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if clip {
|
||||
clipstate.store(true, Relaxed);
|
||||
// We do not have to do anything anymore. The signal
|
||||
// has clipped so we do not have to check any new
|
||||
// blocks anymore.
|
||||
return;
|
||||
}
|
||||
if min <= min_for_clip {
|
||||
clipstate.store(true, Relaxed);
|
||||
// We do not have to do anything anymore. The signal
|
||||
// has clipped so we do not have to check any new
|
||||
// blocks anymore.
|
||||
return;
|
||||
}
|
||||
InStreamMsg::StreamStarted(meta) => {
|
||||
streammeta = Some(meta);
|
||||
},
|
||||
);
|
||||
}
|
||||
// Ignore other stream messages
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
} // end match msg
|
||||
}; // end if let Ok(msg)
|
||||
if stopThread.load(Relaxed) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
} // end of loop
|
||||
}, // End of rayon closure
|
||||
);
|
||||
|
||||
Self {
|
||||
clipped: clipstate2,
|
||||
|
Loading…
Reference in New Issue
Block a user