blob: 29c6908a6c721c40378edabff3e5f5152b775dca [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#include "modules/audio_processing/aec3/echo_audibility.h"
12
13#include <algorithm>
14
15#include "modules/audio_processing/aec3/aec3_common.h"
16#include "modules/audio_processing/aec3/stationarity_estimator.h"
17
18namespace webrtc {
19
20EchoAudibility::EchoAudibility() {
21 Reset();
22}
23
24void EchoAudibility::Reset() {
25 render_stationarity_.Reset();
26}
27
28EchoAudibility::~EchoAudibility() = default;
29
30void EchoAudibility::Update(const RenderBuffer& render_buffer,
31 size_t delay_blocks,
32 size_t capture_block_counter) {
33 RTC_DCHECK_GT(capture_block_counter, delay_blocks);
34
35 size_t num_lookahead = std::min(StationarityEstimator::GetMaxNumLookAhead(),
36 render_buffer.Headroom() - delay_blocks + 1);
37 int render_block_number = capture_block_counter - delay_blocks;
38
39 for (size_t k = 0; k < (num_lookahead + 1); ++k) {
40 // Delay changes can potentially make that not all the farend blocks
41 // are seen. That effect is assumed to have a minimum effect in the
42 // estimation.
43 render_stationarity_.Update(render_buffer.Spectrum(delay_blocks - k),
44 render_block_number + k);
45 }
46 render_stationarity_.UpdateStationarityFlags(render_block_number,
47 num_lookahead);
48}
49
50} // namespace webrtc