Added threshold to ScopeHandle

This commit is contained in:
Weird Constructor 2022-07-27 06:02:06 +02:00
parent c1f09e33f7
commit 5bfe9e8c97
2 changed files with 28 additions and 4 deletions

View file

@ -135,15 +135,18 @@ impl DspNode for Scope {
self.handle.set_offs_gain( self.handle.set_offs_gain(
0, 0,
denorm::Scope::off1(inp::Scope::off1(inputs), 0), denorm::Scope::off1(inp::Scope::off1(inputs), 0),
denorm::Scope::gain1(inp::Scope::gain1(inputs), 0)); denorm::Scope::gain1(inp::Scope::gain1(inputs), 0),
);
self.handle.set_offs_gain( self.handle.set_offs_gain(
1, 1,
denorm::Scope::off2(inp::Scope::off2(inputs), 0), denorm::Scope::off2(inp::Scope::off2(inputs), 0),
denorm::Scope::gain2(inp::Scope::gain2(inputs), 0)); denorm::Scope::gain2(inp::Scope::gain2(inputs), 0),
);
self.handle.set_offs_gain( self.handle.set_offs_gain(
2, 2,
denorm::Scope::off3(inp::Scope::off3(inputs), 0), denorm::Scope::off3(inp::Scope::off3(inputs), 0),
denorm::Scope::gain3(inp::Scope::gain3(inputs), 0)); denorm::Scope::gain3(inp::Scope::gain3(inputs), 0),
);
let time = denorm::Scope::time(time, 0).clamp(0.1, 1000.0 * 300.0); let time = denorm::Scope::time(time, 0).clamp(0.1, 1000.0 * 300.0);
let samples_per_block = (time * self.srate_ms) / SCOPE_SAMPLES as f32; let samples_per_block = (time * self.srate_ms) / SCOPE_SAMPLES as f32;
@ -156,6 +159,8 @@ impl DspNode for Scope {
let trigger_input = if tsrc.i() == 2 { trig } else { in1 }; let trigger_input = if tsrc.i() == 2 { trig } else { in1 };
let trigger_disabled = tsrc.i() == 0; let trigger_disabled = tsrc.i() == 0;
self.handle.set_threshold(if trigger_disabled { None } else { Some(threshold) });
//d// println!("TIME time={}; st={}; tpb={}; frame_time={}", time, sample_time, time_per_block, self.frame_time); //d// println!("TIME time={}; st={}; tpb={}; frame_time={}", time, sample_time, time_per_block, self.frame_time);
if samples_per_block < 1.0 { if samples_per_block < 1.0 {
let copy_count = ((1.0 / samples_per_block) as usize).min(SCOPE_SAMPLES); let copy_count = ((1.0 / samples_per_block) as usize).min(SCOPE_SAMPLES);

View file

@ -3,7 +3,7 @@
// See README.md and COPYING for details. // See README.md and COPYING for details.
use crate::nodes::SCOPE_SAMPLES; use crate::nodes::SCOPE_SAMPLES;
use crate::util::AtomicFloatPair; use crate::util::{AtomicFloatPair, AtomicFloat};
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc; use std::sync::Arc;
@ -12,6 +12,7 @@ pub struct ScopeHandle {
bufs: [Vec<AtomicFloatPair>; 3], bufs: [Vec<AtomicFloatPair>; 3],
active: [AtomicBool; 3], active: [AtomicBool; 3],
offs_gain: [AtomicFloatPair; 3], offs_gain: [AtomicFloatPair; 3],
threshold: (AtomicBool, AtomicFloat),
} }
impl ScopeHandle { impl ScopeHandle {
@ -30,6 +31,7 @@ impl ScopeHandle {
AtomicFloatPair::default(), AtomicFloatPair::default(),
AtomicFloatPair::default(), AtomicFloatPair::default(),
], ],
threshold: (AtomicBool::new(false), AtomicFloat::default()),
}) })
} }
@ -48,6 +50,23 @@ impl ScopeHandle {
self.offs_gain[buf_idx % 3].get() self.offs_gain[buf_idx % 3].get()
} }
pub fn set_threshold(&self, thresh: Option<f32>) {
if let Some(t) = thresh {
self.threshold.1.set(t);
self.threshold.0.store(true, Ordering::Relaxed);
} else {
self.threshold.0.store(false, Ordering::Relaxed);
}
}
pub fn get_threshold(&self) -> Option<f32> {
if self.threshold.0.load(Ordering::Relaxed) {
Some(self.threshold.1.get())
} else {
None
}
}
pub fn write(&self, buf_idx: usize, idx: usize, v: (f32, f32)) { pub fn write(&self, buf_idx: usize, idx: usize, v: (f32, f32)) {
self.bufs[buf_idx % 3][idx % SCOPE_SAMPLES].set(v); self.bufs[buf_idx % 3][idx % SCOPE_SAMPLES].set(v);
} }