alignment_mixer.h (2025B)
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 <array> 15 #include <cstddef> 16 #include <vector> 17 18 #include "api/array_view.h" 19 #include "api/audio/echo_canceller3_config.h" 20 #include "modules/audio_processing/aec3/aec3_common.h" 21 #include "modules/audio_processing/aec3/block.h" 22 23 namespace webrtc { 24 25 // Performs channel conversion to mono for the purpose of providing a decent 26 // mono input for the delay estimation. This is achieved by analyzing all 27 // incoming channels and produce one single channel output. 28 class AlignmentMixer { 29 public: 30 AlignmentMixer(size_t num_channels, 31 const EchoCanceller3Config::Delay::AlignmentMixing& config); 32 33 AlignmentMixer(size_t num_channels, 34 bool downmix, 35 bool adaptive_selection, 36 float excitation_limit, 37 bool prefer_first_two_channels); 38 39 void ProduceOutput(const Block& x, ArrayView<float, kBlockSize> y); 40 41 enum class MixingVariant { kDownmix, kAdaptive, kFixed }; 42 43 private: 44 const size_t num_channels_; 45 const float one_by_num_channels_; 46 const float excitation_energy_threshold_; 47 const bool prefer_first_two_channels_; 48 const MixingVariant selection_variant_; 49 std::array<size_t, 2> strong_block_counters_; 50 std::vector<float> cumulative_energies_; 51 int selected_channel_ = 0; 52 size_t block_counter_ = 0; 53 54 void Downmix(const Block& x, ArrayView<float, kBlockSize> y) const; 55 int SelectChannel(const Block& x); 56 }; 57 } // namespace webrtc 58 59 #endif // MODULES_AUDIO_PROCESSING_AEC3_ALIGNMENT_MIXER_H_