bs2b
A modern Rust implementation of the Bauer stereophonic-to-binaural (bs2b) crossfeed DSP.
This crate ports the reference bs2b algorithm into an idiomatic, type-safe API for real-time and offline audio processing.
Features
- bs2b-compatible filter math and crossfeed behavior.
- Stateful processor suitable for streaming audio.
- Interleaved and planar stereo processing APIs.
- Supports common PCM sample formats:
f32,f64,i32,u32,i16,u16,i8,u8. - Built-in preset levels:
DEFAULT,CMOY,JMEIER. - Benchmarks (Criterion) and tests included.
Feature flags:
std(default): enablesstd::error::Errorintegration forBs2bError.streaming: enables optional adapters for callback/iterator streaming APIs.- disabling default features (
default-features = false) builds inno_stdmode.
Installation
no_std mode:
[]
= { = "0.2", = false }
Quick Start
use ;
API Guidelines
- Use one
Bs2binstance per stereo stream. The processor is stateful. - Call
set_sample_rateif stream sample rate changes. This clears internal history. - Call
clearafter seeks, discontinuities, or stream restarts. - Use
process_interleavedfor contiguous LR data; useprocess_planarfor split channels. - If your pipeline uses unsigned PCM, this crate applies the same signed-bias handling as the C reference implementation.
Choosing a Level
Level::DEFAULT: Closest to virtual speakers at ±30° azimuth, ~3 meters away. A moderate crossfeed.Level::CMOY: Most popular setting. Matches the parameters of Chu Moy's well-known analog crossfeed circuit.Level::JMEIER: Most subtle — makes the smallest changes to the original signal. Intended for relaxed listening. Matches Jan Meier's CORDA amplifier crossfeed.- Custom profile:
use Level;
let level = new?; // cut_frequency_hz, feed_db_tenths
Valid ranges:
cut_frequency_hz: 300..=2000feed_db_tenths: 10..=150
Real-Time Usage Notes
process_frameis available for callback-style per-frame processing.streaming::CallbackAdaptercan process interleaved callback buffers (cpal-style).streaming::StereoSourceAdaptercan wrap interleaved sample iterators (rodio-style).- The library does no allocations while processing audio.
- The processor is
Cloneif you need independent state branches.
Streaming Adapters
Enable the feature:
[]
= { = "0.2", = ["streaming"] }
cpal-style callback buffer processing:
use ;
rodio-style interleaved iterator processing:
use ;
Testing and Benchmarks
To regenerate C-reference golden vectors used by integration tests:
References
- Official project: bs2b.sourceforge.net
- Reference C implementation used for algorithm parity: Debian source mirror
License
MIT