From 2a0ea2014fbe8aa4a746f83770f716477b76f628 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Sun, 6 Jun 2021 11:14:50 +0200 Subject: [PATCH] finished tests for sine and sampl detune --- src/matrix.rs | 14 +++--- src/matrix_repr.rs | 2 +- tests/basics.rs | 12 ++--- tests/common/mod.rs | 8 ++-- tests/node_sampl.rs | 91 ++++++++++++++++++++++++++++++++------ tests/sample_sin.wav | Bin 242 -> 244 bytes tests/sample_sin_long.wav | Bin 0 -> 3050 bytes 7 files changed, 95 insertions(+), 32 deletions(-) create mode 100644 tests/sample_sin_long.wav diff --git a/src/matrix.rs b/src/matrix.rs index e64d071..f9924af 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -1015,9 +1015,9 @@ mod tests { assert!(nodes[2].to_id(2) == NodeId::Sin(2)); let prog = node_exec.get_prog(); - assert_eq!(prog.prog[0].to_string(), "Op(i=0 out=(0-1) in=(0-1) at=(0-0))"); - assert_eq!(prog.prog[1].to_string(), "Op(i=1 out=(1-2) in=(1-2) at=(0-0) cpy=(o0 => i1))"); - assert_eq!(prog.prog[2].to_string(), "Op(i=2 out=(2-3) in=(2-3) at=(0-0) cpy=(o1 => i2))"); + assert_eq!(prog.prog[0].to_string(), "Op(i=0 out=(0-1) in=(0-2) at=(0-0))"); + assert_eq!(prog.prog[1].to_string(), "Op(i=1 out=(1-2) in=(2-4) at=(0-0) cpy=(o0 => i2))"); + assert_eq!(prog.prog[2].to_string(), "Op(i=2 out=(2-3) in=(4-6) at=(0-0) cpy=(o1 => i4))"); } #[test] @@ -1070,8 +1070,8 @@ mod tests { let prog = node_exec.get_prog(); assert_eq!(prog.prog.len(), 2); - assert_eq!(prog.prog[0].to_string(), "Op(i=0 out=(0-1) in=(0-1) at=(0-0))"); - assert_eq!(prog.prog[1].to_string(), "Op(i=1 out=(1-1) in=(1-3) at=(0-1) cpy=(o0 => i1))"); + assert_eq!(prog.prog[0].to_string(), "Op(i=0 out=(0-1) in=(0-2) at=(0-0))"); + assert_eq!(prog.prog[1].to_string(), "Op(i=1 out=(1-1) in=(2-4) at=(0-1) cpy=(o0 => i2))"); } #[test] @@ -1101,8 +1101,8 @@ mod tests { let prog = node_exec.get_prog(); assert_eq!(prog.prog.len(), 2); - assert_eq!(prog.prog[0].to_string(), "Op(i=2 out=(2-3) in=(2-3) at=(0-0))"); - assert_eq!(prog.prog[1].to_string(), "Op(i=3 out=(3-3) in=(3-5) at=(0-1) cpy=(o2 => i3))"); + assert_eq!(prog.prog[0].to_string(), "Op(i=2 out=(2-3) in=(4-6) at=(0-0))"); + assert_eq!(prog.prog[1].to_string(), "Op(i=3 out=(3-3) in=(6-8) at=(0-1) cpy=(o2 => i6))"); } #[test] diff --git a/src/matrix_repr.rs b/src/matrix_repr.rs index 10e04c6..4df414b 100644 --- a/src/matrix_repr.rs +++ b/src/matrix_repr.rs @@ -469,7 +469,7 @@ mod tests { let s = mr.serialize(); assert_eq!(s, - "{\"VERSION\":1,\"atoms\":[[\"out\",0,\"mono\",[\"i\",0]]],\"cells\":[[\"sin\",2,0,0,[-1,-1,-1],[-1,0,-1]],[\"out\",0,1,0,[-1,0,-1],[-1,-1,0]]],\"params\":[[\"out\",0,\"ch1\",0.0],[\"out\",0,\"ch2\",0.0],[\"sin\",0,\"freq\",0.0],[\"sin\",1,\"freq\",0.0],[\"sin\",2,\"freq\",-0.10000000149011612]],\"patterns\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]}"); + "{\"VERSION\":1,\"atoms\":[[\"out\",0,\"mono\",[\"i\",0]]],\"cells\":[[\"sin\",2,0,0,[-1,-1,-1],[-1,0,-1]],[\"out\",0,1,0,[-1,0,-1],[-1,-1,0]]],\"params\":[[\"out\",0,\"ch1\",0.0],[\"out\",0,\"ch2\",0.0],[\"sin\",0,\"det\",0.0],[\"sin\",1,\"det\",0.0],[\"sin\",2,\"det\",0.0],[\"sin\",0,\"freq\",0.0],[\"sin\",1,\"freq\",0.0],[\"sin\",2,\"freq\",-0.10000000149011612]],\"patterns\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]}"); let mut mr2 = MatrixRepr::deserialize(&s).unwrap(); diff --git a/tests/basics.rs b/tests/basics.rs index 277172b..4303321 100644 --- a/tests/basics.rs +++ b/tests/basics.rs @@ -165,17 +165,17 @@ fn check_sine_freq_detune() { run_no_input(&mut node_exec, 50.0); - let cfreq = run_and_get_counted_freq(&mut node_exec, 100.0); + let cfreq = run_and_get_counted_freq(&mut node_exec, 1000.0); assert_float_eq!(cfreq.floor(), 440.0); matrix.set_param(freq_param, SAtom::param(freq_param.norm(4400.0))); run_no_input(&mut node_exec, 50.0); - let cfreq = run_and_get_counted_freq(&mut node_exec, 1000.0); + let cfreq = run_and_get_counted_freq(&mut node_exec, 2000.0); assert_float_eq!(cfreq.floor(), 4400.0); matrix.set_param(freq_param, SAtom::param(freq_param.norm(50.0))); run_no_input(&mut node_exec, 50.0); - let cfreq = run_and_get_counted_freq(&mut node_exec, 100.0); + let cfreq = run_and_get_counted_freq(&mut node_exec, 1000.0); assert_float_eq!(cfreq.floor(), 50.0); matrix.set_param(freq_param, SAtom::param(freq_param.norm(440.0))); @@ -186,17 +186,17 @@ fn check_sine_freq_detune() { matrix.set_param(det_param, SAtom::param(det_param.norm(1.0))); run_no_input(&mut node_exec, 50.0); - let cfreq = run_and_get_counted_freq(&mut node_exec, 250.0); + let cfreq = run_and_get_counted_freq(&mut node_exec, 1000.0); assert_float_eq!(cfreq.floor(), 466.0); matrix.set_param(det_param, SAtom::param(det_param.norm(-1.0))); run_no_input(&mut node_exec, 50.0); - let cfreq = run_and_get_counted_freq(&mut node_exec, 300.0); + let cfreq = run_and_get_counted_freq(&mut node_exec, 2000.0); assert_float_eq!(cfreq.floor(), 415.0); matrix.set_param(det_param, SAtom::param(det_param.norm(-14.0))); run_no_input(&mut node_exec, 50.0); - let cfreq = run_and_get_counted_freq(&mut node_exec, 400.0); + let cfreq = run_and_get_counted_freq(&mut node_exec, 1000.0); assert_float_eq!(cfreq.floor(), 196.0); } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 939f281..e673552 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -216,17 +216,17 @@ pub fn run_and_get_counted_freq( let mut last_val = 0.0; for s in out_l.iter() { - if last_val > 0.0 && *s < 0.0 { + if last_val >= 0.0 && *s < 0.0 { zero_trans += 1; - } else if last_val < 0.0 && *s > 0.0 { + } else if last_val <= 0.0 && *s > 0.0 { zero_trans += 1; } last_val = *s; } - //d// println!("SAMPLES: {}", out_l.len()); - //d// println!("ZERO TRANS: {}", zero_trans); + println!("SAMPLES: {}", out_l.len()); + println!("ZERO TRANS: {}", zero_trans); let trans_per_sample = // substract the extra samples applied earlier. diff --git a/tests/node_sampl.rs b/tests/node_sampl.rs index f0932e2..9baa1bb 100644 --- a/tests/node_sampl.rs +++ b/tests/node_sampl.rs @@ -19,38 +19,65 @@ fn check_node_sampl_1() { matrix.set_param(sample_p, SAtom::audio_unloaded("tests/sample_sin.wav")); let (rms, min, max) = run_and_get_l_rms_mimax(&mut node_exec, 50.0); - assert_rmsmima!((rms, min, max), (0.505, -0.9998, 1.0)); + assert_rmsmima!((rms, min, max), (0.5004, -0.9997, 0.9997)); let fft = run_and_get_fft4096(&mut node_exec, 800, 20.0); - assert_eq!(fft[0], (441, 940)); + assert_eq!(fft[0], (441, 1023)); matrix.set_param(freq_p, SAtom::param(0.1)); let fft = run_and_get_fft4096(&mut node_exec, 800, 20.0); - assert_eq!(fft[0], (894, 988)); + assert_eq!(fft[0], (883, 1020)); matrix.set_param(freq_p, SAtom::param(-0.1)); let fft = run_and_get_fft4096(&mut node_exec, 800, 20.0); - assert_eq!(fft[0], (226, 966)); + assert_eq!(fft[0], (215, 881)); matrix.set_param(freq_p, SAtom::param(-0.2)); let fft = run_and_get_fft4096(&mut node_exec, 800, 20.0); - assert_eq!(fft[0], (108, 953)); + assert_eq!(fft[0], (108, 987)); matrix.set_param(freq_p, SAtom::param(-0.4)); let fft = run_and_get_fft4096(&mut node_exec, 800, 20.0); - assert_eq!(fft[0], (22, 818)); + assert_eq!(fft[0], (22, 831)); matrix.set_param(freq_p, SAtom::param(-0.5)); let fft = run_and_get_fft4096(&mut node_exec, 800, 20.0); - assert_eq!(fft[0], (11, 964)); + assert_eq!(fft[0], (11, 1000)); matrix.set_param(freq_p, SAtom::param(0.2)); let fft = run_and_get_fft4096(&mut node_exec, 800, 20.0); - assert_eq!(fft[0], (1776, 877)); + assert_eq!(fft[0], (1766, 1008)); matrix.set_param(freq_p, SAtom::param(0.4)); let fft = run_and_get_fft4096(&mut node_exec, 800, 20.0); - assert_eq!(fft[0], (7127, 1029)); + assert_eq!(fft[0], (7052, 942)); +} + +#[test] +fn check_node_sampl_long_freq() { + let (node_conf, mut node_exec) = new_node_engine(); + let mut matrix = Matrix::new(node_conf, 3, 3); + + let smpl = NodeId::Sampl(0); + let out = NodeId::Out(0); + matrix.place(0, 0, Cell::empty(smpl) + .out(None, None, smpl.out("sig"))); + matrix.place(0, 1, Cell::empty(out) + .input(out.inp("ch1"), None, None)); + matrix.sync().unwrap(); + + let sample_p = smpl.inp_param("sample").unwrap(); + let freq_p = smpl.inp_param("freq").unwrap(); + matrix.set_param(sample_p, SAtom::audio_unloaded("tests/sample_sin_long.wav")); + + let (out_l, _) = run_no_input(&mut node_exec, 0.05); + + let fft = run_and_get_fft4096(&mut node_exec, 800, 100.0); + assert_eq!(fft[0], (441, 1014)); + + let cfreq = run_and_get_counted_freq(&mut node_exec, 4000.0); + // The slight wrong tune might be from the limited number of samples? + assert_float_eq!(cfreq.floor(), 440.0); } #[test] @@ -71,8 +98,45 @@ fn check_node_sampl_detune() { let det_p = smpl.inp_param("det").unwrap(); matrix.set_param(sample_p, SAtom::audio_unloaded("tests/sample_sin.wav")); + run_no_input(&mut node_exec, 0.05); + let cfreq = run_and_get_counted_freq(&mut node_exec, 1000.0); - assert_float_eq!(cfreq, 1.0); + // The slight wrong tune comes from the very very short sample of a sine wave! + // See also the check_node_sampl_long_freq() test above! + assert_float_eq!(cfreq.floor(), 441.0); + + matrix.set_param(det_p, SAtom::param(det_p.norm(1.0))); + run_no_input(&mut node_exec, 0.05); + let cfreq = run_and_get_counted_freq(&mut node_exec, 2000.0); + assert_float_eq!(cfreq.floor(), 467.0); + + matrix.set_param(det_p, SAtom::param(det_p.norm(-1.0))); + run_no_input(&mut node_exec, 0.05); + let cfreq = run_and_get_counted_freq(&mut node_exec, 1000.0); + assert_float_eq!(cfreq.floor(), 417.0); + + matrix.set_param(det_p, SAtom::param(det_p.norm(-12.0))); + run_no_input(&mut node_exec, 0.05); + let cfreq = run_and_get_counted_freq(&mut node_exec, 1200.0); + assert_float_eq!(cfreq.floor(), 220.0); + + matrix.set_param(det_p, SAtom::param(det_p.norm(-24.0))); + run_no_input(&mut node_exec, 0.05); + let cfreq = run_and_get_counted_freq(&mut node_exec, 1200.0); + assert_float_eq!(cfreq.floor(), 110.0); + + matrix.set_param(det_p, SAtom::param(det_p.norm(24.0))); + run_no_input(&mut node_exec, 0.05); + let cfreq = run_and_get_counted_freq(&mut node_exec, 1000.0); + assert_float_eq!(cfreq.floor(), 1764.0); + + matrix.set_param(det_p, SAtom::param(det_p.norm(36.0))); + run_no_input(&mut node_exec, 0.05); + let cfreq = run_and_get_counted_freq(&mut node_exec, 1000.0); + assert_float_eq!(cfreq.floor(), 3529.0); + + //d// let (out_l, _) = run_no_input(&mut node_exec, 1.0); + //d// save_wav("check_node_sampl_detune.wav", &out_l); } #[test] @@ -103,12 +167,11 @@ fn check_node_sampl_reload() { hexodsp::load_patch_from_file( &mut matrix, "check_matrix_serialize.hxy").unwrap(); - let rmsmima = run_and_get_l_rms_mimax(&mut node_exec, 50.0); - assert_rmsmima!(rmsmima, (0.505, -0.9998, 1.0)); + assert_rmsmima!(rmsmima, (0.5004, -0.9998, 0.9997)); let fft = run_and_get_fft4096(&mut node_exec, 800, 20.0); - assert_eq!(fft[0], (441, 940)); + assert_eq!(fft[0], (441, 1023)); } } @@ -161,7 +224,7 @@ fn check_node_sampl_trigger() { matrix.set_param(trig_p, (1.0).into()); let rmsmima = run_and_get_first_rms_mimax(&mut node_exec, 10.0); - assert_rmsmima!(rmsmima, (0.1136, -0.9998, 1.0)); + assert_rmsmima!(rmsmima, (0.1136, -0.9997, 0.9997)); let rmsmima = run_and_get_l_rms_mimax(&mut node_exec, 20.0); assert_rmsmima!(rmsmima, (0.0, 0.0, 0.0)); diff --git a/tests/sample_sin.wav b/tests/sample_sin.wav index af5f62d2a979b1786d04ea0598284c80965f3351..a67fae6341c970fd46bb5e93e3051e6d515f6338 100644 GIT binary patch delta 219 zcmV<103`qN0rUX{Qb|Te?2!c{f5-p;0EGjD3x5+{8!98qDn&AkIh8l6=)4?1!MhW^=R#d<+6`|;x z7MHq`y^cPMFNm0hfP>$G#egAz3V>*UPJyq2kA&@p!if@%(U1g{o|&Yc2c*iW;;&4$ V{=D|XDa(=4DB9uSzv-*-vH3=hYjOYp delta 217 zcmV;~04D$R0rCL_Qb|Te>X8K_f5rd+000032m=u87sDTSCj>8GHi|uNL>WtLQFm7% zU3g+)XXCQ9giQAjF)Ddo1s3ZD6Mw0 T1iIkB`^QSp&(?b0N#-!_>|A9X diff --git a/tests/sample_sin_long.wav b/tests/sample_sin_long.wav new file mode 100644 index 0000000000000000000000000000000000000000..afb62cb8a8bffa846c228e158695daf59d0338b9 GIT binary patch literal 3050 zcmV3jhEB z00amD5bhVlA9W`NFJLx@J#<79OK(wjS0Y_^Vqs_NYXNYsbKrKIdE$GdeeZs@fBt{P ze++-oeH?t_c{q0sbailKZ0=_WW5!(_SR_)=OE^VRJ~cPoFI6a{Ak!G>5bOx-0O9!T z@bl;-;bqy_(Q(Q}!&bbewMnlvsePj%o+p`{ILiye<0laH5ToS~sNr!K8=vk1E0!2HKa&(PL+-b>~#?kx5!{xk+K4kQ-* z9l9k@Ex9!AJLE!}NdizIR^D4nVM}K0Y94Rkaxr!Yd1-q}eXf3$fB1jhe?osFeu{i> zdfs=?bWm|xZTn~~WC34nS%_0dO}$3zKi4>nF%K$bBAyzy62A()0=4?N^26%p;wRgP z(;m#<#O1vrx3{p2s>Y;EpF*0Gl~|F6jVg*nhu4JXf^>m>fDV8cfT@7AfkA^#h0ll8 zib9Spl7W^$n`ofvrOd1Rv4yxuzgxzd%@){;|%{9puO3|1639Qq@jD-API zI#WR$NRv*-RF+yAU@m3rX)$gQa(Z=cc&PfE$1dfO~*#f!l)3gfxd3igS%Uk$;sS znl+!Eq;IN^u>ZEay|~2h%VX2@+P>nE>W=b-`j7&R3X2kN8aN{6DP1wLIKMxaMk7sO zQ&3snUKC{AXhdx}alUlUcVT*gd>ei~f7*Zgf0%!>epP*Qdl-2{cJgvJZv$&=W@BLl zTs>APP{2tJLlivbGU6xmoQ9VnR zM6*4LHZL!uC+{B{7%vbr2rmFA_%QH1=x*S&*eB7<$(_QuyAHLuuB)j3qNbg@m@SkR zkY|iBiF1Z1gk^#kflYt}fHr{gfFpw1gARtah~bNMkAjo>m)D#iqP(ZQtq8QEx`V-^ z$oJ2K*DT)x=jiU|_UQiZ2I>ym7PKB~CIBvEHIY1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