...
 
Commits (3)
This diff is collapsed.
This diff is collapsed.
......@@ -728,7 +728,7 @@ pub struct InputsOutputsAdaptor {
impl InputsOutputsAdaptor {
pub fn new(nb_inputs: usize, nb_outputs: usize) -> InputsOutputsAdaptor {
assert!(nb_inputs % nb_outputs == 0 || nb_outputs % nb_inputs == 0 );
//assert!(nb_inputs % nb_outputs == 0 || nb_outputs % nb_inputs == 0 );//We don't need that anymore
let stride = if nb_outputs > nb_inputs {nb_outputs / nb_inputs} else {nb_inputs / nb_outputs};
InputsOutputsAdaptor {nb_inputs, nb_outputs, stride}
}
......@@ -756,19 +756,26 @@ impl AudioEffect for InputsOutputsAdaptor {
fn process(&mut self, inputs: &[DspEdge], outputs: &mut[DspEdge]) {
debug_assert_eq!(inputs.len(), self.nb_inputs());
debug_assert_eq!(outputs.len(), self.nb_outputs());
debug_assert!(self.nb_inputs % self.nb_outputs == 0 || self.nb_outputs % self.nb_inputs == 0 );
//Actually, not a problem if it's not the case. The last inputs/outputs will just be the same number
//debug_assert!(self.nb_inputs % self.nb_outputs == 0 || self.nb_outputs % self.nb_inputs == 0 );
if self.nb_outputs > self.nb_inputs {
for (i,group) in outputs.chunks_mut(self.stride).enumerate() {
let iter = outputs.chunks_exact_mut(self.stride);
for (i,group) in iter.enumerate() {
// Copy the last input in the remaining outputs
let index = std::cmp::min(i, inputs.len() - 1);
for output in group.iter_mut() {
output.buffer_mut().copy_from_slice(inputs[i].buffer());
output.buffer_mut().copy_from_slice(inputs[index].buffer());
}
}
}
else {
for (i,group) in inputs.chunks(self.stride).enumerate() {
//To handle the last chunk which will be mixed in the last output with the previous chunk
let index = std::cmp::min(i, outputs.len() - 1);
for input in group {
mixer(outputs[i].buffer_mut(), input.buffer());
mixer(outputs[index].buffer_mut(), input.buffer());
}
}
}
......
......@@ -27,6 +27,9 @@ use audio_adaptive::audiograph::*;
use audio_adaptive::audiograph_parser::*;
use audio_adaptive::sndfile;
use rand::prelude::*;
use rand::distributions::Uniform;
const CHANNELS: i32 = 1;
const SAMPLE_RATE: u32 = 44_100;
const NB_CYCLES : u32 = 12000;
......@@ -163,6 +166,10 @@ fn bounce_run<'a>(mut audio_graph: AudioGraph, graph_name: String, audio_input:
let mut samplerate = SAMPLE_RATE;
let mut nb_cycles = 0;
// Used if there is not input file to have non-zero sources
let mut rng = SmallRng::seed_from_u64(345987);
let unity_interval = Uniform::new_inclusive(-1.,1.);
let mut advance : Box<dyn FnMut(&mut [f32]) -> u32> = if let Some(audio_input_name) = audio_input {
let mut input_file = sndfile::SndFile::open(audio_input_name)?;
nb_channels = input_file.nb_channels();
......@@ -170,7 +177,11 @@ fn bounce_run<'a>(mut audio_graph: AudioGraph, graph_name: String, audio_input:
audio_graph.set_nominal_samplerate(samplerate);
Box::new(move |buf| {input_file.read_float(buf) as u32})
} else {
Box::new(|_buf| { nb_cycles += 1; cycles - nb_cycles })
let n = (nb_frames * nb_channels) as usize;
Box::new(move |buf| {
buf.copy_from_slice(&rng.sample_iter(&unity_interval).take(n).collect::<Vec<f32>>());
nb_cycles += 1; cycles - nb_cycles
})
};
let buffer_size = nb_frames * nb_channels;
......@@ -182,10 +193,11 @@ fn bounce_run<'a>(mut audio_graph: AudioGraph, graph_name: String, audio_input:
while advance(buf_in[0].buffer_mut()) != 0 {
let start = PreciseTime::now();
audio_graph.process(&buf_in, &mut buf_out);
let execution_time = start.to(PreciseTime::now()).num_microseconds().unwrap();
output_file.write_float(buf_out[0].buffer());
//Reporting
let execution_time = start.to(PreciseTime::now()).num_microseconds().unwrap();
if monitor {
let seria = format!("{}\n", execution_time);
f.as_mut().unwrap().write_all(seria.as_bytes()).unwrap();
......