From 78446e659e6c8af5ad76afd463b062137efa2901 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Wed, 27 Jul 2022 05:52:54 +0200 Subject: [PATCH] Pass through offs and gain for the scope --- src/dsp/node_scope.rs | 20 ++++++++++++++++---- src/scope_handle.rs | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/dsp/node_scope.rs b/src/dsp/node_scope.rs index ea6bce1..8d30b1c 100644 --- a/src/dsp/node_scope.rs +++ b/src/dsp/node_scope.rs @@ -129,9 +129,21 @@ impl DspNode for Scope { let thrsh = inp::Scope::thrsh(inputs); let trig = inp::Scope::trig(inputs); let tsrc = at::Scope::tsrc(atoms); - let inputs = [in1, in2, in3]; + let input_bufs = [in1, in2, in3]; self.handle.set_active_from_mask(nctx.in_connected); + self.handle.set_offs_gain( + 0, + denorm::Scope::off1(inp::Scope::off1(inputs), 0), + denorm::Scope::gain1(inp::Scope::gain1(inputs), 0)); + self.handle.set_offs_gain( + 1, + denorm::Scope::off2(inp::Scope::off2(inputs), 0), + denorm::Scope::gain2(inp::Scope::gain2(inputs), 0)); + self.handle.set_offs_gain( + 2, + denorm::Scope::off3(inp::Scope::off3(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 samples_per_block = (time * self.srate_ms) / SCOPE_SAMPLES as f32; @@ -150,7 +162,7 @@ impl DspNode for Scope { for frame in 0..ctx.nframes() { if self.idx < SCOPE_SAMPLES { - for (i, input) in inputs.iter().enumerate() { + for (i, input) in input_bufs.iter().enumerate() { let in_val = input.read(frame); self.handle.write_oversampled(i, self.idx, copy_count, in_val); } @@ -174,14 +186,14 @@ impl DspNode for Scope { for frame in 0..ctx.nframes() { if self.idx < SCOPE_SAMPLES { - for (i, input) in inputs.iter().enumerate() { + for (i, input) in input_bufs.iter().enumerate() { let in_val = input.read(frame); cur_mm[i].0 = cur_mm[i].0.max(in_val); cur_mm[i].1 = cur_mm[i].1.min(in_val); } if self.frame_time >= time_per_block { - for i in 0..inputs.len() { + for i in 0..input_bufs.len() { self.handle.write(i, self.idx, cur_mm[i]); } *cur_mm = [(-99999.0, 99999.0); 3]; diff --git a/src/scope_handle.rs b/src/scope_handle.rs index 6c1e99a..41ee1f2 100644 --- a/src/scope_handle.rs +++ b/src/scope_handle.rs @@ -11,6 +11,7 @@ use std::sync::Arc; pub struct ScopeHandle { bufs: [Vec; 3], active: [AtomicBool; 3], + offs_gain: [AtomicFloatPair; 3], } impl ScopeHandle { @@ -24,6 +25,11 @@ impl ScopeHandle { Arc::new(Self { bufs: [v1, v2, v3], active: [AtomicBool::new(false), AtomicBool::new(false), AtomicBool::new(false)], + offs_gain: [ + AtomicFloatPair::default(), + AtomicFloatPair::default(), + AtomicFloatPair::default(), + ], }) } @@ -34,6 +40,14 @@ impl ScopeHandle { } } + pub fn set_offs_gain(&self, buf_idx: usize, offs: f32, gain: f32) { + self.offs_gain[buf_idx % 3].set((offs, gain)); + } + + pub fn get_offs_gain(&self, buf_idx: usize) -> (f32, f32) { + self.offs_gain[buf_idx % 3].get() + } + pub fn write(&self, buf_idx: usize, idx: usize, v: (f32, f32)) { self.bufs[buf_idx % 3][idx % SCOPE_SAMPLES].set(v); }