| 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_AMBISONIC_MIXING_ENCODER_NODE_H_ | 
| 18 | #define RESONANCE_AUDIO_GRAPH_AMBISONIC_MIXING_ENCODER_NODE_H_ | 
| 19 |  | 
| 20 | #include <vector> | 
| 21 |  | 
| 22 | #include "ambisonics/ambisonic_lookup_table.h" | 
| 23 | #include "base/audio_buffer.h" | 
| 24 | #include "base/spherical_angle.h" | 
| 25 | #include "dsp/gain_mixer.h" | 
| 26 | #include "graph/system_settings.h" | 
| 27 | #include "node/processing_node.h" | 
| 28 |  | 
| 29 | namespace vraudio { | 
| 30 |  | 
| 31 | // Node that accepts single mono sound object buffer as input and encodes it | 
| 32 | // into an Ambisonic sound field. | 
| 33 | class AmbisonicMixingEncoderNode : public ProcessingNode { | 
| 34 |  public: | 
| 35 |   // Initializes AmbisonicMixingEncoderNode class. | 
| 36 |   // | 
| 37 |   // @param system_settings Global system configuration. | 
| 38 |   // @param lookup_table Ambisonic encoding lookup table. | 
| 39 |   // @param ambisonic_order Order of Ambisonic sources. | 
| 40 |   AmbisonicMixingEncoderNode(const SystemSettings& system_settings, | 
| 41 |                              const AmbisonicLookupTable& lookup_table, | 
| 42 |                              int ambisonic_order); | 
| 43 |  | 
| 44 |   // Node implementation. | 
| 45 |   bool CleanUp() final { | 
| 46 |     CallCleanUpOnInputNodes(); | 
| 47 |     // Prevent node from being disconnected when all sources are removed. | 
| 48 |     return false; | 
| 49 |   } | 
| 50 |  | 
| 51 |  protected: | 
| 52 |   // Implements ProcessingNode. | 
| 53 |   const AudioBuffer* AudioProcess(const NodeInput& input) override; | 
| 54 |  | 
| 55 |  private: | 
| 56 |   const SystemSettings& system_settings_; | 
| 57 |   const AmbisonicLookupTable& lookup_table_; | 
| 58 |  | 
| 59 |   // Ambisonic order of encoded sources. | 
| 60 |   const int ambisonic_order_; | 
| 61 |  | 
| 62 |   // |GainMixer| instance. | 
| 63 |   GainMixer gain_mixer_; | 
| 64 |  | 
| 65 |   // Encoding coefficient values to be applied to encode the input. | 
| 66 |   std::vector<float> coefficients_; | 
| 67 | }; | 
| 68 |  | 
| 69 | }  // namespace vraudio | 
| 70 |  | 
| 71 | #endif  // RESONANCE_AUDIO_GRAPH_AMBISONIC_MIXING_ENCODER_NODE_H_ | 
| 72 |  |