Skip to content

A library for combining many small audio processors to one big audio processor

License

Notifications You must be signed in to change notification settings

sebastianpfluegelmeier/pcm-flow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pcm-flow

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

Usage

Add pcm-flow to your Cargo.toml

[dependencies]
pcm-flow = "0.5.0"

A simple Program using pcm-flow

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 }
}

About

A library for combining many small audio processors to one big audio processor

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages