Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Side by Side Diff: webrtc/modules/audio_processing/utility/delay_estimator.cc

Issue 1967033002: Corrected the delay agnostic AEC behavior during periods of silent farend signal. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Updated the unittest reference file for mac with a new standard deviation value obtained from APM w… Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « data/audio_processing/output_data_mac.pb ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_processing/utility/delay_estimator.h" 11 #include "webrtc/modules/audio_processing/utility/delay_estimator.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include <string.h> 15 #include <string.h>
16 #include <algorithm>
16 17
17 // Number of right shifts for scaling is linearly depending on number of bits in 18 // Number of right shifts for scaling is linearly depending on number of bits in
18 // the far-end binary spectrum. 19 // the far-end binary spectrum.
19 static const int kShiftsAtZero = 13; // Right shifts at zero binary spectrum. 20 static const int kShiftsAtZero = 13; // Right shifts at zero binary spectrum.
20 static const int kShiftsLinearSlope = 3; 21 static const int kShiftsLinearSlope = 3;
21 22
22 static const int32_t kProbabilityOffset = 1024; // 2 in Q9. 23 static const int32_t kProbabilityOffset = 1024; // 2 in Q9.
23 static const int32_t kProbabilityLowerLimit = 8704; // 17 in Q9. 24 static const int32_t kProbabilityLowerLimit = 8704; // 17 in Q9.
24 static const int32_t kProbabilityMinSpread = 2816; // 5.5 in Q9. 25 static const int32_t kProbabilityMinSpread = 2816; // 5.5 in Q9.
25 26
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 // 1) The valley is distinct enough (|valley_depth| > |kProbabilityOffset|) 612 // 1) The valley is distinct enough (|valley_depth| > |kProbabilityOffset|)
612 // and 613 // and
613 // 2) The depth of the valley is deep enough 614 // 2) The depth of the valley is deep enough
614 // (|value_best_candidate| < |minimum_probability|) 615 // (|value_best_candidate| < |minimum_probability|)
615 // and deeper than the best estimate so far 616 // and deeper than the best estimate so far
616 // (|value_best_candidate| < |last_delay_probability|) 617 // (|value_best_candidate| < |last_delay_probability|)
617 valid_candidate = ((valley_depth > kProbabilityOffset) && 618 valid_candidate = ((valley_depth > kProbabilityOffset) &&
618 ((value_best_candidate < self->minimum_probability) || 619 ((value_best_candidate < self->minimum_probability) ||
619 (value_best_candidate < self->last_delay_probability))); 620 (value_best_candidate < self->last_delay_probability)));
620 621
621 UpdateRobustValidationStatistics(self, candidate_delay, valley_depth, 622 // Check for nonstationary farend signal.
622 value_best_candidate); 623 const bool non_stationary_farend =
624 std::any_of(self->farend->far_bit_counts,
625 self->farend->far_bit_counts + self->history_size,
626 [](int a) { return a > 0; });
627
628 if (non_stationary_farend) {
629 // Only update the validation statistics when the farend is nonstationary
630 // as the underlying estimates are otherwise frozen.
631 UpdateRobustValidationStatistics(self, candidate_delay, valley_depth,
632 value_best_candidate);
633 }
634
623 if (self->robust_validation_enabled) { 635 if (self->robust_validation_enabled) {
624 int is_histogram_valid = HistogramBasedValidation(self, candidate_delay); 636 int is_histogram_valid = HistogramBasedValidation(self, candidate_delay);
625 valid_candidate = RobustValidation(self, candidate_delay, valid_candidate, 637 valid_candidate = RobustValidation(self, candidate_delay, valid_candidate,
626 is_histogram_valid); 638 is_histogram_valid);
627 639
628 } 640 }
629 if (valid_candidate) { 641
642 // Only update the delay estimate when the farend is nonstationary and when
643 // a valid delay candidate is available.
644 if (non_stationary_farend && valid_candidate) {
630 if (candidate_delay != self->last_delay) { 645 if (candidate_delay != self->last_delay) {
631 self->last_delay_histogram = 646 self->last_delay_histogram =
632 (self->histogram[candidate_delay] > kLastHistogramMax ? 647 (self->histogram[candidate_delay] > kLastHistogramMax ?
633 kLastHistogramMax : self->histogram[candidate_delay]); 648 kLastHistogramMax : self->histogram[candidate_delay]);
634 // Adjust the histogram if we made a change to |last_delay|, though it was 649 // Adjust the histogram if we made a change to |last_delay|, though it was
635 // not the most likely one according to the histogram. 650 // not the most likely one according to the histogram.
636 if (self->histogram[candidate_delay] < 651 if (self->histogram[candidate_delay] <
637 self->histogram[self->compare_delay]) { 652 self->histogram[self->compare_delay]) {
638 self->histogram[self->compare_delay] = self->histogram[candidate_delay]; 653 self->histogram[self->compare_delay] = self->histogram[candidate_delay];
639 } 654 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 int32_t diff = new_value - *mean_value; 693 int32_t diff = new_value - *mean_value;
679 694
680 // mean_new = mean_value + ((new_value - mean_value) >> factor); 695 // mean_new = mean_value + ((new_value - mean_value) >> factor);
681 if (diff < 0) { 696 if (diff < 0) {
682 diff = -((-diff) >> factor); 697 diff = -((-diff) >> factor);
683 } else { 698 } else {
684 diff = (diff >> factor); 699 diff = (diff >> factor);
685 } 700 }
686 *mean_value += diff; 701 *mean_value += diff;
687 } 702 }
OLDNEW
« no previous file with comments | « data/audio_processing/output_data_mac.pb ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698