Compare commits
No commits in common. "26515b9ee015bc700ef911c50f8ba9bb15ccee8f" and "36de394a2ef69c071a1a181cf7ba2470f472ce53" have entirely different histories.
26515b9ee0
...
36de394a2e
@ -43,43 +43,41 @@ impl SimpleClipDetector {
|
|||||||
smgr.addInQueue(tx);
|
smgr.addInQueue(tx);
|
||||||
rayon::spawn(
|
rayon::spawn(
|
||||||
move || {
|
move || {
|
||||||
let mut mins = vec![];
|
let mut streammeta: Option<Arc<StreamMetaData>> = None;
|
||||||
let mut maxs = vec![];
|
|
||||||
let mut ranges = vec![];
|
|
||||||
loop {
|
loop {
|
||||||
if let Ok(msg) = rx.recv_timeout(Duration::from_millis(1500)) {
|
if let Ok(msg) = rx.recv_timeout(Duration::from_millis(1500)) {
|
||||||
match msg {
|
match msg {
|
||||||
InStreamMsg::StreamStarted(meta) => {
|
InStreamMsg::StreamStarted(meta) => {
|
||||||
mins.resize(meta.nchannels(), 0.);
|
streammeta = Some(meta);
|
||||||
maxs.resize(meta.nchannels(), 0.);
|
|
||||||
ranges = meta.channelInfo.iter().map(|ch| ch.range).collect();
|
|
||||||
}
|
}
|
||||||
InStreamMsg::InStreamData(dat) => {
|
InStreamMsg::InStreamData(dat) => {
|
||||||
|
let meta = streammeta
|
||||||
|
.as_ref()
|
||||||
|
.expect("If we are here, stream metadata should be available");
|
||||||
let flt = dat.getFloatData();
|
let flt = dat.getFloatData();
|
||||||
// Update channel maximum values
|
let maxs = flt
|
||||||
flt.columns()
|
.columns()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(maxs.iter_mut())
|
.map(|col| max(col))
|
||||||
.for_each(|(coli, maxi)| *maxi = max(coli));
|
.collect::<Vec<_>>();
|
||||||
// Update channel minimum values
|
let mins = flt
|
||||||
flt.columns()
|
.columns()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(mins.iter_mut())
|
.map(|col| min(col))
|
||||||
.for_each(|(coli, mini)| *mini = min(coli));
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
// Compare minima and maxima against clip limits
|
maxs.into_iter().zip(mins).zip(&meta.channelInfo).for_each(
|
||||||
maxs.iter().zip(mins.iter()).zip(ranges.iter()).for_each(
|
|((max, min), ch)| {
|
||||||
|((max, min), range)| {
|
let min_for_clip = CLIP_REL_LIMIT * ch.range.0;
|
||||||
let min_for_clip = CLIP_REL_LIMIT * range.0;
|
let max_for_clip = CLIP_REL_LIMIT * ch.range.1;
|
||||||
let max_for_clip = CLIP_REL_LIMIT * 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
|
||||||
// has clipped so we do not have to check any new
|
// has clipped so we do not have to check any new
|
||||||
// blocks anymore.
|
// blocks anymore.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if *min <= min_for_clip {
|
if min <= min_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
|
||||||
// has clipped so we do not have to check any new
|
// has clipped so we do not have to check any new
|
||||||
|
Loading…
Reference in New Issue
Block a user