blob: 7b9f283257fd4efba32072a45f20135215c21195 [file] [log] [blame]
Jesús de Vicente Peñad5cb4772018-04-25 13:58:45 +02001/*
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"
21#include "modules/audio_processing/aec3/render_buffer.h"
22#include "modules/audio_processing/aec3/stationarity_estimator.h"
23#include "rtc_base/constructormagic.h"
24
25namespace webrtc {
26
27class ApmDataDumper;
28
29class EchoAudibility {
30 public:
31 EchoAudibility();
32 ~EchoAudibility();
33
34 // Feed new render data to the echo audibility estimator.
35 void Update(const RenderBuffer& render_buffer,
36 size_t delay_blocks,
Jesús de Vicente Peñadc872b62018-04-25 16:11:42 +020037 size_t capture_block_counter_,
38 bool external_delay_seen);
Jesús de Vicente Peñad5cb4772018-04-25 13:58:45 +020039
40 // Get the residual echo scaling.
41 void GetResidualEchoScaling(rtc::ArrayView<float> residual_scaling) const {
42 for (size_t band = 0; band < residual_scaling.size(); ++band) {
43 if (render_stationarity_.IsBandStationary(band)) {
44 residual_scaling[band] = 0.f;
45 } else {
46 residual_scaling[band] = 1.0f;
47 }
48 }
49 }
50
51 private:
52 // Reset the EchoAudibility class.
53 void Reset();
54
55 // Compute the residual scaling per frequency for the current frame.
56 void ComputeResidualScaling();
Jesús de Vicente Peñadc872b62018-04-25 16:11:42 +020057
Jesús de Vicente Peña95581922018-04-30 08:37:57 +020058 // Updates the render stationarity flags for the current frame.
59 void UpdateRenderStationarityFlags(const RenderBuffer& render_buffer,
60 size_t delay_blocks);
Jesús de Vicente Peñadc872b62018-04-25 16:11:42 +020061
Jesús de Vicente Peña95581922018-04-30 08:37:57 +020062 // Updates the noise estimator with the new render data since the previous
63 // call to this method.
64 void UpdateRenderNoiseEstimator(const RenderBuffer& render_buffer);
Jesús de Vicente Peñadc872b62018-04-25 16:11:42 +020065
Jesús de Vicente Peñadc872b62018-04-25 16:11:42 +020066 int render_write_prev_;
Jesús de Vicente Peñad5cb4772018-04-25 13:58:45 +020067 StationarityEstimator render_stationarity_;
68 RTC_DISALLOW_COPY_AND_ASSIGN(EchoAudibility);
69};
70
71} // namespace webrtc
72
73#endif // MODULES_AUDIO_PROCESSING_AEC3_ECHO_AUDIBILITY_H_