Skip to main content

Crate resonant_stream

Crate resonant_stream 

Source
Expand description

resonant-stream — streaming DSP pipeline.

This crate provides a pull-based, synchronous processing pipeline for audio DSP. Chunks of sample data flow through a chain of DspNodes, each transforming the audio in place where possible to minimise allocations.

§Architecture

┌───────────┐    ┌───────────┐    ┌───────────┐
│  Source    │───▶│  Node A   │───▶│  Node B   │───▶ output
│ (Chunk)   │    │ (filter)  │    │ (gain)    │
└───────────┘    └───────────┘    └───────────┘
  • Chunk carries interleaved samples plus metadata (sample rate, channels).
  • DspNode is the core trait — implement it to create custom processors.
  • StreamError covers format mismatches and processing failures.

§Quick start

use resonant_stream::{Chunk, DspNode, StreamError};

// A simple gain node that scales all samples.
struct Gain(f32);

impl DspNode for Gain {
    fn process(&mut self, mut input: Chunk) -> Result<Chunk, StreamError> {
        for s in input.data_mut() {
            *s *= self.0;
        }
        Ok(input)
    }
    fn reset(&mut self) {}
}

let mut gain = Gain(0.5);
let chunk = Chunk::new(vec![1.0, -1.0, 0.5, -0.5], 44100, 1);
let out = gain.process(chunk).unwrap();
assert_eq!(out.data(), &[0.5, -0.5, 0.25, -0.25]);

Re-exports§

pub use graph::GraphExt;
pub use graph::Parallel;
pub use graph::Serial;
pub use graph::Stack;

Modules§

graph
Operator-overloaded graph combinators for pipeline composition. Operator-overloaded pipeline graph composition.
io
Hardware audio I/O nodes backed by cpal.
nodes
Built-in processing nodes. Built-in processing nodes for common DSP operations.

Structs§

Chunk
A buffer of audio samples with associated metadata.
Pipeline
A chain of DspNodes that processes audio sequentially.
PipelineBuilder
Builder for constructing a Pipeline.

Enums§

StreamError
Errors that can occur during stream processing.

Traits§

DspNode
A processing node in a DSP pipeline.