torchrir 0.1.2__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- torchrir/__init__.py +16 -1
- torchrir/animation.py +17 -14
- torchrir/core.py +176 -35
- torchrir/datasets/__init__.py +9 -3
- torchrir/datasets/base.py +43 -3
- torchrir/datasets/cmu_arctic.py +9 -20
- torchrir/datasets/collate.py +90 -0
- torchrir/datasets/librispeech.py +175 -0
- torchrir/datasets/template.py +3 -1
- torchrir/datasets/utils.py +23 -1
- torchrir/dynamic.py +3 -1
- torchrir/plotting.py +13 -6
- torchrir/plotting_utils.py +4 -1
- torchrir/room.py +2 -38
- torchrir/scene_utils.py +6 -2
- torchrir/signal.py +24 -10
- torchrir/simulators.py +12 -4
- torchrir/utils.py +1 -1
- torchrir-0.2.0.dist-info/METADATA +70 -0
- torchrir-0.2.0.dist-info/RECORD +30 -0
- torchrir-0.1.2.dist-info/METADATA +0 -271
- torchrir-0.1.2.dist-info/RECORD +0 -28
- {torchrir-0.1.2.dist-info → torchrir-0.2.0.dist-info}/WHEEL +0 -0
- {torchrir-0.1.2.dist-info → torchrir-0.2.0.dist-info}/licenses/LICENSE +0 -0
- {torchrir-0.1.2.dist-info → torchrir-0.2.0.dist-info}/licenses/NOTICE +0 -0
- {torchrir-0.1.2.dist-info → torchrir-0.2.0.dist-info}/top_level.txt +0 -0
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: torchrir
|
|
3
|
-
Version: 0.1.2
|
|
4
|
-
Summary: PyTorch-based room impulse response (RIR) simulation toolkit for static and dynamic scenes.
|
|
5
|
-
Project-URL: Repository, https://github.com/taishi-n/torchrir
|
|
6
|
-
Requires-Python: >=3.10
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
License-File: LICENSE
|
|
9
|
-
License-File: NOTICE
|
|
10
|
-
Requires-Dist: numpy>=2.2.6
|
|
11
|
-
Requires-Dist: torch>=2.10.0
|
|
12
|
-
Dynamic: license-file
|
|
13
|
-
|
|
14
|
-
# TorchRIR
|
|
15
|
-
|
|
16
|
-
PyTorch-based room impulse response (RIR) simulation toolkit focused on a clean, modern API with GPU support.
|
|
17
|
-
This project has been substantially assisted by AI using Codex.
|
|
18
|
-
|
|
19
|
-
## License
|
|
20
|
-
Apache-2.0. See `LICENSE` and `NOTICE`.
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
```bash
|
|
24
|
-
pip install torchrir
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Current Capabilities
|
|
28
|
-
- ISM-based static and dynamic RIR simulation (2D/3D shoebox rooms).
|
|
29
|
-
- Directivity patterns: `omni`, `cardioid`, `hypercardioid`, `subcardioid`, `bidir` with orientation handling.
|
|
30
|
-
- Acoustic parameters: `beta` or `t60` (Sabine), optional diffuse tail via `tdiff`.
|
|
31
|
-
- Dynamic convolution via `DynamicConvolver` (`trajectory` or `hop` modes).
|
|
32
|
-
- GPU acceleration for ISM accumulation (CUDA/MPS; MPS disables LUT).
|
|
33
|
-
- Dataset utilities with CMU ARCTIC support and example pipelines.
|
|
34
|
-
- Plotting utilities for static and dynamic scenes.
|
|
35
|
-
- Metadata export helpers for time axis, DOA, and array attributes (JSON-ready).
|
|
36
|
-
- Unified CLI with JSON/YAML config and deterministic flag support.
|
|
37
|
-
|
|
38
|
-
## Example Usage
|
|
39
|
-
```bash
|
|
40
|
-
# CMU ARCTIC + static RIR (fixed sources/mics)
|
|
41
|
-
uv run python examples/static.py --plot
|
|
42
|
-
|
|
43
|
-
# Dynamic RIR demos
|
|
44
|
-
uv run python examples/dynamic_mic.py --plot
|
|
45
|
-
uv run python examples/dynamic_src.py --plot
|
|
46
|
-
uv run python examples/dynamic_mic.py --gif
|
|
47
|
-
uv run python examples/dynamic_src.py --gif
|
|
48
|
-
|
|
49
|
-
# Unified CLI
|
|
50
|
-
uv run python examples/cli.py --mode static --plot
|
|
51
|
-
uv run python examples/cli.py --mode dynamic_mic --plot
|
|
52
|
-
uv run python examples/cli.py --mode dynamic_src --plot
|
|
53
|
-
uv run python examples/cli.py --mode dynamic_mic --gif
|
|
54
|
-
uv run python examples/dynamic_mic.py --gif --gif-fps 12
|
|
55
|
-
|
|
56
|
-
# Config + deterministic
|
|
57
|
-
uv run python examples/cli.py --mode static --deterministic --seed 123 --config-out outputs/cli.json
|
|
58
|
-
uv run python examples/cli.py --config-in outputs/cli.json
|
|
59
|
-
```
|
|
60
|
-
GIF FPS is auto-derived from signal duration and RIR steps unless overridden with `--gif-fps`.
|
|
61
|
-
For 3D rooms, an additional `*_3d.gif` is saved.
|
|
62
|
-
YAML configs are supported when `PyYAML` is installed.
|
|
63
|
-
```bash
|
|
64
|
-
# YAML config
|
|
65
|
-
uv run python examples/cli.py --mode static --config-out outputs/cli.yaml
|
|
66
|
-
uv run python examples/cli.py --config-in outputs/cli.yaml
|
|
67
|
-
```
|
|
68
|
-
`examples/cli_example.yaml` provides a ready-to-use template.
|
|
69
|
-
Examples also save `*_metadata.json` alongside audio outputs.
|
|
70
|
-
|
|
71
|
-
```python
|
|
72
|
-
from torchrir import DynamicConvolver, MicrophoneArray, Room, Source, simulate_rir
|
|
73
|
-
|
|
74
|
-
room = Room.shoebox(size=[6.0, 4.0, 3.0], fs=16000, beta=[0.9] * 6)
|
|
75
|
-
sources = Source.positions([[1.0, 2.0, 1.5]])
|
|
76
|
-
mics = MicrophoneArray.positions([[2.0, 2.0, 1.5]])
|
|
77
|
-
|
|
78
|
-
rir = simulate_rir(
|
|
79
|
-
room=room,
|
|
80
|
-
sources=sources,
|
|
81
|
-
mics=mics,
|
|
82
|
-
max_order=6,
|
|
83
|
-
tmax=0.3,
|
|
84
|
-
device="auto",
|
|
85
|
-
)
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
```python
|
|
89
|
-
from torchrir import DynamicConvolver
|
|
90
|
-
|
|
91
|
-
# Trajectory-mode dynamic convolution
|
|
92
|
-
y = DynamicConvolver(mode="trajectory").convolve(signal, rirs)
|
|
93
|
-
|
|
94
|
-
# Hop-mode dynamic convolution
|
|
95
|
-
y = DynamicConvolver(mode="hop", hop=1024).convolve(signal, rirs)
|
|
96
|
-
```
|
|
97
|
-
Dynamic convolution is exposed via `DynamicConvolver` only (no legacy function wrappers).
|
|
98
|
-
|
|
99
|
-
## Limitations and Potential Errors
|
|
100
|
-
- Ray tracing and FDTD simulators are placeholders and raise `NotImplementedError`.
|
|
101
|
-
- `TemplateDataset` methods are not implemented and will raise `NotImplementedError`.
|
|
102
|
-
- `simulate_rir`/`simulate_dynamic_rir` require `max_order` (or `SimulationConfig.max_order`) and either `nsample` or `tmax`.
|
|
103
|
-
- Non-`omni` directivity requires orientation; mismatched shapes raise `ValueError`.
|
|
104
|
-
- `beta` must have 4 (2D) or 6 (3D) elements; invalid sizes raise `ValueError`.
|
|
105
|
-
- `simulate_dynamic_rir` requires `src_traj` and `mic_traj` to have matching time steps.
|
|
106
|
-
- Dynamic simulation currently loops per time step; very long trajectories can be slow.
|
|
107
|
-
- MPS disables the sinc LUT path (falls back to direct sinc), which can be slower and slightly different numerically.
|
|
108
|
-
- Deterministic mode is best-effort; some backends may still be non-deterministic.
|
|
109
|
-
- YAML configs require `PyYAML`; otherwise a `ModuleNotFoundError` is raised.
|
|
110
|
-
- CMU ARCTIC downloads require network access.
|
|
111
|
-
- GIF animation output requires Pillow (via matplotlib animation writer).
|
|
112
|
-
|
|
113
|
-
### Dataset-agnostic utilities
|
|
114
|
-
```python
|
|
115
|
-
from torchrir import (
|
|
116
|
-
CmuArcticDataset,
|
|
117
|
-
binaural_mic_positions,
|
|
118
|
-
clamp_positions,
|
|
119
|
-
load_dataset_sources,
|
|
120
|
-
sample_positions,
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
def dataset_factory(speaker: str | None):
|
|
124
|
-
spk = speaker or "bdl"
|
|
125
|
-
return CmuArcticDataset("datasets/cmu_arctic", speaker=spk, download=True)
|
|
126
|
-
|
|
127
|
-
signals, fs, info = load_dataset_sources(
|
|
128
|
-
dataset_factory=dataset_factory,
|
|
129
|
-
num_sources=2,
|
|
130
|
-
duration_s=10.0,
|
|
131
|
-
rng=random.Random(0),
|
|
132
|
-
)
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Dataset template (for future extension)
|
|
136
|
-
`TemplateDataset` provides a minimal stub to implement new datasets later.
|
|
137
|
-
|
|
138
|
-
### Logging
|
|
139
|
-
```python
|
|
140
|
-
from torchrir import LoggingConfig, get_logger, setup_logging
|
|
141
|
-
|
|
142
|
-
setup_logging(LoggingConfig(level="INFO"))
|
|
143
|
-
logger = get_logger("examples")
|
|
144
|
-
logger.info("running torchrir example")
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Scene container
|
|
148
|
-
```python
|
|
149
|
-
from torchrir import Scene
|
|
150
|
-
|
|
151
|
-
scene = Scene(room=room, sources=sources, mics=mics, src_traj=src_traj, mic_traj=mic_traj)
|
|
152
|
-
scene.validate()
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Immutable geometry helpers
|
|
156
|
-
`Room`, `Source`, and `MicrophoneArray` are immutable; use `.replace()` to update fields.
|
|
157
|
-
|
|
158
|
-
### Result container
|
|
159
|
-
```python
|
|
160
|
-
from torchrir import RIRResult
|
|
161
|
-
|
|
162
|
-
result = RIRResult(rirs=rirs, scene=scene, config=config)
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### Simulation strategies
|
|
166
|
-
```python
|
|
167
|
-
from torchrir import ISMSimulator
|
|
168
|
-
|
|
169
|
-
sim = ISMSimulator()
|
|
170
|
-
result = sim.simulate(scene, config)
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## Device Selection
|
|
174
|
-
- `device="cpu"`: CPU execution
|
|
175
|
-
- `device="cuda"`: NVIDIA GPU (CUDA) if available, otherwise fallback to CPU
|
|
176
|
-
- `device="mps"`: Apple Silicon GPU via Metal (MPS) if available, otherwise fallback to CPU
|
|
177
|
-
- `device="auto"`: prefer CUDA → MPS → CPU
|
|
178
|
-
|
|
179
|
-
```python
|
|
180
|
-
from torchrir import DeviceSpec
|
|
181
|
-
|
|
182
|
-
device, dtype = DeviceSpec(device="auto").resolve()
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
## References
|
|
186
|
-
- [gpuRIR](https://github.com/DavidDiazGuerra/gpuRIR)
|
|
187
|
-
- [Cross3D](https://github.com/DavidDiazGuerra/Cross3D)
|
|
188
|
-
- [pyroomacoustics](https://github.com/LCAV/pyroomacoustics)
|
|
189
|
-
- [das-generator](https://github.com/ehabets/das-generator)
|
|
190
|
-
- [rir-generator](https://github.com/audiolabs/rir-generator)
|
|
191
|
-
|
|
192
|
-
## Specification (Current)
|
|
193
|
-
### Purpose
|
|
194
|
-
- Provide room impulse response (RIR) simulation on PyTorch with CPU/CUDA/MPS support.
|
|
195
|
-
- Support static and dynamic scenes with a maintainable, modern API.
|
|
196
|
-
|
|
197
|
-
### Room Model
|
|
198
|
-
- Shoebox (rectangular) room model.
|
|
199
|
-
- 2D or 3D.
|
|
200
|
-
- Image Source Method (ISM) implementation.
|
|
201
|
-
|
|
202
|
-
### Inputs
|
|
203
|
-
#### Scene Geometry
|
|
204
|
-
- Room size: `[Lx, Ly, Lz]` (2D uses `[Lx, Ly]`).
|
|
205
|
-
- Source positions: `(n_src, dim)`.
|
|
206
|
-
- Microphone positions: `(n_mic, dim)`.
|
|
207
|
-
- Reflection order: `max_order`.
|
|
208
|
-
|
|
209
|
-
#### Acoustic Parameters
|
|
210
|
-
- Sample rate: `fs`.
|
|
211
|
-
- Speed of sound: `c` (default 343.0 m/s).
|
|
212
|
-
- Wall reflection coefficients: `beta` (4 faces for 2D, 6 for 3D) or `t60` (Sabine).
|
|
213
|
-
|
|
214
|
-
#### Output Length
|
|
215
|
-
- Specify `nsample` (samples) or `tmax` (seconds).
|
|
216
|
-
|
|
217
|
-
#### Directivity
|
|
218
|
-
- Patterns: `omni`, `cardioid`, `hypercardioid`, `subcardioid`, `bidir`.
|
|
219
|
-
- Orientation specified by vector or angles.
|
|
220
|
-
|
|
221
|
-
#### Configuration
|
|
222
|
-
- `SimulationConfig` controls algorithm settings (e.g., max_order, tmax, directivity, device, seed, fractional delay length, LUT, chunk sizes, compile path).
|
|
223
|
-
- Passed explicitly via `simulate_rir(..., config=...)` or `simulate_dynamic_rir(..., config=...)`.
|
|
224
|
-
|
|
225
|
-
### Outputs
|
|
226
|
-
- Static RIR shape: `(n_src, n_mic, nsample)`.
|
|
227
|
-
- Dynamic RIR shape: `(T, n_src, n_mic, nsample)`.
|
|
228
|
-
- Preserves dtype/device.
|
|
229
|
-
|
|
230
|
-
### Core APIs
|
|
231
|
-
#### Static RIR
|
|
232
|
-
```python
|
|
233
|
-
room = Room.shoebox(size=[6.0, 4.0, 3.0], fs=16000, beta=[0.9] * 6)
|
|
234
|
-
sources = Source.positions([[1.0, 2.0, 1.5], [4.5, 1.0, 1.2]])
|
|
235
|
-
mics = MicrophoneArray.positions([[2.0, 2.0, 1.5], [3.0, 2.0, 1.5]])
|
|
236
|
-
|
|
237
|
-
rir = simulate_rir(
|
|
238
|
-
room=room,
|
|
239
|
-
sources=sources,
|
|
240
|
-
mics=mics,
|
|
241
|
-
max_order=8,
|
|
242
|
-
tmax=0.4,
|
|
243
|
-
directivity="omni",
|
|
244
|
-
device="auto",
|
|
245
|
-
)
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
#### Dynamic RIRs + Convolution
|
|
249
|
-
```python
|
|
250
|
-
rirs = simulate_dynamic_rir(
|
|
251
|
-
room=room,
|
|
252
|
-
src_traj=src_traj, # (T, n_src, dim)
|
|
253
|
-
mic_traj=mic_traj, # (T, n_mic, dim)
|
|
254
|
-
max_order=8,
|
|
255
|
-
tmax=0.4,
|
|
256
|
-
device="auto",
|
|
257
|
-
)
|
|
258
|
-
|
|
259
|
-
y = DynamicConvolver(mode="trajectory").convolve(signal, rirs)
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
### Device Control
|
|
263
|
-
- `device="cpu"`, `"cuda"`, `"mps"`, or `"auto"`; resolves with fallback to CPU.
|
|
264
|
-
|
|
265
|
-
## Future Work
|
|
266
|
-
- Ray tracing backend: implement `RayTracingSimulator` with frequency-dependent absorption/scattering.
|
|
267
|
-
- FDTD backend: implement `FDTDSimulator` with configurable grid resolution and boundary conditions.
|
|
268
|
-
- Dataset expansion: add additional dataset integrations beyond CMU ARCTIC (see `TemplateDataset`).
|
|
269
|
-
- Enhanced acoustics: frequency-dependent absorption and more advanced diffuse tail models.
|
|
270
|
-
- Add microphone and source directivity models similar to gpuRIR/pyroomacoustics.
|
|
271
|
-
- Add regression tests comparing generated RIRs against gpuRIR outputs.
|
torchrir-0.1.2.dist-info/RECORD
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
torchrir/__init__.py,sha256=gUaLrXkWTqDSHCvU7JEB39Ynh-mWAWQGmnbV7Zghi2w,2362
|
|
2
|
-
torchrir/animation.py,sha256=bQ-yWRV7oCzaFU5I1J-VdsiQAWqU1--R6vH6asxQhRw,6280
|
|
3
|
-
torchrir/config.py,sha256=PsZdDIS3p4jepeNSHyd69aSD9QlOEdpG9v1SAXlZ_Fg,2295
|
|
4
|
-
torchrir/core.py,sha256=1Ups0_os9ArbSA3RIPeS8ftGSygEfwCsoc28u6xy6tg,26587
|
|
5
|
-
torchrir/directivity.py,sha256=v_t37YgeXF_IYzbnrk0TCs1npb_0yKR7zHiG8XV3V4w,1259
|
|
6
|
-
torchrir/dynamic.py,sha256=j8W-2Xwak_v4GQ-RetzlWXyHVUmbTFs1H7dEIwYYXlA,2131
|
|
7
|
-
torchrir/logging_utils.py,sha256=s4jDSSDoHT0HKeplDUpGMsdeBij4eibLSpaaAPzkB68,2146
|
|
8
|
-
torchrir/metadata.py,sha256=cwoXrr_yE2bQRUPnJe6p7POMPCWa9_oabCtp--WqBE8,6958
|
|
9
|
-
torchrir/plotting.py,sha256=ynimJC10QRTMVIC5vH3w1bMEN3e-0CyPHICtZzWu3XE,8145
|
|
10
|
-
torchrir/plotting_utils.py,sha256=uGceTrwWmJhZ_V1FnJNp30vE13hHbXDkY3X0aAxDhvc,5169
|
|
11
|
-
torchrir/results.py,sha256=-HczEfr2u91BNb1xbrIGKCj0G3yzy7l_fmUMUeKbGRw,614
|
|
12
|
-
torchrir/room.py,sha256=BnqA4FY_k_RQV9PvUAX8fr15yIP-PBIrzkmAiwLPZHU,5449
|
|
13
|
-
torchrir/scene.py,sha256=GuHuCspakAUOT81_ArTqaZbmBX0ApoJuCKTaZ21wGis,2435
|
|
14
|
-
torchrir/scene_utils.py,sha256=Kkj1XL1Xtpf_2bk7np_AmQqUHHYC9dxwXRRYgt30EwA,2128
|
|
15
|
-
torchrir/signal.py,sha256=QETI2dv5CPU4H9Jpi4CSEow4qlYVn0kbsun02h9MnP8,8253
|
|
16
|
-
torchrir/simulators.py,sha256=4hBswrBc8erp4ac5O20YbcVN8V_OnjP5ANaVnOtJQ9E,3075
|
|
17
|
-
torchrir/utils.py,sha256=HNQDksskfk6xLZ7XFWA7mh9GHhdfW4SthnJ5w_k58_Y,10652
|
|
18
|
-
torchrir/datasets/__init__.py,sha256=3T55F3fjjRR3j618ubRkMlZnQTxvXaxioFMhygxm7oQ,601
|
|
19
|
-
torchrir/datasets/base.py,sha256=mCHLtGOOaD1II1alJpP6ipzkz87l-rh19NgfeLnJbDU,720
|
|
20
|
-
torchrir/datasets/cmu_arctic.py,sha256=NpF5fATptkBPjf-6fDUYrOqfl-Jvi3j9bj5wfvwmcLI,7034
|
|
21
|
-
torchrir/datasets/template.py,sha256=KByYkCRm3cdTj4_jDvcZQ0Z4igilojJBH-6_W0-JIyc,2076
|
|
22
|
-
torchrir/datasets/utils.py,sha256=UtG8fcBaHiJiZ8Pba9IBY5_ClA_K_ilqUpGzvnwGNpQ,3135
|
|
23
|
-
torchrir-0.1.2.dist-info/licenses/LICENSE,sha256=5vS_7WTsMEw_QQHEPQ_WCwovJXEgmxoEwcwOI-9VbXI,10766
|
|
24
|
-
torchrir-0.1.2.dist-info/licenses/NOTICE,sha256=SRs_q-ZqoVF9_YuuedZOvVBk01jV7YQAeF8rRvlRg0s,118
|
|
25
|
-
torchrir-0.1.2.dist-info/METADATA,sha256=EWDdQ4sWDAcOgCDlg7b4QHFLu_Wm-6CXVc3sY-gx1E0,9161
|
|
26
|
-
torchrir-0.1.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
27
|
-
torchrir-0.1.2.dist-info/top_level.txt,sha256=aIFwntowJjvm7rZk480HymC3ipDo1g-9hEbNY1wF-Oo,9
|
|
28
|
-
torchrir-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|