diff --git a/tests/impulse-tests/Makefile b/tests/impulse-tests/Makefile index 8e6883754c..a3817f7980 100644 --- a/tests/impulse-tests/Makefile +++ b/tests/impulse-tests/Makefile @@ -122,8 +122,9 @@ travis: ######################################################################### # automatic github action test github_action: - $(MAKE) -f Make.rust outdir=rust/no CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -a archs/rust/architecture_normal.rs" - $(MAKE) -f Make.rust outdir=rust/rnt CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -rnt -a archs/rust/architecture.rs" + $(MAKE) -f Make.rust outdir=rust/rnt CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -cm -a archs/rust/architecture_cm.rs" + $(MAKE) -f Make.rust outdir=rust/rnt CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -ec -rnt -a archs/rust/architecture_ecrnt.rs" + $(MAKE) -f Make.rust outdir=rust/no CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -a archs/rust/architecture_trait.rs" $(MAKE) -f Make.gcc outdir=cpp/double lang=cpp arch=impulsearch.cpp FAUSTOPTIONS="-I ../../libraries/ -I dsp -double" ######################################################################### @@ -369,10 +370,12 @@ interp1: ######################################################################### # Rust backend rust: - $(MAKE) -f Make.rust outdir=rust/no CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -rnt -a archs/rust/architecture.rs" - $(MAKE) -f Make.rust outdir=rust/fp FAUSTOPTIONS="-I ../../libraries/ -double -fp -a archs/rust/architecture_normal.rs" - $(MAKE) -f Make.rust outdir=rust/vec4 CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -vec -vs 4 -a archs/rust/architecture_normal.rs" - $(MAKE) -f Make.rust outdir=rust/vec32 FAUSTOPTIONS="-I ../../libraries/ -double -vec -vs 32 -a archs/rust/architecture_normal.rs" + $(MAKE) -f Make.rust outdir=rust/ec CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -cm -a archs/rust/architecture_cm.rs" + $(MAKE) -f Make.rust outdir=rust/ec CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -ec -rnt -a archs/rust/architecture_ecrnt.rs" + $(MAKE) -f Make.rust outdir=rust/no CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -a archs/rust/architecture_trait.rs" + $(MAKE) -f Make.rust outdir=rust/fp FAUSTOPTIONS="-I ../../libraries/ -double -fp -a archs/rust/architecture_trait.rs" + $(MAKE) -f Make.rust outdir=rust/vec4 CARGOOPTIONS="" FAUSTOPTIONS="-I ../../libraries/ -double -vec -vs 4 -a archs/rust/architecture_trait.rs" + $(MAKE) -f Make.rust outdir=rust/vec32 FAUSTOPTIONS="-I ../../libraries/ -double -vec -vs 32 -a archs/rust/architecture_trait.rs" ######################################################################### # Cmajor backend diff --git a/tests/impulse-tests/archs/rust/Cargo.toml b/tests/impulse-tests/archs/rust/Cargo.toml index b0a848cb6b..5747804e89 100644 --- a/tests/impulse-tests/archs/rust/Cargo.toml +++ b/tests/impulse-tests/archs/rust/Cargo.toml @@ -13,4 +13,4 @@ default-boxed = "0.2" default = ["default-boxed"] default-boxed = [] -[workspace] \ No newline at end of file +[workspace] diff --git a/tests/impulse-tests/archs/rust/architecture_cm.rs b/tests/impulse-tests/archs/rust/architecture_cm.rs new file mode 100644 index 0000000000..a6b48baee8 --- /dev/null +++ b/tests/impulse-tests/archs/rust/architecture_cm.rs @@ -0,0 +1,294 @@ +/************************************************************************ +************************************************************************ +FAUST Architecture File +Copyright (C) 2020 GRAME, Centre National de Creation Musicale +--------------------------------------------------------------------- + +This is sample code. This file is provided as an example of minimal +FAUST architecture file. Redistribution and use in source and binary +forms, with or without modification, in part or in full are permitted. +In particular you can create a derived work of this FAUST architecture +and distribute that work under terms of your choice. + +This sample code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +************************************************************************ +************************************************************************/ + +#![allow(unused_parens)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] +#![allow(dead_code)] +#![allow(unused_variables)] +#![allow(unused_mut)] +#![allow(non_upper_case_globals)] +#![recursion_limit = "256"] + +extern crate libm; +extern crate num_traits; +/* extern crate fastfloat; */ + +use std::env; +use std::fs::File; +use std::io::Write; + +use default_boxed::DefaultBoxed; +use num_traits::{cast::FromPrimitive, float::Float}; + +type F32 = f32; +type F64 = f64; + +/* +type F32 = Fast; +type F64 = Fast; +*/ + +#[derive(Copy, Clone)] +pub struct ParamIndex(i32); + +pub struct Soundfile<'a> { + fBuffers: &'a &'a F32, + fLength: &'a i32, + fSR: &'a i32, + fOffset: &'a i32, + fChannels: i32, +} + +pub trait FaustDsp { + type T; + + fn new() -> Self + where + Self: Sized; + fn metadata(&self, m: &mut dyn Meta); + fn get_sample_rate(&self) -> i32; + fn get_num_inputs(&self) -> i32; + fn get_num_outputs(&self) -> i32; + fn class_init(sample_rate: i32) + where + Self: Sized; + fn instance_reset_params(&mut self); + fn instance_clear(&mut self); + fn instance_constants(&mut self, sample_rate: i32); + fn instance_init(&mut self, sample_rate: i32); + fn init(&mut self, sample_rate: i32); + fn build_user_interface(&self, ui_interface: &mut dyn UI); + fn build_user_interface_static(ui_interface: &mut dyn UI) + where + Self: Sized; + fn get_param(&self, param: ParamIndex) -> Option; + fn set_param(&mut self, param: ParamIndex, value: Self::T); + fn compute(&mut self, count: i32, inputs: &[&[Self::T]], outputs: &mut [&mut [Self::T]]); +} + +pub trait Meta { + // -- metadata declarations + fn declare(&mut self, key: &str, value: &str); +} + +pub trait UI { + // -- widget's layouts + fn open_tab_box(&mut self, label: &str); + fn open_horizontal_box(&mut self, label: &str); + fn open_vertical_box(&mut self, label: &str); + fn close_box(&mut self); + + // -- active widgets + fn add_button(&mut self, label: &str, param: ParamIndex); + fn add_check_button(&mut self, label: &str, param: ParamIndex); + fn add_vertical_slider( + &mut self, + label: &str, + param: ParamIndex, + init: T, + min: T, + max: T, + step: T, + ); + fn add_horizontal_slider( + &mut self, + label: &str, + param: ParamIndex, + init: T, + min: T, + max: T, + step: T, + ); + fn add_num_entry(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T); + + // -- passive widgets + fn add_horizontal_bargraph(&mut self, label: &str, param: ParamIndex, min: T, max: T); + fn add_vertical_bargraph(&mut self, label: &str, param: ParamIndex, min: T, max: T); + + // -- metadata declarations + fn declare(&mut self, param: Option, key: &str, value: &str); +} + +pub struct ButtonUI { + all_button_params: Vec, +} + +impl ButtonUI { + fn set_button_parameters_to(&self, dsp: &mut dyn FaustDsp, value: f64) { + for button_param in &self.all_button_params { + dsp.set_param(*button_param, value); + } + } +} + +impl UI for ButtonUI { + // -- widget's layouts + fn open_tab_box(&mut self, label: &str) {} + fn open_horizontal_box(&mut self, label: &str) {} + fn open_vertical_box(&mut self, label: &str) {} + fn close_box(&mut self) {} + + // -- active widgets + fn add_button(&mut self, label: &str, param: ParamIndex) { + self.all_button_params.push(param); + } + fn add_check_button(&mut self, label: &str, param: ParamIndex) {} + fn add_vertical_slider( + &mut self, + label: &str, + param: ParamIndex, + init: T, + min: T, + max: T, + step: T, + ) { + } + fn add_horizontal_slider( + &mut self, + label: &str, + param: ParamIndex, + init: T, + min: T, + max: T, + step: T, + ) { + } + fn add_num_entry(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T) {} + + // -- passive widgets + fn add_horizontal_bargraph(&mut self, label: &str, param: ParamIndex, min: T, max: T) {} + fn add_vertical_bargraph(&mut self, label: &str, param: ParamIndex, min: T, max: T) {} + + // -- metadata declarations + fn declare(&mut self, param: Option, key: &str, value: &str) {} +} + +// // Generated intrinsics: +// <> + +// // Generated class: +// <> + +const SAMPLE_RATE: i32 = 44100; + +type Dsp64 = dyn FaustDsp; + +fn print_header(mut dsp: Box, num_total_samples: usize, output_file: &mut File) { + dsp.init(SAMPLE_RATE); + writeln!(output_file, "number_of_inputs : {}", dsp.get_num_inputs()).unwrap(); + writeln!(output_file, "number_of_outputs : {}", dsp.get_num_outputs()).unwrap(); + writeln!(output_file, "number_of_frames : {}", num_total_samples).unwrap(); +} + +fn run_dsp( + mut dsp: Box, + num_samples: usize, + line_num_offset: usize, + output_file: &mut File, +) { + type T = ::T; + + // Generation constants + let buffer_size = 64usize; + + // Init dsp + dsp.init(SAMPLE_RATE); + + let num_inputs = dsp.get_num_inputs() as usize; + let num_outputs = dsp.get_num_outputs() as usize; + + // Prepare buffers + let mut in_buffer = vec![vec![0 as T; buffer_size]; num_inputs]; + let mut out_buffer = vec![vec![0 as T; buffer_size]; num_outputs]; + + // Prepare UI + let mut ui = ButtonUI { + all_button_params: Vec::new(), + }; + dsp.build_user_interface(&mut ui); + + // Compute + let mut cycle = 0; + let mut num_samples_written = 0; + while num_samples_written < num_samples { + let buffer_size = buffer_size.min(num_samples - num_samples_written); + + // handle inputs + for c in 0..num_inputs { + for j in 0..buffer_size { + let first_frame = num_samples_written == 0 && j == 0; + in_buffer[c][j] = if first_frame { 1.0 } else { 0.0 }; + } + } + + // Set button state + if cycle == 0 { + ui.set_button_parameters_to(&mut *dsp, 1.0); + } else { + ui.set_button_parameters_to(&mut *dsp, 0.0); + } + + // right now the cm flag is only tested for the case that is the buffer is zeroed every time + let i = in_buffer + .iter() + .map(|buffer| buffer.as_slice()) + .collect::>(); + let mut o = out_buffer + .iter_mut() + .map(|buffer| { + buffer.iter_mut().for_each(|i| *i = 0.0); + buffer.as_mut_slice() + }) + .collect::>(); + + dsp.compute(buffer_size as i32, i.as_slice(), o.as_mut_slice()); + + // handle outputs + for j in 0..buffer_size { + write!(output_file, "{:6} :", num_samples_written + line_num_offset).unwrap(); + for c in 0..num_outputs { + write!(output_file, " {:8.6}", out_buffer[c][j]).unwrap(); + } + writeln!(output_file).unwrap(); + num_samples_written += 1; + } + + cycle = cycle + 1; + } +} + +fn new_dsp() -> Box { + mydsp::default_boxed() +} + +fn main() { + let num_total_samples = 60000; + + let block_size = num_total_samples / 4; + + // Open output file + let output_file_name = env::args() + .nth(1) + .expect("ERROR: Output file name expected."); + let mut output_file = File::create(output_file_name).expect("Cannot create output file"); + + print_header(new_dsp(), num_total_samples, &mut output_file); + + run_dsp(mydsp::default_boxed(), block_size, 0, &mut output_file); +} diff --git a/tests/impulse-tests/archs/rust/architecture.rs b/tests/impulse-tests/archs/rust/architecture_ecrnt.rs similarity index 70% rename from tests/impulse-tests/archs/rust/architecture.rs rename to tests/impulse-tests/archs/rust/architecture_ecrnt.rs index 99e38d6779..7bf451e323 100644 --- a/tests/impulse-tests/archs/rust/architecture.rs +++ b/tests/impulse-tests/archs/rust/architecture_ecrnt.rs @@ -23,17 +23,17 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #![allow(unused_variables)] #![allow(unused_mut)] #![allow(non_upper_case_globals)] - -#![recursion_limit="256"] +#![recursion_limit = "256"] extern crate libm; extern crate num_traits; /* extern crate fastfloat; */ +use std::env; use std::fs::File; use std::io::Write; -use std::env; +use default_boxed::DefaultBoxed; use num_traits::{cast::FromPrimitive, float::Float}; type F32 = f32; @@ -48,14 +48,13 @@ type F64 = Fast; pub struct ParamIndex(i32); pub struct Soundfile<'a> { - fBuffers: &'a&'a F32, + fBuffers: &'a &'a F32, fLength: &'a i32, fSR: &'a i32, fOffset: &'a i32, - fChannels: i32 + fChannels: i32, } - pub trait Meta { // -- metadata declarations fn declare(&mut self, key: &str, value: &str); @@ -71,8 +70,24 @@ pub trait UI { // -- active widgets fn add_button(&mut self, label: &str, param: ParamIndex); fn add_check_button(&mut self, label: &str, param: ParamIndex); - fn add_vertical_slider(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T); - fn add_horizontal_slider(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T); + fn add_vertical_slider( + &mut self, + label: &str, + param: ParamIndex, + init: T, + min: T, + max: T, + step: T, + ); + fn add_horizontal_slider( + &mut self, + label: &str, + param: ParamIndex, + init: T, + min: T, + max: T, + step: T, + ); fn add_num_entry(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T); // -- passive widgets @@ -83,22 +98,19 @@ pub trait UI { fn declare(&mut self, param: Option, key: &str, value: &str); } -pub struct ButtonUI -{ - all_button_params: Vec +pub struct ButtonUI { + all_button_params: Vec, } -impl ButtonUI -{ - fn set_button_parameters_to(&self, dsp: &mut mydsp, value: f64) { +impl ButtonUI { + fn set_button_parameters_to(&self, dsp: &mut Box, value: f64) { for button_param in &self.all_button_params { dsp.set_param(*button_param, value); } } } -impl UI for ButtonUI -{ +impl UI for ButtonUI { // -- widget's layouts fn open_tab_box(&mut self, label: &str) {} fn open_horizontal_box(&mut self, label: &str) {} @@ -106,13 +118,30 @@ impl UI for ButtonUI fn close_box(&mut self) {} // -- active widgets - fn add_button(&mut self, label: &str, param: ParamIndex) - { + fn add_button(&mut self, label: &str, param: ParamIndex) { self.all_button_params.push(param); } fn add_check_button(&mut self, label: &str, param: ParamIndex) {} - fn add_vertical_slider(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T) {} - fn add_horizontal_slider(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T) {} + fn add_vertical_slider( + &mut self, + label: &str, + param: ParamIndex, + init: T, + min: T, + max: T, + step: T, + ) { + } + fn add_horizontal_slider( + &mut self, + label: &str, + param: ParamIndex, + init: T, + min: T, + max: T, + step: T, + ) { + } fn add_num_entry(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T) {} // -- passive widgets @@ -138,9 +167,12 @@ fn print_header(mut dsp: Box, num_total_samples: usize, output_file: &mut writeln!(output_file, "number_of_frames : {}", num_total_samples).unwrap(); } -fn run_dsp(mut dsp: Box, num_samples: usize, line_num_offset: usize, output_file: &mut File) { - type T = FaustFloat; - +fn run_dsp( + mut dsp: Box, + num_samples: usize, + line_num_offset: usize, + output_file: &mut File, +) { // Generation constants let buffer_size = 64usize; @@ -148,18 +180,19 @@ fn run_dsp(mut dsp: Box, num_samples: usize, line_num_offset: usize, outp dsp.init(SAMPLE_RATE); // Prepare buffers - let mut in_buffer = vec![vec![0 as T; buffer_size]; FAUST_INPUTS]; - let mut out_buffer = vec![vec![0 as T; buffer_size]; FAUST_OUTPUTS]; + let mut in_buffer = vec![vec![0 as FaustFloat; buffer_size]; FAUST_INPUTS]; + let mut out_buffer = vec![vec![0 as FaustFloat; buffer_size]; FAUST_OUTPUTS]; // Prepare UI - let mut ui = ButtonUI{ all_button_params: Vec::new() }; + let mut ui = ButtonUI { + all_button_params: Vec::new(), + }; dsp.build_user_interface(&mut ui); // Compute let mut cycle = 0; let mut num_samples_written = 0; while num_samples_written < num_samples { - let buffer_size = buffer_size.min(num_samples - num_samples_written); // handle inputs @@ -172,15 +205,24 @@ fn run_dsp(mut dsp: Box, num_samples: usize, line_num_offset: usize, outp // Set button state if cycle == 0 { - ui.set_button_parameters_to(&mut *dsp, 1.0); + ui.set_button_parameters_to(&mut dsp, 1.0); } else { - ui.set_button_parameters_to(&mut *dsp, 0.0); + ui.set_button_parameters_to(&mut dsp, 0.0); } + dsp.control(); dsp.compute( buffer_size, - in_buffer.iter().map(|buffer| buffer.as_slice()).collect::>().as_slice(), - out_buffer.iter_mut().map(|buffer| buffer.as_mut_slice()).collect::>().as_mut_slice(), + in_buffer + .iter() + .map(|buffer| buffer.as_slice()) + .collect::>() + .as_slice(), + out_buffer + .iter_mut() + .map(|buffer| buffer.as_mut_slice()) + .collect::>() + .as_mut_slice(), ); // handle outputs @@ -197,26 +239,18 @@ fn run_dsp(mut dsp: Box, num_samples: usize, line_num_offset: usize, outp } } -fn new_dsp() -> Box { - use default_boxed::DefaultBoxed; - mydsp::default_boxed() -} - fn main() { let num_total_samples = 60000; let block_size = num_total_samples / 4; // Open output file - let output_file_name = env::args().nth(1).expect("ERROR: Output file name expected."); + let output_file_name = env::args() + .nth(1) + .expect("ERROR: Output file name expected."); let mut output_file = File::create(output_file_name).expect("Cannot create output file"); - print_header(new_dsp(), num_total_samples, &mut output_file); - - // Only test mono DSP for now - run_dsp(new_dsp(), block_size, 0, &mut output_file); + print_header(mydsp::default_boxed(), num_total_samples, &mut output_file); - //run_dsp(new_dsp(), block_size, 1 * block_size, &mut output_file); - //run_dsp(new_dsp(), block_size, 2 * block_size, &mut output_file); - //run_dsp(new_dsp(), block_size, 3 * block_size, &mut output_file); + run_dsp(mydsp::default_boxed(), block_size, 0, &mut output_file); } diff --git a/tests/impulse-tests/archs/rust/architecture_normal.rs b/tests/impulse-tests/archs/rust/architecture_trait.rs similarity index 78% rename from tests/impulse-tests/archs/rust/architecture_normal.rs rename to tests/impulse-tests/archs/rust/architecture_trait.rs index 63d9a49db1..c454dd6e1b 100644 --- a/tests/impulse-tests/archs/rust/architecture_normal.rs +++ b/tests/impulse-tests/archs/rust/architecture_trait.rs @@ -23,16 +23,15 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #![allow(unused_variables)] #![allow(unused_mut)] #![allow(non_upper_case_globals)] - -#![recursion_limit="256"] +#![recursion_limit = "256"] extern crate libm; extern crate num_traits; /* extern crate fastfloat; */ +use std::env; use std::fs::File; use std::io::Write; -use std::env; use num_traits::{cast::FromPrimitive, float::Float}; @@ -48,32 +47,38 @@ type F64 = Fast; pub struct ParamIndex(i32); pub struct Soundfile<'a> { - fBuffers: &'a&'a F32, + fBuffers: &'a &'a F32, fLength: &'a i32, fSR: &'a i32, fOffset: &'a i32, - fChannels: i32 + fChannels: i32, } pub trait FaustDsp { type T; - fn new() -> Self where Self: Sized; + fn new() -> Self + where + Self: Sized; fn metadata(&self, m: &mut dyn Meta); fn get_sample_rate(&self) -> i32; fn get_num_inputs(&self) -> i32; fn get_num_outputs(&self) -> i32; - fn class_init(sample_rate: i32) where Self: Sized; + fn class_init(sample_rate: i32) + where + Self: Sized; fn instance_reset_params(&mut self); fn instance_clear(&mut self); fn instance_constants(&mut self, sample_rate: i32); fn instance_init(&mut self, sample_rate: i32); fn init(&mut self, sample_rate: i32); fn build_user_interface(&self, ui_interface: &mut dyn UI); - fn build_user_interface_static(ui_interface: &mut dyn UI) where Self: Sized; + fn build_user_interface_static(ui_interface: &mut dyn UI) + where + Self: Sized; fn get_param(&self, param: ParamIndex) -> Option; fn set_param(&mut self, param: ParamIndex, value: Self::T); - fn compute(&mut self, count: i32, inputs: &[&[Self::T]], outputs: &mut[&mut[Self::T]]); + fn compute(&mut self, count: i32, inputs: &[&[Self::T]], outputs: &mut [&mut [Self::T]]); } pub trait Meta { @@ -91,8 +96,24 @@ pub trait UI { // -- active widgets fn add_button(&mut self, label: &str, param: ParamIndex); fn add_check_button(&mut self, label: &str, param: ParamIndex); - fn add_vertical_slider(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T); - fn add_horizontal_slider(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T); + fn add_vertical_slider( + &mut self, + label: &str, + param: ParamIndex, + init: T, + min: T, + max: T, + step: T, + ); + fn add_horizontal_slider( + &mut self, + label: &str, + param: ParamIndex, + init: T, + min: T, + max: T, + step: T, + ); fn add_num_entry(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T); // -- passive widgets @@ -103,22 +124,19 @@ pub trait UI { fn declare(&mut self, param: Option, key: &str, value: &str); } -pub struct ButtonUI -{ - all_button_params: Vec +pub struct ButtonUI { + all_button_params: Vec, } -impl ButtonUI -{ - fn set_button_parameters_to(&self, dsp: &mut dyn FaustDsp, value: f64) { +impl ButtonUI { + fn set_button_parameters_to(&self, dsp: &mut dyn FaustDsp, value: f64) { for button_param in &self.all_button_params { dsp.set_param(*button_param, value); } } } -impl UI for ButtonUI -{ +impl UI for ButtonUI { // -- widget's layouts fn open_tab_box(&mut self, label: &str) {} fn open_horizontal_box(&mut self, label: &str) {} @@ -126,13 +144,30 @@ impl UI for ButtonUI fn close_box(&mut self) {} // -- active widgets - fn add_button(&mut self, label: &str, param: ParamIndex) - { + fn add_button(&mut self, label: &str, param: ParamIndex) { self.all_button_params.push(param); } fn add_check_button(&mut self, label: &str, param: ParamIndex) {} - fn add_vertical_slider(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T) {} - fn add_horizontal_slider(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T) {} + fn add_vertical_slider( + &mut self, + label: &str, + param: ParamIndex, + init: T, + min: T, + max: T, + step: T, + ) { + } + fn add_horizontal_slider( + &mut self, + label: &str, + param: ParamIndex, + init: T, + min: T, + max: T, + step: T, + ) { + } fn add_num_entry(&mut self, label: &str, param: ParamIndex, init: T, min: T, max: T, step: T) {} // -- passive widgets @@ -151,7 +186,7 @@ impl UI for ButtonUI const SAMPLE_RATE: i32 = 44100; -type Dsp64 = dyn FaustDsp; +type Dsp64 = dyn FaustDsp; fn print_header(mut dsp: Box, num_total_samples: usize, output_file: &mut File) { dsp.init(SAMPLE_RATE); @@ -160,7 +195,12 @@ fn print_header(mut dsp: Box, num_total_samples: usize, output_file: &mut writeln!(output_file, "number_of_frames : {}", num_total_samples).unwrap(); } -fn run_dsp(mut dsp: Box, num_samples: usize, line_num_offset: usize, output_file: &mut File) { +fn run_dsp( + mut dsp: Box, + num_samples: usize, + line_num_offset: usize, + output_file: &mut File, +) { type T = ::T; // Generation constants @@ -177,14 +217,15 @@ fn run_dsp(mut dsp: Box, num_samples: usize, line_num_offset: usize, outp let mut out_buffer = vec![vec![0 as T; buffer_size]; num_outputs]; // Prepare UI - let mut ui = ButtonUI{ all_button_params: Vec::new() }; + let mut ui = ButtonUI { + all_button_params: Vec::new(), + }; dsp.build_user_interface(&mut ui); // Compute let mut cycle = 0; let mut num_samples_written = 0; while num_samples_written < num_samples { - let buffer_size = buffer_size.min(num_samples - num_samples_written); // handle inputs @@ -204,8 +245,16 @@ fn run_dsp(mut dsp: Box, num_samples: usize, line_num_offset: usize, outp dsp.compute( buffer_size as i32, - in_buffer.iter().map(|buffer| buffer.as_slice()).collect::>().as_slice(), - out_buffer.iter_mut().map(|buffer| buffer.as_mut_slice()).collect::>().as_mut_slice(), + in_buffer + .iter() + .map(|buffer| buffer.as_slice()) + .collect::>() + .as_slice(), + out_buffer + .iter_mut() + .map(|buffer| buffer.as_mut_slice()) + .collect::>() + .as_mut_slice(), ); // handle outputs @@ -233,7 +282,9 @@ fn main() { let block_size = num_total_samples / 4; // Open output file - let output_file_name = env::args().nth(1).expect("ERROR: Output file name expected."); + let output_file_name = env::args() + .nth(1) + .expect("ERROR: Output file name expected."); let mut output_file = File::create(output_file_name).expect("Cannot create output file"); print_header(new_dsp(), num_total_samples, &mut output_file);