1 /* 2 * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_AUDIO_PROCESSING_AEC3_ALIGNMENT_MIXER_H_ 12 #define MODULES_AUDIO_PROCESSING_AEC3_ALIGNMENT_MIXER_H_ 13 14 #include <vector> 15 16 #include "api/array_view.h" 17 #include "api/audio/echo_canceller3_config.h" 18 #include "modules/audio_processing/aec3/aec3_common.h" 19 #include "modules/audio_processing/aec3/block.h" 20 21 namespace webrtc { 22 23 // Performs channel conversion to mono for the purpose of providing a decent 24 // mono input for the delay estimation. This is achieved by analyzing all 25 // incoming channels and produce one single channel output. 26 class AlignmentMixer { 27 public: 28 AlignmentMixer(size_t num_channels, 29 const EchoCanceller3Config::Delay::AlignmentMixing& config); 30 31 AlignmentMixer(size_t num_channels, 32 bool downmix, 33 bool adaptive_selection, 34 float excitation_limit, 35 bool prefer_first_two_channels); 36 37 void ProduceOutput(const Block& x, rtc::ArrayView<float, kBlockSize> y); 38 39 enum class MixingVariant { kDownmix, kAdaptive, kFixed }; 40 41 private: 42 const size_t num_channels_; 43 const float one_by_num_channels_; 44 const float excitation_energy_threshold_; 45 const bool prefer_first_two_channels_; 46 const MixingVariant selection_variant_; 47 std::array<size_t, 2> strong_block_counters_; 48 std::vector<float> cumulative_energies_; 49 int selected_channel_ = 0; 50 size_t block_counter_ = 0; 51 52 void Downmix(const Block& x, rtc::ArrayView<float, kBlockSize> y) const; 53 int SelectChannel(const Block& x); 54 }; 55 } // namespace webrtc 56 57 #endif // MODULES_AUDIO_PROCESSING_AEC3_ALIGNMENT_MIXER_H_ 58