RSCuteDSP
A Rust port of the Signalsmith DSP C++ library, providing various DSP (Digital Signal Processing) algorithms for audio and signal processing. This library implements the same high-quality algorithms as the original C++ library, optimized for Rust performance and ergonomics.
Features
- FFT: Fast Fourier Transform implementation optimized for sizes that are products of 2a * 3b, with both complex and real-valued implementations
- Filters: Biquad filters with various configurations (lowpass, highpass, bandpass, etc.) and design methods (Butterworth, cookbook)
- Delay Lines: Efficient delay line implementation with multiple interpolation methods (nearest, linear, cubic)
- Curves: Cubic curve interpolation with control over slope and curvature
- Windows: Window functions for spectral processing (Hann, Hamming, Kaiser, Blackman-Harris, etc.)
- Envelopes: LFOs and envelope generators with precise control and minimal aliasing
- Spectral Processing: Tools for spectral manipulation, phase vocoding, and frequency-domain operations
- Time Stretching: High-quality time stretching and pitch shifting using phase vocoder techniques
- STFT: Short-time Fourier transform implementation with overlap-add processing
- Mixing Utilities: Multi-channel mixing matrices and stereo-to-multi-channel conversion
- Linear Algebra: Expression template system for efficient vector operations
- no_std Support: Can be used in environments without the standard library, with optional
allocfeature - Spacing (Room Reverb): Simulate room acoustics with customizable geometry, early reflections, and multi-channel output
Installation
Add this to your Cargo.toml:
[]
= "0.0.2"
WebAssembly Support
This library supports compilation to WebAssembly for use in web browsers and Node.js, with full DSP functionality exposed.
To build for WASM (no-modules target for broad compatibility):
-
Install
wasm-pack: -
Build the WASM package:
-
Use in HTML/JavaScript (no-modules target):
CuteDSP WASM DemoOr try the included real-time demo:
wasm_demo.html
Usage Examples
FFT Example
use ;
use Complex;
Biquad Filter Example
use ;
Delay Line Example
use ;
Time Stretching and Pitch Shifting Example
use SignalsmithStretch;
Multichannel Mixing Example
use ;
Spacing (Room Reverb) Example
use ;
Advanced Usage
For more advanced usage examples, see the examples directory:
- FFT Example - Fast Fourier Transform
- Filter Example - Biquad filters
- Delay Example - Delay lines
- STFT Example - Short-time Fourier transform
- Stretch Example - Time stretching and pitch shifting
- Curves Example - Curve interpolation
- Envelopes Example - LFOs and envelope generators
- Linear Example - Linear operations
- Mix Example - Audio mixing utilities
- Performance Example - Performance optimizations
- Rates Example - Sample rate conversion
- Spectral Example - Spectral processing
- Windows Example - Window functions
Module Overview
FFT (fft module)
Provides Fast Fourier Transform implementations optimized for different use cases:
SimpleFFT: General purpose complex-to-complex FFTSimpleRealFFT: Optimized for real-valued inputs- Support for non-power-of-2 sizes (factorizable into 2a × 3b)
Filters (filters module)
Digital filter implementations:
Biquad: Second-order filter section with various design methods- Various filter types: lowpass, highpass, bandpass, notch, peaking, etc.
- Support for filter cascading and multi-channel processing
Delay (delay module)
Delay line utilities:
- Various interpolation methods (nearest, linear, cubic)
- Single and multi-channel delay lines
- Buffer abstractions for efficient memory usage
Spectral Processing (spectral module)
Frequency-domain processing tools:
- Magnitude/phase conversion utilities
- Phase vocoder techniques for pitch and time manipulation
- Frequency-domain filtering and manipulation
STFT (stft module)
Short-time Fourier transform processing:
- Overlap-add processing framework
- Window function application
- Spectral processing utilities
Stretch (stretch module)
Time stretching and pitch shifting:
- High-quality phase vocoder implementation using
SignalsmithStretch - Independent control of time and pitch
- Formant preservation and frequency mapping
- Real-time processing capabilities
Mix (mix module)
Multichannel mixing utilities:
- Orthogonal matrices (Hadamard, Householder) for efficient mixing
- Stereo to multichannel conversion
- Energy-preserving crossfading
Windows (windows module)
Window functions for spectral processing:
- Common window types (Hann, Hamming, Kaiser, etc.)
- Window design utilities
- Overlap handling and perfect reconstruction
Envelopes (envelopes module)
Low-frequency oscillators and envelope generators:
- Precise control with minimal aliasing
- Multiple waveform types
- Configurable frequency and amplitude
Linear (linear module)
Linear algebra utilities:
- Expression template system for efficient vector operations
- Optimized mathematical operations
Curves (curves module)
Curve interpolation:
- Cubic curve interpolation with control over slope and curvature
- Smooth parameter transitions
Rates (rates module)
Sample rate conversion:
- High-quality resampling algorithms
- Configurable quality settings
Spacing (spacing module)
Provides a customizable room reverb effect:
- Multi-tap delay network simulating early reflections
- 3D source and receiver positioning
- Adjustable room size, damping, diffusion, bass, decay, and cross-mix
- Suitable for spatial audio and immersive effects
Feature Flags
std(default): Use the Rust standard libraryalloc: Enable allocation without std (for no_std environments)
Performance
This library is designed with performance in mind and offers several optimizations:
- SIMD Opportunities: Code structure allows for SIMD optimizations where applicable
- Cache-Friendly Algorithms: Algorithms are designed to minimize cache misses
- Minimal Allocations: Operations avoid allocations during processing
- Trade-offs: Where appropriate, there are options to trade between quality and performance
For maximum performance:
- Use the largest practical buffer sizes for batch processing
- Reuse processor instances rather than creating new ones
- Consider using the
f32type for most audio applications unless higher precision is needed - Review the examples in
examples/perf_example.rsfor performance-critical applications
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Original C++ library: Signalsmith Audio DSP Library
- Signalsmith Audio's excellent technical blog with in-depth explanations of DSP concepts
- The comprehensive design documentation for the time stretching algorithm