Skip to content

Commit

Permalink
moves is_dirpat check inside the open sofa file function
Browse files Browse the repository at this point in the history
  • Loading branch information
fakufaku committed Jul 4, 2023
1 parent 0ab2ad9 commit 46e30d1
Showing 1 changed file with 13 additions and 46 deletions.
59 changes: 13 additions & 46 deletions pyroomacoustics/open_sofa_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,6 @@
_DATA_SOFA_DIR = Path(__file__).parent / "data/sofa"


def fibonacci_sphere(samples):
"""
Creates a uniform fibonacci sphere.
This version has some point at the pole which leads
to a less *uniform* sampling. We should switch to
fibonnaci_spherical_sampling
Parameter
---------
samples : (int)
Points on the sphere
Return
--------
Points : (np.array) shape(Points) = [no_of_points * 3]
Cartesian coordinates of the points
"""

points = []
phi = math.pi * (3.0 - math.sqrt(5.0)) # golden angle in radians

i = np.arange(samples)
y = 1 - i / float(samples - 1) * 2
radius = np.sqrt(1 - y * y)
theta = phi * i
x = np.cos(theta) * radius
z = np.sin(theta) * radius

return np.array([x, y, z])


def cal_sph_basis(azimuth, colatitude, degree): # theta_target,phi_target
"""
Calculate a spherical basis matrix
Expand Down Expand Up @@ -280,6 +247,7 @@ def DIRPAT_pattern_enum_id(DIRPAT_pattern_enum, source=False):
return DIRPAT_pattern_enum

if source is not True:
# receivers/microphones
if "AKG_c480" in DIRPAT_pattern_enum:
id = 0
elif "AKG_c414K" in DIRPAT_pattern_enum:
Expand All @@ -294,7 +262,9 @@ def DIRPAT_pattern_enum_id(DIRPAT_pattern_enum, source=False):
id = int(DIRPAT_pattern_enum.split("_")[-1])
else:
raise ValueError("Please specifiy correct DIRPAT_pattern_enum for mic")

else:
# sources/loudspeakers
if "Genelec_8020" in DIRPAT_pattern_enum:
id = 0
elif "Lambda_labs_CX-1A" in DIRPAT_pattern_enum:
Expand Down Expand Up @@ -359,29 +329,20 @@ def open_sofa_file(path, measurement_id, is_source, fs=16000):

file_sofa = sofa.Database.open(path)

is_dirpat = path.name in [
"Soundfield_ST450_CUBE.sofa",
"AKG_c480_c414_CUBE.sofa",
"Oktava_MK4012_CUBE.sofa",
"LSPs_HATS_GuitarCabinets_Akustikmessplatz.sofa",
]

conv_name = file_sofa.convention.name

if conv_name == "SimpleFreeFieldHRIR":
return _read_simple_free_field_hrir(file_sofa, measurement_id, fs)

elif conv_name == "GeneralFIR":
return _read_general_fir(
file_sofa, path.name, measurement_id, fs, is_source, is_dirpat
)
return _read_general_fir(file_sofa, path.name, measurement_id, fs, is_source)

else:
raise NotImplementedError(f"SOFA convention {conv_name} not implemented")


def _read_simple_free_field_hrir(file_sofa, measurement_id, fs):
# read the mesurements
# read the mesurements (source direction, receiver location, taps)
IR_S = file_sofa.Data.IR.get_values()

# Source positions
Expand Down Expand Up @@ -426,10 +387,17 @@ def _read_simple_free_field_hrir(file_sofa, measurement_id, fs):
return grid, distance, msr, fs


def _read_general_fir(file_sofa, filename, measurement_id, fs, is_source, is_dirpat):
def _read_general_fir(file_sofa, filename, measurement_id, fs, is_source):
# read the mesurements
IR_S = file_sofa.Data.IR.get_values()

is_dirpat = filename in [
"Soundfield_ST450_CUBE.sofa",
"AKG_c480_c414_CUBE.sofa",
"Oktava_MK4012_CUBE.sofa",
"LSPs_HATS_GuitarCabinets_Akustikmessplatz.sofa",
]

if is_source:
# Receiver positions
pos = file_sofa.Receiver.Position.get_values()
Expand Down Expand Up @@ -656,7 +624,6 @@ class SOFADirectivityFactory:
interp_n_points: (int)
Number of points for the interpolation grid. The interpolation grid is a
Fibonnaci pseudo-uniform sampling of the sphere.
"""

def __init__(
Expand Down

0 comments on commit 46e30d1

Please sign in to comment.