blob: 682aec9124ee22d1838796bc2d22a22cb92c8c48 [file] [log] [blame]
Per Ã…hgren6a05bb12019-12-03 11:24:59 +01001/*
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
20namespace webrtc {
21
22// Performs channel conversion to mono for the purpose of providing a decent
23// mono input for the delay estimation. This is achieved by analyzing all
24// incoming channels and produce one single channel output.
25class AlignmentMixer {
26 public:
27 AlignmentMixer(size_t num_channels,
28 const EchoCanceller3Config::Delay::AlignmentMixing& config);
29
30 AlignmentMixer(size_t num_channels,
31 bool downmix,
32 bool adaptive_selection,
33 float excitation_limit,
34 bool prefer_first_two_channels);
35
36 void ProduceOutput(rtc::ArrayView<const std::vector<float>> x,
37 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 rtc::ArrayView<const std::vector<float>> x,
53 rtc::ArrayView<float, kBlockSize> y) const;
54 int SelectChannel(rtc::ArrayView<const std::vector<float>> x);
55};
56} // namespace webrtc
57
58#endif // MODULES_AUDIO_PROCESSING_AEC3_ALIGNMENT_MIXER_H_