Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
fakufaku committed May 27, 2024
2 parents 120ac43 + 8234c7b commit 1d09fb8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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
8 changes: 6 additions & 2 deletions pyroomacoustics/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -2142,9 +2142,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: # Number of image source that are generated
if n_visible_sources > 0:
# Copy to python managed memory

source.images = (
Expand Down Expand Up @@ -2186,6 +2186,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), dtype=np.int32))

# Update the state
self.simulator_state["ism_done"] = True
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()

0 comments on commit 1d09fb8

Please sign in to comment.