Skip to main content

PyTorch-based room impulse response (RIR) simulation toolkit for static and dynamic scenes.

Project description

TorchRIR

A PyTorch-based room impulse response (RIR) simulation toolkit with a clean API and GPU support. This project has been developed with substantial assistance from 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

Library Comparison

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 โœ… โŒ โœ… โŒ
๐ŸŽ›๏ธ Signal Processing โŒ Scope out โŒ โœ… โŒ
๐Ÿงฑ Non-shoebox Geometry ๐Ÿšง Candidate โŒ โœ… โŒ
๐ŸŒ Geometric Acoustics ๐Ÿšง Candidate โŒ โœ… โŒ

Legend: โœ… native support, ๐ŸŸก manual setup, ๐Ÿšง candidate (not yet implemented), โŒ unavailable

For detailed notes and equations, see Read the Docs: Library Comparisons.

CUDA CI (GitHub Actions)

  • CUDA tests run in .github/workflows/cuda-ci.yml on a self-hosted runner with labels: self-hosted, linux, x64, cuda.
  • The workflow validates installation via uv sync --group test, checks torch.cuda.is_available(), runs tests/test_device_parity.py with -k cuda, and then tries to install gpuRIR from GitHub.
  • If gpuRIR installs successfully, the workflow runs tests/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 and microphones with configurable mic count (default: binaural).
    uv run python examples/static.py --plot
  • examples/dynamic_src.py: moving sources, fixed microphones.
    uv run python examples/dynamic_src.py --plot
  • examples/dynamic_mic.py: fixed sources, moving microphones.
    uv run python examples/dynamic_mic.py --plot
  • examples/cli.py: unified CLI for static/dynamic scenes with JSON/YAML configs.
    uv run python examples/cli.py --mode static --plot
  • examples/build_dynamic_dataset.py: small dynamic dataset generation script (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 2
  • examples/benchmark_device.py: CPU/GPU benchmark for RIR simulation.
    uv run python examples/benchmark_device.py --dynamic

Dataset Notices

Core API Overview

  • Geometry: Room, Source, MicrophoneArray
  • Scene models: StaticScene, DynamicScene (Scene is deprecated)
  • Static RIR: torchrir.sim.simulate_rir
  • Dynamic RIR: torchrir.sim.simulate_dynamic_rir
  • Simulator object: torchrir.sim.ISMSimulator(max_order=..., tmax=... | nsample=...)
  • Dynamic convolution: torchrir.signal.DynamicConvolver
  • Audio I/O:
    • wav-specific: torchrir.io.load_wav, torchrir.io.save_wav, torchrir.io.info_wav
    • backend-supported formats: torchrir.io.load_audio, torchrir.io.save_audio, torchrir.io.info_audio
    • metadata-preserving: torchrir.io.AudioData, torchrir.io.load_audio_data
  • Metadata export: torchrir.io.build_metadata, torchrir.io.save_metadata_json

Module Layout (for contributors)

  • torchrir.sim: simulation backends (ISM implementation lives under torchrir.sim.ism)
  • torchrir.signal: convolution utilities and dynamic convolver
  • torchrir.geometry: array geometries, sampling, trajectories
  • torchrir.viz: plotting and animation helpers
  • torchrir.models: room/scene/result data models
  • torchrir.io: audio I/O and metadata serialization (*_wav for wav-only, *_audio for backend-supported formats)
  • torchrir.util: shared math/tensor/device helpers
  • torchrir.logging: logging utilities
  • torchrir.config: simulation configuration objects

Design Notes

  • Scene typing is explicit: use StaticScene for fixed geometry and DynamicScene for trajectory-based simulation.
  • DynamicScene accepts tensor-like trajectories (e.g., lists) and normalizes them to tensors internally.
  • Scene remains as a backward-compatibility wrapper and emits DeprecationWarning.
  • Scene.validate() performs validation without emitting additional deprecation warnings.
  • ISMSimulator fails fast when max_order or tmax conflicts with the provided SimulationConfig.
  • Model dataclasses are frozen, but tensor payloads remain mutable (shallow immutability).
  • torchrir.load / torchrir.save and torchrir.io.load / save / info are deprecated compatibility aliases.
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: Read the Docs

Future Work

  • Advanced room geometry pipeline beyond shoebox rooms (e.g., irregular polygons/meshes and boundary handling).
    Motivation: pyroomacoustics#393, pyroomacoustics#405
  • General reflection/path capping controls (e.g., first-K, strongest-K, or energy-threshold-based path selection).
    Motivation: pyroomacoustics#338
  • Microphone hardware response modeling (frequency response, sensitivity, and self-noise).
    Motivation: pyroomacoustics#394
  • Near-field speech source modeling for more realistic close-talk scenarios.
    Motivation: pyroomacoustics#417
  • Integrated 3D spatial response visualization (e.g., array/directivity beam-pattern rendering).
    Motivation: pyroomacoustics#397

Related Libraries

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchrir-0.7.0.tar.gz (59.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchrir-0.7.0-py3-none-any.whl (69.9 kB view details)

Uploaded Python 3

File details

Details for the file torchrir-0.7.0.tar.gz.

File metadata

  • Download URL: torchrir-0.7.0.tar.gz
  • Upload date:
  • Size: 59.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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

Hashes for torchrir-0.7.0.tar.gz
Algorithm Hash digest
SHA256 17aba5a3218ddff424c3100879c31bbf97a836c0b0e5ff6cf35b1ecd953574d0
MD5 a541f37f47c88749a6d77f9ce8bed199
BLAKE2b-256 d3f27949c9d5411f84fa9048f2060d9aa6a88b4be1d666cd22a4833a7311d198

See more details on using hashes here.

File details

Details for the file torchrir-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: torchrir-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 69.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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

Hashes for torchrir-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cf2622dbd97b4ec7ed0d3e76d971e6cfacd2a172691b0e949cc11950c5805a1
MD5 9640728473192d5dbee331f4ef7d4efb
BLAKE2b-256 333925756d0d1381ebc4547f6e768c17fc8396fd73f511a5af480ce02426d2e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page