1 | /* |
2 | Copyright 2018 Google Inc. All Rights Reserved. |
3 | |
4 | Licensed under the Apache License, Version 2.0 (the "License"); |
5 | you may not use this file except in compliance with the License. |
6 | You may obtain a copy of the License at |
7 | |
8 | http://www.apache.org/licenses/LICENSE-2.0 |
9 | |
10 | Unless required by applicable law or agreed to in writing, software |
11 | distributed under the License is distributed on an "AS-IS" BASIS, |
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | See the License for the specific language governing permissions and |
14 | limitations under the License. |
15 | */ |
16 | |
17 | #ifndef RESONANCE_AUDIO_PLATFORM_COMMON_ROOM_EFFECTS_UTILS_H_ |
18 | #define RESONANCE_AUDIO_PLATFORM_COMMON_ROOM_EFFECTS_UTILS_H_ |
19 | |
20 | #include <vector> |
21 | |
22 | #include "api/resonance_audio_api.h" |
23 | #include "base/constants_and_types.h" |
24 | #include "base/misc_math.h" |
25 | #include "platforms/common/room_properties.h" |
26 | |
27 | namespace vraudio { |
28 | |
29 | // Room material properties. |
30 | struct RoomMaterial { |
31 | // Material surface integer identifier. |
32 | MaterialName name; |
33 | |
34 | // An array of absorption coefficients defined in octave bands. |
35 | float absorption_coefficients[kNumReverbOctaveBands]; |
36 | }; |
37 | |
38 | // Generates |ReflectionProperties| based on given |room_properties|. |
39 | // |
40 | // @param room_properties Room properties. |
41 | ReflectionProperties ComputeReflectionProperties( |
42 | const RoomProperties& room_properties); |
43 | |
44 | // Generates |ReverbProperties| based on given |room_properties|. |
45 | // |
46 | // @param room_properties Room properties. |
47 | ReverbProperties ComputeReverbProperties(const RoomProperties& room_properties); |
48 | |
49 | // Generates |ReverbProperties| by directly setting the RT60 values, subject |
50 | // to modifications by |brightness_modifier| and |time_scaler|. |
51 | // |
52 | // @param rt60_values RT60 values. |
53 | // @param brightness_modifier Modifier adjusting the brightness of reverb. |
54 | // @param time_scalar Modifier scaling the reverb time. |
55 | // @param gain_multiplier Modifier scaling the reverb gain. |
56 | ReverbProperties ComputeReverbPropertiesFromRT60s(const float* rt60_values, |
57 | float brightness_modifier, |
58 | float time_scalar, |
59 | float gain_multiplier); |
60 | |
61 | // Calculates the gain value for |source_position| with respect to the given |
62 | // room properties. The sound level for the room effects will remain the same |
63 | // inside the room, otherwise, it will decrease with a linear ramp from the |
64 | // closest point on the room. |
65 | // |
66 | // @param source_position World position of the source. |
67 | // @param room_position Center position of the room. |
68 | // @param room_rotation Orientation of the room. |
69 | // @param room_dimensions Dimensions of the room.. |
70 | // @return Attenuation (gain) value in range [0.0f, 1.0f]. |
71 | float ComputeRoomEffectsGain(const WorldPosition& source_position, |
72 | const WorldPosition& room_position, |
73 | const WorldRotation& room_rotation, |
74 | const WorldPosition& room_dimensions); |
75 | |
76 | // Gets the room material properties from a material index. |
77 | // |
78 | // @param material_index Index of the material. |
79 | RoomMaterial GetRoomMaterial(size_t material_index); |
80 | |
81 | } // namespace vraudio |
82 | |
83 | #endif // RESONANCE_AUDIO_PLATFORM_COMMON_ROOM_EFFECTS_UTILS_H_ |
84 | |