Expand description
IIR and FIR filter library for audio processing.
This crate provides digital filter implementations for audio signal processing, including biquad IIR filters, FIR filters, SVF filters, and crossovers.
§Generic precision
All filter types are generic over FilterFloat (f32 or f64), defaulting to
f64 for backward compatibility. Use f32 when throughput matters more than
precision (e.g., real-time processing of many channels). Convenience aliases like
BiquadF32, SvfFilterF32, etc. are provided.
§Features
- Biquad IIR filters: Peak, Lowpass, Highpass, Lowshelf, Highshelf, Bandpass, Notch
- SVF filters: Zero-delay feedback topology for artifact-free parameter changes
- FIR filters: Windowed sinc filters with various window types
- Crossovers: Linkwitz-Riley IIR and linear-phase FIR crossovers
- Offline filtering: Zero-phase
filtfiltfor analysis (no phase distortion) - Frequency response computation: For both IIR and FIR filters
- Multiple output formats: APO, RME, AU Preset
§Example
use math_audio_iir_fir::{Biquad, BiquadFilterType};
// f64 (default)
let filter = Biquad::new(BiquadFilterType::Peak, 1000.0, 48000.0, 2.0, 3.0);
let response_db: f64 = filter.log_result(1000.0);
assert!((response_db - 3.0_f64).abs() < 0.1);
// f32 — same API, lower precision, higher throughput
let filter_f32 = Biquad::<f32>::new(BiquadFilterType::Peak, 1000.0, 48000.0, 2.0, 3.0);
let response_f32: f32 = filter_f32.log_result(1000.0);
assert!((response_f32 - 3.0_f32).abs() < 0.5);§math-iir-fir (lib: math_audio_iir_fir)
IIR, FIR, and SVF filter implementations for audio processing, generic over f32 and f64.
Version: 0.5.13
§Generic precision
All filter types (Biquad, SvfFilter, Fir, BiquadBank) are generic over FilterFloat and default to f64. Use f32 when throughput matters more than precision (e.g., real-time multi-channel processing). Convenience aliases like BiquadF32, SvfFilterF32, etc. are provided.
§Features
- Biquad Filters: Peak, Lowpass, Highpass, Lowshelf, Highshelf, Bandpass, Notch, AllPass
- SVF (State Variable Filter): Zero-delay feedback topology (Zavalishin TPT) for artifact-free parameter changes
- FIR Filters: Windowed sinc filter bank for linear-phase filtering, FIR design from frequency response, Kirkeby correction, pre-ringing suppression
- Crossovers: Linkwitz-Riley 4th-order IIR and linear-phase FIR crossovers
- Offline filtering: Zero-phase
filtfiltandsosfiltfor analysis - PEQ (Parametric Equalizer): Multi-band parametric equalization with SPL response computation, loudness compensation, and 9 export formats (APO, RME, AU Preset, CamillaDSP, EasyEffects, PipeWire, Roon, Wavelet)
- Filter Design: Butterworth and Linkwitz-Riley lowpass/highpass
- Phase Smoothing: Phase unwrapping, smoothing via group delay, complex interpolation
- Warped LPC and Kautz filters: Advanced filter design for room acoustics
§Filter Types
§Biquad Filter Types
BiquadFilterType::LowpassBiquadFilterType::HighpassBiquadFilterType::HighpassVariableQBiquadFilterType::BandpassBiquadFilterType::PeakBiquadFilterType::NotchBiquadFilterType::LowshelfBiquadFilterType::Highshelf
§Usage Examples
§Basic Biquad Filter
use math_audio_iir_fir::{Biquad, BiquadFilterType};
// f64 (default)
let filter = Biquad::new(
BiquadFilterType::Peak,
1000.0, // frequency
48000.0, // sample rate
1.0, // Q factor
3.0 // gain in dB
);
let response_db = filter.log_result(1000.0);
// f32 — same API, less precision, higher throughput
let mut filter_f32 = Biquad::<f32>::new(BiquadFilterType::Peak, 1000.0, 48000.0, 1.0, 3.0);
let output = filter_f32.process(0.5f32);§Parametric EQ (PEQ)
use math_audio_iir_fir::{Biquad, BiquadFilterType, Peq, peq_spl, peq_preamp_gain, peq_format_apo};
use ndarray::Array1;
let mut peq: Peq = Vec::new();
let hp = Biquad::new(BiquadFilterType::Highpass, 80.0, 48000.0, 0.707, 0.0);
peq.push((1.0, hp));
let peak = Biquad::new(BiquadFilterType::Peak, 1000.0, 48000.0, 1.5, 4.0);
peq.push((1.0, peak));
let hs = Biquad::new(BiquadFilterType::Highshelf, 8000.0, 48000.0, 0.8, -2.0);
peq.push((1.0, hs));
let freqs = Array1::logspace(10.0, 20.0_f64.log10(), 20000.0_f64.log10(), 1000);
let response = peq_spl(&freqs, &peq);
let preamp = peq_preamp_gain(&peq);
let apo_config = peq_format_apo("My Custom EQ", &peq);§Filter Design
use math_audio_iir_fir::{peq_butterworth_lowpass, peq_linkwitzriley_highpass};
let lp_filter = peq_butterworth_lowpass(4, 2000.0, 48000.0);
let hp_filter = peq_linkwitzriley_highpass(4, 2000.0, 48000.0);§Key Types
Peq<T>—Vec<(T, Biquad<T>)>where the first element is the weight/amplitude multiplierBiquadBank<T>— Pack 2 or 4 biquad operations per clock depending on hardwareSvfFilter<T>— Zero-delay feedback state variable filterFir<T>/FirCrossover— Linear-phase FIR filtering
§Dependencies
ndarray,num-traits— Numerical arraysrustfft,num-complex— FFT for FIR designserde— Serializationhound— WAV I/O for filter testing
§Testing
cargo test -p math-iir-fir --lib
cargo check -p math-iir-fir && cargo clippy -p math-iir-fir§License
See the root workspace LICENSE file.
Re-exports§
pub use svf::SvfFilter;pub use svf::SvfFilterType;pub use fir_crossover::DEFAULT_FIR_CROSSOVER_TAPS;pub use fir_crossover::FirCrossover;pub use fir_crossover::MultibandFirCrossover;pub use lr4_crossover::CROSSOVER_PRESETS;pub use lr4_crossover::Lr4Crossover;pub use lr4_crossover::MultibandLr4Crossover;pub use lr8_crossover::Lr8Crossover;pub use lr8_crossover::MultibandLr8Crossover;
Modules§
- denormals
- Utilities for handling floating-point denormals (subnormals).
- filtfilt
- Forward-reverse (zero-phase) filtering for offline signal processing. Forward-reverse (zero-phase) filtering for offline signal processing.
- fir_
crossover - Linear-phase FIR crossover (windowed sinc).
- lr4_
crossover - Linkwitz-Riley 4th-order IIR crossover.
- lr8_
crossover - Linkwitz-Riley 8th-order IIR crossover (48 dB/octave).
- svf
- Zero-Delay Feedback State Variable Filter (Zavalishin TPT topology). Zero-Delay Feedback State Variable Filter (ZDF/SVF)
Structs§
- Biquad
- Represents a single biquad IIR filter.
- Biquad
Bank - A bank of biquad filters sharing coefficients but with independent per-channel state.
- Biquad
Coefficients - Biquad filter coefficients for external interpolation.
- Filter
Row - Represents a single filter in a parametric equalizer.
- Fir
- Represents a single FIR filter.
- FirDesign
Config - Configuration for FIR filter generation
- Kautz
Filter - Complete Kautz filter: parallel bank of
KautzSections. - Kautz
Section - A second-order Kautz section with pole tuned to a specific frequency.
- PreRinging
Analysis - Analysis results for pre-ringing in an FIR filter.
- PreRinging
Config - Configuration for pre-ringing suppression on FIR filters.
- Warped
Biquad - Warped biquad IIR filter.
Enums§
- Biquad
Filter Type - Filter types for biquad filters
- FirFilter
Type - FIR filter types
- FirPhase
- Phase type for FIR generation
- IirError
- Errors that can occur during IIR filter operations.
- Window
Type - Window function types for FIR filter design
Constants§
- AUDIBLE_
MAX_ FREQ - Upper bound of human hearing (Hz).
- AUDIBLE_
MIN_ FREQ - Lower bound of human hearing (Hz).
- DEFAULT_
Q_ HIGH_ LOW_ PASS - Default Q factor for high/low pass filters
- DEFAULT_
Q_ HIGH_ LOW_ SHELF - Default Q factor for high/low shelf filters
Traits§
- Filter
Float - Trait bound for the numeric type used throughout the filter crate.
Functions§
- analyze_
pre_ ringing - Analyze pre-ringing in an FIR impulse response.
- bark_
lambda - Compute the Bark-scale warping coefficient for a given sample rate.
- bw2q
- Converts bandwidth in octaves to a Q factor.
- compute_
fir_ bank_ response - Compute the combined FIR bank response (in dB) on a given frequency grid.
- compute_
peq_ response - Compute the combined PEQ response (in dB) on a given frequency grid for a Peq.
- fir_
bank_ preamp_ gain - Calculate the recommended preamp gain to avoid clipping for a FIR bank.
- fir_
bank_ spl - Compute the FIR bank SPL response at given frequencies.
- generate_
fir_ from_ response - Generate an FIR filter to match a target frequency response
- generate_
kirkeby_ correction - Generate Kirkeby regularized FIR correction filter
- generate_
window - Generates a window function for FIR filter design.
- interpolate_
phase_ complex - Interpolate phase in the complex domain to avoid wrap artifacts
- peq_
allpass - Create All-Pass filter
- peq_
butterworth_ highpass - Create Butterworth highpass filter
- peq_
butterworth_ lowpass - Create Butterworth lowpass filter
- peq_
butterworth_ q - Compute Q values for Butterworth filters
- peq_
equal - Check if two PEQs are equal
- peq_
format_ apo - Format PEQ as APO configuration string
- peq_
format_ aupreset - Format PEQ as Apple AUNBandEQ preset (aupreset) plist XML
- peq_
format_ camilladsp - Format a PEQ as a CamillaDSP YAML configuration.
- peq_
format_ easyeffects - Format a PEQ as an EasyEffects JSON preset.
- peq_
format_ pipewire - Format a PEQ as a PipeWire filter-chain SPA-JSON configuration.
- peq_
format_ rme_ channel - Format PEQ as RME TotalMix channel preset XML
- peq_
format_ rme_ room - Format PEQ as RME TotalMix room EQ preset XML (dual channel)
- peq_
format_ roon - Format a PEQ as a Roon DSP parametric EQ preset (JSON).
- peq_
format_ wavelet - Format a PEQ as a Wavelet GraphicEQ string.
- peq_
linkwitzriley_ highpass - Create Linkwitz-Riley highpass filter
- peq_
linkwitzriley_ lowpass - Create Linkwitz-Riley lowpass filter
- peq_
linkwitzriley_ q - Compute Q values for Linkwitz-Riley filters
- peq_
loudness_ gain - Compute loudness-weighted gain adjustment for PEQ to maintain spectral balance
- peq_
preamp_ gain - Compute preamp gain for a PEQ: well adapted to computers
- peq_
preamp_ gain_ max - Compute preamp gain for a PEQ and look at the worst case
- peq_
print - Print a formatted table of the parametric EQ filters from a Peq.
- peq_spl
- Compute SPL for each frequency given a PEQ
- q2bw
- Converts a Q factor to bandwidth in octaves.
- save_
fir_ to_ wav - Save FIR coefficients to a WAV file (32-bit float mono)
- smooth_
phase_ via_ group_ delay - Smooth phase via group delay smoothing
- suppress_
pre_ ringing - Suppress pre-ringing in an FIR impulse response.
- unwarp_
frequency - Map a warped frequency back to the physical frequency domain.
- unwrap_
phase - Unwrap phase by removing 2π discontinuities
- warp_
frequency - Map a physical frequency to the warped frequency domain.
Type Aliases§
- Biquad
Bank F32 - 32-bit biquad bank.
- Biquad
Coefficients F32 - 32-bit biquad coefficients.
- Biquad
F32 - 32-bit biquad filter.
- FirBank
- Type alias for a collection of weighted FIR filters
- FirBank
F32 - 32-bit FIR filter bank.
- FirCrossover
F32 - 32-bit FIR crossover.
- FirF32
- 32-bit FIR filter.
- Lr4Crossover
F32 - 32-bit LR4 crossover.
- Lr8Crossover
F32 - 32-bit LR8 crossover.
- Multiband
FirCrossover F32 - 32-bit multiband FIR crossover.
- Multiband
Lr4Crossover F32 - 32-bit multiband LR4 crossover.
- Multiband
Lr8Crossover F32 - 32-bit multiband LR8 crossover.
- Peq
- Parametric EQ filter chain: a vector of (gain, Biquad) pairs.
- PeqF32
- 32-bit parametric EQ chain.
- Result
- A specialized
Resulttype for IIR operations. - SvfFilter
F32 - 32-bit SVF filter.