# math-rir
Room Impulse Response analysis using the SSIR (Spatial Segmentation of Impulse Response) method.
Based on: Pawlak & Lee, "Spatial segmentation of impulse response for room reflection analysis and auralization", Applied Acoustics 249 (2026).
## What it does
Segments a measured Room Impulse Response (RIR) into consecutive, variable-length sound events (direct sound + early reflections), each with a constant direction of arrival (DOA). This preserves the full temporal energy profile while enabling per-reflection analysis and manipulation.
## Key algorithms
- **Direct sound onset detection** (Algorithm 1 from paper): log-magnitude peak detection with 11 dB threshold
- **Local Energy Ratio reflection detection**: 1ms analysis windows, median energy threshold, DOA/TOA validation
- **Onset refinement**: per-segment onset detection within pre-onset windows
- **Mixing time estimation**: Abel & Huang echo density method
## API
```rust
use math_rir::{analyze_rir, analyze_srir, SsirConfig};
// Mono RIR (energy-based detection only)
let result = analyze_rir(&rir_samples, &SsirConfig::new(48000.0));
// B-format SRIR (full DOA estimation + validation)
let result = analyze_srir(&[&w, &x, &y, &z], &SsirConfig::new(48000.0));
println!("{} events, mixing time {:.1}ms",
result.num_events(), result.mixing_time_ms());
```
## Used by
- `sotf-plugin-binaural`: SSIR-analyzed measured room reflections with per-reflection HRTF
- `autoeq/roomeq`: SSIR-informed correction weights for room EQ optimization