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_GRAPH_SYSTEM_SETTINGS_H_ |
18 | #define RESONANCE_AUDIO_GRAPH_SYSTEM_SETTINGS_H_ |
19 | |
20 | #include "api/resonance_audio_api.h" |
21 | #include "base/constants_and_types.h" |
22 | #include "base/misc_math.h" |
23 | #include "graph/source_parameters_manager.h" |
24 | |
25 | namespace vraudio { |
26 | |
27 | // Contains system-wide settings and parameters. Note that this class is not |
28 | // thread-safe. Updating system parameters must be avoided during the audio |
29 | // graph processing. |
30 | class SystemSettings { |
31 | public: |
32 | // Constructor initializes the system configuration. |
33 | // |
34 | // @param num_output_channels Number of output channels. |
35 | // @param frames_per_buffer Buffer size in frames. |
36 | // @param sample_rate_hz Sample rate. |
37 | SystemSettings(size_t num_output_channels, size_t frames_per_buffer, |
38 | int sample_rate_hz) |
39 | : sample_rate_hz_(sample_rate_hz), |
40 | frames_per_buffer_(frames_per_buffer), |
41 | num_channels_(num_output_channels), |
42 | head_rotation_(WorldRotation::Identity()), |
43 | head_position_(WorldPosition::Zero()), |
44 | master_gain_(1.0f), |
45 | stereo_speaker_mode_(false) {} |
46 | |
47 | // Sets the listener head orientation. |
48 | // |
49 | // @param head_rotation Listener head orientation. |
50 | void SetHeadRotation(const WorldRotation& head_rotation) { |
51 | head_rotation_ = head_rotation; |
52 | } |
53 | |
54 | // Sets the listener head position. |
55 | // |
56 | // @param head_position Listener head position. |
57 | void SetHeadPosition(const WorldPosition& head_position) { |
58 | head_position_ = head_position; |
59 | } |
60 | |
61 | // Sets the global stereo speaker mode flag. This flag enforces stereo panning |
62 | // and disables HRTF-based binauralization. The stereo speaker mode is |
63 | // disabled by default. |
64 | // |
65 | // @param enabled Defines the stereo speaker mode state. |
66 | void SetStereoSpeakerMode(bool enabled) { stereo_speaker_mode_ = enabled; } |
67 | |
68 | // Returns the source parameters manager. |
69 | // |
70 | // @return Mutable source parameters manager. |
71 | SourceParametersManager* GetSourceParametersManager() { |
72 | return &source_parameters_manager_; |
73 | } |
74 | |
75 | // Returns the parameters of source with given |source_id|. |
76 | // |
77 | // @param source_id Source id. |
78 | // @return Pointer to source parameters, nullptr if |source_id| not found. |
79 | const SourceParameters* GetSourceParameters(SourceId source_id) const { |
80 | return source_parameters_manager_.GetParameters(source_id); |
81 | } |
82 | |
83 | // Returns the sample rate. |
84 | // |
85 | // @return Sample rate in Hertz. |
86 | int GetSampleRateHz() const { return sample_rate_hz_; } |
87 | |
88 | // Returns the frames per buffer. |
89 | // |
90 | // @return Buffer size in frames. |
91 | size_t GetFramesPerBuffer() const { return frames_per_buffer_; } |
92 | |
93 | // Returns the number of output channels. |
94 | // |
95 | // @return Number of output channels. |
96 | size_t GetNumChannels() const { return num_channels_; } |
97 | |
98 | // Returns the head rotation. |
99 | // |
100 | // @return Head orientation. |
101 | const WorldRotation& GetHeadRotation() const { return head_rotation_; } |
102 | |
103 | // Returns the head position. |
104 | // |
105 | // @return Head position. |
106 | const WorldPosition& GetHeadPosition() const { return head_position_; } |
107 | |
108 | // Returns the stereo speaker mode state. |
109 | // |
110 | // @return Current stereo speaker mode state. |
111 | bool IsStereoSpeakerModeEnabled() const { return stereo_speaker_mode_; } |
112 | |
113 | // Sets the master gain. |
114 | // |
115 | // @param master_gain Master output gain. |
116 | void SetMasterGain(float master_gain) { master_gain_ = master_gain; } |
117 | |
118 | // Sets current reflection properties. |
119 | // |
120 | // @param reflection_properties Reflection properties. |
121 | void SetReflectionProperties( |
122 | const ReflectionProperties& reflection_properties) { |
123 | reflection_properties_ = reflection_properties; |
124 | } |
125 | |
126 | // Sets current reverb properties. |
127 | // |
128 | // @param reverb_properties Reflection properties. |
129 | void SetReverbProperties(const ReverbProperties& reverb_properties) { |
130 | reverb_properties_ = reverb_properties; |
131 | } |
132 | |
133 | // Returns the master gain. |
134 | // |
135 | // @return Master output gain. |
136 | float GetMasterGain() const { return master_gain_; } |
137 | |
138 | // Returns the current reflection properties of the environment. |
139 | // |
140 | // @return Current reflection properties. |
141 | const ReflectionProperties& GetReflectionProperties() const { |
142 | return reflection_properties_; |
143 | } |
144 | |
145 | // Returns the current reverb properties of the environment. |
146 | // |
147 | // @return Current reverb properties. |
148 | const ReverbProperties& GetReverbProperties() const { |
149 | return reverb_properties_; |
150 | } |
151 | |
152 | // Disable copy and assignment operator. Since |SystemSettings| serves as a |
153 | // global parameter storage, it should never be copied. |
154 | SystemSettings& operator=(const SystemSettings&) = delete; |
155 | SystemSettings(const SystemSettings&) = delete; |
156 | |
157 | private: |
158 | // Sampling rate. |
159 | const int sample_rate_hz_; |
160 | |
161 | // Frames per buffer. |
162 | const size_t frames_per_buffer_; |
163 | |
164 | // Number of channels per buffer. |
165 | const size_t num_channels_; |
166 | |
167 | // The most recently updated head rotation and position. |
168 | WorldRotation head_rotation_; |
169 | WorldPosition head_position_; |
170 | |
171 | // Source parameters manager. |
172 | SourceParametersManager source_parameters_manager_; |
173 | |
174 | // Master gain in amplitude. |
175 | float master_gain_; |
176 | |
177 | // Current reflection properties of the environment. |
178 | ReflectionProperties reflection_properties_; |
179 | |
180 | // Current reverb properties of the environment. |
181 | ReverbProperties reverb_properties_; |
182 | |
183 | // Defines the state of the global speaker mode. |
184 | bool stereo_speaker_mode_; |
185 | }; |
186 | |
187 | } // namespace vraudio |
188 | |
189 | #endif // RESONANCE_AUDIO_GRAPH_SYSTEM_SETTINGS_H_ |
190 | |