From 89c1ffe79eb468de47fef0be61ab280a812184b0 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Sat, 30 Jul 2022 01:52:30 +0200 Subject: [PATCH] rough PoC for Code node --- src/dsp/node_code.rs | 2 ++ src/nodes/node_conf.rs | 21 +++++++++++++++++---- src/wblockdsp.rs | 21 +++++++-------------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/dsp/node_code.rs b/src/dsp/node_code.rs index f06ae5e..7b444fa 100644 --- a/src/dsp/node_code.rs +++ b/src/dsp/node_code.rs @@ -96,6 +96,7 @@ impl DspNode for Code { // let clock = inp::TSeq::clock(inputs); // let trig = inp::TSeq::trig(inputs); // let cmode = at::TSeq::cmode(atoms); + let out = out::Code::sig(outputs); #[cfg(feature = "wblockdsp")] { @@ -109,6 +110,7 @@ impl DspNode for Code { for frame in 0..ctx.nframes() { let (s1, s2, ret) = backend.process(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + out.write(frame, ret); } ctx_vals[0].set(0.0); diff --git a/src/nodes/node_conf.rs b/src/nodes/node_conf.rs index c638644..6a589f0 100644 --- a/src/nodes/node_conf.rs +++ b/src/nodes/node_conf.rs @@ -3,18 +3,18 @@ // See README.md and COPYING for details. use super::{ - FeedbackFilter, GraphMessage, NodeOp, NodeProg, MAX_ALLOCATED_NODES, MAX_AVAIL_TRACKERS, - MAX_INPUTS, MAX_SCOPES, UNUSED_MONITOR_IDX, MAX_AVAIL_CODE_ENGINES + FeedbackFilter, GraphMessage, NodeOp, NodeProg, MAX_ALLOCATED_NODES, MAX_AVAIL_CODE_ENGINES, + MAX_AVAIL_TRACKERS, MAX_INPUTS, MAX_SCOPES, UNUSED_MONITOR_IDX, }; use crate::dsp::tracker::{PatternData, Tracker}; use crate::dsp::{node_factory, Node, NodeId, NodeInfo, ParamId, SAtom}; use crate::monitor::{new_monitor_processor, MinMaxMonitorSamples, Monitor, MON_SIG_CNT}; use crate::nodes::drop_thread::DropThread; use crate::util::AtomicFloat; -use crate::SampleLibrary; -use crate::ScopeHandle; #[cfg(feature = "wblockdsp")] use crate::wblockdsp::CodeEngine; +use crate::SampleLibrary; +use crate::ScopeHandle; use ringbuf::{Producer, RingBuffer}; use std::collections::HashMap; @@ -700,6 +700,19 @@ impl NodeConfigurator { let code_idx = ni.instance(); if let Some(cod) = self.code_engines.get_mut(code_idx) { node.set_backend(cod.get_backend()); + use wblockdsp::build::*; + cod.upload(stmts(&[ + assign( + "*phase", + op_add(var("*phase"), op_mul(literal(440.0), var("israte"))), + ), + _if( + op_gt(var("*phase"), literal(1.0)), + assign("*phase", op_sub(var("*phase"), literal(1.0))), + None, + ), + var("*phase"), + ])); } } diff --git a/src/wblockdsp.rs b/src/wblockdsp.rs index fcbbaa4..b05490c 100644 --- a/src/wblockdsp.rs +++ b/src/wblockdsp.rs @@ -42,20 +42,10 @@ impl CodeEngine { let lib = get_default_library(); - Self { - lib, - dsp_ctx: DSPNodeContext::new_ref(), - update_prod, - return_cons, - } + Self { lib, dsp_ctx: DSPNodeContext::new_ref(), update_prod, return_cons } } - pub fn upload( - &mut self, - code_instance: usize, - ast: Box, - ) -> Result<(), JITCompileError> { - + pub fn upload(&mut self, ast: Box) -> Result<(), JITCompileError> { let jit = JIT::new(self.lib.clone(), self.dsp_ctx.clone()); let fun = jit.compile(ASTFun::new(ast))?; self.update_prod.push(CodeUpdateMsg::UpdateFun(fun)); @@ -97,7 +87,6 @@ impl Drop for CodeEngine { } } - pub struct CodeEngineBackend { sample_rate: f32, function: Box, @@ -106,7 +95,11 @@ pub struct CodeEngineBackend { } impl CodeEngineBackend { - fn new(function: Box, update_cons: Consumer, return_prod: Producer) -> Self { + fn new( + function: Box, + update_cons: Consumer, + return_prod: Producer, + ) -> Self { Self { sample_rate: 0.0, function, update_cons, return_prod } }