ChannelRouterBlock

Flexible channel routing and manipulation.

Overview

ChannelRouterBlock provides various channel routing options for stereo audio, including swapping, duplicating, and inverting channels.

Creating a Router

#![allow(unused)]
fn main() {
use bbx_dsp::{
    blocks::{ChannelMode, ChannelRouterBlock},
    graph::GraphBuilder,
};

let mut builder = GraphBuilder::<f32>::new(44100.0, 512, 2);

// Constructor: new(mode, mono, invert_left, invert_right)
let router = builder.add(
    ChannelRouterBlock::new(ChannelMode::Stereo, false, false, false)
);
}

Constructor Parameters

ParameterTypeDescription
modeChannelModeChannel routing mode
monoboolSum to mono (L+R)/2 on both channels
invert_leftboolInvert left channel phase
invert_rightboolInvert right channel phase

Channel Modes

#![allow(unused)]
fn main() {
use bbx_dsp::blocks::ChannelMode;

ChannelMode::Stereo    // Pass through unchanged
ChannelMode::Left      // Left channel to both outputs
ChannelMode::Right     // Right channel to both outputs
ChannelMode::Swap      // Swap left and right
}

Mode Details

ModeLeft OutRight Out
StereoLeft InRight In
LeftLeft InLeft In
RightRight InRight In
SwapRight InLeft In

Port Layout

PortDirectionDescription
0InputLeft channel
1InputRight channel
0OutputLeft channel
1OutputRight channel

Usage Examples

Mono Summing

For mono compatibility checking:

#![allow(unused)]
fn main() {
use bbx_dsp::{
    blocks::{ChannelMode, ChannelRouterBlock},
    graph::GraphBuilder,
};

let mut builder = GraphBuilder::<f32>::new(44100.0, 512, 2);

// Route left to both channels
let mono = builder.add(
    ChannelRouterBlock::new(ChannelMode::Left, false, false, false)
);
}

Swap Channels

For correcting reversed cables:

#![allow(unused)]
fn main() {
use bbx_dsp::{
    blocks::{ChannelMode, ChannelRouterBlock},
    graph::GraphBuilder,
};

let mut builder = GraphBuilder::<f32>::new(44100.0, 512, 2);

let swap = builder.add(
    ChannelRouterBlock::new(ChannelMode::Swap, false, false, false)
);
}

Phase Inversion

For polarity correction or creative effects:

#![allow(unused)]
fn main() {
use bbx_dsp::{
    blocks::{ChannelMode, ChannelRouterBlock},
    graph::GraphBuilder,
};

let mut builder = GraphBuilder::<f32>::new(44100.0, 512, 2);

// Invert left channel phase only
let phase_flip = builder.add(
    ChannelRouterBlock::new(ChannelMode::Stereo, false, true, false)
);
}

True Mono Sum

Sum both channels to mono output:

#![allow(unused)]
fn main() {
use bbx_dsp::{
    blocks::{ChannelMode, ChannelRouterBlock},
    graph::GraphBuilder,
};

let mut builder = GraphBuilder::<f32>::new(44100.0, 512, 2);

// Enable mono summing
let mono_sum = builder.add(
    ChannelRouterBlock::new(ChannelMode::Stereo, true, false, false)
);
}

Default Passthrough

For a simple stereo passthrough with no modifications:

#![allow(unused)]
fn main() {
use bbx_dsp::{blocks::ChannelRouterBlock, graph::GraphBuilder};

let mut builder = GraphBuilder::<f32>::new(44100.0, 512, 2);

// Use default_new() for stereo passthrough
let passthrough = builder.add(ChannelRouterBlock::default_new());
}

Implementation Notes

  • Zero processing latency
  • No allocation during process
  • Simple sample copying/routing