Update filter analyzer for multi channel

Multi-channel behaviors introduced in this CL:

- All filters are analyzed independently. The filtering is considered
consistent if any filter is consistent.

- The filter echo path gain used to detect saturation is maxed across
capture channels.

- The filter delay is taken to be the minimum of all filters:
Any module that looks in the render data starting from the filter
delay will iterate over all render audio present in any channel.

- The FilterAnalyzer will consider a render block to be active if any
render channel has activity.

The changes in the CL has been shown to be bitexact on a
large set of mono recordings.

Bug: webrtc:10913
Change-Id: I1e360cd7136ee82d1f6e0f8a1459806e83f4426d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/155363
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Sam Zackrisson <saza@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29408}
This commit is contained in:
Sam Zackrisson 2019-10-08 16:17:48 +02:00 committed by Commit Bot
parent 43bd7601d7
commit 46b0140172
11 changed files with 185 additions and 122 deletions

View File

@ -346,11 +346,14 @@ TEST(AdaptiveFirFilter, FilterAndAdapt) {
config.filter.main.length_blocks, config.filter.main.length_blocks, config.filter.main.length_blocks, config.filter.main.length_blocks,
config.filter.config_change_duration_blocks, num_render_channels, config.filter.config_change_duration_blocks, num_render_channels,
DetectOptimization(), &data_dumper); DetectOptimization(), &data_dumper);
std::vector<std::array<float, kFftLengthBy2Plus1>> H2( std::vector<std::vector<std::array<float, kFftLengthBy2Plus1>>> H2(
filter.max_filter_size_partitions(), kNumCaptureChannels, std::vector<std::array<float, kFftLengthBy2Plus1>>(
std::array<float, kFftLengthBy2Plus1>()); filter.max_filter_size_partitions(),
std::vector<float> h( std::array<float, kFftLengthBy2Plus1>()));
GetTimeDomainLength(filter.max_filter_size_partitions()), 0.f); std::vector<std::vector<float>> h(
kNumCaptureChannels,
std::vector<float>(
GetTimeDomainLength(filter.max_filter_size_partitions()), 0.f));
Aec3Fft fft; Aec3Fft fft;
config.delay.default_delay = 1; config.delay.default_delay = 1;
std::unique_ptr<RenderDelayBuffer> render_delay_buffer( std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
@ -454,11 +457,11 @@ TEST(AdaptiveFirFilter, FilterAndAdapt) {
render_buffer->SpectralSum(filter.SizePartitions(), &render_power); render_buffer->SpectralSum(filter.SizePartitions(), &render_power);
gain.Compute(render_power, render_signal_analyzer, E, gain.Compute(render_power, render_signal_analyzer, E,
filter.SizePartitions(), false, &G); filter.SizePartitions(), false, &G);
filter.Adapt(*render_buffer, G, &h); filter.Adapt(*render_buffer, G, &h[0]);
aec_state.HandleEchoPathChange(EchoPathVariability( aec_state.HandleEchoPathChange(EchoPathVariability(
false, EchoPathVariability::DelayAdjustment::kNone, false)); false, EchoPathVariability::DelayAdjustment::kNone, false));
filter.ComputeFrequencyResponse(&H2); filter.ComputeFrequencyResponse(&H2[0]);
aec_state.Update(delay_estimate, H2, h, *render_buffer, E2_main, Y2, aec_state.Update(delay_estimate, H2, h, *render_buffer, E2_main, Y2,
output); output);
} }

View File

