Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 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_ECHO_AUDIBILITY_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AEC3_ECHO_AUDIBILITY_H_ |
| 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 15 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 16 | #include "absl/types/optional.h" |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 17 | #include "api/array_view.h" |
Jesús de Vicente Peña | 2f2633d | 2018-05-02 09:47:22 +0200 | [diff] [blame] | 18 | #include "modules/audio_processing/aec3/matrix_buffer.h" |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 19 | #include "modules/audio_processing/aec3/render_buffer.h" |
| 20 | #include "modules/audio_processing/aec3/stationarity_estimator.h" |
Jesús de Vicente Peña | 2f2633d | 2018-05-02 09:47:22 +0200 | [diff] [blame] | 21 | #include "modules/audio_processing/aec3/vector_buffer.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "rtc_base/constructor_magic.h" |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 26 | class EchoAudibility { |
| 27 | public: |
Jesús de Vicente Peña | 836a7a2 | 2018-08-31 15:03:04 +0200 | [diff] [blame] | 28 | explicit EchoAudibility(bool use_render_stationarity_at_init); |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 29 | ~EchoAudibility(); |
| 30 | |
| 31 | // Feed new render data to the echo audibility estimator. |
| 32 | void Update(const RenderBuffer& render_buffer, |
Jesús de Vicente Peña | c98849c | 2018-10-22 11:41:05 +0200 | [diff] [blame] | 33 | rtc::ArrayView<const float> render_reverb_contribution_spectrum, |
Jesús de Vicente Peña | 2f2633d | 2018-05-02 09:47:22 +0200 | [diff] [blame] | 34 | int delay_blocks, |
Jesús de Vicente Peña | c98849c | 2018-10-22 11:41:05 +0200 | [diff] [blame] | 35 | bool external_delay_seen); |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 36 | // Get the residual echo scaling. |
Per Åhgren | b2d7116 | 2018-09-10 14:10:34 +0200 | [diff] [blame] | 37 | void GetResidualEchoScaling(bool filter_has_had_time_to_converge, |
| 38 | rtc::ArrayView<float> residual_scaling) const { |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 39 | for (size_t band = 0; band < residual_scaling.size(); ++band) { |
Per Åhgren | b2d7116 | 2018-09-10 14:10:34 +0200 | [diff] [blame] | 40 | if (render_stationarity_.IsBandStationary(band) && |
Jesús de Vicente Peña | ba801f6 | 2019-04-16 11:32:11 +0200 | [diff] [blame^] | 41 | (filter_has_had_time_to_converge || |
| 42 | use_render_stationarity_at_init_)) { |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 43 | residual_scaling[band] = 0.f; |
| 44 | } else { |
| 45 | residual_scaling[band] = 1.0f; |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 50 | // Returns true if the current render block is estimated as stationary. |
| 51 | bool IsBlockStationary() const { |
| 52 | return render_stationarity_.IsBlockStationary(); |
| 53 | } |
| 54 | |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 55 | private: |
| 56 | // Reset the EchoAudibility class. |
| 57 | void Reset(); |
| 58 | |
Jesús de Vicente Peña | 9558192 | 2018-04-30 08:37:57 +0200 | [diff] [blame] | 59 | // Updates the render stationarity flags for the current frame. |
Jesús de Vicente Peña | c98849c | 2018-10-22 11:41:05 +0200 | [diff] [blame] | 60 | void UpdateRenderStationarityFlags( |
| 61 | const RenderBuffer& render_buffer, |
| 62 | rtc::ArrayView<const float> render_reverb_contribution_spectrum, |
| 63 | int delay_blocks); |
Jesús de Vicente Peña | dc872b6 | 2018-04-25 16:11:42 +0200 | [diff] [blame] | 64 | |
Jesús de Vicente Peña | 9558192 | 2018-04-30 08:37:57 +0200 | [diff] [blame] | 65 | // Updates the noise estimator with the new render data since the previous |
| 66 | // call to this method. |
Jesús de Vicente Peña | 2f2633d | 2018-05-02 09:47:22 +0200 | [diff] [blame] | 67 | void UpdateRenderNoiseEstimator(const VectorBuffer& spectrum_buffer, |
| 68 | const MatrixBuffer& block_buffer, |
| 69 | bool external_delay_seen); |
Jesús de Vicente Peña | dc872b6 | 2018-04-25 16:11:42 +0200 | [diff] [blame] | 70 | |
Jesús de Vicente Peña | 2f2633d | 2018-05-02 09:47:22 +0200 | [diff] [blame] | 71 | // Returns a bool being true if the render signal contains just close to zero |
| 72 | // values. |
| 73 | bool IsRenderTooLow(const MatrixBuffer& block_buffer); |
| 74 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 75 | absl::optional<int> render_spectrum_write_prev_; |
Jesús de Vicente Peña | 2f2633d | 2018-05-02 09:47:22 +0200 | [diff] [blame] | 76 | int render_block_write_prev_; |
| 77 | bool non_zero_render_seen_; |
Jesús de Vicente Peña | 836a7a2 | 2018-08-31 15:03:04 +0200 | [diff] [blame] | 78 | const bool use_render_stationarity_at_init_; |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 79 | StationarityEstimator render_stationarity_; |
| 80 | RTC_DISALLOW_COPY_AND_ASSIGN(EchoAudibility); |
| 81 | }; |
| 82 | |
| 83 | } // namespace webrtc |
| 84 | |
| 85 | #endif // MODULES_AUDIO_PROCESSING_AEC3_ECHO_AUDIBILITY_H_ |