finished tests for sine and sampl detune

This commit is contained in:
Weird Constructor 2021-06-06 11:14:50 +02:00
parent 1ceb25bf31
commit 2a0ea2014f
7 changed files with 95 additions and 32 deletions

View file

@ -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]

View file

@ -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();

View file

@ -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);
}

View file

@ -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.

View file

@ -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));

Binary file not shown.

BIN
tests/sample_sin_long.wav Normal file

Binary file not shown.