Skip to content

Commit

Permalink
Merge pull request #360 from LCAV/fix/issue353
Browse files Browse the repository at this point in the history
Fixes for issue # 353 and #358
  • Loading branch information
fakufaku authored Aug 5, 2024
2 parents c3c4b79 + 29f1aed commit 6bc0a30
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 7 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ adheres to `Semantic Versioning <http://semver.org/spec/v2.0.0.html>`_.
`Unreleased`_
-------------

Nothing yet.
Bugfix
~~~~~~

- Fixes the default value of ``energy_thres`` in ``experimental.rt60`` to match the
previous behavior of the function (issue #358)
- Further fixes issue with cast reflections delays to float32 in room.py (#353)
which was not fully fixed by the previous update
- Fixes calls to deprecated API of ``scipy.linalg.eigh``
- Fixes use of deprecated feature of numpy (conversion of singleton array to scalar)

`0.7.5`_ - 2024-06-18
---------------------
Expand Down
4 changes: 2 additions & 2 deletions pyroomacoustics/beamforming.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ def rake_max_udr_filters(
SINR, v = la.eigh(
A,
b=B,
eigvals=(self.M * self.Lg - 1, self.M * self.Lg - 1),
subset_by_index=(self.M * self.Lg - 1, self.M * self.Lg - 1),
overwrite_a=True,
overwrite_b=True,
check_finite=False,
Expand Down Expand Up @@ -1316,7 +1316,7 @@ def rake_max_sinr_filters(self, source, interferer, R_n, epsilon=5e-3, delay=0.0
SINR, v = la.eigh(
K_s,
b=K_nq,
eigvals=(self.M * self.Lg - 1, self.M * self.Lg - 1),
subset_by_index=(self.M * self.Lg - 1, self.M * self.Lg - 1),
overwrite_a=True,
overwrite_b=True,
check_finite=False,
Expand Down
2 changes: 1 addition & 1 deletion pyroomacoustics/doa/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _compute_spatial_spectrum(self, cross, k):
Dc = np.array(self.mode_vec[k, :, n], ndmin=2).T
Dc_H = np.conjugate(np.array(self.mode_vec[k, :, n], ndmin=2))
denom = np.linalg.multi_dot([Dc_H, cross, Dc])
P[n] = 1 / abs(denom)
P[n] = 1 / abs(denom[0, 0])

return P

Expand Down
2 changes: 1 addition & 1 deletion pyroomacoustics/experimental/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def edm_line_search(R, tdoa, bounds, steps):
for i in range(d.shape[0]):
D[-1, :-1] = D[:-1, -1] = (dif + d[i]) ** 2
w = np.sort(np.abs(la.eigh(D, eigvals_only=True)))
# w = la.eigh(D, eigvals_only=True, eigvals=(D.shape[0]-6,D.shape[0]-6))
# w = la.eigh(D, eigvals_only=True, subset_by_index=(D.shape[0]-6,D.shape[0]-6))
cost[i] = np.sum(w[: D.shape[0] - 5])

return cost, d
2 changes: 1 addition & 1 deletion pyroomacoustics/experimental/rt60.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import numpy as np


def measure_rt60(h, fs=1, decay_db=60, energy_thres=0.95, plot=False, rt60_tgt=None):
def measure_rt60(h, fs=1, decay_db=60, energy_thres=1.0, plot=False, rt60_tgt=None):
"""
Analyze the RT60 of an impulse response. Optionaly plots some useful information.
Expand Down
8 changes: 7 additions & 1 deletion pyroomacoustics/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -2283,7 +2283,13 @@ def compute_rir(self):
N = int(math.ceil(t_max * self.fs / hbss) * hbss)

# this is where we will compose the RIR
ir = np.zeros(N + fdl)

# here we create an array of the right length to
# receiver the full RIR
# the +1 is due to some rare cases where numerical
# errors push the last sample over the end of the
# array
ir = np.zeros(N + fdl + 1)

# This is the distance travelled wrt time
distance_rir = np.arange(N) / self.fs * self.c
Expand Down
102 changes: 102 additions & 0 deletions pyroomacoustics/tests/test_issue_353.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

import numpy as np
import pytest

import pyroomacoustics as pra

Expand All @@ -39,3 +40,104 @@ def test_issue_353():
room.add_microphone_array(mic_array_in_room)

room.compute_rir()


def test_issue_353_2():
rt60_tgt = 0.451734045124395 # seconds
room_dim = [2.496315595944846, 2.2147285947364708, 3.749472153652182] # meters

fs = 16000

e_absorption, max_order = pra.inverse_sabine(rt60_tgt, room_dim)

room = pra.ShoeBox(
room_dim, fs=fs, materials=pra.Material(e_absorption), max_order=max_order
)

room.add_source([0.24784311631630576, 1.690743273038349, 1.9570721698068267])

mic_array = np.array(
[
[
0.46378325918698565,
],
[
1.5657207092343373,
],
[
3.015697444447528,
],
]
)

room.add_microphone_array(mic_array)

room.compute_rir()


params = (
(
[4.57977238, 5.39054892, 2.82767573],
0.18257819716723472,
[1.22812426, 1.2966769, 1.43330033],
[1.8020194, 0.76576269, 0.53980759],
83,
),
(
[5.3997869, 6.34821279, 2.90299906],
0.2217407971025793,
[4.05889913, 4.15230608, 2.39073375],
[2.45186073, 2.88844052, 1.39751034],
70,
),
(
[5.45909408, 6.34962532, 2.77107005],
0.27431416842419915,
[0.54511116, 2.82639397, 1.04676184],
[4.15744634, 2.82665472, 1.01958203],
58,
),
(
[5.88430842, 5.74587181, 2.81243457],
0.23546727398942446,
[5.2673113, 1.68109104, 2.13159967],
[2.03474247, 0.82147634, 1.25415523],
66,
),
(
[5.8335965, 4.90706049, 2.5410871],
0.25263067293986236,
[0.58218881, 3.25631355, 0.91775666],
[1.06434647, 3.3755251, 1.84040589],
63,
),
(
[5.63150056, 5.21368813, 2.90971373],
0.24979151070744487,
[4.30157587, 2.54104283, 2.22109155],
[1.47065101, 3.65191472, 1.64230692],
61,
),
(
[6.24132556, 4.62941236, 2.52808349],
0.23735500015498867,
[3.75099353, 3.82859854, 1.66480812],
[0.63880713, 1.93500295, 1.12386568],
67,
),
)


@pytest.mark.parametrize("room_dims, abs_coeff, spkr_pos, mic_pos, max_order", params)
def test_issue_353_3(room_dims, abs_coeff, spkr_pos, mic_pos, max_order):
room = pra.ShoeBox(
room_dims,
fs=16000,
materials=pra.Material(abs_coeff),
max_order=max_order,
use_rand_ism=False,
)
room.add_source(spkr_pos)
room.add_microphone(mic_pos)

room.compute_rir()

0 comments on commit 6bc0a30

Please sign in to comment.