diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 647a202..30d3eb4 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -611,6 +611,10 @@ pub fn fft(buf: &mut [f32], size: FFT, amp_thres: u32) -> Vec<(u16, u32)> { for (i, amp) in amplitudes.iter().enumerate() { if *amp >= amp_thres { let freq = (i as f32 * SAMPLE_RATE) / len as f32; + if freq > 22050.0 { + // no freqency images above nyquist... + continue; + } // println!("{:6.0} {}", freq, *amp); res.push((freq.round() as u16, *amp)); } diff --git a/tests/node_bosc.rs b/tests/node_bosc.rs new file mode 100644 index 0000000..af51fa8 --- /dev/null +++ b/tests/node_bosc.rs @@ -0,0 +1,88 @@ +mod common; +use common::*; + +#[test] +fn check_node_bosc_1() { + let (node_conf, mut node_exec) = new_node_engine(); + let mut matrix = Matrix::new(node_conf, 4, 4); + + let bosc = NodeId::BOsc(0); + let out = NodeId::Out(0); + matrix.place(0, 0, Cell::empty(bosc) + .out(None, None, bosc.out("sig"))); + matrix.place(0, 1, Cell::empty(out) + .input(out.inp("ch1"), None, None) + .out(None, None, None)); + pset_s(&mut matrix, bosc, "wtype", 0); // Sine + pset_d(&mut matrix, bosc, "freq", 220.0); + matrix.sync().unwrap(); + + run_for_ms(&mut node_exec, 10.0); + let fft = run_and_get_fft4096_now(&mut node_exec, 20); + assert_eq!(fft[0].0, 194); + assert_eq!(fft[1].0, 205); + assert_eq!(fft[2].0, 215); + assert_eq!(fft[3].0, 226); + assert_eq!(fft[4].0, 237); + assert_eq!(fft[5].0, 248); + + pset_s(&mut matrix, bosc, "wtype", 1); // Triangle + let fft = run_and_get_fft4096_now(&mut node_exec, 20); + assert_eq!(fft[0].0, 194); + assert_eq!(fft[1].0, 205); + assert_eq!(fft[2].0, 215); + assert_eq!(fft[3].0, 226); + assert_eq!(fft[4].0, 237); + assert_eq!(fft[5].0, 646); + assert_eq!(fft[6].0, 657); + assert_eq!(fft[7].0, 668); + assert_eq!(fft[8].0, 1098); + assert_eq!(fft[9].0, 1109); + + pset_s(&mut matrix, bosc, "wtype", 2); // Saw + let fft = run_and_get_fft4096_now(&mut node_exec, 120); + assert_eq!(fft[0].0, 205); + assert_eq!(fft[1].0, 215); + assert_eq!(fft[2].0, 226); + assert_eq!(fft[3].0, 431); + assert_eq!(fft[4].0, 441); + assert_eq!(fft[5].0, 452); + assert_eq!(fft[6].0, 657); + assert_eq!(fft[7].0, 668); + assert_eq!(fft[8].0, 883); + assert_eq!(fft[9].0, 1098); + + pset_s(&mut matrix, bosc, "wtype", 3); // Pulse + pset_n(&mut matrix, bosc, "pw", 0.0); // Pulse width no mod + run_for_ms(&mut node_exec, 10.0); + let fft = run_and_get_fft4096_now(&mut node_exec, 120); + assert_eq!(fft[0].0, 205); + assert_eq!(fft[1].0, 215); + assert_eq!(fft[2].0, 226); + assert_eq!(fft[3].0, 237); + assert_eq!(fft[4].0, 646); + assert_eq!(fft[5].0, 657); + assert_eq!(fft[6].0, 668); + assert_eq!(fft[7].0, 1098); + assert_eq!(fft[8].0, 1109); + assert_eq!(fft[9].0, 1540); + assert_eq!(fft[10].0, 1981); + + pset_n(&mut matrix, bosc, "pw", 1.0); // Pulse width no mod + run_for_ms(&mut node_exec, 10.0); + let fft = run_and_get_fft4096_now(&mut node_exec, 120); + assert_eq!(fft[0].0, 215); + assert_eq!(fft[1].0, 226); + assert_eq!(fft[2].0, 431); + assert_eq!(fft[3].0, 441); + assert_eq!(fft[4].0, 452); + assert_eq!(fft[5].0, 657); + assert_eq!(fft[6].0, 668); + assert_eq!(fft[7].0, 872); + assert_eq!(fft[8].0, 883); + assert_eq!(fft[9].0, 1098); + assert_eq!(fft[10].0, 1109); + assert_eq!(fft[11].0, 1314); + assert_eq!(fft[12].0, 1324); + assert_eq!(fft[13].0, 1540); +}