| 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_REFLECTIONS_NODE_H_ | 
| 18 | #define RESONANCE_AUDIO_GRAPH_REFLECTIONS_NODE_H_ | 
| 19 |  | 
| 20 | #include <vector> | 
| 21 |  | 
| 22 | #include "ambisonics/foa_rotator.h" | 
| 23 | #include "api/resonance_audio_api.h" | 
| 24 | #include "base/audio_buffer.h" | 
| 25 | #include "base/misc_math.h" | 
| 26 | #include "dsp/reflections_processor.h" | 
| 27 | #include "graph/system_settings.h" | 
| 28 | #include "node/processing_node.h" | 
| 29 |  | 
| 30 | namespace vraudio { | 
| 31 |  | 
| 32 | // Node that accepts a single mono buffer as input and outputs an ambisonically | 
| 33 | // encoded sound field buffer of the mix of all the early room reflections. | 
| 34 | class ReflectionsNode : public ProcessingNode { | 
| 35 |  public: | 
| 36 |   // Initializes |ReflectionsNode| class. | 
| 37 |   // | 
| 38 |   // @param system_settings Global system configuration. | 
| 39 |   explicit ReflectionsNode(const SystemSettings& system_settings); | 
| 40 |  | 
| 41 |   // Updates the reflections. Depending on whether to use RT60s for reverb | 
| 42 |   // according to the global system settings, the reflections are calculated | 
| 43 |   // either by the current room properties or the proxy room properties. | 
| 44 |   void Update(); | 
| 45 |  | 
| 46 |  protected: | 
| 47 |   // Implements ProcessingNode. | 
| 48 |   const AudioBuffer* AudioProcess(const NodeInput& input) override; | 
| 49 |  | 
| 50 |  private: | 
| 51 |   const SystemSettings& system_settings_; | 
| 52 |  | 
| 53 |   // First-order-ambisonics rotator to be used to rotate the reflections with | 
| 54 |   // respect to the listener's orientation. | 
| 55 |   FoaRotator foa_rotator_; | 
| 56 |  | 
| 57 |   // Processes and encodes reflections into an ambisonic buffer. | 
| 58 |   ReflectionsProcessor reflections_processor_; | 
| 59 |  | 
| 60 |   // Most recently updated reflection properties. | 
| 61 |   ReflectionProperties reflection_properties_; | 
| 62 |  | 
| 63 |   // Most recently updated listener position. | 
| 64 |   WorldPosition listener_position_; | 
| 65 |  | 
| 66 |   size_t num_frames_processed_on_empty_input_; | 
| 67 |  | 
| 68 |   // Ambisonic output buffer. | 
| 69 |   AudioBuffer output_buffer_; | 
| 70 |  | 
| 71 |   // Silence mono buffer to render reflection tails during the absence of input | 
| 72 |   // buffers. | 
| 73 |   AudioBuffer silence_mono_buffer_; | 
| 74 | }; | 
| 75 |  | 
| 76 | }  // namespace vraudio | 
| 77 |  | 
| 78 | #endif  // RESONANCE_AUDIO_GRAPH_REFLECTIONS_NODE_H_ | 
| 79 |  |