Fix the top reflection in the RndWk max

This commit is contained in:
Weird Constructor 2021-08-14 00:39:46 +02:00
parent 488192fd81
commit a9ac7ec1e8
2 changed files with 16 additions and 7 deletions

View file

@ -128,11 +128,19 @@ impl DspNode for RndWk {
let step = denorm::RndWk::step(step, frame).clamp(-1.0, 1.0); let step = denorm::RndWk::step(step, frame).clamp(-1.0, 1.0);
let offs = denorm::RndWk::offs(offs, frame).clamp(-1.0, 1.0); let offs = denorm::RndWk::offs(offs, frame).clamp(-1.0, 1.0);
let target = let mut target =
self.slew_val.value() as f32 self.slew_val.value() as f32
+ ((self.rng.next() * 2.0 * step) - step) + ((self.rng.next() * 2.0 * step) - step)
+ offs; + offs;
self.target = (((target - min) % delta).abs() + min) as f64;
// println!("{:8.6} {:8.6} {:8.6}", min, max, target);
// clamp target into a range we can reflect
target = target.clamp(min - (delta * 0.99), max + (delta * 0.99));
// reflect back the overshoots:
if target > max { target = max - (max - target).abs(); }
if target < min { target = min + (min - target).abs(); }
self.target = target as f64;
} }
let slew_time_ms = denorm::RndWk::slew(slew, frame); let slew_time_ms = denorm::RndWk::slew(slew, frame);

View file

@ -152,14 +152,15 @@ fn check_node_rndwk_max() {
pset_n(&mut matrix, rwk, "trig", 1.0); pset_n(&mut matrix, rwk, "trig", 1.0);
run_for_ms(&mut node_exec, 7.0); // wait for trigger... run_for_ms(&mut node_exec, 7.0); // wait for trigger...
let (out_l, _) = run_for_ms(&mut node_exec, 20.0); let (out_l, _) = run_for_ms(&mut node_exec, 50.0);
assert_decimated_feq!(out_l, 60, vec![ assert_decimated_feq!(out_l, 200, vec![
0.0, // start value 0.0, // start value
// slew ramp: // slew ramp:
0.011791383, 0.029931974, 0.04807256, 0.06621315, 0.054119427, 0.11458806, 0.1750567, 0.23552532, 0.29599395,
0.3564626, 0.4169312,
// end value // end value
// which is 0.5 - 0.56891763 // which is (0.5 - 0.43108237) == 0.06891763
0.06891763, 0.06891763, 0.43108237, 0.43108237, 0.43108237, 0.43108237
]); ]);
} }