@ -66,18 +66,26 @@ AecState::AecState(const EchoCanceller3Config& config,
filter_quality_state_(config_), filter_quality_state_(config_),
erl_estimator_(2 * kNumBlocksPerSecond), erl_estimator_(2 * kNumBlocksPerSecond),
erle_estimator_(2 * kNumBlocksPerSecond, config_, num_capture_channels), erle_estimator_(2 * kNumBlocksPerSecond, config_, num_capture_channels),
filter_analyzer_(config_), max_echo_path_gain_(config_.ep_strength.default_gain),
filter_analyzers_(num_capture_channels),
echo_audibility_( echo_audibility_(
config_.echo_audibility.use_stationarity_properties_at_init), config_.echo_audibility.use_stationarity_properties_at_init),
reverb_model_estimator_(config_), reverb_model_estimator_(config_),
subtractor_output_analyzers_(num_capture_channels) {} subtractor_output_analyzers_(num_capture_channels) {
for (size_t ch = 0; ch < num_capture_channels; ++ch) {
filter_analyzers_[ch] = std::make_unique<FilterAnalyzer>(config_);
}
}
AecState::~AecState() = default; AecState::~AecState() = default;
void AecState::HandleEchoPathChange( void AecState::HandleEchoPathChange(
const EchoPathVariability& echo_path_variability) { const EchoPathVariability& echo_path_variability) {
const auto full_reset = [&]() { const auto full_reset = [&]() {
filter_analyzer_.Reset(); for (auto& filter_analyzer : filter_analyzers_) {
filter_analyzer->Reset();
}
max_echo_path_gain_ = config_.ep_strength.default_gain;
capture_signal_saturation_ = false; capture_signal_saturation_ = false;
strong_not_saturated_render_blocks_ = 0; strong_not_saturated_render_blocks_ = 0;
blocks_with_active_render_ = 0; blocks_with_active_render_ = 0;
@ -104,26 +112,43 @@ void AecState::HandleEchoPathChange(
void AecState::Update( void AecState::Update(
const absl::optional<DelayEstimate>& external_delay, const absl::optional<DelayEstimate>& external_delay,
const std::vector<std::array<float, kFftLengthBy2Plus1>>& rtc::ArrayView<const std::vector<std::array<float, kFftLengthBy2Plus1>>>
adaptive_filter_frequency_response, adaptive_filter_frequency_response,
const std::vector<float>& adaptive_filter_impulse_response, rtc::ArrayView<const std::vector<float>> adaptive_filter_impulse_response,
const RenderBuffer& render_buffer, const RenderBuffer& render_buffer,
const std::array<float, kFftLengthBy2Plus1>& E2_main, const std::array<float, kFftLengthBy2Plus1>& E2_main,
const std::array<float, kFftLengthBy2Plus1>& Y2, const std::array<float, kFftLengthBy2Plus1>& Y2,
rtc::ArrayView<const SubtractorOutput> subtractor_output) { rtc::ArrayView<const SubtractorOutput> subtractor_output) {
RTC_DCHECK_EQ(subtractor_output.size(), subtractor_output_analyzers_.size()); const size_t num_capture_channels = filter_analyzers_.size();
RTC_DCHECK_EQ(num_capture_channels, subtractor_output.size());
RTC_DCHECK_EQ(num_capture_channels, subtractor_output_analyzers_.size());
RTC_DCHECK_EQ(num_capture_channels,
adaptive_filter_frequency_response.size());
RTC_DCHECK_EQ(num_capture_channels, adaptive_filter_impulse_response.size());
// Analyze the filter output. // Analyze the filter outputs and filters.
bool any_filter_converged = false;
bool all_filters_diverged = true;
bool any_filter_consistent = false;
max_echo_path_gain_ = 0.f;
for (size_t ch = 0; ch < subtractor_output.size(); ++ch) { for (size_t ch = 0; ch < subtractor_output.size(); ++ch) {
subtractor_output_analyzers_[ch].Update(subtractor_output[ch]); subtractor_output_analyzers_[ch].Update(subtractor_output[ch]);
} any_filter_converged = any_filter_converged ||
subtractor_output_analyzers_[ch].ConvergedFilter();
all_filters_diverged = all_filters_diverged &&
subtractor_output_analyzers_[ch].DivergedFilter();
// Analyze the properties of the filter. filter_analyzers_[ch]->Update(adaptive_filter_impulse_response[ch],
filter_analyzer_.Update(adaptive_filter_impulse_response, render_buffer); render_buffer);
any_filter_consistent =
any_filter_consistent || filter_analyzers_[ch]->Consistent();
max_echo_path_gain_ =
std::max(max_echo_path_gain_, filter_analyzers_[ch]->Gain());
}
// Estimate the direct path delay of the filter. // Estimate the direct path delay of the filter.
if (config_.filter.use_linear_filter) { if (config_.filter.use_linear_filter) {
delay_state_.Update(filter_analyzer_, external_delay, delay_state_.Update(filter_analyzers_, external_delay,
strong_not_saturated_render_blocks_); strong_not_saturated_render_blocks_);
} }
@ -170,7 +195,7 @@ void AecState::Update(
/*channel=*/0); /*channel=*/0);
const auto& X2_input_erle = X2_reverb; const auto& X2_input_erle = X2_reverb;
erle_estimator_.Update(render_buffer, adaptive_filter_frequency_response, erle_estimator_.Update(render_buffer, adaptive_filter_frequency_response[0],
X2_input_erle, Y2, E2_main, X2_input_erle, Y2, E2_main,
subtractor_output_analyzers_[0].ConvergedFilter(), subtractor_output_analyzers_[0].ConvergedFilter(),
config_.erle.onset_detection); config_.erle.onset_detection);
@ -188,24 +213,22 @@ void AecState::Update(
// Detect whether the transparent mode should be activated. // Detect whether the transparent mode should be activated.
transparent_state_.Update(delay_state_.DirectPathFilterDelay(), transparent_state_.Update(delay_state_.DirectPathFilterDelay(),
filter_analyzer_.Consistent(), any_filter_consistent, any_filter_converged,
subtractor_output_analyzers_[0].ConvergedFilter(), all_filters_diverged, active_render,
subtractor_output_analyzers_[0].DivergedFilter(), SaturatedCapture());
active_render, SaturatedCapture());
// Analyze the quality of the filter. // Analyze the quality of the filter.
filter_quality_state_.Update( filter_quality_state_.Update(active_render, TransparentMode(),
active_render, TransparentMode(), SaturatedCapture(), SaturatedCapture(), external_delay,
filter_analyzer_.Consistent(), external_delay, any_filter_converged);
subtractor_output_analyzers_[0].ConvergedFilter());
// Update the reverb estimate. // Update the reverb estimate.
const bool stationary_block = const bool stationary_block =
config_.echo_audibility.use_stationarity_properties && config_.echo_audibility.use_stationarity_properties &&
echo_audibility_.IsBlockStationary(); echo_audibility_.IsBlockStationary();
reverb_model_estimator_.Update(filter_analyzer_.GetAdjustedFilter(), reverb_model_estimator_.Update(filter_analyzers_[0]->GetAdjustedFilter(),
adaptive_filter_frequency_response, adaptive_filter_frequency_response[0],
erle_estimator_.GetInstLinearQualityEstimate(), erle_estimator_.GetInstLinearQualityEstimate(),
delay_state_.DirectPathFilterDelay(), delay_state_.DirectPathFilterDelay(),
UsableLinearEstimate(), stationary_block); UsableLinearEstimate(), stationary_block);
@ -217,18 +240,16 @@ void AecState::Update(
data_dumper_->DumpRaw("aec3_erle", Erle()[0]); data_dumper_->DumpRaw("aec3_erle", Erle()[0]);
data_dumper_->DumpRaw("aec3_usable_linear_estimate", UsableLinearEstimate()); data_dumper_->DumpRaw("aec3_usable_linear_estimate", UsableLinearEstimate());
data_dumper_->DumpRaw("aec3_transparent_mode", TransparentMode()); data_dumper_->DumpRaw("aec3_transparent_mode", TransparentMode());
data_dumper_->DumpRaw("aec3_filter_delay", filter_analyzer_.DelayBlocks()); data_dumper_->DumpRaw("aec3_filter_delay",
filter_analyzers_[0]->DelayBlocks());
data_dumper_->DumpRaw("aec3_consistent_filter", data_dumper_->DumpRaw("aec3_any_filter_consistent", any_filter_consistent);
filter_analyzer_.Consistent());
data_dumper_->DumpRaw("aec3_initial_state", data_dumper_->DumpRaw("aec3_initial_state",
initial_state_.InitialStateActive()); initial_state_.InitialStateActive());
data_dumper_->DumpRaw("aec3_capture_saturation", SaturatedCapture()); data_dumper_->DumpRaw("aec3_capture_saturation", SaturatedCapture());
data_dumper_->DumpRaw("aec3_echo_saturation", SaturatedEcho()); data_dumper_->DumpRaw("aec3_echo_saturation", SaturatedEcho());
data_dumper_->DumpRaw("aec3_converged_filter", data_dumper_->DumpRaw("aec3_any_filter_converged", any_filter_converged);
subtractor_output_analyzers_[0].ConvergedFilter()); data_dumper_->DumpRaw("aec3_all_filters_diverged", all_filters_diverged);
data_dumper_->DumpRaw("aec3_diverged_filter",
subtractor_output_analyzers_[0].DivergedFilter());
data_dumper_->DumpRaw("aec3_external_delay_avaliable", data_dumper_->DumpRaw("aec3_external_delay_avaliable",
external_delay ? 1 : 0); external_delay ? 1 : 0);
@ -268,7 +289,7 @@ AecState::FilterDelay::FilterDelay(const EchoCanceller3Config& config)
: delay_headroom_samples_(config.delay.delay_headroom_samples) {} : delay_headroom_samples_(config.delay.delay_headroom_samples) {}
void AecState::FilterDelay::Update( void AecState::FilterDelay::Update(
const FilterAnalyzer& filter_analyzer, const std::vector<std::unique_ptr<FilterAnalyzer>>& filter_analyzers,
const absl::optional<DelayEstimate>& external_delay, const absl::optional<DelayEstimate>& external_delay,
size_t blocks_with_proper_filter_adaptation) { size_t blocks_with_proper_filter_adaptation) {
// Update the delay based on the external delay. // Update the delay based on the external delay.
@ -285,7 +306,12 @@ void AecState::FilterDelay::Update(
if (delay_estimator_may_not_have_converged && external_delay_) { if (delay_estimator_may_not_have_converged && external_delay_) {
filter_delay_blocks_ = delay_headroom_samples_ / kBlockSize; filter_delay_blocks_ = delay_headroom_samples_ / kBlockSize;
} else { } else {
filter_delay_blocks_ = filter_analyzer.DelayBlocks(); // Conservatively use the min delay among the filters.
filter_delay_blocks_ = filter_analyzers[0]->DelayBlocks();
for (size_t ch = 1; ch < filter_analyzers.size(); ++ch) {
filter_delay_blocks_ =
std::min(filter_delay_blocks_, filter_analyzers[ch]->DelayBlocks());
}
} }
} }
@ -306,16 +332,16 @@ void AecState::TransparentMode::Reset() {
} }
void AecState::TransparentMode::Update(int filter_delay_blocks, void AecState::TransparentMode::Update(int filter_delay_blocks,
bool consistent_filter, bool any_filter_consistent,
bool converged_filter, bool any_filter_converged,
bool diverged_filter, bool all_filters_diverged,
bool active_render, bool active_render,
bool saturated_capture) { bool saturated_capture) {
++capture_block_counter_; ++capture_block_counter_;
strong_not_saturated_render_blocks_ += strong_not_saturated_render_blocks_ +=
active_render && !saturated_capture ? 1 : 0; active_render && !saturated_capture ? 1 : 0;
if (consistent_filter && filter_delay_blocks < 5) { if (any_filter_consistent && filter_delay_blocks < 5) {
sane_filter_observed_ = true; sane_filter_observed_ = true;
active_blocks_since_sane_filter_ = 0; active_blocks_since_sane_filter_ = 0;
} else if (active_render) { } else if (active_render) {
@ -331,7 +357,7 @@ void AecState::TransparentMode::Update(int filter_delay_blocks,
active_blocks_since_sane_filter_ <= 30 * kNumBlocksPerSecond; active_blocks_since_sane_filter_ <= 30 * kNumBlocksPerSecond;
} }
if (converged_filter) { if (any_filter_converged) {
recent_convergence_during_activity_ = true; recent_convergence_during_activity_ = true;
active_non_converged_sequence_size_ = 0; active_non_converged_sequence_size_ = 0;
non_converged_sequence_size_ = 0; non_converged_sequence_size_ = 0;
@ -347,7 +373,7 @@ void AecState::TransparentMode::Update(int filter_delay_blocks,
} }
} }
if (!diverged_filter) { if (!all_filters_diverged) {
diverged_sequence_size_ = 0; diverged_sequence_size_ = 0;
} else if (++diverged_sequence_size_ >= 60) { } else if (++diverged_sequence_size_ >= 60) {
// TODO(peah): Change these lines to ensure proper triggering of usable // TODO(peah): Change these lines to ensure proper triggering of usable
@ -387,16 +413,15 @@ void AecState::FilteringQualityAnalyzer::Update(
bool active_render, bool active_render,
bool transparent_mode, bool transparent_mode,
bool saturated_capture, bool saturated_capture,
bool consistent_estimate_,
const absl::optional<DelayEstimate>& external_delay, const absl::optional<DelayEstimate>& external_delay,
bool converged_filter) { bool any_filter_converged) {
// Update blocks counter. // Update blocks counter.
const bool filter_update = active_render && !saturated_capture; const bool filter_update = active_render && !saturated_capture;
filter_update_blocks_since_reset_ += filter_update ? 1 : 0; filter_update_blocks_since_reset_ += filter_update ? 1 : 0;
filter_update_blocks_since_start_ += filter_update ? 1 : 0; filter_update_blocks_since_start_ += filter_update ? 1 : 0;
// Store convergence flag when observed. // Store convergence flag when observed.
convergence_seen_ = convergence_seen_ || converged_filter; convergence_seen_ = convergence_seen_ || any_filter_converged;
// Verify requirements for achieving a decent filter. The requirements for // Verify requirements for achieving a decent filter. The requirements for
// filter adaptation at call startup are more restrictive than after an // filter adaptation at call startup are more restrictive than after an

View File

@ -57,7 +57,7 @@ class AecState {
} }
// Returns the estimated echo path gain. // Returns the estimated echo path gain.
float EchoPathGain() const { return filter_analyzer_.Gain(); } float EchoPathGain() const { return max_echo_path_gain_; }
// Returns whether the render signal is currently active. // Returns whether the render signal is currently active.
bool ActiveRender() const { return blocks_with_active_render_ > 200; } bool ActiveRender() const { return blocks_with_active_render_ > 200; }
@ -131,18 +131,20 @@ class AecState {
// Updates the aec state. // Updates the aec state.
// TODO(bugs.webrtc.org/10913): Handle multi-channel adaptive filter response. // TODO(bugs.webrtc.org/10913): Handle multi-channel adaptive filter response.
// TODO(bugs.webrtc.org/10913): Compute multi-channel ERL, ERLE, and reverb. // TODO(bugs.webrtc.org/10913): Compute multi-channel ERL, ERLE, and reverb.
void Update(const absl::optional<DelayEstimate>& external_delay, void Update(
const std::vector<std::array<float, kFftLengthBy2Plus1>>& const absl::optional<DelayEstimate>& external_delay,
adaptive_filter_frequency_response, rtc::ArrayView<const std::vector<std::array<float, kFftLengthBy2Plus1>>>
const std::vector<float>& adaptive_filter_impulse_response, adaptive_filter_frequency_response,
const RenderBuffer& render_buffer, rtc::ArrayView<const std::vector<float>> adaptive_filter_impulse_response,
const std::array<float, kFftLengthBy2Plus1>& E2_main, const RenderBuffer& render_buffer,
const std::array<float, kFftLengthBy2Plus1>& Y2, const std::array<float, kFftLengthBy2Plus1>& E2_main,
rtc::ArrayView<const SubtractorOutput> subtractor_output); const std::array<float, kFftLengthBy2Plus1>& Y2,
rtc::ArrayView<const SubtractorOutput> subtractor_output);
// Returns filter length in blocks. // Returns filter length in blocks.
int FilterLengthBlocks() const { int FilterLengthBlocks() const {
return filter_analyzer_.FilterLengthBlocks(); // All filters have the same length, so arbitrarily return channel 0 length.
return filter_analyzers_[/*channel=*/0]->FilterLengthBlocks();
} }
private: private:
@ -191,9 +193,10 @@ class AecState {
int DirectPathFilterDelay() const { return filter_delay_blocks_; } int DirectPathFilterDelay() const { return filter_delay_blocks_; }
// Updates the delay estimates based on new data. // Updates the delay estimates based on new data.
void Update(const FilterAnalyzer& filter_analyzer, void Update(
const absl::optional<DelayEstimate>& external_delay, const std::vector<std::unique_ptr<FilterAnalyzer>>& filter_analyzer,
size_t blocks_with_proper_filter_adaptation); const absl::optional<DelayEstimate>& external_delay,
size_t blocks_with_proper_filter_adaptation);
private: private:
const int delay_headroom_samples_; const int delay_headroom_samples_;
@ -216,9 +219,9 @@ class AecState {
// Updates the detection deciscion based on new data. // Updates the detection deciscion based on new data.
void Update(int filter_delay_blocks, void Update(int filter_delay_blocks,
bool consistent_filter, bool any_filter_consistent,
bool converged_filter, bool any_filter_converged,
bool diverged_filter, bool all_filters_diverged,
bool active_render, bool active_render,
bool saturated_capture); bool saturated_capture);
@ -257,9 +260,8 @@ class AecState {
void Update(bool active_render, void Update(bool active_render,
bool transparent_mode, bool transparent_mode,
bool saturated_capture, bool saturated_capture,
bool consistent_estimate_,
const absl::optional<DelayEstimate>& external_delay, const absl::optional<DelayEstimate>& external_delay,
bool converged_filter); bool any_filter_converged);
private: private:
bool usable_linear_estimate_ = false; bool usable_linear_estimate_ = false;
@ -290,8 +292,9 @@ class AecState {
ErleEstimator erle_estimator_; ErleEstimator erle_estimator_;
size_t strong_not_saturated_render_blocks_ = 0; size_t strong_not_saturated_render_blocks_ = 0;
size_t blocks_with_active_render_ = 0; size_t blocks_with_active_render_ = 0;
float max_echo_path_gain_;
bool capture_signal_saturation_ = false; bool capture_signal_saturation_ = false;
FilterAnalyzer filter_analyzer_; std::vector<std::unique_ptr<FilterAnalyzer>> filter_analyzers_;
absl::optional<DelayEstimate> external_delay_; absl::optional<DelayEstimate> external_delay_;
EchoAudibility echo_audibility_; EchoAudibility echo_audibility_;
ReverbModelEstimator reverb_model_estimator_; ReverbModelEstimator reverb_model_estimator_;

View File

@ -55,17 +55,23 @@ void RunNormalUsageTest(size_t num_render_channels,
y[ch].fill(1000.f); y[ch].fill(1000.f);
} }
Aec3Fft fft; Aec3Fft fft;
std::vector<std::array<float, kFftLengthBy2Plus1>> std::vector<std::vector<std::array<float, kFftLengthBy2Plus1>>>
converged_filter_frequency_response(10); converged_filter_frequency_response(
for (auto& v : converged_filter_frequency_response) { num_capture_channels,
v.fill(0.01f); std::vector<std::array<float, kFftLengthBy2Plus1>>(10));
for (auto& v_ch : converged_filter_frequency_response) {
for (auto& v : v_ch) {
v.fill(0.01f);
}
} }
std::vector<std::array<float, kFftLengthBy2Plus1>> std::vector<std::vector<std::array<float, kFftLengthBy2Plus1>>>
diverged_filter_frequency_response = converged_filter_frequency_response; diverged_filter_frequency_response = converged_filter_frequency_response;
converged_filter_frequency_response[2].fill(100.f); converged_filter_frequency_response[0][2].fill(100.f);
converged_filter_frequency_response[2][0] = 1.f; converged_filter_frequency_response[0][2][0] = 1.f;
std::vector<float> impulse_response( std::vector<std::vector<float>> impulse_response(
GetTimeDomainLength(config.filter.main.length_blocks), 0.f); num_capture_channels,
std::vector<float>(GetTimeDomainLength(config.filter.main.length_blocks),
0.f));
// Verify that linear AEC usability is true when the filter is converged // Verify that linear AEC usability is true when the filter is converged
for (size_t band = 0; band < kNumBands; ++band) { for (size_t band = 0; band < kNumBands; ++band) {
@ -243,20 +249,28 @@ TEST(AecState, ConvergedFilterDelay) {
x.fill(0.f); x.fill(0.f);
y.fill(0.f); y.fill(0.f);
std::vector<std::array<float, kFftLengthBy2Plus1>> frequency_response( std::vector<std::vector<std::array<float, kFftLengthBy2Plus1>>>
kFilterLengthBlocks); frequency_response(
for (auto& v : frequency_response) { kNumCaptureChannels,
v.fill(0.01f); std::vector<std::array<float, kFftLengthBy2Plus1>>(kFilterLengthBlocks));
for (auto& v_ch : frequency_response) {
for (auto& v : v_ch) {
v.fill(0.01f);
}
} }
std::vector<float> impulse_response( std::vector<std::vector<float>> impulse_response(
GetTimeDomainLength(config.filter.main.length_blocks), 0.f); kNumCaptureChannels,
std::vector<float>(GetTimeDomainLength(config.filter.main.length_blocks),
0.f));
// Verify that the filter delay for a converged filter is properly // Verify that the filter delay for a converged filter is properly
// identified. // identified.
for (int k = 0; k < kFilterLengthBlocks; ++k) { for (int k = 0; k < kFilterLengthBlocks; ++k) {
std::fill(impulse_response.begin(), impulse_response.end(), 0.f); for (auto& ir : impulse_response) {
impulse_response[k * kBlockSize + 1] = 1.f; std::fill(ir.begin(), ir.end(), 0.f);
ir[k * kBlockSize + 1] = 1.f;
}
state.HandleEchoPathChange(echo_path_variability); state.HandleEchoPathChange(echo_path_variability);
subtractor_output[0].ComputeMetrics(y); subtractor_output[0].ComputeMetrics(y);

View File

@ -384,9 +384,9 @@ void EchoRemoverImpl::ProcessCapture(
// Update the AEC state information. // Update the AEC state information.
// TODO(bugs.webrtc.org/10913): Take all subtractors into account. // TODO(bugs.webrtc.org/10913): Take all subtractors into account.
aec_state_.Update(external_delay, subtractor_.FilterFrequencyResponse()[0], aec_state_.Update(external_delay, subtractor_.FilterFrequencyResponse(),
subtractor_.FilterImpulseResponse()[0], *render_buffer, subtractor_.FilterImpulseResponse(), *render_buffer, E2[0],
E2[0], Y2[0], subtractor_output); Y2[0], subtractor_output);
// Choose the linear output. // Choose the linear output.
const auto& Y_fft = aec_state_.UseLinearFilterOutput() ? E : Y; const auto& Y_fft = aec_state_.UseLinearFilterOutput() ? E : Y;

View File

@ -96,8 +96,8 @@ void FilterAnalyzer::AnalyzeRegion(
filter_length_blocks_ = filter_time_domain.size() * (1.f / kBlockSize); filter_length_blocks_ = filter_time_domain.size() * (1.f / kBlockSize);
consistent_estimate_ = consistent_filter_detector_.Detect( consistent_estimate_ = consistent_filter_detector_.Detect(
h_highpass_, region_, render_buffer.Block(-delay_blocks_)[0][0], h_highpass_, region_, render_buffer.Block(-delay_blocks_)[0], peak_index_,
peak_index_, delay_blocks_); delay_blocks_);
} }
void FilterAnalyzer::UpdateFilterGain( void FilterAnalyzer::UpdateFilterGain(
@ -176,7 +176,7 @@ void FilterAnalyzer::ConsistentFilterDetector::Reset() {
bool FilterAnalyzer::ConsistentFilterDetector::Detect( bool FilterAnalyzer::ConsistentFilterDetector::Detect(
rtc::ArrayView<const float> filter_to_analyze, rtc::ArrayView<const float> filter_to_analyze,
const FilterRegion& region, const FilterRegion& region,
rtc::ArrayView<const float> x_block, rtc::ArrayView<const std::vector<float>> x_block,
size_t peak_index, size_t peak_index,
int delay_blocks) { int delay_blocks) {
if (region.start_sample_ == 0) { if (region.start_sample_ == 0) {
@ -212,9 +212,15 @@ bool FilterAnalyzer::ConsistentFilterDetector::Detect(
} }
if (significant_peak_) { if (significant_peak_) {
const float x_energy = std::inner_product(x_block.begin(), x_block.end(), bool active_render_block = false;
x_block.begin(), 0.f); for (auto& x_channel : x_block) {
const bool active_render_block = x_energy > active_render_threshold_; const float x_energy = std::inner_product(
x_channel.begin(), x_channel.end(), x_channel.begin(), 0.f);
if (x_energy > active_render_threshold_) {
active_render_block = true;
break;
}
}
if (consistent_delay_reference_ == delay_blocks) { if (consistent_delay_reference_ == delay_blocks) {
if (active_render_block) { if (active_render_block) {

View File

@ -33,6 +33,9 @@ class FilterAnalyzer {
explicit FilterAnalyzer(const EchoCanceller3Config& config); explicit FilterAnalyzer(const EchoCanceller3Config& config);
~FilterAnalyzer(); ~FilterAnalyzer();
FilterAnalyzer(const FilterAnalyzer&) = delete;
FilterAnalyzer& operator=(const FilterAnalyzer&) = delete;
// Resets the analysis. // Resets the analysis.
void Reset(); void Reset();
@ -82,7 +85,7 @@ class FilterAnalyzer {
void Reset(); void Reset();
bool Detect(rtc::ArrayView<const float> filter_to_analyze, bool Detect(rtc::ArrayView<const float> filter_to_analyze,
const FilterRegion& region, const FilterRegion& region,
rtc::ArrayView<const float> x_block, rtc::ArrayView<const std::vector<float>> x_block,
size_t peak_index, size_t peak_index,
int delay_blocks); int delay_blocks);
@ -110,8 +113,6 @@ class FilterAnalyzer {
int filter_length_blocks_; int filter_length_blocks_;
FilterRegion region_; FilterRegion region_;
ConsistentFilterDetector consistent_filter_detector_; ConsistentFilterDetector consistent_filter_detector_;
RTC_DISALLOW_COPY_AND_ASSIGN(FilterAnalyzer);
}; };
} // namespace webrtc } // namespace webrtc

View File

@ -59,14 +59,19 @@ void RunFilterUpdateTest(int num_blocks_to_process,
config.filter.shadow.length_blocks, config.filter.shadow.length_blocks,
config.filter.config_change_duration_blocks, config.filter.config_change_duration_blocks,
1, optimization, &data_dumper); 1, optimization, &data_dumper);
std::vector<std::array<float, kFftLengthBy2Plus1>> H2( std::vector<std::vector<std::array<float, kFftLengthBy2Plus1>>> H2(
main_filter.max_filter_size_partitions(), kNumChannels, std::vector<std::array<float, kFftLengthBy2Plus1>>(
std::array<float, kFftLengthBy2Plus1>()); main_filter.max_filter_size_partitions(),
for (auto& H2_k : H2) { std::array<float, kFftLengthBy2Plus1>()));
H2_k.fill(0.f); for (auto& H2_ch : H2) {
for (auto& H2_k : H2_ch) {
H2_k.fill(0.f);
}
} }
std::vector<float> h( std::vector<std::vector<float>> h(
GetTimeDomainLength(main_filter.max_filter_size_partitions()), 0.f); kNumChannels,
std::vector<float>(
GetTimeDomainLength(main_filter.max_filter_size_partitions()), 0.f));
Aec3Fft fft; Aec3Fft fft;
std::array<float, kBlockSize> x_old; std::array<float, kBlockSize> x_old;
@ -183,15 +188,15 @@ void RunFilterUpdateTest(int num_blocks_to_process,
main_filter.SizePartitions(), &render_power); main_filter.SizePartitions(), &render_power);
std::array<float, kFftLengthBy2Plus1> erl; std::array<float, kFftLengthBy2Plus1> erl;
ComputeErl(optimization, H2, erl); ComputeErl(optimization, H2[0], erl);
main_gain.Compute(render_power, render_signal_analyzer, output[0], erl, main_gain.Compute(render_power, render_signal_analyzer, output[0], erl,
main_filter.SizePartitions(), saturation, &G); main_filter.SizePartitions(), saturation, &G);
main_filter.Adapt(*render_delay_buffer->GetRenderBuffer(), G, &h); main_filter.Adapt(*render_delay_buffer->GetRenderBuffer(), G, &h[0]);
// Update the delay. // Update the delay.
aec_state.HandleEchoPathChange(EchoPathVariability( aec_state.HandleEchoPathChange(EchoPathVariability(
false, EchoPathVariability::DelayAdjustment::kNone, false)); false, EchoPathVariability::DelayAdjustment::kNone, false));
main_filter.ComputeFrequencyResponse(&H2); main_filter.ComputeFrequencyResponse(&H2[0]);
aec_state.Update(delay_estimate, H2, h, aec_state.Update(delay_estimate, H2, h,
*render_delay_buffer->GetRenderBuffer(), E2_main, Y2, *render_delay_buffer->GetRenderBuffer(), E2_main, Y2,
output); output);

View File

@ -28,7 +28,7 @@ TEST(ResidualEchoEstimator, BasicTest) {
EchoCanceller3Config config; EchoCanceller3Config config;
ResidualEchoEstimator estimator(config, num_render_channels); ResidualEchoEstimator estimator(config, num_render_channels);
AecState aec_state(config, num_render_channels); AecState aec_state(config, num_capture_channels);
std::unique_ptr<RenderDelayBuffer> render_delay_buffer( std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
RenderDelayBuffer::Create(config, kSampleRateHz, RenderDelayBuffer::Create(config, kSampleRateHz,
num_render_channels)); num_render_channels));
@ -44,20 +44,26 @@ TEST(ResidualEchoEstimator, BasicTest) {
kNumBands, kNumBands,
std::vector<std::vector<float>>(num_render_channels, std::vector<std::vector<float>>(num_render_channels,
std::vector<float>(kBlockSize, 0.f))); std::vector<float>(kBlockSize, 0.f)));
std::vector<std::array<float, kFftLengthBy2Plus1>> H2(10); std::vector<std::vector<std::array<float, kFftLengthBy2Plus1>>> H2(
num_capture_channels,
std::vector<std::array<float, kFftLengthBy2Plus1>>(10));
Random random_generator(42U); Random random_generator(42U);
std::vector<SubtractorOutput> output(num_render_channels); std::vector<SubtractorOutput> output(num_capture_channels);
std::array<float, kBlockSize> y; std::array<float, kBlockSize> y;
absl::optional<DelayEstimate> delay_estimate; absl::optional<DelayEstimate> delay_estimate;
for (auto& H2_k : H2) { for (auto& H2_ch : H2) {
H2_k.fill(0.01f); for (auto& H2_k : H2_ch) {
H2_k.fill(0.01f);
}
H2_ch[2].fill(10.f);
H2_ch[2][0] = 0.1f;
} }
H2[2].fill(10.f);
H2[2][0] = 0.1f;
std::vector<float> h( std::vector<std::vector<float>> h(
GetTimeDomainLength(config.filter.main.length_blocks), 0.f); num_capture_channels,
std::vector<float>(
GetTimeDomainLength(config.filter.main.length_blocks), 0.f));
for (auto& subtractor_output : output) { for (auto& subtractor_output : output) {
subtractor_output.Reset(); subtractor_output.Reset();

View File

@ -145,8 +145,8 @@ std::vector<float> RunSubtractorTest(
aec_state.HandleEchoPathChange(EchoPathVariability( aec_state.HandleEchoPathChange(EchoPathVariability(
false, EchoPathVariability::DelayAdjustment::kNone, false)); false, EchoPathVariability::DelayAdjustment::kNone, false));
aec_state.Update(delay_estimate, subtractor.FilterFrequencyResponse()[0], aec_state.Update(delay_estimate, subtractor.FilterFrequencyResponse(),
subtractor.FilterImpulseResponse()[0], subtractor.FilterImpulseResponse(),
*render_delay_buffer->GetRenderBuffer(), E2_main, Y2, *render_delay_buffer->GetRenderBuffer(), E2_main, Y2,
output); output);
} }

View File

@ -97,14 +97,14 @@ TEST(SuppressionGain, BasicGainComputation) {
// Ensure that the gain is no longer forced to zero. // Ensure that the gain is no longer forced to zero.
for (int k = 0; k <= kNumBlocksPerSecond / 5 + 1; ++k) { for (int k = 0; k <= kNumBlocksPerSecond / 5 + 1; ++k) {
aec_state.Update(delay_estimate, subtractor.FilterFrequencyResponse()[0], aec_state.Update(delay_estimate, subtractor.FilterFrequencyResponse(),
subtractor.FilterImpulseResponse()[0], subtractor.FilterImpulseResponse(),
*render_delay_buffer->GetRenderBuffer(), E2, Y2, output); *render_delay_buffer->GetRenderBuffer(), E2, Y2, output);
} }
for (int k = 0; k < 100; ++k) { for (int k = 0; k < 100; ++k) {
aec_state.Update(delay_estimate, subtractor.FilterFrequencyResponse()[0], aec_state.Update(delay_estimate, subtractor.FilterFrequencyResponse(),
subtractor.FilterImpulseResponse()[0], subtractor.FilterImpulseResponse(),
*render_delay_buffer->GetRenderBuffer(), E2, Y2, output); *render_delay_buffer->GetRenderBuffer(), E2, Y2, output);
suppression_gain.GetGain(E2, S2, R2, N2, analyzer, aec_state, x, suppression_gain.GetGain(E2, S2, R2, N2, analyzer, aec_state, x,
&high_bands_gain, &g); &high_bands_gain, &g);
@ -120,8 +120,8 @@ TEST(SuppressionGain, BasicGainComputation) {
N2.fill(0.f); N2.fill(0.f);
for (int k = 0; k < 100; ++k) { for (int k = 0; k < 100; ++k) {
aec_state.Update(delay_estimate, subtractor.FilterFrequencyResponse()[0], aec_state.Update(delay_estimate, subtractor.FilterFrequencyResponse(),
subtractor.FilterImpulseResponse()[0], subtractor.FilterImpulseResponse(),
*render_delay_buffer->GetRenderBuffer(), E2, Y2, output); *render_delay_buffer->GetRenderBuffer(), E2, Y2, output);
suppression_gain.GetGain(E2, S2, R2, N2, analyzer, aec_state, x, suppression_gain.GetGain(E2, S2, R2, N2, analyzer, aec_state, x,
&high_bands_gain, &g); &high_bands_gain, &g);