PyTorch-based room impulse response (RIR) simulation toolkit for static and dynamic scenes.
Project description
TorchRIR
PyTorch-based room impulse response (RIR) simulation toolkit focused on a clean, modern API with GPU support. This project has been substantially assisted by AI using Codex.
[!WARNING] TorchRIR is under active development and may contain bugs or breaking changes. Please validate results for your use case. If you find bugs or have feature requests, please open an issue. Contributions are welcome.
Installation
pip install torchrir
CUDA CI (GitHub Actions)
- CUDA tests run in
.github/workflows/cuda-ci.ymlon a self-hosted runner with labels:self-hosted,linux,x64,cuda. - The workflow validates installation via
uv sync --group test, checkstorch.cuda.is_available(), runstests/test_device_parity.pywith-k cuda, and then tries to installgpuRIRfrom GitHub. - If
gpuRIRinstalls successfully, the workflow runstests/test_compare_gpurir.py(static + dynamic RIR comparisons). If installation fails, those comparison tests are skipped without failing the whole CUDA CI job.
Examples
examples/static.py: fixed sources/mics with configurable mic count (default: binaural).
uv run python examples/static.py --plotexamples/dynamic_src.py: moving sources, fixed mics.
uv run python examples/dynamic_src.py --plotexamples/dynamic_mic.py: fixed sources, moving mics.
uv run python examples/dynamic_mic.py --plotexamples/cli.py: unified CLI for static/dynamic scenes, JSON/YAML configs.
uv run python examples/cli.py --mode static --plotexamples/build_dynamic_dataset.py: small dynamic dataset generator (CMU ARCTIC / LibriSpeech; fixed room/mics, randomized source motion).
uv run python examples/build_dynamic_dataset.py --dataset cmu_arctic --num-scenes 4 --num-sources 2examples/benchmark_device.py: CPU/GPU benchmark for RIR simulation.
uv run python examples/benchmark_device.py --dynamic
Core API Overview
- Geometry:
Room,Source,MicrophoneArray - Static RIR:
torchrir.sim.simulate_rir - Dynamic RIR:
torchrir.sim.simulate_dynamic_rir - Dynamic convolution:
torchrir.signal.DynamicConvolver - Metadata export:
torchrir.io.build_metadata,torchrir.io.save_metadata_json
Module Layout (for contributors)
torchrir.sim: simulation backends (ISM implementation lives undertorchrir.sim.ism)torchrir.signal: convolution utilities and dynamic convolvertorchrir.geometry: array geometries, sampling, trajectoriestorchrir.viz: plotting and animation helperstorchrir.models: room/scene/result data modelstorchrir.io: audio I/O and metadata serialization (wav-only load/save/info with backend selection)torchrir.util: shared math/tensor/device helperstorchrir.logging: logging utilitiestorchrir.config: simulation configuration objects
from torchrir import MicrophoneArray, Room, Source
from torchrir.sim import simulate_rir
from torchrir.signal import DynamicConvolver
room = Room.shoebox(size=[6.0, 4.0, 3.0], fs=16000, beta=[0.9] * 6)
sources = Source.from_positions([[1.0, 2.0, 1.5]])
mics = MicrophoneArray.from_positions([[2.0, 2.0, 1.5]])
rir = simulate_rir(room=room, sources=sources, mics=mics, max_order=6, tmax=0.3)
# For dynamic scenes, compute rirs with torchrir.sim.simulate_dynamic_rir and convolve:
# y = DynamicConvolver(mode="trajectory").convolve(signal, rirs)
For detailed documentation, see the docs under docs/ and Read the Docs.
Future Work
- Ray tracing backend: implement
torchrir.experimental.RayTracingSimulatorwith frequency-dependent absorption/scattering. - Dataset expansion: add additional dataset integrations beyond CMU ARCTIC (see
torchrir.experimental.TemplateDataset), including torchaudio datasets (e.g., LibriSpeech, VCTK, LibriTTS, SpeechCommands, CommonVoice, GTZAN, MUSDB-HQ).
Related Libraries
Related Library Comparison (Quick View)
Dynamic Simulation
| Feature | torchrir |
gpuRIR |
pyroomacoustics |
rir-generator |
|---|---|---|---|---|
| 🎯 Dynamic Sources | ✅ | 🟡 Single moving source | 🟡 Manual loop | ❌ |
| 🎤 Dynamic Microphones | ✅ | ❌ | 🟡 Manual loop | ❌ |
| 🖥️ CPU | ✅ | ❌ | ✅ | ✅ |
| 🧮 CUDA | ✅ | ✅ | ❌ | ❌ |
| 🍎 MPS | ✅ | ❌ | ❌ | ❌ |
| 📊 Scene Plot | ✅ | ❌ | ✅ | ❌ |
| 🎞️ Dynamic Scene GIF | ✅ | ❌ | 🟡 Manual animation script | ❌ |
| 🗂️ Dataset Build | ✅ | ❌ | ✅ | ❌ |
Legend:
✅native support🟡manual setup❌unavailable
Detailed notes and equations: docs/comparisons.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchrir-0.6.1.tar.gz.
File metadata
- Download URL: torchrir-0.6.1.tar.gz
- Upload date:
- Size: 51.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.1 {"installer":{"name":"uv","version":"0.10.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12e15ccb119736afd8c2fd93b50fe8d22780fc949e30dc5e97fcb72df12a3282
|
|
| MD5 |
883293e26a766b66fc7f6a4c1e9023a0
|
|
| BLAKE2b-256 |
678e87dcd0844596e0755bfb821e3946fb88d6e869578d69e9b83cd4845d2afb
|
File details
Details for the file torchrir-0.6.1-py3-none-any.whl.
File metadata
- Download URL: torchrir-0.6.1-py3-none-any.whl
- Upload date:
- Size: 62.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.1 {"installer":{"name":"uv","version":"0.10.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bff2e5cd22578e4385ed14c8ee47c972e357f8b771be9bf9fdcb7459aeae372e
|
|
| MD5 |
2c540032f4e03b4e737c9c35e7b02b79
|
|
| BLAKE2b-256 |
dbc5335dcd68f05df2d345c62d1003cb5de92f1c8713bfac503c9943bfd2d943
|