Added test for the Comb node
This commit is contained in:
parent
ec88b9821c
commit
fc4d4b418a
2 changed files with 77 additions and 0 deletions
|
@ -531,6 +531,33 @@ pub fn run_and_get_fft4096_now(
|
||||||
fft_thres_at_ms(&mut out_l[..], FFT::F4096, thres, 0.0)
|
fft_thres_at_ms(&mut out_l[..], FFT::F4096, thres, 0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Takes about 1 second of audio to average 10 ffts
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn run_and_get_avg_fft4096_now(
|
||||||
|
node_exec: &mut hexodsp::nodes::NodeExecutor,
|
||||||
|
thres: u32) -> Vec<(u16, u32)>
|
||||||
|
{
|
||||||
|
let min_samples_for_fft = 4096.0 * 1.5; // 1.5 for some extra margin
|
||||||
|
let run_len_s = min_samples_for_fft / SAMPLE_RATE;
|
||||||
|
|
||||||
|
let (mut out_l, _out_r) = run_no_input(node_exec, run_len_s);
|
||||||
|
let mut data = fft_thres_at_ms(&mut out_l[..], FFT::F4096, 0, 0.0);
|
||||||
|
|
||||||
|
for _ in 0..9 {
|
||||||
|
let (mut out_l, _out_r) = run_no_input(node_exec, run_len_s);
|
||||||
|
let out = fft_thres_at_ms(&mut out_l[..], FFT::F4096, 0, 0.0);
|
||||||
|
for (x, d) in out.iter().zip(data.iter_mut()) {
|
||||||
|
d.1 += x.1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for d in data.iter_mut() {
|
||||||
|
d.1 /= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.iter().filter(|d| d.1 >= thres).copied().collect()
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub enum FFT {
|
pub enum FFT {
|
||||||
F16,
|
F16,
|
||||||
|
|
50
tests/node_comb.rs
Normal file
50
tests/node_comb.rs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
mod common;
|
||||||
|
use common::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_node_comb_1() {
|
||||||
|
let (node_conf, mut node_exec) = new_node_engine();
|
||||||
|
let mut matrix = Matrix::new(node_conf, 3, 3);
|
||||||
|
|
||||||
|
let noise_1 = NodeId::Noise(0);
|
||||||
|
let comb_1 = NodeId::Comb(0);
|
||||||
|
let out_1 = NodeId::Out(0);
|
||||||
|
matrix.place(0, 1,
|
||||||
|
Cell::empty(noise_1)
|
||||||
|
.input(None, None, None)
|
||||||
|
.out(None, noise_1.out("sig"), None));
|
||||||
|
matrix.place(1, 1,
|
||||||
|
Cell::empty(comb_1)
|
||||||
|
.input(None, comb_1.inp("inp"), None)
|
||||||
|
.out(None, comb_1.out("sig"), None));
|
||||||
|
matrix.place(2, 2,
|
||||||
|
Cell::empty(out_1)
|
||||||
|
.input(None, out_1.inp("ch1"), out_1.inp("ch1"))
|
||||||
|
.out(None, None, None));
|
||||||
|
|
||||||
|
pset_n(&mut matrix, comb_1, "g", 0.950);
|
||||||
|
pset_n(&mut matrix, comb_1, "time", 0.014);
|
||||||
|
matrix.sync().unwrap();
|
||||||
|
|
||||||
|
let fft = run_and_get_avg_fft4096_now(&mut node_exec, 180);
|
||||||
|
assert_eq!(fft, vec![
|
||||||
|
(0, 216), (11, 221), (22, 216), (3370, 206), (3381, 248),
|
||||||
|
(3391, 191), (6740, 185), (6751, 207), (6761, 195), (10131, 215),
|
||||||
|
(10142, 210), (10153, 213), (10164, 201), (20338, 187), (20349, 184)
|
||||||
|
]);
|
||||||
|
|
||||||
|
pset_n_wait(&mut matrix, &mut node_exec, comb_1, "time", 0.030);
|
||||||
|
|
||||||
|
let fft = run_and_get_avg_fft4096_now(&mut node_exec, 180);
|
||||||
|
assert_eq!(fft, vec![
|
||||||
|
(1001, 206), (2993, 196), (3004, 219), (3994, 197),
|
||||||
|
(6998, 211), (8000, 201)
|
||||||
|
]);
|
||||||
|
|
||||||
|
pset_n_wait(&mut matrix, &mut node_exec, comb_1, "g", 0.999);
|
||||||
|
let fft = run_and_get_avg_fft4096_now(&mut node_exec, 1000);
|
||||||
|
assert_eq!(fft, vec![
|
||||||
|
(0, 2003), (11, 1015), (991, 1078), (1001, 1837), (2003, 1059),
|
||||||
|
(2993, 1420), (3004, 1775), (3994, 1297), (4005, 1485)
|
||||||
|
]);
|
||||||
|
}
|
Loading…
Reference in a new issue