From c4a9b560994a5c6f29802c7cc53d10248e48673d Mon Sep 17 00:00:00 2001 From: Dimas Leenman Date: Sun, 7 Aug 2022 23:51:12 +0200 Subject: [PATCH] should be done --- src/dsp/node_formant.rs | 16 ++++++++++++---- tests/node_formant.rs | 29 ++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/dsp/node_formant.rs b/src/dsp/node_formant.rs index dfe4094..c9a623c 100644 --- a/src/dsp/node_formant.rs +++ b/src/dsp/node_formant.rs @@ -13,19 +13,27 @@ impl Formant { Self { inv_sample_rate: 1.0 / 44100.0, phase: 0.0 } } pub const freq: &'static str = "Formant freq\nBase frequency to oscilate at\n"; - pub const form: &'static str = "Formant form\nFrequency of the formant\n"; + pub const form: &'static str = "Formant form\nFrequency of the formant\nThis affects how much lower or higher tones the sound has."; pub const atk: &'static str = "Formant atk\nFormant attack bandwidth, controls the general bandwidth"; pub const dcy: &'static str = "Formant dcy\nFormant decay bandwidth, controls the peak bandwidth"; pub const sig: &'static str = "Formant sig\nGenerated formant signal"; - pub const DESC: &'static str = r#"A direct formant synthesizer + pub const DESC: &'static str = r#"Direct formant synthesizer This generates a single formant from a given frequency, formant frequency, as well as attack and decay frequencies. The attack and decay frequencies both control the bandwidth of the formant, decay the peak of the bandwidth, attack peak. "#; - pub const HELP: &'static str = r#"Formant - Single formant synthesizer -This is a formant synthesizer that directly generates the audio, no filters needed. + pub const HELP: &'static str = r#"Formant - Direct formant synthesized +This is a formant synthesizer that directly generates the audio of a single formant. + +This can be seen as passing a saw wave with frequency `freq` into a bandpass filter with the cutoff at `form` + +`freq` controls the base frequency of the formant. +`form` controls the formant frequency. Lower values give more bass to the sound, and higher values give the high frequencies more sound. +If `form` is lower than `freq`, the overal loudness will go down, however it's guaranteed to never exceed the [-1,1] range. +`atk` and `dcy` both control the bandwidth/resonance of the formant. The further apart they are in value, the higher the bandwidth/lower the resonance. +If these are set to a low value, the sine wave used for the formant effect becomes very audible. "#; } diff --git a/tests/node_formant.rs b/tests/node_formant.rs index e23909d..9bbcdb8 100644 --- a/tests/node_formant.rs +++ b/tests/node_formant.rs @@ -130,4 +130,31 @@ fn check_no_nan() { } #[test] -fn check_formant_freq() {} +fn check_formant_freq() { + let (node_conf, mut node_exec) = new_node_engine(); + + let mut matrix = Matrix::new(node_conf, 3, 3); + + let mut chain = MatrixCellChain::new(CellDir::B); + chain.node_out("formant", "sig").node_inp("out", "ch1").place(&mut matrix, 0, 0).unwrap(); + + matrix.sync().unwrap(); + + let formant = NodeId::Formant(0); + + // params + let freq_p = formant.inp_param("freq").unwrap(); + let form_p = formant.inp_param("form").unwrap(); + let atk_p = formant.inp_param("atk").unwrap(); + let dcy_p = formant.inp_param("dcy").unwrap(); + + // set params to reasonable values + matrix.set_param(freq_p, SAtom::param(-0.2)); + matrix.set_param(form_p, SAtom::param(0.0)); + matrix.set_param(atk_p, SAtom::param(0.2)); + matrix.set_param(dcy_p, SAtom::param(-0.2)); + + // run + let fft = run_and_get_avg_fft4096_now(&mut node_exec, 180); + assert_eq!(fft, vec![(334, 191), (431, 331), (441, 546), (452, 222), (549, 209)]); +}