-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switches to using source directions computed as part of the image sou…
…rce model for source directivities. This enables the use of source directivities with non-shoebox rooms.
- Loading branch information
Showing
5 changed files
with
142 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
pyroomacoustics/directivities/tests/test_source_directivities_nonshoebox.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
import pyroomacoustics as pra | ||
|
||
""" | ||
+ - - - - - - - - - - - + | ||
| | | ||
| | | ||
| | | ||
| + - - - - - - - + | ||
| | | ||
| | | ||
| | | ||
+ - - - + | ||
""" | ||
|
||
corners = np.array([[0, 0], [4, 0], [4, 4], [12, 4], [12, 8], [0, 8]]) | ||
source_location = [6, 6, 1.5] | ||
mic_location = [1, 6, 1.5] | ||
|
||
images_expected = np.array( | ||
[ | ||
source_location, # direct | ||
[6, 10, 1.5], # north | ||
[-6, 6, 1.5], # west | ||
[18, 6, 1.5], # east | ||
[6, 6, 4.5], # ceilling | ||
[6, 6, -1.5], # floor | ||
] | ||
) | ||
directions_expected = np.array( | ||
[ | ||
[-1, 0, 0], | ||
np.array([-2.5, 2, 0]) / np.sqrt(2.5**2 + 2**2), | ||
[-1, 0, 0], | ||
[1, 0, 0], | ||
np.array([-2.5, 0, 1.5]) / np.sqrt(2.5**2 + 1.5**2), | ||
np.array([-2.5, 0, -1.5]) / np.sqrt(2.5**2 + 1.5**2), | ||
] | ||
) | ||
|
||
|
||
room = pra.Room.from_corners(corners.T, materials=pra.Material(0.1), max_order=1) | ||
room.extrude(3.0, materials=pra.Material(0.1)) | ||
room.add_source( | ||
source_location, | ||
directivity=pra.directivities.Cardioid( | ||
orientation=pra.directivities.DirectionVector( | ||
azimuth=0, colatitude=np.pi / 2, degrees=False | ||
) | ||
), | ||
).add_microphone(mic_location).add_microphone([3, 6, 1.5]) | ||
# We add one microphone with other images visible to make sure we have some | ||
# image sources not visible. | ||
|
||
|
||
def test_source_directions_nonshoebox(): | ||
room.image_source_model() | ||
visible = room.visibility[0][0, :] | ||
directions_obtained = room.sources[0].directions[0, :, visible] | ||
images_obtained = room.sources[0].images[:, visible] | ||
|
||
order_obtained = np.lexsort(images_obtained) | ||
images_obtained = images_obtained[:, order_obtained].T | ||
directions_obtained = directions_obtained[order_obtained, :] | ||
|
||
order_expected = np.lexsort(images_expected.T) | ||
images_expected_reordered = images_expected[order_expected, :] | ||
directions_expected_reordered = directions_expected[order_expected, :] | ||
|
||
np.testing.assert_almost_equal(images_obtained, images_expected_reordered) | ||
np.testing.assert_almost_equal(directions_obtained, directions_expected_reordered) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters