1 /* 2 * Copyright (c) 2018 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_REVERB_MODEL_ESTIMATOR_H_ 12 #define MODULES_AUDIO_PROCESSING_AEC3_REVERB_MODEL_ESTIMATOR_H_ 13 14 #include <array> 15 #include <memory> 16 #include <vector> 17 18 #include "absl/types/optional.h" 19 #include "api/array_view.h" 20 #include "api/audio/echo_canceller3_config.h" 21 #include "modules/audio_processing/aec3/aec3_common.h" // kFftLengthBy2Plus1 22 #include "modules/audio_processing/aec3/reverb_decay_estimator.h" 23 #include "modules/audio_processing/aec3/reverb_frequency_response.h" 24 25 namespace webrtc { 26 27 class ApmDataDumper; 28 29 // Class for estimating the model parameters for the reverberant echo. 30 class ReverbModelEstimator { 31 public: 32 ReverbModelEstimator(const EchoCanceller3Config& config, 33 size_t num_capture_channels); 34 ~ReverbModelEstimator(); 35 36 // Updates the estimates based on new data. 37 void Update( 38 rtc::ArrayView<const std::vector<float>> impulse_responses, 39 rtc::ArrayView<const std::vector<std::array<float, kFftLengthBy2Plus1>>> 40 frequency_responses, 41 rtc::ArrayView<const absl::optional<float>> linear_filter_qualities, 42 rtc::ArrayView<const int> filter_delays_blocks, 43 const std::vector<bool>& usable_linear_estimates, 44 bool stationary_block); 45 46 // Returns the exponential decay of the reverberant echo. The parameter `mild` 47 // indicates which exponential decay to return, the default one or a milder 48 // one. 49 // TODO(peah): Correct to properly support multiple channels. ReverbDecay(bool mild)50 float ReverbDecay(bool mild) const { 51 return reverb_decay_estimators_[0]->Decay(mild); 52 } 53 54 // Return the frequency response of the reverberant echo. 55 // TODO(peah): Correct to properly support multiple channels. GetReverbFrequencyResponse()56 rtc::ArrayView<const float> GetReverbFrequencyResponse() const { 57 return reverb_frequency_responses_[0].FrequencyResponse(); 58 } 59 60 // Dumps debug data. Dump(ApmDataDumper * data_dumper)61 void Dump(ApmDataDumper* data_dumper) const { 62 reverb_decay_estimators_[0]->Dump(data_dumper); 63 } 64 65 private: 66 std::vector<std::unique_ptr<ReverbDecayEstimator>> reverb_decay_estimators_; 67 std::vector<ReverbFrequencyResponse> reverb_frequency_responses_; 68 }; 69 70 } // namespace webrtc 71 72 #endif // MODULES_AUDIO_PROCESSING_AEC3_REVERB_MODEL_ESTIMATOR_H_ 73