| 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_NEAR_FIELD_EFFECT_NODE_H_ | 
| 18 | #define RESONANCE_AUDIO_GRAPH_NEAR_FIELD_EFFECT_NODE_H_ | 
| 19 |  | 
| 20 | #include <vector> | 
| 21 |  | 
| 22 | #include "base/audio_buffer.h" | 
| 23 | #include "base/constants_and_types.h" | 
| 24 | #include "dsp/gain_processor.h" | 
| 25 | #include "dsp/near_field_processor.h" | 
| 26 | #include "graph/system_settings.h" | 
| 27 | #include "node/processing_node.h" | 
| 28 |  | 
| 29 | namespace vraudio { | 
| 30 |  | 
| 31 | // Node that accepts a single mono audio buffer as input, applies an appoximate | 
| 32 | // near field effect and outputs a processed stereo audio buffer. The stereo | 
| 33 | // output buffer can then be combined with a binaural output in order to | 
| 34 | // simulate a sound source which is close (<1m) to the listener's head. | 
| 35 | class NearFieldEffectNode : public ProcessingNode { | 
| 36 |  public: | 
| 37 |   // Constructor. | 
| 38 |   // | 
| 39 |   // @param source_id Output buffer source id. | 
| 40 |   // @param system_settings Global system settings. | 
| 41 |   NearFieldEffectNode(SourceId source_id, | 
| 42 |                       const SystemSettings& system_settings); | 
| 43 |  | 
| 44 |  protected: | 
| 45 |   // Implements ProcessingNode. | 
| 46 |   const AudioBuffer* AudioProcess(const NodeInput& input) override; | 
| 47 |  | 
| 48 |  private: | 
| 49 |   // Left and right processors apply both near field gain and panner gains. | 
| 50 |   GainProcessor left_panner_; | 
| 51 |   GainProcessor right_panner_; | 
| 52 |  | 
| 53 |   // Left and right gains for near field and panning combined. | 
| 54 |   std::vector<float> pan_gains_; | 
| 55 |  | 
| 56 |   // Near field processor used to apply approximate near field effect to the | 
| 57 |   // mono source signal. | 
| 58 |   NearFieldProcessor near_field_processor_; | 
| 59 |  | 
| 60 |   // Used to obtain head rotation. | 
| 61 |   const SystemSettings& system_settings_; | 
| 62 |  | 
| 63 |   // Output buffer. | 
| 64 |   AudioBuffer output_buffer_; | 
| 65 | }; | 
| 66 |  | 
| 67 | }  // namespace vraudio | 
| 68 |  | 
| 69 | #endif  // RESONANCE_AUDIO_GRAPH_NEAR_FIELD_EFFECT_NODE_H_ | 
| 70 |  |