Skip to content

Commit b6aa302

Browse files
committed
relocates the from directivities to simulation/ism
1 parent e96f4ee commit b6aa302

File tree

3 files changed

+52
-53
lines changed

3 files changed

+52
-53
lines changed

pyroomacoustics/directivities.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -331,54 +331,3 @@ def cardioid_func(x, direction, coef, gain=1.0, normalize=True, magnitude=False)
331331
return np.abs(resp)
332332
else:
333333
return resp
334-
335-
336-
def source_angle_shoebox(image_source_loc, wall_flips, mic_loc):
337-
"""
338-
Determine outgoing angle for each image source for a ShoeBox configuration.
339-
340-
Implementation of the method described in the paper:
341-
https://www2.ak.tu-berlin.de/~akgroup/ak_pub/2018/000458.pdf
342-
343-
Parameters
344-
-----------
345-
image_source_loc : array_like
346-
Locations of image sources.
347-
wall_flips: array_like
348-
Number of x, y, z flips for each image source.
349-
mic_loc: array_like
350-
Microphone location.
351-
352-
Returns
353-
-------
354-
azimuth : :py:class:`~numpy.ndarray`
355-
Azimith for each image source, in radians
356-
colatitude : :py:class:`~numpy.ndarray`
357-
Colatitude for each image source, in radians.
358-
359-
"""
360-
361-
image_source_loc = np.array(image_source_loc)
362-
wall_flips = np.array(wall_flips)
363-
mic_loc = np.array(mic_loc)
364-
365-
dim, n_sources = image_source_loc.shape
366-
assert wall_flips.shape[0] == dim
367-
assert mic_loc.shape[0] == dim
368-
369-
p_vector_array = image_source_loc - np.array(mic_loc)[:, np.newaxis]
370-
d_array = np.linalg.norm(p_vector_array, axis=0)
371-
372-
# Using (12) from the paper
373-
power_array = np.ones_like(image_source_loc) * -1
374-
power_array = np.power(power_array, (wall_flips + np.ones_like(image_source_loc)))
375-
p_dash_array = p_vector_array * power_array
376-
377-
# Using (13) from the paper
378-
azimuth = np.arctan2(p_dash_array[1], p_dash_array[0])
379-
if dim == 2:
380-
colatitude = np.ones(n_sources) * np.pi / 2
381-
else:
382-
colatitude = np.pi / 2 - np.arcsin(p_dash_array[2] / d_array)
383-
384-
return azimuth, colatitude

pyroomacoustics/room.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def callback_mix(premix, snr=0, sir=0, ref_mic=0, n_src=None, n_tgt=None):
698698
from . import libroom
699699
from .acoustics import OctaveBandsFactory, rt60_eyring, rt60_sabine
700700
from .beamforming import MicrophoneArray
701-
from .directivities import CardioidFamily, source_angle_shoebox
701+
from .directivities import CardioidFamily
702702
from .experimental import measure_rt60
703703
from .libroom import Wall, Wall2D
704704
from .open_sofa_interpolate import MeasuredDirectivity

pyroomacoustics/simulation/ism.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from scipy.signal import fftconvolve, hilbert
55

66
from .. import libroom
7-
from ..directivities import source_angle_shoebox
87
from ..parameters import constants
98
from ..utilities import angle_function
109

@@ -82,6 +81,57 @@ def interpolate_octave_bands(
8281
return ir
8382

8483

84+
def source_angle_shoebox(image_source_loc, wall_flips, mic_loc):
85+
"""
86+
Determine outgoing angle for each image source for a ShoeBox configuration.
87+
88+
Implementation of the method described in the paper:
89+
https://www2.ak.tu-berlin.de/~akgroup/ak_pub/2018/000458.pdf
90+
91+
Parameters
92+
-----------
93+
image_source_loc : array_like
94+
Locations of image sources.
95+
wall_flips: array_like
96+
Number of x, y, z flips for each image source.
97+
mic_loc: array_like
98+
Microphone location.
99+
100+
Returns
101+
-------
102+
azimuth : :py:class:`~numpy.ndarray`
103+
Azimith for each image source, in radians
104+
colatitude : :py:class:`~numpy.ndarray`
105+
Colatitude for each image source, in radians.
106+
107+
"""
108+
109+
image_source_loc = np.array(image_source_loc)
110+
wall_flips = np.array(wall_flips)
111+
mic_loc = np.array(mic_loc)
112+
113+
dim, n_sources = image_source_loc.shape
114+
assert wall_flips.shape[0] == dim
115+
assert mic_loc.shape[0] == dim
116+
117+
p_vector_array = image_source_loc - np.array(mic_loc)[:, np.newaxis]
118+
d_array = np.linalg.norm(p_vector_array, axis=0)
119+
120+
# Using (12) from the paper
121+
power_array = np.ones_like(image_source_loc) * -1
122+
power_array = np.power(power_array, (wall_flips + np.ones_like(image_source_loc)))
123+
p_dash_array = p_vector_array * power_array
124+
125+
# Using (13) from the paper
126+
azimuth = np.arctan2(p_dash_array[1], p_dash_array[0])
127+
if dim == 2:
128+
colatitude = np.ones(n_sources) * np.pi / 2
129+
else:
130+
colatitude = np.pi / 2 - np.arcsin(p_dash_array[2] / d_array)
131+
132+
return azimuth, colatitude
133+
134+
85135
def compute_ism_rir(
86136
src,
87137
mic,

0 commit comments

Comments
 (0)