Skip to content

Commit 449f725

Browse files
committed
fixes issue #353 and adds a test
1 parent 40e973c commit 449f725

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

pyroomacoustics/room.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,8 @@ def compute_rir(self):
22582258

22592259
# compute the distance from image sources
22602260
dist = np.sqrt(np.sum((src.images - mic[:, None]) ** 2, axis=0))
2261-
time = dist / self.c
2261+
# the RIR building routine works in float32, so we cast here
2262+
time = (dist / self.c).astype(np.float32)
22622263
t_max = time.max()
22632264
N = int(math.ceil(t_max * self.fs))
22642265

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
# Test for Issue 353
3+
4+
[issue #353](https://github.com/LCAV/pyroomacoustics/issues/353)
5+
6+
The cause of the issue was that the time of the maximum delay
7+
in the RIR is used to determine the necessary size of the array.
8+
9+
The float64 value of the delay was used to determine the size and construct the array.
10+
However, the `rir_build` routine takes float32.
11+
After conversion, the array size would evaluate to one delay more due to rounding
12+
offset and an array size check would fail.
13+
14+
Converting the delay time array to float32 before creating the rir array
15+
solved the issue.
16+
"""
17+
18+
import numpy as np
19+
20+
import pyroomacoustics as pra
21+
22+
23+
def test_issue_353():
24+
room_dims = np.array([10.0, 10.0, 10.0])
25+
room = pra.ShoeBox(
26+
room_dims, fs=24000, materials=None, max_order=22, use_rand_ism=False
27+
)
28+
29+
source = np.array([[6.35551912], [4.33308523], [3.69586303]])
30+
room.add_source(source)
31+
32+
mic_array_in_room = np.array(
33+
[
34+
[1.5205189, 1.49366285, 1.73302404, 1.67847898],
35+
[4.68430529, 4.76250254, 4.67956424, 4.60702604],
36+
[2.68214263, 2.7980202, 2.55341851, 2.72701718],
37+
]
38+
)
39+
room.add_microphone_array(mic_array_in_room)
40+
41+
room.compute_rir()

0 commit comments

Comments
 (0)