Skip to content

Commit ebaf558

Browse files
committed
fixes issue #313
1 parent d66cf05 commit ebaf558

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

CHANGELOG.rst

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Bugfix
2424
- Fixes a bug in ``beamforming.circular_microphone_array_xyplane`` (#348)
2525
- Fixes a bug in ``room.Room.plot_rir`` where the x-axis would have the wrong
2626
ticks when called with ``kind="tf"``
27+
- Fixes an issue where the ``visibility`` attribute of the room is not
28+
set if there are no visible source or image source in the room. (#313)
2729

2830
`0.7.4`_ - 2024-04-25
2931
---------------------

pyroomacoustics/room.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -2149,9 +2149,9 @@ def image_source_model(self):
21492149
self.visibility = []
21502150

21512151
for source in self.sources:
2152-
n_sources = self.room_engine.image_source_model(source.position)
2152+
n_visible_sources = self.room_engine.image_source_model(source.position)
21532153

2154-
if n_sources > 0:
2154+
if n_visible_sources > 0:
21552155
# Copy to python managed memory
21562156
source.images = self.room_engine.sources.copy()
21572157
source.orders = self.room_engine.orders.copy()
@@ -2181,6 +2181,10 @@ def image_source_model(self):
21812181
# if not, it's not visible from anywhere!
21822182
if not self.is_inside(self.mic_array.R[:, m]):
21832183
self.visibility[-1][m, :] = 0
2184+
else:
2185+
# if we are here, this means even the direct path is not visible
2186+
# we set the visibility of the direct path as 0
2187+
self.visibility.append(np.zeros((self.mic_array.M, 1)))
21842188

21852189
# Update the state
21862190
self.simulator_state["ism_done"] = True
@@ -2315,9 +2319,6 @@ def compute_rir(self):
23152319
degrees=False,
23162320
)
23172321

2318-
# Use the Cython extension for the fractional delays
2319-
# from .build_rir import fast_rir_builder
2320-
23212322
vis = self.visibility[s][m, :].astype(np.int32)
23222323
# we add the delay due to the factional delay filter to
23232324
# the arrival times to avoid problems when propagation
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
4+
import pyroomacoustics as pra
5+
6+
7+
def test_issue_313():
8+
"""
9+
Fixes an issue where the `visibility` attribute of the room is not
10+
set if there are no visible source or image source in the room.
11+
"""
12+
# Room
13+
sigma2 = 5e-4
14+
fs = 16000
15+
16+
corners = np.array(
17+
[
18+
[0, 0],
19+
[10, 0],
20+
[10, 16],
21+
[0, 16],
22+
[0, 10],
23+
[8, 10],
24+
[8, 6],
25+
[0, 6],
26+
]
27+
).T
28+
room = pra.Room.from_corners(corners, fs=fs, max_order=1, sigma2_awgn=sigma2)
29+
30+
# Microphones
31+
def mic_array_at(pos: np.ndarray) -> pra.MicrophoneArray:
32+
mic_locations = pra.circular_2D_array(center=pos, M=6, phi0=0, radius=37.5e-3)
33+
mic_locations = np.concatenate(
34+
(mic_locations, np.array(pos, ndmin=2).T), axis=1
35+
)
36+
return pra.MicrophoneArray(mic_locations, room.fs)
37+
38+
mic = mic_array_at(np.array([3, 3]))
39+
room.add_microphone_array(mic)
40+
41+
# Sources
42+
rng = np.random.RandomState(23)
43+
duration_samples = int(fs)
44+
source_location = np.array([3, 13])
45+
source_signal = rng.randn(duration_samples)
46+
room.add_source(source_location, signal=source_signal)
47+
48+
room.image_source_model()
49+
50+
room.compute_rir()

0 commit comments

Comments
 (0)