Skip to content

Commit

Permalink
Add baffle sources
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Jul 7, 2024
1 parent 3de7f6a commit 76a3f3a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/python/Studio_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/python/Studio_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
55 changes: 55 additions & 0 deletions src/python/common/room_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np


def find_third_vertex(A, B):
A = np.array(A)
B = np.array(B)
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)

0 comments on commit 76a3f3a

Please sign in to comment.