diff --git a/src/dsp/node_sampl.rs b/src/dsp/node_sampl.rs index 85a57b6..85c2342 100644 --- a/src/dsp/node_sampl.rs +++ b/src/dsp/node_sampl.rs @@ -168,13 +168,13 @@ impl Sampl { sample_slice); if declick { - let samples_to_end = sample_data.len() - sample_idx; + let samples_to_end = sample_slice.len() - sample_idx; let ramp_atten_factor = if sample_idx < ramp_sample_count { sample_idx as f64 * ramp_inc } else if samples_to_end < ramp_sample_count { - 1.0 - (samples_to_end as f64 * ramp_inc) + samples_to_end as f64 * ramp_inc } else { 1.0 }; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 51e1cf5..4903106 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -58,6 +58,27 @@ macro_rules! assert_f3tupl_eq { } } +#[macro_export] +macro_rules! assert_decimated_feq { + ($vec:expr, $decimate:expr, $cmp_vec:expr) => { + let cmp_vec = $cmp_vec; + let res : Vec = $vec.iter().step_by($decimate).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_rules! assert_rmsmima { ($rms:expr, $b:expr) => { diff --git a/tests/node_sampl.rs b/tests/node_sampl.rs index 57cae97..5252fb5 100644 --- a/tests/node_sampl.rs +++ b/tests/node_sampl.rs @@ -404,32 +404,19 @@ fn check_node_sampl_declick_offs_len() { matrix.set_param(dclick_p, SAtom::setting(1)); matrix.set_param(trig_p, (1.0).into()); matrix.set_param(offs_p, SAtom::param(0.9)); - matrix.set_param(len_p, SAtom::param(0.06)); + matrix.set_param(len_p, SAtom::param(0.08)); // trigger: run_for_ms(&mut node_exec, 7.5); let res = run_for_ms(&mut node_exec, 12.0); - println!("RMS: {:#?}", res.0); - assert!(false); - -// assert_minmax_of_rms!(rmsvec[0], (0.0, 2.0)); -// assert_minmax_of_rms!(rmsvec[1], (0.0, 1.0)); -// assert_minmax_of_rms!(rmsvec[2], (1.0, 1.0)); -// -// // reset trigger: -// matrix.set_param(trig_p, (0.0).into()); -// run_for_ms(&mut node_exec, 1000.0); -// -// matrix.set_param(dclick_p, SAtom::setting(1)); -// matrix.set_param(trig_p, (1.0).into()); -// // let the trigger appear in the sampler: -// run_for_ms(&mut node_exec, 7.5); -// // now the de-click should run: -// let rmsvec = run_and_get_each_rms_mimax(&mut node_exec, 1.0); -// -// assert_minmax_of_rms!(rmsvec[0], (0.0, 0.3105)); -// assert_minmax_of_rms!(rmsvec[1], (0.3177, 0.6282)); -// assert_minmax_of_rms!(rmsvec[2], (0.6354, 0.9460)); + assert_decimated_feq!(res.0, 15, vec![ + 0.0, 0.10832358, 0.21664716, 0.32497075, 0.43329433, 0.54161793, + 0.6499415, 0.7582651, 0.86658865, 0.9749123, + 1.0, 1.0, 1.0, 1.0, 1.0, + 0.9243612, 0.81603765, 0.7077141, 0.5993905, 0.4910669, + 0.38274333, 0.27441975, 0.16609617, 0.057772577, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); }