-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtdw_scene_audio.py
168 lines (137 loc) · 6.53 KB
/
tdw_scene_audio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
from abc import ABC, abstractmethod
from enum import Enum
from numpy.random import RandomState
from tdw.py_impact import AudioMaterial
class SurfaceMaterial(Enum):
"""
Resonance Audio surface materials.
"""
smoothPlaster = 1
roughPlaster = 2
glass = 4
parquet = 8
marble = 16
grass = 32
concrete = 64
brick = 128
tile = 256
acousticTile = 512
class _ReverbSpaceParameters:
"""
Parameters for a Resonance Audio reverb space
"""
def __init__(self, floor: SurfaceMaterial,
ceiling: SurfaceMaterial,
front_wall: SurfaceMaterial,
back_wall: SurfaceMaterial,
left_wall: SurfaceMaterial,
right_wall: SurfaceMaterial):
"""
:param floor: The floor material.
:param ceiling: The ceiling material.
:param front_wall: The front wall material.
:param back_wall: The back wall material.
:param left_wall: The left wall material.
:param right_wall: The right wall material.
"""
self.floor = floor
self.ceiling = ceiling
self.front_wall = front_wall
self.back_wall = back_wall
self.left_wall = left_wall
self.right_wall = right_wall
class TDWSceneAudio(ABC):
"""
Audio system for a "TDW" scene.
"""
RNG = RandomState(0)
@abstractmethod
def _get_reverb_space_parameters(self) -> _ReverbSpaceParameters:
"""
:return: The parameters used to create the reverb space.
"""
raise Exception()
@abstractmethod
def get_audio_material(self) -> AudioMaterial:
"""
:return: The surface audio material (for PyImpact).
"""
raise Exception()
def get_command(self) -> dict:
"""
:return: The command to create the reverb space.
"""
parameters = self._get_reverb_space_parameters()
return {"$type": "set_reverb_space_simple",
"env_id": 0,
"reverb_floor_material": parameters.floor.name,
"reverb_ceiling_material": parameters.ceiling.name,
"reverb_front_wall_material": parameters.front_wall.name,
"reverb_back_wall_material": parameters.back_wall.name,
"reverb_left_wall_material": parameters.left_wall.name,
"reverb_right_wall_material": parameters.right_wall.name}
class Realistic(TDWSceneAudio):
"""
Surface materials are chosen randomly, but are "plausible" (e.g. walls are never made out of grass).
The walls all have the same surface material.
"""
_FLOOR = [SurfaceMaterial.concrete,
SurfaceMaterial.grass,
SurfaceMaterial.marble,
SurfaceMaterial.tile,
SurfaceMaterial.brick,
SurfaceMaterial.parquet]
_WALL = [SurfaceMaterial.brick,
SurfaceMaterial.concrete,
SurfaceMaterial.acousticTile,
SurfaceMaterial.roughPlaster,
SurfaceMaterial.smoothPlaster]
_CEILING = [SurfaceMaterial.brick,
SurfaceMaterial.concrete,
SurfaceMaterial.roughPlaster,
SurfaceMaterial.smoothPlaster,
SurfaceMaterial.acousticTile]
_AUDIO_MATERIALS = {SurfaceMaterial.concrete: AudioMaterial.ceramic,
SurfaceMaterial.grass: AudioMaterial.cardboard,
SurfaceMaterial.marble: AudioMaterial.metal,
SurfaceMaterial.tile: AudioMaterial.ceramic,
SurfaceMaterial.brick: AudioMaterial.wood,
SurfaceMaterial.parquet: AudioMaterial.hardwood}
def __init__(self):
self._floor = Realistic._FLOOR[TDWSceneAudio.RNG.randint(0, len(Realistic._FLOOR))]
def _get_reverb_space_parameters(self) -> _ReverbSpaceParameters:
wall = Realistic._WALL[TDWSceneAudio.RNG.randint(0, len(Realistic._WALL))]
ceiling = Realistic._CEILING[TDWSceneAudio.RNG.randint(0, len(Realistic._CEILING))]
return _ReverbSpaceParameters(floor=self._floor, ceiling=ceiling,
front_wall=wall, back_wall=wall, left_wall=wall, right_wall=wall)
def get_audio_material(self) -> AudioMaterial:
# A PyImpact audio material that corresponds to the ResonanceAudio surface material.
return Realistic._AUDIO_MATERIALS[self._floor]
class Unrealistic(Realistic):
"""
Surface materials are chosen randomly, but are "plausible" (e.g. walls are never made out of grass).
Each of the walls can have a different material.
"""
def _get_reverb_space_parameters(self) -> _ReverbSpaceParameters:
return _ReverbSpaceParameters(floor=Realistic._FLOOR[TDWSceneAudio.RNG.randint(0, len(Realistic._FLOOR))],
ceiling=Realistic._CEILING[TDWSceneAudio.RNG.randint(0, len(Realistic._CEILING))],
front_wall=Realistic._WALL[TDWSceneAudio.RNG.randint(0, len(Realistic._WALL))],
back_wall=Realistic._WALL[TDWSceneAudio.RNG.randint(0, len(Realistic._WALL))],
left_wall=Realistic._WALL[TDWSceneAudio.RNG.randint(0, len(Realistic._WALL))],
right_wall=Realistic._WALL[TDWSceneAudio.RNG.randint(0, len(Realistic._WALL))])
class Chaos(TDWSceneAudio):
"""
A "chaotic" reverb space. All materials are random.
The PyImpact material might not match the ResonanceAudio floor material.
"""
_MATERIALS = [m for m in SurfaceMaterial]
_PY_IMPACT_MATERIALS = [m for m in AudioMaterial]
def _get_reverb_space_parameters(self) -> _ReverbSpaceParameters:
return _ReverbSpaceParameters(floor=Chaos._MATERIALS[TDWSceneAudio.RNG.randint(0, len(Chaos._MATERIALS))],
ceiling=Chaos._MATERIALS[TDWSceneAudio.RNG.randint(0, len(Chaos._MATERIALS))],
front_wall=Chaos._MATERIALS[TDWSceneAudio.RNG.randint(0, len(Chaos._MATERIALS))],
back_wall=Chaos._MATERIALS[TDWSceneAudio.RNG.randint(0, len(Chaos._MATERIALS))],
left_wall=Chaos._MATERIALS[TDWSceneAudio.RNG.randint(0, len(Chaos._MATERIALS))],
right_wall=Chaos._MATERIALS[TDWSceneAudio.RNG.randint(0, len(Chaos._MATERIALS))])
def get_audio_material(self) -> AudioMaterial:
return Chaos._PY_IMPACT_MATERIALS[TDWSceneAudio.RNG.randint(0, len(Chaos._PY_IMPACT_MATERIALS))]