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 | |
| 14 | #include <algorithm> |
| 15 | #include <array> |
| 16 | #include <limits> |
| 17 | #include <memory> |
| 18 | #include <vector> |
| 19 | |
| 20 | #include "api/array_view.h" |
Jesús de Vicente Peña | 2f2633d | 2018-05-02 09:47:22 +0200 | [diff] [blame] | 21 | #include "api/optional.h" |
| 22 | #include "modules/audio_processing/aec3/matrix_buffer.h" |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 23 | #include "modules/audio_processing/aec3/render_buffer.h" |
| 24 | #include "modules/audio_processing/aec3/stationarity_estimator.h" |
Jesús de Vicente Peña | 2f2633d | 2018-05-02 09:47:22 +0200 | [diff] [blame] | 25 | #include "modules/audio_processing/aec3/vector_buffer.h" |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 26 | #include "rtc_base/constructormagic.h" |
| 27 | |
| 28 | namespace webrtc { |
| 29 | |
| 30 | class ApmDataDumper; |
| 31 | |
| 32 | class EchoAudibility { |
| 33 | public: |
| 34 | EchoAudibility(); |
| 35 | ~EchoAudibility(); |
| 36 | |
| 37 | // Feed new render data to the echo audibility estimator. |
| 38 | void Update(const RenderBuffer& render_buffer, |
Jesús de Vicente Peña | 2f2633d | 2018-05-02 09:47:22 +0200 | [diff] [blame] | 39 | int delay_blocks, |
Jesús de Vicente Peña | 075cb2b | 2018-06-13 15:13:55 +0200 | [diff] [blame^] | 40 | bool external_delay_seen, |
| 41 | float reverb_decay); |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 42 | |
| 43 | // Get the residual echo scaling. |
| 44 | void GetResidualEchoScaling(rtc::ArrayView<float> residual_scaling) const { |
| 45 | for (size_t band = 0; band < residual_scaling.size(); ++band) { |
| 46 | if (render_stationarity_.IsBandStationary(band)) { |
| 47 | residual_scaling[band] = 0.f; |
| 48 | } else { |
| 49 | residual_scaling[band] = 1.0f; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | private: |
| 55 | // Reset the EchoAudibility class. |
| 56 | void Reset(); |
| 57 | |
Jesús de Vicente Peña | 9558192 | 2018-04-30 08:37:57 +0200 | [diff] [blame] | 58 | // Updates the render stationarity flags for the current frame. |
| 59 | void UpdateRenderStationarityFlags(const RenderBuffer& render_buffer, |
Jesús de Vicente Peña | 075cb2b | 2018-06-13 15:13:55 +0200 | [diff] [blame^] | 60 | int delay_blocks, |
| 61 | float reverb_decay); |
Jesús de Vicente Peña | dc872b6 | 2018-04-25 16:11:42 +0200 | [diff] [blame] | 62 | |
Jesús de Vicente Peña | 9558192 | 2018-04-30 08:37:57 +0200 | [diff] [blame] | 63 | // Updates the noise estimator with the new render data since the previous |
| 64 | // call to this method. |
Jesús de Vicente Peña | 2f2633d | 2018-05-02 09:47:22 +0200 | [diff] [blame] | 65 | void UpdateRenderNoiseEstimator(const VectorBuffer& spectrum_buffer, |
| 66 | const MatrixBuffer& block_buffer, |
| 67 | bool external_delay_seen); |
Jesús de Vicente Peña | dc872b6 | 2018-04-25 16:11:42 +0200 | [diff] [blame] | 68 | |
Jesús de Vicente Peña | 2f2633d | 2018-05-02 09:47:22 +0200 | [diff] [blame] | 69 | // Returns a bool being true if the render signal contains just close to zero |
| 70 | // values. |
| 71 | bool IsRenderTooLow(const MatrixBuffer& block_buffer); |
| 72 | |
| 73 | rtc::Optional<int> render_spectrum_write_prev_; |
| 74 | int render_block_write_prev_; |
| 75 | bool non_zero_render_seen_; |
Jesús de Vicente Peña | d5cb477 | 2018-04-25 13:58:45 +0200 | [diff] [blame] | 76 | StationarityEstimator render_stationarity_; |
| 77 | RTC_DISALLOW_COPY_AND_ASSIGN(EchoAudibility); |
| 78 | }; |
| 79 | |
| 80 | } // namespace webrtc |
| 81 | |
| 82 | #endif // MODULES_AUDIO_PROCESSING_AEC3_ECHO_AUDIBILITY_H_ |