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