Repaired first scope test

This commit is contained in:
Weird Constructor 2022-07-27 06:59:58 +02:00
parent cacd417c6d
commit 366903bee5
2 changed files with 55 additions and 33 deletions

View file

@ -405,12 +405,28 @@ pub fn pset_n(matrix: &mut Matrix, nid: NodeId, parm: &str, v_norm: f32) {
matrix.set_param(p, SAtom::param(v_norm)); matrix.set_param(p, SAtom::param(v_norm));
} }
#[allow(unused)]
pub fn node_pset_n(matrix: &mut Matrix, node: &str, instance: usize, parm: &str, v_norm: f32) {
let nid = NodeId::from_str(node).to_instance(instance);
assert!(nid != NodeId::Nop);
let p = nid.inp_param(parm).unwrap();
matrix.set_param(p, SAtom::param(v_norm));
}
#[allow(unused)] #[allow(unused)]
pub fn pset_d(matrix: &mut Matrix, nid: NodeId, parm: &str, v_denorm: f32) { pub fn pset_d(matrix: &mut Matrix, nid: NodeId, parm: &str, v_denorm: f32) {
let p = nid.inp_param(parm).unwrap(); let p = nid.inp_param(parm).unwrap();
matrix.set_param(p, SAtom::param(p.norm(v_denorm))); matrix.set_param(p, SAtom::param(p.norm(v_denorm)));
} }
#[allow(unused)]
pub fn node_pset_d(matrix: &mut Matrix, node: &str, instance: usize, parm: &str, v_denorm: f32) {
let nid = NodeId::from_str(node).to_instance(instance);
assert!(nid != NodeId::Nop);
let p = nid.inp_param(parm).unwrap();
matrix.set_param(p, SAtom::param(p.norm(v_denorm)));
}
#[allow(unused)] #[allow(unused)]
pub fn pset_n_wait( pub fn pset_n_wait(
matrix: &mut Matrix, matrix: &mut Matrix,

View file

@ -7,41 +7,47 @@ use common::*;
use hexodsp::nodes::SCOPE_SAMPLES; use hexodsp::nodes::SCOPE_SAMPLES;
fn read_scope_buf(matrix: &Matrix, sig_idx: usize) -> (Vec<f32>, Vec<f32>, f32, f32) {
let handle = matrix.get_scope_handle(0).unwrap();
let mut min = vec![];
let mut max = vec![];
let mut total_min: f32 = 99999.9;
let mut total_max: f32 = -99999.9;
for i in 0..SCOPE_SAMPLES {
let (mi, ma) = handle.read(sig_idx, i);
min.push(mi);
max.push(ma);
total_min = total_min.min(mi);
total_max = total_max.max(ma);
}
(min, max, total_min, total_max)
}
#[test] #[test]
fn check_node_scope_1() { fn check_node_scope_inputs() {
for (sig_idx, inp_name) in ["in1", "in2", "in3"].iter().enumerate() {
let (node_conf, mut node_exec) = new_node_engine(); let (node_conf, mut node_exec) = new_node_engine();
let mut matrix = Matrix::new(node_conf, 3, 3); let mut matrix = Matrix::new(node_conf, 3, 3);
let mut chain = MatrixCellChain::new(CellDir::B); let mut chain = MatrixCellChain::new(CellDir::B);
chain.node_inp("scope", "in1").place(&mut matrix, 0, 0).unwrap(); chain
.node_out("amp", "sig")
.node_inp("scope", inp_name)
.set_denorm("time", (1000.0 / 44100.0) * (SCOPE_SAMPLES as f32))
.place(&mut matrix, 0, 0)
.unwrap();
matrix.sync().unwrap(); matrix.sync().unwrap();
let scope = NodeId::Scope(0); node_pset_d(&mut matrix, "amp", 0, "inp", 1.0);
let in1_p = scope.inp_param("in1").unwrap();
let in2_p = scope.inp_param("in2").unwrap();
let in3_p = scope.inp_param("in3").unwrap();
matrix.set_param(in1_p, SAtom::param(1.0));
matrix.set_param(in2_p, SAtom::param(1.0));
matrix.set_param(in3_p, SAtom::param(1.0));
let _res = run_for_ms(&mut node_exec, 11.0); let _res = run_for_ms(&mut node_exec, 11.0);
let scope = matrix.get_scope_handle(0).unwrap(); let (minv, maxv, min, max) = read_scope_buf(&matrix, sig_idx);
let mut v = vec![]; assert_decimated_feq!(minv, 80, vec![0.0022, 0.1836, 0.3650, 0.5464, 0.7278, 0.9093, 1.0]);
for x in 0..SCOPE_SAMPLES { assert_decimated_feq!(maxv, 80, vec![0.0022, 0.1836, 0.3650, 0.5464, 0.7278, 0.9093, 1.0]);
v.push(scope.read(0, x)); assert_float_eq!(min, 0.0);
assert_float_eq!(max, 1.0);
} }
assert_decimated_feq!(v, 80, vec![0.0022, 0.1836, 0.3650, 0.5464, 0.7278, 0.9093, 1.0]);
let mut v = vec![];
for x in 0..SCOPE_SAMPLES {
v.push(scope.read(1, x));
}
assert_decimated_feq!(v, 80, vec![0.0022, 0.1836, 0.3650, 0.5464, 0.7278, 0.9093, 1.0]);
let mut v = vec![];
for x in 0..SCOPE_SAMPLES {
v.push(scope.read(2, x));
}
assert_decimated_feq!(v, 80, vec![0.0022, 0.1836, 0.3650, 0.5464, 0.7278, 0.9093, 1.0]);
} }