rough PoC for Code node

This commit is contained in:
Weird Constructor 2022-07-30 01:52:30 +02:00
parent 4fc1dc75fd
commit 89c1ffe79e
3 changed files with 26 additions and 18 deletions

View file

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

View file

@ -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"),
]));
}
}

View file

@ -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<ASTNode>,
) -> Result<(), JITCompileError> {
pub fn upload(&mut self, ast: Box<ASTNode>) -> 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<DSPFunction>,
@ -106,7 +95,11 @@ pub struct CodeEngineBackend {
}
impl CodeEngineBackend {
fn new(function: Box<DSPFunction>, update_cons: Consumer<CodeUpdateMsg>, return_prod: Producer<CodeReturnMsg>) -> Self {
fn new(
function: Box<DSPFunction>,
update_cons: Consumer<CodeUpdateMsg>,
return_prod: Producer<CodeReturnMsg>,
) -> Self {
Self { sample_rate: 0.0, function, update_cons, return_prod }
}