diff --git a/src/python/Studio_cpu.py b/src/python/Studio_cpu.py index 3b7774b..95d4ec5 100644 --- a/src/python/Studio_cpu.py +++ b/src/python/Studio_cpu.py @@ -4,11 +4,12 @@ model_json_file='../../data/models/Studio/model.json', mat_folder='../../data/materials', source_num=1, - insig_type='impulse', # for RIR - diff_source=True, # for single precision + insig_type='impulse', + diff_source=True, mat_files_dict={ 'Absorber M': 'absorber_8000_100mm.h5', 'Absorber L': 'absorber_8000_200mm_gap_100mm.h5', + 'Baffle': 'door_wood.h5', 'Ceiling': 'concrete_painted.h5', 'Floor': 'floor_wood.h5', 'Sofa': 'absorber_8000_200mm.h5', diff --git a/src/python/Studio_model.py b/src/python/Studio_model.py index 17ca73b..e8863e0 100644 --- a/src/python/Studio_model.py +++ b/src/python/Studio_model.py @@ -43,8 +43,8 @@ room.add_box("Sofa", [2.52, 0.98, 0.48], [W/2-2.52/2, 0.4, 0.05]) room.add_box("Table", [1.8, 0.8, 0.02], [W/2-1.8/2, listener[1]+0.4, 0.7]) -room.add_source("Speaker Left", src_left) -room.add_source("Speaker Right", src_right) +room.add_source("Speaker Left", src_left, baffle_size=0.65) +room.add_source("Speaker Right", src_right, baffle_size=0.65) room.add_receiver("Engineer", listener.tolist()) room.add_receiver("Producer Sitting", producer_sit.tolist()) diff --git a/src/python/common/room_builder.py b/src/python/common/room_builder.py index ce5ea55..986a9f7 100644 --- a/src/python/common/room_builder.py +++ b/src/python/common/room_builder.py @@ -3,6 +3,7 @@ import numpy as np + def find_third_vertex(A, B): A = np.array(A) B = np.array(B) @@ -118,12 +119,32 @@ def make_box(W, L, H, translate, rotate=None, first_idx=0): return points, triangles +def make_surface(W, H, translate, rotate=None, first_idx=0): + if not rotate: + rotate = [0, 0, 0] + + points = [ + transform_point([0, 0, 0], [W, 0, H], [0, 0, 0], translate), + transform_point([1, 0, 0], [W, 0, H], [0, 0, 0], translate), + transform_point([1, 0, 1], [W, 0, H], [0, 0, 0], translate), + transform_point([0, 0, 1], [W, 0, H], [0, 0, 0], translate), + ] + + triangles = [ + [first_idx+0, first_idx+1, first_idx+2], + [first_idx+0, first_idx+2, first_idx+3], + ] + + return points, triangles + + class RoomBuilder: def __init__(self, width, length, height, wall_color=None): self.length = length self.width = width self.height = height self.sources = [] + self.baffle_sources = [] self.receivers = [] self.boxes = defaultdict(list) self.wall_color = wall_color @@ -145,6 +166,14 @@ def add_source(self, name, position): }) return self + def add_baffle_source(self, name, position, baffle_size=1.0): + self.add_source(name, position) + self.baffle_sources.append({ + "xyz": position, + "size": baffle_size, + }) + return self + def add_receiver(self, name, position): self.receivers.append({ "name": name, @@ -245,6 +274,32 @@ def build(self, file_path): model["mats_hash"][key] = spec + baffle_spec = { + "tris": [], + "pts": [], + "color": [10, 10, 10], + "sides": [] + } + + counter = 0 + for src in self.baffle_sources: + size = src["size"] + rot = [0, 0, 0] + offset = 0.075 + # offset = 0.05 + pos = list( + np.array(src["xyz"]) + np.array([-0.435/2, offset, -0.52]) + ) + + ps, ts = make_surface(0.435, size, pos, rot, counter) + baffle_spec["tris"] += ts + baffle_spec["pts"] += ps + baffle_spec["sides"] += [3]*len(ts) + counter += len(ps) + + if len(self.baffle_sources) > 0: + model["mats_hash"]["Baffle"] = baffle_spec + with open(file_path, "w") as file: json.dump(model, file) print("", file=file)