Commit 9946f8af authored by Pierre Donat-Bouillud's avatar Pierre Donat-Bouillud
Browse files

Handle 0 input or output nodes from audiograph format and source not at

the beginning of the schedule.
parent 319ea2de
Pipeline #724 passed with stage
in 2 minutes and 54 seconds
......@@ -77,13 +77,16 @@ impl DspNode {
DspNode {node_infos, node_processor}
}
pub fn new(node_infos: audiograph_parser::Node) -> DspNode {
pub fn new(node_infos: audiograph_parser::Node, nb_channels: usize) -> DspNode {
let node_processor : Box<dyn AudioEffect> = match node_infos.class_name.as_str() {
"osc" => Box::new(Oscillator::from_node_infos(&node_infos)),
"mod" => Box::new(Modulator::from_node_infos(&node_infos)),
"mix" => Box::new(InputsOutputsAdaptor::from_node_infos(&node_infos)),
"resampler" => Box::new(Resampler::from_node_infos(&node_infos)),
"source" => Box::new(InputsOutputsAdaptor::new(nb_channels, node_infos.nb_outlets as usize)),
"sink" => Box::new(InputsOutputsAdaptor::new(node_infos.nb_inlets as usize, nb_channels)),
_ => {//We replace it by a default effect
println!("Unkwown node {:?}. Replacing it by a known one.", node_infos);
if node_infos.nb_inlets == 0 && node_infos.nb_outlets == 1 {
Box::new(Oscillator::new(0., 440, 1.))
}
......@@ -317,11 +320,22 @@ impl AudioGraph {
//self.print_schedule(&self.schedule);
self.schedule = filtered_schedule;
//self.schedule = self.schedule.iter().filter(|v| {dfs.discovered.is_visited(v)}).collect::<Vec<_>>();
if self.schedule.contains(&self.input_node_index) {
let mut source_index = 0;
for (i,e) in self.schedule.iter().enumerate() {
if *e == self.input_node_index {
self.has_source = true;
source_index = i;
break;
}
}
if self.has_source {
self.schedule.remove(source_index);
}
/*if self.schedule.contains(&self.input_node_index) {
self.has_source = true;
assert!(self.schedule[0] == self.input_node_index);
self.schedule.remove(0);
}
}*/
}
/// Adjust buffer sizes and samplerates for nodes between two resamplers
......
......@@ -179,7 +179,7 @@ fn bounce_run<'a>(mut audio_graph: AudioGraph, graph_name: String, audio_input:
let mut output_file = sndfile::SndFile::open_write(graph_name + ".wav", samplerate, nb_channels as u32)?;
while advance(buf_in[0].buffer_mut()) != 0 {
while advance(buf_in[0].buffer_mut()) != 0 {
let start = PreciseTime::now();
audio_graph.process(&buf_in, &mut buf_out);
output_file.write_float(buf_out[0].buffer());
......
......@@ -8,8 +8,6 @@ use std::collections::HashMap;
use petgraph::graph::NodeIndex;
use itertools::Itertools;
use pest::error::Error as ParseError;
use audiograph::*;
......@@ -116,7 +114,7 @@ pub fn parse_audiograph(audiograph : &str, buffer_size: usize, nb_channels: usiz
for node_infos in nodes.into_iter() {
let id = node_infos.id.clone();
let node = DspNode::new(node_infos);
let node = DspNode::new(node_infos, nb_channels);
let node_index = audiograph.add_node(node);
node_indexes.insert(id, node_index);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment