Skip to content

Commit b8155bf

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

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-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

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
import numpy as np
18+
import pyroomacoustics as pra
19+
20+
21+
def test_issue_353():
22+
room_dims = np.array([10., 10., 10.])
23+
room = pra.ShoeBox(
24+
room_dims,
25+
fs=24000,
26+
materials=None,
27+
max_order=22,
28+
use_rand_ism=False
29+
)
30+
31+
source = np.array([[6.35551912],[4.33308523], [3.69586303]])
32+
room.add_source(source)
33+
34+
mic_array_in_room = np.array(
35+
[
36+
[1.5205189, 1.49366285, 1.73302404, 1.67847898],
37+
[4.68430529, 4.76250254, 4.67956424, 4.60702604],
38+
[2.68214263, 2.7980202, 2.55341851, 2.72701718]
39+
]
40+
)
41+
room.add_microphone_array(mic_array_in_room)
42+
43+
room.compute_rir()

0 commit comments

Comments
 (0)