wrote retrigger test

This commit is contained in:
Weird Constructor 2021-06-16 05:06:50 +02:00
parent 9cc9fafc7e
commit f673792c17
4 changed files with 112 additions and 3 deletions

View file

@ -150,6 +150,7 @@ impl DspNode for Ad {
for frame in 0..ctx.nframes() { for frame in 0..ctx.nframes() {
if self.trig.check_trigger(denorm::Ad::trig(trig, frame)) { if self.trig.check_trigger(denorm::Ad::trig(trig, frame)) {
//d// println!("RETRIGGER!");
self.stage = 1; self.stage = 1;
self.last_time = -1.0; self.last_time = -1.0;
target = 1.0; target = 1.0;

View file

@ -60,7 +60,6 @@ impl DspNode for Test {
let p = at::Test::p(atoms); let p = at::Test::p(atoms);
let out = out::Test::sig(outputs); let out = out::Test::sig(outputs);
for frame in 0..ctx.nframes() { for frame in 0..ctx.nframes() {
println!("R {}", p.f());
out.write(frame, p.f()); out.write(frame, p.f());
} }
} }

View file

@ -58,6 +58,27 @@ macro_rules! assert_f3tupl_eq {
} }
} }
#[macro_export]
macro_rules! assert_vec_feq {
($vec:expr, $cmp_vec:expr) => {
let cmp_vec = $cmp_vec;
let res : Vec<f32> = $vec.iter().copied().collect();
for (i, (s, scmp)) in res.iter().zip(cmp_vec.iter()).enumerate() {
if (s - scmp).abs() > 0.0001 {
panic!(r#"
table_left: {:?}
table_right: {:?}
assertion failed: `(left[{}] == right[{}])`
left: `{:?}`,
right: `{:?}`"#, &res[i..], &(cmp_vec[i..]), i, i, s, scmp)
}
}
}
}
#[macro_export] #[macro_export]
macro_rules! assert_decimated_feq { macro_rules! assert_decimated_feq {
($vec:expr, $decimate:expr, $cmp_vec:expr) => { ($vec:expr, $decimate:expr, $cmp_vec:expr) => {
@ -79,15 +100,48 @@ assertion failed: `(left[{}] == right[{}])`
} }
} }
#[macro_export]
macro_rules! assert_slope_feq {
($vec:expr, $cmp_vec:expr) => {
let cmp_vec = $cmp_vec;
let mut res : Vec<f32> = vec![];
let mut prev = 0.0;
for (i, s) in $vec.iter().enumerate() {
let delta = *s - prev;
if i > 0 {
res.push(delta);
}
prev = *s;
}
let res : Vec<f32> = res.iter().copied().collect();
for (i, (s, scmp)) in res.iter().zip(cmp_vec.iter()).enumerate() {
if (s - scmp).abs() > 0.0001 {
panic!(r#"
table_left: {:?}
table_right: {:?}
assertion failed: `(left[{}] == right[{}])`
left: `{:?}`,
right: `{:?}`"#, &res[i..], &(cmp_vec[i..]), i, i, s, scmp)
}
}
}
}
#[macro_export] #[macro_export]
macro_rules! assert_decimated_slope_feq { macro_rules! assert_decimated_slope_feq {
($vec:expr, $decimate:expr, $cmp_vec:expr) => { ($vec:expr, $decimate:expr, $cmp_vec:expr) => {
let cmp_vec = $cmp_vec; let cmp_vec = $cmp_vec;
let mut res : Vec<f32> = vec![]; let mut res : Vec<f32> = vec![];
let mut prev = 0.0; let mut prev = 0.0;
for s in $vec.iter() { for (i, s) in $vec.iter().enumerate() {
let delta = *s - prev; let delta = *s - prev;
if i > 0 {
res.push(delta); res.push(delta);
}
prev = *s; prev = *s;
} }

View file

@ -74,4 +74,59 @@ fn check_node_ad_retrig() {
-0.0022675726, -0.0022675726,
0.0, 0.0, 0.0, 0.0 0.0, 0.0, 0.0, 0.0
]); ]);
matrix.set_param(trig_p, SAtom::param(0.0));
let res = run_for_ms(&mut node_exec, 0.1);
matrix.set_param(trig_p, SAtom::param(1.0));
let res = run_for_ms(&mut node_exec, 1.5);
assert_decimated_feq!(res.0, 2, vec![
0.0075585, 0.022675736, 0.03779289, 0.05291005, 0.068027206, 0.08314436,
0.09826152, 0.113378674, 0.12849583, 0.143613, 0.15873015,
0.1738473, 0.18896446, 0.20408161, 0.21919878, 0.23431593,
0.24943309, 0.26455024, 0.2796674, 0.29478455, 0.3099017,
0.32501888, 0.34013602, 0.3552532, 0.37037033, 0.3854875,
0.40060467, 0.4157218, 0.43083897, 0.4459561, 0.46107328,
0.47619045, 0.4913076
]);
// Reset trigger
matrix.set_param(trig_p, SAtom::param(0.0));
let res = run_for_ms(&mut node_exec, 0.1);
assert_slope_feq!(res.0, vec![0.00755; 3]);
// Retrigger attack (should do nothing)
matrix.set_param(trig_p, SAtom::param(1.0));
let res = run_for_ms(&mut node_exec, 0.1);
assert_slope_feq!(res.0, vec![0.00755; 7]);
// Wait into decay phase
matrix.set_param(trig_p, SAtom::param(0.0));
let res = run_for_ms(&mut node_exec, 1.4);
let mut v = vec![0.00755; 57];
v.append(&mut vec![0.002267, -0.002267, -0.002267]);
assert_slope_feq!(res.0, v);
// Decay some more
let res = run_for_ms(&mut node_exec, 0.8);
assert_slope_feq!(res.0, vec![-0.002267; 100]);
// Retrigger right in the decay phase
matrix.set_param(trig_p, SAtom::param(1.0));
let res = run_for_ms(&mut node_exec, 1.0);
assert_slope_feq!(res.0, vec![
// Re-attack until we are at 1.0 again
0.007558584, 0.007558584, 0.007558584, 0.0075585246, 0.007558584,
0.007558584, 0.007558584, 0.007558584, 0.007558584, 0.007558584,
0.0007558465,
// Restart decay after 1.0 was reached:
-0.002267599, -0.0022675395, -0.002267599,
-0.0022675395, -0.002267599, -0.0022675395, -0.002267599,
-0.002267599, -0.0022675395, -0.002267599, -0.0022675395,
-0.002267599, -0.0022675395, -0.002267599, -0.002267599,
-0.0022675395, -0.002267599, -0.0022675395, -0.002267599,
-0.0022675395, -0.002267599, -0.002267599, -0.0022675395,
-0.002267599, -0.0022675395, -0.002267599, -0.0022675395,
-0.002267599, -0.002267599, -0.0022675395, -0.002267599, -0.0022675395
]);
} }