working on the wblockdsp integration, found some weird bug in wblockdsp though...

This commit is contained in:
Weird Constructor 2022-07-30 00:26:01 +02:00
parent 70f369af70
commit 4fc1dc75fd
5 changed files with 70 additions and 14 deletions

View file

@ -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<Box<CodeEngineBackend>>,
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);
}
}

View file

@ -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());

View file

@ -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();

View file

@ -1,4 +1,4 @@
// Copyright (c) 2021 Weird Constructor <weirdconstructor@gmail.com>
// Copyright (c) 2021-2022 Weird Constructor <weirdconstructor@gmail.com>
// This file is a part of HexoDSP. Released under GPL-3.0-or-later.
// See README.md and COPYING for details.

38
tests/wblockdsp.rs Normal file
View file

@ -0,0 +1,38 @@
// Copyright (c) 2022 Weird Constructor <weirdconstructor@gmail.com>
// 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();
}