From 76a0e5cb88295ae2598a44313899239b86a32b53 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Fri, 29 Jul 2022 21:10:51 +0200 Subject: [PATCH] Integration of WBlockDSP --- Cargo.toml | 5 +++-- src/lib.rs | 4 +++- src/nodes/node_conf.rs | 4 ++++ src/nodes/node_exec.rs | 23 ++++++++++++++++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9746475..2e2a5b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,8 @@ description = "Comprehensive DSP graph and synthesis library for developing a mo keywords = ["audio", "music", "real-time", "synthesis", "synthesizer", "dsp", "sound"] categories = ["multimedia::audio", "multimedia", "algorithms", "mathematics"] -#[features] -#default = [ "hexotk" ] +[features] +default = [ "wblockdsp" ] [dependencies] serde = { version = "1.0", features = ["derive"] } @@ -19,6 +19,7 @@ triple_buffer = "5.0.6" lazy_static = "1.4.0" hound = "3.4.0" num-traits = "0.2.14" +wblockdsp = { path = "../wblockdsp", optional = true } [dev-dependencies] num-complex = "0.2" diff --git a/src/lib.rs b/src/lib.rs index 5ba821d..eab30ed 100644 --- a/src/lib.rs +++ b/src/lib.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. @@ -314,6 +314,8 @@ pub mod monitor; pub mod nodes; pub mod sample_lib; pub mod scope_handle; +#[cfg(feature="wblockdsp")] +pub mod wblockdsp; mod util; pub use cell_dir::CellDir; diff --git a/src/nodes/node_conf.rs b/src/nodes/node_conf.rs index b9c8dad..36055f3 100644 --- a/src/nodes/node_conf.rs +++ b/src/nodes/node_conf.rs @@ -13,6 +13,8 @@ use crate::nodes::drop_thread::DropThread; use crate::util::AtomicFloat; use crate::SampleLibrary; use crate::ScopeHandle; +#[cfg(feature = "wblockdsp")] +use crate::wblockdsp::CodeEngine; use ringbuf::{Producer, RingBuffer}; use std::collections::HashMap; @@ -254,6 +256,8 @@ impl SharedNodeConf { graph_update_con: rb_graph_con, graph_drop_prod: rb_drop_prod, monitor_backend, + #[cfg(feature = "wblockdsp")] + code_backend: None, // TODO: FILL THIS! }, ) } diff --git a/src/nodes/node_exec.rs b/src/nodes/node_exec.rs index 699d026..dbedbfb 100644 --- a/src/nodes/node_exec.rs +++ b/src/nodes/node_exec.rs @@ -9,6 +9,8 @@ use super::{ use crate::dsp::{Node, NodeContext, NodeId, MAX_BLOCK_SIZE}; use crate::monitor::{MonitorBackend, MON_SIG_CNT}; use crate::util::{AtomicFloat, Smoother}; +#[cfg(feature = "wblockdsp")] +use crate::wblockdsp::CodeEngineBackend; use crate::log; use std::io::Write; @@ -81,6 +83,9 @@ pub(crate) struct SharedNodeExec { pub(crate) graph_drop_prod: Producer, /// For sending feedback to the frontend thread. pub(crate) monitor_backend: MonitorBackend, + /// For handing over the [crate::wblockdsp::CodeEngineBackend] + #[cfg(feature = "wblockdsp")] + pub(crate) code_backend: Option>, } /// Contains audio driver context informations. Such as the number @@ -168,25 +173,41 @@ impl Default for FeedbackBuffer { /// This is used for instance to implement the feedbackd delay nodes. pub struct NodeExecContext { pub feedback_delay_buffers: Vec, + #[cfg(feature = "wblockdsp")] + pub code_backend: Option>, } impl NodeExecContext { fn new() -> Self { let mut fbdb = vec![]; fbdb.resize_with(MAX_ALLOCATED_NODES, FeedbackBuffer::new); - Self { feedback_delay_buffers: fbdb } + Self { + feedback_delay_buffers: fbdb, + #[cfg(feature = "wblockdsp")] + code_backend: None + } } fn set_sample_rate(&mut self, srate: f32) { for b in self.feedback_delay_buffers.iter_mut() { b.set_sample_rate(srate); } + + #[cfg(feature = "wblockdsp")] + if let Some(code_backend) = self.code_backend.as_mut() { + code_backend.set_sample_rate(srate); + } } fn clear(&mut self) { for b in self.feedback_delay_buffers.iter_mut() { b.clear(); } + + #[cfg(feature = "wblockdsp")] + if let Some(code_backend) = self.code_backend.as_mut() { + code_backend.clear(); + } } }