alignment_mixer.h 2.0 KB

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