Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes issue when there are no visible sources #351

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Bugfix
- Fixes a bug in ``beamforming.circular_microphone_array_xyplane`` (#348)
- Fixes a bug in ``room.Room.plot_rir`` where the x-axis would have the wrong
ticks when called with ``kind="tf"``
- Fixes an issue where the ``visibility`` attribute of the room is not
set if there are no visible source or image source in the room. (#313)

`0.7.4`_ - 2024-04-25
---------------------
Expand Down
11 changes: 6 additions & 5 deletions pyroomacoustics/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -2149,9 +2149,9 @@ def image_source_model(self):
self.visibility = []

for source in self.sources:
n_sources = self.room_engine.image_source_model(source.position)
n_visible_sources = self.room_engine.image_source_model(source.position)

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

# Update the state
self.simulator_state["ism_done"] = True
Expand Down Expand Up @@ -2315,9 +2319,6 @@ def compute_rir(self):
degrees=False,
)

# Use the Cython extension for the fractional delays
# from .build_rir import fast_rir_builder

vis = self.visibility[s][m, :].astype(np.int32)
# we add the delay due to the factional delay filter to
# the arrival times to avoid problems when propagation
Expand Down
50 changes: 50 additions & 0 deletions pyroomacoustics/tests/test_issue_313.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import matplotlib.pyplot as plt
import numpy as np

import pyroomacoustics as pra


def test_issue_313():
"""
Fixes an issue where the `visibility` attribute of the room is not
set if there are no visible source or image source in the room.
"""
# Room
sigma2 = 5e-4
fs = 16000

corners = np.array(
[
[0, 0],
[10, 0],
[10, 16],
[0, 16],
[0, 10],
[8, 10],
[8, 6],
[0, 6],
]
).T
room = pra.Room.from_corners(corners, fs=fs, max_order=1, sigma2_awgn=sigma2)

# Microphones
def mic_array_at(pos: np.ndarray) -> pra.MicrophoneArray:
mic_locations = pra.circular_2D_array(center=pos, M=6, phi0=0, radius=37.5e-3)
mic_locations = np.concatenate(
(mic_locations, np.array(pos, ndmin=2).T), axis=1
)
return pra.MicrophoneArray(mic_locations, room.fs)

mic = mic_array_at(np.array([3, 3]))
room.add_microphone_array(mic)

# Sources
rng = np.random.RandomState(23)
duration_samples = int(fs)
source_location = np.array([3, 13])
source_signal = rng.randn(duration_samples)
room.add_source(source_location, signal=source_signal)

room.image_source_model()

room.compute_rir()
Loading