From 4fc1dc75fd87845489568749af039a83f187f9cd Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Sat, 30 Jul 2022 00:26:01 +0200 Subject: [PATCH] working on the wblockdsp integration, found some weird bug in wblockdsp though... --- src/dsp/node_code.rs | 31 ++++++++++++++++++++----------- src/nodes/node_conf.rs | 9 +++++++++ src/wblockdsp.rs | 4 ++-- tests/node_ad.rs | 2 +- tests/wblockdsp.rs | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 tests/wblockdsp.rs diff --git a/src/dsp/node_code.rs b/src/dsp/node_code.rs index 0f00176..f06ae5e 100644 --- a/src/dsp/node_code.rs +++ b/src/dsp/node_code.rs @@ -4,12 +4,14 @@ use crate::dsp::{DspNode, LedPhaseVals, NodeContext, NodeId, ProcBuf, SAtom}; use crate::nodes::{NodeAudioContext, NodeExecContext}; +#[cfg(feature = "wblockdsp")] use crate::wblockdsp::CodeEngineBackend; use crate::dsp::MAX_BLOCK_SIZE; /// A WBlockDSP code execution node for JIT'ed DSP code pub struct Code { + #[cfg(feature = "wblockdsp")] backend: Option>, srate: f64, } @@ -29,11 +31,13 @@ impl Clone for Code { impl Code { pub fn new(_nid: &NodeId) -> Self { Self { + #[cfg(feature = "wblockdsp")] backend: None, srate: 48000.0, } } + #[cfg(feature = "wblockdsp")] pub fn set_backend(&mut self, backend: CodeEngineBackend) { self.backend = Some(Box::new(backend)); } @@ -64,12 +68,14 @@ impl DspNode for Code { fn set_sample_rate(&mut self, srate: f32) { self.srate = srate as f64; + #[cfg(feature = "wblockdsp")] if let Some(backend) = self.backend.as_mut() { backend.set_sample_rate(srate); } } fn reset(&mut self) { + #[cfg(feature = "wblockdsp")] if let Some(backend) = self.backend.as_mut() { backend.clear(); } @@ -91,19 +97,22 @@ impl DspNode for Code { // let trig = inp::TSeq::trig(inputs); // let cmode = at::TSeq::cmode(atoms); - let backend = if let Some(backend) = &mut self.backend { - backend - } else { - return; - }; + #[cfg(feature = "wblockdsp")] + { + let backend = if let Some(backend) = &mut self.backend { + backend + } else { + return; + }; - backend.process_updates(); + backend.process_updates(); - for frame in 0..ctx.nframes() { - let (s1, s2, ret) = backend.process(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + for frame in 0..ctx.nframes() { + let (s1, s2, ret) = backend.process(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + } + + ctx_vals[0].set(0.0); + ctx_vals[1].set(0.0); } - - ctx_vals[0].set(0.0); - ctx_vals[1].set(0.0); } } diff --git a/src/nodes/node_conf.rs b/src/nodes/node_conf.rs index bc4b3d0..c638644 100644 --- a/src/nodes/node_conf.rs +++ b/src/nodes/node_conf.rs @@ -290,6 +290,7 @@ impl NodeConfigurator { atom_values: std::collections::HashMap::new(), node2idx: HashMap::new(), trackers: vec![Tracker::new(); MAX_AVAIL_TRACKERS], + #[cfg(feature = "wblockdsp")] code_engines: vec![CodeEngine::new(); MAX_AVAIL_CODE_ENGINES], scopes, }, @@ -694,6 +695,14 @@ impl NodeConfigurator { } } + #[cfg(feature = "wblockdsp")] + if let Node::Code { node } = &mut node { + let code_idx = ni.instance(); + if let Some(cod) = self.code_engines.get_mut(code_idx) { + node.set_backend(cod.get_backend()); + } + } + if let Node::Scope { node } = &mut node { if let Some(handle) = self.scopes.get(ni.instance()) { node.set_scope_handle(handle.clone()); diff --git a/src/wblockdsp.rs b/src/wblockdsp.rs index 115be8a..fcbbaa4 100644 --- a/src/wblockdsp.rs +++ b/src/wblockdsp.rs @@ -36,9 +36,9 @@ impl Clone for CodeEngine { impl CodeEngine { pub fn new() -> Self { let rb = RingBuffer::new(MAX_RINGBUF_SIZE); - let (update_prod, update_cons) = rb.split(); + let (update_prod, _update_cons) = rb.split(); let rb = RingBuffer::new(MAX_RINGBUF_SIZE); - let (return_prod, return_cons) = rb.split(); + let (_return_prod, return_cons) = rb.split(); let lib = get_default_library(); diff --git a/tests/node_ad.rs b/tests/node_ad.rs index 59dfccf..c5d5c6f 100644 --- a/tests/node_ad.rs +++ b/tests/node_ad.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Weird Constructor +// Copyright (c) 2021-2022 Weird Constructor // This file is a part of HexoDSP. Released under GPL-3.0-or-later. // See README.md and COPYING for details. diff --git a/tests/wblockdsp.rs b/tests/wblockdsp.rs new file mode 100644 index 0000000..8eb7129 --- /dev/null +++ b/tests/wblockdsp.rs @@ -0,0 +1,38 @@ +// Copyright (c) 2022 Weird Constructor +// This file is a part of HexoDSP. Released under GPL-3.0-or-later. +// See README.md and COPYING for details. + +mod common; +use common::*; +use hexodsp::wblockdsp::*; + +#[test] +fn check_wblockdsp_init() { + let mut engine = CodeEngine::new(); + + let backend = engine.get_backend(); +} + +#[test] +fn check_wblockdsp_code_node() { + let (node_conf, mut node_exec) = new_node_engine(); + let mut matrix = Matrix::new(node_conf, 3, 3); + + let mut chain = MatrixCellChain::new(CellDir::B); + chain + .node_out("code", "sig") + .node_io("code", "in1", "sig") + .node_inp("out", "ch1") + .place(&mut matrix, 0, 0) + .unwrap(); + matrix.sync().unwrap(); + + let mut chain = MatrixCellChain::new(CellDir::B); + chain + .node_out("code", "sig") + .node_io("code", "in1", "sig") + .node_inp("out", "ch1") + .place(&mut matrix, 0, 0) + .unwrap(); + matrix.sync().unwrap(); +}