Crates.io | pcm-flow |
lib.rs | pcm-flow |
version | 0.5.0 |
source | src |
created_at | 2017-11-19 19:35:37.782735 |
updated_at | 2017-12-01 12:49:09.399596 |
description | Compose many small audio Processors to a big audio Processor |
homepage | |
repository | https://github.com/sebastianpfluegelmeier/pcm-flow |
max_upload_size | |
id | 39944 |
size | 41,268 |
A library for building big synthesizers and effects from small modules. You can write structs implementing the Processor Trait and chain them together in a flexible way. This library is still in early development and it is not advised to use it yet
Add pcm-flow to your Cargo.toml
[dependencies]
pcm-flow = "0.5.0"
This program shows how to use pcm-flow in a very useless but simple way. We define a struct implementing the Processor trait which just takes an input and passes it to its output. Then we make two instances of this struct and chain them together.
extern crate pcm_flow;
use pcm_flow::graph::Graph;
use pcm_flow::processor::Processor;
fn main() {
// create a new graph Struct, it is the main container for our Processors
let mut graph = Graph::new(1);
// Add two PassThrough structs to the graph and store their IDs in variables
let pass_through1 = graph.add_processor(Box::new(PassThrough{}));
let pass_through2 = graph.add_processor(Box::new(PassThrough{}));
// connect the two processors
graph.add_connection(&(pass_through1, 0), &(pass_through2, 0)).unwrap();
// add an input to the graph
graph.set_input_amt(1);
// add an output to the graph
graph.set_output_amt(1);
// connect the input to the first Processor
graph.connect_input(0, (pass_through1, 0)).unwrap();
// connect the second Processor to the Output
graph.connect_output(0, (pass_through2, 0)).unwrap();
}
// The struct we define here, takes one input and passes the signal to the output
struct PassThrough {}
impl Processor<[f32; 2]> for PassThrough {
fn process(&mut self, inputs: &Vec<Vec<[f32; 2]>>, outputs: &mut Vec<Vec<[f32; 2]>>) {
for i in 0..2 {
for sample in 0..1 {
outputs[0][sample][i] = inputs[0][sample][i];
}
}
}
fn inputs_amt(&self) -> usize { 1 }
fn outputs_amt(&self) -> usize { 1 }
}