Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 01b3df3

Browse files
peahCommit bot
authored andcommitted
Merge of Corrected the behavior in AEC3 during buffer overruns and underruns
This CL contains a merge of the cl debaa44 into the branch M59. This CL corrects the behavior in AEC3 during buffer overruns and underruns in three ways. 1) When there is no render signal available (due to a buffering issues, a zero block is inserted instead of the previous render block. This avoids the same block being repeatedly inserted when there are many back-to-back calls. 2) The internal counters in the main adaptive filter gain are also reset when the filter is reset. 3) The internal counters in the shadow adaptive filter gain are reset when the filter is reset. NOTRY=true NOPRESUBMIT=true BUG=chromium:717920,webrtc:7559 Review-Url: https://codereview.webrtc.org/2862533002 Cr-Commit-Position: refs/heads/master@{#17991} (cherry picked from commit debaa44) Review-Url: https://codereview.webrtc.org/2862683002 Cr-Commit-Position: refs/branch-heads/59@{#7} Cr-Branched-From: 10d095d-refs/heads/master@{#17657}
1 parent 02ba69d commit 01b3df3

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

webrtc/modules/audio_processing/aec3/main_filter_update_gain.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace webrtc {
2222
namespace {
2323

2424
constexpr float kHErrorInitial = 10000.f;
25+
constexpr int kPoorExcitationCounterInitial = 1000;
2526

2627
} // namespace
2728

@@ -30,14 +31,16 @@ int MainFilterUpdateGain::instance_count_ = 0;
3031
MainFilterUpdateGain::MainFilterUpdateGain()
3132
: data_dumper_(
3233
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
33-
poor_excitation_counter_(1000) {
34+
poor_excitation_counter_(kPoorExcitationCounterInitial) {
3435
H_error_.fill(kHErrorInitial);
3536
}
3637

3738
MainFilterUpdateGain::~MainFilterUpdateGain() {}
3839

3940
void MainFilterUpdateGain::HandleEchoPathChange() {
4041
H_error_.fill(kHErrorInitial);
42+
poor_excitation_counter_ = kPoorExcitationCounterInitial;
43+
call_counter_ = 0;
4144
}
4245

4346
void MainFilterUpdateGain::Compute(

webrtc/modules/audio_processing/aec3/render_delay_buffer.cc

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class RenderDelayBufferImpl final : public RenderDelayBuffer {
9797
DownsampledRenderBuffer downsampled_render_buffer_;
9898
DecimatorBy4 render_decimator_;
9999
ApiCallJitterBuffer api_call_jitter_buffer_;
100+
const std::vector<std::vector<float>> zero_block_;
100101
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderDelayBufferImpl);
101102
};
102103

@@ -107,7 +108,8 @@ RenderDelayBufferImpl::RenderDelayBufferImpl(size_t num_bands)
107108
num_bands,
108109
std::max(kResidualEchoPowerRenderWindowSize, kAdaptiveFilterLength),
109110
std::vector<size_t>(1, kAdaptiveFilterLength)),
110-
api_call_jitter_buffer_(num_bands) {
111+
api_call_jitter_buffer_(num_bands),
112+
zero_block_(num_bands, std::vector<float>(kBlockSize, 0.f)) {
111113
buffer_.fill(std::vector<std::vector<float>>(
112114
num_bands, std::vector<float>(kBlockSize, 0.f)));
113115

@@ -147,12 +149,11 @@ bool RenderDelayBufferImpl::Insert(
147149

148150
bool RenderDelayBufferImpl::UpdateBuffers() {
149151
bool underrun = true;
150-
// Update the buffers with a new block if such is available, otherwise repeat
151-
// the previous block.
152+
// Update the buffers with a new block if such is available, otherwise insert
153+
// a block of silence.
152154
if (api_call_jitter_buffer_.Size() > 0) {
153155
last_insert_index_ = (last_insert_index_ + 1) % buffer_.size();
154156
api_call_jitter_buffer_.Remove(&buffer_[last_insert_index_]);
155-
156157
underrun = false;
157158
}
158159

@@ -162,14 +163,22 @@ bool RenderDelayBufferImpl::UpdateBuffers() {
162163
downsampled_render_buffer_.buffer.size();
163164

164165
std::array<float, kSubBlockSize> render_downsampled;
165-
render_decimator_.Decimate(buffer_[last_insert_index_][0],
166-
render_downsampled);
166+
if (underrun) {
167+
render_decimator_.Decimate(zero_block_[0], render_downsampled);
168+
} else {
169+
render_decimator_.Decimate(buffer_[last_insert_index_][0],
170+
render_downsampled);
171+
}
167172
std::copy(render_downsampled.rbegin(), render_downsampled.rend(),
168173
downsampled_render_buffer_.buffer.begin() +
169174
downsampled_render_buffer_.position);
170175

171-
fft_buffer_.Insert(
172-
buffer_[(last_insert_index_ - delay_ + buffer_.size()) % buffer_.size()]);
176+
if (underrun) {
177+
fft_buffer_.Insert(zero_block_);
178+
} else {
179+
fft_buffer_.Insert(buffer_[(last_insert_index_ - delay_ + buffer_.size()) %
180+
buffer_.size()]);
181+
}
173182
return !underrun;
174183
}
175184

webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
namespace webrtc {
1919

20+
void ShadowFilterUpdateGain::HandleEchoPathChange() {
21+
// TODO(peah): Check whether this counter should instead be initialized to a
22+
// large value.
23+
poor_signal_excitation_counter_ = 0;
24+
call_counter_ = 0;
25+
}
26+
2027
void ShadowFilterUpdateGain::Compute(
2128
const RenderBuffer& render_buffer,
2229
const RenderSignalAnalyzer& render_signal_analyzer,

webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ namespace webrtc {
2121
// Provides functionality for computing the fixed gain for the shadow filter.
2222
class ShadowFilterUpdateGain {
2323
public:
24+
// Takes action in the case of a known echo path change.
25+
void HandleEchoPathChange();
26+
2427
// Computes the gain.
2528
void Compute(const RenderBuffer& render_buffer,
2629
const RenderSignalAnalyzer& render_signal_analyzer,
@@ -30,6 +33,8 @@ class ShadowFilterUpdateGain {
3033
FftData* G);
3134

3235
private:
36+
// TODO(peah): Check whether this counter should instead be initialized to a
37+
// large value.
3338
size_t poor_signal_excitation_counter_ = 0;
3439
size_t call_counter_ = 0;
3540
};

webrtc/modules/audio_processing/aec3/subtractor.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void Subtractor::HandleEchoPathChange(
5555
main_filter_.HandleEchoPathChange();
5656
shadow_filter_.HandleEchoPathChange();
5757
G_main_.HandleEchoPathChange();
58+
G_shadow_.HandleEchoPathChange();
5859
}
5960
}
6061

0 commit comments

Comments
 (0)